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 | /* 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 CKMK_H |
michael@0 | 6 | #define CKMK_H 1 |
michael@0 | 7 | |
michael@0 | 8 | #include <Security/SecKeychainSearch.h> |
michael@0 | 9 | #include <Security/SecKeychainItem.h> |
michael@0 | 10 | #include <Security/SecKeychain.h> |
michael@0 | 11 | #include <Security/cssmtype.h> |
michael@0 | 12 | #include <Security/cssmapi.h> |
michael@0 | 13 | #include <Security/SecKey.h> |
michael@0 | 14 | #include <Security/SecCertificate.h> |
michael@0 | 15 | |
michael@0 | 16 | #define NTO |
michael@0 | 17 | |
michael@0 | 18 | #include "nssckmdt.h" |
michael@0 | 19 | #include "nssckfw.h" |
michael@0 | 20 | /* |
michael@0 | 21 | * I'm including this for access to the arena functions. |
michael@0 | 22 | * Looks like we should publish that API. |
michael@0 | 23 | */ |
michael@0 | 24 | #ifndef BASE_H |
michael@0 | 25 | #include "base.h" |
michael@0 | 26 | #endif /* BASE_H */ |
michael@0 | 27 | /* |
michael@0 | 28 | * This is where the Netscape extensions live, at least for now. |
michael@0 | 29 | */ |
michael@0 | 30 | #ifndef CKT_H |
michael@0 | 31 | #include "ckt.h" |
michael@0 | 32 | #endif /* CKT_H */ |
michael@0 | 33 | |
michael@0 | 34 | /* |
michael@0 | 35 | * statically defined raw objects. Allows us to data description objects |
michael@0 | 36 | * to this PKCS #11 module. |
michael@0 | 37 | */ |
michael@0 | 38 | struct ckmkRawObjectStr { |
michael@0 | 39 | CK_ULONG n; |
michael@0 | 40 | const CK_ATTRIBUTE_TYPE *types; |
michael@0 | 41 | const NSSItem *items; |
michael@0 | 42 | }; |
michael@0 | 43 | typedef struct ckmkRawObjectStr ckmkRawObject; |
michael@0 | 44 | |
michael@0 | 45 | /* |
michael@0 | 46 | * Key/Cert Items |
michael@0 | 47 | */ |
michael@0 | 48 | struct ckmkItemObjectStr { |
michael@0 | 49 | SecKeychainItemRef itemRef; |
michael@0 | 50 | SecItemClass itemClass; |
michael@0 | 51 | PRBool hasID; |
michael@0 | 52 | NSSItem modify; |
michael@0 | 53 | NSSItem private; |
michael@0 | 54 | NSSItem encrypt; |
michael@0 | 55 | NSSItem decrypt; |
michael@0 | 56 | NSSItem derive; |
michael@0 | 57 | NSSItem sign; |
michael@0 | 58 | NSSItem signRecover; |
michael@0 | 59 | NSSItem verify; |
michael@0 | 60 | NSSItem verifyRecover; |
michael@0 | 61 | NSSItem wrap; |
michael@0 | 62 | NSSItem unwrap; |
michael@0 | 63 | NSSItem label; |
michael@0 | 64 | NSSItem subject; |
michael@0 | 65 | NSSItem issuer; |
michael@0 | 66 | NSSItem serial; |
michael@0 | 67 | NSSItem derCert; |
michael@0 | 68 | NSSItem id; |
michael@0 | 69 | NSSItem modulus; |
michael@0 | 70 | NSSItem exponent; |
michael@0 | 71 | NSSItem privateExponent; |
michael@0 | 72 | NSSItem prime1; |
michael@0 | 73 | NSSItem prime2; |
michael@0 | 74 | NSSItem exponent1; |
michael@0 | 75 | NSSItem exponent2; |
michael@0 | 76 | NSSItem coefficient; |
michael@0 | 77 | }; |
michael@0 | 78 | typedef struct ckmkItemObjectStr ckmkItemObject; |
michael@0 | 79 | |
michael@0 | 80 | typedef enum { |
michael@0 | 81 | ckmkRaw, |
michael@0 | 82 | ckmkItem, |
michael@0 | 83 | } ckmkObjectType; |
michael@0 | 84 | |
michael@0 | 85 | /* |
michael@0 | 86 | * all the various types of objects are abstracted away in cobject and |
michael@0 | 87 | * cfind as ckmkInternalObjects. |
michael@0 | 88 | */ |
michael@0 | 89 | struct ckmkInternalObjectStr { |
michael@0 | 90 | ckmkObjectType type; |
michael@0 | 91 | union { |
michael@0 | 92 | ckmkRawObject raw; |
michael@0 | 93 | ckmkItemObject item; |
michael@0 | 94 | } u; |
michael@0 | 95 | CK_OBJECT_CLASS objClass; |
michael@0 | 96 | NSSItem hashKey; |
michael@0 | 97 | unsigned char hashKeyData[128]; |
michael@0 | 98 | NSSCKMDObject mdObject; |
michael@0 | 99 | }; |
michael@0 | 100 | typedef struct ckmkInternalObjectStr ckmkInternalObject; |
michael@0 | 101 | |
michael@0 | 102 | /* our raw object data array */ |
michael@0 | 103 | NSS_EXTERN_DATA ckmkInternalObject nss_ckmk_data[]; |
michael@0 | 104 | NSS_EXTERN_DATA const PRUint32 nss_ckmk_nObjects; |
michael@0 | 105 | |
michael@0 | 106 | NSS_EXTERN_DATA const CK_VERSION nss_ckmk_CryptokiVersion; |
michael@0 | 107 | NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_ManufacturerID; |
michael@0 | 108 | NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_LibraryDescription; |
michael@0 | 109 | NSS_EXTERN_DATA const CK_VERSION nss_ckmk_LibraryVersion; |
michael@0 | 110 | NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_SlotDescription; |
michael@0 | 111 | NSS_EXTERN_DATA const CK_VERSION nss_ckmk_HardwareVersion; |
michael@0 | 112 | NSS_EXTERN_DATA const CK_VERSION nss_ckmk_FirmwareVersion; |
michael@0 | 113 | NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_TokenLabel; |
michael@0 | 114 | NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_TokenModel; |
michael@0 | 115 | NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_TokenSerialNumber; |
michael@0 | 116 | |
michael@0 | 117 | NSS_EXTERN_DATA const NSSCKMDInstance nss_ckmk_mdInstance; |
michael@0 | 118 | NSS_EXTERN_DATA const NSSCKMDSlot nss_ckmk_mdSlot; |
michael@0 | 119 | NSS_EXTERN_DATA const NSSCKMDToken nss_ckmk_mdToken; |
michael@0 | 120 | NSS_EXTERN_DATA const NSSCKMDMechanism nss_ckmk_mdMechanismRSA; |
michael@0 | 121 | |
michael@0 | 122 | NSS_EXTERN NSSCKMDSession * |
michael@0 | 123 | nss_ckmk_CreateSession |
michael@0 | 124 | ( |
michael@0 | 125 | NSSCKFWSession *fwSession, |
michael@0 | 126 | CK_RV *pError |
michael@0 | 127 | ); |
michael@0 | 128 | |
michael@0 | 129 | NSS_EXTERN NSSCKMDFindObjects * |
michael@0 | 130 | nss_ckmk_FindObjectsInit |
michael@0 | 131 | ( |
michael@0 | 132 | NSSCKFWSession *fwSession, |
michael@0 | 133 | CK_ATTRIBUTE_PTR pTemplate, |
michael@0 | 134 | CK_ULONG ulAttributeCount, |
michael@0 | 135 | CK_RV *pError |
michael@0 | 136 | ); |
michael@0 | 137 | |
michael@0 | 138 | /* |
michael@0 | 139 | * Object Utilities |
michael@0 | 140 | */ |
michael@0 | 141 | NSS_EXTERN NSSCKMDObject * |
michael@0 | 142 | nss_ckmk_CreateMDObject |
michael@0 | 143 | ( |
michael@0 | 144 | NSSArena *arena, |
michael@0 | 145 | ckmkInternalObject *io, |
michael@0 | 146 | CK_RV *pError |
michael@0 | 147 | ); |
michael@0 | 148 | |
michael@0 | 149 | NSS_EXTERN NSSCKMDObject * |
michael@0 | 150 | nss_ckmk_CreateObject |
michael@0 | 151 | ( |
michael@0 | 152 | NSSCKFWSession *fwSession, |
michael@0 | 153 | CK_ATTRIBUTE_PTR pTemplate, |
michael@0 | 154 | CK_ULONG ulAttributeCount, |
michael@0 | 155 | CK_RV *pError |
michael@0 | 156 | ); |
michael@0 | 157 | |
michael@0 | 158 | NSS_EXTERN const NSSItem * |
michael@0 | 159 | nss_ckmk_FetchAttribute |
michael@0 | 160 | ( |
michael@0 | 161 | ckmkInternalObject *io, |
michael@0 | 162 | CK_ATTRIBUTE_TYPE type, |
michael@0 | 163 | CK_RV *pError |
michael@0 | 164 | ); |
michael@0 | 165 | |
michael@0 | 166 | NSS_EXTERN void |
michael@0 | 167 | nss_ckmk_DestroyInternalObject |
michael@0 | 168 | ( |
michael@0 | 169 | ckmkInternalObject *io |
michael@0 | 170 | ); |
michael@0 | 171 | |
michael@0 | 172 | unsigned char * |
michael@0 | 173 | nss_ckmk_DERUnwrap |
michael@0 | 174 | ( |
michael@0 | 175 | unsigned char *src, |
michael@0 | 176 | int size, |
michael@0 | 177 | int *outSize, |
michael@0 | 178 | unsigned char **next |
michael@0 | 179 | ); |
michael@0 | 180 | |
michael@0 | 181 | CK_ULONG |
michael@0 | 182 | nss_ckmk_GetULongAttribute |
michael@0 | 183 | ( |
michael@0 | 184 | CK_ATTRIBUTE_TYPE type, |
michael@0 | 185 | CK_ATTRIBUTE *template, |
michael@0 | 186 | CK_ULONG templateSize, |
michael@0 | 187 | CK_RV *pError |
michael@0 | 188 | ); |
michael@0 | 189 | |
michael@0 | 190 | #define NSS_CKMK_ARRAY_SIZE(x) ((sizeof (x))/(sizeof ((x)[0]))) |
michael@0 | 191 | |
michael@0 | 192 | #ifdef DEBUG |
michael@0 | 193 | #define CKMK_MACERR(str,err) cssmPerror(str,err) |
michael@0 | 194 | #else |
michael@0 | 195 | #define CKMK_MACERR(str,err) |
michael@0 | 196 | #endif |
michael@0 | 197 | |
michael@0 | 198 | #endif |