/security/nss/lib/ckfw/nssmkey/ckmk.h

http://github.com/zpao/v8monkey · C Header · 236 lines · 154 code · 23 blank · 59 comment · 0 complexity · 69831427ab069bd5e3a847a4833d2a19 MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Netscape security libraries.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19. * the Initial Developer. All Rights Reserved.
  20. * Portions created by Red Hat, Inc, are Copyright (C) 2005
  21. *
  22. * Contributor(s):
  23. * Bob Relyea (rrelyea@redhat.com)
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. #ifndef CKMK_H
  39. #define CKMK_H 1
  40. #ifdef DEBUG
  41. static const char CKMK_CVS_ID[] = "@(#) $RCSfile: ckmk.h,v $ $Revision: 1.2 $ $Date: 2006/01/26 23:21:39 $";
  42. #endif /* DEBUG */
  43. #include <Security/SecKeychainSearch.h>
  44. #include <Security/SecKeychainItem.h>
  45. #include <Security/SecKeychain.h>
  46. #include <Security/cssmtype.h>
  47. #include <Security/cssmapi.h>
  48. #include <Security/SecKey.h>
  49. #include <Security/SecCertificate.h>
  50. #define NTO
  51. #include "nssckmdt.h"
  52. #include "nssckfw.h"
  53. /*
  54. * I'm including this for access to the arena functions.
  55. * Looks like we should publish that API.
  56. */
  57. #ifndef BASE_H
  58. #include "base.h"
  59. #endif /* BASE_H */
  60. /*
  61. * This is where the Netscape extensions live, at least for now.
  62. */
  63. #ifndef CKT_H
  64. #include "ckt.h"
  65. #endif /* CKT_H */
  66. /*
  67. * statically defined raw objects. Allows us to data description objects
  68. * to this PKCS #11 module.
  69. */
  70. struct ckmkRawObjectStr {
  71. CK_ULONG n;
  72. const CK_ATTRIBUTE_TYPE *types;
  73. const NSSItem *items;
  74. };
  75. typedef struct ckmkRawObjectStr ckmkRawObject;
  76. /*
  77. * Key/Cert Items
  78. */
  79. struct ckmkItemObjectStr {
  80. SecKeychainItemRef itemRef;
  81. SecItemClass itemClass;
  82. PRBool hasID;
  83. NSSItem modify;
  84. NSSItem private;
  85. NSSItem encrypt;
  86. NSSItem decrypt;
  87. NSSItem derive;
  88. NSSItem sign;
  89. NSSItem signRecover;
  90. NSSItem verify;
  91. NSSItem verifyRecover;
  92. NSSItem wrap;
  93. NSSItem unwrap;
  94. NSSItem label;
  95. NSSItem subject;
  96. NSSItem issuer;
  97. NSSItem serial;
  98. NSSItem derCert;
  99. NSSItem id;
  100. NSSItem modulus;
  101. NSSItem exponent;
  102. NSSItem privateExponent;
  103. NSSItem prime1;
  104. NSSItem prime2;
  105. NSSItem exponent1;
  106. NSSItem exponent2;
  107. NSSItem coefficient;
  108. };
  109. typedef struct ckmkItemObjectStr ckmkItemObject;
  110. typedef enum {
  111. ckmkRaw,
  112. ckmkItem,
  113. } ckmkObjectType;
  114. /*
  115. * all the various types of objects are abstracted away in cobject and
  116. * cfind as ckmkInternalObjects.
  117. */
  118. struct ckmkInternalObjectStr {
  119. ckmkObjectType type;
  120. union {
  121. ckmkRawObject raw;
  122. ckmkItemObject item;
  123. } u;
  124. CK_OBJECT_CLASS objClass;
  125. NSSItem hashKey;
  126. unsigned char hashKeyData[128];
  127. NSSCKMDObject mdObject;
  128. };
  129. typedef struct ckmkInternalObjectStr ckmkInternalObject;
  130. /* our raw object data array */
  131. NSS_EXTERN_DATA ckmkInternalObject nss_ckmk_data[];
  132. NSS_EXTERN_DATA const PRUint32 nss_ckmk_nObjects;
  133. NSS_EXTERN_DATA const CK_VERSION nss_ckmk_CryptokiVersion;
  134. NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_ManufacturerID;
  135. NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_LibraryDescription;
  136. NSS_EXTERN_DATA const CK_VERSION nss_ckmk_LibraryVersion;
  137. NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_SlotDescription;
  138. NSS_EXTERN_DATA const CK_VERSION nss_ckmk_HardwareVersion;
  139. NSS_EXTERN_DATA const CK_VERSION nss_ckmk_FirmwareVersion;
  140. NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_TokenLabel;
  141. NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_TokenModel;
  142. NSS_EXTERN_DATA const NSSUTF8 * nss_ckmk_TokenSerialNumber;
  143. NSS_EXTERN_DATA const NSSCKMDInstance nss_ckmk_mdInstance;
  144. NSS_EXTERN_DATA const NSSCKMDSlot nss_ckmk_mdSlot;
  145. NSS_EXTERN_DATA const NSSCKMDToken nss_ckmk_mdToken;
  146. NSS_EXTERN_DATA const NSSCKMDMechanism nss_ckmk_mdMechanismRSA;
  147. NSS_EXTERN NSSCKMDSession *
  148. nss_ckmk_CreateSession
  149. (
  150. NSSCKFWSession *fwSession,
  151. CK_RV *pError
  152. );
  153. NSS_EXTERN NSSCKMDFindObjects *
  154. nss_ckmk_FindObjectsInit
  155. (
  156. NSSCKFWSession *fwSession,
  157. CK_ATTRIBUTE_PTR pTemplate,
  158. CK_ULONG ulAttributeCount,
  159. CK_RV *pError
  160. );
  161. /*
  162. * Object Utilities
  163. */
  164. NSS_EXTERN NSSCKMDObject *
  165. nss_ckmk_CreateMDObject
  166. (
  167. NSSArena *arena,
  168. ckmkInternalObject *io,
  169. CK_RV *pError
  170. );
  171. NSS_EXTERN NSSCKMDObject *
  172. nss_ckmk_CreateObject
  173. (
  174. NSSCKFWSession *fwSession,
  175. CK_ATTRIBUTE_PTR pTemplate,
  176. CK_ULONG ulAttributeCount,
  177. CK_RV *pError
  178. );
  179. NSS_EXTERN const NSSItem *
  180. nss_ckmk_FetchAttribute
  181. (
  182. ckmkInternalObject *io,
  183. CK_ATTRIBUTE_TYPE type,
  184. CK_RV *pError
  185. );
  186. NSS_EXTERN void
  187. nss_ckmk_DestroyInternalObject
  188. (
  189. ckmkInternalObject *io
  190. );
  191. unsigned char *
  192. nss_ckmk_DERUnwrap
  193. (
  194. unsigned char *src,
  195. int size,
  196. int *outSize,
  197. unsigned char **next
  198. );
  199. CK_ULONG
  200. nss_ckmk_GetULongAttribute
  201. (
  202. CK_ATTRIBUTE_TYPE type,
  203. CK_ATTRIBUTE *template,
  204. CK_ULONG templateSize,
  205. CK_RV *pError
  206. );
  207. #define NSS_CKMK_ARRAY_SIZE(x) ((sizeof (x))/(sizeof ((x)[0])))
  208. #ifdef DEBUG
  209. #define CKMK_MACERR(str,err) cssmPerror(str,err)
  210. #else
  211. #define CKMK_MACERR(str,err)
  212. #endif
  213. #endif