nsIX509CertDB.idl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is mozilla.org code.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * Netscape Communications Corporation.
  20. * Portions created by the Initial Developer are Copyright (C) 1998
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. * Javier Delgadillo <[email protected]>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either the GNU General Public License Version 2 or later (the "GPL"), or
  28. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #include "nsISupports.idl"
  40. interface nsIArray;
  41. interface nsIX509Cert;
  42. interface nsILocalFile;
  43. interface nsIInterfaceRequestor;
  44. %{C++
  45. #define NS_X509CERTDB_CONTRACTID "@mozilla.org/security/x509certdb;1"
  46. %}
  47. /**
  48. * This represents a service to access and manipulate
  49. * X.509 certificates stored in a database.
  50. *
  51. * @status FROZEN
  52. */
  53. [scriptable, uuid(da48b3c0-1284-11d5-ac67-000064657374)]
  54. interface nsIX509CertDB : nsISupports {
  55. /**
  56. * Constants that define which usages a certificate
  57. * is trusted for.
  58. */
  59. const unsigned long UNTRUSTED = 0;
  60. const unsigned long TRUSTED_SSL = 1 << 0;
  61. const unsigned long TRUSTED_EMAIL = 1 << 1;
  62. const unsigned long TRUSTED_OBJSIGN = 1 << 2;
  63. /**
  64. * Given a nickname and optionally a token,
  65. * locate the matching certificate.
  66. *
  67. * @param aToken Optionally limits the scope of
  68. * this function to a token device.
  69. * Can be null to mean any token.
  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 nsISupports aToken,
  76. in AString aNickname);
  77. /**
  78. * Will find a certificate based on its dbkey
  79. * retrieved by getting the dbKey attribute of
  80. * the certificate.
  81. *
  82. * @param aDBkey Database internal key, as obtained using
  83. * attribute dbkey in nsIX509Cert.
  84. * @param aToken Optionally limits the scope of
  85. * this function to a token device.
  86. * Can be null to mean any token.
  87. */
  88. nsIX509Cert findCertByDBKey(in string aDBkey, in nsISupports aToken);
  89. /**
  90. * Obtain a list of certificate nicknames from the database.
  91. * What the name is depends on type:
  92. * user, ca, or server cert - the nickname
  93. * email cert - the email address
  94. *
  95. * @param aToken Optionally limits the scope of
  96. * this function to a token device.
  97. * Can be null to mean any token.
  98. * @param aType Type of certificate to obtain
  99. * See certificate type constants in nsIX509Cert.
  100. * @param count The number of nicknames in the returned array
  101. * @param certNameList The returned array of certificate nicknames.
  102. */
  103. void findCertNicknames(in nsISupports aToken,
  104. in unsigned long aType,
  105. out unsigned long count,
  106. [array, size_is(count)] out wstring certNameList);
  107. /**
  108. * Find the email encryption certificate by nickname.
  109. *
  110. * @param aNickname The nickname to be used as the key
  111. * to find the certificate.
  112. *
  113. * @return The matching certificate if found.
  114. */
  115. nsIX509Cert findEmailEncryptionCert(in AString aNickname);
  116. /**
  117. * Find the email signing certificate by nickname.
  118. *
  119. * @param aNickname The nickname to be used as the key
  120. * to find the certificate.
  121. *
  122. * @return The matching certificate if found.
  123. */
  124. nsIX509Cert findEmailSigningCert(in AString aNickname);
  125. /**
  126. * Find a certificate by email address.
  127. *
  128. * @param aToken Optionally limits the scope of
  129. * this function to a token device.
  130. * Can be null to mean any token.
  131. * @param aEmailAddress The email address to be used as the key
  132. * to find the certificate.
  133. *
  134. * @return The matching certificate if found.
  135. */
  136. nsIX509Cert findCertByEmailAddress(in nsISupports aToken,
  137. in string aEmailAddress);
  138. /**
  139. * Use this to import a stream sent down as a mime type into
  140. * the certificate database on the default token.
  141. * The stream may consist of one or more certificates.
  142. *
  143. * @param data The raw data to be imported
  144. * @param length The length of the data to be imported
  145. * @param type The type of the certificate, see constants in nsIX509Cert
  146. * @param ctx A UI context.
  147. */
  148. void importCertificates([array, size_is(length)] in octet data,
  149. in unsigned long length,
  150. in unsigned long type,
  151. in nsIInterfaceRequestor ctx);
  152. /**
  153. * Import another person's email certificate into the database.
  154. *
  155. * @param data The raw data to be imported
  156. * @param length The length of the data to be imported
  157. * @param ctx A UI context.
  158. */
  159. void importEmailCertificate([array, size_is(length)] in octet data,
  160. in unsigned long length,
  161. in nsIInterfaceRequestor ctx);
  162. /**
  163. * Import a server machine's certificate into the database.
  164. *
  165. * @param data The raw data to be imported
  166. * @param length The length of the data to be imported
  167. * @param ctx A UI context.
  168. */
  169. void importServerCertificate([array, size_is(length)] in octet data,
  170. in unsigned long length,
  171. in nsIInterfaceRequestor ctx);
  172. /**
  173. * Import a personal certificate into the database, assuming
  174. * the database already contains the private key for this certificate.
  175. *
  176. * @param data The raw data to be imported
  177. * @param length The length of the data to be imported
  178. * @param ctx A UI context.
  179. */
  180. void importUserCertificate([array, size_is(length)] in octet data,
  181. in unsigned long length,
  182. in nsIInterfaceRequestor ctx);
  183. /**
  184. * Delete a certificate stored in the database.
  185. *
  186. * @param aCert Delete this certificate.
  187. */
  188. void deleteCertificate(in nsIX509Cert aCert);
  189. /**
  190. * Modify the trust that is stored and associated to a certificate within
  191. * a database. Separate trust is stored for
  192. * One call manipulates the trust for one trust type only.
  193. * See the trust type constants defined within this interface.
  194. *
  195. * @param cert Change the stored trust of this certificate.
  196. * @param type The type of the certificate. See nsIX509Cert.
  197. * @param trust A bitmask. The new trust for the possible usages.
  198. * See the trust constants defined within this interface.
  199. */
  200. void setCertTrust(in nsIX509Cert cert,
  201. in unsigned long type,
  202. in unsigned long trust);
  203. /**
  204. * Query whether a certificate is trusted for a particular use.
  205. *
  206. * @param cert Obtain the stored trust of this certificate.
  207. * @param certType The type of the certificate. See nsIX509Cert.
  208. * @param trustType A single bit from the usages constants defined
  209. * within this interface.
  210. *
  211. * @return Returns true if the certificate is trusted for the given use.
  212. */
  213. boolean isCertTrusted(in nsIX509Cert cert,
  214. in unsigned long certType,
  215. in unsigned long trustType);
  216. /**
  217. * Import certificate(s) from file
  218. *
  219. * @param aToken Optionally limits the scope of
  220. * this function to a token device.
  221. * Can be null to mean any token.
  222. * @param aFile Identifies a file that contains the certificate
  223. * to be imported.
  224. * @param aType Describes the type of certificate that is going to
  225. * be imported. See type constants in nsIX509Cert.
  226. */
  227. void importCertsFromFile(in nsISupports aToken,
  228. in nsILocalFile aFile,
  229. in unsigned long aType);
  230. /**
  231. * Import a PKCS#12 file containing cert(s) and key(s) into the database.
  232. *
  233. * @param aToken Optionally limits the scope of
  234. * this function to a token device.
  235. * Can be null to mean any token.
  236. * @param aFile Identifies a file that contains the data
  237. * to be imported.
  238. */
  239. void importPKCS12File(in nsISupports aToken,
  240. in nsILocalFile aFile);
  241. /**
  242. * Export a set of certs and keys from the database to a PKCS#12 file.
  243. *
  244. * @param aToken Optionally limits the scope of
  245. * this function to a token device.
  246. * Can be null to mean any token.
  247. * @param aFile Identifies a file that will be filled with the data
  248. * to be exported.
  249. * @param count The number of certificates to be exported.
  250. * @param aCerts The array of all certificates to be exported.
  251. */
  252. void exportPKCS12File(in nsISupports aToken,
  253. in nsILocalFile aFile,
  254. in unsigned long count,
  255. [array, size_is(count)] in nsIX509Cert aCerts);
  256. /**
  257. * An array of all known OCSP responders within the scope of the
  258. * certificate database.
  259. *
  260. * @return Array of OCSP responders, entries are QIable to nsIOCSPResponder.
  261. */
  262. nsIArray getOCSPResponders();
  263. /**
  264. * Whether OCSP is enabled in preferences.
  265. */
  266. readonly attribute boolean isOcspOn;
  267. /*
  268. * Decode a raw data presentation and instantiate an object in memory.
  269. *
  270. * @param base64 The raw representation of a certificate,
  271. * encoded as Base 64.
  272. * @return The new certificate object.
  273. */
  274. nsIX509Cert constructX509FromBase64(in string base64);
  275. };