PageRenderTime 36ms CodeModel.GetById 1ms app.highlight 27ms RepoModel.GetById 2ms app.codeStats 0ms

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