Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsISupports.idl" |
michael@0 | 8 | |
michael@0 | 9 | interface nsIArray; |
michael@0 | 10 | interface nsIX509Cert; |
michael@0 | 11 | interface nsIX509Cert3; |
michael@0 | 12 | interface nsIFile; |
michael@0 | 13 | interface nsIInterfaceRequestor; |
michael@0 | 14 | interface nsIZipReader; |
michael@0 | 15 | interface nsIRecentBadCerts; |
michael@0 | 16 | interface nsIX509CertList; |
michael@0 | 17 | |
michael@0 | 18 | %{C++ |
michael@0 | 19 | #define NS_X509CERTDB_CONTRACTID "@mozilla.org/security/x509certdb;1" |
michael@0 | 20 | %} |
michael@0 | 21 | |
michael@0 | 22 | typedef uint32_t AppTrustedRoot; |
michael@0 | 23 | |
michael@0 | 24 | [scriptable, function, uuid(0927baea-622d-4e41-a76d-255af426e7fb)] |
michael@0 | 25 | interface nsIOpenSignedAppFileCallback : nsISupports |
michael@0 | 26 | { |
michael@0 | 27 | void openSignedAppFileFinished(in nsresult rv, |
michael@0 | 28 | in nsIZipReader aZipReader, |
michael@0 | 29 | in nsIX509Cert3 aSignerCert); |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * This represents a service to access and manipulate |
michael@0 | 34 | * X.509 certificates stored in a database. |
michael@0 | 35 | */ |
michael@0 | 36 | [scriptable, uuid(7446a5b1-84ca-491f-a2fe-0bc60a71ffa5)] |
michael@0 | 37 | interface nsIX509CertDB : nsISupports { |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Constants that define which usages a certificate |
michael@0 | 41 | * is trusted for. |
michael@0 | 42 | */ |
michael@0 | 43 | const unsigned long UNTRUSTED = 0; |
michael@0 | 44 | const unsigned long TRUSTED_SSL = 1 << 0; |
michael@0 | 45 | const unsigned long TRUSTED_EMAIL = 1 << 1; |
michael@0 | 46 | const unsigned long TRUSTED_OBJSIGN = 1 << 2; |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * Given a nickname and optionally a token, |
michael@0 | 50 | * locate the matching certificate. |
michael@0 | 51 | * |
michael@0 | 52 | * @param aToken Optionally limits the scope of |
michael@0 | 53 | * this function to a token device. |
michael@0 | 54 | * Can be null to mean any token. |
michael@0 | 55 | * @param aNickname The nickname to be used as the key |
michael@0 | 56 | * to find a certificate. |
michael@0 | 57 | * |
michael@0 | 58 | * @return The matching certificate if found. |
michael@0 | 59 | */ |
michael@0 | 60 | nsIX509Cert findCertByNickname(in nsISupports aToken, |
michael@0 | 61 | in AString aNickname); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Will find a certificate based on its dbkey |
michael@0 | 65 | * retrieved by getting the dbKey attribute of |
michael@0 | 66 | * the certificate. |
michael@0 | 67 | * |
michael@0 | 68 | * @param aDBkey Database internal key, as obtained using |
michael@0 | 69 | * attribute dbkey in nsIX509Cert. |
michael@0 | 70 | * @param aToken Optionally limits the scope of |
michael@0 | 71 | * this function to a token device. |
michael@0 | 72 | * Can be null to mean any token. |
michael@0 | 73 | */ |
michael@0 | 74 | nsIX509Cert findCertByDBKey(in string aDBkey, in nsISupports aToken); |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * Obtain a list of certificate nicknames from the database. |
michael@0 | 78 | * What the name is depends on type: |
michael@0 | 79 | * user, ca, or server cert - the nickname |
michael@0 | 80 | * email cert - the email address |
michael@0 | 81 | * |
michael@0 | 82 | * @param aToken Optionally limits the scope of |
michael@0 | 83 | * this function to a token device. |
michael@0 | 84 | * Can be null to mean any token. |
michael@0 | 85 | * @param aType Type of certificate to obtain |
michael@0 | 86 | * See certificate type constants in nsIX509Cert. |
michael@0 | 87 | * @param count The number of nicknames in the returned array |
michael@0 | 88 | * @param certNameList The returned array of certificate nicknames. |
michael@0 | 89 | */ |
michael@0 | 90 | void findCertNicknames(in nsISupports aToken, |
michael@0 | 91 | in unsigned long aType, |
michael@0 | 92 | out unsigned long count, |
michael@0 | 93 | [array, size_is(count)] out wstring certNameList); |
michael@0 | 94 | |
michael@0 | 95 | /** |
michael@0 | 96 | * Find user's own email encryption certificate by nickname. |
michael@0 | 97 | * |
michael@0 | 98 | * @param aNickname The nickname to be used as the key |
michael@0 | 99 | * to find the certificate. |
michael@0 | 100 | * |
michael@0 | 101 | * @return The matching certificate if found. |
michael@0 | 102 | */ |
michael@0 | 103 | nsIX509Cert findEmailEncryptionCert(in AString aNickname); |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Find user's own email signing certificate by nickname. |
michael@0 | 107 | * |
michael@0 | 108 | * @param aNickname The nickname to be used as the key |
michael@0 | 109 | * to find the certificate. |
michael@0 | 110 | * |
michael@0 | 111 | * @return The matching certificate if found. |
michael@0 | 112 | */ |
michael@0 | 113 | nsIX509Cert findEmailSigningCert(in AString aNickname); |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Find a certificate by email address. |
michael@0 | 117 | * |
michael@0 | 118 | * @param aToken Optionally limits the scope of |
michael@0 | 119 | * this function to a token device. |
michael@0 | 120 | * Can be null to mean any token. |
michael@0 | 121 | * @param aEmailAddress The email address to be used as the key |
michael@0 | 122 | * to find the certificate. |
michael@0 | 123 | * |
michael@0 | 124 | * @return The matching certificate if found. |
michael@0 | 125 | */ |
michael@0 | 126 | nsIX509Cert findCertByEmailAddress(in nsISupports aToken, |
michael@0 | 127 | in string aEmailAddress); |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Use this to import a stream sent down as a mime type into |
michael@0 | 131 | * the certificate database on the default token. |
michael@0 | 132 | * The stream may consist of one or more certificates. |
michael@0 | 133 | * |
michael@0 | 134 | * @param data The raw data to be imported |
michael@0 | 135 | * @param length The length of the data to be imported |
michael@0 | 136 | * @param type The type of the certificate, see constants in nsIX509Cert |
michael@0 | 137 | * @param ctx A UI context. |
michael@0 | 138 | */ |
michael@0 | 139 | void importCertificates([array, size_is(length)] in octet data, |
michael@0 | 140 | in unsigned long length, |
michael@0 | 141 | in unsigned long type, |
michael@0 | 142 | in nsIInterfaceRequestor ctx); |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Import another person's email certificate into the database. |
michael@0 | 146 | * |
michael@0 | 147 | * @param data The raw data to be imported |
michael@0 | 148 | * @param length The length of the data to be imported |
michael@0 | 149 | * @param ctx A UI context. |
michael@0 | 150 | */ |
michael@0 | 151 | void importEmailCertificate([array, size_is(length)] in octet data, |
michael@0 | 152 | in unsigned long length, |
michael@0 | 153 | in nsIInterfaceRequestor ctx); |
michael@0 | 154 | |
michael@0 | 155 | /** |
michael@0 | 156 | * Import a server machine's certificate into the database. |
michael@0 | 157 | * |
michael@0 | 158 | * @param data The raw data to be imported |
michael@0 | 159 | * @param length The length of the data to be imported |
michael@0 | 160 | * @param ctx A UI context. |
michael@0 | 161 | */ |
michael@0 | 162 | void importServerCertificate([array, size_is(length)] in octet data, |
michael@0 | 163 | in unsigned long length, |
michael@0 | 164 | in nsIInterfaceRequestor ctx); |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Import a personal certificate into the database, assuming |
michael@0 | 168 | * the database already contains the private key for this certificate. |
michael@0 | 169 | * |
michael@0 | 170 | * @param data The raw data to be imported |
michael@0 | 171 | * @param length The length of the data to be imported |
michael@0 | 172 | * @param ctx A UI context. |
michael@0 | 173 | */ |
michael@0 | 174 | void importUserCertificate([array, size_is(length)] in octet data, |
michael@0 | 175 | in unsigned long length, |
michael@0 | 176 | in nsIInterfaceRequestor ctx); |
michael@0 | 177 | |
michael@0 | 178 | /** |
michael@0 | 179 | * Delete a certificate stored in the database. |
michael@0 | 180 | * |
michael@0 | 181 | * @param aCert Delete this certificate. |
michael@0 | 182 | */ |
michael@0 | 183 | void deleteCertificate(in nsIX509Cert aCert); |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * Modify the trust that is stored and associated to a certificate within |
michael@0 | 187 | * a database. Separate trust is stored for |
michael@0 | 188 | * One call manipulates the trust for one trust type only. |
michael@0 | 189 | * See the trust type constants defined within this interface. |
michael@0 | 190 | * |
michael@0 | 191 | * @param cert Change the stored trust of this certificate. |
michael@0 | 192 | * @param type The type of the certificate. See nsIX509Cert. |
michael@0 | 193 | * @param trust A bitmask. The new trust for the possible usages. |
michael@0 | 194 | * See the trust constants defined within this interface. |
michael@0 | 195 | */ |
michael@0 | 196 | void setCertTrust(in nsIX509Cert cert, |
michael@0 | 197 | in unsigned long type, |
michael@0 | 198 | in unsigned long trust); |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * @param cert The certificate for which to modify trust. |
michael@0 | 202 | * @param trustString decoded by CERT_DecodeTrustString. 3 comma separated |
michael@0 | 203 | * characters, indicating SSL, Email, and Obj signing |
michael@0 | 204 | * trust. |
michael@0 | 205 | */ |
michael@0 | 206 | void setCertTrustFromString(in nsIX509Cert3 cert, in string trustString); |
michael@0 | 207 | |
michael@0 | 208 | /** |
michael@0 | 209 | * Query whether a certificate is trusted for a particular use. |
michael@0 | 210 | * |
michael@0 | 211 | * @param cert Obtain the stored trust of this certificate. |
michael@0 | 212 | * @param certType The type of the certificate. See nsIX509Cert. |
michael@0 | 213 | * @param trustType A single bit from the usages constants defined |
michael@0 | 214 | * within this interface. |
michael@0 | 215 | * |
michael@0 | 216 | * @return Returns true if the certificate is trusted for the given use. |
michael@0 | 217 | */ |
michael@0 | 218 | boolean isCertTrusted(in nsIX509Cert cert, |
michael@0 | 219 | in unsigned long certType, |
michael@0 | 220 | in unsigned long trustType); |
michael@0 | 221 | |
michael@0 | 222 | /** |
michael@0 | 223 | * Import certificate(s) from file |
michael@0 | 224 | * |
michael@0 | 225 | * @param aToken Optionally limits the scope of |
michael@0 | 226 | * this function to a token device. |
michael@0 | 227 | * Can be null to mean any token. |
michael@0 | 228 | * @param aFile Identifies a file that contains the certificate |
michael@0 | 229 | * to be imported. |
michael@0 | 230 | * @param aType Describes the type of certificate that is going to |
michael@0 | 231 | * be imported. See type constants in nsIX509Cert. |
michael@0 | 232 | */ |
michael@0 | 233 | void importCertsFromFile(in nsISupports aToken, |
michael@0 | 234 | in nsIFile aFile, |
michael@0 | 235 | in unsigned long aType); |
michael@0 | 236 | |
michael@0 | 237 | /** |
michael@0 | 238 | * Import a PKCS#12 file containing cert(s) and key(s) into the database. |
michael@0 | 239 | * |
michael@0 | 240 | * @param aToken Optionally limits the scope of |
michael@0 | 241 | * this function to a token device. |
michael@0 | 242 | * Can be null to mean any token. |
michael@0 | 243 | * @param aFile Identifies a file that contains the data |
michael@0 | 244 | * to be imported. |
michael@0 | 245 | */ |
michael@0 | 246 | void importPKCS12File(in nsISupports aToken, |
michael@0 | 247 | in nsIFile aFile); |
michael@0 | 248 | |
michael@0 | 249 | /** |
michael@0 | 250 | * Export a set of certs and keys from the database to a PKCS#12 file. |
michael@0 | 251 | * |
michael@0 | 252 | * @param aToken Optionally limits the scope of |
michael@0 | 253 | * this function to a token device. |
michael@0 | 254 | * Can be null to mean any token. |
michael@0 | 255 | * @param aFile Identifies a file that will be filled with the data |
michael@0 | 256 | * to be exported. |
michael@0 | 257 | * @param count The number of certificates to be exported. |
michael@0 | 258 | * @param aCerts The array of all certificates to be exported. |
michael@0 | 259 | */ |
michael@0 | 260 | void exportPKCS12File(in nsISupports aToken, |
michael@0 | 261 | in nsIFile aFile, |
michael@0 | 262 | in unsigned long count, |
michael@0 | 263 | [array, size_is(count)] in nsIX509Cert aCerts); |
michael@0 | 264 | |
michael@0 | 265 | /* |
michael@0 | 266 | * Decode a raw data presentation and instantiate an object in memory. |
michael@0 | 267 | * |
michael@0 | 268 | * @param base64 The raw representation of a certificate, |
michael@0 | 269 | * encoded as Base 64. |
michael@0 | 270 | * @return The new certificate object. |
michael@0 | 271 | */ |
michael@0 | 272 | nsIX509Cert constructX509FromBase64(in string base64); |
michael@0 | 273 | |
michael@0 | 274 | /* |
michael@0 | 275 | * Decode a raw data presentation and instantiate an object in memory. |
michael@0 | 276 | * |
michael@0 | 277 | * @param certDER The raw representation of a certificate, |
michael@0 | 278 | * encoded as raw DER. |
michael@0 | 279 | * @param length The length of the DER string. |
michael@0 | 280 | * @return The new certificate object. |
michael@0 | 281 | */ |
michael@0 | 282 | nsIX509Cert constructX509(in string certDER, in unsigned long length); |
michael@0 | 283 | |
michael@0 | 284 | /* |
michael@0 | 285 | * Obtain a reference to the appropriate service for recent |
michael@0 | 286 | * bad certificates. May only be called on the main thread. |
michael@0 | 287 | * |
michael@0 | 288 | * @param isPrivate True if the service for certs for private connections |
michael@0 | 289 | * is desired, false otherwise. |
michael@0 | 290 | * @return The requested service. |
michael@0 | 291 | */ |
michael@0 | 292 | nsIRecentBadCerts getRecentBadCerts(in boolean isPrivate); |
michael@0 | 293 | |
michael@0 | 294 | /** |
michael@0 | 295 | * Verifies the signature on the given JAR file to verify that it has a |
michael@0 | 296 | * valid signature. To be considered valid, there must be exactly one |
michael@0 | 297 | * signature on the JAR file and that signature must have signed every |
michael@0 | 298 | * entry. Further, the signature must come from a certificate that |
michael@0 | 299 | * is trusted for code signing. |
michael@0 | 300 | * |
michael@0 | 301 | * On success, NS_OK, a nsIZipReader, and the trusted certificate that |
michael@0 | 302 | * signed the JAR are returned. |
michael@0 | 303 | * |
michael@0 | 304 | * On failure, an error code is returned. |
michael@0 | 305 | * |
michael@0 | 306 | * This method returns a nsIZipReader, instead of taking an nsIZipReader |
michael@0 | 307 | * as input, to encourage users of the API to verify the signature as the |
michael@0 | 308 | * first step in opening the JAR. |
michael@0 | 309 | */ |
michael@0 | 310 | const AppTrustedRoot AppMarketplaceProdPublicRoot = 1; |
michael@0 | 311 | const AppTrustedRoot AppMarketplaceProdReviewersRoot = 2; |
michael@0 | 312 | const AppTrustedRoot AppMarketplaceDevPublicRoot = 3; |
michael@0 | 313 | const AppTrustedRoot AppMarketplaceDevReviewersRoot = 4; |
michael@0 | 314 | const AppTrustedRoot AppXPCShellRoot = 5; |
michael@0 | 315 | void openSignedAppFileAsync(in AppTrustedRoot trustedRoot, |
michael@0 | 316 | in nsIFile aJarFile, |
michael@0 | 317 | in nsIOpenSignedAppFileCallback callback); |
michael@0 | 318 | |
michael@0 | 319 | /* |
michael@0 | 320 | * Add a cert to a cert DB from a binary string. |
michael@0 | 321 | * |
michael@0 | 322 | * @param certDER The raw DER encoding of a certificate. |
michael@0 | 323 | * @param aTrust decoded by CERT_DecodeTrustString. 3 comma separated characters, |
michael@0 | 324 | * indicating SSL, Email, and Obj signing trust |
michael@0 | 325 | * @param aName name of the cert for display purposes. |
michael@0 | 326 | */ |
michael@0 | 327 | void addCert(in ACString certDER, in string aTrust, in string aName); |
michael@0 | 328 | |
michael@0 | 329 | // Flags for verifyCertNow (these must match the values in CertVerifier.cpp): |
michael@0 | 330 | // Prevent network traffic. Doesn't work with classic verification. |
michael@0 | 331 | const uint32_t FLAG_LOCAL_ONLY = 1 << 0; |
michael@0 | 332 | // Do not fall back to DV verification after attempting EV validation. |
michael@0 | 333 | // Actually does prevent network traffic, but can cause a valid EV |
michael@0 | 334 | // certificate to not be considered valid. |
michael@0 | 335 | const uint32_t FLAG_MUST_BE_EV = 1 << 1; |
michael@0 | 336 | |
michael@0 | 337 | /** Warning: This interface is inteded to use only for testing only as: |
michael@0 | 338 | * 1. It can create IO on the main thread. |
michael@0 | 339 | * 2. It is in constant change, so in/out can change at any release. |
michael@0 | 340 | * |
michael@0 | 341 | * Obtain the verification result for a cert given a particular usage. |
michael@0 | 342 | * On success, the call returns 0, the chain built during verification, |
michael@0 | 343 | * and whether the cert is good for EV usage. |
michael@0 | 344 | * On failure, the call returns the PRErrorCode for the verification failure |
michael@0 | 345 | * |
michael@0 | 346 | * @param aCert Obtain the stored trust of this certificate |
michael@0 | 347 | * @param aUsage a integer representing the usage from NSS |
michael@0 | 348 | * @param aFlags flags as described above |
michael@0 | 349 | * @param verifedChain chain of verification up to the root if success |
michael@0 | 350 | * @param aHasEVPolicy bool that signified that the cert was an EV cert |
michael@0 | 351 | * @return 0 if success or the value or the error code for the verification |
michael@0 | 352 | * failure |
michael@0 | 353 | */ |
michael@0 | 354 | int32_t /*PRErrorCode*/ |
michael@0 | 355 | verifyCertNow(in nsIX509Cert aCert, |
michael@0 | 356 | in int64_t /*SECCertificateUsage*/ aUsage, |
michael@0 | 357 | in uint32_t aFlags, |
michael@0 | 358 | out nsIX509CertList verifiedChain, |
michael@0 | 359 | out bool aHasEVPolicy); |
michael@0 | 360 | |
michael@0 | 361 | // Clears the OCSP cache for the current certificate verification |
michael@0 | 362 | // implementation. |
michael@0 | 363 | void clearOCSPCache(); |
michael@0 | 364 | }; |