From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- security/nss/lib/ckfw/Makefile | 39 + security/nss/lib/ckfw/builtins/Makefile | 54 + security/nss/lib/ckfw/builtins/README | 45 + security/nss/lib/ckfw/builtins/anchor.c | 17 + security/nss/lib/ckfw/builtins/bfind.c | 261 + security/nss/lib/ckfw/builtins/binst.c | 87 + security/nss/lib/ckfw/builtins/bobject.c | 206 + security/nss/lib/ckfw/builtins/bsession.c | 71 + security/nss/lib/ckfw/builtins/bslot.c | 81 + security/nss/lib/ckfw/builtins/btoken.c | 135 + security/nss/lib/ckfw/builtins/builtins.gyp | 61 + security/nss/lib/ckfw/builtins/builtins.h | 66 + security/nss/lib/ckfw/builtins/certdata.perl | 192 + security/nss/lib/ckfw/builtins/certdata.txt | 29506 +++++++++++++++++++++++++ security/nss/lib/ckfw/builtins/ckbiver.c | 18 + security/nss/lib/ckfw/builtins/config.mk | 38 + security/nss/lib/ckfw/builtins/constants.c | 64 + security/nss/lib/ckfw/builtins/exports.gyp | 25 + security/nss/lib/ckfw/builtins/manifest.mn | 30 + security/nss/lib/ckfw/builtins/nssckbi.def | 26 + security/nss/lib/ckfw/builtins/nssckbi.h | 61 + security/nss/lib/ckfw/builtins/nssckbi.rc | 64 + security/nss/lib/ckfw/capi/Makefile | 75 + security/nss/lib/ckfw/capi/README | 7 + security/nss/lib/ckfw/capi/anchor.c | 17 + security/nss/lib/ckfw/capi/cfind.c | 562 + security/nss/lib/ckfw/capi/cinst.c | 97 + security/nss/lib/ckfw/capi/ckcapi.h | 242 + security/nss/lib/ckfw/capi/ckcapiver.c | 17 + security/nss/lib/ckfw/capi/cobject.c | 2226 ++ security/nss/lib/ckfw/capi/config.mk | 31 + security/nss/lib/ckfw/capi/constants.c | 63 + security/nss/lib/ckfw/capi/crsa.c | 687 + security/nss/lib/ckfw/capi/csession.c | 87 + security/nss/lib/ckfw/capi/cslot.c | 81 + security/nss/lib/ckfw/capi/ctoken.c | 184 + security/nss/lib/ckfw/capi/manifest.mn | 33 + security/nss/lib/ckfw/capi/nsscapi.def | 26 + security/nss/lib/ckfw/capi/nsscapi.h | 41 + security/nss/lib/ckfw/capi/nsscapi.rc | 64 + security/nss/lib/ckfw/capi/staticobj.c | 40 + security/nss/lib/ckfw/ck.api | 541 + security/nss/lib/ckfw/ck.h | 88 + security/nss/lib/ckfw/ckapi.perl | 434 + security/nss/lib/ckfw/ckfw.gyp | 34 + security/nss/lib/ckfw/ckfw.h | 2049 ++ security/nss/lib/ckfw/ckfwm.h | 112 + security/nss/lib/ckfw/ckfwtm.h | 23 + security/nss/lib/ckfw/ckmd.h | 28 + security/nss/lib/ckfw/ckt.h | 8 + security/nss/lib/ckfw/config.mk | 25 + security/nss/lib/ckfw/crypto.c | 318 + security/nss/lib/ckfw/dbm/Makefile | 9 + security/nss/lib/ckfw/dbm/anchor.c | 17 + security/nss/lib/ckfw/dbm/ckdbm.h | 210 + security/nss/lib/ckfw/dbm/config.mk | 8 + security/nss/lib/ckfw/dbm/db.c | 1069 + security/nss/lib/ckfw/dbm/find.c | 126 + security/nss/lib/ckfw/dbm/instance.c | 147 + security/nss/lib/ckfw/dbm/manifest.mn | 25 + security/nss/lib/ckfw/dbm/object.c | 155 + security/nss/lib/ckfw/dbm/session.c | 255 + security/nss/lib/ckfw/dbm/slot.c | 165 + security/nss/lib/ckfw/dbm/token.c | 260 + security/nss/lib/ckfw/exports.gyp | 44 + security/nss/lib/ckfw/find.c | 362 + security/nss/lib/ckfw/hash.c | 280 + security/nss/lib/ckfw/instance.c | 1294 ++ security/nss/lib/ckfw/manifest.mn | 53 + security/nss/lib/ckfw/mechanism.c | 1102 + security/nss/lib/ckfw/mutex.c | 248 + security/nss/lib/ckfw/nssck.api | 1854 ++ security/nss/lib/ckfw/nssckepv.h | 10 + security/nss/lib/ckfw/nssckft.h | 11 + security/nss/lib/ckfw/nssckfw.h | 462 + security/nss/lib/ckfw/nssckfwc.h | 879 + security/nss/lib/ckfw/nssckfwt.h | 109 + security/nss/lib/ckfw/nssckg.h | 10 + security/nss/lib/ckfw/nssckmdt.h | 1904 ++ security/nss/lib/ckfw/nssckt.h | 12 + security/nss/lib/ckfw/nssmkey/Makefile | 72 + security/nss/lib/ckfw/nssmkey/README | 21 + security/nss/lib/ckfw/nssmkey/ckmk.h | 182 + security/nss/lib/ckfw/nssmkey/ckmkver.c | 17 + security/nss/lib/ckfw/nssmkey/config.mk | 24 + security/nss/lib/ckfw/nssmkey/manchor.c | 17 + security/nss/lib/ckfw/nssmkey/manifest.mn | 33 + security/nss/lib/ckfw/nssmkey/mconstants.c | 61 + security/nss/lib/ckfw/nssmkey/mfind.c | 352 + security/nss/lib/ckfw/nssmkey/minst.c | 97 + security/nss/lib/ckfw/nssmkey/mobject.c | 1861 ++ security/nss/lib/ckfw/nssmkey/mrsa.c | 479 + security/nss/lib/ckfw/nssmkey/msession.c | 87 + security/nss/lib/ckfw/nssmkey/mslot.c | 81 + security/nss/lib/ckfw/nssmkey/mtoken.c | 184 + security/nss/lib/ckfw/nssmkey/nssmkey.def | 26 + security/nss/lib/ckfw/nssmkey/nssmkey.h | 41 + security/nss/lib/ckfw/nssmkey/staticobj.c | 36 + security/nss/lib/ckfw/object.c | 973 + security/nss/lib/ckfw/session.c | 2390 ++ security/nss/lib/ckfw/sessobj.c | 1012 + security/nss/lib/ckfw/slot.c | 694 + security/nss/lib/ckfw/token.c | 1791 ++ security/nss/lib/ckfw/wrap.c | 5550 +++++ 104 files changed, 66548 insertions(+) create mode 100644 security/nss/lib/ckfw/Makefile create mode 100644 security/nss/lib/ckfw/builtins/Makefile create mode 100644 security/nss/lib/ckfw/builtins/README create mode 100644 security/nss/lib/ckfw/builtins/anchor.c create mode 100644 security/nss/lib/ckfw/builtins/bfind.c create mode 100644 security/nss/lib/ckfw/builtins/binst.c create mode 100644 security/nss/lib/ckfw/builtins/bobject.c create mode 100644 security/nss/lib/ckfw/builtins/bsession.c create mode 100644 security/nss/lib/ckfw/builtins/bslot.c create mode 100644 security/nss/lib/ckfw/builtins/btoken.c create mode 100644 security/nss/lib/ckfw/builtins/builtins.gyp create mode 100644 security/nss/lib/ckfw/builtins/builtins.h create mode 100644 security/nss/lib/ckfw/builtins/certdata.perl create mode 100644 security/nss/lib/ckfw/builtins/certdata.txt create mode 100644 security/nss/lib/ckfw/builtins/ckbiver.c create mode 100644 security/nss/lib/ckfw/builtins/config.mk create mode 100644 security/nss/lib/ckfw/builtins/constants.c create mode 100644 security/nss/lib/ckfw/builtins/exports.gyp create mode 100644 security/nss/lib/ckfw/builtins/manifest.mn create mode 100644 security/nss/lib/ckfw/builtins/nssckbi.def create mode 100644 security/nss/lib/ckfw/builtins/nssckbi.h create mode 100644 security/nss/lib/ckfw/builtins/nssckbi.rc create mode 100644 security/nss/lib/ckfw/capi/Makefile create mode 100644 security/nss/lib/ckfw/capi/README create mode 100644 security/nss/lib/ckfw/capi/anchor.c create mode 100644 security/nss/lib/ckfw/capi/cfind.c create mode 100644 security/nss/lib/ckfw/capi/cinst.c create mode 100644 security/nss/lib/ckfw/capi/ckcapi.h create mode 100644 security/nss/lib/ckfw/capi/ckcapiver.c create mode 100644 security/nss/lib/ckfw/capi/cobject.c create mode 100644 security/nss/lib/ckfw/capi/config.mk create mode 100644 security/nss/lib/ckfw/capi/constants.c create mode 100644 security/nss/lib/ckfw/capi/crsa.c create mode 100644 security/nss/lib/ckfw/capi/csession.c create mode 100644 security/nss/lib/ckfw/capi/cslot.c create mode 100644 security/nss/lib/ckfw/capi/ctoken.c create mode 100644 security/nss/lib/ckfw/capi/manifest.mn create mode 100644 security/nss/lib/ckfw/capi/nsscapi.def create mode 100644 security/nss/lib/ckfw/capi/nsscapi.h create mode 100644 security/nss/lib/ckfw/capi/nsscapi.rc create mode 100644 security/nss/lib/ckfw/capi/staticobj.c create mode 100644 security/nss/lib/ckfw/ck.api create mode 100644 security/nss/lib/ckfw/ck.h create mode 100644 security/nss/lib/ckfw/ckapi.perl create mode 100644 security/nss/lib/ckfw/ckfw.gyp create mode 100644 security/nss/lib/ckfw/ckfw.h create mode 100644 security/nss/lib/ckfw/ckfwm.h create mode 100644 security/nss/lib/ckfw/ckfwtm.h create mode 100644 security/nss/lib/ckfw/ckmd.h create mode 100644 security/nss/lib/ckfw/ckt.h create mode 100644 security/nss/lib/ckfw/config.mk create mode 100644 security/nss/lib/ckfw/crypto.c create mode 100644 security/nss/lib/ckfw/dbm/Makefile create mode 100644 security/nss/lib/ckfw/dbm/anchor.c create mode 100644 security/nss/lib/ckfw/dbm/ckdbm.h create mode 100644 security/nss/lib/ckfw/dbm/config.mk create mode 100644 security/nss/lib/ckfw/dbm/db.c create mode 100644 security/nss/lib/ckfw/dbm/find.c create mode 100644 security/nss/lib/ckfw/dbm/instance.c create mode 100644 security/nss/lib/ckfw/dbm/manifest.mn create mode 100644 security/nss/lib/ckfw/dbm/object.c create mode 100644 security/nss/lib/ckfw/dbm/session.c create mode 100644 security/nss/lib/ckfw/dbm/slot.c create mode 100644 security/nss/lib/ckfw/dbm/token.c create mode 100644 security/nss/lib/ckfw/exports.gyp create mode 100644 security/nss/lib/ckfw/find.c create mode 100644 security/nss/lib/ckfw/hash.c create mode 100644 security/nss/lib/ckfw/instance.c create mode 100644 security/nss/lib/ckfw/manifest.mn create mode 100644 security/nss/lib/ckfw/mechanism.c create mode 100644 security/nss/lib/ckfw/mutex.c create mode 100644 security/nss/lib/ckfw/nssck.api create mode 100644 security/nss/lib/ckfw/nssckepv.h create mode 100644 security/nss/lib/ckfw/nssckft.h create mode 100644 security/nss/lib/ckfw/nssckfw.h create mode 100644 security/nss/lib/ckfw/nssckfwc.h create mode 100644 security/nss/lib/ckfw/nssckfwt.h create mode 100644 security/nss/lib/ckfw/nssckg.h create mode 100644 security/nss/lib/ckfw/nssckmdt.h create mode 100644 security/nss/lib/ckfw/nssckt.h create mode 100644 security/nss/lib/ckfw/nssmkey/Makefile create mode 100644 security/nss/lib/ckfw/nssmkey/README create mode 100644 security/nss/lib/ckfw/nssmkey/ckmk.h create mode 100644 security/nss/lib/ckfw/nssmkey/ckmkver.c create mode 100644 security/nss/lib/ckfw/nssmkey/config.mk create mode 100644 security/nss/lib/ckfw/nssmkey/manchor.c create mode 100644 security/nss/lib/ckfw/nssmkey/manifest.mn create mode 100644 security/nss/lib/ckfw/nssmkey/mconstants.c create mode 100644 security/nss/lib/ckfw/nssmkey/mfind.c create mode 100644 security/nss/lib/ckfw/nssmkey/minst.c create mode 100644 security/nss/lib/ckfw/nssmkey/mobject.c create mode 100644 security/nss/lib/ckfw/nssmkey/mrsa.c create mode 100644 security/nss/lib/ckfw/nssmkey/msession.c create mode 100644 security/nss/lib/ckfw/nssmkey/mslot.c create mode 100644 security/nss/lib/ckfw/nssmkey/mtoken.c create mode 100644 security/nss/lib/ckfw/nssmkey/nssmkey.def create mode 100644 security/nss/lib/ckfw/nssmkey/nssmkey.h create mode 100644 security/nss/lib/ckfw/nssmkey/staticobj.c create mode 100644 security/nss/lib/ckfw/object.c create mode 100644 security/nss/lib/ckfw/session.c create mode 100644 security/nss/lib/ckfw/sessobj.c create mode 100644 security/nss/lib/ckfw/slot.c create mode 100644 security/nss/lib/ckfw/token.c create mode 100644 security/nss/lib/ckfw/wrap.c (limited to 'security/nss/lib/ckfw') diff --git a/security/nss/lib/ckfw/Makefile b/security/nss/lib/ckfw/Makefile new file mode 100644 index 000000000..484dbb511 --- /dev/null +++ b/security/nss/lib/ckfw/Makefile @@ -0,0 +1,39 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +include manifest.mn +include $(CORE_DEPTH)/coreconf/config.mk +include config.mk +include $(CORE_DEPTH)/coreconf/rules.mk + +ifdef NOTDEF # was ifdef MOZILLA_CLIENT +NSS_BUILD_CAPI = 1 +endif + +# This'll need some help from a build person. + +# The generated files are checked in, and differ from what ckapi.perl +# will produce. ckapi.perl is currently newer than the targets, so +# these rules are invoked, causing the wrong files to be generated. +# Turning off to fix builds. +# +# nssckepv.h: ck.api ckapi.perl +# nssckft.h: ck.api ckapi.perl +# nssckg.h: ck.api ckapi.perl +# nssck.api: ck.api ckapi.perl +# $(PERL) ckapi.perl ck.api + +export:: private_export + +# can't do this in manifest.mn because OS_TARGET isn't defined there. +ifeq (,$(filter-out WINNT WIN95,$(OS_TARGET))) +ifdef NSS_BUILD_CAPI +DIRS += capi +endif +endif + +#ifeq ($(OS_ARCH), Darwin) +#DIRS += nssmkey +#endif diff --git a/security/nss/lib/ckfw/builtins/Makefile b/security/nss/lib/ckfw/builtins/Makefile new file mode 100644 index 000000000..22726e286 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/Makefile @@ -0,0 +1,54 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +include manifest.mn +include $(CORE_DEPTH)/coreconf/config.mk +include config.mk + +EXTRA_LIBS = \ + $(DIST)/lib/$(LIB_PREFIX)nssckfw.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)nssb.$(LIB_SUFFIX) \ + $(NULL) + +# can't do this in manifest.mn because OS_TARGET isn't defined there. +ifeq (,$(filter-out WIN%,$(OS_TARGET))) + +ifdef NS_USE_GCC +EXTRA_SHARED_LIBS += \ + -L$(NSPR_LIB_DIR) \ + -lplc4 \ + -lplds4 \ + -lnspr4 \ + $(NULL) +else +EXTRA_SHARED_LIBS += \ + $(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plc4.lib \ + $(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plds4.lib \ + $(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)nspr4.lib \ + $(NULL) +endif # NS_USE_GCC +else + +EXTRA_SHARED_LIBS += \ + -L$(NSPR_LIB_DIR) \ + -lplc4 \ + -lplds4 \ + -lnspr4 \ + $(NULL) +endif + + +include $(CORE_DEPTH)/coreconf/rules.mk + +# Generate certdata.c. + +# By default, use the unmodified certdata.txt. +ifndef NSS_CERTDATA_TXT +NSS_CERTDATA_TXT = certdata.txt +endif + +$(OBJDIR)/certdata.c: $(NSS_CERTDATA_TXT) certdata.perl + @$(MAKE_OBJDIR) + $(PERL) certdata.perl $(NSS_CERTDATA_TXT) $@ diff --git a/security/nss/lib/ckfw/builtins/README b/security/nss/lib/ckfw/builtins/README new file mode 100644 index 000000000..fc0393c38 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/README @@ -0,0 +1,45 @@ +This README file explains how to add a builtin root CA certificate to NSS +or remove a builtin root CA certificate from NSS. + +The builtin root CA certificates in NSS are stored in the nssckbi PKCS #11 +module. The sources to the nssckbi module are in this directory. + +I. Adding a Builtin Root CA Certificate + +You need to use the addbuiltin command-line tool to add a root CA certificate +to the nssckbi module. In the procedure described below, we assume that the +new root CA certificate is distributed in DER format in the file newroot.der. + +1. Add the directory where the addbuiltin executable resides to your PATH +environment variable. Then, add the directory where the NSPR and NSS shared +libraries (DLLs) reside to the platform-specific environment variable that +specifies your shared library search path: LD_LIBRARY_PATH (most Unix +variants), SHLIB_PATH (32-bit HP-UX), LIBPATH (AIX), or PATH (Windows). + +2. Copy newroot.der to this directory. + +3. In this directory, run addbuiltin to add the new root certificate. The +argument to the -n option should be replaced by the nickname of the root +certificate. + + % addbuiltin -n "Nickname of the Root Certificate" -t C,C,C < newroot.der >> certdata.txt + +4. Edit nssckbi.h to bump the version of the module. + +5. Run gmake in this directory to build the nssckbi module. + +6. After you verify that the new nssckbi module is correct, check in +certdata.txt and nssckbi.h. + +II. Removing a Builtin Root CA Certificate + +1. Change directory to this directory. + +2. Edit certdata.txt and remove the root CA certificate. + +3. Edit nssckbi.h to bump the version of the module. + +4. Run gmake in this directory to build the nssckbi module. + +5. After you verify that the new nssckbi module is correct, check in +certdata.txt and nssckbi.h. diff --git a/security/nss/lib/ckfw/builtins/anchor.c b/security/nss/lib/ckfw/builtins/anchor.c new file mode 100644 index 000000000..af21c6a0b --- /dev/null +++ b/security/nss/lib/ckfw/builtins/anchor.c @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * builtins/anchor.c + * + * This file "anchors" the actual cryptoki entry points in this module's + * shared library, which is required for dynamic loading. See the + * comments in nssck.api for more information. + */ + +#include "builtins.h" + +#define MODULE_NAME builtins +#define INSTANCE_NAME (NSSCKMDInstance *)&nss_builtins_mdInstance +#include "nssck.api" diff --git a/security/nss/lib/ckfw/builtins/bfind.c b/security/nss/lib/ckfw/builtins/bfind.c new file mode 100644 index 000000000..3e5da1a55 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/bfind.c @@ -0,0 +1,261 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BUILTINS_H +#include "builtins.h" +#endif /* BUILTINS_H */ + +/* + * builtins/find.c + * + * This file implements the NSSCKMDFindObjects object for the + * "builtin objects" cryptoki module. + */ + +struct builtinsFOStr { + NSSArena *arena; + CK_ULONG n; + CK_ULONG i; + builtinsInternalObject **objs; +}; + +static void +builtins_mdFindObjects_Final( + NSSCKMDFindObjects *mdFindObjects, + NSSCKFWFindObjects *fwFindObjects, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + struct builtinsFOStr *fo = (struct builtinsFOStr *)mdFindObjects->etc; + NSSArena *arena = fo->arena; + + nss_ZFreeIf(fo->objs); + nss_ZFreeIf(fo); + nss_ZFreeIf(mdFindObjects); + if ((NSSArena *)NULL != arena) { + NSSArena_Destroy(arena); + } + + return; +} + +static NSSCKMDObject * +builtins_mdFindObjects_Next( + NSSCKMDFindObjects *mdFindObjects, + NSSCKFWFindObjects *fwFindObjects, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + NSSArena *arena, + CK_RV *pError) +{ + struct builtinsFOStr *fo = (struct builtinsFOStr *)mdFindObjects->etc; + builtinsInternalObject *io; + + if (fo->i == fo->n) { + *pError = CKR_OK; + return (NSSCKMDObject *)NULL; + } + + io = fo->objs[fo->i]; + fo->i++; + + return nss_builtins_CreateMDObject(arena, io, pError); +} + +static int +builtins_derUnwrapInt(unsigned char *src, int size, unsigned char **dest) +{ + unsigned char *start = src; + int len = 0; + + if (*src++ != 2) { + return 0; + } + len = *src++; + if (len & 0x80) { + int count = len & 0x7f; + len = 0; + + if (count + 2 > size) { + return 0; + } + while (count-- > 0) { + len = (len << 8) | *src++; + } + } + if (len + (src - start) != size) { + return 0; + } + *dest = src; + return len; +} + +static CK_BBOOL +builtins_attrmatch( + CK_ATTRIBUTE_PTR a, + const NSSItem *b) +{ + PRBool prb; + + if (a->ulValueLen != b->size) { + /* match a decoded serial number */ + if ((a->type == CKA_SERIAL_NUMBER) && (a->ulValueLen < b->size)) { + int len; + unsigned char *data = NULL; + + len = builtins_derUnwrapInt(b->data, b->size, &data); + if (data && + (len == a->ulValueLen) && + nsslibc_memequal(a->pValue, data, len, (PRStatus *)NULL)) { + return CK_TRUE; + } + } + return CK_FALSE; + } + + prb = nsslibc_memequal(a->pValue, b->data, b->size, (PRStatus *)NULL); + + if (PR_TRUE == prb) { + return CK_TRUE; + } else { + return CK_FALSE; + } +} + +static CK_BBOOL +builtins_match( + CK_ATTRIBUTE_PTR pTemplate, + CK_ULONG ulAttributeCount, + builtinsInternalObject *o) +{ + CK_ULONG i; + + for (i = 0; i < ulAttributeCount; i++) { + CK_ULONG j; + + for (j = 0; j < o->n; j++) { + if (o->types[j] == pTemplate[i].type) { + if (CK_FALSE == builtins_attrmatch(&pTemplate[i], &o->items[j])) { + return CK_FALSE; + } else { + break; + } + } + } + + if (j == o->n) { + /* Loop ran to the end: no matching attribute */ + return CK_FALSE; + } + } + + /* Every attribute passed */ + return CK_TRUE; +} + +NSS_IMPLEMENT NSSCKMDFindObjects * +nss_builtins_FindObjectsInit( + NSSCKFWSession *fwSession, + CK_ATTRIBUTE_PTR pTemplate, + CK_ULONG ulAttributeCount, + CK_RV *pError) +{ + /* This could be made more efficient. I'm rather rushed. */ + NSSArena *arena; + NSSCKMDFindObjects *rv = (NSSCKMDFindObjects *)NULL; + struct builtinsFOStr *fo = (struct builtinsFOStr *)NULL; + +/* + * 99% of the time we get 0 or 1 matches. So we start with a small + * stack-allocated array to hold the matches and switch to a heap-allocated + * array later if the number of matches exceeds STACK_BUF_LENGTH. + */ +#define STACK_BUF_LENGTH 1 + builtinsInternalObject *stackTemp[STACK_BUF_LENGTH]; + builtinsInternalObject **temp = stackTemp; + PRBool tempIsHeapAllocated = PR_FALSE; + PRUint32 i; + + arena = NSSArena_Create(); + if ((NSSArena *)NULL == arena) { + goto loser; + } + + rv = nss_ZNEW(arena, NSSCKMDFindObjects); + if ((NSSCKMDFindObjects *)NULL == rv) { + *pError = CKR_HOST_MEMORY; + goto loser; + } + + fo = nss_ZNEW(arena, struct builtinsFOStr); + if ((struct builtinsFOStr *)NULL == fo) { + *pError = CKR_HOST_MEMORY; + goto loser; + } + + fo->arena = arena; + /* fo->n and fo->i are already zero */ + + rv->etc = (void *)fo; + rv->Final = builtins_mdFindObjects_Final; + rv->Next = builtins_mdFindObjects_Next; + rv->null = (void *)NULL; + + for (i = 0; i < nss_builtins_nObjects; i++) { + builtinsInternalObject *o = (builtinsInternalObject *)&nss_builtins_data[i]; + + if (CK_TRUE == builtins_match(pTemplate, ulAttributeCount, o)) { + if (fo->n == STACK_BUF_LENGTH) { + /* Switch from the small stack array to a heap-allocated array large + * enough to handle matches in all remaining cases. */ + temp = nss_ZNEWARRAY((NSSArena *)NULL, builtinsInternalObject *, + fo->n + nss_builtins_nObjects - i); + if ((builtinsInternalObject **)NULL == temp) { + *pError = + CKR_HOST_MEMORY; + goto loser; + } + tempIsHeapAllocated = PR_TRUE; + (void)nsslibc_memcpy(temp, stackTemp, + sizeof(builtinsInternalObject *) * fo->n); + } + + temp[fo->n] = o; + fo->n++; + } + } + + fo->objs = nss_ZNEWARRAY(arena, builtinsInternalObject *, fo->n); + if ((builtinsInternalObject **)NULL == fo->objs) { + *pError = CKR_HOST_MEMORY; + goto loser; + } + + (void)nsslibc_memcpy(fo->objs, temp, sizeof(builtinsInternalObject *) * fo->n); + if (tempIsHeapAllocated) { + nss_ZFreeIf(temp); + temp = (builtinsInternalObject **)NULL; + } + + return rv; + +loser: + if (tempIsHeapAllocated) { + nss_ZFreeIf(temp); + } + nss_ZFreeIf(fo); + nss_ZFreeIf(rv); + if ((NSSArena *)NULL != arena) { + NSSArena_Destroy(arena); + } + return (NSSCKMDFindObjects *)NULL; +} diff --git a/security/nss/lib/ckfw/builtins/binst.c b/security/nss/lib/ckfw/builtins/binst.c new file mode 100644 index 000000000..ca1dac89c --- /dev/null +++ b/security/nss/lib/ckfw/builtins/binst.c @@ -0,0 +1,87 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "builtins.h" + +/* + * builtins/instance.c + * + * This file implements the NSSCKMDInstance object for the + * "builtin objects" cryptoki module. + */ + +/* + * NSSCKMDInstance methods + */ + +static CK_ULONG +builtins_mdInstance_GetNSlots( + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (CK_ULONG)1; +} + +static CK_VERSION +builtins_mdInstance_GetCryptokiVersion( + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return nss_builtins_CryptokiVersion; +} + +static NSSUTF8 * +builtins_mdInstance_GetManufacturerID( + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_ManufacturerID; +} + +static NSSUTF8 * +builtins_mdInstance_GetLibraryDescription( + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_LibraryDescription; +} + +static CK_VERSION +builtins_mdInstance_GetLibraryVersion( + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ +#define NSS_VERSION_VARIABLE __nss_builtins_version +#include "verref.h" + return nss_builtins_LibraryVersion; +} + +static CK_RV +builtins_mdInstance_GetSlots( + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + NSSCKMDSlot *slots[]) +{ + slots[0] = (NSSCKMDSlot *)&nss_builtins_mdSlot; + return CKR_OK; +} + +const NSSCKMDInstance + nss_builtins_mdInstance = { + (void *)NULL, /* etc */ + NULL, /* Initialize */ + NULL, /* Finalize */ + builtins_mdInstance_GetNSlots, + builtins_mdInstance_GetCryptokiVersion, + builtins_mdInstance_GetManufacturerID, + builtins_mdInstance_GetLibraryDescription, + builtins_mdInstance_GetLibraryVersion, + NULL, /* ModuleHandlesSessionObjects -- defaults to false */ + builtins_mdInstance_GetSlots, + NULL, /* WaitForSlotEvent */ + (void *)NULL /* null terminator */ + }; diff --git a/security/nss/lib/ckfw/builtins/bobject.c b/security/nss/lib/ckfw/builtins/bobject.c new file mode 100644 index 000000000..1c0babdd6 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/bobject.c @@ -0,0 +1,206 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "builtins.h" + +/* + * builtins/object.c + * + * This file implements the NSSCKMDObject object for the + * "builtin objects" cryptoki module. + */ + +/* + * Finalize - unneeded + * Destroy - CKR_SESSION_READ_ONLY + * IsTokenObject - CK_TRUE + * GetAttributeCount + * GetAttributeTypes + * GetAttributeSize + * GetAttribute + * SetAttribute - unneeded + * GetObjectSize + */ + +static CK_RV +builtins_mdObject_Destroy( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return CKR_SESSION_READ_ONLY; +} + +static CK_BBOOL +builtins_mdObject_IsTokenObject( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return CK_TRUE; +} + +static CK_ULONG +builtins_mdObject_GetAttributeCount( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + builtinsInternalObject *io = (builtinsInternalObject *)mdObject->etc; + return io->n; +} + +static CK_RV +builtins_mdObject_GetAttributeTypes( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_ATTRIBUTE_TYPE_PTR typeArray, + CK_ULONG ulCount) +{ + builtinsInternalObject *io = (builtinsInternalObject *)mdObject->etc; + CK_ULONG i; + + if (io->n != ulCount) { + return CKR_BUFFER_TOO_SMALL; + } + + for (i = 0; i < io->n; i++) { + typeArray[i] = io->types[i]; + } + + return CKR_OK; +} + +static CK_ULONG +builtins_mdObject_GetAttributeSize( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_ATTRIBUTE_TYPE attribute, + CK_RV *pError) +{ + builtinsInternalObject *io = (builtinsInternalObject *)mdObject->etc; + CK_ULONG i; + + for (i = 0; i < io->n; i++) { + if (attribute == io->types[i]) { + return (CK_ULONG)(io->items[i].size); + } + } + + *pError = CKR_ATTRIBUTE_TYPE_INVALID; + return 0; +} + +static NSSCKFWItem +builtins_mdObject_GetAttribute( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_ATTRIBUTE_TYPE attribute, + CK_RV *pError) +{ + NSSCKFWItem mdItem; + builtinsInternalObject *io = (builtinsInternalObject *)mdObject->etc; + CK_ULONG i; + + mdItem.needsFreeing = PR_FALSE; + mdItem.item = (NSSItem *)NULL; + + for (i = 0; i < io->n; i++) { + if (attribute == io->types[i]) { + mdItem.item = (NSSItem *)&io->items[i]; + return mdItem; + } + } + + *pError = CKR_ATTRIBUTE_TYPE_INVALID; + return mdItem; +} + +static CK_ULONG +builtins_mdObject_GetObjectSize( + NSSCKMDObject *mdObject, + NSSCKFWObject *fwObject, + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + builtinsInternalObject *io = (builtinsInternalObject *)mdObject->etc; + CK_ULONG i; + CK_ULONG rv = sizeof(CK_ULONG); + + for (i = 0; i < io->n; i++) { + rv += sizeof(CK_ATTRIBUTE_TYPE) + sizeof(NSSItem) + io->items[i].size; + } + + return rv; +} + +static const NSSCKMDObject + builtins_prototype_mdObject = { + (void *)NULL, /* etc */ + NULL, /* Finalize */ + builtins_mdObject_Destroy, + builtins_mdObject_IsTokenObject, + builtins_mdObject_GetAttributeCount, + builtins_mdObject_GetAttributeTypes, + builtins_mdObject_GetAttributeSize, + builtins_mdObject_GetAttribute, + NULL, /* FreeAttribute */ + NULL, /* SetAttribute */ + builtins_mdObject_GetObjectSize, + (void *)NULL /* null terminator */ + }; + +NSS_IMPLEMENT NSSCKMDObject * +nss_builtins_CreateMDObject( + NSSArena *arena, + builtinsInternalObject *io, + CK_RV *pError) +{ + if ((void *)NULL == io->mdObject.etc) { + (void)nsslibc_memcpy(&io->mdObject, &builtins_prototype_mdObject, + sizeof(builtins_prototype_mdObject)); + io->mdObject.etc = (void *)io; + } + + return &io->mdObject; +} diff --git a/security/nss/lib/ckfw/builtins/bsession.c b/security/nss/lib/ckfw/builtins/bsession.c new file mode 100644 index 000000000..6828a49af --- /dev/null +++ b/security/nss/lib/ckfw/builtins/bsession.c @@ -0,0 +1,71 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "builtins.h" + +/* + * builtins/session.c + * + * This file implements the NSSCKMDSession object for the + * "builtin objects" cryptoki module. + */ + +static NSSCKMDFindObjects * +builtins_mdSession_FindObjectsInit( + NSSCKMDSession *mdSession, + NSSCKFWSession *fwSession, + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_ATTRIBUTE_PTR pTemplate, + CK_ULONG ulAttributeCount, + CK_RV *pError) +{ + return nss_builtins_FindObjectsInit(fwSession, pTemplate, ulAttributeCount, pError); +} + +NSS_IMPLEMENT NSSCKMDSession * +nss_builtins_CreateSession( + NSSCKFWSession *fwSession, + CK_RV *pError) +{ + NSSArena *arena; + NSSCKMDSession *rv; + + arena = NSSCKFWSession_GetArena(fwSession, pError); + if ((NSSArena *)NULL == arena) { + return (NSSCKMDSession *)NULL; + } + + rv = nss_ZNEW(arena, NSSCKMDSession); + if ((NSSCKMDSession *)NULL == rv) { + *pError = CKR_HOST_MEMORY; + return (NSSCKMDSession *)NULL; + } + + /* + * rv was zeroed when allocated, so we only + * need to set the non-zero members. + */ + + rv->etc = (void *)fwSession; + /* rv->Close */ + /* rv->GetDeviceError */ + /* rv->Login */ + /* rv->Logout */ + /* rv->InitPIN */ + /* rv->SetPIN */ + /* rv->GetOperationStateLen */ + /* rv->GetOperationState */ + /* rv->SetOperationState */ + /* rv->CreateObject */ + /* rv->CopyObject */ + rv->FindObjectsInit = builtins_mdSession_FindObjectsInit; + /* rv->SeedRandom */ + /* rv->GetRandom */ + /* rv->null */ + + return rv; +} diff --git a/security/nss/lib/ckfw/builtins/bslot.c b/security/nss/lib/ckfw/builtins/bslot.c new file mode 100644 index 000000000..f2ef1efb9 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/bslot.c @@ -0,0 +1,81 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "builtins.h" + +/* + * builtins/slot.c + * + * This file implements the NSSCKMDSlot object for the + * "builtin objects" cryptoki module. + */ + +static NSSUTF8 * +builtins_mdSlot_GetSlotDescription( + NSSCKMDSlot *mdSlot, + NSSCKFWSlot *fwSlot, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_SlotDescription; +} + +static NSSUTF8 * +builtins_mdSlot_GetManufacturerID( + NSSCKMDSlot *mdSlot, + NSSCKFWSlot *fwSlot, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_ManufacturerID; +} + +static CK_VERSION +builtins_mdSlot_GetHardwareVersion( + NSSCKMDSlot *mdSlot, + NSSCKFWSlot *fwSlot, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return nss_builtins_HardwareVersion; +} + +static CK_VERSION +builtins_mdSlot_GetFirmwareVersion( + NSSCKMDSlot *mdSlot, + NSSCKFWSlot *fwSlot, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return nss_builtins_FirmwareVersion; +} + +static NSSCKMDToken * +builtins_mdSlot_GetToken( + NSSCKMDSlot *mdSlot, + NSSCKFWSlot *fwSlot, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSCKMDToken *)&nss_builtins_mdToken; +} + +const NSSCKMDSlot + nss_builtins_mdSlot = { + (void *)NULL, /* etc */ + NULL, /* Initialize */ + NULL, /* Destroy */ + builtins_mdSlot_GetSlotDescription, + builtins_mdSlot_GetManufacturerID, + NULL, /* GetTokenPresent -- defaults to true */ + NULL, /* GetRemovableDevice -- defaults to false */ + NULL, /* GetHardwareSlot -- defaults to false */ + builtins_mdSlot_GetHardwareVersion, + builtins_mdSlot_GetFirmwareVersion, + builtins_mdSlot_GetToken, + (void *)NULL /* null terminator */ + }; diff --git a/security/nss/lib/ckfw/builtins/btoken.c b/security/nss/lib/ckfw/builtins/btoken.c new file mode 100644 index 000000000..ae1e1380b --- /dev/null +++ b/security/nss/lib/ckfw/builtins/btoken.c @@ -0,0 +1,135 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "builtins.h" + +/* + * builtins/token.c + * + * This file implements the NSSCKMDToken object for the + * "builtin objects" cryptoki module. + */ + +static NSSUTF8 * +builtins_mdToken_GetLabel( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_TokenLabel; +} + +static NSSUTF8 * +builtins_mdToken_GetManufacturerID( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_ManufacturerID; +} + +static NSSUTF8 * +builtins_mdToken_GetModel( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_TokenModel; +} + +static NSSUTF8 * +builtins_mdToken_GetSerialNumber( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + CK_RV *pError) +{ + return (NSSUTF8 *)nss_builtins_TokenSerialNumber; +} + +static CK_BBOOL +builtins_mdToken_GetIsWriteProtected( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return CK_TRUE; +} + +static CK_VERSION +builtins_mdToken_GetHardwareVersion( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return nss_builtins_HardwareVersion; +} + +static CK_VERSION +builtins_mdToken_GetFirmwareVersion( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance) +{ + return nss_builtins_FirmwareVersion; +} + +static NSSCKMDSession * +builtins_mdToken_OpenSession( + NSSCKMDToken *mdToken, + NSSCKFWToken *fwToken, + NSSCKMDInstance *mdInstance, + NSSCKFWInstance *fwInstance, + NSSCKFWSession *fwSession, + CK_BBOOL rw, + CK_RV *pError) +{ + return nss_builtins_CreateSession(fwSession, pError); +} + +const NSSCKMDToken + nss_builtins_mdToken = { + (void *)NULL, /* etc */ + NULL, /* Setup */ + NULL, /* Invalidate */ + NULL, /* InitToken -- default errs */ + builtins_mdToken_GetLabel, + builtins_mdToken_GetManufacturerID, + builtins_mdToken_GetModel, + builtins_mdToken_GetSerialNumber, + NULL, /* GetHasRNG -- default is false */ + builtins_mdToken_GetIsWriteProtected, + NULL, /* GetLoginRequired -- default is false */ + NULL, /* GetUserPinInitialized -- default is false */ + NULL, /* GetRestoreKeyNotNeeded -- irrelevant */ + NULL, /* GetHasClockOnToken -- default is false */ + NULL, /* GetHasProtectedAuthenticationPath -- default is false */ + NULL, /* GetSupportsDualCryptoOperations -- default is false */ + NULL, /* GetMaxSessionCount -- default is CK_UNAVAILABLE_INFORMATION */ + NULL, /* GetMaxRwSessionCount -- default is CK_UNAVAILABLE_INFORMATION */ + NULL, /* GetMaxPinLen -- irrelevant */ + NULL, /* GetMinPinLen -- irrelevant */ + NULL, /* GetTotalPublicMemory -- default is CK_UNAVAILABLE_INFORMATION */ + NULL, /* GetFreePublicMemory -- default is CK_UNAVAILABLE_INFORMATION */ + NULL, /* GetTotalPrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */ + NULL, /* GetFreePrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */ + builtins_mdToken_GetHardwareVersion, + builtins_mdToken_GetFirmwareVersion, + NULL, /* GetUTCTime -- no clock */ + builtins_mdToken_OpenSession, + NULL, /* GetMechanismCount -- default is zero */ + NULL, /* GetMechanismTypes -- irrelevant */ + NULL, /* GetMechanism -- irrelevant */ + (void *)NULL /* null terminator */ + }; diff --git a/security/nss/lib/ckfw/builtins/builtins.gyp b/security/nss/lib/ckfw/builtins/builtins.gyp new file mode 100644 index 000000000..d85442585 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/builtins.gyp @@ -0,0 +1,61 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +{ + 'includes': [ + '../../../coreconf/config.gypi' + ], + 'targets': [ + { + 'target_name': 'nssckbi', + 'type': 'shared_library', + 'sources': [ + 'anchor.c', + 'bfind.c', + 'binst.c', + 'bobject.c', + 'bsession.c', + 'bslot.c', + 'btoken.c', + 'ckbiver.c', + 'constants.c', + '<(INTERMEDIATE_DIR)/certdata.c' + ], + 'dependencies': [ + '<(DEPTH)/exports.gyp:nss_exports', + '<(DEPTH)/lib/ckfw/ckfw.gyp:nssckfw', + '<(DEPTH)/lib/base/base.gyp:nssb' + ], + 'actions': [ + { + 'msvs_cygwin_shell': 0, + 'action': [ + 'perl', + 'certdata.perl', + 'certdata.txt', + '<@(_outputs)', + ], + 'inputs': [ + 'certdata.perl', + 'certdata.txt' + ], + 'outputs': [ + '<(INTERMEDIATE_DIR)/certdata.c' + ], + 'action_name': 'generate_certdata_c' + } + ], + 'variables': { + 'mapfile': 'nssckbi.def' + } + } + ], + 'target_defaults': { + 'include_dirs': [ + '.' + ] + }, + 'variables': { + 'module': 'nss', + } +} diff --git a/security/nss/lib/ckfw/builtins/builtins.h b/security/nss/lib/ckfw/builtins/builtins.h new file mode 100644 index 000000000..a1693c29c --- /dev/null +++ b/security/nss/lib/ckfw/builtins/builtins.h @@ -0,0 +1,66 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nssckmdt.h" +#include "nssckfw.h" + +/* + * I'm including this for access to the arena functions. + * Looks like we should publish that API. + */ +#ifndef BASE_H +#include "base.h" +#endif /* BASE_H */ + +/* + * This is where the Netscape extensions live, at least for now. + */ +#ifndef CKT_H +#include "ckt.h" +#endif /* CKT_H */ + +struct builtinsInternalObjectStr { + CK_ULONG n; + const CK_ATTRIBUTE_TYPE *types; + const NSSItem *items; + NSSCKMDObject mdObject; +}; +typedef struct builtinsInternalObjectStr builtinsInternalObject; + +extern builtinsInternalObject nss_builtins_data[]; +extern const PRUint32 nss_builtins_nObjects; + +extern const CK_VERSION nss_builtins_CryptokiVersion; +extern const CK_VERSION nss_builtins_LibraryVersion; +extern const CK_VERSION nss_builtins_HardwareVersion; +extern const CK_VERSION nss_builtins_FirmwareVersion; + +extern const NSSUTF8 nss_builtins_ManufacturerID[]; +extern const NSSUTF8 nss_builtins_LibraryDescription[]; +extern const NSSUTF8 nss_builtins_SlotDescription[]; +extern const NSSUTF8 nss_builtins_TokenLabel[]; +extern const NSSUTF8 nss_builtins_TokenModel[]; +extern const NSSUTF8 nss_builtins_TokenSerialNumber[]; + +extern const NSSCKMDInstance nss_builtins_mdInstance; +extern const NSSCKMDSlot nss_builtins_mdSlot; +extern const NSSCKMDToken nss_builtins_mdToken; + +NSS_EXTERN NSSCKMDSession * +nss_builtins_CreateSession( + NSSCKFWSession *fwSession, + CK_RV *pError); + +NSS_EXTERN NSSCKMDFindObjects * +nss_builtins_FindObjectsInit( + NSSCKFWSession *fwSession, + CK_ATTRIBUTE_PTR pTemplate, + CK_ULONG ulAttributeCount, + CK_RV *pError); + +NSS_EXTERN NSSCKMDObject * +nss_builtins_CreateMDObject( + NSSArena *arena, + builtinsInternalObject *io, + CK_RV *pError); diff --git a/security/nss/lib/ckfw/builtins/certdata.perl b/security/nss/lib/ckfw/builtins/certdata.perl new file mode 100644 index 000000000..502dfb0c5 --- /dev/null +++ b/security/nss/lib/ckfw/builtins/certdata.perl @@ -0,0 +1,192 @@ +#!perl -w +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +use strict; + +my %constants; +my $count = 0; +my $o; +my @objects = (); +my @objsize; + +$constants{CK_TRUE} = "static const CK_BBOOL ck_true = CK_TRUE;\n"; +$constants{CK_FALSE} = "static const CK_BBOOL ck_false = CK_FALSE;\n"; + +if( scalar @ARGV == 0 ) { + print STDERR "Usage: $0 [output-file]\n"; + exit 1; +} + +open(STDIN, '<', $ARGV[0]) + or die "Could not open input file '$ARGV[0]' $!"; +if( scalar @ARGV > 1 ) { + open(STDOUT, '>', $ARGV[1]) + or die "Could not open output file '$ARGV[1]' $!"; +} + +while(<>) { + my @fields = (); + my $size; + + s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/; + next if (/^\s*$/); + + # This was taken from the perl faq #4. + my $text = $_; + push(@fields, $+) while $text =~ m{ + "([^\"\\]*(?:\\.[^\"\\]*)*)"\s? # groups the phrase inside the quotes + | ([^\s]+)\s? + | \s + }gx; + push(@fields, undef) if substr($text,-1,1) eq '\s'; + + if( $fields[0] =~ /BEGINDATA/ ) { + next; + } + + if( $fields[1] =~ /MULTILINE/ ) { + $fields[2] = ""; + while(<>) { + last if /END/; + chomp; + $fields[2] .= "\"$_\"\n"; + } + } + + if( $fields[1] =~ /UTF8/ ) { + if( $fields[2] =~ /^"/ ) { + ; + } else { + $fields[2] = "\"" . $fields[2] . "\""; + } + + my $scratch = eval($fields[2]); + + $size = length($scratch) + 1; # null terminate + } + + if( $fields[1] =~ /OCTAL/ ) { + if( $fields[2] =~ /^"/ ) { + ; + } else { + $fields[2] = "\"" . $fields[2] . "\""; + } + + my $scratch = $fields[2]; + $size = $scratch =~ tr/\\//; + # no null termination + } + + if( $fields[1] =~ /^CK_/ ) { + my $lcv = $fields[2]; + $lcv =~ tr/A-Z/a-z/; + if( !defined($constants{$fields[2]}) ) { + $constants{$fields[2]} = "static const $fields[1] $lcv = $fields[2];\n"; + } + + $size = "sizeof($fields[1])"; + $fields[2] = "&$lcv"; + } + + if( $fields[0] =~ /CKA_CLASS/ ) { + $count++; + $objsize[$count] = 0; + } + + @{$objects[$count][$objsize[$count]++]} = ( "$fields[0]", $fields[2], "$size" ); + + # print "$fields[0] | $fields[1] | $size | $fields[2]\n"; +} + +doprint(); + +sub dudump { +my $i; +for( $i = 1; $i <= $count; $i++ ) { + print "\n"; + $o = $objects[$i]; + my @ob = @{$o}; + my $l; + my $j; + for( $j = 0; $j < @ob; $j++ ) { + $l = $ob[$j]; + my @a = @{$l}; + print "$a[0] ! $a[1] ! $a[2]\n"; + } +} + +} + +sub doprint { +my $i; + +print <