nsIX509CertDB.idl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsISupports.idl"
  7. interface nsIArray;
  8. interface nsIX509Cert;
  9. interface nsIFile;
  10. interface nsIInterfaceRequestor;
  11. interface nsIZipReader;
  12. interface nsIX509CertList;
  13. interface nsIInputStream;
  14. %{C++
  15. #define NS_X509CERTDB_CONTRACTID "@mozilla.org/security/x509certdb;1"
  16. %}
  17. typedef uint32_t AppTrustedRoot;
  18. [scriptable, function, uuid(fc2b60e5-9a07-47c2-a2cd-b83b68a660ac)]
  19. interface nsIOpenSignedAppFileCallback : nsISupports
  20. {
  21. void openSignedAppFileFinished(in nsresult rv,
  22. in nsIZipReader aZipReader,
  23. in nsIX509Cert aSignerCert);
  24. };
  25. [scriptable, function, uuid(d5f97827-622a-488f-be08-d850432ac8ec)]
  26. interface nsIVerifySignedDirectoryCallback : nsISupports
  27. {
  28. void verifySignedDirectoryFinished(in nsresult rv,
  29. in nsIX509Cert aSignerCert);
  30. };
  31. [scriptable, function, uuid(3d6a9c87-5c5f-46fc-9410-96da6092f0f2)]
  32. interface nsIVerifySignedManifestCallback : nsISupports
  33. {
  34. void verifySignedManifestFinished(in nsresult rv,
  35. in nsIX509Cert aSignerCert);
  36. };
  37. /**
  38. * Callback type for use with asyncVerifyCertAtTime.
  39. * If aPRErrorCode is PRErrorCodeSuccess (i.e. 0), aVerifiedChain represents the
  40. * verified certificate chain determined by asyncVerifyCertAtTime. aHasEVPolicy
  41. * represents whether or not the end-entity certificate verified as EV.
  42. * If aPRErrorCode is non-zero, it represents the error encountered during
  43. * verification. aVerifiedChain is null in that case and aHasEVPolicy has no
  44. * meaning.
  45. */
  46. [scriptable, function, uuid(49e16fc8-efac-4f57-8361-956ef6b960a4)]
  47. interface nsICertVerificationCallback : nsISupports {
  48. void verifyCertFinished(in int32_t aPRErrorCode,
  49. in nsIX509CertList aVerifiedChain,
  50. in bool aHasEVPolicy);
  51. };
  52. /**
  53. * This represents a service to access and manipulate
  54. * X.509 certificates stored in a database.
  55. */
  56. [scriptable, uuid(5c16cd9b-5a73-47f1-ab0f-11ede7495cce)]
  57. interface nsIX509CertDB : nsISupports {
  58. /**
  59. * Constants that define which usages a certificate
  60. * is trusted for.
  61. */
  62. const unsigned long UNTRUSTED = 0;
  63. const unsigned long TRUSTED_SSL = 1 << 0;
  64. const unsigned long TRUSTED_EMAIL = 1 << 1;
  65. const unsigned long TRUSTED_OBJSIGN = 1 << 2;
  66. /**
  67. * Given a nickname,
  68. * locate the matching certificate.
  69. *
  70. * @param aNickname The nickname to be used as the key
  71. * to find a certificate.
  72. *
  73. * @return The matching certificate if found.
  74. */
  75. nsIX509Cert findCertByNickname(in AString aNickname);
  76. /**
  77. * Will find a certificate based on its dbkey
  78. * retrieved by getting the dbKey attribute of
  79. * the certificate.
  80. *
  81. * @param aDBkey Database internal key, as obtained using
  82. * attribute dbkey in nsIX509Cert.
  83. */
  84. nsIX509Cert findCertByDBKey(in string aDBkey);
  85. /**
  86. * Find user's own email encryption certificate by nickname.
  87. *
  88. * @param aNickname The nickname to be used as the key
  89. * to find the certificate.
  90. *
  91. * @return The matching certificate if found.
  92. */
  93. nsIX509Cert findEmailEncryptionCert(in AString aNickname);
  94. /**
  95. * Find user's own email signing certificate by nickname.
  96. *
  97. * @param aNickname The nickname to be used as the key
  98. * to find the certificate.
  99. *
  100. * @return The matching certificate if found.
  101. */
  102. nsIX509Cert findEmailSigningCert(in AString aNickname);
  103. /**
  104. * Find a certificate by email address.
  105. *
  106. * @param aEmailAddress The email address to be used as the key
  107. * to find the certificate.
  108. *
  109. * @return The matching certificate if found.
  110. */
  111. nsIX509Cert findCertByEmailAddress(in string aEmailAddress);
  112. /**
  113. * Use this to import a stream sent down as a mime type into
  114. * the certificate database on the default token.
  115. * The stream may consist of one or more certificates.
  116. *
  117. * @param data The raw data to be imported
  118. * @param length The length of the data to be imported
  119. * @param type The type of the certificate, see constants in nsIX509Cert
  120. * @param ctx A UI context.
  121. */
  122. void importCertificates([array, size_is(length)] in octet data,
  123. in unsigned long length,
  124. in unsigned long type,
  125. in nsIInterfaceRequestor ctx);
  126. /**
  127. * Import another person's email certificate into the database.
  128. *
  129. * @param data The raw data to be imported
  130. * @param length The length of the data to be imported
  131. * @param ctx A UI context.
  132. */
  133. void importEmailCertificate([array, size_is(length)] in octet data,
  134. in unsigned long length,
  135. in nsIInterfaceRequestor ctx);
  136. /**
  137. * Import a personal certificate into the database, assuming
  138. * the database already contains the private key for this certificate.
  139. *
  140. * @param data The raw data to be imported
  141. * @param length The length of the data to be imported
  142. * @param ctx A UI context.
  143. */
  144. void importUserCertificate([array, size_is(length)] in octet data,
  145. in unsigned long length,
  146. in nsIInterfaceRequestor ctx);
  147. /**
  148. * Delete a certificate stored in the database.
  149. *
  150. * @param aCert Delete this certificate.
  151. */
  152. void deleteCertificate(in nsIX509Cert aCert);
  153. /**
  154. * Modify the trust that is stored and associated to a certificate within
  155. * a database. Separate trust is stored for
  156. * One call manipulates the trust for one trust type only.
  157. * See the trust type constants defined within this interface.
  158. *
  159. * @param cert Change the stored trust of this certificate.
  160. * @param type The type of the certificate. See nsIX509Cert.
  161. * @param trust A bitmask. The new trust for the possible usages.
  162. * See the trust constants defined within this interface.
  163. */
  164. void setCertTrust(in nsIX509Cert cert,
  165. in unsigned long type,
  166. in unsigned long trust);
  167. /**
  168. * @param cert The certificate for which to modify trust.
  169. * @param trustString decoded by CERT_DecodeTrustString. 3 comma separated
  170. * characters, indicating SSL, Email, and Obj signing
  171. * trust.
  172. */
  173. void setCertTrustFromString(in nsIX509Cert cert, in ACString trustString);
  174. /**
  175. * Query whether a certificate is trusted for a particular use.
  176. *
  177. * @param cert Obtain the stored trust of this certificate.
  178. * @param certType The type of the certificate. See nsIX509Cert.
  179. * @param trustType A single bit from the usages constants defined
  180. * within this interface.
  181. *
  182. * @return Returns true if the certificate is trusted for the given use.
  183. */
  184. boolean isCertTrusted(in nsIX509Cert cert,
  185. in unsigned long certType,
  186. in unsigned long trustType);
  187. /**
  188. * Import certificate(s) from file
  189. *
  190. * @param aFile Identifies a file that contains the certificate
  191. * to be imported.
  192. * @param aType Describes the type of certificate that is going to
  193. * be imported. See type constants in nsIX509Cert.
  194. */
  195. void importCertsFromFile(in nsIFile aFile,
  196. in unsigned long aType);
  197. /**
  198. * Import a PKCS#12 file containing cert(s) and key(s) into the database.
  199. *
  200. * @param aToken Optionally limits the scope of
  201. * this function to a token device.
  202. * Can be null to mean any token.
  203. * @param aFile Identifies a file that contains the data
  204. * to be imported.
  205. */
  206. void importPKCS12File(in nsISupports aToken,
  207. in nsIFile aFile);
  208. /**
  209. * Export a set of certs and keys from the database to a PKCS#12 file.
  210. *
  211. * @param aToken Optionally limits the scope of
  212. * this function to a token device.
  213. * Can be null to mean any token.
  214. * @param aFile Identifies a file that will be filled with the data
  215. * to be exported.
  216. * @param count The number of certificates to be exported.
  217. * @param aCerts The array of all certificates to be exported.
  218. */
  219. void exportPKCS12File(in nsISupports aToken,
  220. in nsIFile aFile,
  221. in unsigned long count,
  222. [array, size_is(count)] in nsIX509Cert aCerts);
  223. /*
  224. * Decode a raw data presentation and instantiate an object in memory.
  225. *
  226. * @param base64 The raw representation of a certificate,
  227. * encoded as Base 64.
  228. * @return The new certificate object.
  229. */
  230. nsIX509Cert constructX509FromBase64(in ACString base64);
  231. /*
  232. * Decode a raw data presentation and instantiate an object in memory.
  233. *
  234. * @param certDER The raw representation of a certificate,
  235. * encoded as raw DER.
  236. * @param length The length of the DER string.
  237. * @return The new certificate object.
  238. */
  239. nsIX509Cert constructX509(in string certDER, in unsigned long length);
  240. /**
  241. * Verifies the signature on the given JAR file to verify that it has a
  242. * valid signature. To be considered valid, there must be exactly one
  243. * signature on the JAR file and that signature must have signed every
  244. * entry. Further, the signature must come from a certificate that
  245. * is trusted for code signing.
  246. *
  247. * On success, NS_OK, a nsIZipReader, and the trusted certificate that
  248. * signed the JAR are returned.
  249. *
  250. * On failure, an error code is returned.
  251. *
  252. * This method returns a nsIZipReader, instead of taking an nsIZipReader
  253. * as input, to encourage users of the API to verify the signature as the
  254. * first step in opening the JAR.
  255. */
  256. const AppTrustedRoot AppMarketplaceProdPublicRoot = 1;
  257. const AppTrustedRoot AppMarketplaceProdReviewersRoot = 2;
  258. const AppTrustedRoot AppMarketplaceDevPublicRoot = 3;
  259. const AppTrustedRoot AppMarketplaceDevReviewersRoot = 4;
  260. const AppTrustedRoot AppMarketplaceStageRoot = 5;
  261. const AppTrustedRoot AppXPCShellRoot = 6;
  262. const AppTrustedRoot AddonsPublicRoot = 7;
  263. const AppTrustedRoot AddonsStageRoot = 8;
  264. const AppTrustedRoot PrivilegedPackageRoot = 9;
  265. /*
  266. * If DeveloperImportedRoot is set as trusted root, a CA from local file
  267. * system will be imported. Only used when preference
  268. * "network.http.packaged-apps-developer-mode" is set.
  269. * The path of the CA is specified by preference
  270. * "network.http.packaged-apps-developer-trusted-root".
  271. */
  272. const AppTrustedRoot DeveloperImportedRoot = 10;
  273. void openSignedAppFileAsync(in AppTrustedRoot trustedRoot,
  274. in nsIFile aJarFile,
  275. in nsIOpenSignedAppFileCallback callback);
  276. /**
  277. * Verifies the signature on a directory representing an unpacked signed
  278. * JAR file. To be considered valid, there must be exactly one signature
  279. * on the directory structure and that signature must have signed every
  280. * entry. Further, the signature must come from a certificate that
  281. * is trusted for code signing.
  282. *
  283. * On success NS_OK and the trusted certificate that signed the
  284. * unpacked JAR are returned.
  285. *
  286. * On failure, an error code is returned.
  287. */
  288. void verifySignedDirectoryAsync(in AppTrustedRoot trustedRoot,
  289. in nsIFile aUnpackedDir,
  290. in nsIVerifySignedDirectoryCallback callback);
  291. /**
  292. * Given streams containing a signature and a manifest file, verifies
  293. * that the signature is valid for the manifest. The signature must
  294. * come from a certificate that is trusted for code signing and that
  295. * was issued by the given trusted root.
  296. *
  297. * On success, NS_OK and the trusted certificate that signed the
  298. * Manifest are returned.
  299. *
  300. * On failure, an error code is returned.
  301. */
  302. void verifySignedManifestAsync(in AppTrustedRoot trustedRoot,
  303. in nsIInputStream aManifestStream,
  304. in nsIInputStream aSignatureStream,
  305. in nsIVerifySignedManifestCallback callback);
  306. /*
  307. * Add a cert to a cert DB from a binary string.
  308. *
  309. * @param certDER The raw DER encoding of a certificate.
  310. * @param aTrust decoded by CERT_DecodeTrustString. 3 comma separated characters,
  311. * indicating SSL, Email, and Obj signing trust
  312. * @param aName name of the cert for display purposes.
  313. * TODO(bug 857627): aName is currently ignored. It should either
  314. * not be ignored, or be removed.
  315. */
  316. void addCert(in ACString certDER, in ACString aTrust, in AUTF8String aName);
  317. // Flags for verifyCertNow (these must match the values in CertVerifier.cpp):
  318. // Prevent network traffic. Doesn't work with classic verification.
  319. const uint32_t FLAG_LOCAL_ONLY = 1 << 0;
  320. // Do not fall back to DV verification after attempting EV validation.
  321. // Actually does prevent network traffic, but can cause a valid EV
  322. // certificate to not be considered valid.
  323. const uint32_t FLAG_MUST_BE_EV = 1 << 1;
  324. /** Warning: This interface is inteded to use only for testing only as:
  325. * 1. It can create IO on the main thread.
  326. * 2. It is in constant change, so in/out can change at any release.
  327. *
  328. * Obtain the verification result for a cert given a particular usage.
  329. * On success, the call returns 0, the chain built during verification,
  330. * and whether the cert is good for EV usage.
  331. * On failure, the call returns the PRErrorCode for the verification failure
  332. *
  333. * @param aCert Obtain the stored trust of this certificate
  334. * @param aUsage a integer representing the usage from NSS
  335. * @param aFlags flags as described above
  336. * @param aHostname the (optional) hostname to verify for
  337. * @param aTime the time at which to verify, in seconds since the epoch
  338. * @param aVerifiedChain chain of verification up to the root if success
  339. * @param aHasEVPolicy bool that signified that the cert was an EV cert
  340. * @return 0 if success or the value or the error code for the verification
  341. * failure
  342. */
  343. int32_t /*PRErrorCode*/
  344. verifyCertAtTime(in nsIX509Cert aCert,
  345. in int64_t /*SECCertificateUsage*/ aUsage,
  346. in uint32_t aFlags,
  347. in string aHostname,
  348. in uint64_t aTime,
  349. out nsIX509CertList aVerifiedChain,
  350. out bool aHasEVPolicy);
  351. int32_t /*PRErrorCode*/
  352. verifyCertNow(in nsIX509Cert aCert,
  353. in int64_t /*SECCertificateUsage*/ aUsage,
  354. in uint32_t aFlags,
  355. in string aHostname,
  356. out nsIX509CertList aVerifiedChain,
  357. out bool aHasEVPolicy);
  358. /**
  359. * Similar to the above, but asynchronous. As a result, use of this API is not
  360. * limited to tests.
  361. */
  362. void asyncVerifyCertAtTime(in nsIX509Cert aCert,
  363. in int64_t /*SECCertificateUsage*/ aUsage,
  364. in uint32_t aFlags,
  365. in string aHostname,
  366. in uint64_t aTime,
  367. in nsICertVerificationCallback aCallback);
  368. // Clears the OCSP cache for the current certificate verification
  369. // implementation.
  370. void clearOCSPCache();
  371. /*
  372. * Add a cert to a cert DB from a base64 encoded string.
  373. *
  374. * @param base64 The raw representation of a certificate,
  375. * encoded as Base 64.
  376. * @param aTrust decoded by CERT_DecodeTrustString. 3 comma separated characters,
  377. * indicating SSL, Email, and Obj signing trust
  378. * @param aName name of the cert for display purposes.
  379. * TODO(bug 857627): aName is currently ignored. It should either
  380. * not be ignored, or be removed.
  381. */
  382. void addCertFromBase64(in ACString base64, in ACString aTrust,
  383. in AUTF8String aName);
  384. /*
  385. * Get all the known certs in the database
  386. */
  387. nsIX509CertList getCerts();
  388. /*
  389. * Get a list of imported enterprise root certificates (currently only
  390. * implemented on Windows).
  391. */
  392. nsIX509CertList getEnterpriseRoots();
  393. };