Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef _LOWKEYI_H_ |
michael@0 | 6 | #define _LOWKEYI_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "prtypes.h" |
michael@0 | 9 | #include "seccomon.h" |
michael@0 | 10 | #include "secoidt.h" |
michael@0 | 11 | #include "pcertt.h" |
michael@0 | 12 | #include "lowkeyti.h" |
michael@0 | 13 | #include "sdb.h" |
michael@0 | 14 | |
michael@0 | 15 | SEC_BEGIN_PROTOS |
michael@0 | 16 | |
michael@0 | 17 | /* |
michael@0 | 18 | * See bugzilla bug 125359 |
michael@0 | 19 | * Since NSS (via PKCS#11) wants to handle big integers as unsigned ints, |
michael@0 | 20 | * all of the templates above that en/decode into integers must be converted |
michael@0 | 21 | * from ASN.1's signed integer type. This is done by marking either the |
michael@0 | 22 | * source or destination (encoding or decoding, respectively) type as |
michael@0 | 23 | * siUnsignedInteger. |
michael@0 | 24 | */ |
michael@0 | 25 | extern void lg_prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); |
michael@0 | 26 | extern void lg_prepare_low_pqg_params_for_asn1(PQGParams *params); |
michael@0 | 27 | extern void lg_prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); |
michael@0 | 28 | extern void lg_prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); |
michael@0 | 29 | #ifndef NSS_DISABLE_ECC |
michael@0 | 30 | extern void lg_prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); |
michael@0 | 31 | extern void lg_prepare_low_ecparams_for_asn1(ECParams *params); |
michael@0 | 32 | #endif /* NSS_DISABLE_ECC */ |
michael@0 | 33 | |
michael@0 | 34 | typedef char * (* NSSLOWKEYDBNameFunc)(void *arg, int dbVersion); |
michael@0 | 35 | |
michael@0 | 36 | /* |
michael@0 | 37 | ** Open a key database. |
michael@0 | 38 | */ |
michael@0 | 39 | extern NSSLOWKEYDBHandle *nsslowkey_OpenKeyDB(PRBool readOnly, |
michael@0 | 40 | const char *domain, |
michael@0 | 41 | const char *prefix, |
michael@0 | 42 | NSSLOWKEYDBNameFunc namecb, |
michael@0 | 43 | void *cbarg); |
michael@0 | 44 | |
michael@0 | 45 | /* |
michael@0 | 46 | ** Close the specified key database. |
michael@0 | 47 | */ |
michael@0 | 48 | extern void nsslowkey_CloseKeyDB(NSSLOWKEYDBHandle *handle); |
michael@0 | 49 | |
michael@0 | 50 | /* |
michael@0 | 51 | * Get the version number of the database |
michael@0 | 52 | */ |
michael@0 | 53 | extern int nsslowkey_GetKeyDBVersion(NSSLOWKEYDBHandle *handle); |
michael@0 | 54 | |
michael@0 | 55 | /* |
michael@0 | 56 | ** Delete a key from the database |
michael@0 | 57 | */ |
michael@0 | 58 | extern SECStatus nsslowkey_DeleteKey(NSSLOWKEYDBHandle *handle, |
michael@0 | 59 | const SECItem *pubkey); |
michael@0 | 60 | |
michael@0 | 61 | /* |
michael@0 | 62 | ** Store a key in the database, indexed by its public key modulus. |
michael@0 | 63 | ** "pk" is the private key to store |
michael@0 | 64 | ** "f" is the callback function for getting the password |
michael@0 | 65 | ** "arg" is the argument for the callback |
michael@0 | 66 | */ |
michael@0 | 67 | extern SECStatus nsslowkey_StoreKeyByPublicKey(NSSLOWKEYDBHandle *handle, |
michael@0 | 68 | NSSLOWKEYPrivateKey *pk, |
michael@0 | 69 | SECItem *pubKeyData, |
michael@0 | 70 | char *nickname, |
michael@0 | 71 | SDB *sdb); |
michael@0 | 72 | |
michael@0 | 73 | /* does the key for this cert exist in the database filed by modulus */ |
michael@0 | 74 | extern PRBool nsslowkey_KeyForCertExists(NSSLOWKEYDBHandle *handle, |
michael@0 | 75 | NSSLOWCERTCertificate *cert); |
michael@0 | 76 | /* does a key with this ID already exist? */ |
michael@0 | 77 | extern PRBool nsslowkey_KeyForIDExists(NSSLOWKEYDBHandle *handle, SECItem *id); |
michael@0 | 78 | |
michael@0 | 79 | /* |
michael@0 | 80 | ** Destroy a private key object. |
michael@0 | 81 | ** "key" the object |
michael@0 | 82 | ** "freeit" if PR_TRUE then free the object as well as its sub-objects |
michael@0 | 83 | */ |
michael@0 | 84 | extern void lg_nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key); |
michael@0 | 85 | |
michael@0 | 86 | /* |
michael@0 | 87 | ** Destroy a public key object. |
michael@0 | 88 | ** "key" the object |
michael@0 | 89 | ** "freeit" if PR_TRUE then free the object as well as its sub-objects |
michael@0 | 90 | */ |
michael@0 | 91 | extern void lg_nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key); |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | /* |
michael@0 | 95 | ** Convert a low private key "privateKey" into a public low key |
michael@0 | 96 | */ |
michael@0 | 97 | extern NSSLOWKEYPublicKey |
michael@0 | 98 | *lg_nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey); |
michael@0 | 99 | |
michael@0 | 100 | |
michael@0 | 101 | SECStatus |
michael@0 | 102 | nsslowkey_UpdateNickname(NSSLOWKEYDBHandle *handle, |
michael@0 | 103 | NSSLOWKEYPrivateKey *privkey, |
michael@0 | 104 | SECItem *pubKeyData, |
michael@0 | 105 | char *nickname, |
michael@0 | 106 | SDB *sdb); |
michael@0 | 107 | |
michael@0 | 108 | /* Store key by modulus and specify an encryption algorithm to use. |
michael@0 | 109 | * handle is the pointer to the key database, |
michael@0 | 110 | * privkey is the private key to be stored, |
michael@0 | 111 | * f and arg are the function and arguments to the callback |
michael@0 | 112 | * to get a password, |
michael@0 | 113 | * algorithm is the algorithm which the privKey is to be stored. |
michael@0 | 114 | * A return of anything but SECSuccess indicates failure. |
michael@0 | 115 | */ |
michael@0 | 116 | extern SECStatus |
michael@0 | 117 | nsslowkey_StoreKeyByPublicKeyAlg(NSSLOWKEYDBHandle *handle, |
michael@0 | 118 | NSSLOWKEYPrivateKey *privkey, |
michael@0 | 119 | SECItem *pubKeyData, |
michael@0 | 120 | char *nickname, |
michael@0 | 121 | SDB *sdb, |
michael@0 | 122 | PRBool update); |
michael@0 | 123 | |
michael@0 | 124 | /* Find key by modulus. This function is the inverse of store key |
michael@0 | 125 | * by modulus. An attempt to locate the key with "modulus" is |
michael@0 | 126 | * performed. If the key is found, the private key is returned, |
michael@0 | 127 | * else NULL is returned. |
michael@0 | 128 | * modulus is the modulus to locate |
michael@0 | 129 | */ |
michael@0 | 130 | extern NSSLOWKEYPrivateKey * |
michael@0 | 131 | nsslowkey_FindKeyByPublicKey(NSSLOWKEYDBHandle *handle, SECItem *modulus, |
michael@0 | 132 | SDB *sdb); |
michael@0 | 133 | |
michael@0 | 134 | extern char * |
michael@0 | 135 | nsslowkey_FindKeyNicknameByPublicKey(NSSLOWKEYDBHandle *handle, |
michael@0 | 136 | SECItem *modulus, SDB *sdb); |
michael@0 | 137 | |
michael@0 | 138 | #ifndef NSS_DISABLE_ECC |
michael@0 | 139 | /* |
michael@0 | 140 | * smaller version of EC_FillParams. In this code, we only need |
michael@0 | 141 | * oid and DER data. |
michael@0 | 142 | */ |
michael@0 | 143 | SECStatus LGEC_FillParams(PLArenaPool *arena, const SECItem *encodedParams, |
michael@0 | 144 | ECParams *params); |
michael@0 | 145 | |
michael@0 | 146 | /* Copy all of the fields from srcParams into dstParams */ |
michael@0 | 147 | SECStatus LGEC_CopyParams(PLArenaPool *arena, ECParams *dstParams, |
michael@0 | 148 | const ECParams *srcParams); |
michael@0 | 149 | #endif |
michael@0 | 150 | SEC_END_PROTOS |
michael@0 | 151 | |
michael@0 | 152 | #endif /* _LOWKEYI_H_ */ |