1cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/mscrypto/Makefile.am 2009-06-25 22:53:18.000000000 +0200 2cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/mscrypto/Makefile.am 2009-09-21 14:02:48.563253008 +0200 3cdf0e10cSrcweir@@ -3,6 +3,7 @@ 4cdf0e10cSrcweir xmlsecmscryptoincdir = $(includedir)/xmlsec1/xmlsec/mscrypto 5cdf0e10cSrcweir 6cdf0e10cSrcweir xmlsecmscryptoinc_HEADERS = \ 7cdf0e10cSrcweir+akmngr.h \ 8cdf0e10cSrcweir app.h \ 9cdf0e10cSrcweir certkeys.h \ 10cdf0e10cSrcweir crypto.h \ 11cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/mscrypto/Makefile.in 2009-06-25 22:53:30.000000000 +0200 12cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/mscrypto/Makefile.in 2009-09-21 14:02:48.571021349 +0200 13cdf0e10cSrcweir@@ -281,6 +281,7 @@ 14cdf0e10cSrcweir NULL = 15cdf0e10cSrcweir xmlsecmscryptoincdir = $(includedir)/xmlsec1/xmlsec/mscrypto 16cdf0e10cSrcweir xmlsecmscryptoinc_HEADERS = \ 17cdf0e10cSrcweir+akmngr.h \ 18cdf0e10cSrcweir app.h \ 19cdf0e10cSrcweir certkeys.h \ 20cdf0e10cSrcweir crypto.h \ 21cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/mscrypto/akmngr.h 2009-09-21 14:07:19.052318336 +0200 22cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/mscrypto/akmngr.h 2009-09-21 14:02:48.504966762 +0200 23cdf0e10cSrcweir@@ -1 +1,71 @@ 24cdf0e10cSrcweir-dummy 25cdf0e10cSrcweir+/** 26cdf0e10cSrcweir+ * XMLSec library 27cdf0e10cSrcweir+ * 28cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 29cdf0e10cSrcweir+ * distribution for preciese wording. 30cdf0e10cSrcweir+ * 31cdf0e10cSrcweir+ * Copyright .......................... 32cdf0e10cSrcweir+ */ 33cdf0e10cSrcweir+#ifndef __XMLSEC_MSCRYPTO_AKMNGR_H__ 34cdf0e10cSrcweir+#define __XMLSEC_MSCRYPTO_AKMNGR_H__ 35cdf0e10cSrcweir+ 36cdf0e10cSrcweir+#include <windows.h> 37cdf0e10cSrcweir+#include <wincrypt.h> 38cdf0e10cSrcweir+ 39cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 40cdf0e10cSrcweir+#include <xmlsec/keys.h> 41cdf0e10cSrcweir+#include <xmlsec/transforms.h> 42cdf0e10cSrcweir+ 43cdf0e10cSrcweir+#ifdef __cplusplus 44cdf0e10cSrcweir+extern "C" { 45cdf0e10cSrcweir+#endif /* __cplusplus */ 46cdf0e10cSrcweir+ 47cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT xmlSecKeysMngrPtr 48cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrCreate( 49cdf0e10cSrcweir+ HCERTSTORE keyStore , 50cdf0e10cSrcweir+ HCERTSTORE certStore 51cdf0e10cSrcweir+) ; 52cdf0e10cSrcweir+ 53cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 54cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrSymKeyLoad( 55cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 56cdf0e10cSrcweir+ HCRYPTKEY symKey 57cdf0e10cSrcweir+) ; 58cdf0e10cSrcweir+ 59cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 60cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrPubKeyLoad( 61cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 62cdf0e10cSrcweir+ HCRYPTKEY pubKey 63cdf0e10cSrcweir+) ; 64cdf0e10cSrcweir+ 65cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 66cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrPriKeyLoad( 67cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 68cdf0e10cSrcweir+ HCRYPTKEY priKey 69cdf0e10cSrcweir+) ; 70cdf0e10cSrcweir+ 71cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 72cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore ( 73cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 74cdf0e10cSrcweir+ HCERTSTORE keyStore 75cdf0e10cSrcweir+) ; 76cdf0e10cSrcweir+ 77cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 78cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore ( 79cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 80cdf0e10cSrcweir+ HCERTSTORE trustedStore 81cdf0e10cSrcweir+) ; 82cdf0e10cSrcweir+ 83cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 84cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore ( 85cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 86cdf0e10cSrcweir+ HCERTSTORE untrustedStore 87cdf0e10cSrcweir+) ; 88cdf0e10cSrcweir+ 89cdf0e10cSrcweir+#ifdef __cplusplus 90cdf0e10cSrcweir+} 91cdf0e10cSrcweir+#endif /* __cplusplus */ 92cdf0e10cSrcweir+ 93cdf0e10cSrcweir+#endif /* __XMLSEC_MSCRYPTO_AKMNGR_H__ */ 94cdf0e10cSrcweir+ 95cdf0e10cSrcweir+ 96cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/Makefile.am 2009-06-25 22:53:18.000000000 +0200 97cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/Makefile.am 2009-09-21 14:02:48.577933031 +0200 98cdf0e10cSrcweir@@ -10,6 +10,9 @@ 99cdf0e10cSrcweir keysstore.h \ 100cdf0e10cSrcweir pkikeys.h \ 101cdf0e10cSrcweir x509.h \ 102cdf0e10cSrcweir+akmngr.h \ 103cdf0e10cSrcweir+tokens.h \ 104cdf0e10cSrcweir+ciphers.h \ 105cdf0e10cSrcweir $(NULL) 106cdf0e10cSrcweir 107cdf0e10cSrcweir install-exec-hook: 108cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/Makefile.in 2009-06-25 22:53:31.000000000 +0200 109cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/Makefile.in 2009-09-21 14:02:48.585376325 +0200 110cdf0e10cSrcweir@@ -288,6 +288,9 @@ 111cdf0e10cSrcweir keysstore.h \ 112cdf0e10cSrcweir pkikeys.h \ 113cdf0e10cSrcweir x509.h \ 114cdf0e10cSrcweir+akmngr.h \ 115cdf0e10cSrcweir+tokens.h \ 116cdf0e10cSrcweir+ciphers.h \ 117cdf0e10cSrcweir $(NULL) 118cdf0e10cSrcweir 119cdf0e10cSrcweir all: all-am 120cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/akmngr.h 2009-09-21 14:07:19.105517659 +0200 121cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/akmngr.h 2009-09-21 14:02:48.510978278 +0200 122cdf0e10cSrcweir@@ -1 +1,56 @@ 123cdf0e10cSrcweir-dummy 124cdf0e10cSrcweir+/** 125cdf0e10cSrcweir+ * XMLSec library 126cdf0e10cSrcweir+ * 127cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 128cdf0e10cSrcweir+ * distribution for preciese wording. 129cdf0e10cSrcweir+ * 130cdf0e10cSrcweir+ * Copyright .......................... 131cdf0e10cSrcweir+ */ 132cdf0e10cSrcweir+#ifndef __XMLSEC_NSS_AKMNGR_H__ 133cdf0e10cSrcweir+#define __XMLSEC_NSS_AKMNGR_H__ 134cdf0e10cSrcweir+ 135cdf0e10cSrcweir+#include <nss.h> 136cdf0e10cSrcweir+#include <nspr.h> 137cdf0e10cSrcweir+#include <pk11func.h> 138cdf0e10cSrcweir+#include <cert.h> 139cdf0e10cSrcweir+ 140cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 141cdf0e10cSrcweir+#include <xmlsec/keys.h> 142cdf0e10cSrcweir+#include <xmlsec/transforms.h> 143cdf0e10cSrcweir+ 144cdf0e10cSrcweir+#ifdef __cplusplus 145cdf0e10cSrcweir+extern "C" { 146cdf0e10cSrcweir+#endif /* __cplusplus */ 147cdf0e10cSrcweir+ 148cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT xmlSecKeysMngrPtr 149cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrCreate( 150cdf0e10cSrcweir+ PK11SlotInfo** slots, 151cdf0e10cSrcweir+ int cSlots, 152cdf0e10cSrcweir+ CERTCertDBHandle* handler 153cdf0e10cSrcweir+) ; 154cdf0e10cSrcweir+ 155cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 156cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrSymKeyLoad( 157cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 158cdf0e10cSrcweir+ PK11SymKey* symKey 159cdf0e10cSrcweir+) ; 160cdf0e10cSrcweir+ 161cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 162cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrPubKeyLoad( 163cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 164cdf0e10cSrcweir+ SECKEYPublicKey* pubKey 165cdf0e10cSrcweir+) ; 166cdf0e10cSrcweir+ 167cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 168cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrPriKeyLoad( 169cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 170cdf0e10cSrcweir+ SECKEYPrivateKey* priKey 171cdf0e10cSrcweir+) ; 172cdf0e10cSrcweir+ 173cdf0e10cSrcweir+#ifdef __cplusplus 174cdf0e10cSrcweir+} 175cdf0e10cSrcweir+#endif /* __cplusplus */ 176cdf0e10cSrcweir+ 177cdf0e10cSrcweir+#endif /* __XMLSEC_NSS_AKMNGR_H__ */ 178cdf0e10cSrcweir+ 179cdf0e10cSrcweir+ 180cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/app.h 2009-06-25 22:53:18.000000000 +0200 181cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/app.h 2009-09-21 14:02:48.612847068 +0200 182cdf0e10cSrcweir@@ -22,6 +22,9 @@ 183cdf0e10cSrcweir #include <xmlsec/keysmngr.h> 184cdf0e10cSrcweir #include <xmlsec/transforms.h> 185cdf0e10cSrcweir 186cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 187cdf0e10cSrcweir+#include <xmlsec/nss/akmngr.h> 188cdf0e10cSrcweir+ 189cdf0e10cSrcweir /** 190cdf0e10cSrcweir * Init/shutdown 191cdf0e10cSrcweir */ 192cdf0e10cSrcweir@@ -36,6 +39,8 @@ 193cdf0e10cSrcweir xmlSecKeyPtr key); 194cdf0e10cSrcweir XMLSEC_CRYPTO_EXPORT int xmlSecNssAppDefaultKeysMngrLoad (xmlSecKeysMngrPtr mngr, 195cdf0e10cSrcweir const char* uri); 196cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int xmlSecNssAppDefaultKeysMngrAdoptKeySlot(xmlSecKeysMngrPtr mngr, 197cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot); 198cdf0e10cSrcweir XMLSEC_CRYPTO_EXPORT int xmlSecNssAppDefaultKeysMngrSave (xmlSecKeysMngrPtr mngr, 199cdf0e10cSrcweir const char* filename, 200cdf0e10cSrcweir xmlSecKeyDataType type); 201cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/ciphers.h 2009-09-21 14:07:19.146496548 +0200 202cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/ciphers.h 2009-09-21 14:02:48.516689712 +0200 203cdf0e10cSrcweir@@ -1 +1,35 @@ 204cdf0e10cSrcweir-dummy 205cdf0e10cSrcweir+/** 206cdf0e10cSrcweir+ * XMLSec library 207cdf0e10cSrcweir+ * 208cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 209cdf0e10cSrcweir+ * distribution for preciese wording. 210cdf0e10cSrcweir+ * 211cdf0e10cSrcweir+ * Copyright .......................... 212cdf0e10cSrcweir+ */ 213cdf0e10cSrcweir+#ifndef __XMLSEC_NSS_CIPHERS_H__ 214cdf0e10cSrcweir+#define __XMLSEC_NSS_CIPHERS_H__ 215cdf0e10cSrcweir+ 216cdf0e10cSrcweir+#ifdef __cplusplus 217cdf0e10cSrcweir+extern "C" { 218cdf0e10cSrcweir+#endif /* __cplusplus */ 219cdf0e10cSrcweir+ 220cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 221cdf0e10cSrcweir+#include <xmlsec/keys.h> 222cdf0e10cSrcweir+#include <xmlsec/transforms.h> 223cdf0e10cSrcweir+ 224cdf0e10cSrcweir+ 225cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int xmlSecNssSymKeyDataAdoptKey( xmlSecKeyDataPtr data, 226cdf0e10cSrcweir+ PK11SymKey* symkey ) ; 227cdf0e10cSrcweir+ 228cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT xmlSecKeyDataPtr xmlSecNssSymKeyDataKeyAdopt( PK11SymKey* symKey ) ; 229cdf0e10cSrcweir+ 230cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT PK11SymKey* xmlSecNssSymKeyDataGetKey(xmlSecKeyDataPtr data); 231cdf0e10cSrcweir+ 232cdf0e10cSrcweir+ 233cdf0e10cSrcweir+#ifdef __cplusplus 234cdf0e10cSrcweir+} 235cdf0e10cSrcweir+#endif /* __cplusplus */ 236cdf0e10cSrcweir+ 237cdf0e10cSrcweir+#endif /* __XMLSEC_NSS_CIPHERS_H__ */ 238cdf0e10cSrcweir+ 239cdf0e10cSrcweir+ 240cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/keysstore.h 2009-06-25 22:53:18.000000000 +0200 241cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/keysstore.h 2009-09-21 14:02:48.626261748 +0200 242cdf0e10cSrcweir@@ -16,6 +16,8 @@ 243cdf0e10cSrcweir #endif /* __cplusplus */ 244cdf0e10cSrcweir 245cdf0e10cSrcweir #include <xmlsec/xmlsec.h> 246cdf0e10cSrcweir+#include <xmlsec/keysmngr.h> 247cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 248cdf0e10cSrcweir 249cdf0e10cSrcweir /**************************************************************************** 250cdf0e10cSrcweir * 251cdf0e10cSrcweir@@ -31,6 +33,8 @@ 252cdf0e10cSrcweir XMLSEC_CRYPTO_EXPORT xmlSecKeyStoreId xmlSecNssKeysStoreGetKlass (void); 253cdf0e10cSrcweir XMLSEC_CRYPTO_EXPORT int xmlSecNssKeysStoreAdoptKey (xmlSecKeyStorePtr store, 254cdf0e10cSrcweir xmlSecKeyPtr key); 255cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int xmlSecNssKeysStoreAdoptKeySlot(xmlSecKeyStorePtr store, 256cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot); 257cdf0e10cSrcweir XMLSEC_CRYPTO_EXPORT int xmlSecNssKeysStoreLoad (xmlSecKeyStorePtr store, 258cdf0e10cSrcweir const char *uri, 259cdf0e10cSrcweir xmlSecKeysMngrPtr keysMngr); 260cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/include/xmlsec/nss/tokens.h 2009-09-21 14:07:19.172421448 +0200 261cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/include/xmlsec/nss/tokens.h 2009-09-21 14:02:48.522913605 +0200 262cdf0e10cSrcweir@@ -1 +1,182 @@ 263cdf0e10cSrcweir-dummy 264cdf0e10cSrcweir+/** 265cdf0e10cSrcweir+ * XMLSec library 266cdf0e10cSrcweir+ * 267cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 268cdf0e10cSrcweir+ * distribution for preciese wording. 269cdf0e10cSrcweir+ * 270cdf0e10cSrcweir+ * Copyright (c) 2003 Sun Microsystems, Inc. All rights reserved. 271cdf0e10cSrcweir+ * 272cdf0e10cSrcweir+ * Contributor(s): _____________________________ 273cdf0e10cSrcweir+ * 274cdf0e10cSrcweir+ */ 275cdf0e10cSrcweir+#ifndef __XMLSEC_NSS_TOKENS_H__ 276cdf0e10cSrcweir+#define __XMLSEC_NSS_TOKENS_H__ 277cdf0e10cSrcweir+ 278cdf0e10cSrcweir+#include <string.h> 279cdf0e10cSrcweir+ 280cdf0e10cSrcweir+#include <nss.h> 281cdf0e10cSrcweir+#include <pk11func.h> 282cdf0e10cSrcweir+ 283cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 284cdf0e10cSrcweir+#include <xmlsec/list.h> 285cdf0e10cSrcweir+ 286cdf0e10cSrcweir+#ifdef __cplusplus 287cdf0e10cSrcweir+extern "C" { 288cdf0e10cSrcweir+#endif /* __cplusplus */ 289cdf0e10cSrcweir+ 290cdf0e10cSrcweir+/** 291cdf0e10cSrcweir+ * xmlSecNssKeySlotListId 292cdf0e10cSrcweir+ * 293cdf0e10cSrcweir+ * The crypto mechanism list klass 294cdf0e10cSrcweir+ */ 295cdf0e10cSrcweir+#define xmlSecNssKeySlotListId xmlSecNssKeySlotListGetKlass() 296cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT xmlSecPtrListId xmlSecNssKeySlotListGetKlass( void ) ; 297cdf0e10cSrcweir+ 298cdf0e10cSrcweir+/******************************************* 299cdf0e10cSrcweir+ * KeySlot interfaces 300cdf0e10cSrcweir+ *******************************************/ 301cdf0e10cSrcweir+/** 302cdf0e10cSrcweir+ * Internal NSS key slot data 303cdf0e10cSrcweir+ * @mechanismList: the mechanisms that the slot bound with. 304cdf0e10cSrcweir+ * @slot: the pkcs slot 305cdf0e10cSrcweir+ * 306cdf0e10cSrcweir+ * This context is located after xmlSecPtrList 307cdf0e10cSrcweir+ */ 308cdf0e10cSrcweir+typedef struct _xmlSecNssKeySlot xmlSecNssKeySlot ; 309cdf0e10cSrcweir+typedef struct _xmlSecNssKeySlot* xmlSecNssKeySlotPtr ; 310cdf0e10cSrcweir+ 311cdf0e10cSrcweir+struct _xmlSecNssKeySlot { 312cdf0e10cSrcweir+ CK_MECHANISM_TYPE_PTR mechanismList ; /* mech. array, NULL ternimated */ 313cdf0e10cSrcweir+ PK11SlotInfo* slot ; 314cdf0e10cSrcweir+} ; 315cdf0e10cSrcweir+ 316cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 317cdf0e10cSrcweir+xmlSecNssKeySlotSetMechList( 318cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 319cdf0e10cSrcweir+ CK_MECHANISM_TYPE_PTR mechanismList 320cdf0e10cSrcweir+) ; 321cdf0e10cSrcweir+ 322cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 323cdf0e10cSrcweir+xmlSecNssKeySlotEnableMech( 324cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 325cdf0e10cSrcweir+ CK_MECHANISM_TYPE mechanism 326cdf0e10cSrcweir+) ; 327cdf0e10cSrcweir+ 328cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 329cdf0e10cSrcweir+xmlSecNssKeySlotDisableMech( 330cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 331cdf0e10cSrcweir+ CK_MECHANISM_TYPE mechanism 332cdf0e10cSrcweir+) ; 333cdf0e10cSrcweir+ 334cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT CK_MECHANISM_TYPE_PTR 335cdf0e10cSrcweir+xmlSecNssKeySlotGetMechList( 336cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 337cdf0e10cSrcweir+) ; 338cdf0e10cSrcweir+ 339cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 340cdf0e10cSrcweir+xmlSecNssKeySlotSetSlot( 341cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 342cdf0e10cSrcweir+ PK11SlotInfo* slot 343cdf0e10cSrcweir+) ; 344cdf0e10cSrcweir+ 345cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 346cdf0e10cSrcweir+xmlSecNssKeySlotInitialize( 347cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 348cdf0e10cSrcweir+ PK11SlotInfo* slot 349cdf0e10cSrcweir+) ; 350cdf0e10cSrcweir+ 351cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT void 352cdf0e10cSrcweir+xmlSecNssKeySlotFinalize( 353cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 354cdf0e10cSrcweir+) ; 355cdf0e10cSrcweir+ 356cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT PK11SlotInfo* 357cdf0e10cSrcweir+xmlSecNssKeySlotGetSlot( 358cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 359cdf0e10cSrcweir+) ; 360cdf0e10cSrcweir+ 361cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT xmlSecNssKeySlotPtr 362cdf0e10cSrcweir+xmlSecNssKeySlotCreate() ; 363cdf0e10cSrcweir+ 364cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 365cdf0e10cSrcweir+xmlSecNssKeySlotCopy( 366cdf0e10cSrcweir+ xmlSecNssKeySlotPtr newKeySlot , 367cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 368cdf0e10cSrcweir+) ; 369cdf0e10cSrcweir+ 370cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT xmlSecNssKeySlotPtr 371cdf0e10cSrcweir+xmlSecNssKeySlotDuplicate( 372cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 373cdf0e10cSrcweir+) ; 374cdf0e10cSrcweir+ 375cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT void 376cdf0e10cSrcweir+xmlSecNssKeySlotDestroy( 377cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 378cdf0e10cSrcweir+) ; 379cdf0e10cSrcweir+ 380cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 381cdf0e10cSrcweir+xmlSecNssKeySlotBindMech( 382cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 383cdf0e10cSrcweir+ CK_MECHANISM_TYPE type 384cdf0e10cSrcweir+) ; 385cdf0e10cSrcweir+ 386cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int 387cdf0e10cSrcweir+xmlSecNssKeySlotSupportMech( 388cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 389cdf0e10cSrcweir+ CK_MECHANISM_TYPE type 390cdf0e10cSrcweir+) ; 391cdf0e10cSrcweir+ 392cdf0e10cSrcweir+ 393cdf0e10cSrcweir+/************************************************************************ 394cdf0e10cSrcweir+ * PKCS#11 crypto token interfaces 395cdf0e10cSrcweir+ * 396cdf0e10cSrcweir+ * A PKCS#11 slot repository will be defined internally. From the 397cdf0e10cSrcweir+ * repository, a user can specify a particular slot for a certain crypto 398cdf0e10cSrcweir+ * mechanism. 399cdf0e10cSrcweir+ * 400cdf0e10cSrcweir+ * In some situation, some cryptographic operation should act in a user 401cdf0e10cSrcweir+ * designated devices. The interfaces defined here provide the way. If 402cdf0e10cSrcweir+ * the user do not initialize the repository distinctly, the interfaces 403cdf0e10cSrcweir+ * use the default functions provided by NSS itself. 404cdf0e10cSrcweir+ * 405cdf0e10cSrcweir+ ************************************************************************/ 406cdf0e10cSrcweir+/** 407cdf0e10cSrcweir+ * Initialize NSS pkcs#11 slot repository 408cdf0e10cSrcweir+ * 409cdf0e10cSrcweir+ * Returns 0 if success or -1 if an error occurs. 410cdf0e10cSrcweir+ */ 411cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int xmlSecNssSlotInitialize( void ) ; 412cdf0e10cSrcweir+ 413cdf0e10cSrcweir+/** 414cdf0e10cSrcweir+ * Shutdown and destroy NSS pkcs#11 slot repository 415cdf0e10cSrcweir+ */ 416cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT void xmlSecNssSlotShutdown() ; 417cdf0e10cSrcweir+ 418cdf0e10cSrcweir+/** 419cdf0e10cSrcweir+ * Get PKCS#11 slot handler 420cdf0e10cSrcweir+ * @type the mechanism that the slot must support. 421cdf0e10cSrcweir+ * 422cdf0e10cSrcweir+ * Returns a pointer to PKCS#11 slot or NULL if an error occurs. 423cdf0e10cSrcweir+ * 424cdf0e10cSrcweir+ * Notes: The returned handler must be destroied distinctly. 425cdf0e10cSrcweir+ */ 426cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT PK11SlotInfo* xmlSecNssSlotGet( CK_MECHANISM_TYPE type ) ; 427cdf0e10cSrcweir+ 428cdf0e10cSrcweir+/** 429cdf0e10cSrcweir+ * Adopt a pkcs#11 slot with a mechanism into the repository 430cdf0e10cSrcweir+ * @slot: the pkcs#11 slot. 431cdf0e10cSrcweir+ * @mech: the mechanism. 432cdf0e10cSrcweir+ * 433cdf0e10cSrcweir+ * If @mech is available( @mech != CKM_INVALID_MECHANISM ), every operation with 434cdf0e10cSrcweir+ * this mechanism only can perform on the @slot. 435cdf0e10cSrcweir+ * 436cdf0e10cSrcweir+ * Returns 0 if success or -1 if an error occurs. 437cdf0e10cSrcweir+ */ 438cdf0e10cSrcweir+XMLSEC_CRYPTO_EXPORT int xmlSecNssSlotAdopt( PK11SlotInfo* slot, CK_MECHANISM_TYPE mech ) ; 439cdf0e10cSrcweir+ 440cdf0e10cSrcweir+#ifdef __cplusplus 441cdf0e10cSrcweir+} 442cdf0e10cSrcweir+#endif /* __cplusplus */ 443cdf0e10cSrcweir+ 444cdf0e10cSrcweir+#endif /* __XMLSEC_NSS_TOKENS_H__ */ 445cdf0e10cSrcweir+ 446cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/mscrypto/akmngr.c 2009-09-21 14:07:19.078910929 +0200 447cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/mscrypto/akmngr.c 2009-09-21 14:02:48.531281225 +0200 448cdf0e10cSrcweir@@ -1 +1,236 @@ 449cdf0e10cSrcweir-dummy 450cdf0e10cSrcweir+/** 451cdf0e10cSrcweir+ * XMLSec library 452cdf0e10cSrcweir+ * 453cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 454cdf0e10cSrcweir+ * distribution for preciese wording. 455cdf0e10cSrcweir+ * 456cdf0e10cSrcweir+ * Copyright......................... 457cdf0e10cSrcweir+ */ 458cdf0e10cSrcweir+#include "globals.h" 459cdf0e10cSrcweir+ 460cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 461cdf0e10cSrcweir+#include <xmlsec/keys.h> 462cdf0e10cSrcweir+#include <xmlsec/keysmngr.h> 463cdf0e10cSrcweir+#include <xmlsec/transforms.h> 464cdf0e10cSrcweir+#include <xmlsec/errors.h> 465cdf0e10cSrcweir+ 466cdf0e10cSrcweir+#include <xmlsec/mscrypto/crypto.h> 467cdf0e10cSrcweir+#include <xmlsec/mscrypto/keysstore.h> 468cdf0e10cSrcweir+#include <xmlsec/mscrypto/akmngr.h> 469cdf0e10cSrcweir+#include <xmlsec/mscrypto/x509.h> 470cdf0e10cSrcweir+ 471cdf0e10cSrcweir+/** 472cdf0e10cSrcweir+ * xmlSecMSCryptoAppliedKeysMngrCreate: 473cdf0e10cSrcweir+ * @hKeyStore: the pointer to key store. 474cdf0e10cSrcweir+ * @hCertStore: the pointer to certificate database. 475cdf0e10cSrcweir+ * 476cdf0e10cSrcweir+ * Create and load key store and certificate database into keys manager 477cdf0e10cSrcweir+ * 478cdf0e10cSrcweir+ * Returns keys manager pointer on success or NULL otherwise. 479cdf0e10cSrcweir+ */ 480cdf0e10cSrcweir+xmlSecKeysMngrPtr 481cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrCreate( 482cdf0e10cSrcweir+ HCERTSTORE hKeyStore , 483cdf0e10cSrcweir+ HCERTSTORE hCertStore 484cdf0e10cSrcweir+) { 485cdf0e10cSrcweir+ xmlSecKeyDataStorePtr certStore = NULL ; 486cdf0e10cSrcweir+ xmlSecKeysMngrPtr keyMngr = NULL ; 487cdf0e10cSrcweir+ xmlSecKeyStorePtr keyStore = NULL ; 488cdf0e10cSrcweir+ 489cdf0e10cSrcweir+ keyStore = xmlSecKeyStoreCreate( xmlSecMSCryptoKeysStoreId ) ; 490cdf0e10cSrcweir+ if( keyStore == NULL ) { 491cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 492cdf0e10cSrcweir+ NULL , 493cdf0e10cSrcweir+ "xmlSecKeyStoreCreate" , 494cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 495cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 496cdf0e10cSrcweir+ return NULL ; 497cdf0e10cSrcweir+ } 498cdf0e10cSrcweir+ 499cdf0e10cSrcweir+ /*- 500cdf0e10cSrcweir+ * At present, MS Crypto engine do not provide a way to setup a key store. 501cdf0e10cSrcweir+ */ 502cdf0e10cSrcweir+ if( keyStore != NULL ) { 503cdf0e10cSrcweir+ /*TODO: binding key store.*/ 504cdf0e10cSrcweir+ } 505cdf0e10cSrcweir+ 506cdf0e10cSrcweir+ keyMngr = xmlSecKeysMngrCreate() ; 507cdf0e10cSrcweir+ if( keyMngr == NULL ) { 508cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 509cdf0e10cSrcweir+ NULL , 510cdf0e10cSrcweir+ "xmlSecKeysMngrCreate" , 511cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 512cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 513cdf0e10cSrcweir+ 514cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 515cdf0e10cSrcweir+ return NULL ; 516cdf0e10cSrcweir+ } 517cdf0e10cSrcweir+ 518cdf0e10cSrcweir+ /*- 519cdf0e10cSrcweir+ * Add key store to manager, from now on keys manager destroys the store if 520cdf0e10cSrcweir+ * needed 521cdf0e10cSrcweir+ */ 522cdf0e10cSrcweir+ if( xmlSecKeysMngrAdoptKeysStore( keyMngr, keyStore ) < 0 ) { 523cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 524cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 525cdf0e10cSrcweir+ "xmlSecKeysMngrAdoptKeyStore" , 526cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 527cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 528cdf0e10cSrcweir+ 529cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 530cdf0e10cSrcweir+ xmlSecKeysMngrDestroy( keyMngr ) ; 531cdf0e10cSrcweir+ return NULL ; 532cdf0e10cSrcweir+ } 533cdf0e10cSrcweir+ 534cdf0e10cSrcweir+ /*- 535cdf0e10cSrcweir+ * Initialize crypto library specific data in keys manager 536cdf0e10cSrcweir+ */ 537cdf0e10cSrcweir+ if( xmlSecMSCryptoKeysMngrInit( keyMngr ) < 0 ) { 538cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 539cdf0e10cSrcweir+ NULL , 540cdf0e10cSrcweir+ "xmlSecMSCryptoKeysMngrInit" , 541cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 542cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 543cdf0e10cSrcweir+ 544cdf0e10cSrcweir+ xmlSecKeysMngrDestroy( keyMngr ) ; 545cdf0e10cSrcweir+ return NULL ; 546cdf0e10cSrcweir+ } 547cdf0e10cSrcweir+ 548cdf0e10cSrcweir+ /*- 549cdf0e10cSrcweir+ * Set certificate databse to X509 key data store 550cdf0e10cSrcweir+ */ 551cdf0e10cSrcweir+ /*- 552cdf0e10cSrcweir+ * At present, MS Crypto engine do not provide a way to setup a cert store. 553cdf0e10cSrcweir+ */ 554cdf0e10cSrcweir+ 555cdf0e10cSrcweir+ /*- 556cdf0e10cSrcweir+ * Set the getKey callback 557cdf0e10cSrcweir+ */ 558cdf0e10cSrcweir+ keyMngr->getKey = xmlSecKeysMngrGetKey ; 559cdf0e10cSrcweir+ 560cdf0e10cSrcweir+ return keyMngr ; 561cdf0e10cSrcweir+} 562cdf0e10cSrcweir+ 563cdf0e10cSrcweir+int 564cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrSymKeyLoad( 565cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 566cdf0e10cSrcweir+ HCRYPTKEY symKey 567cdf0e10cSrcweir+) { 568cdf0e10cSrcweir+ /*TODO: import the key into keys manager.*/ 569cdf0e10cSrcweir+ return(0) ; 570cdf0e10cSrcweir+} 571cdf0e10cSrcweir+ 572cdf0e10cSrcweir+int 573cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrPubKeyLoad( 574cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 575cdf0e10cSrcweir+ HCRYPTKEY pubKey 576cdf0e10cSrcweir+) { 577cdf0e10cSrcweir+ /*TODO: import the key into keys manager.*/ 578cdf0e10cSrcweir+ return(0) ; 579cdf0e10cSrcweir+} 580cdf0e10cSrcweir+ 581cdf0e10cSrcweir+int 582cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrPriKeyLoad( 583cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 584cdf0e10cSrcweir+ HCRYPTKEY priKey 585cdf0e10cSrcweir+) { 586cdf0e10cSrcweir+ /*TODO: import the key into keys manager.*/ 587cdf0e10cSrcweir+ return(0) ; 588cdf0e10cSrcweir+} 589cdf0e10cSrcweir+ 590cdf0e10cSrcweir+int 591cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore ( 592cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 593cdf0e10cSrcweir+ HCERTSTORE keyStore 594cdf0e10cSrcweir+) { 595cdf0e10cSrcweir+ xmlSecKeyDataStorePtr x509Store ; 596cdf0e10cSrcweir+ 597cdf0e10cSrcweir+ xmlSecAssert2( mngr != NULL, -1 ) ; 598cdf0e10cSrcweir+ xmlSecAssert2( keyStore != NULL, -1 ) ; 599cdf0e10cSrcweir+ 600cdf0e10cSrcweir+ x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ; 601cdf0e10cSrcweir+ if( x509Store == NULL ) { 602cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 603cdf0e10cSrcweir+ NULL , 604cdf0e10cSrcweir+ "xmlSecKeysMngrGetDataStore" , 605cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 606cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 607cdf0e10cSrcweir+ return( -1 ) ; 608cdf0e10cSrcweir+ } 609cdf0e10cSrcweir+ 610cdf0e10cSrcweir+ if( xmlSecMSCryptoX509StoreAdoptKeyStore( x509Store, keyStore ) < 0 ) { 611cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 612cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) , 613cdf0e10cSrcweir+ "xmlSecMSCryptoX509StoreAdoptKeyStore" , 614cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 615cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 616cdf0e10cSrcweir+ return( -1 ) ; 617cdf0e10cSrcweir+ } 618cdf0e10cSrcweir+ 619cdf0e10cSrcweir+ return( 0 ) ; 620cdf0e10cSrcweir+} 621cdf0e10cSrcweir+ 622cdf0e10cSrcweir+int 623cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore ( 624cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 625cdf0e10cSrcweir+ HCERTSTORE trustedStore 626cdf0e10cSrcweir+) { 627cdf0e10cSrcweir+ xmlSecKeyDataStorePtr x509Store ; 628cdf0e10cSrcweir+ 629cdf0e10cSrcweir+ xmlSecAssert2( mngr != NULL, -1 ) ; 630cdf0e10cSrcweir+ xmlSecAssert2( trustedStore != NULL, -1 ) ; 631cdf0e10cSrcweir+ 632cdf0e10cSrcweir+ x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ; 633cdf0e10cSrcweir+ if( x509Store == NULL ) { 634cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 635cdf0e10cSrcweir+ NULL , 636cdf0e10cSrcweir+ "xmlSecKeysMngrGetDataStore" , 637cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 638cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 639cdf0e10cSrcweir+ return( -1 ) ; 640cdf0e10cSrcweir+ } 641cdf0e10cSrcweir+ 642cdf0e10cSrcweir+ if( xmlSecMSCryptoX509StoreAdoptTrustedStore( x509Store, trustedStore ) < 0 ) { 643cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 644cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) , 645cdf0e10cSrcweir+ "xmlSecMSCryptoX509StoreAdoptKeyStore" , 646cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 647cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 648cdf0e10cSrcweir+ return( -1 ) ; 649cdf0e10cSrcweir+ } 650cdf0e10cSrcweir+ 651cdf0e10cSrcweir+ return( 0 ) ; 652cdf0e10cSrcweir+} 653cdf0e10cSrcweir+ 654cdf0e10cSrcweir+int 655cdf0e10cSrcweir+xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore ( 656cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 657cdf0e10cSrcweir+ HCERTSTORE untrustedStore 658cdf0e10cSrcweir+) { 659cdf0e10cSrcweir+ xmlSecKeyDataStorePtr x509Store ; 660cdf0e10cSrcweir+ 661cdf0e10cSrcweir+ xmlSecAssert2( mngr != NULL, -1 ) ; 662cdf0e10cSrcweir+ xmlSecAssert2( untrustedStore != NULL, -1 ) ; 663cdf0e10cSrcweir+ 664cdf0e10cSrcweir+ x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ; 665cdf0e10cSrcweir+ if( x509Store == NULL ) { 666cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 667cdf0e10cSrcweir+ NULL , 668cdf0e10cSrcweir+ "xmlSecKeysMngrGetDataStore" , 669cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 670cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 671cdf0e10cSrcweir+ return( -1 ) ; 672cdf0e10cSrcweir+ } 673cdf0e10cSrcweir+ 674cdf0e10cSrcweir+ if( xmlSecMSCryptoX509StoreAdoptUntrustedStore( x509Store, untrustedStore ) < 0 ) { 675cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 676cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) , 677cdf0e10cSrcweir+ "xmlSecMSCryptoX509StoreAdoptKeyStore" , 678cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 679cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 680cdf0e10cSrcweir+ return( -1 ) ; 681cdf0e10cSrcweir+ } 682cdf0e10cSrcweir+ 683cdf0e10cSrcweir+ return( 0 ) ; 684cdf0e10cSrcweir+} 685cdf0e10cSrcweir+ 686cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/Makefile.am 2009-06-25 22:53:18.000000000 +0200 687cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/Makefile.am 2009-09-21 14:02:48.591560472 +0200 688cdf0e10cSrcweir@@ -35,6 +35,9 @@ 689cdf0e10cSrcweir kw_des.c \ 690cdf0e10cSrcweir kw_aes.c \ 691cdf0e10cSrcweir globals.h \ 692cdf0e10cSrcweir+ akmngr.c \ 693cdf0e10cSrcweir+ keywrapers.c \ 694cdf0e10cSrcweir+ tokens.c \ 695cdf0e10cSrcweir $(NULL) 696cdf0e10cSrcweir 697cdf0e10cSrcweir if SHAREDLIB_HACK 698cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/Makefile.in 2009-06-25 22:53:33.000000000 +0200 699cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/Makefile.in 2009-09-21 14:02:48.599339718 +0200 700cdf0e10cSrcweir@@ -72,7 +72,8 @@ 701cdf0e10cSrcweir am__libxmlsec1_nss_la_SOURCES_DIST = app.c bignum.c ciphers.c crypto.c \ 702cdf0e10cSrcweir digests.c hmac.c pkikeys.c signatures.c symkeys.c x509.c \ 703cdf0e10cSrcweir x509vfy.c keysstore.c keytrans.c kw_des.c kw_aes.c globals.h \ 704cdf0e10cSrcweir- ../strings.c 705cdf0e10cSrcweir+ ../strings.c \ 706cdf0e10cSrcweir+ akmngr.c keywrapers.c tokens.c 707cdf0e10cSrcweir am__objects_1 = 708cdf0e10cSrcweir @SHAREDLIB_HACK_TRUE@am__objects_2 = libxmlsec1_nss_la-strings.lo 709cdf0e10cSrcweir am_libxmlsec1_nss_la_OBJECTS = libxmlsec1_nss_la-app.lo \ 710cdf0e10cSrcweir@@ -83,6 +84,8 @@ 711cdf0e10cSrcweir libxmlsec1_nss_la-x509.lo libxmlsec1_nss_la-x509vfy.lo \ 712cdf0e10cSrcweir libxmlsec1_nss_la-keysstore.lo libxmlsec1_nss_la-keytrans.lo \ 713cdf0e10cSrcweir libxmlsec1_nss_la-kw_des.lo libxmlsec1_nss_la-kw_aes.lo \ 714cdf0e10cSrcweir+ libxmlsec1_nss_la-akmngr.lo libxmlsec1_nss_la-keywrapers.lo \ 715cdf0e10cSrcweir+ libxmlsec1_nss_la-tokens.lo \ 716cdf0e10cSrcweir $(am__objects_1) $(am__objects_2) 717cdf0e10cSrcweir libxmlsec1_nss_la_OBJECTS = $(am_libxmlsec1_nss_la_OBJECTS) 718cdf0e10cSrcweir libxmlsec1_nss_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ 719cdf0e10cSrcweir@@ -333,6 +336,7 @@ 720cdf0e10cSrcweir libxmlsec1_nss_la_SOURCES = app.c bignum.c ciphers.c crypto.c \ 721cdf0e10cSrcweir digests.c hmac.c pkikeys.c signatures.c symkeys.c x509.c \ 722cdf0e10cSrcweir x509vfy.c keysstore.c keytrans.c kw_des.c kw_aes.c globals.h \ 723cdf0e10cSrcweir+ akmngr.c keywrapers.c tokens.c \ 724cdf0e10cSrcweir $(NULL) $(am__append_1) 725cdf0e10cSrcweir libxmlsec1_nss_la_LIBADD = \ 726cdf0e10cSrcweir ../libxmlsec1.la \ 727cdf0e10cSrcweir@@ -439,6 +443,9 @@ 728cdf0e10cSrcweir @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libxmlsec1_nss_la-symkeys.Plo@am__quote@ 729cdf0e10cSrcweir @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libxmlsec1_nss_la-x509.Plo@am__quote@ 730cdf0e10cSrcweir @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libxmlsec1_nss_la-x509vfy.Plo@am__quote@ 731cdf0e10cSrcweir+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libxmlsec1_nss_la-akmngr.Plo@am__quote@ 732cdf0e10cSrcweir+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libxmlsec1_nss_la-keywrapers.Plo@am__quote@ 733cdf0e10cSrcweir+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libxmlsec1_nss_la-tokens.Plo@am__quote@ 734cdf0e10cSrcweir 735cdf0e10cSrcweir .c.o: 736cdf0e10cSrcweir @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< 737cdf0e10cSrcweir@@ -468,6 +475,27 @@ 738cdf0e10cSrcweir @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 739cdf0e10cSrcweir @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libxmlsec1_nss_la-app.lo `test -f 'app.c' || echo '$(srcdir)/'`app.c 740cdf0e10cSrcweir 741cdf0e10cSrcweir+libxmlsec1_nss_la-akmngr.lo: akmngr.c 742cdf0e10cSrcweir+@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libxmlsec1_nss_la-akmngr.lo -MD -MP -MF "$(DEPDIR)/libxmlsec1_nss_la-akmngr.Tpo" -c -o libxmlsec1_nss_la-akmngr.lo `test -f 'akmngr.c' || echo '$(srcdir)/'`akmngr.c; \ 743cdf0e10cSrcweir+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libxmlsec1_nss_la-akmngr.Tpo" "$(DEPDIR)/libxmlsec1_nss_la-akmngr.Plo"; else rm -f "$(DEPDIR)/libxmlsec1_nss_la-akmngr.Tpo"; exit 1; fi 744cdf0e10cSrcweir+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='akmngr.c' object='libxmlsec1_nss_la-akmngr.lo' libtool=yes @AMDEPBACKSLASH@ 745cdf0e10cSrcweir+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 746cdf0e10cSrcweir+@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libxmlsec1_nss_la-akmngr.lo `test -f 'akmngr.c' || echo '$(srcdir)/'`akmngr.c 747cdf0e10cSrcweir+ 748cdf0e10cSrcweir+libxmlsec1_nss_la-keywrapers.lo: keywrapers.c 749cdf0e10cSrcweir+@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libxmlsec1_nss_la-keywrapers.lo -MD -MP -MF "$(DEPDIR)/libxmlsec1_nss_la-keywrapers.Tpo" -c -o libxmlsec1_nss_la-keywrapers.lo `test -f 'keywrapers.c' || echo '$(srcdir)/'`keywrapers.c; \ 750cdf0e10cSrcweir+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libxmlsec1_nss_la-keywrapers.Tpo" "$(DEPDIR)/libxmlsec1_nss_la-keywrapers.Plo"; else rm -f "$(DEPDIR)/libxmlsec1_nss_la-keywrapers.Tpo"; exit 1; fi 751cdf0e10cSrcweir+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='keywrapers.c' object='libxmlsec1_nss_la-keywrapers.lo' libtool=yes @AMDEPBACKSLASH@ 752cdf0e10cSrcweir+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 753cdf0e10cSrcweir+@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libxmlsec1_nss_la-keywrapers.lo `test -f 'keywrapers.c' || echo '$(srcdir)/'`keywrapers.c 754cdf0e10cSrcweir+ 755cdf0e10cSrcweir+libxmlsec1_nss_la-tokens.lo: tokens.c 756cdf0e10cSrcweir+@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libxmlsec1_nss_la-tokens.lo -MD -MP -MF "$(DEPDIR)/libxmlsec1_nss_la-tokens.Tpo" -c -o libxmlsec1_nss_la-tokens.lo `test -f 'tokens.c' || echo '$(srcdir)/'`tokens.c; \ 757cdf0e10cSrcweir+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libxmlsec1_nss_la-tokens.Tpo" "$(DEPDIR)/libxmlsec1_nss_la-tokens.Plo"; else rm -f "$(DEPDIR)/libxmlsec1_nss_la-tokens.Tpo"; exit 1; fi 758cdf0e10cSrcweir+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tokens.c' object='libxmlsec1_nss_la-tokens.lo' libtool=yes @AMDEPBACKSLASH@ 759cdf0e10cSrcweir+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 760cdf0e10cSrcweir+@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libxmlsec1_nss_la-tokens.lo `test -f 'tokens.c' || echo '$(srcdir)/'`tokens.c 761cdf0e10cSrcweir+ 762cdf0e10cSrcweir libxmlsec1_nss_la-bignum.lo: bignum.c 763cdf0e10cSrcweir @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libxmlsec1_nss_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libxmlsec1_nss_la-bignum.lo -MD -MP -MF $(DEPDIR)/libxmlsec1_nss_la-bignum.Tpo -c -o libxmlsec1_nss_la-bignum.lo `test -f 'bignum.c' || echo '$(srcdir)/'`bignum.c 764cdf0e10cSrcweir @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libxmlsec1_nss_la-bignum.Tpo $(DEPDIR)/libxmlsec1_nss_la-bignum.Plo 765cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/akmngr.c 2009-09-21 14:07:19.197249962 +0200 766cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/akmngr.c 2009-09-21 14:02:48.539616129 +0200 767cdf0e10cSrcweir@@ -1 +1,384 @@ 768cdf0e10cSrcweir-dummy 769cdf0e10cSrcweir+/** 770cdf0e10cSrcweir+ * XMLSec library 771cdf0e10cSrcweir+ * 772cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 773cdf0e10cSrcweir+ * distribution for preciese wording. 774cdf0e10cSrcweir+ * 775cdf0e10cSrcweir+ * Copyright......................... 776cdf0e10cSrcweir+ */ 777cdf0e10cSrcweir+#include "globals.h" 778cdf0e10cSrcweir+ 779cdf0e10cSrcweir+#include <nspr.h> 780cdf0e10cSrcweir+#include <nss.h> 781cdf0e10cSrcweir+#include <pk11func.h> 782cdf0e10cSrcweir+#include <cert.h> 783cdf0e10cSrcweir+#include <keyhi.h> 784cdf0e10cSrcweir+ 785cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 786cdf0e10cSrcweir+#include <xmlsec/keys.h> 787cdf0e10cSrcweir+#include <xmlsec/transforms.h> 788cdf0e10cSrcweir+#include <xmlsec/errors.h> 789cdf0e10cSrcweir+ 790cdf0e10cSrcweir+#include <xmlsec/nss/crypto.h> 791cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 792cdf0e10cSrcweir+#include <xmlsec/nss/akmngr.h> 793cdf0e10cSrcweir+#include <xmlsec/nss/pkikeys.h> 794cdf0e10cSrcweir+#include <xmlsec/nss/ciphers.h> 795cdf0e10cSrcweir+#include <xmlsec/nss/keysstore.h> 796cdf0e10cSrcweir+ 797cdf0e10cSrcweir+/** 798cdf0e10cSrcweir+ * xmlSecNssAppliedKeysMngrCreate: 799a893be29SPedro Giffuni+ * @slot: array of pointers to NSS PKCS#11 slot information. 800cdf0e10cSrcweir+ * @cSlots: number of slots in the array 801cdf0e10cSrcweir+ * @handler: the pointer to NSS certificate database. 802cdf0e10cSrcweir+ * 803cdf0e10cSrcweir+ * Create and load NSS crypto slot and certificate database into keys manager 804cdf0e10cSrcweir+ * 805cdf0e10cSrcweir+ * Returns keys manager pointer on success or NULL otherwise. 806cdf0e10cSrcweir+ */ 807cdf0e10cSrcweir+xmlSecKeysMngrPtr 808cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrCreate( 809cdf0e10cSrcweir+ PK11SlotInfo** slots, 810cdf0e10cSrcweir+ int cSlots, 811cdf0e10cSrcweir+ CERTCertDBHandle* handler 812cdf0e10cSrcweir+) { 813cdf0e10cSrcweir+ xmlSecKeyDataStorePtr certStore = NULL ; 814cdf0e10cSrcweir+ xmlSecKeysMngrPtr keyMngr = NULL ; 815cdf0e10cSrcweir+ xmlSecKeyStorePtr keyStore = NULL ; 816cdf0e10cSrcweir+ int islot = 0; 817cdf0e10cSrcweir+ keyStore = xmlSecKeyStoreCreate( xmlSecNssKeysStoreId ) ; 818cdf0e10cSrcweir+ if( keyStore == NULL ) { 819cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 820cdf0e10cSrcweir+ NULL , 821cdf0e10cSrcweir+ "xmlSecKeyStoreCreate" , 822cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 823cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 824cdf0e10cSrcweir+ return NULL ; 825cdf0e10cSrcweir+ } 826cdf0e10cSrcweir+ 827cdf0e10cSrcweir+ for (islot = 0; islot < cSlots; islot++) 828cdf0e10cSrcweir+ { 829cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot ; 830cdf0e10cSrcweir+ 831cdf0e10cSrcweir+ /* Create a key slot */ 832cdf0e10cSrcweir+ keySlot = xmlSecNssKeySlotCreate() ; 833cdf0e10cSrcweir+ if( keySlot == NULL ) { 834cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 835cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 836cdf0e10cSrcweir+ "xmlSecNssKeySlotCreate" , 837cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 838cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 839cdf0e10cSrcweir+ 840cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 841cdf0e10cSrcweir+ return NULL ; 842cdf0e10cSrcweir+ } 843cdf0e10cSrcweir+ 844cdf0e10cSrcweir+ /* Set slot */ 845cdf0e10cSrcweir+ if( xmlSecNssKeySlotSetSlot( keySlot , slots[islot] ) < 0 ) { 846cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 847cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 848cdf0e10cSrcweir+ "xmlSecNssKeySlotSetSlot" , 849cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 850cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 851cdf0e10cSrcweir+ 852cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 853cdf0e10cSrcweir+ xmlSecNssKeySlotDestroy( keySlot ) ; 854cdf0e10cSrcweir+ return NULL ; 855cdf0e10cSrcweir+ } 856cdf0e10cSrcweir+ 857cdf0e10cSrcweir+ /* Adopt keySlot */ 858cdf0e10cSrcweir+ if( xmlSecNssKeysStoreAdoptKeySlot( keyStore , keySlot ) < 0 ) { 859cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 860cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 861cdf0e10cSrcweir+ "xmlSecNssKeysStoreAdoptKeySlot" , 862cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 863cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 864cdf0e10cSrcweir+ 865cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 866cdf0e10cSrcweir+ xmlSecNssKeySlotDestroy( keySlot ) ; 867cdf0e10cSrcweir+ return NULL ; 868cdf0e10cSrcweir+ } 869cdf0e10cSrcweir+ } 870cdf0e10cSrcweir+ 871cdf0e10cSrcweir+ keyMngr = xmlSecKeysMngrCreate() ; 872cdf0e10cSrcweir+ if( keyMngr == NULL ) { 873cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 874cdf0e10cSrcweir+ NULL , 875cdf0e10cSrcweir+ "xmlSecKeysMngrCreate" , 876cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 877cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 878cdf0e10cSrcweir+ 879cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 880cdf0e10cSrcweir+ return NULL ; 881cdf0e10cSrcweir+ } 882cdf0e10cSrcweir+ 883cdf0e10cSrcweir+ /*- 884cdf0e10cSrcweir+ * Add key store to manager, from now on keys manager destroys the store if 885cdf0e10cSrcweir+ * needed 886cdf0e10cSrcweir+ */ 887cdf0e10cSrcweir+ if( xmlSecKeysMngrAdoptKeysStore( keyMngr, keyStore ) < 0 ) { 888cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 889cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 890cdf0e10cSrcweir+ "xmlSecKeysMngrAdoptKeyStore" , 891cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 892cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 893cdf0e10cSrcweir+ 894cdf0e10cSrcweir+ xmlSecKeyStoreDestroy( keyStore ) ; 895cdf0e10cSrcweir+ xmlSecKeysMngrDestroy( keyMngr ) ; 896cdf0e10cSrcweir+ return NULL ; 897cdf0e10cSrcweir+ } 898cdf0e10cSrcweir+ 899cdf0e10cSrcweir+ /*- 900cdf0e10cSrcweir+ * Initialize crypto library specific data in keys manager 901cdf0e10cSrcweir+ */ 902cdf0e10cSrcweir+ if( xmlSecNssKeysMngrInit( keyMngr ) < 0 ) { 903cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 904cdf0e10cSrcweir+ NULL , 905cdf0e10cSrcweir+ "xmlSecKeysMngrCreate" , 906cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 907cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 908cdf0e10cSrcweir+ 909cdf0e10cSrcweir+ xmlSecKeysMngrDestroy( keyMngr ) ; 910cdf0e10cSrcweir+ return NULL ; 911cdf0e10cSrcweir+ } 912cdf0e10cSrcweir+ 913cdf0e10cSrcweir+ /*- 914cdf0e10cSrcweir+ * Set certificate databse to X509 key data store 915cdf0e10cSrcweir+ */ 916cdf0e10cSrcweir+ /** 917cdf0e10cSrcweir+ * Because Tej's implementation of certDB use the default DB, so I ignore 918cdf0e10cSrcweir+ * the certDB handler at present. I'll modify the cert store sources to 919cdf0e10cSrcweir+ * accept particular certDB instead of default ones. 920cdf0e10cSrcweir+ certStore = xmlSecKeysMngrGetDataStore( keyMngr , xmlSecNssKeyDataStoreX509Id ) ; 921cdf0e10cSrcweir+ if( certStore == NULL ) { 922cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 923cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 924cdf0e10cSrcweir+ "xmlSecKeysMngrGetDataStore" , 925cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 926cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 927cdf0e10cSrcweir+ 928cdf0e10cSrcweir+ xmlSecKeysMngrDestroy( keyMngr ) ; 929cdf0e10cSrcweir+ return NULL ; 930cdf0e10cSrcweir+ } 931cdf0e10cSrcweir+ 932cdf0e10cSrcweir+ if( xmlSecNssKeyDataStoreX509SetCertDb( certStore , handler ) < 0 ) { 933cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 934cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) , 935cdf0e10cSrcweir+ "xmlSecNssKeyDataStoreX509SetCertDb" , 936cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 937cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 938cdf0e10cSrcweir+ 939cdf0e10cSrcweir+ xmlSecKeysMngrDestroy( keyMngr ) ; 940cdf0e10cSrcweir+ return NULL ; 941cdf0e10cSrcweir+ } 942cdf0e10cSrcweir+ */ 943cdf0e10cSrcweir+ 944cdf0e10cSrcweir+ /*- 945cdf0e10cSrcweir+ * Set the getKey callback 946cdf0e10cSrcweir+ */ 947cdf0e10cSrcweir+ keyMngr->getKey = xmlSecKeysMngrGetKey ; 948cdf0e10cSrcweir+ 949cdf0e10cSrcweir+ return keyMngr ; 950cdf0e10cSrcweir+} 951cdf0e10cSrcweir+ 952cdf0e10cSrcweir+int 953cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrSymKeyLoad( 954cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 955cdf0e10cSrcweir+ PK11SymKey* symKey 956cdf0e10cSrcweir+) { 957cdf0e10cSrcweir+ xmlSecKeyPtr key ; 958cdf0e10cSrcweir+ xmlSecKeyDataPtr data ; 959cdf0e10cSrcweir+ xmlSecKeyStorePtr keyStore ; 960cdf0e10cSrcweir+ 961cdf0e10cSrcweir+ xmlSecAssert2( mngr != NULL , -1 ) ; 962cdf0e10cSrcweir+ xmlSecAssert2( symKey != NULL , -1 ) ; 963cdf0e10cSrcweir+ 964cdf0e10cSrcweir+ keyStore = xmlSecKeysMngrGetKeysStore( mngr ) ; 965cdf0e10cSrcweir+ if( keyStore == NULL ) { 966cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 967cdf0e10cSrcweir+ NULL , 968cdf0e10cSrcweir+ "xmlSecKeysMngrGetKeysStore" , 969cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 970cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 971cdf0e10cSrcweir+ return(-1) ; 972cdf0e10cSrcweir+ } 973cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( keyStore , xmlSecNssKeysStoreId ) , -1 ) ; 974cdf0e10cSrcweir+ 975cdf0e10cSrcweir+ data = xmlSecNssSymKeyDataKeyAdopt( symKey ) ; 976cdf0e10cSrcweir+ if( data == NULL ) { 977cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 978cdf0e10cSrcweir+ NULL , 979cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 980cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 981cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 982cdf0e10cSrcweir+ return(-1) ; 983cdf0e10cSrcweir+ } 984cdf0e10cSrcweir+ 985cdf0e10cSrcweir+ key = xmlSecKeyCreate() ; 986cdf0e10cSrcweir+ if( key == NULL ) { 987cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 988cdf0e10cSrcweir+ NULL , 989cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 990cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 991cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 992cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 993cdf0e10cSrcweir+ return(-1) ; 994cdf0e10cSrcweir+ } 995cdf0e10cSrcweir+ 996cdf0e10cSrcweir+ if( xmlSecKeySetValue( key , data ) < 0 ) { 997cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 998cdf0e10cSrcweir+ NULL , 999cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1000cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1001cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1002cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1003cdf0e10cSrcweir+ return(-1) ; 1004cdf0e10cSrcweir+ } 1005cdf0e10cSrcweir+ 1006cdf0e10cSrcweir+ if( xmlSecNssKeysStoreAdoptKey( keyStore, key ) < 0 ) { 1007cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1008cdf0e10cSrcweir+ NULL , 1009cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1010cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1011cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1012cdf0e10cSrcweir+ xmlSecKeyDestroy( key ) ; 1013cdf0e10cSrcweir+ return(-1) ; 1014cdf0e10cSrcweir+ } 1015cdf0e10cSrcweir+ 1016cdf0e10cSrcweir+ return(0) ; 1017cdf0e10cSrcweir+} 1018cdf0e10cSrcweir+ 1019cdf0e10cSrcweir+int 1020cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrPubKeyLoad( 1021cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 1022cdf0e10cSrcweir+ SECKEYPublicKey* pubKey 1023cdf0e10cSrcweir+) { 1024cdf0e10cSrcweir+ xmlSecKeyPtr key ; 1025cdf0e10cSrcweir+ xmlSecKeyDataPtr data ; 1026cdf0e10cSrcweir+ xmlSecKeyStorePtr keyStore ; 1027cdf0e10cSrcweir+ 1028cdf0e10cSrcweir+ xmlSecAssert2( mngr != NULL , -1 ) ; 1029cdf0e10cSrcweir+ xmlSecAssert2( pubKey != NULL , -1 ) ; 1030cdf0e10cSrcweir+ 1031cdf0e10cSrcweir+ keyStore = xmlSecKeysMngrGetKeysStore( mngr ) ; 1032cdf0e10cSrcweir+ if( keyStore == NULL ) { 1033cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1034cdf0e10cSrcweir+ NULL , 1035cdf0e10cSrcweir+ "xmlSecKeysMngrGetKeysStore" , 1036cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1037cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1038cdf0e10cSrcweir+ return(-1) ; 1039cdf0e10cSrcweir+ } 1040cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( keyStore , xmlSecNssKeysStoreId ) , -1 ) ; 1041cdf0e10cSrcweir+ 1042cdf0e10cSrcweir+ data = xmlSecNssPKIAdoptKey( NULL, pubKey ) ; 1043cdf0e10cSrcweir+ if( data == NULL ) { 1044cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1045cdf0e10cSrcweir+ NULL , 1046cdf0e10cSrcweir+ "xmlSecNssPKIAdoptKey" , 1047cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1048cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1049cdf0e10cSrcweir+ return(-1) ; 1050cdf0e10cSrcweir+ } 1051cdf0e10cSrcweir+ 1052cdf0e10cSrcweir+ key = xmlSecKeyCreate() ; 1053cdf0e10cSrcweir+ if( key == NULL ) { 1054cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1055cdf0e10cSrcweir+ NULL , 1056cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1057cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1058cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1059cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1060cdf0e10cSrcweir+ return(-1) ; 1061cdf0e10cSrcweir+ } 1062cdf0e10cSrcweir+ 1063cdf0e10cSrcweir+ if( xmlSecKeySetValue( key , data ) < 0 ) { 1064cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1065cdf0e10cSrcweir+ NULL , 1066cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1067cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1068cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1069cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1070cdf0e10cSrcweir+ return(-1) ; 1071cdf0e10cSrcweir+ } 1072cdf0e10cSrcweir+ 1073cdf0e10cSrcweir+ if( xmlSecNssKeysStoreAdoptKey( keyStore, key ) < 0 ) { 1074cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1075cdf0e10cSrcweir+ NULL , 1076cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1077cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1078cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1079cdf0e10cSrcweir+ xmlSecKeyDestroy( key ) ; 1080cdf0e10cSrcweir+ return(-1) ; 1081cdf0e10cSrcweir+ } 1082cdf0e10cSrcweir+ 1083cdf0e10cSrcweir+ return(0) ; 1084cdf0e10cSrcweir+} 1085cdf0e10cSrcweir+ 1086cdf0e10cSrcweir+int 1087cdf0e10cSrcweir+xmlSecNssAppliedKeysMngrPriKeyLoad( 1088cdf0e10cSrcweir+ xmlSecKeysMngrPtr mngr , 1089cdf0e10cSrcweir+ SECKEYPrivateKey* priKey 1090cdf0e10cSrcweir+) { 1091cdf0e10cSrcweir+ xmlSecKeyPtr key ; 1092cdf0e10cSrcweir+ xmlSecKeyDataPtr data ; 1093cdf0e10cSrcweir+ xmlSecKeyStorePtr keyStore ; 1094cdf0e10cSrcweir+ 1095cdf0e10cSrcweir+ xmlSecAssert2( mngr != NULL , -1 ) ; 1096cdf0e10cSrcweir+ xmlSecAssert2( priKey != NULL , -1 ) ; 1097cdf0e10cSrcweir+ 1098cdf0e10cSrcweir+ keyStore = xmlSecKeysMngrGetKeysStore( mngr ) ; 1099cdf0e10cSrcweir+ if( keyStore == NULL ) { 1100cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1101cdf0e10cSrcweir+ NULL , 1102cdf0e10cSrcweir+ "xmlSecKeysMngrGetKeysStore" , 1103cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1104cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1105cdf0e10cSrcweir+ return(-1) ; 1106cdf0e10cSrcweir+ } 1107cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( keyStore , xmlSecNssKeysStoreId ) , -1 ) ; 1108cdf0e10cSrcweir+ 1109cdf0e10cSrcweir+ data = xmlSecNssPKIAdoptKey( priKey, NULL ) ; 1110cdf0e10cSrcweir+ if( data == NULL ) { 1111cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1112cdf0e10cSrcweir+ NULL , 1113cdf0e10cSrcweir+ "xmlSecNssPKIAdoptKey" , 1114cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1115cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1116cdf0e10cSrcweir+ return(-1) ; 1117cdf0e10cSrcweir+ } 1118cdf0e10cSrcweir+ 1119cdf0e10cSrcweir+ key = xmlSecKeyCreate() ; 1120cdf0e10cSrcweir+ if( key == NULL ) { 1121cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1122cdf0e10cSrcweir+ NULL , 1123cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1124cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1125cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1126cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1127cdf0e10cSrcweir+ return(-1) ; 1128cdf0e10cSrcweir+ } 1129cdf0e10cSrcweir+ 1130cdf0e10cSrcweir+ if( xmlSecKeySetValue( key , data ) < 0 ) { 1131cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1132cdf0e10cSrcweir+ NULL , 1133cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1134cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1135cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1136cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1137cdf0e10cSrcweir+ return(-1) ; 1138cdf0e10cSrcweir+ } 1139cdf0e10cSrcweir+ 1140cdf0e10cSrcweir+ if( xmlSecNssKeysStoreAdoptKey( keyStore, key ) < 0 ) { 1141cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1142cdf0e10cSrcweir+ NULL , 1143cdf0e10cSrcweir+ "xmlSecNssSymKeyDataKeyAdopt" , 1144cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1145cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1146cdf0e10cSrcweir+ xmlSecKeyDestroy( key ) ; 1147cdf0e10cSrcweir+ return(-1) ; 1148cdf0e10cSrcweir+ } 1149cdf0e10cSrcweir+ 1150cdf0e10cSrcweir+ return(0) ; 1151cdf0e10cSrcweir+} 1152cdf0e10cSrcweir+ 1153cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/hmac.c 2009-06-26 06:18:13.000000000 +0200 1154cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/hmac.c 2009-09-21 14:02:48.649065288 +0200 1155cdf0e10cSrcweir@@ -23,8 +23,8 @@ 1156cdf0e10cSrcweir #include <xmlsec/transforms.h> 1157cdf0e10cSrcweir #include <xmlsec/errors.h> 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir-#include <xmlsec/nss/app.h> 1160cdf0e10cSrcweir #include <xmlsec/nss/crypto.h> 1161cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir /* sizes in bits */ 1164cdf0e10cSrcweir #define XMLSEC_NSS_MIN_HMAC_SIZE 80 1165cdf0e10cSrcweir@@ -286,13 +286,13 @@ 1166cdf0e10cSrcweir keyItem.data = xmlSecBufferGetData(buffer); 1167cdf0e10cSrcweir keyItem.len = xmlSecBufferGetSize(buffer); 1168cdf0e10cSrcweir 1169cdf0e10cSrcweir- slot = PK11_GetBestSlot(ctx->digestType, NULL); 1170cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(ctx->digestType); 1171cdf0e10cSrcweir if(slot == NULL) { 1172cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 1173cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), 1174cdf0e10cSrcweir- "PK11_GetBestSlot", 1175cdf0e10cSrcweir+ "xmlSecNssSlotGet", 1176cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 1177cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 1178cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 1179cdf0e10cSrcweir return(-1); 1180cdf0e10cSrcweir } 1181cdf0e10cSrcweir 1182cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/keysstore.c 2009-06-25 22:53:18.000000000 +0200 1183cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/keysstore.c 2009-09-21 14:02:48.633533885 +0200 1184cdf0e10cSrcweir@@ -1,36 +1,56 @@ 1185cdf0e10cSrcweir /** 1186cdf0e10cSrcweir * XMLSec library 1187cdf0e10cSrcweir * 1188cdf0e10cSrcweir- * Nss keys store that uses Simple Keys Store under the hood. Uses the 1189cdf0e10cSrcweir- * Nss DB as a backing store for the finding keys, but the NSS DB is 1190cdf0e10cSrcweir- * not written to by the keys store. 1191cdf0e10cSrcweir- * So, if store->findkey is done and the key is not found in the simple 1192cdf0e10cSrcweir- * keys store, the NSS DB is looked up. 1193cdf0e10cSrcweir- * If store is called to adopt a key, that key is not written to the NSS 1194cdf0e10cSrcweir- * DB. 1195cdf0e10cSrcweir- * Thus, the NSS DB can be used to pre-load keys and becomes an alternate 1196cdf0e10cSrcweir- * source of keys for xmlsec 1197cdf0e10cSrcweir- * 1198cdf0e10cSrcweir * This is free software; see Copyright file in the source 1199cdf0e10cSrcweir * distribution for precise wording. 1200cdf0e10cSrcweir * 1201cdf0e10cSrcweir * Copyright (c) 2003 America Online, Inc. All rights reserved. 1202cdf0e10cSrcweir */ 1203cdf0e10cSrcweir+ 1204cdf0e10cSrcweir+/** 1205cdf0e10cSrcweir+ * NSS key store uses a key list and a slot list as the key repository. NSS slot 1206cdf0e10cSrcweir+ * list is a backup repository for the finding keys. If a key is not found from 1207cdf0e10cSrcweir+ * the key list, the NSS slot list is looked up. 1208cdf0e10cSrcweir+ * 1209cdf0e10cSrcweir+ * Any key in the key list will not save to pkcs11 slot. When a store to called 1210cdf0e10cSrcweir+ * to adopt a key, the key is resident in the key list; While a store to called 1211cdf0e10cSrcweir+ * to set a is resident in the key list; While a store to called to set a slot 1212cdf0e10cSrcweir+ * list, which means that the keys in the listed slot can be used for xml sign- 1213cdf0e10cSrcweir+ * nature or encryption. 1214cdf0e10cSrcweir+ * 1215cdf0e10cSrcweir+ * Then, a user can adjust slot list to effect the crypto behaviors of xmlSec. 1216cdf0e10cSrcweir+ * 1217cdf0e10cSrcweir+ * The framework will decrease the user interfaces to administrate xmlSec crypto 1218cdf0e10cSrcweir+ * engine. He can only focus on NSS layer functions. For examples, after the 1219cdf0e10cSrcweir+ * user set up a slot list handler to the keys store, he do not need to do any 1220cdf0e10cSrcweir+ * other work atop xmlSec interfaces, his action on the slot list handler, such 1221cdf0e10cSrcweir+ * as add a token to, delete a token from the list, will directly effect the key 1222cdf0e10cSrcweir+ * store behaviors. 1223cdf0e10cSrcweir+ * 1224cdf0e10cSrcweir+ * For example, a scenariio: 1225cdf0e10cSrcweir+ * 0. Create a slot list;( NSS interfaces ) 1226cdf0e10cSrcweir+ * 1. Create a keys store;( xmlSec interfaces ) 1227cdf0e10cSrcweir+ * 2. Set slot list with the keys store;( xmlSec Interfaces ) 1228cdf0e10cSrcweir+ * 3. Add a slot to the slot list;( NSS interfaces ) 1229cdf0e10cSrcweir+ * 4. Perform xml signature; ( xmlSec Interfaces ) 1230cdf0e10cSrcweir+ * 5. Deleter a slot from the slot list;( NSS interfaces ) 1231cdf0e10cSrcweir+ * 6. Perform xml encryption; ( xmlSec Interfaces ) 1232cdf0e10cSrcweir+ * 7. Perform xml signature;( xmlSec Interfaces ) 1233cdf0e10cSrcweir+ * 8. Destroy the keys store;( xmlSec Interfaces ) 1234cdf0e10cSrcweir+ * 8. Destroy the slot list.( NSS Interfaces ) 1235cdf0e10cSrcweir+ */ 1236cdf0e10cSrcweir #include "globals.h" 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir #include <stdlib.h> 1239cdf0e10cSrcweir #include <string.h> 1240cdf0e10cSrcweir 1241cdf0e10cSrcweir #include <nss.h> 1242cdf0e10cSrcweir-#include <cert.h> 1243cdf0e10cSrcweir #include <pk11func.h> 1244cdf0e10cSrcweir+#include <prinit.h> 1245cdf0e10cSrcweir #include <keyhi.h> 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir-#include <libxml/tree.h> 1248cdf0e10cSrcweir- 1249cdf0e10cSrcweir #include <xmlsec/xmlsec.h> 1250cdf0e10cSrcweir-#include <xmlsec/buffer.h> 1251cdf0e10cSrcweir-#include <xmlsec/base64.h> 1252cdf0e10cSrcweir+#include <xmlsec/keys.h> 1253cdf0e10cSrcweir #include <xmlsec/errors.h> 1254cdf0e10cSrcweir #include <xmlsec/xmltree.h> 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir@@ -38,82 +58,461 @@ 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir #include <xmlsec/nss/crypto.h> 1259cdf0e10cSrcweir #include <xmlsec/nss/keysstore.h> 1260cdf0e10cSrcweir-#include <xmlsec/nss/x509.h> 1261cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 1262cdf0e10cSrcweir+#include <xmlsec/nss/ciphers.h> 1263cdf0e10cSrcweir #include <xmlsec/nss/pkikeys.h> 1264cdf0e10cSrcweir 1265cdf0e10cSrcweir /**************************************************************************** 1266cdf0e10cSrcweir * 1267cdf0e10cSrcweir- * Nss Keys Store. Uses Simple Keys Store under the hood 1268cdf0e10cSrcweir+ * Internal NSS key store context 1269cdf0e10cSrcweir * 1270cdf0e10cSrcweir- * Simple Keys Store ptr is located after xmlSecKeyStore 1271cdf0e10cSrcweir+ * This context is located after xmlSecKeyStore 1272cdf0e10cSrcweir * 1273cdf0e10cSrcweir ***************************************************************************/ 1274cdf0e10cSrcweir+typedef struct _xmlSecNssKeysStoreCtx xmlSecNssKeysStoreCtx ; 1275cdf0e10cSrcweir+typedef struct _xmlSecNssKeysStoreCtx* xmlSecNssKeysStoreCtxPtr ; 1276cdf0e10cSrcweir+ 1277cdf0e10cSrcweir+struct _xmlSecNssKeysStoreCtx { 1278cdf0e10cSrcweir+ xmlSecPtrListPtr keyList ; 1279cdf0e10cSrcweir+ xmlSecPtrListPtr slotList ; 1280cdf0e10cSrcweir+} ; 1281cdf0e10cSrcweir+ 1282cdf0e10cSrcweir #define xmlSecNssKeysStoreSize \ 1283cdf0e10cSrcweir- (sizeof(xmlSecKeyStore) + sizeof(xmlSecKeyStorePtr)) 1284cdf0e10cSrcweir+ ( sizeof( xmlSecKeyStore ) + sizeof( xmlSecNssKeysStoreCtx ) ) 1285cdf0e10cSrcweir 1286cdf0e10cSrcweir-#define xmlSecNssKeysStoreGetSS(store) \ 1287cdf0e10cSrcweir- ((xmlSecKeyStoreCheckSize((store), xmlSecNssKeysStoreSize)) ? \ 1288cdf0e10cSrcweir- (xmlSecKeyStorePtr*)(((xmlSecByte*)(store)) + sizeof(xmlSecKeyStore)) : \ 1289cdf0e10cSrcweir- (xmlSecKeyStorePtr*)NULL) 1290cdf0e10cSrcweir- 1291cdf0e10cSrcweir-static int xmlSecNssKeysStoreInitialize (xmlSecKeyStorePtr store); 1292cdf0e10cSrcweir-static void xmlSecNssKeysStoreFinalize (xmlSecKeyStorePtr store); 1293cdf0e10cSrcweir-static xmlSecKeyPtr xmlSecNssKeysStoreFindKey (xmlSecKeyStorePtr store, 1294cdf0e10cSrcweir- const xmlChar* name, 1295cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx); 1296cdf0e10cSrcweir+#define xmlSecNssKeysStoreGetCtx( data ) \ 1297cdf0e10cSrcweir+ ( ( xmlSecNssKeysStoreCtxPtr )( ( ( xmlSecByte* )( data ) ) + sizeof( xmlSecKeyStore ) ) ) 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir-static xmlSecKeyStoreKlass xmlSecNssKeysStoreKlass = { 1300cdf0e10cSrcweir- sizeof(xmlSecKeyStoreKlass), 1301cdf0e10cSrcweir- xmlSecNssKeysStoreSize, 1302cdf0e10cSrcweir+int xmlSecNssKeysStoreAdoptKeySlot( 1303cdf0e10cSrcweir+ xmlSecKeyStorePtr store , 1304cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 1305cdf0e10cSrcweir+) { 1306cdf0e10cSrcweir+ xmlSecNssKeysStoreCtxPtr context = NULL ; 1307cdf0e10cSrcweir+ 1308cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( store , xmlSecNssKeysStoreId ) , -1 ) ; 1309cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckSize( store , xmlSecNssKeysStoreSize ) , -1 ) ; 1310cdf0e10cSrcweir+ context = xmlSecNssKeysStoreGetCtx( store ) ; 1311cdf0e10cSrcweir+ if( context == NULL ) { 1312cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1313cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1314cdf0e10cSrcweir+ "xmlSecNssKeysStoreGetCtx" , 1315cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1316cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1317cdf0e10cSrcweir+ return -1 ; 1318cdf0e10cSrcweir+ } 1319cdf0e10cSrcweir+ 1320cdf0e10cSrcweir+ if( context->slotList == NULL ) { 1321cdf0e10cSrcweir+ if( ( context->slotList = xmlSecPtrListCreate( xmlSecNssKeySlotListId ) ) == NULL ) { 1322cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1323cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1324cdf0e10cSrcweir+ "xmlSecPtrListCreate" , 1325cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1326cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1327cdf0e10cSrcweir+ return -1 ; 1328cdf0e10cSrcweir+ } 1329cdf0e10cSrcweir+ } 1330cdf0e10cSrcweir+ 1331cdf0e10cSrcweir+ if( !xmlSecPtrListCheckId( context->slotList , xmlSecNssKeySlotListId ) ) { 1332cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1333cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1334cdf0e10cSrcweir+ "xmlSecPtrListCheckId" , 1335cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1336cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1337cdf0e10cSrcweir+ return -1 ; 1338cdf0e10cSrcweir+ } 1339cdf0e10cSrcweir+ 1340cdf0e10cSrcweir+ if( xmlSecPtrListAdd( context->slotList , keySlot ) < 0 ) { 1341cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1342cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1343cdf0e10cSrcweir+ "xmlSecPtrListAdd" , 1344cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1345cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1346cdf0e10cSrcweir+ return -1 ; 1347cdf0e10cSrcweir+ } 1348cdf0e10cSrcweir+ return 0 ; 1349cdf0e10cSrcweir+} 1350cdf0e10cSrcweir 1351cdf0e10cSrcweir- /* data */ 1352cdf0e10cSrcweir- BAD_CAST "NSS-keys-store", /* const xmlChar* name; */ 1353cdf0e10cSrcweir- 1354cdf0e10cSrcweir- /* constructors/destructor */ 1355cdf0e10cSrcweir- xmlSecNssKeysStoreInitialize, /* xmlSecKeyStoreInitializeMethod initialize; */ 1356cdf0e10cSrcweir- xmlSecNssKeysStoreFinalize, /* xmlSecKeyStoreFinalizeMethod finalize; */ 1357cdf0e10cSrcweir- xmlSecNssKeysStoreFindKey, /* xmlSecKeyStoreFindKeyMethod findKey; */ 1358cdf0e10cSrcweir- 1359cdf0e10cSrcweir- /* reserved for the future */ 1360cdf0e10cSrcweir- NULL, /* void* reserved0; */ 1361cdf0e10cSrcweir- NULL, /* void* reserved1; */ 1362cdf0e10cSrcweir-}; 1363cdf0e10cSrcweir+int xmlSecNssKeysStoreAdoptKey( 1364cdf0e10cSrcweir+ xmlSecKeyStorePtr store , 1365cdf0e10cSrcweir+ xmlSecKeyPtr key 1366cdf0e10cSrcweir+) { 1367cdf0e10cSrcweir+ xmlSecNssKeysStoreCtxPtr context = NULL ; 1368cdf0e10cSrcweir+ 1369cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( store , xmlSecNssKeysStoreId ) , -1 ) ; 1370cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckSize( store , xmlSecNssKeysStoreSize ) , -1 ) ; 1371cdf0e10cSrcweir+ 1372cdf0e10cSrcweir+ context = xmlSecNssKeysStoreGetCtx( store ) ; 1373cdf0e10cSrcweir+ if( context == NULL ) { 1374cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1375cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1376cdf0e10cSrcweir+ "xmlSecNssKeysStoreGetCtx" , 1377cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1378cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1379cdf0e10cSrcweir+ return -1 ; 1380cdf0e10cSrcweir+ } 1381cdf0e10cSrcweir+ 1382cdf0e10cSrcweir+ if( context->keyList == NULL ) { 1383cdf0e10cSrcweir+ if( ( context->keyList = xmlSecPtrListCreate( xmlSecKeyPtrListId ) ) == NULL ) { 1384cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1385cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1386cdf0e10cSrcweir+ "xmlSecPtrListCreate" , 1387cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1388cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1389cdf0e10cSrcweir+ return -1 ; 1390cdf0e10cSrcweir+ } 1391cdf0e10cSrcweir+ } 1392cdf0e10cSrcweir+ 1393cdf0e10cSrcweir+ if( !xmlSecPtrListCheckId( context->keyList , xmlSecKeyPtrListId ) ) { 1394cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1395cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1396cdf0e10cSrcweir+ "xmlSecPtrListCheckId" , 1397cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1398cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1399cdf0e10cSrcweir+ return -1 ; 1400cdf0e10cSrcweir+ } 1401cdf0e10cSrcweir+ 1402cdf0e10cSrcweir+ if( xmlSecPtrListAdd( context->keyList , key ) < 0 ) { 1403cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1404cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1405cdf0e10cSrcweir+ "xmlSecPtrListAdd" , 1406cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1407cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1408cdf0e10cSrcweir+ return -1 ; 1409cdf0e10cSrcweir+ } 1410cdf0e10cSrcweir 1411cdf0e10cSrcweir-/** 1412cdf0e10cSrcweir- * xmlSecNssKeysStoreGetKlass: 1413cdf0e10cSrcweir- * 1414cdf0e10cSrcweir- * The Nss list based keys store klass. 1415cdf0e10cSrcweir+ return 0 ; 1416cdf0e10cSrcweir+} 1417cdf0e10cSrcweir+ 1418cdf0e10cSrcweir+/* 1419cdf0e10cSrcweir+ * xmlSecKeyStoreInitializeMethod: 1420cdf0e10cSrcweir+ * @store: the store. 1421cdf0e10cSrcweir+ * 1422cdf0e10cSrcweir+ * Keys store specific initialization method. 1423cdf0e10cSrcweir * 1424cdf0e10cSrcweir- * Returns: Nss list based keys store klass. 1425cdf0e10cSrcweir+ * Returns 0 on success or a negative value if an error occurs. 1426cdf0e10cSrcweir */ 1427cdf0e10cSrcweir-xmlSecKeyStoreId 1428cdf0e10cSrcweir-xmlSecNssKeysStoreGetKlass(void) { 1429cdf0e10cSrcweir- return(&xmlSecNssKeysStoreKlass); 1430cdf0e10cSrcweir+static int 1431cdf0e10cSrcweir+xmlSecNssKeysStoreInitialize( 1432cdf0e10cSrcweir+ xmlSecKeyStorePtr store 1433cdf0e10cSrcweir+) { 1434cdf0e10cSrcweir+ xmlSecNssKeysStoreCtxPtr context = NULL ; 1435cdf0e10cSrcweir+ 1436cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( store , xmlSecNssKeysStoreId ) , -1 ) ; 1437cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckSize( store , xmlSecNssKeysStoreSize ) , -1 ) ; 1438cdf0e10cSrcweir+ 1439cdf0e10cSrcweir+ context = xmlSecNssKeysStoreGetCtx( store ) ; 1440cdf0e10cSrcweir+ if( context == NULL ) { 1441cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1442cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1443cdf0e10cSrcweir+ "xmlSecNssKeysStoreGetCtx" , 1444cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1445cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1446cdf0e10cSrcweir+ return -1 ; 1447cdf0e10cSrcweir+ } 1448cdf0e10cSrcweir+ 1449cdf0e10cSrcweir+ context->keyList = NULL ; 1450cdf0e10cSrcweir+ context->slotList = NULL ; 1451cdf0e10cSrcweir+ 1452cdf0e10cSrcweir+ return 0 ; 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir /** 1456cdf0e10cSrcweir- * xmlSecNssKeysStoreAdoptKey: 1457cdf0e10cSrcweir- * @store: the pointer to Nss keys store. 1458cdf0e10cSrcweir- * @key: the pointer to key. 1459cdf0e10cSrcweir- * 1460cdf0e10cSrcweir- * Adds @key to the @store. 1461cdf0e10cSrcweir * 1462cdf0e10cSrcweir- * Returns: 0 on success or a negative value if an error occurs. 1463cdf0e10cSrcweir+ * xmlSecKeyStoreFinalizeMethod: 1464cdf0e10cSrcweir+ * @store: the store. 1465cdf0e10cSrcweir+ * 1466cdf0e10cSrcweir+ * Keys store specific finalization (destroy) method. 1467cdf0e10cSrcweir */ 1468cdf0e10cSrcweir-int 1469cdf0e10cSrcweir-xmlSecNssKeysStoreAdoptKey(xmlSecKeyStorePtr store, xmlSecKeyPtr key) { 1470cdf0e10cSrcweir- xmlSecKeyStorePtr *ss; 1471cdf0e10cSrcweir- 1472cdf0e10cSrcweir- xmlSecAssert2(xmlSecKeyStoreCheckId(store, xmlSecNssKeysStoreId), -1); 1473cdf0e10cSrcweir- xmlSecAssert2((key != NULL), -1); 1474cdf0e10cSrcweir+void 1475cdf0e10cSrcweir+xmlSecNssKeysStoreFinalize( 1476cdf0e10cSrcweir+ xmlSecKeyStorePtr store 1477cdf0e10cSrcweir+) { 1478cdf0e10cSrcweir+ xmlSecNssKeysStoreCtxPtr context = NULL ; 1479cdf0e10cSrcweir+ 1480cdf0e10cSrcweir+ xmlSecAssert( xmlSecKeyStoreCheckId( store , xmlSecNssKeysStoreId ) ) ; 1481cdf0e10cSrcweir+ xmlSecAssert( xmlSecKeyStoreCheckSize( store , xmlSecNssKeysStoreSize ) ) ; 1482cdf0e10cSrcweir+ 1483cdf0e10cSrcweir+ context = xmlSecNssKeysStoreGetCtx( store ) ; 1484cdf0e10cSrcweir+ if( context == NULL ) { 1485cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1486cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1487cdf0e10cSrcweir+ "xmlSecNssKeysStoreGetCtx" , 1488cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1489cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1490cdf0e10cSrcweir+ return ; 1491cdf0e10cSrcweir+ } 1492cdf0e10cSrcweir+ 1493cdf0e10cSrcweir+ if( context->keyList != NULL ) { 1494cdf0e10cSrcweir+ xmlSecPtrListDestroy( context->keyList ) ; 1495cdf0e10cSrcweir+ context->keyList = NULL ; 1496cdf0e10cSrcweir+ } 1497cdf0e10cSrcweir+ 1498cdf0e10cSrcweir+ if( context->slotList != NULL ) { 1499cdf0e10cSrcweir+ xmlSecPtrListDestroy( context->slotList ) ; 1500cdf0e10cSrcweir+ context->slotList = NULL ; 1501cdf0e10cSrcweir+ } 1502cdf0e10cSrcweir+} 1503cdf0e10cSrcweir+ 1504cdf0e10cSrcweir+xmlSecKeyPtr 1505cdf0e10cSrcweir+xmlSecNssKeysStoreFindKeyFromSlot( 1506cdf0e10cSrcweir+ PK11SlotInfo* slot, 1507cdf0e10cSrcweir+ const xmlChar* name, 1508cdf0e10cSrcweir+ xmlSecKeyInfoCtxPtr keyInfoCtx 1509cdf0e10cSrcweir+) { 1510cdf0e10cSrcweir+ xmlSecKeyPtr key = NULL ; 1511cdf0e10cSrcweir+ xmlSecKeyDataPtr data = NULL ; 1512cdf0e10cSrcweir+ int length ; 1513cdf0e10cSrcweir+ 1514cdf0e10cSrcweir+ xmlSecAssert2( slot != NULL , NULL ) ; 1515cdf0e10cSrcweir+ xmlSecAssert2( name != NULL , NULL ) ; 1516cdf0e10cSrcweir+ xmlSecAssert2( keyInfoCtx != NULL , NULL ) ; 1517cdf0e10cSrcweir+ 1518cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyType & xmlSecKeyDataTypeSymmetric ) == xmlSecKeyDataTypeSymmetric ) { 1519cdf0e10cSrcweir+ PK11SymKey* symKey ; 1520cdf0e10cSrcweir+ PK11SymKey* curKey ; 1521cdf0e10cSrcweir+ 1522cdf0e10cSrcweir+ /* Find symmetric key from the slot by name */ 1523cdf0e10cSrcweir+ symKey = PK11_ListFixedKeysInSlot( slot , ( char* )name , NULL ) ; 1524cdf0e10cSrcweir+ for( curKey = symKey ; curKey != NULL ; curKey = PK11_GetNextSymKey( curKey ) ) { 1525cdf0e10cSrcweir+ /* Check the key request */ 1526cdf0e10cSrcweir+ length = PK11_GetKeyLength( curKey ) ; 1527cdf0e10cSrcweir+ length *= 8 ; 1528cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyBitsSize > 0 ) && 1529cdf0e10cSrcweir+ ( length > 0 ) && 1530cdf0e10cSrcweir+ ( length < keyInfoCtx->keyReq.keyBitsSize ) ) 1531cdf0e10cSrcweir+ continue ; 1532cdf0e10cSrcweir+ 1533cdf0e10cSrcweir+ /* We find a eligible key */ 1534cdf0e10cSrcweir+ data = xmlSecNssSymKeyDataKeyAdopt( curKey ) ; 1535cdf0e10cSrcweir+ if( data == NULL ) { 1536cdf0e10cSrcweir+ /* Do nothing */ 1537cdf0e10cSrcweir+ } 1538cdf0e10cSrcweir+ break ; 1539cdf0e10cSrcweir+ } 1540cdf0e10cSrcweir+ 1541cdf0e10cSrcweir+ /* Destroy the sym key list */ 1542cdf0e10cSrcweir+ for( curKey = symKey ; curKey != NULL ; ) { 1543cdf0e10cSrcweir+ symKey = curKey ; 1544cdf0e10cSrcweir+ curKey = PK11_GetNextSymKey( symKey ) ; 1545cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 1546cdf0e10cSrcweir+ } 1547cdf0e10cSrcweir+ } else if( ( keyInfoCtx->keyReq.keyType & xmlSecKeyDataTypePublic ) == xmlSecKeyDataTypePublic ) { 1548cdf0e10cSrcweir+ SECKEYPublicKeyList* pubKeyList ; 1549cdf0e10cSrcweir+ SECKEYPublicKey* pubKey ; 1550cdf0e10cSrcweir+ SECKEYPublicKeyListNode* curPub ; 1551cdf0e10cSrcweir+ 1552cdf0e10cSrcweir+ /* Find asymmetric key from the slot by name */ 1553cdf0e10cSrcweir+ pubKeyList = PK11_ListPublicKeysInSlot( slot , ( char* )name ) ; 1554cdf0e10cSrcweir+ pubKey = NULL ; 1555cdf0e10cSrcweir+ curPub = PUBKEY_LIST_HEAD(pubKeyList); 1556cdf0e10cSrcweir+ for( ; !PUBKEY_LIST_END(curPub, pubKeyList) ; curPub = PUBKEY_LIST_NEXT( curPub ) ) { 1557cdf0e10cSrcweir+ /* Check the key request */ 1558cdf0e10cSrcweir+ length = SECKEY_PublicKeyStrength( curPub->key ) ; 1559cdf0e10cSrcweir+ length *= 8 ; 1560cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyBitsSize > 0 ) && 1561cdf0e10cSrcweir+ ( length > 0 ) && 1562cdf0e10cSrcweir+ ( length < keyInfoCtx->keyReq.keyBitsSize ) ) 1563cdf0e10cSrcweir+ continue ; 1564cdf0e10cSrcweir+ 1565cdf0e10cSrcweir+ /* We find a eligible key */ 1566cdf0e10cSrcweir+ pubKey = curPub->key ; 1567cdf0e10cSrcweir+ break ; 1568cdf0e10cSrcweir+ } 1569cdf0e10cSrcweir+ 1570cdf0e10cSrcweir+ if( pubKey != NULL ) { 1571cdf0e10cSrcweir+ data = xmlSecNssPKIAdoptKey( NULL, pubKey ) ; 1572cdf0e10cSrcweir+ if( data == NULL ) { 1573cdf0e10cSrcweir+ /* Do nothing */ 1574cdf0e10cSrcweir+ } 1575cdf0e10cSrcweir+ } 1576cdf0e10cSrcweir+ 1577cdf0e10cSrcweir+ /* Destroy the public key list */ 1578cdf0e10cSrcweir+ SECKEY_DestroyPublicKeyList( pubKeyList ) ; 1579cdf0e10cSrcweir+ } else if( ( keyInfoCtx->keyReq.keyType & xmlSecKeyDataTypePrivate ) == xmlSecKeyDataTypePrivate ) { 1580cdf0e10cSrcweir+ SECKEYPrivateKeyList* priKeyList = NULL ; 1581cdf0e10cSrcweir+ SECKEYPrivateKey* priKey = NULL ; 1582cdf0e10cSrcweir+ SECKEYPrivateKeyListNode* curPri ; 1583cdf0e10cSrcweir+ 1584cdf0e10cSrcweir+ /* Find asymmetric key from the slot by name */ 1585cdf0e10cSrcweir+ priKeyList = PK11_ListPrivKeysInSlot( slot , ( char* )name , NULL ) ; 1586cdf0e10cSrcweir+ priKey = NULL ; 1587cdf0e10cSrcweir+ curPri = PRIVKEY_LIST_HEAD(priKeyList); 1588cdf0e10cSrcweir+ for( ; !PRIVKEY_LIST_END(curPri, priKeyList) ; curPri = PRIVKEY_LIST_NEXT( curPri ) ) { 1589cdf0e10cSrcweir+ /* Check the key request */ 1590cdf0e10cSrcweir+ length = PK11_SignatureLen( curPri->key ) ; 1591cdf0e10cSrcweir+ length *= 8 ; 1592cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyBitsSize > 0 ) && 1593cdf0e10cSrcweir+ ( length > 0 ) && 1594cdf0e10cSrcweir+ ( length < keyInfoCtx->keyReq.keyBitsSize ) ) 1595cdf0e10cSrcweir+ continue ; 1596cdf0e10cSrcweir+ 1597cdf0e10cSrcweir+ /* We find a eligible key */ 1598cdf0e10cSrcweir+ priKey = curPri->key ; 1599cdf0e10cSrcweir+ break ; 1600cdf0e10cSrcweir+ } 1601cdf0e10cSrcweir+ 1602cdf0e10cSrcweir+ if( priKey != NULL ) { 1603cdf0e10cSrcweir+ data = xmlSecNssPKIAdoptKey( priKey, NULL ) ; 1604cdf0e10cSrcweir+ if( data == NULL ) { 1605cdf0e10cSrcweir+ /* Do nothing */ 1606cdf0e10cSrcweir+ } 1607cdf0e10cSrcweir+ } 1608cdf0e10cSrcweir+ 1609cdf0e10cSrcweir+ /* Destroy the private key list */ 1610cdf0e10cSrcweir+ SECKEY_DestroyPrivateKeyList( priKeyList ) ; 1611cdf0e10cSrcweir+ } 1612cdf0e10cSrcweir+ 1613cdf0e10cSrcweir+ /* If we have gotten the key value */ 1614cdf0e10cSrcweir+ if( data != NULL ) { 1615cdf0e10cSrcweir+ if( ( key = xmlSecKeyCreate() ) == NULL ) { 1616cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1617cdf0e10cSrcweir+ NULL , 1618cdf0e10cSrcweir+ "xmlSecKeyCreate" , 1619cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1620cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1621cdf0e10cSrcweir+ 1622cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1623cdf0e10cSrcweir+ return NULL ; 1624cdf0e10cSrcweir+ } 1625cdf0e10cSrcweir+ 1626cdf0e10cSrcweir+ if( xmlSecKeySetValue( key , data ) < 0 ) { 1627cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1628cdf0e10cSrcweir+ NULL , 1629cdf0e10cSrcweir+ "xmlSecKeySetValue" , 1630cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1631cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1632cdf0e10cSrcweir+ 1633cdf0e10cSrcweir+ xmlSecKeyDestroy( key ) ; 1634cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 1635cdf0e10cSrcweir+ return NULL ; 1636cdf0e10cSrcweir+ } 1637cdf0e10cSrcweir+ } 1638cdf0e10cSrcweir 1639cdf0e10cSrcweir- ss = xmlSecNssKeysStoreGetSS(store); 1640cdf0e10cSrcweir- xmlSecAssert2(((ss != NULL) && (*ss != NULL) && 1641cdf0e10cSrcweir- (xmlSecKeyStoreCheckId(*ss, xmlSecSimpleKeysStoreId))), -1); 1642cdf0e10cSrcweir+ return(key); 1643cdf0e10cSrcweir+} 1644cdf0e10cSrcweir+ 1645cdf0e10cSrcweir+/** 1646cdf0e10cSrcweir+ * xmlSecKeyStoreFindKeyMethod: 1647cdf0e10cSrcweir+ * @store: the store. 1648cdf0e10cSrcweir+ * @name: the desired key name. 1649cdf0e10cSrcweir+ * @keyInfoCtx: the pointer to key info context. 1650cdf0e10cSrcweir+ * 1651cdf0e10cSrcweir+ * Keys store specific find method. The caller is responsible for destroying 1652cdf0e10cSrcweir+ * the returned key using #xmlSecKeyDestroy method. 1653cdf0e10cSrcweir+ * 1654cdf0e10cSrcweir+ * Returns the pointer to a key or NULL if key is not found or an error occurs. 1655cdf0e10cSrcweir+ */ 1656cdf0e10cSrcweir+static xmlSecKeyPtr 1657cdf0e10cSrcweir+xmlSecNssKeysStoreFindKey( 1658cdf0e10cSrcweir+ xmlSecKeyStorePtr store , 1659cdf0e10cSrcweir+ const xmlChar* name , 1660cdf0e10cSrcweir+ xmlSecKeyInfoCtxPtr keyInfoCtx 1661cdf0e10cSrcweir+) { 1662cdf0e10cSrcweir+ xmlSecNssKeysStoreCtxPtr context = NULL ; 1663cdf0e10cSrcweir+ xmlSecKeyPtr key = NULL ; 1664cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot = NULL ; 1665cdf0e10cSrcweir+ xmlSecSize pos ; 1666cdf0e10cSrcweir+ xmlSecSize size ; 1667cdf0e10cSrcweir+ 1668cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckId( store , xmlSecNssKeysStoreId ) , NULL ) ; 1669cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckSize( store , xmlSecNssKeysStoreSize ) , NULL ) ; 1670cdf0e10cSrcweir+ xmlSecAssert2( keyInfoCtx != NULL , NULL ) ; 1671cdf0e10cSrcweir+ 1672cdf0e10cSrcweir+ context = xmlSecNssKeysStoreGetCtx( store ) ; 1673cdf0e10cSrcweir+ if( context == NULL ) { 1674cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1675cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1676cdf0e10cSrcweir+ "xmlSecNssKeysStoreGetCtx" , 1677cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1678cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1679cdf0e10cSrcweir+ return NULL ; 1680cdf0e10cSrcweir+ } 1681cdf0e10cSrcweir+ 1682cdf0e10cSrcweir+ /*- 1683cdf0e10cSrcweir+ * Look for key at keyList at first. 1684cdf0e10cSrcweir+ */ 1685cdf0e10cSrcweir+ if( context->keyList != NULL ) { 1686cdf0e10cSrcweir+ size = xmlSecPtrListGetSize( context->keyList ) ; 1687cdf0e10cSrcweir+ for( pos = 0 ; pos < size ; pos ++ ) { 1688cdf0e10cSrcweir+ key = ( xmlSecKeyPtr )xmlSecPtrListGetItem( context->keyList , pos ) ; 1689cdf0e10cSrcweir+ if( key != NULL && xmlSecKeyMatch( key , name , &( keyInfoCtx->keyReq ) ) ) { 1690cdf0e10cSrcweir+ return xmlSecKeyDuplicate( key ) ; 1691cdf0e10cSrcweir+ } 1692cdf0e10cSrcweir+ } 1693cdf0e10cSrcweir+ } 1694cdf0e10cSrcweir+ 1695cdf0e10cSrcweir+ /*- 1696cdf0e10cSrcweir+ * Find the key from slotList 1697cdf0e10cSrcweir+ */ 1698cdf0e10cSrcweir+ if( context->slotList != NULL ) { 1699cdf0e10cSrcweir+ PK11SlotInfo* slot = NULL ; 1700cdf0e10cSrcweir+ 1701cdf0e10cSrcweir+ size = xmlSecPtrListGetSize( context->slotList ) ; 1702cdf0e10cSrcweir+ for( pos = 0 ; pos < size ; pos ++ ) { 1703cdf0e10cSrcweir+ keySlot = ( xmlSecNssKeySlotPtr )xmlSecPtrListGetItem( context->slotList , pos ) ; 1704cdf0e10cSrcweir+ slot = xmlSecNssKeySlotGetSlot( keySlot ) ; 1705cdf0e10cSrcweir+ if( slot == NULL ) { 1706cdf0e10cSrcweir+ continue ; 1707cdf0e10cSrcweir+ } else { 1708cdf0e10cSrcweir+ key = xmlSecNssKeysStoreFindKeyFromSlot( slot, name, keyInfoCtx ) ; 1709cdf0e10cSrcweir+ if( key == NULL ) { 1710cdf0e10cSrcweir+ continue ; 1711cdf0e10cSrcweir+ } else { 1712cdf0e10cSrcweir+ return( key ) ; 1713cdf0e10cSrcweir+ } 1714cdf0e10cSrcweir+ } 1715cdf0e10cSrcweir+ } 1716cdf0e10cSrcweir+ } 1717cdf0e10cSrcweir+ 1718cdf0e10cSrcweir+ /*- 1719cdf0e10cSrcweir+ * Create a session key if we can not find the key from keyList and slotList 1720cdf0e10cSrcweir+ */ 1721cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyType & xmlSecKeyDataTypeSession ) == xmlSecKeyDataTypeSession ) { 1722cdf0e10cSrcweir+ key = xmlSecKeyGenerate( keyInfoCtx->keyReq.keyId , keyInfoCtx->keyReq.keyBitsSize , xmlSecKeyDataTypeSession ) ; 1723cdf0e10cSrcweir+ if( key == NULL ) { 1724cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 1725cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyStoreGetName( store ) ) , 1726cdf0e10cSrcweir+ "xmlSecKeySetValue" , 1727cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 1728cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 1729cdf0e10cSrcweir+ return NULL ; 1730cdf0e10cSrcweir+ } 1731cdf0e10cSrcweir+ 1732cdf0e10cSrcweir+ return key ; 1733cdf0e10cSrcweir+ } 1734cdf0e10cSrcweir+ 1735cdf0e10cSrcweir+ /** 1736cdf0e10cSrcweir+ * We have no way to find the key any more. 1737cdf0e10cSrcweir+ */ 1738cdf0e10cSrcweir+ return NULL ; 1739cdf0e10cSrcweir+} 1740cdf0e10cSrcweir+ 1741cdf0e10cSrcweir+static xmlSecKeyStoreKlass xmlSecNssKeysStoreKlass = { 1742cdf0e10cSrcweir+ sizeof( xmlSecKeyStoreKlass ) , 1743cdf0e10cSrcweir+ xmlSecNssKeysStoreSize , 1744cdf0e10cSrcweir+ BAD_CAST "implicit_nss_keys_store" , 1745cdf0e10cSrcweir+ xmlSecNssKeysStoreInitialize , 1746cdf0e10cSrcweir+ xmlSecNssKeysStoreFinalize , 1747cdf0e10cSrcweir+ xmlSecNssKeysStoreFindKey , 1748cdf0e10cSrcweir+ NULL , 1749cdf0e10cSrcweir+ NULL 1750cdf0e10cSrcweir+} ; 1751cdf0e10cSrcweir 1752cdf0e10cSrcweir- return (xmlSecSimpleKeysStoreAdoptKey(*ss, key)); 1753cdf0e10cSrcweir+/** 1754cdf0e10cSrcweir+ * xmlSecNssKeysStoreGetKlass: 1755cdf0e10cSrcweir+ * 1756cdf0e10cSrcweir+ * The simple list based keys store klass. 1757cdf0e10cSrcweir+ * 1758cdf0e10cSrcweir+ */ 1759cdf0e10cSrcweir+xmlSecKeyStoreId 1760cdf0e10cSrcweir+xmlSecNssKeysStoreGetKlass( void ) { 1761cdf0e10cSrcweir+ return &xmlSecNssKeysStoreKlass ; 1762cdf0e10cSrcweir } 1763cdf0e10cSrcweir 1764cdf0e10cSrcweir+/************************** 1765cdf0e10cSrcweir+ * Application routines 1766cdf0e10cSrcweir+ */ 1767cdf0e10cSrcweir+ 1768cdf0e10cSrcweir /** 1769cdf0e10cSrcweir * xmlSecNssKeysStoreLoad: 1770cdf0e10cSrcweir * @store: the pointer to Nss keys store. 1771cdf0e10cSrcweir@@ -252,234 +651,147 @@ 1772cdf0e10cSrcweir */ 1773cdf0e10cSrcweir int 1774cdf0e10cSrcweir xmlSecNssKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecKeyDataType type) { 1775cdf0e10cSrcweir- xmlSecKeyStorePtr *ss; 1776cdf0e10cSrcweir+ xmlSecKeyInfoCtx keyInfoCtx; 1777cdf0e10cSrcweir+ xmlSecNssKeysStoreCtxPtr context ; 1778cdf0e10cSrcweir+ xmlSecPtrListPtr list; 1779cdf0e10cSrcweir+ xmlSecKeyPtr key; 1780cdf0e10cSrcweir+ xmlSecSize i, keysSize; 1781cdf0e10cSrcweir+ xmlDocPtr doc; 1782cdf0e10cSrcweir+ xmlNodePtr cur; 1783cdf0e10cSrcweir+ xmlSecKeyDataPtr data; 1784cdf0e10cSrcweir+ xmlSecPtrListPtr idsList; 1785cdf0e10cSrcweir+ xmlSecKeyDataId dataId; 1786cdf0e10cSrcweir+ xmlSecSize idsSize, j; 1787cdf0e10cSrcweir+ int ret; 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir xmlSecAssert2(xmlSecKeyStoreCheckId(store, xmlSecNssKeysStoreId), -1); 1790cdf0e10cSrcweir- xmlSecAssert2((filename != NULL), -1); 1791cdf0e10cSrcweir- 1792cdf0e10cSrcweir- ss = xmlSecNssKeysStoreGetSS(store); 1793cdf0e10cSrcweir- xmlSecAssert2(((ss != NULL) && (*ss != NULL) && 1794cdf0e10cSrcweir- (xmlSecKeyStoreCheckId(*ss, xmlSecSimpleKeysStoreId))), -1); 1795cdf0e10cSrcweir- 1796cdf0e10cSrcweir- return (xmlSecSimpleKeysStoreSave(*ss, filename, type)); 1797cdf0e10cSrcweir-} 1798cdf0e10cSrcweir- 1799cdf0e10cSrcweir-static int 1800cdf0e10cSrcweir-xmlSecNssKeysStoreInitialize(xmlSecKeyStorePtr store) { 1801cdf0e10cSrcweir- xmlSecKeyStorePtr *ss; 1802cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyStoreCheckSize( store , xmlSecNssKeysStoreSize ), -1 ) ; 1803cdf0e10cSrcweir+ xmlSecAssert2(filename != NULL, -1); 1804cdf0e10cSrcweir 1805cdf0e10cSrcweir- xmlSecAssert2(xmlSecKeyStoreCheckId(store, xmlSecNssKeysStoreId), -1); 1806cdf0e10cSrcweir+ context = xmlSecNssKeysStoreGetCtx( store ) ; 1807cdf0e10cSrcweir+ xmlSecAssert2( context != NULL, -1 ); 1808cdf0e10cSrcweir 1809cdf0e10cSrcweir- ss = xmlSecNssKeysStoreGetSS(store); 1810cdf0e10cSrcweir- xmlSecAssert2((*ss == NULL), -1); 1811cdf0e10cSrcweir+ list = context->keyList ; 1812cdf0e10cSrcweir+ xmlSecAssert2( list != NULL, -1 ); 1813cdf0e10cSrcweir+ xmlSecAssert2(xmlSecPtrListCheckId(list, xmlSecKeyPtrListId), -1); 1814cdf0e10cSrcweir 1815cdf0e10cSrcweir- *ss = xmlSecKeyStoreCreate(xmlSecSimpleKeysStoreId); 1816cdf0e10cSrcweir- if(*ss == NULL) { 1817cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 1818cdf0e10cSrcweir+ /* create doc */ 1819cdf0e10cSrcweir+ doc = xmlSecCreateTree(BAD_CAST "Keys", xmlSecNs); 1820cdf0e10cSrcweir+ if(doc == NULL) { 1821cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 1822cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 1823cdf0e10cSrcweir- "xmlSecKeyStoreCreate", 1824cdf0e10cSrcweir+ "xmlSecCreateTree", 1825cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 1826cdf0e10cSrcweir- "xmlSecSimpleKeysStoreId"); 1827cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 1828cdf0e10cSrcweir return(-1); 1829cdf0e10cSrcweir } 1830cdf0e10cSrcweir 1831cdf0e10cSrcweir- return(0); 1832cdf0e10cSrcweir-} 1833cdf0e10cSrcweir- 1834cdf0e10cSrcweir-static void 1835cdf0e10cSrcweir-xmlSecNssKeysStoreFinalize(xmlSecKeyStorePtr store) { 1836cdf0e10cSrcweir- xmlSecKeyStorePtr *ss; 1837cdf0e10cSrcweir- 1838cdf0e10cSrcweir- xmlSecAssert(xmlSecKeyStoreCheckId(store, xmlSecNssKeysStoreId)); 1839cdf0e10cSrcweir- 1840cdf0e10cSrcweir- ss = xmlSecNssKeysStoreGetSS(store); 1841cdf0e10cSrcweir- xmlSecAssert((ss != NULL) && (*ss != NULL)); 1842cdf0e10cSrcweir- 1843cdf0e10cSrcweir- xmlSecKeyStoreDestroy(*ss); 1844cdf0e10cSrcweir-} 1845cdf0e10cSrcweir- 1846cdf0e10cSrcweir-static xmlSecKeyPtr 1847cdf0e10cSrcweir-xmlSecNssKeysStoreFindKey(xmlSecKeyStorePtr store, const xmlChar* name, 1848cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx) { 1849cdf0e10cSrcweir- xmlSecKeyStorePtr* ss; 1850cdf0e10cSrcweir- xmlSecKeyPtr key = NULL; 1851cdf0e10cSrcweir- xmlSecKeyPtr retval = NULL; 1852cdf0e10cSrcweir- xmlSecKeyReqPtr keyReq = NULL; 1853cdf0e10cSrcweir- CERTCertificate *cert = NULL; 1854cdf0e10cSrcweir- SECKEYPublicKey *pubkey = NULL; 1855cdf0e10cSrcweir- SECKEYPrivateKey *privkey = NULL; 1856cdf0e10cSrcweir- xmlSecKeyDataPtr data = NULL; 1857cdf0e10cSrcweir- xmlSecKeyDataPtr x509Data = NULL; 1858cdf0e10cSrcweir- int ret; 1859cdf0e10cSrcweir- 1860cdf0e10cSrcweir- xmlSecAssert2(xmlSecKeyStoreCheckId(store, xmlSecNssKeysStoreId), NULL); 1861cdf0e10cSrcweir- xmlSecAssert2(keyInfoCtx != NULL, NULL); 1862cdf0e10cSrcweir- 1863cdf0e10cSrcweir- ss = xmlSecNssKeysStoreGetSS(store); 1864cdf0e10cSrcweir- xmlSecAssert2(((ss != NULL) && (*ss != NULL)), NULL); 1865cdf0e10cSrcweir- 1866cdf0e10cSrcweir- key = xmlSecKeyStoreFindKey(*ss, name, keyInfoCtx); 1867cdf0e10cSrcweir- if (key != NULL) { 1868cdf0e10cSrcweir- return (key); 1869cdf0e10cSrcweir- } 1870cdf0e10cSrcweir- 1871cdf0e10cSrcweir- /* Try to find the key in the NSS DB, and construct an xmlSecKey. 1872cdf0e10cSrcweir- * we must have a name to lookup keys in NSS DB. 1873cdf0e10cSrcweir- */ 1874cdf0e10cSrcweir- if (name == NULL) { 1875cdf0e10cSrcweir- goto done; 1876cdf0e10cSrcweir- } 1877cdf0e10cSrcweir+ idsList = xmlSecKeyDataIdsGet(); 1878cdf0e10cSrcweir+ xmlSecAssert2(idsList != NULL, -1); 1879cdf0e10cSrcweir 1880cdf0e10cSrcweir- /* what type of key are we looking for? 1881cdf0e10cSrcweir- * TBD: For now, we'll look only for public/private keys using the 1882cdf0e10cSrcweir- * name as a cert nickname. Later on, we can attempt to find 1883cdf0e10cSrcweir- * symmetric keys using PK11_FindFixedKey 1884cdf0e10cSrcweir- */ 1885cdf0e10cSrcweir- keyReq = &(keyInfoCtx->keyReq); 1886cdf0e10cSrcweir- if (keyReq->keyType & 1887cdf0e10cSrcweir- (xmlSecKeyDataTypePublic | xmlSecKeyDataTypePrivate)) { 1888cdf0e10cSrcweir- cert = CERT_FindCertByNickname (CERT_GetDefaultCertDB(), (char *)name); 1889cdf0e10cSrcweir- if (cert == NULL) { 1890cdf0e10cSrcweir- goto done; 1891cdf0e10cSrcweir- } 1892cdf0e10cSrcweir+ keysSize = xmlSecPtrListGetSize(list); 1893cdf0e10cSrcweir+ idsSize = xmlSecPtrListGetSize(idsList); 1894cdf0e10cSrcweir+ for(i = 0; i < keysSize; ++i) { 1895cdf0e10cSrcweir+ key = (xmlSecKeyPtr)xmlSecPtrListGetItem(list, i); 1896cdf0e10cSrcweir+ xmlSecAssert2(key != NULL, -1); 1897cdf0e10cSrcweir 1898cdf0e10cSrcweir- if (keyReq->keyType & xmlSecKeyDataTypePublic) { 1899cdf0e10cSrcweir- pubkey = CERT_ExtractPublicKey(cert); 1900cdf0e10cSrcweir- if (pubkey == NULL) { 1901cdf0e10cSrcweir+ cur = xmlSecAddChild(xmlDocGetRootElement(doc), xmlSecNodeKeyInfo, xmlSecDSigNs); 1902cdf0e10cSrcweir+ if(cur == NULL) { 1903cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 1904cdf0e10cSrcweir- NULL, 1905cdf0e10cSrcweir- "CERT_ExtractPublicKey", 1906cdf0e10cSrcweir- XMLSEC_ERRORS_R_CRYPTO_FAILED, 1907cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 1908cdf0e10cSrcweir- goto done; 1909cdf0e10cSrcweir- } 1910cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 1911cdf0e10cSrcweir+ "xmlSecAddChild", 1912cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 1913cdf0e10cSrcweir+ "node=%s", 1914cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecNodeKeyInfo)); 1915cdf0e10cSrcweir+ xmlFreeDoc(doc); 1916cdf0e10cSrcweir+ return(-1); 1917cdf0e10cSrcweir } 1918cdf0e10cSrcweir 1919cdf0e10cSrcweir- if (keyReq->keyType & xmlSecKeyDataTypePrivate) { 1920cdf0e10cSrcweir- privkey = PK11_FindKeyByAnyCert(cert, NULL); 1921cdf0e10cSrcweir- if (privkey == NULL) { 1922cdf0e10cSrcweir+ /* special data key name */ 1923cdf0e10cSrcweir+ if(xmlSecKeyGetName(key) != NULL) { 1924cdf0e10cSrcweir+ if(xmlSecAddChild(cur, xmlSecNodeKeyName, xmlSecDSigNs) == NULL) { 1925cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 1926cdf0e10cSrcweir- NULL, 1927cdf0e10cSrcweir- "PK11_FindKeyByAnyCert", 1928cdf0e10cSrcweir- XMLSEC_ERRORS_R_CRYPTO_FAILED, 1929cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 1930cdf0e10cSrcweir- goto done; 1931cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 1932cdf0e10cSrcweir+ "xmlSecAddChild", 1933cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 1934cdf0e10cSrcweir+ "node=%s", 1935cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecNodeKeyName)); 1936cdf0e10cSrcweir+ xmlFreeDoc(doc); 1937cdf0e10cSrcweir+ return(-1); 1938cdf0e10cSrcweir } 1939cdf0e10cSrcweir } 1940cdf0e10cSrcweir 1941cdf0e10cSrcweir- data = xmlSecNssPKIAdoptKey(privkey, pubkey); 1942cdf0e10cSrcweir- if(data == NULL) { 1943cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 1944cdf0e10cSrcweir- NULL, 1945cdf0e10cSrcweir- "xmlSecNssPKIAdoptKey", 1946cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 1947cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 1948cdf0e10cSrcweir- goto done; 1949cdf0e10cSrcweir- } 1950cdf0e10cSrcweir- privkey = NULL; 1951cdf0e10cSrcweir- pubkey = NULL; 1952cdf0e10cSrcweir- 1953cdf0e10cSrcweir- key = xmlSecKeyCreate(); 1954cdf0e10cSrcweir- if (key == NULL) { 1955cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 1956cdf0e10cSrcweir- NULL, 1957cdf0e10cSrcweir- "xmlSecKeyCreate", 1958cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 1959cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 1960cdf0e10cSrcweir- return (NULL); 1961cdf0e10cSrcweir- } 1962cdf0e10cSrcweir- 1963cdf0e10cSrcweir- x509Data = xmlSecKeyDataCreate(xmlSecNssKeyDataX509Id); 1964cdf0e10cSrcweir- if(x509Data == NULL) { 1965cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 1966cdf0e10cSrcweir- NULL, 1967cdf0e10cSrcweir- "xmlSecKeyDataCreate", 1968cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 1969cdf0e10cSrcweir- "transform=%s", 1970cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecTransformKlassGetName(xmlSecNssKeyDataX509Id))); 1971cdf0e10cSrcweir- goto done; 1972cdf0e10cSrcweir- } 1973cdf0e10cSrcweir+ /* create nodes for other keys data */ 1974cdf0e10cSrcweir+ for(j = 0; j < idsSize; ++j) { 1975cdf0e10cSrcweir+ dataId = (xmlSecKeyDataId)xmlSecPtrListGetItem(idsList, j); 1976cdf0e10cSrcweir+ xmlSecAssert2(dataId != xmlSecKeyDataIdUnknown, -1); 1977cdf0e10cSrcweir+ 1978cdf0e10cSrcweir+ if(dataId->dataNodeName == NULL) { 1979cdf0e10cSrcweir+ continue; 1980cdf0e10cSrcweir+ } 1981cdf0e10cSrcweir+ 1982cdf0e10cSrcweir+ data = xmlSecKeyGetData(key, dataId); 1983cdf0e10cSrcweir+ if(data == NULL) { 1984cdf0e10cSrcweir+ continue; 1985cdf0e10cSrcweir+ } 1986cdf0e10cSrcweir 1987cdf0e10cSrcweir- ret = xmlSecNssKeyDataX509AdoptKeyCert(x509Data, cert); 1988cdf0e10cSrcweir- if (ret < 0) { 1989cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 1990cdf0e10cSrcweir- NULL, 1991cdf0e10cSrcweir- "xmlSecNssKeyDataX509AdoptKeyCert", 1992cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 1993cdf0e10cSrcweir- "data=%s", 1994cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); 1995cdf0e10cSrcweir- goto done; 1996cdf0e10cSrcweir- } 1997cdf0e10cSrcweir- cert = CERT_DupCertificate(cert); 1998cdf0e10cSrcweir- if (cert == NULL) { 1999cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 2000cdf0e10cSrcweir- NULL, 2001cdf0e10cSrcweir- "CERT_DupCertificate", 2002cdf0e10cSrcweir- XMLSEC_ERRORS_R_CRYPTO_FAILED, 2003cdf0e10cSrcweir- "data=%s", 2004cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); 2005cdf0e10cSrcweir- goto done; 2006cdf0e10cSrcweir+ if(xmlSecAddChild(cur, dataId->dataNodeName, dataId->dataNodeNs) == NULL) { 2007cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2008cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 2009cdf0e10cSrcweir+ "xmlSecAddChild", 2010cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2011cdf0e10cSrcweir+ "node=%s", 2012cdf0e10cSrcweir+ xmlSecErrorsSafeString(dataId->dataNodeName)); 2013cdf0e10cSrcweir+ xmlFreeDoc(doc); 2014cdf0e10cSrcweir+ return(-1); 2015cdf0e10cSrcweir+ } 2016cdf0e10cSrcweir } 2017cdf0e10cSrcweir 2018cdf0e10cSrcweir- ret = xmlSecNssKeyDataX509AdoptCert(x509Data, cert); 2019cdf0e10cSrcweir+ ret = xmlSecKeyInfoCtxInitialize(&keyInfoCtx, NULL); 2020cdf0e10cSrcweir if (ret < 0) { 2021cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 2022cdf0e10cSrcweir- NULL, 2023cdf0e10cSrcweir- "xmlSecNssKeyDataX509AdoptCert", 2024cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 2025cdf0e10cSrcweir+ "xmlSecKeyInfoCtxInitialize", 2026cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 2027cdf0e10cSrcweir- "data=%s", 2028cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); 2029cdf0e10cSrcweir- goto done; 2030cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2031cdf0e10cSrcweir+ xmlFreeDoc(doc); 2032cdf0e10cSrcweir+ return(-1); 2033cdf0e10cSrcweir } 2034cdf0e10cSrcweir- cert = NULL; 2035cdf0e10cSrcweir 2036cdf0e10cSrcweir- ret = xmlSecKeySetValue(key, data); 2037cdf0e10cSrcweir- if (ret < 0) { 2038cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 2039cdf0e10cSrcweir- NULL, 2040cdf0e10cSrcweir- "xmlSecKeySetValue", 2041cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 2042cdf0e10cSrcweir- "data=%s", 2043cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))); 2044cdf0e10cSrcweir- goto done; 2045cdf0e10cSrcweir- } 2046cdf0e10cSrcweir- data = NULL; 2047cdf0e10cSrcweir+ keyInfoCtx.mode = xmlSecKeyInfoModeWrite; 2048cdf0e10cSrcweir+ keyInfoCtx.keyReq.keyId = xmlSecKeyDataIdUnknown; 2049cdf0e10cSrcweir+ keyInfoCtx.keyReq.keyType = type; 2050cdf0e10cSrcweir+ keyInfoCtx.keyReq.keyUsage = xmlSecKeyDataUsageAny; 2051cdf0e10cSrcweir 2052cdf0e10cSrcweir- ret = xmlSecKeyAdoptData(key, x509Data); 2053cdf0e10cSrcweir+ /* finally write key in the node */ 2054cdf0e10cSrcweir+ ret = xmlSecKeyInfoNodeWrite(cur, key, &keyInfoCtx); 2055cdf0e10cSrcweir if (ret < 0) { 2056cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 2057cdf0e10cSrcweir- NULL, 2058cdf0e10cSrcweir- "xmlSecKeyAdoptData", 2059cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 2060cdf0e10cSrcweir+ "xmlSecKeyInfoNodeWrite", 2061cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 2062cdf0e10cSrcweir- "data=%s", 2063cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); 2064cdf0e10cSrcweir- goto done; 2065cdf0e10cSrcweir- } 2066cdf0e10cSrcweir- x509Data = NULL; 2067cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2068cdf0e10cSrcweir+ xmlSecKeyInfoCtxFinalize(&keyInfoCtx); 2069cdf0e10cSrcweir+ xmlFreeDoc(doc); 2070cdf0e10cSrcweir+ return(-1); 2071cdf0e10cSrcweir+ } 2072cdf0e10cSrcweir 2073cdf0e10cSrcweir- retval = key; 2074cdf0e10cSrcweir- key = NULL; 2075cdf0e10cSrcweir+ xmlSecKeyInfoCtxFinalize(&keyInfoCtx); 2076cdf0e10cSrcweir } 2077cdf0e10cSrcweir 2078cdf0e10cSrcweir-done: 2079cdf0e10cSrcweir- if (cert != NULL) { 2080cdf0e10cSrcweir- CERT_DestroyCertificate(cert); 2081cdf0e10cSrcweir- } 2082cdf0e10cSrcweir- if (pubkey != NULL) { 2083cdf0e10cSrcweir- SECKEY_DestroyPublicKey(pubkey); 2084cdf0e10cSrcweir- } 2085cdf0e10cSrcweir- if (privkey != NULL) { 2086cdf0e10cSrcweir- SECKEY_DestroyPrivateKey(privkey); 2087cdf0e10cSrcweir- } 2088cdf0e10cSrcweir- if (data != NULL) { 2089cdf0e10cSrcweir- xmlSecKeyDataDestroy(data); 2090cdf0e10cSrcweir- } 2091cdf0e10cSrcweir- if (x509Data != NULL) { 2092cdf0e10cSrcweir- xmlSecKeyDataDestroy(x509Data); 2093cdf0e10cSrcweir- } 2094cdf0e10cSrcweir- if (key != NULL) { 2095cdf0e10cSrcweir- xmlSecKeyDestroy(key); 2096cdf0e10cSrcweir+ /* now write result */ 2097cdf0e10cSrcweir+ ret = xmlSaveFormatFile(filename, doc, 1); 2098cdf0e10cSrcweir+ if (ret < 0) { 2099cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2100cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)), 2101cdf0e10cSrcweir+ "xmlSaveFormatFile", 2102cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XML_FAILED, 2103cdf0e10cSrcweir+ "filename=%s", 2104cdf0e10cSrcweir+ xmlSecErrorsSafeString(filename)); 2105cdf0e10cSrcweir+ xmlFreeDoc(doc); 2106cdf0e10cSrcweir+ return(-1); 2107cdf0e10cSrcweir } 2108cdf0e10cSrcweir 2109cdf0e10cSrcweir- return (retval); 2110cdf0e10cSrcweir+ xmlFreeDoc(doc); 2111cdf0e10cSrcweir+ return(0); 2112cdf0e10cSrcweir } 2113cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/keywrapers.c 2009-09-21 14:07:19.223802688 +0200 2114cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/keywrapers.c 2009-09-21 14:02:48.548869372 +0200 2115cdf0e10cSrcweir@@ -1 +1,1213 @@ 2116cdf0e10cSrcweir-dummy 2117cdf0e10cSrcweir+/** 2118cdf0e10cSrcweir+ * 2119cdf0e10cSrcweir+ * XMLSec library 2120cdf0e10cSrcweir+ * 2121cdf0e10cSrcweir+ * AES Algorithm support 2122cdf0e10cSrcweir+ * 2123cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 2124cdf0e10cSrcweir+ * distribution for preciese wording. 2125cdf0e10cSrcweir+ * 2126cdf0e10cSrcweir+ * Copyright ................................. 2127cdf0e10cSrcweir+ */ 2128cdf0e10cSrcweir+#include "globals.h" 2129cdf0e10cSrcweir+ 2130cdf0e10cSrcweir+#include <stdlib.h> 2131cdf0e10cSrcweir+#include <stdio.h> 2132cdf0e10cSrcweir+#include <string.h> 2133cdf0e10cSrcweir+ 2134cdf0e10cSrcweir+#include <nss.h> 2135cdf0e10cSrcweir+#include <pk11func.h> 2136cdf0e10cSrcweir+#include <hasht.h> 2137cdf0e10cSrcweir+ 2138cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 2139cdf0e10cSrcweir+#include <xmlsec/xmltree.h> 2140cdf0e10cSrcweir+#include <xmlsec/keys.h> 2141cdf0e10cSrcweir+#include <xmlsec/transforms.h> 2142cdf0e10cSrcweir+#include <xmlsec/errors.h> 2143cdf0e10cSrcweir+ 2144cdf0e10cSrcweir+#include <xmlsec/nss/crypto.h> 2145cdf0e10cSrcweir+#include <xmlsec/nss/ciphers.h> 2146cdf0e10cSrcweir+ 2147cdf0e10cSrcweir+#define XMLSEC_NSS_AES128_KEY_SIZE 16 2148cdf0e10cSrcweir+#define XMLSEC_NSS_AES192_KEY_SIZE 24 2149cdf0e10cSrcweir+#define XMLSEC_NSS_AES256_KEY_SIZE 32 2150cdf0e10cSrcweir+#define XMLSEC_NSS_DES3_KEY_SIZE 24 2151cdf0e10cSrcweir+#define XMLSEC_NSS_DES3_KEY_LENGTH 24 2152cdf0e10cSrcweir+#define XMLSEC_NSS_DES3_IV_LENGTH 8 2153cdf0e10cSrcweir+#define XMLSEC_NSS_DES3_BLOCK_LENGTH 8 2154cdf0e10cSrcweir+ 2155cdf0e10cSrcweir+static xmlSecByte xmlSecNssKWDes3Iv[XMLSEC_NSS_DES3_IV_LENGTH] = { 2156cdf0e10cSrcweir+ 0x4a, 0xdd, 0xa2, 0x2c, 0x79, 0xe8, 0x21, 0x05 2157cdf0e10cSrcweir+}; 2158cdf0e10cSrcweir+ 2159cdf0e10cSrcweir+/********************************************************************* 2160cdf0e10cSrcweir+ * 2161cdf0e10cSrcweir+ * key wrap transforms 2162cdf0e10cSrcweir+ * 2163cdf0e10cSrcweir+ ********************************************************************/ 2164cdf0e10cSrcweir+typedef struct _xmlSecNssKeyWrapCtx xmlSecNssKeyWrapCtx ; 2165cdf0e10cSrcweir+typedef struct _xmlSecNssKeyWrapCtx* xmlSecNssKeyWrapCtxPtr ; 2166cdf0e10cSrcweir+ 2167cdf0e10cSrcweir+#define xmlSecNssKeyWrapSize \ 2168cdf0e10cSrcweir+ ( sizeof( xmlSecTransform ) + sizeof( xmlSecNssKeyWrapCtx ) ) 2169cdf0e10cSrcweir+ 2170cdf0e10cSrcweir+#define xmlSecNssKeyWrapGetCtx( transform ) \ 2171cdf0e10cSrcweir+ ( ( xmlSecNssKeyWrapCtxPtr )( ( ( xmlSecByte* )( transform ) ) + sizeof( xmlSecTransform ) ) ) 2172cdf0e10cSrcweir+ 2173cdf0e10cSrcweir+struct _xmlSecNssKeyWrapCtx { 2174cdf0e10cSrcweir+ CK_MECHANISM_TYPE cipher ; 2175cdf0e10cSrcweir+ PK11SymKey* symkey ; 2176cdf0e10cSrcweir+ xmlSecKeyDataId keyId ; 2177cdf0e10cSrcweir+ xmlSecBufferPtr material ; /* to be encrypted/decrypted key material */ 2178cdf0e10cSrcweir+} ; 2179cdf0e10cSrcweir+ 2180cdf0e10cSrcweir+static int xmlSecNssKeyWrapInitialize(xmlSecTransformPtr transform); 2181cdf0e10cSrcweir+static void xmlSecNssKeyWrapFinalize(xmlSecTransformPtr transform); 2182cdf0e10cSrcweir+static int xmlSecNssKeyWrapSetKeyReq(xmlSecTransformPtr transform, 2183cdf0e10cSrcweir+ xmlSecKeyReqPtr keyReq); 2184cdf0e10cSrcweir+static int xmlSecNssKeyWrapSetKey(xmlSecTransformPtr transform, 2185cdf0e10cSrcweir+ xmlSecKeyPtr key); 2186cdf0e10cSrcweir+static int xmlSecNssKeyWrapExecute(xmlSecTransformPtr transform, 2187cdf0e10cSrcweir+ int last, 2188cdf0e10cSrcweir+ xmlSecTransformCtxPtr transformCtx); 2189cdf0e10cSrcweir+static xmlSecSize xmlSecNssKeyWrapGetKeySize(xmlSecTransformPtr transform); 2190cdf0e10cSrcweir+ 2191cdf0e10cSrcweir+static int 2192cdf0e10cSrcweir+xmlSecNssKeyWrapCheckId( 2193cdf0e10cSrcweir+ xmlSecTransformPtr transform 2194cdf0e10cSrcweir+) { 2195cdf0e10cSrcweir+ #ifndef XMLSEC_NO_DES 2196cdf0e10cSrcweir+ if( xmlSecTransformCheckId( transform, xmlSecNssTransformKWDes3Id ) ) { 2197cdf0e10cSrcweir+ return(1); 2198cdf0e10cSrcweir+ } 2199cdf0e10cSrcweir+ #endif /* XMLSEC_NO_DES */ 2200cdf0e10cSrcweir+ 2201cdf0e10cSrcweir+ #ifndef XMLSEC_NO_AES 2202cdf0e10cSrcweir+ if( xmlSecTransformCheckId( transform, xmlSecNssTransformKWAes128Id ) || 2203cdf0e10cSrcweir+ xmlSecTransformCheckId( transform, xmlSecNssTransformKWAes192Id ) || 2204cdf0e10cSrcweir+ xmlSecTransformCheckId( transform, xmlSecNssTransformKWAes256Id ) ) { 2205cdf0e10cSrcweir+ 2206cdf0e10cSrcweir+ return(1); 2207cdf0e10cSrcweir+ } 2208cdf0e10cSrcweir+ #endif /* XMLSEC_NO_AES */ 2209cdf0e10cSrcweir+ 2210cdf0e10cSrcweir+ return(0); 2211cdf0e10cSrcweir+} 2212cdf0e10cSrcweir+ 2213cdf0e10cSrcweir+static xmlSecSize 2214cdf0e10cSrcweir+xmlSecNssKeyWrapGetKeySize(xmlSecTransformPtr transform) { 2215cdf0e10cSrcweir+#ifndef XMLSEC_NO_DES 2216cdf0e10cSrcweir+ if( xmlSecTransformCheckId( transform, xmlSecNssTransformKWDes3Id ) ) { 2217cdf0e10cSrcweir+ return(XMLSEC_NSS_DES3_KEY_SIZE); 2218cdf0e10cSrcweir+ } else 2219cdf0e10cSrcweir+#endif /* XMLSEC_NO_DES */ 2220cdf0e10cSrcweir+ 2221cdf0e10cSrcweir+#ifndef XMLSEC_NO_AES 2222cdf0e10cSrcweir+ if(xmlSecTransformCheckId(transform, xmlSecNssTransformKWAes128Id)) { 2223cdf0e10cSrcweir+ return(XMLSEC_NSS_AES128_KEY_SIZE); 2224cdf0e10cSrcweir+ } else if(xmlSecTransformCheckId(transform, xmlSecNssTransformKWAes192Id)) { 2225cdf0e10cSrcweir+ return(XMLSEC_NSS_AES192_KEY_SIZE); 2226cdf0e10cSrcweir+ } else if(xmlSecTransformCheckId(transform, xmlSecNssTransformKWAes256Id)) { 2227cdf0e10cSrcweir+ return(XMLSEC_NSS_AES256_KEY_SIZE); 2228cdf0e10cSrcweir+ } else if(xmlSecTransformCheckId(transform, xmlSecNssTransformKWAes256Id)) { 2229cdf0e10cSrcweir+ return(XMLSEC_NSS_AES256_KEY_SIZE); 2230cdf0e10cSrcweir+ } else 2231cdf0e10cSrcweir+#endif /* XMLSEC_NO_AES */ 2232cdf0e10cSrcweir+ 2233cdf0e10cSrcweir+ if(1) 2234cdf0e10cSrcweir+ return(0); 2235cdf0e10cSrcweir+} 2236cdf0e10cSrcweir+ 2237cdf0e10cSrcweir+ 2238cdf0e10cSrcweir+static int 2239cdf0e10cSrcweir+xmlSecNssKeyWrapInitialize(xmlSecTransformPtr transform) { 2240cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr context ; 2241cdf0e10cSrcweir+ int ret; 2242cdf0e10cSrcweir+ 2243cdf0e10cSrcweir+ xmlSecAssert2(xmlSecNssKeyWrapCheckId(transform), -1); 2244cdf0e10cSrcweir+ xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecNssKeyWrapSize), -1); 2245cdf0e10cSrcweir+ 2246cdf0e10cSrcweir+ context = xmlSecNssKeyWrapGetCtx( transform ) ; 2247cdf0e10cSrcweir+ xmlSecAssert2( context != NULL , -1 ) ; 2248cdf0e10cSrcweir+ 2249cdf0e10cSrcweir+ #ifndef XMLSEC_NO_DES 2250cdf0e10cSrcweir+ if( transform->id == xmlSecNssTransformKWDes3Id ) { 2251cdf0e10cSrcweir+ context->cipher = CKM_DES3_CBC ; 2252cdf0e10cSrcweir+ context->keyId = xmlSecNssKeyDataDesId ; 2253cdf0e10cSrcweir+ } else 2254cdf0e10cSrcweir+ #endif /* XMLSEC_NO_DES */ 2255cdf0e10cSrcweir+ 2256cdf0e10cSrcweir+ #ifndef XMLSEC_NO_AES 2257cdf0e10cSrcweir+ if( transform->id == xmlSecNssTransformKWAes128Id ) { 2258cdf0e10cSrcweir+ /* context->cipher = CKM_NETSCAPE_AES_KEY_WRAP ;*/ 2259cdf0e10cSrcweir+ context->cipher = CKM_AES_CBC ; 2260cdf0e10cSrcweir+ context->keyId = xmlSecNssKeyDataAesId ; 2261cdf0e10cSrcweir+ } else 2262cdf0e10cSrcweir+ if( transform->id == xmlSecNssTransformKWAes192Id ) { 2263cdf0e10cSrcweir+ /* context->cipher = CKM_NETSCAPE_AES_KEY_WRAP ;*/ 2264cdf0e10cSrcweir+ context->cipher = CKM_AES_CBC ; 2265cdf0e10cSrcweir+ context->keyId = xmlSecNssKeyDataAesId ; 2266cdf0e10cSrcweir+ } else 2267cdf0e10cSrcweir+ if( transform->id == xmlSecNssTransformKWAes256Id ) { 2268cdf0e10cSrcweir+ /* context->cipher = CKM_NETSCAPE_AES_KEY_WRAP ;*/ 2269cdf0e10cSrcweir+ context->cipher = CKM_AES_CBC ; 2270cdf0e10cSrcweir+ context->keyId = xmlSecNssKeyDataAesId ; 2271cdf0e10cSrcweir+ } else 2272cdf0e10cSrcweir+ #endif /* XMLSEC_NO_AES */ 2273cdf0e10cSrcweir+ 2274cdf0e10cSrcweir+ 2275cdf0e10cSrcweir+ if( 1 ) { 2276cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2277cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), 2278cdf0e10cSrcweir+ NULL , 2279cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2280cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2281cdf0e10cSrcweir+ return(-1); 2282cdf0e10cSrcweir+ } 2283cdf0e10cSrcweir+ 2284cdf0e10cSrcweir+ context->symkey = NULL ; 2285cdf0e10cSrcweir+ context->material = NULL ; 2286cdf0e10cSrcweir+ 2287cdf0e10cSrcweir+ return(0); 2288cdf0e10cSrcweir+} 2289cdf0e10cSrcweir+ 2290cdf0e10cSrcweir+static void 2291cdf0e10cSrcweir+xmlSecNssKeyWrapFinalize(xmlSecTransformPtr transform) { 2292cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr context ; 2293cdf0e10cSrcweir+ 2294cdf0e10cSrcweir+ xmlSecAssert(xmlSecNssKeyWrapCheckId(transform)); 2295cdf0e10cSrcweir+ xmlSecAssert(xmlSecTransformCheckSize(transform, xmlSecNssKeyWrapSize)); 2296cdf0e10cSrcweir+ 2297cdf0e10cSrcweir+ context = xmlSecNssKeyWrapGetCtx( transform ) ; 2298cdf0e10cSrcweir+ xmlSecAssert( context != NULL ) ; 2299cdf0e10cSrcweir+ 2300cdf0e10cSrcweir+ if( context->symkey != NULL ) { 2301cdf0e10cSrcweir+ PK11_FreeSymKey( context->symkey ) ; 2302cdf0e10cSrcweir+ context->symkey = NULL ; 2303cdf0e10cSrcweir+ } 2304cdf0e10cSrcweir+ 2305cdf0e10cSrcweir+ if( context->material != NULL ) { 2306cdf0e10cSrcweir+ xmlSecBufferDestroy(context->material); 2307cdf0e10cSrcweir+ context->material = NULL ; 2308cdf0e10cSrcweir+ } 2309cdf0e10cSrcweir+} 2310cdf0e10cSrcweir+ 2311cdf0e10cSrcweir+static int 2312cdf0e10cSrcweir+xmlSecNssKeyWrapSetKeyReq(xmlSecTransformPtr transform, xmlSecKeyReqPtr keyReq) { 2313cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr context ; 2314cdf0e10cSrcweir+ xmlSecSize cipherSize = 0 ; 2315cdf0e10cSrcweir+ 2316cdf0e10cSrcweir+ 2317cdf0e10cSrcweir+ xmlSecAssert2(xmlSecNssKeyWrapCheckId(transform), -1); 2318cdf0e10cSrcweir+ xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecNssKeyWrapSize), -1); 2319cdf0e10cSrcweir+ xmlSecAssert2((transform->operation == xmlSecTransformOperationEncrypt) || (transform->operation == xmlSecTransformOperationDecrypt), -1); 2320cdf0e10cSrcweir+ xmlSecAssert2(keyReq != NULL, -1); 2321cdf0e10cSrcweir+ 2322cdf0e10cSrcweir+ context = xmlSecNssKeyWrapGetCtx( transform ) ; 2323cdf0e10cSrcweir+ xmlSecAssert2( context != NULL , -1 ) ; 2324cdf0e10cSrcweir+ 2325cdf0e10cSrcweir+ keyReq->keyId = context->keyId; 2326cdf0e10cSrcweir+ keyReq->keyType = xmlSecKeyDataTypeSymmetric; 2327cdf0e10cSrcweir+ if(transform->operation == xmlSecTransformOperationEncrypt) { 2328cdf0e10cSrcweir+ keyReq->keyUsage = xmlSecKeyUsageEncrypt; 2329cdf0e10cSrcweir+ } else { 2330cdf0e10cSrcweir+ keyReq->keyUsage = xmlSecKeyUsageDecrypt; 2331cdf0e10cSrcweir+ } 2332cdf0e10cSrcweir+ 2333cdf0e10cSrcweir+ keyReq->keyBitsSize = xmlSecNssKeyWrapGetKeySize( transform ) ; 2334cdf0e10cSrcweir+ 2335cdf0e10cSrcweir+ return(0); 2336cdf0e10cSrcweir+} 2337cdf0e10cSrcweir+ 2338cdf0e10cSrcweir+static int 2339cdf0e10cSrcweir+xmlSecNssKeyWrapSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) { 2340cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr context = NULL ; 2341cdf0e10cSrcweir+ xmlSecKeyDataPtr keyData = NULL ; 2342cdf0e10cSrcweir+ PK11SymKey* symkey = NULL ; 2343cdf0e10cSrcweir+ 2344cdf0e10cSrcweir+ xmlSecAssert2(xmlSecNssKeyWrapCheckId(transform), -1); 2345cdf0e10cSrcweir+ xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecNssKeyWrapSize), -1); 2346cdf0e10cSrcweir+ xmlSecAssert2((transform->operation == xmlSecTransformOperationEncrypt) || (transform->operation == xmlSecTransformOperationDecrypt), -1); 2347cdf0e10cSrcweir+ xmlSecAssert2(key != NULL, -1); 2348cdf0e10cSrcweir+ 2349cdf0e10cSrcweir+ context = xmlSecNssKeyWrapGetCtx( transform ) ; 2350cdf0e10cSrcweir+ if( context == NULL || context->keyId == NULL || context->symkey != NULL ) { 2351cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2352cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 2353cdf0e10cSrcweir+ "xmlSecNssKeyWrapGetCtx" , 2354cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2355cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2356cdf0e10cSrcweir+ return(-1); 2357cdf0e10cSrcweir+ } 2358cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyCheckId( key, context->keyId ), -1 ) ; 2359cdf0e10cSrcweir+ 2360cdf0e10cSrcweir+ keyData = xmlSecKeyGetValue( key ) ; 2361cdf0e10cSrcweir+ if( keyData == NULL ) { 2362cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2363cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyGetName( key ) ) , 2364cdf0e10cSrcweir+ "xmlSecKeyGetValue" , 2365cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2366cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2367cdf0e10cSrcweir+ return(-1); 2368cdf0e10cSrcweir+ } 2369cdf0e10cSrcweir+ 2370cdf0e10cSrcweir+ if( ( symkey = xmlSecNssSymKeyDataGetKey( keyData ) ) == NULL ) { 2371cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2372cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( keyData ) ) , 2373cdf0e10cSrcweir+ "xmlSecNssSymKeyDataGetKey" , 2374cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2375cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2376cdf0e10cSrcweir+ return(-1); 2377cdf0e10cSrcweir+ } 2378cdf0e10cSrcweir+ 2379cdf0e10cSrcweir+ context->symkey = symkey ; 2380cdf0e10cSrcweir+ 2381cdf0e10cSrcweir+ return(0) ; 2382cdf0e10cSrcweir+} 2383cdf0e10cSrcweir+ 2384cdf0e10cSrcweir+/** 2385cdf0e10cSrcweir+ * key wrap transform 2386cdf0e10cSrcweir+ */ 2387cdf0e10cSrcweir+static int 2388cdf0e10cSrcweir+xmlSecNssKeyWrapCtxInit( 2389cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr ctx , 2390cdf0e10cSrcweir+ xmlSecBufferPtr in , 2391cdf0e10cSrcweir+ xmlSecBufferPtr out , 2392cdf0e10cSrcweir+ int encrypt , 2393cdf0e10cSrcweir+ xmlSecTransformCtxPtr transformCtx 2394cdf0e10cSrcweir+) { 2395cdf0e10cSrcweir+ xmlSecSize blockSize ; 2396cdf0e10cSrcweir+ 2397cdf0e10cSrcweir+ xmlSecAssert2( ctx != NULL , -1 ) ; 2398cdf0e10cSrcweir+ xmlSecAssert2( ctx->cipher != CKM_INVALID_MECHANISM , -1 ) ; 2399cdf0e10cSrcweir+ xmlSecAssert2( ctx->symkey != NULL , -1 ) ; 2400cdf0e10cSrcweir+ xmlSecAssert2( ctx->keyId != NULL , -1 ) ; 2401cdf0e10cSrcweir+ xmlSecAssert2( in != NULL , -1 ) ; 2402cdf0e10cSrcweir+ xmlSecAssert2( out != NULL , -1 ) ; 2403cdf0e10cSrcweir+ xmlSecAssert2( transformCtx != NULL , -1 ) ; 2404cdf0e10cSrcweir+ 2405cdf0e10cSrcweir+ if( ctx->material != NULL ) { 2406cdf0e10cSrcweir+ xmlSecBufferDestroy( ctx->material ) ; 2407cdf0e10cSrcweir+ ctx->material = NULL ; 2408cdf0e10cSrcweir+ } 2409cdf0e10cSrcweir+ 2410cdf0e10cSrcweir+ if( ( blockSize = PK11_GetBlockSize( ctx->cipher , NULL ) ) < 0 ) { 2411cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2412cdf0e10cSrcweir+ NULL , 2413cdf0e10cSrcweir+ "PK11_GetBlockSize" , 2414cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2415cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2416cdf0e10cSrcweir+ return(-1); 2417cdf0e10cSrcweir+ } 2418cdf0e10cSrcweir+ 2419cdf0e10cSrcweir+ ctx->material = xmlSecBufferCreate( blockSize ) ; 2420cdf0e10cSrcweir+ if( ctx->material == NULL ) { 2421cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2422cdf0e10cSrcweir+ NULL , 2423cdf0e10cSrcweir+ "xmlSecBufferCreate" , 2424cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2425cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2426cdf0e10cSrcweir+ return(-1); 2427cdf0e10cSrcweir+ } 2428cdf0e10cSrcweir+ 2429cdf0e10cSrcweir+ /* read raw key material into context */ 2430cdf0e10cSrcweir+ if( xmlSecBufferSetData( ctx->material, xmlSecBufferGetData(in), xmlSecBufferGetSize(in) ) < 0 ) { 2431cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2432cdf0e10cSrcweir+ NULL , 2433cdf0e10cSrcweir+ "xmlSecBufferSetData" , 2434cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2435cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2436cdf0e10cSrcweir+ return(-1); 2437cdf0e10cSrcweir+ } 2438cdf0e10cSrcweir+ 2439cdf0e10cSrcweir+ if( xmlSecBufferRemoveHead( in , xmlSecBufferGetSize(in) ) < 0 ) { 2440cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2441cdf0e10cSrcweir+ NULL , 2442cdf0e10cSrcweir+ "xmlSecBufferRemoveHead" , 2443cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2444cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2445cdf0e10cSrcweir+ return(-1); 2446cdf0e10cSrcweir+ } 2447cdf0e10cSrcweir+ 2448cdf0e10cSrcweir+ return(0); 2449cdf0e10cSrcweir+} 2450cdf0e10cSrcweir+ 2451cdf0e10cSrcweir+/** 2452cdf0e10cSrcweir+ * key wrap transform update 2453cdf0e10cSrcweir+ */ 2454cdf0e10cSrcweir+static int 2455cdf0e10cSrcweir+xmlSecNssKeyWrapCtxUpdate( 2456cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr ctx , 2457cdf0e10cSrcweir+ xmlSecBufferPtr in , 2458cdf0e10cSrcweir+ xmlSecBufferPtr out , 2459cdf0e10cSrcweir+ int encrypt , 2460cdf0e10cSrcweir+ xmlSecTransformCtxPtr transformCtx 2461cdf0e10cSrcweir+) { 2462cdf0e10cSrcweir+ xmlSecAssert2( ctx != NULL , -1 ) ; 2463cdf0e10cSrcweir+ xmlSecAssert2( ctx->cipher != CKM_INVALID_MECHANISM , -1 ) ; 2464cdf0e10cSrcweir+ xmlSecAssert2( ctx->symkey != NULL , -1 ) ; 2465cdf0e10cSrcweir+ xmlSecAssert2( ctx->keyId != NULL , -1 ) ; 2466cdf0e10cSrcweir+ xmlSecAssert2( ctx->material != NULL , -1 ) ; 2467cdf0e10cSrcweir+ xmlSecAssert2( in != NULL , -1 ) ; 2468cdf0e10cSrcweir+ xmlSecAssert2( out != NULL , -1 ) ; 2469cdf0e10cSrcweir+ xmlSecAssert2( transformCtx != NULL , -1 ) ; 2470cdf0e10cSrcweir+ 2471cdf0e10cSrcweir+ /* read raw key material and append into context */ 2472cdf0e10cSrcweir+ if( xmlSecBufferAppend( ctx->material, xmlSecBufferGetData(in), xmlSecBufferGetSize(in) ) < 0 ) { 2473cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2474cdf0e10cSrcweir+ NULL , 2475cdf0e10cSrcweir+ "xmlSecBufferAppend" , 2476cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2477cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2478cdf0e10cSrcweir+ return(-1); 2479cdf0e10cSrcweir+ } 2480cdf0e10cSrcweir+ 2481cdf0e10cSrcweir+ if( xmlSecBufferRemoveHead( in , xmlSecBufferGetSize(in) ) < 0 ) { 2482cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2483cdf0e10cSrcweir+ NULL , 2484cdf0e10cSrcweir+ "xmlSecBufferRemoveHead" , 2485cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2486cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2487cdf0e10cSrcweir+ return(-1); 2488cdf0e10cSrcweir+ } 2489cdf0e10cSrcweir+ 2490cdf0e10cSrcweir+ return(0); 2491cdf0e10cSrcweir+} 2492cdf0e10cSrcweir+ 2493cdf0e10cSrcweir+static int 2494cdf0e10cSrcweir+xmlSecNssKWDes3BufferReverse(xmlSecByte *buf, xmlSecSize size) { 2495cdf0e10cSrcweir+ xmlSecSize s; 2496cdf0e10cSrcweir+ xmlSecSize i; 2497cdf0e10cSrcweir+ xmlSecByte c; 2498cdf0e10cSrcweir+ 2499cdf0e10cSrcweir+ xmlSecAssert2(buf != NULL, -1); 2500cdf0e10cSrcweir+ 2501cdf0e10cSrcweir+ s = size / 2; 2502cdf0e10cSrcweir+ --size; 2503cdf0e10cSrcweir+ for(i = 0; i < s; ++i) { 2504cdf0e10cSrcweir+ c = buf[i]; 2505cdf0e10cSrcweir+ buf[i] = buf[size - i]; 2506cdf0e10cSrcweir+ buf[size - i] = c; 2507cdf0e10cSrcweir+ } 2508cdf0e10cSrcweir+ return(0); 2509cdf0e10cSrcweir+} 2510cdf0e10cSrcweir+ 2511cdf0e10cSrcweir+static xmlSecByte * 2512cdf0e10cSrcweir+xmlSecNssComputeSHA1(const xmlSecByte *in, xmlSecSize inSize, 2513cdf0e10cSrcweir+ xmlSecByte *out, xmlSecSize outSize) 2514cdf0e10cSrcweir+{ 2515cdf0e10cSrcweir+ PK11Context *context = NULL; 2516cdf0e10cSrcweir+ SECStatus s; 2517cdf0e10cSrcweir+ xmlSecByte *digest = NULL; 2518cdf0e10cSrcweir+ unsigned int len; 2519cdf0e10cSrcweir+ 2520cdf0e10cSrcweir+ xmlSecAssert2(in != NULL, NULL); 2521cdf0e10cSrcweir+ xmlSecAssert2(out != NULL, NULL); 2522cdf0e10cSrcweir+ xmlSecAssert2(outSize >= SHA1_LENGTH, NULL); 2523cdf0e10cSrcweir+ 2524cdf0e10cSrcweir+ /* Create a context for hashing (digesting) */ 2525cdf0e10cSrcweir+ context = PK11_CreateDigestContext(SEC_OID_SHA1); 2526cdf0e10cSrcweir+ if (context == NULL) { 2527cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2528cdf0e10cSrcweir+ NULL, 2529cdf0e10cSrcweir+ "PK11_CreateDigestContext", 2530cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2531cdf0e10cSrcweir+ "error code = %d", PORT_GetError()); 2532cdf0e10cSrcweir+ goto done; 2533cdf0e10cSrcweir+ } 2534cdf0e10cSrcweir+ 2535cdf0e10cSrcweir+ s = PK11_DigestBegin(context); 2536cdf0e10cSrcweir+ if (s != SECSuccess) { 2537cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2538cdf0e10cSrcweir+ NULL, 2539cdf0e10cSrcweir+ "PK11_DigestBegin", 2540cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2541cdf0e10cSrcweir+ "error code = %d", PORT_GetError()); 2542cdf0e10cSrcweir+ goto done; 2543cdf0e10cSrcweir+ } 2544cdf0e10cSrcweir+ 2545cdf0e10cSrcweir+ s = PK11_DigestOp(context, in, inSize); 2546cdf0e10cSrcweir+ if (s != SECSuccess) { 2547cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2548cdf0e10cSrcweir+ NULL, 2549cdf0e10cSrcweir+ "PK11_DigestOp", 2550cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2551cdf0e10cSrcweir+ "error code = %d", PORT_GetError()); 2552cdf0e10cSrcweir+ goto done; 2553cdf0e10cSrcweir+ } 2554cdf0e10cSrcweir+ 2555cdf0e10cSrcweir+ s = PK11_DigestFinal(context, out, &len, outSize); 2556cdf0e10cSrcweir+ if (s != SECSuccess) { 2557cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2558cdf0e10cSrcweir+ NULL, 2559cdf0e10cSrcweir+ "PK11_DigestFinal", 2560cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2561cdf0e10cSrcweir+ "error code = %d", PORT_GetError()); 2562cdf0e10cSrcweir+ goto done; 2563cdf0e10cSrcweir+ } 2564cdf0e10cSrcweir+ xmlSecAssert2(len == SHA1_LENGTH, NULL); 2565cdf0e10cSrcweir+ 2566cdf0e10cSrcweir+ digest = out; 2567cdf0e10cSrcweir+ 2568cdf0e10cSrcweir+done: 2569cdf0e10cSrcweir+ if (context != NULL) { 2570cdf0e10cSrcweir+ PK11_DestroyContext(context, PR_TRUE); 2571cdf0e10cSrcweir+ } 2572cdf0e10cSrcweir+ return (digest); 2573cdf0e10cSrcweir+} 2574cdf0e10cSrcweir+ 2575cdf0e10cSrcweir+static int 2576cdf0e10cSrcweir+xmlSecNssKWDes3Encrypt( 2577cdf0e10cSrcweir+ PK11SymKey* symKey , 2578cdf0e10cSrcweir+ CK_MECHANISM_TYPE cipherMech , 2579cdf0e10cSrcweir+ const xmlSecByte* iv , 2580cdf0e10cSrcweir+ xmlSecSize ivSize , 2581cdf0e10cSrcweir+ const xmlSecByte* in , 2582cdf0e10cSrcweir+ xmlSecSize inSize , 2583cdf0e10cSrcweir+ xmlSecByte* out , 2584cdf0e10cSrcweir+ xmlSecSize outSize , 2585cdf0e10cSrcweir+ int enc 2586cdf0e10cSrcweir+) { 2587cdf0e10cSrcweir+ PK11Context* EncContext = NULL; 2588cdf0e10cSrcweir+ SECItem ivItem ; 2589cdf0e10cSrcweir+ SECItem* secParam = NULL ; 2590cdf0e10cSrcweir+ int tmp1_outlen; 2591cdf0e10cSrcweir+ unsigned int tmp2_outlen; 2592cdf0e10cSrcweir+ int result_len = -1; 2593cdf0e10cSrcweir+ SECStatus rv; 2594cdf0e10cSrcweir+ 2595cdf0e10cSrcweir+ xmlSecAssert2( cipherMech != CKM_INVALID_MECHANISM , -1 ) ; 2596cdf0e10cSrcweir+ xmlSecAssert2( symKey != NULL , -1 ) ; 2597cdf0e10cSrcweir+ xmlSecAssert2(iv != NULL, -1); 2598cdf0e10cSrcweir+ xmlSecAssert2(ivSize == XMLSEC_NSS_DES3_IV_LENGTH, -1); 2599cdf0e10cSrcweir+ xmlSecAssert2(in != NULL, -1); 2600cdf0e10cSrcweir+ xmlSecAssert2(inSize > 0, -1); 2601cdf0e10cSrcweir+ xmlSecAssert2(out != NULL, -1); 2602cdf0e10cSrcweir+ xmlSecAssert2(outSize >= inSize, -1); 2603cdf0e10cSrcweir+ 2604cdf0e10cSrcweir+ /* Prepare IV */ 2605cdf0e10cSrcweir+ ivItem.data = ( unsigned char* )iv ; 2606cdf0e10cSrcweir+ ivItem.len = ivSize ; 2607cdf0e10cSrcweir+ 2608cdf0e10cSrcweir+ secParam = PK11_ParamFromIV(cipherMech, &ivItem); 2609cdf0e10cSrcweir+ if (secParam == NULL) { 2610cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2611cdf0e10cSrcweir+ NULL, 2612cdf0e10cSrcweir+ "PK11_ParamFromIV", 2613cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2614cdf0e10cSrcweir+ "Error code = %d", PORT_GetError()); 2615cdf0e10cSrcweir+ goto done; 2616cdf0e10cSrcweir+ } 2617cdf0e10cSrcweir+ 2618cdf0e10cSrcweir+ EncContext = PK11_CreateContextBySymKey(cipherMech, 2619cdf0e10cSrcweir+ enc ? CKA_ENCRYPT : CKA_DECRYPT, 2620cdf0e10cSrcweir+ symKey, secParam); 2621cdf0e10cSrcweir+ if (EncContext == NULL) { 2622cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2623cdf0e10cSrcweir+ NULL, 2624cdf0e10cSrcweir+ "PK11_CreateContextBySymKey", 2625cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2626cdf0e10cSrcweir+ "Error code = %d", PORT_GetError()); 2627cdf0e10cSrcweir+ goto done; 2628cdf0e10cSrcweir+ } 2629cdf0e10cSrcweir+ 2630cdf0e10cSrcweir+ tmp1_outlen = tmp2_outlen = 0; 2631cdf0e10cSrcweir+ rv = PK11_CipherOp(EncContext, out, &tmp1_outlen, outSize, 2632cdf0e10cSrcweir+ (unsigned char *)in, inSize); 2633cdf0e10cSrcweir+ if (rv != SECSuccess) { 2634cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2635cdf0e10cSrcweir+ NULL, 2636cdf0e10cSrcweir+ "PK11_CipherOp", 2637cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2638cdf0e10cSrcweir+ "Error code = %d", PORT_GetError()); 2639cdf0e10cSrcweir+ goto done; 2640cdf0e10cSrcweir+ } 2641cdf0e10cSrcweir+ 2642cdf0e10cSrcweir+ rv = PK11_DigestFinal(EncContext, out+tmp1_outlen, 2643cdf0e10cSrcweir+ &tmp2_outlen, outSize-tmp1_outlen); 2644cdf0e10cSrcweir+ if (rv != SECSuccess) { 2645cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2646cdf0e10cSrcweir+ NULL, 2647cdf0e10cSrcweir+ "PK11_DigestFinal", 2648cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2649cdf0e10cSrcweir+ "Error code = %d", PORT_GetError()); 2650cdf0e10cSrcweir+ goto done; 2651cdf0e10cSrcweir+ } 2652cdf0e10cSrcweir+ 2653cdf0e10cSrcweir+ result_len = tmp1_outlen + tmp2_outlen; 2654cdf0e10cSrcweir+ 2655cdf0e10cSrcweir+done: 2656cdf0e10cSrcweir+ if (secParam) { 2657cdf0e10cSrcweir+ SECITEM_FreeItem(secParam, PR_TRUE); 2658cdf0e10cSrcweir+ } 2659cdf0e10cSrcweir+ if (EncContext) { 2660cdf0e10cSrcweir+ PK11_DestroyContext(EncContext, PR_TRUE); 2661cdf0e10cSrcweir+ } 2662cdf0e10cSrcweir+ 2663cdf0e10cSrcweir+ return(result_len); 2664cdf0e10cSrcweir+} 2665cdf0e10cSrcweir+ 2666cdf0e10cSrcweir+static int 2667cdf0e10cSrcweir+xmlSecNssKeyWrapDesOp( 2668cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr ctx , 2669cdf0e10cSrcweir+ int encrypt , 2670cdf0e10cSrcweir+ xmlSecBufferPtr result 2671cdf0e10cSrcweir+) { 2672cdf0e10cSrcweir+ xmlSecByte sha1[SHA1_LENGTH]; 2673cdf0e10cSrcweir+ xmlSecByte iv[XMLSEC_NSS_DES3_IV_LENGTH]; 2674cdf0e10cSrcweir+ xmlSecByte* in; 2675cdf0e10cSrcweir+ xmlSecSize inSize; 2676cdf0e10cSrcweir+ xmlSecByte* out; 2677cdf0e10cSrcweir+ xmlSecSize outSize; 2678cdf0e10cSrcweir+ xmlSecSize s; 2679cdf0e10cSrcweir+ int ret; 2680cdf0e10cSrcweir+ SECStatus status; 2681cdf0e10cSrcweir+ 2682cdf0e10cSrcweir+ xmlSecAssert2( ctx != NULL , -1 ) ; 2683cdf0e10cSrcweir+ xmlSecAssert2( ctx->cipher != CKM_INVALID_MECHANISM , -1 ) ; 2684cdf0e10cSrcweir+ xmlSecAssert2( ctx->symkey != NULL , -1 ) ; 2685cdf0e10cSrcweir+ xmlSecAssert2( ctx->keyId != NULL , -1 ) ; 2686cdf0e10cSrcweir+ xmlSecAssert2( ctx->material != NULL , -1 ) ; 2687cdf0e10cSrcweir+ xmlSecAssert2( result != NULL , -1 ) ; 2688cdf0e10cSrcweir+ 2689cdf0e10cSrcweir+ in = xmlSecBufferGetData(ctx->material); 2690cdf0e10cSrcweir+ inSize = xmlSecBufferGetSize(ctx->material) ; 2691cdf0e10cSrcweir+ out = xmlSecBufferGetData(result); 2692cdf0e10cSrcweir+ outSize = xmlSecBufferGetMaxSize(result) ; 2693cdf0e10cSrcweir+ if( encrypt ) { 2694cdf0e10cSrcweir+ /* step 2: calculate sha1 and CMS */ 2695cdf0e10cSrcweir+ if(xmlSecNssComputeSHA1(in, inSize, sha1, SHA1_LENGTH) == NULL) { 2696cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2697cdf0e10cSrcweir+ NULL, 2698cdf0e10cSrcweir+ "xmlSecNssComputeSHA1", 2699cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2700cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2701cdf0e10cSrcweir+ return(-1); 2702cdf0e10cSrcweir+ } 2703cdf0e10cSrcweir+ 2704cdf0e10cSrcweir+ /* step 3: construct WKCKS */ 2705cdf0e10cSrcweir+ memcpy(out, in, inSize); 2706cdf0e10cSrcweir+ memcpy(out + inSize, sha1, XMLSEC_NSS_DES3_BLOCK_LENGTH); 2707cdf0e10cSrcweir+ 2708cdf0e10cSrcweir+ /* step 4: generate random iv */ 2709cdf0e10cSrcweir+ status = PK11_GenerateRandom(iv, XMLSEC_NSS_DES3_IV_LENGTH); 2710cdf0e10cSrcweir+ if(status != SECSuccess) { 2711cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2712cdf0e10cSrcweir+ NULL, 2713cdf0e10cSrcweir+ "PK11_GenerateRandom", 2714cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2715cdf0e10cSrcweir+ "error code = %d", PORT_GetError()); 2716cdf0e10cSrcweir+ return(-1); 2717cdf0e10cSrcweir+ } 2718cdf0e10cSrcweir+ 2719cdf0e10cSrcweir+ /* step 5: first encryption, result is TEMP1 */ 2720cdf0e10cSrcweir+ ret = xmlSecNssKWDes3Encrypt( ctx->symkey, ctx->cipher, 2721cdf0e10cSrcweir+ iv, XMLSEC_NSS_DES3_IV_LENGTH, 2722cdf0e10cSrcweir+ out, inSize + XMLSEC_NSS_DES3_IV_LENGTH, 2723cdf0e10cSrcweir+ out, outSize, 1); 2724cdf0e10cSrcweir+ if(ret < 0) { 2725cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2726cdf0e10cSrcweir+ NULL, 2727cdf0e10cSrcweir+ "xmlSecNssKWDes3Encrypt", 2728cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2729cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2730cdf0e10cSrcweir+ return(-1); 2731cdf0e10cSrcweir+ } 2732cdf0e10cSrcweir+ 2733cdf0e10cSrcweir+ /* step 6: construct TEMP2=IV || TEMP1 */ 2734cdf0e10cSrcweir+ memmove(out + XMLSEC_NSS_DES3_IV_LENGTH, out, 2735cdf0e10cSrcweir+ inSize + XMLSEC_NSS_DES3_IV_LENGTH); 2736cdf0e10cSrcweir+ memcpy(out, iv, XMLSEC_NSS_DES3_IV_LENGTH); 2737cdf0e10cSrcweir+ s = ret + XMLSEC_NSS_DES3_IV_LENGTH; 2738cdf0e10cSrcweir+ 2739cdf0e10cSrcweir+ /* step 7: reverse octets order, result is TEMP3 */ 2740cdf0e10cSrcweir+ ret = xmlSecNssKWDes3BufferReverse(out, s); 2741cdf0e10cSrcweir+ if(ret < 0) { 2742cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2743cdf0e10cSrcweir+ NULL, 2744cdf0e10cSrcweir+ "xmlSecNssKWDes3BufferReverse", 2745cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2746cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2747cdf0e10cSrcweir+ return(-1); 2748cdf0e10cSrcweir+ } 2749cdf0e10cSrcweir+ 2750cdf0e10cSrcweir+ /* step 8: second encryption with static IV */ 2751cdf0e10cSrcweir+ ret = xmlSecNssKWDes3Encrypt( ctx->symkey, ctx->cipher, 2752cdf0e10cSrcweir+ xmlSecNssKWDes3Iv, XMLSEC_NSS_DES3_IV_LENGTH, 2753cdf0e10cSrcweir+ out, s, 2754cdf0e10cSrcweir+ out, outSize, 1); 2755cdf0e10cSrcweir+ if(ret < 0) { 2756cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2757cdf0e10cSrcweir+ NULL, 2758cdf0e10cSrcweir+ "xmlSecNssKWDes3Encrypt", 2759cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2760cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2761cdf0e10cSrcweir+ return(-1); 2762cdf0e10cSrcweir+ } 2763cdf0e10cSrcweir+ s = ret; 2764cdf0e10cSrcweir+ 2765cdf0e10cSrcweir+ if( xmlSecBufferSetSize( result , s ) < 0 ) { 2766cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2767cdf0e10cSrcweir+ NULL, 2768cdf0e10cSrcweir+ "xmlSecBufferSetSize", 2769cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2770cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2771cdf0e10cSrcweir+ return(-1); 2772cdf0e10cSrcweir+ } 2773cdf0e10cSrcweir+ } else { 2774cdf0e10cSrcweir+ /* step 2: first decryption with static IV, result is TEMP3 */ 2775cdf0e10cSrcweir+ ret = xmlSecNssKWDes3Encrypt( ctx->symkey, ctx->cipher, 2776cdf0e10cSrcweir+ xmlSecNssKWDes3Iv, XMLSEC_NSS_DES3_IV_LENGTH, 2777cdf0e10cSrcweir+ in, inSize, 2778cdf0e10cSrcweir+ out, outSize, 0); 2779cdf0e10cSrcweir+ if((ret < 0) || (ret < XMLSEC_NSS_DES3_IV_LENGTH)) { 2780cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2781cdf0e10cSrcweir+ NULL, 2782cdf0e10cSrcweir+ "xmlSecNssKWDes3Encrypt", 2783cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2784cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2785cdf0e10cSrcweir+ return(-1); 2786cdf0e10cSrcweir+ } 2787cdf0e10cSrcweir+ s = ret; 2788cdf0e10cSrcweir+ 2789cdf0e10cSrcweir+ /* step 3: reverse octets order in TEMP3, result is TEMP2 */ 2790cdf0e10cSrcweir+ ret = xmlSecNssKWDes3BufferReverse(out, s); 2791cdf0e10cSrcweir+ if(ret < 0) { 2792cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2793cdf0e10cSrcweir+ NULL, 2794cdf0e10cSrcweir+ "xmlSecNssKWDes3BufferReverse", 2795cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2796cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2797cdf0e10cSrcweir+ return(-1); 2798cdf0e10cSrcweir+ } 2799cdf0e10cSrcweir+ 2800cdf0e10cSrcweir+ /* steps 4 and 5: get IV and decrypt second time, result is WKCKS */ 2801cdf0e10cSrcweir+ ret = xmlSecNssKWDes3Encrypt( ctx->symkey, ctx->cipher, 2802cdf0e10cSrcweir+ out, XMLSEC_NSS_DES3_IV_LENGTH, 2803cdf0e10cSrcweir+ out+XMLSEC_NSS_DES3_IV_LENGTH, s-XMLSEC_NSS_DES3_IV_LENGTH, 2804cdf0e10cSrcweir+ out, outSize, 0); 2805cdf0e10cSrcweir+ if((ret < 0) || (ret < XMLSEC_NSS_DES3_BLOCK_LENGTH)) { 2806cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2807cdf0e10cSrcweir+ NULL, 2808cdf0e10cSrcweir+ "xmlSecNssKWDes3Encrypt", 2809cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2810cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2811cdf0e10cSrcweir+ return(-1); 2812cdf0e10cSrcweir+ } 2813cdf0e10cSrcweir+ s = ret - XMLSEC_NSS_DES3_IV_LENGTH; 2814cdf0e10cSrcweir+ 2815cdf0e10cSrcweir+ /* steps 6 and 7: calculate SHA1 and validate it */ 2816cdf0e10cSrcweir+ if(xmlSecNssComputeSHA1(out, s, sha1, SHA1_LENGTH) == NULL) { 2817cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2818cdf0e10cSrcweir+ NULL, 2819cdf0e10cSrcweir+ "xmlSecNssComputeSHA1", 2820cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED, 2821cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2822cdf0e10cSrcweir+ return(-1); 2823cdf0e10cSrcweir+ } 2824cdf0e10cSrcweir+ 2825cdf0e10cSrcweir+ if(memcmp(sha1, out + s, XMLSEC_NSS_DES3_BLOCK_LENGTH) != 0) { 2826cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2827cdf0e10cSrcweir+ NULL, 2828cdf0e10cSrcweir+ NULL, 2829cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_DATA, 2830cdf0e10cSrcweir+ "SHA1 does not match"); 2831cdf0e10cSrcweir+ return(-1); 2832cdf0e10cSrcweir+ } 2833cdf0e10cSrcweir+ 2834cdf0e10cSrcweir+ if( xmlSecBufferSetSize( result , s ) < 0 ) { 2835cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 2836cdf0e10cSrcweir+ NULL, 2837cdf0e10cSrcweir+ "xmlSecBufferSetSize", 2838cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 2839cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 2840cdf0e10cSrcweir+ return(-1); 2841cdf0e10cSrcweir+ } 2842cdf0e10cSrcweir+ } 2843cdf0e10cSrcweir+ 2844cdf0e10cSrcweir+ return(0); 2845cdf0e10cSrcweir+} 2846cdf0e10cSrcweir+ 2847cdf0e10cSrcweir+static int 2848cdf0e10cSrcweir+xmlSecNssKeyWrapAesOp( 2849cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr ctx , 2850cdf0e10cSrcweir+ int encrypt , 2851cdf0e10cSrcweir+ xmlSecBufferPtr result 2852cdf0e10cSrcweir+) { 2853cdf0e10cSrcweir+ PK11Context* cipherCtx = NULL; 2854cdf0e10cSrcweir+ SECItem ivItem ; 2855cdf0e10cSrcweir+ SECItem* secParam = NULL ; 2856cdf0e10cSrcweir+ xmlSecSize inSize ; 2857cdf0e10cSrcweir+ xmlSecSize inBlocks ; 2858cdf0e10cSrcweir+ int blockSize ; 2859cdf0e10cSrcweir+ int midSize ; 2860cdf0e10cSrcweir+ int finSize ; 2861cdf0e10cSrcweir+ xmlSecByte* out ; 2862cdf0e10cSrcweir+ xmlSecSize outSize; 2863cdf0e10cSrcweir+ 2864cdf0e10cSrcweir+ xmlSecAssert2( ctx != NULL , -1 ) ; 2865cdf0e10cSrcweir+ xmlSecAssert2( ctx->cipher != CKM_INVALID_MECHANISM , -1 ) ; 2866cdf0e10cSrcweir+ xmlSecAssert2( ctx->symkey != NULL , -1 ) ; 2867cdf0e10cSrcweir+ xmlSecAssert2( ctx->keyId != NULL , -1 ) ; 2868cdf0e10cSrcweir+ xmlSecAssert2( ctx->material != NULL , -1 ) ; 2869cdf0e10cSrcweir+ xmlSecAssert2( result != NULL , -1 ) ; 2870cdf0e10cSrcweir+ 2871cdf0e10cSrcweir+ /* Do not set any IV */ 2872cdf0e10cSrcweir+ memset(&ivItem, 0, sizeof(ivItem)); 2873cdf0e10cSrcweir+ 2874cdf0e10cSrcweir+ /* Get block size */ 2875cdf0e10cSrcweir+ if( ( blockSize = PK11_GetBlockSize( ctx->cipher , NULL ) ) < 0 ) { 2876cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2877cdf0e10cSrcweir+ NULL , 2878cdf0e10cSrcweir+ "PK11_GetBlockSize" , 2879cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2880cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2881cdf0e10cSrcweir+ return(-1); 2882cdf0e10cSrcweir+ } 2883cdf0e10cSrcweir+ 2884cdf0e10cSrcweir+ inSize = xmlSecBufferGetSize( ctx->material ) ; 2885cdf0e10cSrcweir+ if( xmlSecBufferSetMaxSize( result , inSize + blockSize ) < 0 ) { 2886cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2887cdf0e10cSrcweir+ NULL , 2888cdf0e10cSrcweir+ "xmlSecBufferSetMaxSize" , 2889cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2890cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2891cdf0e10cSrcweir+ return(-1); 2892cdf0e10cSrcweir+ } 2893cdf0e10cSrcweir+ 2894cdf0e10cSrcweir+ /* Get Param for context initialization */ 2895cdf0e10cSrcweir+ if( ( secParam = PK11_ParamFromIV( ctx->cipher , &ivItem ) ) == NULL ) { 2896cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2897cdf0e10cSrcweir+ NULL , 2898cdf0e10cSrcweir+ "PK11_ParamFromIV" , 2899cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2900cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2901cdf0e10cSrcweir+ return(-1); 2902cdf0e10cSrcweir+ } 2903cdf0e10cSrcweir+ 2904cdf0e10cSrcweir+ cipherCtx = PK11_CreateContextBySymKey( ctx->cipher , encrypt ? CKA_ENCRYPT : CKA_DECRYPT , ctx->symkey , secParam ) ; 2905cdf0e10cSrcweir+ if( cipherCtx == NULL ) { 2906cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2907cdf0e10cSrcweir+ NULL , 2908cdf0e10cSrcweir+ "PK11_CreateContextBySymKey" , 2909cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2910cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2911cdf0e10cSrcweir+ SECITEM_FreeItem( secParam , PR_TRUE ) ; 2912cdf0e10cSrcweir+ return(-1); 2913cdf0e10cSrcweir+ } 2914cdf0e10cSrcweir+ 2915cdf0e10cSrcweir+ out = xmlSecBufferGetData(result) ; 2916cdf0e10cSrcweir+ outSize = xmlSecBufferGetMaxSize(result) ; 2917cdf0e10cSrcweir+ if( PK11_CipherOp( cipherCtx , out, &midSize , outSize , xmlSecBufferGetData( ctx->material ) , inSize ) != SECSuccess ) { 2918cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2919cdf0e10cSrcweir+ NULL , 2920cdf0e10cSrcweir+ "PK11_CipherOp" , 2921cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2922cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2923cdf0e10cSrcweir+ return(-1); 2924cdf0e10cSrcweir+ } 2925cdf0e10cSrcweir+ 2926cdf0e10cSrcweir+ if( PK11_DigestFinal( cipherCtx , out + midSize , &finSize , outSize - midSize ) != SECSuccess ) { 2927cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2928cdf0e10cSrcweir+ NULL , 2929cdf0e10cSrcweir+ "PK11_DigestFinal" , 2930cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2931cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2932cdf0e10cSrcweir+ return(-1); 2933cdf0e10cSrcweir+ } 2934cdf0e10cSrcweir+ 2935cdf0e10cSrcweir+ if( xmlSecBufferSetSize( result , midSize + finSize ) < 0 ) { 2936cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2937cdf0e10cSrcweir+ NULL , 2938cdf0e10cSrcweir+ "xmlSecBufferSetSize" , 2939cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2940cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2941cdf0e10cSrcweir+ return(-1); 2942cdf0e10cSrcweir+ } 2943cdf0e10cSrcweir+ 2944cdf0e10cSrcweir+ return 0 ; 2945cdf0e10cSrcweir+} 2946cdf0e10cSrcweir+ 2947cdf0e10cSrcweir+/** 2948cdf0e10cSrcweir+ * Block cipher transform final 2949cdf0e10cSrcweir+ */ 2950cdf0e10cSrcweir+static int 2951cdf0e10cSrcweir+xmlSecNssKeyWrapCtxFinal( 2952cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr ctx , 2953cdf0e10cSrcweir+ xmlSecBufferPtr in , 2954cdf0e10cSrcweir+ xmlSecBufferPtr out , 2955cdf0e10cSrcweir+ int encrypt , 2956cdf0e10cSrcweir+ xmlSecTransformCtxPtr transformCtx 2957cdf0e10cSrcweir+) { 2958cdf0e10cSrcweir+ PK11SymKey* targetKey ; 2959cdf0e10cSrcweir+ xmlSecSize blockSize ; 2960cdf0e10cSrcweir+ xmlSecBufferPtr result ; 2961cdf0e10cSrcweir+ 2962cdf0e10cSrcweir+ xmlSecAssert2( ctx != NULL , -1 ) ; 2963cdf0e10cSrcweir+ xmlSecAssert2( ctx->cipher != CKM_INVALID_MECHANISM , -1 ) ; 2964cdf0e10cSrcweir+ xmlSecAssert2( ctx->symkey != NULL , -1 ) ; 2965cdf0e10cSrcweir+ xmlSecAssert2( ctx->keyId != NULL , -1 ) ; 2966cdf0e10cSrcweir+ xmlSecAssert2( ctx->material != NULL , -1 ) ; 2967cdf0e10cSrcweir+ xmlSecAssert2( in != NULL , -1 ) ; 2968cdf0e10cSrcweir+ xmlSecAssert2( out != NULL , -1 ) ; 2969cdf0e10cSrcweir+ xmlSecAssert2( transformCtx != NULL , -1 ) ; 2970cdf0e10cSrcweir+ 2971cdf0e10cSrcweir+ /* read raw key material and append into context */ 2972cdf0e10cSrcweir+ if( xmlSecBufferAppend( ctx->material, xmlSecBufferGetData(in), xmlSecBufferGetSize(in) ) < 0 ) { 2973cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2974cdf0e10cSrcweir+ NULL , 2975cdf0e10cSrcweir+ "xmlSecBufferAppend" , 2976cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2977cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2978cdf0e10cSrcweir+ return(-1); 2979cdf0e10cSrcweir+ } 2980cdf0e10cSrcweir+ 2981cdf0e10cSrcweir+ if( xmlSecBufferRemoveHead( in , xmlSecBufferGetSize(in) ) < 0 ) { 2982cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2983cdf0e10cSrcweir+ NULL , 2984cdf0e10cSrcweir+ "xmlSecBufferRemoveHead" , 2985cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2986cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2987cdf0e10cSrcweir+ return(-1); 2988cdf0e10cSrcweir+ } 2989cdf0e10cSrcweir+ 2990*38e54eaaSJohn Bampton+ /* Now we get all of the key material */ 2991cdf0e10cSrcweir+ /* from now on we will wrap or unwrap the key */ 2992cdf0e10cSrcweir+ if( ( blockSize = PK11_GetBlockSize( ctx->cipher , NULL ) ) < 0 ) { 2993cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 2994cdf0e10cSrcweir+ NULL , 2995cdf0e10cSrcweir+ "PK11_GetBlockSize" , 2996cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 2997cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 2998cdf0e10cSrcweir+ return(-1); 2999cdf0e10cSrcweir+ } 3000cdf0e10cSrcweir+ 3001cdf0e10cSrcweir+ result = xmlSecBufferCreate( blockSize ) ; 3002cdf0e10cSrcweir+ if( result == NULL ) { 3003cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3004cdf0e10cSrcweir+ NULL , 3005cdf0e10cSrcweir+ "xmlSecBufferCreate" , 3006cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3007cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3008cdf0e10cSrcweir+ return(-1); 3009cdf0e10cSrcweir+ } 3010cdf0e10cSrcweir+ 3011cdf0e10cSrcweir+ switch( ctx->cipher ) { 3012cdf0e10cSrcweir+ case CKM_DES3_CBC : 3013cdf0e10cSrcweir+ if( xmlSecNssKeyWrapDesOp(ctx, encrypt, result) < 0 ) { 3014cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3015cdf0e10cSrcweir+ NULL , 3016cdf0e10cSrcweir+ "xmlSecNssKeyWrapDesOp" , 3017cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3018cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3019cdf0e10cSrcweir+ xmlSecBufferDestroy(result); 3020cdf0e10cSrcweir+ return(-1); 3021cdf0e10cSrcweir+ } 3022cdf0e10cSrcweir+ break ; 3023cdf0e10cSrcweir+ /* case CKM_NETSCAPE_AES_KEY_WRAP :*/ 3024cdf0e10cSrcweir+ case CKM_AES_CBC : 3025cdf0e10cSrcweir+ if( xmlSecNssKeyWrapAesOp(ctx, encrypt, result) < 0 ) { 3026cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3027cdf0e10cSrcweir+ NULL , 3028cdf0e10cSrcweir+ "xmlSecNssKeyWrapAesOp" , 3029cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3030cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3031cdf0e10cSrcweir+ xmlSecBufferDestroy(result); 3032cdf0e10cSrcweir+ return(-1); 3033cdf0e10cSrcweir+ } 3034cdf0e10cSrcweir+ break ; 3035cdf0e10cSrcweir+ } 3036cdf0e10cSrcweir+ 3037cdf0e10cSrcweir+ /* Write output */ 3038cdf0e10cSrcweir+ if( xmlSecBufferAppend( out, xmlSecBufferGetData(result), xmlSecBufferGetSize(result) ) < 0 ) { 3039cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3040cdf0e10cSrcweir+ NULL , 3041cdf0e10cSrcweir+ "xmlSecBufferAppend" , 3042cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3043cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3044cdf0e10cSrcweir+ xmlSecBufferDestroy(result); 3045cdf0e10cSrcweir+ return(-1); 3046cdf0e10cSrcweir+ } 3047cdf0e10cSrcweir+ xmlSecBufferDestroy(result); 3048cdf0e10cSrcweir+ 3049cdf0e10cSrcweir+ return(0); 3050cdf0e10cSrcweir+} 3051cdf0e10cSrcweir+ 3052cdf0e10cSrcweir+static int 3053cdf0e10cSrcweir+xmlSecNssKeyWrapExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxPtr transformCtx) { 3054cdf0e10cSrcweir+ xmlSecNssKeyWrapCtxPtr context = NULL ; 3055cdf0e10cSrcweir+ xmlSecBufferPtr inBuf, outBuf ; 3056cdf0e10cSrcweir+ int operation ; 3057cdf0e10cSrcweir+ int rtv ; 3058cdf0e10cSrcweir+ 3059cdf0e10cSrcweir+ xmlSecAssert2( xmlSecNssKeyWrapCheckId( transform ), -1 ) ; 3060cdf0e10cSrcweir+ xmlSecAssert2( xmlSecTransformCheckSize( transform, xmlSecNssKeyWrapSize ), -1 ) ; 3061cdf0e10cSrcweir+ xmlSecAssert2( ( transform->operation == xmlSecTransformOperationEncrypt ) || ( transform->operation == xmlSecTransformOperationDecrypt ), -1 ) ; 3062cdf0e10cSrcweir+ xmlSecAssert2( transformCtx != NULL , -1 ) ; 3063cdf0e10cSrcweir+ 3064cdf0e10cSrcweir+ context = xmlSecNssKeyWrapGetCtx( transform ) ; 3065cdf0e10cSrcweir+ if( context == NULL ) { 3066cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3067cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3068cdf0e10cSrcweir+ "xmlSecNssKeyWrapGetCtx" , 3069cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3070cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3071cdf0e10cSrcweir+ return(-1); 3072cdf0e10cSrcweir+ } 3073cdf0e10cSrcweir+ 3074cdf0e10cSrcweir+ inBuf = &( transform->inBuf ) ; 3075cdf0e10cSrcweir+ outBuf = &( transform->outBuf ) ; 3076cdf0e10cSrcweir+ 3077cdf0e10cSrcweir+ if( transform->status == xmlSecTransformStatusNone ) { 3078cdf0e10cSrcweir+ transform->status = xmlSecTransformStatusWorking ; 3079cdf0e10cSrcweir+ } 3080cdf0e10cSrcweir+ 3081cdf0e10cSrcweir+ operation = ( transform->operation == xmlSecTransformOperationEncrypt ) ? 1 : 0 ; 3082cdf0e10cSrcweir+ if( transform->status == xmlSecTransformStatusWorking ) { 3083cdf0e10cSrcweir+ if( context->material == NULL ) { 3084cdf0e10cSrcweir+ rtv = xmlSecNssKeyWrapCtxInit( context, inBuf , outBuf , operation , transformCtx ) ; 3085cdf0e10cSrcweir+ if( rtv < 0 ) { 3086cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3087cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3088cdf0e10cSrcweir+ "xmlSecNssKeyWrapCtxInit" , 3089cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_STATUS , 3090cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3091cdf0e10cSrcweir+ return(-1); 3092cdf0e10cSrcweir+ } 3093cdf0e10cSrcweir+ } 3094cdf0e10cSrcweir+ 3095cdf0e10cSrcweir+ if( context->material == NULL && last != 0 ) { 3096cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3097cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3098cdf0e10cSrcweir+ NULL , 3099cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_STATUS , 3100509df7cbSJohn Bampton+ "No enough data to initialize transform" ) ; 3101cdf0e10cSrcweir+ return(-1); 3102cdf0e10cSrcweir+ } 3103cdf0e10cSrcweir+ 3104cdf0e10cSrcweir+ if( context->material != NULL ) { 3105cdf0e10cSrcweir+ rtv = xmlSecNssKeyWrapCtxUpdate( context, inBuf , outBuf , operation , transformCtx ) ; 3106cdf0e10cSrcweir+ if( rtv < 0 ) { 3107cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3108cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3109cdf0e10cSrcweir+ "xmlSecNssKeyWrapCtxUpdate" , 3110cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_STATUS , 3111cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3112cdf0e10cSrcweir+ return(-1); 3113cdf0e10cSrcweir+ } 3114cdf0e10cSrcweir+ } 3115cdf0e10cSrcweir+ 3116cdf0e10cSrcweir+ if( last ) { 3117cdf0e10cSrcweir+ rtv = xmlSecNssKeyWrapCtxFinal( context, inBuf , outBuf , operation , transformCtx ) ; 3118cdf0e10cSrcweir+ if( rtv < 0 ) { 3119cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3120cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3121cdf0e10cSrcweir+ "xmlSecNssKeyWrapCtxFinal" , 3122cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_STATUS , 3123cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3124cdf0e10cSrcweir+ return(-1); 3125cdf0e10cSrcweir+ } 3126cdf0e10cSrcweir+ transform->status = xmlSecTransformStatusFinished ; 3127cdf0e10cSrcweir+ } 3128cdf0e10cSrcweir+ } else if( transform->status == xmlSecTransformStatusFinished ) { 3129cdf0e10cSrcweir+ if( xmlSecBufferGetSize( inBuf ) != 0 ) { 3130cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3131cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3132cdf0e10cSrcweir+ NULL , 3133cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_STATUS , 3134cdf0e10cSrcweir+ "status=%d", transform->status ) ; 3135cdf0e10cSrcweir+ return(-1); 3136cdf0e10cSrcweir+ } 3137cdf0e10cSrcweir+ } else { 3138cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3139cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecTransformGetName( transform ) ) , 3140cdf0e10cSrcweir+ NULL , 3141cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_STATUS , 3142cdf0e10cSrcweir+ "status=%d", transform->status ) ; 3143cdf0e10cSrcweir+ return(-1); 3144cdf0e10cSrcweir+ } 3145cdf0e10cSrcweir+ 3146cdf0e10cSrcweir+ return(0); 3147cdf0e10cSrcweir+} 3148cdf0e10cSrcweir+ 3149cdf0e10cSrcweir+#ifndef XMLSEC_NO_AES 3150cdf0e10cSrcweir+ 3151cdf0e10cSrcweir+ 3152cdf0e10cSrcweir+#ifdef __MINGW32__ // for runtime-pseudo-reloc 3153cdf0e10cSrcweir+static struct _xmlSecTransformKlass xmlSecNssKWAes128Klass = { 3154cdf0e10cSrcweir+#else 3155cdf0e10cSrcweir+static xmlSecTransformKlass xmlSecNssKWAes128Klass = { 3156cdf0e10cSrcweir+#endif 3157cdf0e10cSrcweir+ /* klass/object sizes */ 3158cdf0e10cSrcweir+ sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ 3159cdf0e10cSrcweir+ xmlSecNssKeyWrapSize, /* xmlSecSize objSize */ 3160cdf0e10cSrcweir+ 3161cdf0e10cSrcweir+ xmlSecNameKWAes128, /* const xmlChar* name; */ 3162cdf0e10cSrcweir+ xmlSecHrefKWAes128, /* const xmlChar* href; */ 3163cdf0e10cSrcweir+ xmlSecTransformUsageEncryptionMethod, /* xmlSecAlgorithmUsage usage; */ 3164cdf0e10cSrcweir+ 3165cdf0e10cSrcweir+ xmlSecNssKeyWrapInitialize, /* xmlSecTransformInitializeMethod initialize; */ 3166cdf0e10cSrcweir+ xmlSecNssKeyWrapFinalize, /* xmlSecTransformFinalizeMethod finalize; */ 3167cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeReadMethod readNode; */ 3168cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ 3169cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKeyReq, /* xmlSecTransformSetKeyMethod setKeyReq; */ 3170cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKey, /* xmlSecTransformSetKeyMethod setKey; */ 3171cdf0e10cSrcweir+ NULL, /* xmlSecTransformValidateMethod validate; */ 3172cdf0e10cSrcweir+ xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ 3173cdf0e10cSrcweir+ xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */ 3174cdf0e10cSrcweir+ xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */ 3175cdf0e10cSrcweir+ NULL, /* xmlSecTransformPushXmlMethod pushXml; */ 3176cdf0e10cSrcweir+ NULL, /* xmlSecTransformPopXmlMethod popXml; */ 3177cdf0e10cSrcweir+ xmlSecNssKeyWrapExecute, /* xmlSecTransformExecuteMethod execute; */ 3178cdf0e10cSrcweir+ 3179cdf0e10cSrcweir+ NULL, /* void* reserved0; */ 3180cdf0e10cSrcweir+ NULL, /* void* reserved1; */ 3181cdf0e10cSrcweir+}; 3182cdf0e10cSrcweir+ 3183cdf0e10cSrcweir+#ifdef __MINGW32__ // for runtime-pseudo-reloc 3184cdf0e10cSrcweir+static struct _xmlSecTransformKlass xmlSecNssKWAes192Klass = { 3185cdf0e10cSrcweir+#else 3186cdf0e10cSrcweir+static xmlSecTransformKlass xmlSecNssKWAes192Klass = { 3187cdf0e10cSrcweir+#endif 3188cdf0e10cSrcweir+ /* klass/object sizes */ 3189cdf0e10cSrcweir+ sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ 3190cdf0e10cSrcweir+ xmlSecNssKeyWrapSize, /* xmlSecSize objSize */ 3191cdf0e10cSrcweir+ 3192cdf0e10cSrcweir+ xmlSecNameKWAes192, /* const xmlChar* name; */ 3193cdf0e10cSrcweir+ xmlSecHrefKWAes192, /* const xmlChar* href; */ 3194cdf0e10cSrcweir+ xmlSecTransformUsageEncryptionMethod, /* xmlSecAlgorithmUsage usage; */ 3195cdf0e10cSrcweir+ 3196cdf0e10cSrcweir+ xmlSecNssKeyWrapInitialize, /* xmlSecTransformInitializeMethod initialize; */ 3197cdf0e10cSrcweir+ xmlSecNssKeyWrapFinalize, /* xmlSecTransformFinalizeMethod finalize; */ 3198cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeReadMethod readNode; */ 3199cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ 3200cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKeyReq, /* xmlSecTransformSetKeyMethod setKeyReq; */ 3201cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKey, /* xmlSecTransformSetKeyMethod setKey; */ 3202cdf0e10cSrcweir+ NULL, /* xmlSecTransformValidateMethod validate; */ 3203cdf0e10cSrcweir+ xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ 3204cdf0e10cSrcweir+ xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */ 3205cdf0e10cSrcweir+ xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */ 3206cdf0e10cSrcweir+ NULL, /* xmlSecTransformPushXmlMethod pushXml; */ 3207cdf0e10cSrcweir+ NULL, /* xmlSecTransformPopXmlMethod popXml; */ 3208cdf0e10cSrcweir+ xmlSecNssKeyWrapExecute, /* xmlSecTransformExecuteMethod execute; */ 3209cdf0e10cSrcweir+ 3210cdf0e10cSrcweir+ NULL, /* void* reserved0; */ 3211cdf0e10cSrcweir+ NULL, /* void* reserved1; */ 3212cdf0e10cSrcweir+}; 3213cdf0e10cSrcweir+ 3214cdf0e10cSrcweir+#ifdef __MINGW32__ // for runtime-pseudo-reloc 3215cdf0e10cSrcweir+static struct _xmlSecTransformKlass xmlSecNssKWAes256Klass = { 3216cdf0e10cSrcweir+#else 3217cdf0e10cSrcweir+static xmlSecTransformKlass xmlSecNssKWAes256Klass = { 3218cdf0e10cSrcweir+#endif 3219cdf0e10cSrcweir+ /* klass/object sizes */ 3220cdf0e10cSrcweir+ sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ 3221cdf0e10cSrcweir+ xmlSecNssKeyWrapSize, /* xmlSecSize objSize */ 3222cdf0e10cSrcweir+ 3223cdf0e10cSrcweir+ xmlSecNameKWAes256, /* const xmlChar* name; */ 3224cdf0e10cSrcweir+ xmlSecHrefKWAes256, /* const xmlChar* href; */ 3225cdf0e10cSrcweir+ xmlSecTransformUsageEncryptionMethod, /* xmlSecAlgorithmUsage usage; */ 3226cdf0e10cSrcweir+ 3227cdf0e10cSrcweir+ xmlSecNssKeyWrapInitialize, /* xmlSecTransformInitializeMethod initialize; */ 3228cdf0e10cSrcweir+ xmlSecNssKeyWrapFinalize, /* xmlSecTransformFinalizeMethod finalize; */ 3229cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeReadMethod readNode; */ 3230cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ 3231cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKeyReq, /* xmlSecTransformSetKeyMethod setKeyReq; */ 3232cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKey, /* xmlSecTransformSetKeyMethod setKey; */ 3233cdf0e10cSrcweir+ NULL, /* xmlSecTransformValidateMethod validate; */ 3234cdf0e10cSrcweir+ xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ 3235cdf0e10cSrcweir+ xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */ 3236cdf0e10cSrcweir+ xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */ 3237cdf0e10cSrcweir+ NULL, /* xmlSecTransformPushXmlMethod pushXml; */ 3238cdf0e10cSrcweir+ NULL, /* xmlSecTransformPopXmlMethod popXml; */ 3239cdf0e10cSrcweir+ xmlSecNssKeyWrapExecute, /* xmlSecTransformExecuteMethod execute; */ 3240cdf0e10cSrcweir+ 3241cdf0e10cSrcweir+ NULL, /* void* reserved0; */ 3242cdf0e10cSrcweir+ NULL, /* void* reserved1; */ 3243cdf0e10cSrcweir+}; 3244cdf0e10cSrcweir+ 3245cdf0e10cSrcweir+/** 3246cdf0e10cSrcweir+ * xmlSecNssTransformKWAes128GetKlass: 3247cdf0e10cSrcweir+ * 3248cdf0e10cSrcweir+ * The AES-128 key wrapper transform klass. 3249cdf0e10cSrcweir+ * 3250cdf0e10cSrcweir+ * Returns AES-128 key wrapper transform klass. 3251cdf0e10cSrcweir+ */ 3252cdf0e10cSrcweir+xmlSecTransformId 3253cdf0e10cSrcweir+xmlSecNssTransformKWAes128GetKlass(void) { 3254cdf0e10cSrcweir+ return(&xmlSecNssKWAes128Klass); 3255cdf0e10cSrcweir+} 3256cdf0e10cSrcweir+ 3257cdf0e10cSrcweir+/** 3258cdf0e10cSrcweir+ * xmlSecNssTransformKWAes192GetKlass: 3259cdf0e10cSrcweir+ * 3260cdf0e10cSrcweir+ * The AES-192 key wrapper transform klass. 3261cdf0e10cSrcweir+ * 3262cdf0e10cSrcweir+ * Returns AES-192 key wrapper transform klass. 3263cdf0e10cSrcweir+ */ 3264cdf0e10cSrcweir+xmlSecTransformId 3265cdf0e10cSrcweir+xmlSecNssTransformKWAes192GetKlass(void) { 3266cdf0e10cSrcweir+ return(&xmlSecNssKWAes192Klass); 3267cdf0e10cSrcweir+} 3268cdf0e10cSrcweir+ 3269cdf0e10cSrcweir+/** 3270cdf0e10cSrcweir+ * 3271cdf0e10cSrcweir+ * The AES-256 key wrapper transform klass. 3272cdf0e10cSrcweir+ * 3273cdf0e10cSrcweir+ * Returns AES-256 key wrapper transform klass. 3274cdf0e10cSrcweir+ */ 3275cdf0e10cSrcweir+xmlSecTransformId 3276cdf0e10cSrcweir+xmlSecNssTransformKWAes256GetKlass(void) { 3277cdf0e10cSrcweir+ return(&xmlSecNssKWAes256Klass); 3278cdf0e10cSrcweir+} 3279cdf0e10cSrcweir+ 3280cdf0e10cSrcweir+#endif /* XMLSEC_NO_AES */ 3281cdf0e10cSrcweir+ 3282cdf0e10cSrcweir+ 3283cdf0e10cSrcweir+#ifndef XMLSEC_NO_DES 3284cdf0e10cSrcweir+ 3285cdf0e10cSrcweir+#ifdef __MINGW32__ // for runtime-pseudo-reloc 3286cdf0e10cSrcweir+static struct _xmlSecTransformKlass xmlSecNssKWDes3Klass = { 3287cdf0e10cSrcweir+#else 3288cdf0e10cSrcweir+static xmlSecTransformKlass xmlSecNssKWDes3Klass = { 3289cdf0e10cSrcweir+#endif 3290cdf0e10cSrcweir+ /* klass/object sizes */ 3291cdf0e10cSrcweir+ sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ 3292cdf0e10cSrcweir+ xmlSecNssKeyWrapSize, /* xmlSecSize objSize */ 3293cdf0e10cSrcweir+ 3294cdf0e10cSrcweir+ xmlSecNameKWDes3, /* const xmlChar* name; */ 3295cdf0e10cSrcweir+ xmlSecHrefKWDes3, /* const xmlChar* href; */ 3296cdf0e10cSrcweir+ xmlSecTransformUsageEncryptionMethod, /* xmlSecAlgorithmUsage usage; */ 3297cdf0e10cSrcweir+ 3298cdf0e10cSrcweir+ xmlSecNssKeyWrapInitialize, /* xmlSecTransformInitializeMethod initialize; */ 3299cdf0e10cSrcweir+ xmlSecNssKeyWrapFinalize, /* xmlSecTransformFinalizeMethod finalize; */ 3300cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeReadMethod readNode; */ 3301cdf0e10cSrcweir+ NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ 3302cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKeyReq, /* xmlSecTransformSetKeyMethod setKeyReq; */ 3303cdf0e10cSrcweir+ xmlSecNssKeyWrapSetKey, /* xmlSecTransformSetKeyMethod setKey; */ 3304cdf0e10cSrcweir+ NULL, /* xmlSecTransformValidateMethod validate; */ 3305cdf0e10cSrcweir+ xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ 3306cdf0e10cSrcweir+ xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */ 3307cdf0e10cSrcweir+ xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */ 3308cdf0e10cSrcweir+ NULL, /* xmlSecTransformPushXmlMethod pushXml; */ 3309cdf0e10cSrcweir+ NULL, /* xmlSecTransformPopXmlMethod popXml; */ 3310cdf0e10cSrcweir+ xmlSecNssKeyWrapExecute, /* xmlSecTransformExecuteMethod execute; */ 3311cdf0e10cSrcweir+ 3312cdf0e10cSrcweir+ NULL, /* void* reserved0; */ 3313cdf0e10cSrcweir+ NULL, /* void* reserved1; */ 3314cdf0e10cSrcweir+}; 3315cdf0e10cSrcweir+ 3316cdf0e10cSrcweir+/** 3317cdf0e10cSrcweir+ * xmlSecNssTransformKWDes3GetKlass: 3318cdf0e10cSrcweir+ * 3319cdf0e10cSrcweir+ * The Triple DES key wrapper transform klass. 3320cdf0e10cSrcweir+ * 3321cdf0e10cSrcweir+ * Returns Triple DES key wrapper transform klass. 3322cdf0e10cSrcweir+ */ 3323cdf0e10cSrcweir+xmlSecTransformId 3324cdf0e10cSrcweir+xmlSecNssTransformKWDes3GetKlass(void) { 3325cdf0e10cSrcweir+ return(&xmlSecNssKWDes3Klass); 3326cdf0e10cSrcweir+} 3327cdf0e10cSrcweir+ 3328cdf0e10cSrcweir+#endif /* XMLSEC_NO_DES */ 3329cdf0e10cSrcweir+ 3330cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/pkikeys.c 2009-06-25 22:53:18.000000000 +0200 3331cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/pkikeys.c 2009-09-21 14:02:48.657352624 +0200 3332cdf0e10cSrcweir@@ -24,6 +24,7 @@ 3333cdf0e10cSrcweir #include <xmlsec/nss/crypto.h> 3334cdf0e10cSrcweir #include <xmlsec/nss/bignum.h> 3335cdf0e10cSrcweir #include <xmlsec/nss/pkikeys.h> 3336cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 3337cdf0e10cSrcweir 3338cdf0e10cSrcweir /************************************************************************** 3339cdf0e10cSrcweir * 3340cdf0e10cSrcweir@@ -115,6 +116,8 @@ 3341cdf0e10cSrcweir xmlSecNssPKIKeyDataCtxPtr ctxSrc) 3342cdf0e10cSrcweir { 3343cdf0e10cSrcweir xmlSecNSSPKIKeyDataCtxFree(ctxDst); 3344cdf0e10cSrcweir+ ctxDst->privkey = NULL ; 3345cdf0e10cSrcweir+ ctxDst->pubkey = NULL ; 3346cdf0e10cSrcweir if (ctxSrc->privkey != NULL) { 3347cdf0e10cSrcweir ctxDst->privkey = SECKEY_CopyPrivateKey(ctxSrc->privkey); 3348cdf0e10cSrcweir if(ctxDst->privkey == NULL) { 3349cdf0e10cSrcweir@@ -588,13 +591,13 @@ 3350cdf0e10cSrcweir goto done; 3351cdf0e10cSrcweir } 3352cdf0e10cSrcweir 3353cdf0e10cSrcweir- slot = PK11_GetBestSlot(CKM_DSA, NULL); 3354cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(CKM_DSA); 3355cdf0e10cSrcweir if(slot == NULL) { 3356cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 3357cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3358cdf0e10cSrcweir- "PK11_GetBestSlot", 3359cdf0e10cSrcweir+ "xmlSecNssSlotGet", 3360cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 3361cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 3362cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 3363cdf0e10cSrcweir ret = -1; 3364cdf0e10cSrcweir goto done; 3365cdf0e10cSrcweir } 3366cdf0e10cSrcweir@@ -792,14 +795,14 @@ 3367cdf0e10cSrcweir if (slot != NULL) { 3368cdf0e10cSrcweir PK11_FreeSlot(slot); 3369cdf0e10cSrcweir } 3370cdf0e10cSrcweir- if (ret != 0) { 3371cdf0e10cSrcweir+ 3372cdf0e10cSrcweir if (pubkey != NULL) { 3373cdf0e10cSrcweir SECKEY_DestroyPublicKey(pubkey); 3374cdf0e10cSrcweir } 3375cdf0e10cSrcweir if (data != NULL) { 3376cdf0e10cSrcweir xmlSecKeyDataDestroy(data); 3377cdf0e10cSrcweir } 3378cdf0e10cSrcweir- } 3379cdf0e10cSrcweir+ 3380cdf0e10cSrcweir return(ret); 3381cdf0e10cSrcweir } 3382cdf0e10cSrcweir 3383cdf0e10cSrcweir@@ -818,7 +821,7 @@ 3384cdf0e10cSrcweir 3385cdf0e10cSrcweir ctx = xmlSecNssPKIKeyDataGetCtx(xmlSecKeyGetValue(key)); 3386cdf0e10cSrcweir xmlSecAssert2(ctx != NULL, -1); 3387cdf0e10cSrcweir- xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1); 3388cdf0e10cSrcweir+/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1);*/ 3389cdf0e10cSrcweir 3390cdf0e10cSrcweir if(((xmlSecKeyDataTypePublic | xmlSecKeyDataTypePrivate) & keyInfoCtx->keyReq.keyType) == 0) { 3391cdf0e10cSrcweir /* we can have only private key or public key */ 3392cdf0e10cSrcweir@@ -940,7 +943,8 @@ 3393cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 3394cdf0e10cSrcweir "PK11_PQG_ParamGen", 3395cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 3396cdf0e10cSrcweir- "size=%d", sizeBits); 3397cdf0e10cSrcweir+ "size=%d, error code=%d", sizeBits, PORT_GetError()); 3398cdf0e10cSrcweir+ ret = -1; 3399cdf0e10cSrcweir goto done; 3400cdf0e10cSrcweir } 3401cdf0e10cSrcweir 3402cdf0e10cSrcweir@@ -950,11 +954,12 @@ 3403cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 3404cdf0e10cSrcweir "PK11_PQG_VerifyParams", 3405cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 3406cdf0e10cSrcweir- "size=%d", sizeBits); 3407cdf0e10cSrcweir+ "size=%d, error code=%d", sizeBits, PORT_GetError()); 3408cdf0e10cSrcweir+ ret = -1; 3409cdf0e10cSrcweir goto done; 3410cdf0e10cSrcweir } 3411cdf0e10cSrcweir 3412cdf0e10cSrcweir- slot = PK11_GetBestSlot(CKM_DSA_KEY_PAIR_GEN, NULL); 3413cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(CKM_DSA_KEY_PAIR_GEN); 3414cdf0e10cSrcweir PK11_Authenticate(slot, PR_TRUE, NULL /* default pwd callback */); 3415cdf0e10cSrcweir privkey = PK11_GenerateKeyPair(slot, CKM_DSA_KEY_PAIR_GEN, pqgParams, 3416cdf0e10cSrcweir &pubkey, PR_FALSE, PR_TRUE, NULL); 3417cdf0e10cSrcweir@@ -964,8 +969,9 @@ 3418cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 3419cdf0e10cSrcweir "PK11_GenerateKeyPair", 3420cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 3421cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 3422cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 3423cdf0e10cSrcweir 3424cdf0e10cSrcweir+ ret = -1; 3425cdf0e10cSrcweir goto done; 3426cdf0e10cSrcweir } 3427cdf0e10cSrcweir 3428cdf0e10cSrcweir@@ -979,6 +985,8 @@ 3429cdf0e10cSrcweir goto done; 3430cdf0e10cSrcweir } 3431cdf0e10cSrcweir 3432cdf0e10cSrcweir+ privkey = NULL ; 3433cdf0e10cSrcweir+ pubkey = NULL ; 3434cdf0e10cSrcweir ret = 0; 3435cdf0e10cSrcweir 3436cdf0e10cSrcweir done: 3437cdf0e10cSrcweir@@ -991,16 +999,13 @@ 3438cdf0e10cSrcweir if (pqgVerify != NULL) { 3439cdf0e10cSrcweir PK11_PQG_DestroyVerify(pqgVerify); 3440cdf0e10cSrcweir } 3441cdf0e10cSrcweir- if (ret == 0) { 3442cdf0e10cSrcweir- return (0); 3443cdf0e10cSrcweir- } 3444cdf0e10cSrcweir if (pubkey != NULL) { 3445cdf0e10cSrcweir SECKEY_DestroyPublicKey(pubkey); 3446cdf0e10cSrcweir } 3447cdf0e10cSrcweir if (privkey != NULL) { 3448cdf0e10cSrcweir SECKEY_DestroyPrivateKey(privkey); 3449cdf0e10cSrcweir } 3450cdf0e10cSrcweir- return(-1); 3451cdf0e10cSrcweir+ return(ret); 3452cdf0e10cSrcweir } 3453cdf0e10cSrcweir 3454cdf0e10cSrcweir static xmlSecKeyDataType 3455cdf0e10cSrcweir@@ -1010,10 +1015,10 @@ 3456cdf0e10cSrcweir xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId), xmlSecKeyDataTypeUnknown); 3457cdf0e10cSrcweir ctx = xmlSecNssPKIKeyDataGetCtx(data); 3458cdf0e10cSrcweir xmlSecAssert2(ctx != NULL, -1); 3459cdf0e10cSrcweir- xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1); 3460cdf0e10cSrcweir+/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1);*/ 3461cdf0e10cSrcweir if (ctx->privkey != NULL) { 3462cdf0e10cSrcweir return(xmlSecKeyDataTypePrivate | xmlSecKeyDataTypePublic); 3463cdf0e10cSrcweir- } else { 3464cdf0e10cSrcweir+ } else if( ctx->pubkey != NULL ) { 3465cdf0e10cSrcweir return(xmlSecKeyDataTypePublic); 3466cdf0e10cSrcweir } 3467cdf0e10cSrcweir 3468cdf0e10cSrcweir@@ -1027,7 +1032,7 @@ 3469cdf0e10cSrcweir xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId), 0); 3470cdf0e10cSrcweir ctx = xmlSecNssPKIKeyDataGetCtx(data); 3471cdf0e10cSrcweir xmlSecAssert2(ctx != NULL, -1); 3472cdf0e10cSrcweir- xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1); 3473cdf0e10cSrcweir+/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1);*/ 3474cdf0e10cSrcweir 3475cdf0e10cSrcweir return(8 * SECKEY_PublicKeyStrength(ctx->pubkey)); 3476cdf0e10cSrcweir } 3477cdf0e10cSrcweir@@ -1216,13 +1221,13 @@ 3478cdf0e10cSrcweir goto done; 3479cdf0e10cSrcweir } 3480cdf0e10cSrcweir 3481cdf0e10cSrcweir- slot = PK11_GetBestSlot(CKM_RSA_PKCS, NULL); 3482cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(CKM_RSA_PKCS); 3483cdf0e10cSrcweir if(slot == NULL) { 3484cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 3485cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3486cdf0e10cSrcweir- "PK11_GetBestSlot", 3487cdf0e10cSrcweir+ "xmlSecNssSlotGet", 3488cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 3489cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 3490cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 3491cdf0e10cSrcweir ret = -1; 3492cdf0e10cSrcweir goto done; 3493cdf0e10cSrcweir } 3494cdf0e10cSrcweir@@ -1384,7 +1389,7 @@ 3495cdf0e10cSrcweir 3496cdf0e10cSrcweir ctx = xmlSecNssPKIKeyDataGetCtx(xmlSecKeyGetValue(key)); 3497cdf0e10cSrcweir xmlSecAssert2(ctx != NULL, -1); 3498cdf0e10cSrcweir- xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1); 3499cdf0e10cSrcweir+/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1);*/ 3500cdf0e10cSrcweir 3501cdf0e10cSrcweir 3502cdf0e10cSrcweir if(((xmlSecKeyDataTypePublic | xmlSecKeyDataTypePrivate) & keyInfoCtx->keyReq.keyType) == 0) { 3503cdf0e10cSrcweir@@ -1455,7 +1460,7 @@ 3504cdf0e10cSrcweir params.keySizeInBits = sizeBits; 3505cdf0e10cSrcweir params.pe = 65537; 3506cdf0e10cSrcweir 3507cdf0e10cSrcweir- slot = PK11_GetBestSlot(CKM_RSA_PKCS_KEY_PAIR_GEN, NULL); 3508cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(CKM_RSA_PKCS_KEY_PAIR_GEN); 3509cdf0e10cSrcweir PK11_Authenticate(slot, PR_TRUE, NULL /* default pwd callback */); 3510cdf0e10cSrcweir privkey = PK11_GenerateKeyPair(slot, CKM_RSA_PKCS_KEY_PAIR_GEN, ¶ms, 3511cdf0e10cSrcweir &pubkey, PR_FALSE, PR_TRUE, NULL); 3512cdf0e10cSrcweir@@ -1525,7 +1530,7 @@ 3513cdf0e10cSrcweir 3514cdf0e10cSrcweir ctx = xmlSecNssPKIKeyDataGetCtx(data); 3515cdf0e10cSrcweir xmlSecAssert2(ctx != NULL, -1); 3516cdf0e10cSrcweir- xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1); 3517cdf0e10cSrcweir+/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1);*/ 3518cdf0e10cSrcweir 3519cdf0e10cSrcweir return(8 * SECKEY_PublicKeyStrength(ctx->pubkey)); 3520cdf0e10cSrcweir } 3521cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/symkeys.c 2009-06-25 22:53:18.000000000 +0200 3522cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/symkeys.c 2009-09-21 14:02:48.620574832 +0200 3523cdf0e10cSrcweir@@ -15,20 +15,41 @@ 3524cdf0e10cSrcweir #include <stdio.h> 3525cdf0e10cSrcweir #include <string.h> 3526cdf0e10cSrcweir 3527cdf0e10cSrcweir+#include <pk11func.h> 3528cdf0e10cSrcweir+#include <nss.h> 3529cdf0e10cSrcweir+ 3530cdf0e10cSrcweir #include <xmlsec/xmlsec.h> 3531cdf0e10cSrcweir #include <xmlsec/xmltree.h> 3532cdf0e10cSrcweir+#include <xmlsec/base64.h> 3533cdf0e10cSrcweir #include <xmlsec/keys.h> 3534cdf0e10cSrcweir #include <xmlsec/keyinfo.h> 3535cdf0e10cSrcweir #include <xmlsec/transforms.h> 3536cdf0e10cSrcweir #include <xmlsec/errors.h> 3537cdf0e10cSrcweir 3538cdf0e10cSrcweir #include <xmlsec/nss/crypto.h> 3539cdf0e10cSrcweir+#include <xmlsec/nss/ciphers.h> 3540cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 3541cdf0e10cSrcweir 3542cdf0e10cSrcweir /***************************************************************************** 3543cdf0e10cSrcweir * 3544cdf0e10cSrcweir- * Symmetic (binary) keys - just a wrapper for xmlSecKeyDataBinary 3545cdf0e10cSrcweir+ * Symmetic (binary) keys - a wrapper over slot information and PK11SymKey 3546cdf0e10cSrcweir * 3547cdf0e10cSrcweir ****************************************************************************/ 3548cdf0e10cSrcweir+typedef struct _xmlSecNssSymKeyDataCtx xmlSecNssSymKeyDataCtx ; 3549cdf0e10cSrcweir+typedef struct _xmlSecNssSymKeyDataCtx* xmlSecNssSymKeyDataCtxPtr ; 3550cdf0e10cSrcweir+ 3551cdf0e10cSrcweir+struct _xmlSecNssSymKeyDataCtx { 3552cdf0e10cSrcweir+ CK_MECHANISM_TYPE cipher ; /* the symmetic key mechanism */ 3553cdf0e10cSrcweir+ PK11SlotInfo* slot ; /* the key resident slot */ 3554cdf0e10cSrcweir+ PK11SymKey* symkey ; /* the symmetic key */ 3555cdf0e10cSrcweir+} ; 3556cdf0e10cSrcweir+ 3557cdf0e10cSrcweir+#define xmlSecNssSymKeyDataSize \ 3558cdf0e10cSrcweir+ ( sizeof( xmlSecKeyData ) + sizeof( xmlSecNssSymKeyDataCtx ) ) 3559cdf0e10cSrcweir+ 3560cdf0e10cSrcweir+#define xmlSecNssSymKeyDataGetCtx( data ) \ 3561cdf0e10cSrcweir+ ( ( xmlSecNssSymKeyDataCtxPtr )( ( ( xmlSecByte* )( data ) ) + sizeof( xmlSecKeyData ) ) ) 3562cdf0e10cSrcweir+ 3563cdf0e10cSrcweir static int xmlSecNssSymKeyDataInitialize (xmlSecKeyDataPtr data); 3564cdf0e10cSrcweir static int xmlSecNssSymKeyDataDuplicate (xmlSecKeyDataPtr dst, 3565cdf0e10cSrcweir xmlSecKeyDataPtr src); 3566cdf0e10cSrcweir@@ -67,107 +88,743 @@ 3567cdf0e10cSrcweir (xmlSecKeyDataIsValid((data)) && \ 3568cdf0e10cSrcweir xmlSecNssSymKeyDataKlassCheck((data)->id)) 3569cdf0e10cSrcweir 3570cdf0e10cSrcweir+/** 3571cdf0e10cSrcweir+ * xmlSecNssSymKeyDataAdoptKey: 3572cdf0e10cSrcweir+ * @data: the pointer to symmetric key data. 3573cdf0e10cSrcweir+ * @symkey: the symmetric key 3574cdf0e10cSrcweir+ * 3575cdf0e10cSrcweir+ * Set the value of symmetric key data. 3576cdf0e10cSrcweir+ * 3577cdf0e10cSrcweir+ * Returns 0 on success or a negative value if an error occurs. 3578cdf0e10cSrcweir+ */ 3579cdf0e10cSrcweir+int 3580cdf0e10cSrcweir+xmlSecNssSymKeyDataAdoptKey( 3581cdf0e10cSrcweir+ xmlSecKeyDataPtr data , 3582cdf0e10cSrcweir+ PK11SymKey* symkey 3583cdf0e10cSrcweir+) { 3584cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr context = NULL ; 3585cdf0e10cSrcweir+ 3586cdf0e10cSrcweir+ xmlSecAssert2( xmlSecNssSymKeyDataCheckId( data ), -1 ) ; 3587cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyDataCheckSize( data, xmlSecNssSymKeyDataSize ), -1 ) ; 3588cdf0e10cSrcweir+ xmlSecAssert2( symkey != NULL, -1 ) ; 3589cdf0e10cSrcweir+ 3590cdf0e10cSrcweir+ context = xmlSecNssSymKeyDataGetCtx( data ) ; 3591cdf0e10cSrcweir+ xmlSecAssert2(context != NULL, -1); 3592cdf0e10cSrcweir+ 3593cdf0e10cSrcweir+ context->cipher = PK11_GetMechanism( symkey ) ; 3594cdf0e10cSrcweir+ 3595cdf0e10cSrcweir+ if( context->slot != NULL ) { 3596cdf0e10cSrcweir+ PK11_FreeSlot( context->slot ) ; 3597cdf0e10cSrcweir+ context->slot = NULL ; 3598cdf0e10cSrcweir+ } 3599cdf0e10cSrcweir+ context->slot = PK11_GetSlotFromKey( symkey ) ; 3600cdf0e10cSrcweir+ 3601cdf0e10cSrcweir+ if( context->symkey != NULL ) { 3602cdf0e10cSrcweir+ PK11_FreeSymKey( context->symkey ) ; 3603cdf0e10cSrcweir+ context->symkey = NULL ; 3604cdf0e10cSrcweir+ } 3605cdf0e10cSrcweir+ context->symkey = PK11_ReferenceSymKey( symkey ) ; 3606cdf0e10cSrcweir+ 3607cdf0e10cSrcweir+ return 0 ; 3608cdf0e10cSrcweir+} 3609cdf0e10cSrcweir+ 3610cdf0e10cSrcweir+xmlSecKeyDataPtr xmlSecNssSymKeyDataKeyAdopt( 3611cdf0e10cSrcweir+ PK11SymKey* symKey 3612cdf0e10cSrcweir+) { 3613cdf0e10cSrcweir+ xmlSecKeyDataPtr data = NULL ; 3614cdf0e10cSrcweir+ CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM ; 3615cdf0e10cSrcweir+ 3616cdf0e10cSrcweir+ xmlSecAssert2( symKey != NULL , NULL ) ; 3617cdf0e10cSrcweir+ 3618cdf0e10cSrcweir+ mechanism = PK11_GetMechanism( symKey ) ; 3619cdf0e10cSrcweir+ switch( mechanism ) { 3620cdf0e10cSrcweir+ case CKM_DES3_KEY_GEN : 3621cdf0e10cSrcweir+ case CKM_DES3_CBC : 3622cdf0e10cSrcweir+ case CKM_DES3_MAC : 3623cdf0e10cSrcweir+ data = xmlSecKeyDataCreate( xmlSecNssKeyDataDesId ) ; 3624cdf0e10cSrcweir+ if( data == NULL ) { 3625cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3626cdf0e10cSrcweir+ NULL , 3627cdf0e10cSrcweir+ "xmlSecKeyDataCreate" , 3628cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3629cdf0e10cSrcweir+ "xmlSecNssKeyDataDesId" ) ; 3630cdf0e10cSrcweir+ return NULL ; 3631cdf0e10cSrcweir+ } 3632cdf0e10cSrcweir+ break ; 3633cdf0e10cSrcweir+ case CKM_AES_KEY_GEN : 3634cdf0e10cSrcweir+ case CKM_AES_CBC : 3635cdf0e10cSrcweir+ case CKM_AES_MAC : 3636cdf0e10cSrcweir+ data = xmlSecKeyDataCreate( xmlSecNssKeyDataAesId ) ; 3637cdf0e10cSrcweir+ if( data == NULL ) { 3638cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3639cdf0e10cSrcweir+ NULL , 3640cdf0e10cSrcweir+ "xmlSecKeyDataCreate" , 3641cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3642cdf0e10cSrcweir+ "xmlSecNssKeyDataDesId" ) ; 3643cdf0e10cSrcweir+ return NULL ; 3644cdf0e10cSrcweir+ } 3645cdf0e10cSrcweir+ break ; 3646cdf0e10cSrcweir+ default : 3647cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3648cdf0e10cSrcweir+ NULL , 3649cdf0e10cSrcweir+ NULL , 3650cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3651cdf0e10cSrcweir+ "Unsupported mechanism" ) ; 3652cdf0e10cSrcweir+ return NULL ; 3653cdf0e10cSrcweir+ } 3654cdf0e10cSrcweir+ 3655cdf0e10cSrcweir+ if( xmlSecNssSymKeyDataAdoptKey( data , symKey ) < 0 ) { 3656cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3657cdf0e10cSrcweir+ NULL , 3658cdf0e10cSrcweir+ "xmlSecNssSymKeyDataAdoptKey" , 3659cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 3660cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3661cdf0e10cSrcweir+ 3662cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3663cdf0e10cSrcweir+ return NULL ; 3664cdf0e10cSrcweir+ } 3665cdf0e10cSrcweir+ 3666cdf0e10cSrcweir+ return data ; 3667cdf0e10cSrcweir+} 3668cdf0e10cSrcweir+ 3669cdf0e10cSrcweir+ 3670cdf0e10cSrcweir+PK11SymKey* 3671cdf0e10cSrcweir+xmlSecNssSymKeyDataGetKey( 3672cdf0e10cSrcweir+ xmlSecKeyDataPtr data 3673cdf0e10cSrcweir+) { 3674cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctx; 3675cdf0e10cSrcweir+ PK11SymKey* symkey ; 3676cdf0e10cSrcweir+ 3677cdf0e10cSrcweir+ xmlSecAssert2(xmlSecNssSymKeyDataCheckId(data), NULL); 3678cdf0e10cSrcweir+ xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssSymKeyDataSize), NULL); 3679cdf0e10cSrcweir+ 3680cdf0e10cSrcweir+ ctx = xmlSecNssSymKeyDataGetCtx(data); 3681cdf0e10cSrcweir+ xmlSecAssert2(ctx != NULL, NULL); 3682cdf0e10cSrcweir+ 3683cdf0e10cSrcweir+ if( ctx->symkey != NULL ) { 3684cdf0e10cSrcweir+ symkey = PK11_ReferenceSymKey( ctx->symkey ) ; 3685cdf0e10cSrcweir+ } else { 3686cdf0e10cSrcweir+ symkey = NULL ; 3687cdf0e10cSrcweir+ } 3688cdf0e10cSrcweir+ 3689cdf0e10cSrcweir+ return(symkey); 3690cdf0e10cSrcweir+} 3691cdf0e10cSrcweir+ 3692cdf0e10cSrcweir static int 3693cdf0e10cSrcweir xmlSecNssSymKeyDataInitialize(xmlSecKeyDataPtr data) { 3694cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctx; 3695cdf0e10cSrcweir+ 3696cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataCheckId(data), -1); 3697cdf0e10cSrcweir- 3698cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueInitialize(data)); 3699cdf0e10cSrcweir+ xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssSymKeyDataSize), -1); 3700cdf0e10cSrcweir+ 3701cdf0e10cSrcweir+ ctx = xmlSecNssSymKeyDataGetCtx(data); 3702cdf0e10cSrcweir+ xmlSecAssert2(ctx != NULL, -1); 3703cdf0e10cSrcweir+ 3704cdf0e10cSrcweir+ memset( ctx, 0, sizeof(xmlSecNssSymKeyDataCtx)); 3705cdf0e10cSrcweir+ 3706cdf0e10cSrcweir+ /* Set the block cipher mechanism */ 3707cdf0e10cSrcweir+#ifndef XMLSEC_NO_DES 3708cdf0e10cSrcweir+ if(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDesId)) { 3709cdf0e10cSrcweir+ ctx->cipher = CKM_DES3_KEY_GEN; 3710cdf0e10cSrcweir+ } else 3711cdf0e10cSrcweir+#endif /* XMLSEC_NO_DES */ 3712cdf0e10cSrcweir+ 3713cdf0e10cSrcweir+#ifndef XMLSEC_NO_AES 3714cdf0e10cSrcweir+ if(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDesId)) { 3715cdf0e10cSrcweir+ ctx->cipher = CKM_AES_KEY_GEN; 3716cdf0e10cSrcweir+ } else 3717cdf0e10cSrcweir+#endif /* XMLSEC_NO_AES */ 3718cdf0e10cSrcweir+ 3719cdf0e10cSrcweir+ if(1) { 3720cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3721cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 3722cdf0e10cSrcweir+ NULL , 3723cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 3724cdf0e10cSrcweir+ "Unsupported block cipher" ) ; 3725cdf0e10cSrcweir+ return(-1) ; 3726cdf0e10cSrcweir+ } 3727cdf0e10cSrcweir+ 3728cdf0e10cSrcweir+ return(0); 3729cdf0e10cSrcweir } 3730cdf0e10cSrcweir 3731cdf0e10cSrcweir static int 3732cdf0e10cSrcweir xmlSecNssSymKeyDataDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) { 3733cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctxDst; 3734cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctxSrc; 3735cdf0e10cSrcweir+ 3736cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataCheckId(dst), -1); 3737cdf0e10cSrcweir+ xmlSecAssert2(xmlSecKeyDataCheckSize(dst, xmlSecNssSymKeyDataSize), -1); 3738cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataCheckId(src), -1); 3739cdf0e10cSrcweir+ xmlSecAssert2(xmlSecKeyDataCheckSize(src, xmlSecNssSymKeyDataSize), -1); 3740cdf0e10cSrcweir xmlSecAssert2(dst->id == src->id, -1); 3741cdf0e10cSrcweir- 3742cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueDuplicate(dst, src)); 3743cdf0e10cSrcweir+ 3744cdf0e10cSrcweir+ ctxDst = xmlSecNssSymKeyDataGetCtx(dst); 3745cdf0e10cSrcweir+ xmlSecAssert2(ctxDst != NULL, -1); 3746cdf0e10cSrcweir+ 3747cdf0e10cSrcweir+ ctxSrc = xmlSecNssSymKeyDataGetCtx(src); 3748cdf0e10cSrcweir+ xmlSecAssert2(ctxSrc != NULL, -1); 3749cdf0e10cSrcweir+ 3750cdf0e10cSrcweir+ ctxDst->cipher = ctxSrc->cipher ; 3751cdf0e10cSrcweir+ 3752cdf0e10cSrcweir+ if( ctxSrc->slot != NULL ) { 3753cdf0e10cSrcweir+ if( ctxDst->slot != NULL && ctxDst->slot != ctxSrc->slot ) { 3754cdf0e10cSrcweir+ PK11_FreeSlot( ctxDst->slot ) ; 3755cdf0e10cSrcweir+ ctxDst->slot = NULL ; 3756cdf0e10cSrcweir+ } 3757cdf0e10cSrcweir+ 3758cdf0e10cSrcweir+ if( ctxDst->slot == NULL && ctxSrc->slot != NULL ) 3759cdf0e10cSrcweir+ ctxDst->slot = PK11_ReferenceSlot( ctxSrc->slot ) ; 3760cdf0e10cSrcweir+ } else { 3761cdf0e10cSrcweir+ if( ctxDst->slot != NULL ) { 3762cdf0e10cSrcweir+ PK11_FreeSlot( ctxDst->slot ) ; 3763cdf0e10cSrcweir+ ctxDst->slot = NULL ; 3764cdf0e10cSrcweir+ } 3765cdf0e10cSrcweir+ } 3766cdf0e10cSrcweir+ 3767cdf0e10cSrcweir+ if( ctxSrc->symkey != NULL ) { 3768cdf0e10cSrcweir+ if( ctxDst->symkey != NULL && ctxDst->symkey != ctxSrc->symkey ) { 3769cdf0e10cSrcweir+ PK11_FreeSymKey( ctxDst->symkey ) ; 3770cdf0e10cSrcweir+ ctxDst->symkey = NULL ; 3771cdf0e10cSrcweir+ } 3772cdf0e10cSrcweir+ 3773cdf0e10cSrcweir+ if( ctxDst->symkey == NULL && ctxSrc->symkey != NULL ) 3774cdf0e10cSrcweir+ ctxDst->symkey = PK11_ReferenceSymKey( ctxSrc->symkey ) ; 3775cdf0e10cSrcweir+ } else { 3776cdf0e10cSrcweir+ if( ctxDst->symkey != NULL ) { 3777cdf0e10cSrcweir+ PK11_FreeSymKey( ctxDst->symkey ) ; 3778cdf0e10cSrcweir+ ctxDst->symkey = NULL ; 3779cdf0e10cSrcweir+ } 3780cdf0e10cSrcweir+ } 3781cdf0e10cSrcweir+ 3782cdf0e10cSrcweir+ return(0); 3783cdf0e10cSrcweir } 3784cdf0e10cSrcweir 3785cdf0e10cSrcweir static void 3786cdf0e10cSrcweir xmlSecNssSymKeyDataFinalize(xmlSecKeyDataPtr data) { 3787cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctx; 3788cdf0e10cSrcweir+ 3789cdf0e10cSrcweir xmlSecAssert(xmlSecNssSymKeyDataCheckId(data)); 3790cdf0e10cSrcweir- 3791cdf0e10cSrcweir- xmlSecKeyDataBinaryValueFinalize(data); 3792cdf0e10cSrcweir+ xmlSecAssert(xmlSecKeyDataCheckSize(data, xmlSecNssSymKeyDataSize)); 3793cdf0e10cSrcweir+ 3794cdf0e10cSrcweir+ ctx = xmlSecNssSymKeyDataGetCtx(data); 3795cdf0e10cSrcweir+ xmlSecAssert(ctx != NULL); 3796cdf0e10cSrcweir+ 3797cdf0e10cSrcweir+ if( ctx->slot != NULL ) { 3798cdf0e10cSrcweir+ PK11_FreeSlot( ctx->slot ) ; 3799cdf0e10cSrcweir+ ctx->slot = NULL ; 3800cdf0e10cSrcweir+ } 3801cdf0e10cSrcweir+ 3802cdf0e10cSrcweir+ if( ctx->symkey != NULL ) { 3803cdf0e10cSrcweir+ PK11_FreeSymKey( ctx->symkey ) ; 3804cdf0e10cSrcweir+ ctx->symkey = NULL ; 3805cdf0e10cSrcweir+ } 3806cdf0e10cSrcweir+ 3807cdf0e10cSrcweir+ ctx->cipher = CKM_INVALID_MECHANISM ; 3808cdf0e10cSrcweir } 3809cdf0e10cSrcweir 3810cdf0e10cSrcweir static int 3811cdf0e10cSrcweir xmlSecNssSymKeyDataXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, 3812cdf0e10cSrcweir xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 3813cdf0e10cSrcweir- xmlSecAssert2(xmlSecNssSymKeyDataKlassCheck(id), -1); 3814cdf0e10cSrcweir+ PK11SymKey* symKey ; 3815cdf0e10cSrcweir+ PK11SlotInfo* slot ; 3816cdf0e10cSrcweir+ xmlSecBufferPtr keyBuf; 3817cdf0e10cSrcweir+ xmlSecSize len; 3818cdf0e10cSrcweir+ xmlSecKeyDataPtr data; 3819cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctx; 3820cdf0e10cSrcweir+ SECItem keyItem ; 3821cdf0e10cSrcweir+ int ret; 3822cdf0e10cSrcweir+ 3823cdf0e10cSrcweir+ xmlSecAssert2(id != xmlSecKeyDataIdUnknown, -1); 3824cdf0e10cSrcweir+ xmlSecAssert2(key != NULL, -1); 3825cdf0e10cSrcweir+ xmlSecAssert2(node != NULL, -1); 3826cdf0e10cSrcweir+ xmlSecAssert2(keyInfoCtx != NULL, -1); 3827cdf0e10cSrcweir+ 3828cdf0e10cSrcweir+ /* Create a new KeyData from a id */ 3829cdf0e10cSrcweir+ data = xmlSecKeyDataCreate(id); 3830cdf0e10cSrcweir+ if(data == NULL ) { 3831cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3832cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3833cdf0e10cSrcweir+ "xmlSecKeyDataCreate", 3834cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3835cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3836cdf0e10cSrcweir+ return(-1); 3837cdf0e10cSrcweir+ } 3838cdf0e10cSrcweir+ 3839cdf0e10cSrcweir+ ctx = xmlSecNssSymKeyDataGetCtx(data); 3840cdf0e10cSrcweir+ xmlSecAssert2(ctx != NULL, -1); 3841cdf0e10cSrcweir+ 3842cdf0e10cSrcweir+ /* Create a buffer for raw symmetric key value */ 3843cdf0e10cSrcweir+ if( ( keyBuf = xmlSecBufferCreate( 128 ) ) == NULL ) { 3844cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3845cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3846cdf0e10cSrcweir+ "xmlSecBufferCreate" , 3847cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 3848cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3849cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3850cdf0e10cSrcweir+ return(-1) ; 3851cdf0e10cSrcweir+ } 3852cdf0e10cSrcweir+ 3853cdf0e10cSrcweir+ /* Read the raw key value */ 3854cdf0e10cSrcweir+ if( xmlSecBufferBase64NodeContentRead( keyBuf , node ) < 0 ) { 3855cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3856cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3857cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecNodeGetName(node)), 3858cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 3859cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3860cdf0e10cSrcweir+ 3861cdf0e10cSrcweir+ xmlSecBufferDestroy( keyBuf ) ; 3862cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3863cdf0e10cSrcweir+ return(-1) ; 3864cdf0e10cSrcweir+ } 3865cdf0e10cSrcweir+ 3866cdf0e10cSrcweir+ /* Get slot */ 3867cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(ctx->cipher); 3868cdf0e10cSrcweir+ if( slot == NULL ) { 3869cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3870cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3871cdf0e10cSrcweir+ "xmlSecNssSlotGet" , 3872cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 3873cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3874cdf0e10cSrcweir+ 3875cdf0e10cSrcweir+ xmlSecBufferDestroy( keyBuf ) ; 3876cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3877cdf0e10cSrcweir+ return(-1) ; 3878cdf0e10cSrcweir+ } 3879cdf0e10cSrcweir+ 3880cdf0e10cSrcweir+ /* Wrap the raw key value SECItem */ 3881cdf0e10cSrcweir+ keyItem.type = siBuffer ; 3882cdf0e10cSrcweir+ keyItem.data = xmlSecBufferGetData( keyBuf ) ; 3883cdf0e10cSrcweir+ keyItem.len = xmlSecBufferGetSize( keyBuf ) ; 3884cdf0e10cSrcweir+ 3885cdf0e10cSrcweir+ /* Import the raw key into slot temporalily and get the key handler*/ 3886cdf0e10cSrcweir+ symKey = PK11_ImportSymKey(slot, ctx->cipher, PK11_OriginGenerated, CKA_VALUE, &keyItem, NULL ) ; 3887cdf0e10cSrcweir+ if( symKey == NULL ) { 3888cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 3889cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3890cdf0e10cSrcweir+ "PK11_ImportSymKey" , 3891cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 3892cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 3893cdf0e10cSrcweir+ 3894cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 3895cdf0e10cSrcweir+ xmlSecBufferDestroy( keyBuf ) ; 3896cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3897cdf0e10cSrcweir+ return(-1) ; 3898cdf0e10cSrcweir+ } 3899cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 3900cdf0e10cSrcweir+ 3901cdf0e10cSrcweir+ /* raw key material has been copied into symKey, it isn't used any more */ 3902cdf0e10cSrcweir+ xmlSecBufferDestroy( keyBuf ) ; 3903cdf0e10cSrcweir+ 3904cdf0e10cSrcweir+ /* Adopt the symmetric key into key data */ 3905cdf0e10cSrcweir+ ret = xmlSecNssSymKeyDataAdoptKey(data, symKey); 3906cdf0e10cSrcweir+ if(ret < 0) { 3907cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3908cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3909cdf0e10cSrcweir+ "xmlSecKeyDataBinaryValueSetBuffer", 3910cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3911cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3912cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 3913cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3914cdf0e10cSrcweir+ return(-1); 3915cdf0e10cSrcweir+ } 3916cdf0e10cSrcweir+ /* symKey has been duplicated into data, it isn't used any more */ 3917cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 3918cdf0e10cSrcweir+ 3919cdf0e10cSrcweir+ /* Check value */ 3920cdf0e10cSrcweir+ if(xmlSecKeyReqMatchKeyValue(&(keyInfoCtx->keyReq), data) != 1) { 3921cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3922cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3923cdf0e10cSrcweir+ "xmlSecKeyReqMatchKeyValue", 3924cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3925cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3926cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3927cdf0e10cSrcweir+ return(0); 3928cdf0e10cSrcweir+ } 3929cdf0e10cSrcweir 3930cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueXmlRead(id, key, node, keyInfoCtx)); 3931cdf0e10cSrcweir+ ret = xmlSecKeySetValue(key, data); 3932cdf0e10cSrcweir+ if(ret < 0) { 3933cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3934cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3935cdf0e10cSrcweir+ "xmlSecKeySetValue", 3936cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3937cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3938cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 3939cdf0e10cSrcweir+ return(-1); 3940cdf0e10cSrcweir+ } 3941cdf0e10cSrcweir+ 3942cdf0e10cSrcweir+ return(0); 3943cdf0e10cSrcweir } 3944cdf0e10cSrcweir 3945cdf0e10cSrcweir static int 3946cdf0e10cSrcweir xmlSecNssSymKeyDataXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, 3947cdf0e10cSrcweir xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 3948cdf0e10cSrcweir+ PK11SymKey* symKey ; 3949cdf0e10cSrcweir+ 3950cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataKlassCheck(id), -1); 3951cdf0e10cSrcweir- 3952cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueXmlWrite(id, key, node, keyInfoCtx)); 3953cdf0e10cSrcweir+ xmlSecAssert2(key != NULL, -1); 3954cdf0e10cSrcweir+ xmlSecAssert2(node != NULL, -1); 3955cdf0e10cSrcweir+ xmlSecAssert2(keyInfoCtx != NULL, -1); 3956cdf0e10cSrcweir+ 3957cdf0e10cSrcweir+ /* Get symmetric key from "key" */ 3958cdf0e10cSrcweir+ symKey = xmlSecNssSymKeyDataGetKey(xmlSecKeyGetValue(key)); 3959cdf0e10cSrcweir+ if( symKey != NULL ) { 3960cdf0e10cSrcweir+ SECItem* keyItem ; 3961cdf0e10cSrcweir+ xmlSecBufferPtr keyBuf ; 3962cdf0e10cSrcweir+ 3963cdf0e10cSrcweir+ /* Extract raw key data from symmetric key */ 3964cdf0e10cSrcweir+ if( PK11_ExtractKeyValue( symKey ) != SECSuccess ) { 3965cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3966cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3967cdf0e10cSrcweir+ "PK11_ExtractKeyValue", 3968cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3969cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3970cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 3971cdf0e10cSrcweir+ return(-1); 3972cdf0e10cSrcweir+ } 3973cdf0e10cSrcweir+ 3974cdf0e10cSrcweir+ /* Get raw key data from "symKey" */ 3975cdf0e10cSrcweir+ keyItem = PK11_GetKeyData( symKey ) ; 3976cdf0e10cSrcweir+ if(keyItem == NULL) { 3977cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3978cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3979cdf0e10cSrcweir+ "PK11_GetKeyData", 3980cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3981cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3982cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 3983cdf0e10cSrcweir+ return(-1); 3984cdf0e10cSrcweir+ } 3985cdf0e10cSrcweir+ 3986cdf0e10cSrcweir+ /* Create key data buffer with raw kwy material */ 3987cdf0e10cSrcweir+ keyBuf = xmlSecBufferCreate(keyItem->len) ; 3988cdf0e10cSrcweir+ if(keyBuf == NULL) { 3989cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 3990cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 3991cdf0e10cSrcweir+ "xmlSecBufferCreate", 3992cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 3993cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 3994cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 3995cdf0e10cSrcweir+ return(-1); 3996cdf0e10cSrcweir+ } 3997cdf0e10cSrcweir+ 3998cdf0e10cSrcweir+ xmlSecBufferSetData( keyBuf , keyItem->data , keyItem->len ) ; 3999cdf0e10cSrcweir+ 4000cdf0e10cSrcweir+ /* Write raw key material into current xml node */ 4001cdf0e10cSrcweir+ if( xmlSecBufferBase64NodeContentWrite( keyBuf, node, XMLSEC_BASE64_LINESIZE ) < 0 ) { 4002cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4003cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4004cdf0e10cSrcweir+ "xmlSecBufferBase64NodeContentWrite", 4005cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4006cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4007cdf0e10cSrcweir+ xmlSecBufferDestroy(keyBuf); 4008cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4009cdf0e10cSrcweir+ return(-1); 4010cdf0e10cSrcweir+ } 4011cdf0e10cSrcweir+ xmlSecBufferDestroy(keyBuf); 4012cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4013cdf0e10cSrcweir+ } 4014cdf0e10cSrcweir+ 4015cdf0e10cSrcweir+ return 0 ; 4016cdf0e10cSrcweir } 4017cdf0e10cSrcweir 4018cdf0e10cSrcweir static int 4019cdf0e10cSrcweir xmlSecNssSymKeyDataBinRead(xmlSecKeyDataId id, xmlSecKeyPtr key, 4020cdf0e10cSrcweir const xmlSecByte* buf, xmlSecSize bufSize, 4021cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx) { 4022cdf0e10cSrcweir- xmlSecAssert2(xmlSecNssSymKeyDataKlassCheck(id), -1); 4023cdf0e10cSrcweir+ PK11SymKey* symKey ; 4024cdf0e10cSrcweir+ PK11SlotInfo* slot ; 4025cdf0e10cSrcweir+ xmlSecKeyDataPtr data; 4026cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctx; 4027cdf0e10cSrcweir+ SECItem keyItem ; 4028cdf0e10cSrcweir+ int ret; 4029cdf0e10cSrcweir+ 4030cdf0e10cSrcweir+ xmlSecAssert2(id != xmlSecKeyDataIdUnknown, -1); 4031cdf0e10cSrcweir+ xmlSecAssert2(key != NULL, -1); 4032cdf0e10cSrcweir+ xmlSecAssert2(buf != NULL, -1); 4033cdf0e10cSrcweir+ xmlSecAssert2(bufSize != 0, -1); 4034cdf0e10cSrcweir+ xmlSecAssert2(keyInfoCtx != NULL, -1); 4035cdf0e10cSrcweir+ 4036cdf0e10cSrcweir+ /* Create a new KeyData from a id */ 4037cdf0e10cSrcweir+ data = xmlSecKeyDataCreate(id); 4038cdf0e10cSrcweir+ if(data == NULL ) { 4039cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4040cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4041cdf0e10cSrcweir+ "xmlSecKeyDataCreate", 4042cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4043cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4044cdf0e10cSrcweir+ return(-1); 4045cdf0e10cSrcweir+ } 4046cdf0e10cSrcweir+ 4047cdf0e10cSrcweir+ ctx = xmlSecNssSymKeyDataGetCtx(data); 4048cdf0e10cSrcweir+ xmlSecAssert2(ctx != NULL, -1); 4049cdf0e10cSrcweir+ 4050cdf0e10cSrcweir+ /* Get slot */ 4051cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(ctx->cipher); 4052cdf0e10cSrcweir+ if( slot == NULL ) { 4053cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4054cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4055cdf0e10cSrcweir+ "xmlSecNssSlotGet" , 4056cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4057cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4058cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 4059cdf0e10cSrcweir+ return(-1) ; 4060cdf0e10cSrcweir+ } 4061cdf0e10cSrcweir+ 4062cdf0e10cSrcweir+ /* Wrap the raw key value SECItem */ 4063cdf0e10cSrcweir+ keyItem.type = siBuffer ; 4064cdf0e10cSrcweir+ keyItem.data = buf ; 4065cdf0e10cSrcweir+ keyItem.len = bufSize ; 4066cdf0e10cSrcweir+ 4067cdf0e10cSrcweir+ /* Import the raw key into slot temporalily and get the key handler*/ 4068cdf0e10cSrcweir+ symKey = PK11_ImportSymKey(slot, ctx->cipher, PK11_OriginGenerated, CKA_VALUE, &keyItem, NULL ) ; 4069cdf0e10cSrcweir+ if( symKey == NULL ) { 4070cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4071cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4072cdf0e10cSrcweir+ "PK11_ImportSymKey" , 4073cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4074cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4075cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 4076cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 4077cdf0e10cSrcweir+ return(-1) ; 4078cdf0e10cSrcweir+ } 4079cdf0e10cSrcweir+ 4080cdf0e10cSrcweir+ /* Adopt the symmetric key into key data */ 4081cdf0e10cSrcweir+ ret = xmlSecNssSymKeyDataAdoptKey(data, symKey); 4082cdf0e10cSrcweir+ if(ret < 0) { 4083cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4084cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4085cdf0e10cSrcweir+ "xmlSecKeyDataBinaryValueSetBuffer", 4086cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4087cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4088cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4089cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 4090cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 4091cdf0e10cSrcweir+ return(-1); 4092cdf0e10cSrcweir+ } 4093cdf0e10cSrcweir+ /* symKey has been duplicated into data, it isn't used any more */ 4094cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4095cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 4096cdf0e10cSrcweir+ 4097cdf0e10cSrcweir+ /* Check value */ 4098cdf0e10cSrcweir+ if(xmlSecKeyReqMatchKeyValue(&(keyInfoCtx->keyReq), data) != 1) { 4099cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4100cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4101cdf0e10cSrcweir+ "xmlSecKeyReqMatchKeyValue", 4102cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4103cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4104cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 4105cdf0e10cSrcweir+ return(0); 4106cdf0e10cSrcweir+ } 4107cdf0e10cSrcweir 4108cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueBinRead(id, key, buf, bufSize, keyInfoCtx)); 4109cdf0e10cSrcweir+ ret = xmlSecKeySetValue(key, data); 4110cdf0e10cSrcweir+ if(ret < 0) { 4111cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4112cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4113cdf0e10cSrcweir+ "xmlSecKeySetValue", 4114cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4115cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4116cdf0e10cSrcweir+ xmlSecKeyDataDestroy( data ) ; 4117cdf0e10cSrcweir+ return(-1); 4118cdf0e10cSrcweir+ } 4119cdf0e10cSrcweir+ 4120cdf0e10cSrcweir+ return(0); 4121cdf0e10cSrcweir } 4122cdf0e10cSrcweir 4123cdf0e10cSrcweir static int 4124cdf0e10cSrcweir xmlSecNssSymKeyDataBinWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, 4125cdf0e10cSrcweir xmlSecByte** buf, xmlSecSize* bufSize, 4126cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx) { 4127cdf0e10cSrcweir+ PK11SymKey* symKey ; 4128cdf0e10cSrcweir+ 4129cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataKlassCheck(id), -1); 4130cdf0e10cSrcweir+ xmlSecAssert2(key != NULL, -1); 4131cdf0e10cSrcweir+ xmlSecAssert2(buf != NULL, -1); 4132cdf0e10cSrcweir+ xmlSecAssert2(bufSize != 0, -1); 4133cdf0e10cSrcweir+ xmlSecAssert2(keyInfoCtx != NULL, -1); 4134cdf0e10cSrcweir+ 4135cdf0e10cSrcweir+ /* Get symmetric key from "key" */ 4136cdf0e10cSrcweir+ symKey = xmlSecNssSymKeyDataGetKey(xmlSecKeyGetValue(key)); 4137cdf0e10cSrcweir+ if( symKey != NULL ) { 4138cdf0e10cSrcweir+ SECItem* keyItem ; 4139cdf0e10cSrcweir+ 4140cdf0e10cSrcweir+ /* Extract raw key data from symmetric key */ 4141cdf0e10cSrcweir+ if( PK11_ExtractKeyValue( symKey ) != SECSuccess ) { 4142cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4143cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4144cdf0e10cSrcweir+ "PK11_ExtractKeyValue", 4145cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4146cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4147cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4148cdf0e10cSrcweir+ return(-1); 4149cdf0e10cSrcweir+ } 4150cdf0e10cSrcweir+ 4151cdf0e10cSrcweir+ /* Get raw key data from "symKey" */ 4152cdf0e10cSrcweir+ keyItem = PK11_GetKeyData( symKey ) ; 4153cdf0e10cSrcweir+ if(keyItem == NULL) { 4154cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4155cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4156cdf0e10cSrcweir+ "PK11_GetKeyData", 4157cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4158cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4159cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4160cdf0e10cSrcweir+ return(-1); 4161cdf0e10cSrcweir+ } 4162cdf0e10cSrcweir+ 4163cdf0e10cSrcweir+ *bufSize = keyItem->len; 4164cdf0e10cSrcweir+ *buf = ( xmlSecByte* )xmlMalloc( *bufSize ); 4165cdf0e10cSrcweir+ if( *buf == NULL ) { 4166cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4167cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4168cdf0e10cSrcweir+ NULL, 4169cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4170cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 4171cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4172cdf0e10cSrcweir+ return(-1); 4173cdf0e10cSrcweir+ } 4174cdf0e10cSrcweir+ 4175cdf0e10cSrcweir+ memcpy((*buf), keyItem->data, (*bufSize)); 4176cdf0e10cSrcweir+ PK11_FreeSymKey( symKey ) ; 4177cdf0e10cSrcweir+ } 4178cdf0e10cSrcweir 4179cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueBinWrite(id, key, buf, bufSize, keyInfoCtx)); 4180cdf0e10cSrcweir+ return 0 ; 4181cdf0e10cSrcweir } 4182cdf0e10cSrcweir 4183cdf0e10cSrcweir static int 4184cdf0e10cSrcweir xmlSecNssSymKeyDataGenerate(xmlSecKeyDataPtr data, xmlSecSize sizeBits, xmlSecKeyDataType type ATTRIBUTE_UNUSED) { 4185cdf0e10cSrcweir- xmlSecBufferPtr buffer; 4186cdf0e10cSrcweir+ PK11SymKey* symkey ; 4187cdf0e10cSrcweir+ PK11SlotInfo* slot ; 4188cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr ctx; 4189cdf0e10cSrcweir+ int ret; 4190cdf0e10cSrcweir 4191cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataCheckId(data), -1); 4192cdf0e10cSrcweir xmlSecAssert2(sizeBits > 0, -1); 4193cdf0e10cSrcweir 4194cdf0e10cSrcweir- buffer = xmlSecKeyDataBinaryValueGetBuffer(data); 4195cdf0e10cSrcweir- xmlSecAssert2(buffer != NULL, -1); 4196cdf0e10cSrcweir- 4197cdf0e10cSrcweir- return(xmlSecNssGenerateRandom(buffer, (sizeBits + 7) / 8)); 4198cdf0e10cSrcweir+ ctx = xmlSecNssSymKeyDataGetCtx(data); 4199cdf0e10cSrcweir+ xmlSecAssert2(ctx != NULL, -1); 4200cdf0e10cSrcweir+ 4201cdf0e10cSrcweir+ if( sizeBits % 8 != 0 ) { 4202cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 4203cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 4204cdf0e10cSrcweir+ NULL, 4205cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 4206cdf0e10cSrcweir+ "Symmetric key size must be octuple"); 4207cdf0e10cSrcweir+ return(-1); 4208cdf0e10cSrcweir+ } 4209cdf0e10cSrcweir+ 4210cdf0e10cSrcweir+ /* Get slot */ 4211cdf0e10cSrcweir+ slot = xmlSecNssSlotGet(ctx->cipher); 4212cdf0e10cSrcweir+ if( slot == NULL ) { 4213cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4214cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 4215cdf0e10cSrcweir+ "xmlSecNssSlotGet" , 4216cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4217cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4218cdf0e10cSrcweir+ return(-1) ; 4219cdf0e10cSrcweir+ } 4220cdf0e10cSrcweir+ 4221cdf0e10cSrcweir+ if( PK11_Authenticate( slot, PR_FALSE , NULL ) != SECSuccess ) { 4222cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4223cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 4224cdf0e10cSrcweir+ "PK11_Authenticate" , 4225cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 4226cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4227cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 4228cdf0e10cSrcweir+ return -1 ; 4229cdf0e10cSrcweir+ } 4230cdf0e10cSrcweir+ 4231cdf0e10cSrcweir+ symkey = PK11_KeyGen( slot , ctx->cipher , NULL , sizeBits/8 , NULL ) ; 4232cdf0e10cSrcweir+ if( symkey == NULL ) { 4233cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4234cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 4235cdf0e10cSrcweir+ "PK11_KeyGen" , 4236cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 4237cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4238cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 4239cdf0e10cSrcweir+ return -1 ; 4240cdf0e10cSrcweir+ } 4241cdf0e10cSrcweir+ 4242cdf0e10cSrcweir+ if( ctx->slot != NULL ) { 4243cdf0e10cSrcweir+ PK11_FreeSlot( ctx->slot ) ; 4244cdf0e10cSrcweir+ ctx->slot = NULL ; 4245cdf0e10cSrcweir+ } 4246cdf0e10cSrcweir+ ctx->slot = slot ; 4247cdf0e10cSrcweir+ 4248cdf0e10cSrcweir+ if( ctx->symkey != NULL ) { 4249cdf0e10cSrcweir+ PK11_FreeSymKey( ctx->symkey ) ; 4250cdf0e10cSrcweir+ ctx->symkey = NULL ; 4251cdf0e10cSrcweir+ } 4252cdf0e10cSrcweir+ ctx->symkey = symkey ; 4253cdf0e10cSrcweir+ 4254cdf0e10cSrcweir+ return 0; 4255cdf0e10cSrcweir } 4256cdf0e10cSrcweir 4257cdf0e10cSrcweir static xmlSecKeyDataType 4258cdf0e10cSrcweir xmlSecNssSymKeyDataGetType(xmlSecKeyDataPtr data) { 4259cdf0e10cSrcweir- xmlSecBufferPtr buffer; 4260cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr context = NULL ; 4261cdf0e10cSrcweir+ xmlSecKeyDataType type = xmlSecKeyDataTypeUnknown ; 4262cdf0e10cSrcweir 4263cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataCheckId(data), xmlSecKeyDataTypeUnknown); 4264cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyDataCheckSize( data, xmlSecNssSymKeyDataSize ), xmlSecKeyDataTypeUnknown ) ; 4265cdf0e10cSrcweir 4266cdf0e10cSrcweir- buffer = xmlSecKeyDataBinaryValueGetBuffer(data); 4267cdf0e10cSrcweir- xmlSecAssert2(buffer != NULL, xmlSecKeyDataTypeUnknown); 4268cdf0e10cSrcweir+ context = xmlSecNssSymKeyDataGetCtx( data ) ; 4269cdf0e10cSrcweir+ if( context == NULL ) { 4270cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4271cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 4272cdf0e10cSrcweir+ "xmlSecNssSymKeyDataGetCtx" , 4273cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 4274cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4275cdf0e10cSrcweir+ return xmlSecKeyDataTypeUnknown ; 4276cdf0e10cSrcweir+ } 4277cdf0e10cSrcweir 4278cdf0e10cSrcweir- return((xmlSecBufferGetSize(buffer) > 0) ? xmlSecKeyDataTypeSymmetric : xmlSecKeyDataTypeUnknown); 4279cdf0e10cSrcweir+ if( context->symkey != NULL ) { 4280cdf0e10cSrcweir+ type |= xmlSecKeyDataTypeSymmetric ; 4281cdf0e10cSrcweir+ } else { 4282cdf0e10cSrcweir+ type |= xmlSecKeyDataTypeUnknown ; 4283cdf0e10cSrcweir+ } 4284cdf0e10cSrcweir+ 4285cdf0e10cSrcweir+ return type ; 4286cdf0e10cSrcweir } 4287cdf0e10cSrcweir 4288cdf0e10cSrcweir static xmlSecSize 4289cdf0e10cSrcweir xmlSecNssSymKeyDataGetSize(xmlSecKeyDataPtr data) { 4290cdf0e10cSrcweir+ xmlSecNssSymKeyDataCtxPtr context ; 4291cdf0e10cSrcweir+ unsigned int length = 0 ; 4292cdf0e10cSrcweir+ 4293cdf0e10cSrcweir xmlSecAssert2(xmlSecNssSymKeyDataCheckId(data), 0); 4294cdf0e10cSrcweir+ xmlSecAssert2( xmlSecKeyDataCheckSize( data, xmlSecNssSymKeyDataSize ), 0 ) ; 4295cdf0e10cSrcweir+ context = xmlSecNssSymKeyDataGetCtx( data ) ; 4296cdf0e10cSrcweir+ if( context == NULL ) { 4297cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4298cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 4299cdf0e10cSrcweir+ "xmlSecNssSymKeyDataGetCtx" , 4300cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 4301cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4302cdf0e10cSrcweir+ return 0 ; 4303cdf0e10cSrcweir+ } 4304cdf0e10cSrcweir+ 4305cdf0e10cSrcweir+ if( context->symkey != NULL ) { 4306cdf0e10cSrcweir+ length = PK11_GetKeyLength( context->symkey ) ; 4307cdf0e10cSrcweir+ length *= 8 ; 4308cdf0e10cSrcweir+ } 4309cdf0e10cSrcweir 4310cdf0e10cSrcweir- return(xmlSecKeyDataBinaryValueGetSize(data)); 4311cdf0e10cSrcweir+ return length ; 4312cdf0e10cSrcweir } 4313cdf0e10cSrcweir 4314cdf0e10cSrcweir static void 4315cdf0e10cSrcweir xmlSecNssSymKeyDataDebugDump(xmlSecKeyDataPtr data, FILE* output) { 4316cdf0e10cSrcweir xmlSecAssert(xmlSecNssSymKeyDataCheckId(data)); 4317cdf0e10cSrcweir 4318cdf0e10cSrcweir- xmlSecKeyDataBinaryValueDebugDump(data, output); 4319cdf0e10cSrcweir+ /* print only size, everything else is sensitive */ 4320cdf0e10cSrcweir+ fprintf( output , "=== %s: size=%d\n" , data->id->dataNodeName , 4321cdf0e10cSrcweir+ xmlSecKeyDataGetSize(data)) ; 4322cdf0e10cSrcweir } 4323cdf0e10cSrcweir 4324cdf0e10cSrcweir static void 4325cdf0e10cSrcweir xmlSecNssSymKeyDataDebugXmlDump(xmlSecKeyDataPtr data, FILE* output) { 4326cdf0e10cSrcweir xmlSecAssert(xmlSecNssSymKeyDataCheckId(data)); 4327cdf0e10cSrcweir- 4328cdf0e10cSrcweir- xmlSecKeyDataBinaryValueDebugXmlDump(data, output); 4329cdf0e10cSrcweir+ 4330cdf0e10cSrcweir+ /* print only size, everything else is sensitive */ 4331cdf0e10cSrcweir+ fprintf( output , "<%s size=\"%d\" />\n" , data->id->dataNodeName , 4332cdf0e10cSrcweir+ xmlSecKeyDataGetSize(data)) ; 4333cdf0e10cSrcweir } 4334cdf0e10cSrcweir 4335cdf0e10cSrcweir static int 4336cdf0e10cSrcweir@@ -201,7 +858,7 @@ 4337cdf0e10cSrcweir *************************************************************************/ 4338cdf0e10cSrcweir static xmlSecKeyDataKlass xmlSecNssKeyDataAesKlass = { 4339cdf0e10cSrcweir sizeof(xmlSecKeyDataKlass), 4340cdf0e10cSrcweir- xmlSecKeyDataBinarySize, 4341cdf0e10cSrcweir+ xmlSecNssSymKeyDataSize, 4342cdf0e10cSrcweir 4343cdf0e10cSrcweir /* data */ 4344cdf0e10cSrcweir xmlSecNameAESKeyValue, 4345cdf0e10cSrcweir@@ -282,7 +939,7 @@ 4346cdf0e10cSrcweir *************************************************************************/ 4347cdf0e10cSrcweir static xmlSecKeyDataKlass xmlSecNssKeyDataDesKlass = { 4348cdf0e10cSrcweir sizeof(xmlSecKeyDataKlass), 4349cdf0e10cSrcweir- xmlSecKeyDataBinarySize, 4350cdf0e10cSrcweir+ xmlSecNssSymKeyDataSize, 4351cdf0e10cSrcweir 4352cdf0e10cSrcweir /* data */ 4353cdf0e10cSrcweir xmlSecNameDESKeyValue, 4354cdf0e10cSrcweir@@ -364,7 +1021,7 @@ 4355cdf0e10cSrcweir *************************************************************************/ 4356cdf0e10cSrcweir static xmlSecKeyDataKlass xmlSecNssKeyDataHmacKlass = { 4357cdf0e10cSrcweir sizeof(xmlSecKeyDataKlass), 4358cdf0e10cSrcweir- xmlSecKeyDataBinarySize, 4359cdf0e10cSrcweir+ xmlSecNssSymKeyDataSize, 4360cdf0e10cSrcweir 4361cdf0e10cSrcweir /* data */ 4362cdf0e10cSrcweir xmlSecNameHMACKeyValue, 4363cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/tokens.c 2009-09-21 14:07:19.249145861 +0200 4364cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/tokens.c 2009-09-21 14:02:48.556772442 +0200 4365cdf0e10cSrcweir@@ -1 +1,548 @@ 4366cdf0e10cSrcweir-dummy 4367cdf0e10cSrcweir+/** 4368cdf0e10cSrcweir+ * XMLSec library 4369cdf0e10cSrcweir+ * 4370cdf0e10cSrcweir+ * This is free software; see Copyright file in the source 4371cdf0e10cSrcweir+ * distribution for preciese wording. 4372cdf0e10cSrcweir+ * 4373cdf0e10cSrcweir+ * Copyright.................................. 4374cdf0e10cSrcweir+ * 4375cdf0e10cSrcweir+ * Contributor(s): _____________________________ 4376cdf0e10cSrcweir+ * 4377cdf0e10cSrcweir+ */ 4378cdf0e10cSrcweir+ 4379cdf0e10cSrcweir+/** 4380cdf0e10cSrcweir+ * In order to ensure that particular crypto operation is performed on 4381cdf0e10cSrcweir+ * particular crypto device, a subclass of xmlSecList is used to store slot and 4382cdf0e10cSrcweir+ * mechanism information. 4383cdf0e10cSrcweir+ * 4384cdf0e10cSrcweir+ * In the list, a slot is bound with a mechanism. If the mechanism is available, 4385cdf0e10cSrcweir+ * this mechanism only can perform on the slot; otherwise, it can perform on 4386cdf0e10cSrcweir+ * every eligibl slot in the list. 4387cdf0e10cSrcweir+ * 4388cdf0e10cSrcweir+ * When try to find a slot for a particular mechanism, the slot bound with 4389a893be29SPedro Giffuni+ * available mechanism will be looked up firstly. 4390cdf0e10cSrcweir+ */ 4391cdf0e10cSrcweir+#include "globals.h" 4392cdf0e10cSrcweir+#include <string.h> 4393cdf0e10cSrcweir+ 4394cdf0e10cSrcweir+#include <xmlsec/xmlsec.h> 4395cdf0e10cSrcweir+#include <xmlsec/errors.h> 4396cdf0e10cSrcweir+#include <xmlsec/list.h> 4397cdf0e10cSrcweir+ 4398cdf0e10cSrcweir+#include <xmlsec/nss/tokens.h> 4399cdf0e10cSrcweir+ 4400cdf0e10cSrcweir+int 4401cdf0e10cSrcweir+xmlSecNssKeySlotSetMechList( 4402cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4403cdf0e10cSrcweir+ CK_MECHANISM_TYPE_PTR mechanismList 4404cdf0e10cSrcweir+) { 4405cdf0e10cSrcweir+ int counter ; 4406cdf0e10cSrcweir+ 4407cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , -1 ) ; 4408cdf0e10cSrcweir+ 4409cdf0e10cSrcweir+ if( keySlot->mechanismList != CK_NULL_PTR ) { 4410cdf0e10cSrcweir+ xmlFree( keySlot->mechanismList ) ; 4411cdf0e10cSrcweir+ 4412cdf0e10cSrcweir+ for( counter = 0 ; *( mechanismList + counter ) != CKM_INVALID_MECHANISM ; counter ++ ) ; 4413cdf0e10cSrcweir+ keySlot->mechanismList = ( CK_MECHANISM_TYPE_PTR )xmlMalloc( ( counter + 1 ) * sizeof( CK_MECHANISM_TYPE ) ) ; 4414cdf0e10cSrcweir+ if( keySlot->mechanismList == NULL ) { 4415cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4416cdf0e10cSrcweir+ NULL , 4417cdf0e10cSrcweir+ NULL , 4418cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4419cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4420cdf0e10cSrcweir+ return( -1 ); 4421cdf0e10cSrcweir+ } 4422cdf0e10cSrcweir+ for( ; counter >= 0 ; counter -- ) 4423cdf0e10cSrcweir+ *( keySlot->mechanismList + counter ) = *( mechanismList + counter ) ; 4424cdf0e10cSrcweir+ } 4425cdf0e10cSrcweir+ 4426cdf0e10cSrcweir+ return( 0 ); 4427cdf0e10cSrcweir+} 4428cdf0e10cSrcweir+ 4429cdf0e10cSrcweir+int 4430cdf0e10cSrcweir+xmlSecNssKeySlotEnableMech( 4431cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4432cdf0e10cSrcweir+ CK_MECHANISM_TYPE mechanism 4433cdf0e10cSrcweir+) { 4434cdf0e10cSrcweir+ int counter ; 4435cdf0e10cSrcweir+ CK_MECHANISM_TYPE_PTR newList ; 4436cdf0e10cSrcweir+ 4437cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , -1 ) ; 4438cdf0e10cSrcweir+ 4439cdf0e10cSrcweir+ if( mechanism != CKM_INVALID_MECHANISM ) { 4440cdf0e10cSrcweir+ for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM ; counter ++ ) ; 4441cdf0e10cSrcweir+ newList = ( CK_MECHANISM_TYPE_PTR )xmlMalloc( ( counter + 1 + 1 ) * sizeof( CK_MECHANISM_TYPE ) ) ; 4442cdf0e10cSrcweir+ if( newList == NULL ) { 4443cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4444cdf0e10cSrcweir+ NULL , 4445cdf0e10cSrcweir+ NULL , 4446cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4447cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4448cdf0e10cSrcweir+ return( -1 ); 4449cdf0e10cSrcweir+ } 4450cdf0e10cSrcweir+ *( newList + counter + 1 ) = CKM_INVALID_MECHANISM ; 4451cdf0e10cSrcweir+ *( newList + counter ) = mechanism ; 4452cdf0e10cSrcweir+ for( counter -= 1 ; counter >= 0 ; counter -- ) 4453cdf0e10cSrcweir+ *( newList + counter ) = *( keySlot->mechanismList + counter ) ; 4454cdf0e10cSrcweir+ 4455cdf0e10cSrcweir+ xmlFree( keySlot->mechanismList ) ; 4456cdf0e10cSrcweir+ keySlot->mechanismList = newList ; 4457cdf0e10cSrcweir+ } 4458cdf0e10cSrcweir+ 4459cdf0e10cSrcweir+ return(0); 4460cdf0e10cSrcweir+} 4461cdf0e10cSrcweir+ 4462cdf0e10cSrcweir+int 4463cdf0e10cSrcweir+xmlSecNssKeySlotDisableMech( 4464cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4465cdf0e10cSrcweir+ CK_MECHANISM_TYPE mechanism 4466cdf0e10cSrcweir+) { 4467cdf0e10cSrcweir+ int counter ; 4468cdf0e10cSrcweir+ 4469cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , -1 ) ; 4470cdf0e10cSrcweir+ 4471cdf0e10cSrcweir+ for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM ; counter ++ ) { 4472cdf0e10cSrcweir+ if( *( keySlot->mechanismList + counter ) == mechanism ) { 4473cdf0e10cSrcweir+ for( ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM ; counter ++ ) { 4474cdf0e10cSrcweir+ *( keySlot->mechanismList + counter ) = *( keySlot->mechanismList + counter + 1 ) ; 4475cdf0e10cSrcweir+ } 4476cdf0e10cSrcweir+ 4477cdf0e10cSrcweir+ break ; 4478cdf0e10cSrcweir+ } 4479cdf0e10cSrcweir+ } 4480cdf0e10cSrcweir+ 4481cdf0e10cSrcweir+ return(0); 4482cdf0e10cSrcweir+} 4483cdf0e10cSrcweir+ 4484cdf0e10cSrcweir+CK_MECHANISM_TYPE_PTR 4485cdf0e10cSrcweir+xmlSecNssKeySlotGetMechList( 4486cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 4487cdf0e10cSrcweir+) { 4488cdf0e10cSrcweir+ if( keySlot != NULL ) 4489cdf0e10cSrcweir+ return keySlot->mechanismList ; 4490cdf0e10cSrcweir+ else 4491cdf0e10cSrcweir+ return NULL ; 4492cdf0e10cSrcweir+} 4493cdf0e10cSrcweir+ 4494cdf0e10cSrcweir+int 4495cdf0e10cSrcweir+xmlSecNssKeySlotSetSlot( 4496cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4497cdf0e10cSrcweir+ PK11SlotInfo* slot 4498cdf0e10cSrcweir+) { 4499cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , -1 ) ; 4500cdf0e10cSrcweir+ 4501cdf0e10cSrcweir+ if( slot != NULL && keySlot->slot != slot ) { 4502cdf0e10cSrcweir+ if( keySlot->slot != NULL ) 4503cdf0e10cSrcweir+ PK11_FreeSlot( keySlot->slot ) ; 4504cdf0e10cSrcweir+ 4505cdf0e10cSrcweir+ if( keySlot->mechanismList != NULL ) { 4506cdf0e10cSrcweir+ xmlFree( keySlot->mechanismList ) ; 4507cdf0e10cSrcweir+ keySlot->mechanismList = NULL ; 4508cdf0e10cSrcweir+ } 4509cdf0e10cSrcweir+ 4510cdf0e10cSrcweir+ keySlot->slot = PK11_ReferenceSlot( slot ) ; 4511cdf0e10cSrcweir+ } 4512cdf0e10cSrcweir+ 4513cdf0e10cSrcweir+ return(0); 4514cdf0e10cSrcweir+} 4515cdf0e10cSrcweir+ 4516cdf0e10cSrcweir+int 4517cdf0e10cSrcweir+xmlSecNssKeySlotInitialize( 4518cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4519cdf0e10cSrcweir+ PK11SlotInfo* slot 4520cdf0e10cSrcweir+) { 4521cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , -1 ) ; 4522cdf0e10cSrcweir+ xmlSecAssert2( keySlot->slot == NULL , -1 ) ; 4523cdf0e10cSrcweir+ xmlSecAssert2( keySlot->mechanismList == NULL , -1 ) ; 4524cdf0e10cSrcweir+ 4525cdf0e10cSrcweir+ if( slot != NULL ) { 4526cdf0e10cSrcweir+ keySlot->slot = PK11_ReferenceSlot( slot ) ; 4527cdf0e10cSrcweir+ } 4528cdf0e10cSrcweir+ 4529cdf0e10cSrcweir+ return(0); 4530cdf0e10cSrcweir+} 4531cdf0e10cSrcweir+ 4532cdf0e10cSrcweir+void 4533cdf0e10cSrcweir+xmlSecNssKeySlotFinalize( 4534cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 4535cdf0e10cSrcweir+) { 4536cdf0e10cSrcweir+ xmlSecAssert( keySlot != NULL ) ; 4537cdf0e10cSrcweir+ 4538cdf0e10cSrcweir+ if( keySlot->mechanismList != NULL ) { 4539cdf0e10cSrcweir+ xmlFree( keySlot->mechanismList ) ; 4540cdf0e10cSrcweir+ keySlot->mechanismList = NULL ; 4541cdf0e10cSrcweir+ } 4542cdf0e10cSrcweir+ 4543cdf0e10cSrcweir+ if( keySlot->slot != NULL ) { 4544cdf0e10cSrcweir+ PK11_FreeSlot( keySlot->slot ) ; 4545cdf0e10cSrcweir+ keySlot->slot = NULL ; 4546cdf0e10cSrcweir+ } 4547cdf0e10cSrcweir+ 4548cdf0e10cSrcweir+} 4549cdf0e10cSrcweir+ 4550cdf0e10cSrcweir+PK11SlotInfo* 4551cdf0e10cSrcweir+xmlSecNssKeySlotGetSlot( 4552cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 4553cdf0e10cSrcweir+) { 4554cdf0e10cSrcweir+ if( keySlot != NULL ) 4555cdf0e10cSrcweir+ return keySlot->slot ; 4556cdf0e10cSrcweir+ else 4557cdf0e10cSrcweir+ return NULL ; 4558cdf0e10cSrcweir+} 4559cdf0e10cSrcweir+ 4560cdf0e10cSrcweir+xmlSecNssKeySlotPtr 4561cdf0e10cSrcweir+xmlSecNssKeySlotCreate() { 4562cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot ; 4563cdf0e10cSrcweir+ 4564cdf0e10cSrcweir+ /* Allocates a new xmlSecNssKeySlot and fill the fields */ 4565cdf0e10cSrcweir+ keySlot = ( xmlSecNssKeySlotPtr )xmlMalloc( sizeof( xmlSecNssKeySlot ) ) ; 4566cdf0e10cSrcweir+ if( keySlot == NULL ) { 4567cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4568cdf0e10cSrcweir+ NULL , 4569cdf0e10cSrcweir+ NULL , 4570cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4571cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4572cdf0e10cSrcweir+ return( NULL ); 4573cdf0e10cSrcweir+ } 4574cdf0e10cSrcweir+ memset( keySlot, 0, sizeof( xmlSecNssKeySlot ) ) ; 4575cdf0e10cSrcweir+ 4576cdf0e10cSrcweir+ return( keySlot ) ; 4577cdf0e10cSrcweir+} 4578cdf0e10cSrcweir+ 4579cdf0e10cSrcweir+int 4580cdf0e10cSrcweir+xmlSecNssKeySlotCopy( 4581cdf0e10cSrcweir+ xmlSecNssKeySlotPtr newKeySlot , 4582cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 4583cdf0e10cSrcweir+) { 4584cdf0e10cSrcweir+ CK_MECHANISM_TYPE_PTR mech ; 4585cdf0e10cSrcweir+ int counter ; 4586cdf0e10cSrcweir+ 4587cdf0e10cSrcweir+ xmlSecAssert2( newKeySlot != NULL , -1 ) ; 4588cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , -1 ) ; 4589cdf0e10cSrcweir+ 4590cdf0e10cSrcweir+ if( keySlot->slot != NULL && newKeySlot->slot != keySlot->slot ) { 4591cdf0e10cSrcweir+ if( newKeySlot->slot != NULL ) 4592cdf0e10cSrcweir+ PK11_FreeSlot( newKeySlot->slot ) ; 4593cdf0e10cSrcweir+ 4594cdf0e10cSrcweir+ newKeySlot->slot = PK11_ReferenceSlot( keySlot->slot ) ; 4595cdf0e10cSrcweir+ } 4596cdf0e10cSrcweir+ 4597cdf0e10cSrcweir+ if( keySlot->mechanismList != CK_NULL_PTR ) { 4598cdf0e10cSrcweir+ xmlFree( newKeySlot->mechanismList ) ; 4599cdf0e10cSrcweir+ 4600cdf0e10cSrcweir+ for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM ; counter ++ ) ; 4601cdf0e10cSrcweir+ newKeySlot->mechanismList = ( CK_MECHANISM_TYPE_PTR )xmlMalloc( ( counter + 1 ) * sizeof( CK_MECHANISM_TYPE ) ) ; 4602cdf0e10cSrcweir+ if( newKeySlot->mechanismList == NULL ) { 4603cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4604cdf0e10cSrcweir+ NULL , 4605cdf0e10cSrcweir+ NULL , 4606cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4607cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4608cdf0e10cSrcweir+ return( -1 ); 4609cdf0e10cSrcweir+ } 4610cdf0e10cSrcweir+ for( ; counter >= 0 ; counter -- ) 4611cdf0e10cSrcweir+ *( newKeySlot->mechanismList + counter ) = *( keySlot->mechanismList + counter ) ; 4612cdf0e10cSrcweir+ } 4613cdf0e10cSrcweir+ 4614cdf0e10cSrcweir+ return( 0 ); 4615cdf0e10cSrcweir+} 4616cdf0e10cSrcweir+ 4617cdf0e10cSrcweir+xmlSecNssKeySlotPtr 4618cdf0e10cSrcweir+xmlSecNssKeySlotDuplicate( 4619cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 4620cdf0e10cSrcweir+) { 4621cdf0e10cSrcweir+ xmlSecNssKeySlotPtr newKeySlot ; 4622cdf0e10cSrcweir+ int ret ; 4623cdf0e10cSrcweir+ 4624cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , NULL ) ; 4625cdf0e10cSrcweir+ 4626cdf0e10cSrcweir+ newKeySlot = xmlSecNssKeySlotCreate() ; 4627cdf0e10cSrcweir+ if( newKeySlot == NULL ) { 4628cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4629cdf0e10cSrcweir+ NULL , 4630cdf0e10cSrcweir+ NULL , 4631cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4632cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4633cdf0e10cSrcweir+ return( NULL ); 4634cdf0e10cSrcweir+ } 4635cdf0e10cSrcweir+ 4636cdf0e10cSrcweir+ if( xmlSecNssKeySlotCopy( newKeySlot, keySlot ) < 0 ) { 4637cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4638cdf0e10cSrcweir+ NULL , 4639cdf0e10cSrcweir+ NULL , 4640cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4641cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4642cdf0e10cSrcweir+ return( NULL ); 4643cdf0e10cSrcweir+ } 4644cdf0e10cSrcweir+ 4645cdf0e10cSrcweir+ return( newKeySlot ); 4646cdf0e10cSrcweir+} 4647cdf0e10cSrcweir+ 4648cdf0e10cSrcweir+void 4649cdf0e10cSrcweir+xmlSecNssKeySlotDestroy( 4650cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot 4651cdf0e10cSrcweir+) { 4652cdf0e10cSrcweir+ xmlSecAssert( keySlot != NULL ) ; 4653cdf0e10cSrcweir+ 4654cdf0e10cSrcweir+ if( keySlot->mechanismList != NULL ) 4655cdf0e10cSrcweir+ xmlFree( keySlot->mechanismList ) ; 4656cdf0e10cSrcweir+ 4657cdf0e10cSrcweir+ if( keySlot->slot != NULL ) 4658cdf0e10cSrcweir+ PK11_FreeSlot( keySlot->slot ) ; 4659cdf0e10cSrcweir+ 4660cdf0e10cSrcweir+ xmlFree( keySlot ) ; 4661cdf0e10cSrcweir+} 4662cdf0e10cSrcweir+ 4663cdf0e10cSrcweir+int 4664cdf0e10cSrcweir+xmlSecNssKeySlotBindMech( 4665cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4666cdf0e10cSrcweir+ CK_MECHANISM_TYPE type 4667cdf0e10cSrcweir+) { 4668cdf0e10cSrcweir+ int counter ; 4669cdf0e10cSrcweir+ 4670cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , 0 ) ; 4671cdf0e10cSrcweir+ xmlSecAssert2( keySlot->slot != NULL , 0 ) ; 4672cdf0e10cSrcweir+ xmlSecAssert2( type != CKM_INVALID_MECHANISM , 0 ) ; 4673cdf0e10cSrcweir+ 4674cdf0e10cSrcweir+ for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM ; counter ++ ) { 4675cdf0e10cSrcweir+ if( *( keySlot->mechanismList + counter ) == type ) 4676cdf0e10cSrcweir+ return(1) ; 4677cdf0e10cSrcweir+ } 4678cdf0e10cSrcweir+ 4679cdf0e10cSrcweir+ return( 0 ) ; 4680cdf0e10cSrcweir+} 4681cdf0e10cSrcweir+ 4682cdf0e10cSrcweir+int 4683cdf0e10cSrcweir+xmlSecNssKeySlotSupportMech( 4684cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4685cdf0e10cSrcweir+ CK_MECHANISM_TYPE type 4686cdf0e10cSrcweir+) { 4687cdf0e10cSrcweir+ xmlSecAssert2( keySlot != NULL , 0 ) ; 4688cdf0e10cSrcweir+ xmlSecAssert2( keySlot->slot != NULL , 0 ) ; 4689cdf0e10cSrcweir+ xmlSecAssert2( type != CKM_INVALID_MECHANISM , 0 ) ; 4690cdf0e10cSrcweir+ 4691cdf0e10cSrcweir+ if( PK11_DoesMechanism( keySlot->slot , type ) == PR_TRUE ) { 4692cdf0e10cSrcweir+ return(1); 4693cdf0e10cSrcweir+ } else 4694cdf0e10cSrcweir+ return(0); 4695cdf0e10cSrcweir+} 4696cdf0e10cSrcweir+ 4697cdf0e10cSrcweir+void 4698cdf0e10cSrcweir+xmlSecNssKeySlotDebugDump( 4699cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4700cdf0e10cSrcweir+ FILE* output 4701cdf0e10cSrcweir+) { 4702cdf0e10cSrcweir+ xmlSecAssert( keySlot != NULL ) ; 4703cdf0e10cSrcweir+ xmlSecAssert( output != NULL ) ; 4704cdf0e10cSrcweir+ 4705cdf0e10cSrcweir+ fprintf( output, "== KEY SLOT\n" ); 4706cdf0e10cSrcweir+} 4707cdf0e10cSrcweir+ 4708cdf0e10cSrcweir+void 4709cdf0e10cSrcweir+xmlSecNssKeySlotDebugXmlDump( 4710cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot , 4711cdf0e10cSrcweir+ FILE* output 4712cdf0e10cSrcweir+) { 4713cdf0e10cSrcweir+} 4714cdf0e10cSrcweir+ 4715cdf0e10cSrcweir+/** 4716cdf0e10cSrcweir+ * Key Slot List 4717cdf0e10cSrcweir+ */ 4718cdf0e10cSrcweir+#ifdef __MINGW32__ // for runtime-pseudo-reloc 4719cdf0e10cSrcweir+static struct _xmlSecPtrListKlass xmlSecNssKeySlotPtrListKlass = { 4720cdf0e10cSrcweir+#else 4721cdf0e10cSrcweir+static xmlSecPtrListKlass xmlSecNssKeySlotPtrListKlass = { 4722cdf0e10cSrcweir+#endif 4723cdf0e10cSrcweir+ BAD_CAST "mechanism-list", 4724cdf0e10cSrcweir+ (xmlSecPtrDuplicateItemMethod)xmlSecNssKeySlotDuplicate, 4725cdf0e10cSrcweir+ (xmlSecPtrDestroyItemMethod)xmlSecNssKeySlotDestroy, 4726cdf0e10cSrcweir+ (xmlSecPtrDebugDumpItemMethod)xmlSecNssKeySlotDebugDump, 4727cdf0e10cSrcweir+ (xmlSecPtrDebugDumpItemMethod)xmlSecNssKeySlotDebugXmlDump, 4728cdf0e10cSrcweir+}; 4729cdf0e10cSrcweir+ 4730cdf0e10cSrcweir+xmlSecPtrListId 4731cdf0e10cSrcweir+xmlSecNssKeySlotListGetKlass(void) { 4732cdf0e10cSrcweir+ return(&xmlSecNssKeySlotPtrListKlass); 4733cdf0e10cSrcweir+} 4734cdf0e10cSrcweir+ 4735cdf0e10cSrcweir+ 4736cdf0e10cSrcweir+/*- 4737cdf0e10cSrcweir+ * Global PKCS#11 crypto token repository -- Key slot list 4738cdf0e10cSrcweir+ */ 4739cdf0e10cSrcweir+static xmlSecPtrListPtr _xmlSecNssKeySlotList = NULL ; 4740cdf0e10cSrcweir+ 4741cdf0e10cSrcweir+PK11SlotInfo* 4742cdf0e10cSrcweir+xmlSecNssSlotGet( 4743cdf0e10cSrcweir+ CK_MECHANISM_TYPE type 4744cdf0e10cSrcweir+) { 4745cdf0e10cSrcweir+ PK11SlotInfo* slot = NULL ; 4746cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot ; 4747cdf0e10cSrcweir+ xmlSecSize ksSize ; 4748cdf0e10cSrcweir+ xmlSecSize ksPos ; 4749cdf0e10cSrcweir+ char flag ; 4750cdf0e10cSrcweir+ 4751cdf0e10cSrcweir+ if( _xmlSecNssKeySlotList == NULL ) { 4752cdf0e10cSrcweir+ slot = PK11_GetBestSlot( type , NULL ) ; 4753cdf0e10cSrcweir+ } else { 4754cdf0e10cSrcweir+ ksSize = xmlSecPtrListGetSize( _xmlSecNssKeySlotList ) ; 4755cdf0e10cSrcweir+ 4756cdf0e10cSrcweir+ /*- 4757cdf0e10cSrcweir+ * Firstly, checking whether the mechanism is bound with a special slot. 4758cdf0e10cSrcweir+ * If no bound slot, we try to find the first eligible slot in the list. 4759cdf0e10cSrcweir+ */ 4760cdf0e10cSrcweir+ for( flag = 0, ksPos = 0 ; ksPos < ksSize ; ksPos ++ ) { 4761cdf0e10cSrcweir+ keySlot = ( xmlSecNssKeySlotPtr )xmlSecPtrListGetItem( _xmlSecNssKeySlotList, ksPos ) ; 4762cdf0e10cSrcweir+ if( keySlot != NULL && xmlSecNssKeySlotBindMech( keySlot, type ) ) { 4763cdf0e10cSrcweir+ slot = xmlSecNssKeySlotGetSlot( keySlot ) ; 4764cdf0e10cSrcweir+ flag = 2 ; 4765cdf0e10cSrcweir+ } else if( flag == 0 && xmlSecNssKeySlotSupportMech( keySlot, type ) ) { 4766cdf0e10cSrcweir+ slot = xmlSecNssKeySlotGetSlot( keySlot ) ; 4767cdf0e10cSrcweir+ flag = 1 ; 4768cdf0e10cSrcweir+ } 4769cdf0e10cSrcweir+ 4770cdf0e10cSrcweir+ if( flag == 2 ) 4771cdf0e10cSrcweir+ break ; 4772cdf0e10cSrcweir+ } 4773cdf0e10cSrcweir+ if( slot != NULL ) 4774cdf0e10cSrcweir+ slot = PK11_ReferenceSlot( slot ) ; 4775cdf0e10cSrcweir+ } 4776cdf0e10cSrcweir+ 4777cdf0e10cSrcweir+ if( slot != NULL && PK11_NeedLogin( slot ) ) { 4778cdf0e10cSrcweir+ if( PK11_Authenticate( slot , PR_TRUE , NULL ) != SECSuccess ) { 4779cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4780cdf0e10cSrcweir+ NULL , 4781cdf0e10cSrcweir+ NULL , 4782cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4783cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4784cdf0e10cSrcweir+ PK11_FreeSlot( slot ) ; 4785cdf0e10cSrcweir+ return( NULL ); 4786cdf0e10cSrcweir+ } 4787cdf0e10cSrcweir+ } 4788cdf0e10cSrcweir+ 4789cdf0e10cSrcweir+ return slot ; 4790cdf0e10cSrcweir+} 4791cdf0e10cSrcweir+ 4792cdf0e10cSrcweir+int 4793cdf0e10cSrcweir+xmlSecNssSlotInitialize( 4794cdf0e10cSrcweir+ void 4795cdf0e10cSrcweir+) { 4796cdf0e10cSrcweir+ if( _xmlSecNssKeySlotList != NULL ) { 4797cdf0e10cSrcweir+ xmlSecPtrListDestroy( _xmlSecNssKeySlotList ) ; 4798cdf0e10cSrcweir+ _xmlSecNssKeySlotList = NULL ; 4799cdf0e10cSrcweir+ } 4800cdf0e10cSrcweir+ 4801cdf0e10cSrcweir+ _xmlSecNssKeySlotList = xmlSecPtrListCreate( xmlSecNssKeySlotListId ) ; 4802cdf0e10cSrcweir+ if( _xmlSecNssKeySlotList == NULL ) { 4803cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4804cdf0e10cSrcweir+ NULL , 4805cdf0e10cSrcweir+ NULL , 4806cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4807cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4808cdf0e10cSrcweir+ return( -1 ); 4809cdf0e10cSrcweir+ } 4810cdf0e10cSrcweir+ 4811cdf0e10cSrcweir+ return(0); 4812cdf0e10cSrcweir+} 4813cdf0e10cSrcweir+ 4814cdf0e10cSrcweir+void 4815cdf0e10cSrcweir+xmlSecNssSlotShutdown( 4816cdf0e10cSrcweir+ void 4817cdf0e10cSrcweir+) { 4818cdf0e10cSrcweir+ if( _xmlSecNssKeySlotList != NULL ) { 4819cdf0e10cSrcweir+ xmlSecPtrListDestroy( _xmlSecNssKeySlotList ) ; 4820cdf0e10cSrcweir+ _xmlSecNssKeySlotList = NULL ; 4821cdf0e10cSrcweir+ } 4822cdf0e10cSrcweir+} 4823cdf0e10cSrcweir+ 4824cdf0e10cSrcweir+int 4825cdf0e10cSrcweir+xmlSecNssSlotAdopt( 4826cdf0e10cSrcweir+ PK11SlotInfo* slot, 4827cdf0e10cSrcweir+ CK_MECHANISM_TYPE type 4828cdf0e10cSrcweir+) { 4829cdf0e10cSrcweir+ xmlSecNssKeySlotPtr keySlot ; 4830cdf0e10cSrcweir+ xmlSecSize ksSize ; 4831cdf0e10cSrcweir+ xmlSecSize ksPos ; 4832cdf0e10cSrcweir+ char flag ; 4833cdf0e10cSrcweir+ 4834cdf0e10cSrcweir+ xmlSecAssert2( _xmlSecNssKeySlotList != NULL, -1 ) ; 4835cdf0e10cSrcweir+ xmlSecAssert2( slot != NULL, -1 ) ; 4836cdf0e10cSrcweir+ 4837cdf0e10cSrcweir+ ksSize = xmlSecPtrListGetSize( _xmlSecNssKeySlotList ) ; 4838cdf0e10cSrcweir+ 4839cdf0e10cSrcweir+ /*- 4840cdf0e10cSrcweir+ * Firstly, checking whether the slot is in the repository already. 4841cdf0e10cSrcweir+ */ 4842cdf0e10cSrcweir+ flag = 0 ; 4843cdf0e10cSrcweir+ for( ksPos = 0 ; ksPos < ksSize ; ksPos ++ ) { 4844cdf0e10cSrcweir+ keySlot = ( xmlSecNssKeySlotPtr )xmlSecPtrListGetItem( _xmlSecNssKeySlotList, ksPos ) ; 4845cdf0e10cSrcweir+ /* If find the slot in the list */ 4846cdf0e10cSrcweir+ if( keySlot != NULL && xmlSecNssKeySlotGetSlot( keySlot ) == slot ) { 4847*38e54eaaSJohn Bampton+ /* If mechanism type is valid, bind the slot with the mechanism */ 4848cdf0e10cSrcweir+ if( type != CKM_INVALID_MECHANISM ) { 4849cdf0e10cSrcweir+ if( xmlSecNssKeySlotEnableMech( keySlot, type ) < 0 ) { 4850cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4851cdf0e10cSrcweir+ NULL , 4852cdf0e10cSrcweir+ NULL , 4853cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4854cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4855cdf0e10cSrcweir+ return(-1); 4856cdf0e10cSrcweir+ } 4857cdf0e10cSrcweir+ } 4858cdf0e10cSrcweir+ 4859cdf0e10cSrcweir+ flag = 1 ; 4860cdf0e10cSrcweir+ } 4861cdf0e10cSrcweir+ } 4862cdf0e10cSrcweir+ 4863cdf0e10cSrcweir+ /* If the slot do not in the list, add a new item to the list */ 4864cdf0e10cSrcweir+ if( flag == 0 ) { 4865cdf0e10cSrcweir+ /* Create a new KeySlot */ 4866cdf0e10cSrcweir+ keySlot = xmlSecNssKeySlotCreate() ; 4867cdf0e10cSrcweir+ if( keySlot == NULL ) { 4868cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4869cdf0e10cSrcweir+ NULL , 4870cdf0e10cSrcweir+ NULL , 4871cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4872cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4873cdf0e10cSrcweir+ return(-1); 4874cdf0e10cSrcweir+ } 4875cdf0e10cSrcweir+ 4876cdf0e10cSrcweir+ /* Initialize the keySlot with a slot */ 4877cdf0e10cSrcweir+ if( xmlSecNssKeySlotInitialize( keySlot, slot ) < 0 ) { 4878cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4879cdf0e10cSrcweir+ NULL , 4880cdf0e10cSrcweir+ NULL , 4881cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4882cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4883cdf0e10cSrcweir+ xmlSecNssKeySlotDestroy( keySlot ) ; 4884cdf0e10cSrcweir+ return(-1); 4885cdf0e10cSrcweir+ } 4886cdf0e10cSrcweir+ 4887*38e54eaaSJohn Bampton+ /* If mechanism type is valid, bind the slot with the mechanism */ 4888cdf0e10cSrcweir+ if( type != CKM_INVALID_MECHANISM ) { 4889cdf0e10cSrcweir+ if( xmlSecNssKeySlotEnableMech( keySlot, type ) < 0 ) { 4890cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4891cdf0e10cSrcweir+ NULL , 4892cdf0e10cSrcweir+ NULL , 4893cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4894cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4895cdf0e10cSrcweir+ xmlSecNssKeySlotDestroy( keySlot ) ; 4896cdf0e10cSrcweir+ return(-1); 4897cdf0e10cSrcweir+ } 4898cdf0e10cSrcweir+ } 4899cdf0e10cSrcweir+ 4900cdf0e10cSrcweir+ /* Add keySlot into the list */ 4901cdf0e10cSrcweir+ if( xmlSecPtrListAdd( _xmlSecNssKeySlotList, keySlot ) < 0 ) { 4902cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 4903cdf0e10cSrcweir+ NULL , 4904cdf0e10cSrcweir+ NULL , 4905cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED , 4906cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 4907cdf0e10cSrcweir+ xmlSecNssKeySlotDestroy( keySlot ) ; 4908cdf0e10cSrcweir+ return(-1); 4909cdf0e10cSrcweir+ } 4910cdf0e10cSrcweir+ } 4911cdf0e10cSrcweir+ 4912cdf0e10cSrcweir+ return(0); 4913cdf0e10cSrcweir+} 4914cdf0e10cSrcweir+ 4915cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/x509.c 2009-06-25 22:53:18.000000000 +0200 4916cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/x509.c 2009-09-21 14:02:48.642312431 +0200 4917cdf0e10cSrcweir@@ -34,7 +34,6 @@ 4918cdf0e10cSrcweir #include <xmlsec/keys.h> 4919cdf0e10cSrcweir #include <xmlsec/keyinfo.h> 4920cdf0e10cSrcweir #include <xmlsec/keysmngr.h> 4921cdf0e10cSrcweir-#include <xmlsec/x509.h> 4922cdf0e10cSrcweir #include <xmlsec/base64.h> 4923cdf0e10cSrcweir #include <xmlsec/errors.h> 4924cdf0e10cSrcweir 4925cdf0e10cSrcweir@@ -61,33 +60,18 @@ 4926cdf0e10cSrcweir static int xmlSecNssX509CertificateNodeRead (xmlSecKeyDataPtr data, 4927cdf0e10cSrcweir xmlNodePtr node, 4928cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4929cdf0e10cSrcweir-static int xmlSecNssX509CertificateNodeWrite (CERTCertificate* cert, 4930cdf0e10cSrcweir- xmlNodePtr node, 4931cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx); 4932cdf0e10cSrcweir static int xmlSecNssX509SubjectNameNodeRead (xmlSecKeyDataPtr data, 4933cdf0e10cSrcweir xmlNodePtr node, 4934cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4935cdf0e10cSrcweir-static int xmlSecNssX509SubjectNameNodeWrite (CERTCertificate* cert, 4936cdf0e10cSrcweir- xmlNodePtr node, 4937cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx); 4938cdf0e10cSrcweir static int xmlSecNssX509IssuerSerialNodeRead (xmlSecKeyDataPtr data, 4939cdf0e10cSrcweir xmlNodePtr node, 4940cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4941cdf0e10cSrcweir-static int xmlSecNssX509IssuerSerialNodeWrite (CERTCertificate* cert, 4942cdf0e10cSrcweir- xmlNodePtr node, 4943cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx); 4944cdf0e10cSrcweir static int xmlSecNssX509SKINodeRead (xmlSecKeyDataPtr data, 4945cdf0e10cSrcweir xmlNodePtr node, 4946cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4947cdf0e10cSrcweir-static int xmlSecNssX509SKINodeWrite (CERTCertificate* cert, 4948cdf0e10cSrcweir- xmlNodePtr node, 4949cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx); 4950cdf0e10cSrcweir static int xmlSecNssX509CRLNodeRead (xmlSecKeyDataPtr data, 4951cdf0e10cSrcweir xmlNodePtr node, 4952cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4953cdf0e10cSrcweir-static int xmlSecNssX509CRLNodeWrite (CERTSignedCrl* crl, 4954cdf0e10cSrcweir- xmlNodePtr node, 4955cdf0e10cSrcweir- xmlSecKeyInfoCtxPtr keyInfoCtx); 4956cdf0e10cSrcweir static int xmlSecNssKeyDataX509VerifyAndExtractKey(xmlSecKeyDataPtr data, 4957cdf0e10cSrcweir xmlSecKeyPtr key, 4958cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4959cdf0e10cSrcweir@@ -104,9 +88,6 @@ 4960cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx); 4961cdf0e10cSrcweir static xmlChar* xmlSecNssX509CrlBase64DerWrite (CERTSignedCrl* crl, 4962cdf0e10cSrcweir int base64LineWrap); 4963cdf0e10cSrcweir-static xmlChar* xmlSecNssX509NameWrite (CERTName* nm); 4964cdf0e10cSrcweir-static xmlChar* xmlSecNssASN1IntegerWrite (SECItem *num); 4965cdf0e10cSrcweir-static xmlChar* xmlSecNssX509SKIWrite (CERTCertificate* cert); 4966cdf0e10cSrcweir static void xmlSecNssX509CertDebugDump (CERTCertificate* cert, 4967cdf0e10cSrcweir FILE* output); 4968cdf0e10cSrcweir static void xmlSecNssX509CertDebugXmlDump (CERTCertificate* cert, 4969cdf0e10cSrcweir@@ -752,31 +733,22 @@ 4970cdf0e10cSrcweir xmlSecNssKeyDataX509XmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, 4971cdf0e10cSrcweir xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 4972cdf0e10cSrcweir xmlSecKeyDataPtr data; 4973cdf0e10cSrcweir+ xmlNodePtr cur; 4974cdf0e10cSrcweir+ xmlChar* buf; 4975cdf0e10cSrcweir CERTCertificate* cert; 4976cdf0e10cSrcweir CERTSignedCrl* crl; 4977cdf0e10cSrcweir xmlSecSize size, pos; 4978cdf0e10cSrcweir- int content = 0; 4979cdf0e10cSrcweir- int ret; 4980cdf0e10cSrcweir 4981cdf0e10cSrcweir xmlSecAssert2(id == xmlSecNssKeyDataX509Id, -1); 4982cdf0e10cSrcweir xmlSecAssert2(key != NULL, -1); 4983cdf0e10cSrcweir xmlSecAssert2(node != NULL, -1); 4984cdf0e10cSrcweir xmlSecAssert2(keyInfoCtx != NULL, -1); 4985cdf0e10cSrcweir 4986cdf0e10cSrcweir- content = xmlSecX509DataGetNodeContent (node, 1, keyInfoCtx); 4987cdf0e10cSrcweir- if (content < 0) { 4988cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 4989cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 4990cdf0e10cSrcweir- "xmlSecX509DataGetNodeContent", 4991cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 4992cdf0e10cSrcweir- "content=%d", content); 4993cdf0e10cSrcweir- return(-1); 4994cdf0e10cSrcweir- } else if(content == 0) { 4995cdf0e10cSrcweir- /* by default we are writing certificates and crls */ 4996cdf0e10cSrcweir- content = XMLSEC_X509DATA_DEFAULT; 4997cdf0e10cSrcweir+ /* todo: flag in ctx remove all existing content */ 4998cdf0e10cSrcweir+ if(0) { 4999cdf0e10cSrcweir+ xmlNodeSetContent(node, NULL); 5000cdf0e10cSrcweir } 5001cdf0e10cSrcweir 5002cdf0e10cSrcweir- /* get x509 data */ 5003cdf0e10cSrcweir data = xmlSecKeyGetData(key, id); 5004cdf0e10cSrcweir if(data == NULL) { 5005cdf0e10cSrcweir /* no x509 data in the key */ 5006cdf0e10cSrcweir@@ -796,79 +768,74 @@ 5007cdf0e10cSrcweir return(-1); 5008cdf0e10cSrcweir } 5009cdf0e10cSrcweir 5010cdf0e10cSrcweir- if((content & XMLSEC_X509DATA_CERTIFICATE_NODE) != 0) { 5011cdf0e10cSrcweir- ret = xmlSecNssX509CertificateNodeWrite(cert, node, keyInfoCtx); 5012cdf0e10cSrcweir- if(ret < 0) { 5013cdf0e10cSrcweir+ /* set base64 lines size from context */ 5014cdf0e10cSrcweir+ buf = xmlSecNssX509CertBase64DerWrite(cert, keyInfoCtx->base64LineSize); 5015cdf0e10cSrcweir+ if(buf == NULL) { 5016cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5017cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5018cdf0e10cSrcweir- "xmlSecNssX509CertificateNodeWrite", 5019cdf0e10cSrcweir+ "xmlSecNssX509CertBase64DerWrite", 5020cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 5021cdf0e10cSrcweir- "pos=%d", pos); 5022cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 5023cdf0e10cSrcweir return(-1); 5024cdf0e10cSrcweir- } 5025cdf0e10cSrcweir } 5026cdf0e10cSrcweir 5027cdf0e10cSrcweir- if((content & XMLSEC_X509DATA_SUBJECTNAME_NODE) != 0) { 5028cdf0e10cSrcweir- ret = xmlSecNssX509SubjectNameNodeWrite(cert, node, keyInfoCtx); 5029cdf0e10cSrcweir- if(ret < 0) { 5030cdf0e10cSrcweir+ cur = xmlSecAddChild(node, xmlSecNodeX509Certificate, xmlSecDSigNs); 5031cdf0e10cSrcweir+ if(cur == NULL) { 5032cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5033cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5034cdf0e10cSrcweir- "xmlSecNssX509SubjectNameNodeWrite", 5035cdf0e10cSrcweir+ "xmlSecAddChild", 5036cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 5037cdf0e10cSrcweir- "pos=%d", pos); 5038cdf0e10cSrcweir+ "node=%s", 5039cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecNodeX509Certificate)); 5040cdf0e10cSrcweir+ xmlFree(buf); 5041cdf0e10cSrcweir return(-1); 5042cdf0e10cSrcweir- } 5043cdf0e10cSrcweir } 5044cdf0e10cSrcweir+ /* todo: add \n around base64 data - from context */ 5045cdf0e10cSrcweir+ /* todo: add errors check */ 5046cdf0e10cSrcweir+ xmlNodeSetContent(cur, xmlSecStringCR); 5047cdf0e10cSrcweir+ xmlNodeSetContent(cur, buf); 5048cdf0e10cSrcweir+ xmlFree(buf); 5049cdf0e10cSrcweir+ } 5050cdf0e10cSrcweir 5051cdf0e10cSrcweir- if((content & XMLSEC_X509DATA_ISSUERSERIAL_NODE) != 0) { 5052cdf0e10cSrcweir- ret = xmlSecNssX509IssuerSerialNodeWrite(cert, node, keyInfoCtx); 5053cdf0e10cSrcweir- if(ret < 0) { 5054cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5055cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5056cdf0e10cSrcweir- "xmlSecNssX509IssuerSerialNodeWrite", 5057cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5058cdf0e10cSrcweir- "pos=%d", pos); 5059cdf0e10cSrcweir- return(-1); 5060cdf0e10cSrcweir- } 5061cdf0e10cSrcweir+ /* write crls */ 5062cdf0e10cSrcweir+ size = xmlSecNssKeyDataX509GetCrlsSize(data); 5063cdf0e10cSrcweir+ for(pos = 0; pos < size; ++pos) { 5064cdf0e10cSrcweir+ crl = xmlSecNssKeyDataX509GetCrl(data, pos); 5065cdf0e10cSrcweir+ if(crl == NULL) { 5066cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 5067cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5068cdf0e10cSrcweir+ "xmlSecNssKeyDataX509GetCrl", 5069cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 5070cdf0e10cSrcweir+ "pos=%d", pos); 5071cdf0e10cSrcweir+ return(-1); 5072cdf0e10cSrcweir } 5073cdf0e10cSrcweir 5074cdf0e10cSrcweir- if((content & XMLSEC_X509DATA_SKI_NODE) != 0) { 5075cdf0e10cSrcweir- ret = xmlSecNssX509SKINodeWrite(cert, node, keyInfoCtx); 5076cdf0e10cSrcweir- if(ret < 0) { 5077cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5078cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5079cdf0e10cSrcweir- "xmlSecNssX509SKINodeWrite", 5080cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5081cdf0e10cSrcweir- "pos=%d", pos); 5082cdf0e10cSrcweir- return(-1); 5083cdf0e10cSrcweir- } 5084cdf0e10cSrcweir+ /* set base64 lines size from context */ 5085cdf0e10cSrcweir+ buf = xmlSecNssX509CrlBase64DerWrite(crl, keyInfoCtx->base64LineSize); 5086cdf0e10cSrcweir+ if(buf == NULL) { 5087cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 5088cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5089cdf0e10cSrcweir+ "xmlSecNssX509CrlBase64DerWrite", 5090cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 5091cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 5092cdf0e10cSrcweir+ return(-1); 5093cdf0e10cSrcweir } 5094cdf0e10cSrcweir- } 5095cdf0e10cSrcweir 5096cdf0e10cSrcweir- /* write crls if needed */ 5097cdf0e10cSrcweir- if((content & XMLSEC_X509DATA_CRL_NODE) != 0) { 5098cdf0e10cSrcweir- size = xmlSecNssKeyDataX509GetCrlsSize(data); 5099cdf0e10cSrcweir- for(pos = 0; pos < size; ++pos) { 5100cdf0e10cSrcweir- crl = xmlSecNssKeyDataX509GetCrl(data, pos); 5101cdf0e10cSrcweir- if(crl == NULL) { 5102cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5103cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5104cdf0e10cSrcweir- "xmlSecNssKeyDataX509GetCrl", 5105cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5106cdf0e10cSrcweir- "pos=%d", pos); 5107cdf0e10cSrcweir- return(-1); 5108cdf0e10cSrcweir- } 5109cdf0e10cSrcweir- 5110cdf0e10cSrcweir- ret = xmlSecNssX509CRLNodeWrite(crl, node, keyInfoCtx); 5111cdf0e10cSrcweir- if(ret < 0) { 5112cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5113cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5114cdf0e10cSrcweir- "xmlSecNssX509CRLNodeWrite", 5115cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5116cdf0e10cSrcweir- "pos=%d", pos); 5117cdf0e10cSrcweir- return(-1); 5118cdf0e10cSrcweir- } 5119cdf0e10cSrcweir- } 5120cdf0e10cSrcweir+ cur = xmlSecAddChild(node, xmlSecNodeX509CRL, xmlSecDSigNs); 5121cdf0e10cSrcweir+ if(cur == NULL) { 5122cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 5123cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), 5124cdf0e10cSrcweir+ "xmlSecAddChild", 5125cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 5126cdf0e10cSrcweir+ "new_node=%s", 5127cdf0e10cSrcweir+ xmlSecErrorsSafeString(xmlSecNodeX509CRL)); 5128cdf0e10cSrcweir+ xmlFree(buf); 5129cdf0e10cSrcweir+ return(-1); 5130cdf0e10cSrcweir+ } 5131cdf0e10cSrcweir+ /* todo: add \n around base64 data - from context */ 5132cdf0e10cSrcweir+ /* todo: add errors check */ 5133cdf0e10cSrcweir+ xmlNodeSetContent(cur, xmlSecStringCR); 5134cdf0e10cSrcweir+ xmlNodeSetContent(cur, buf); 5135cdf0e10cSrcweir } 5136cdf0e10cSrcweir 5137cdf0e10cSrcweir return(0); 5138cdf0e10cSrcweir@@ -1057,46 +1024,6 @@ 5139cdf0e10cSrcweir return(0); 5140cdf0e10cSrcweir } 5141cdf0e10cSrcweir 5142cdf0e10cSrcweir-static int 5143cdf0e10cSrcweir-xmlSecNssX509CertificateNodeWrite(CERTCertificate* cert, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 5144cdf0e10cSrcweir- xmlChar* buf; 5145cdf0e10cSrcweir- xmlNodePtr cur; 5146cdf0e10cSrcweir- 5147cdf0e10cSrcweir- xmlSecAssert2(cert != NULL, -1); 5148cdf0e10cSrcweir- xmlSecAssert2(node != NULL, -1); 5149cdf0e10cSrcweir- xmlSecAssert2(keyInfoCtx != NULL, -1); 5150cdf0e10cSrcweir- 5151cdf0e10cSrcweir- /* set base64 lines size from context */ 5152cdf0e10cSrcweir- buf = xmlSecNssX509CertBase64DerWrite(cert, keyInfoCtx->base64LineSize); 5153cdf0e10cSrcweir- if(buf == NULL) { 5154cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5155cdf0e10cSrcweir- NULL, 5156cdf0e10cSrcweir- "xmlSecNssX509CertBase64DerWrite", 5157cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5158cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5159cdf0e10cSrcweir- return(-1); 5160cdf0e10cSrcweir- } 5161cdf0e10cSrcweir- 5162cdf0e10cSrcweir- cur = xmlSecAddChild(node, xmlSecNodeX509Certificate, xmlSecDSigNs); 5163cdf0e10cSrcweir- if(cur == NULL) { 5164cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5165cdf0e10cSrcweir- NULL, 5166cdf0e10cSrcweir- "xmlSecAddChild", 5167cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5168cdf0e10cSrcweir- "node=%s", 5169cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509Certificate)); 5170cdf0e10cSrcweir- xmlFree(buf); 5171cdf0e10cSrcweir- return(-1); 5172cdf0e10cSrcweir- } 5173cdf0e10cSrcweir- 5174cdf0e10cSrcweir- /* todo: add \n around base64 data - from context */ 5175cdf0e10cSrcweir- /* todo: add errors check */ 5176cdf0e10cSrcweir- xmlNodeSetContent(cur, xmlSecStringCR); 5177cdf0e10cSrcweir- xmlNodeSetContent(cur, buf); 5178cdf0e10cSrcweir- xmlFree(buf); 5179cdf0e10cSrcweir- return(0); 5180cdf0e10cSrcweir-} 5181cdf0e10cSrcweir- 5182cdf0e10cSrcweir static int 5183cdf0e10cSrcweir xmlSecNssX509SubjectNameNodeRead(xmlSecKeyDataPtr data, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 5184cdf0e10cSrcweir xmlSecKeyDataStorePtr x509Store; 5185cdf0e10cSrcweir@@ -1120,19 +1047,13 @@ 5186cdf0e10cSrcweir } 5187cdf0e10cSrcweir 5188cdf0e10cSrcweir subject = xmlNodeGetContent(node); 5189cdf0e10cSrcweir- if((subject == NULL) || (xmlSecIsEmptyString(subject) == 1)) { 5190cdf0e10cSrcweir- if(subject != NULL) { 5191cdf0e10cSrcweir- xmlFree(subject); 5192cdf0e10cSrcweir- } 5193cdf0e10cSrcweir- if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_STOP_ON_EMPTY_NODE) != 0) { 5194cdf0e10cSrcweir+ if(subject == NULL) { 5195cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5196cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 5197cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecNodeGetName(node)), 5198cdf0e10cSrcweir XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, 5199cdf0e10cSrcweir XMLSEC_ERRORS_NO_MESSAGE); 5200cdf0e10cSrcweir return(-1); 5201cdf0e10cSrcweir- } 5202cdf0e10cSrcweir- return(0); 5203cdf0e10cSrcweir } 5204cdf0e10cSrcweir 5205cdf0e10cSrcweir cert = xmlSecNssX509StoreFindCert(x509Store, subject, NULL, NULL, NULL, keyInfoCtx); 5206cdf0e10cSrcweir@@ -1169,40 +1090,6 @@ 5207cdf0e10cSrcweir return(0); 5208cdf0e10cSrcweir } 5209cdf0e10cSrcweir 5210cdf0e10cSrcweir-static int 5211cdf0e10cSrcweir-xmlSecNssX509SubjectNameNodeWrite(CERTCertificate* cert, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx ATTRIBUTE_UNUSED) { 5212cdf0e10cSrcweir- xmlChar* buf = NULL; 5213cdf0e10cSrcweir- xmlNodePtr cur = NULL; 5214cdf0e10cSrcweir- 5215cdf0e10cSrcweir- xmlSecAssert2(cert != NULL, -1); 5216cdf0e10cSrcweir- xmlSecAssert2(node != NULL, -1); 5217cdf0e10cSrcweir- 5218cdf0e10cSrcweir- buf = xmlSecNssX509NameWrite(&(cert->subject)); 5219cdf0e10cSrcweir- if(buf == NULL) { 5220cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5221cdf0e10cSrcweir- NULL, 5222cdf0e10cSrcweir- "xmlSecNssX509NameWrite(&(cert->subject))", 5223cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5224cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5225cdf0e10cSrcweir- return(-1); 5226cdf0e10cSrcweir- } 5227cdf0e10cSrcweir- 5228cdf0e10cSrcweir- cur = xmlSecAddChild(node, xmlSecNodeX509SubjectName, xmlSecDSigNs); 5229cdf0e10cSrcweir- if(cur == NULL) { 5230cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5231cdf0e10cSrcweir- NULL, 5232cdf0e10cSrcweir- "xmlSecAddChild", 5233cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5234cdf0e10cSrcweir- "node=%s", 5235cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509SubjectName)); 5236cdf0e10cSrcweir- xmlFree(buf); 5237cdf0e10cSrcweir- return(-1); 5238cdf0e10cSrcweir- } 5239cdf0e10cSrcweir- xmlSecNodeEncodeAndSetContent(cur, buf); 5240cdf0e10cSrcweir- xmlFree(buf); 5241cdf0e10cSrcweir- return(0); 5242cdf0e10cSrcweir-} 5243cdf0e10cSrcweir- 5244cdf0e10cSrcweir static int 5245cdf0e10cSrcweir xmlSecNssX509IssuerSerialNodeRead(xmlSecKeyDataPtr data, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 5246cdf0e10cSrcweir xmlSecKeyDataStorePtr x509Store; 5247cdf0e10cSrcweir@@ -1228,21 +1115,9 @@ 5248cdf0e10cSrcweir } 5249cdf0e10cSrcweir 5250cdf0e10cSrcweir cur = xmlSecGetNextElementNode(node->children); 5251cdf0e10cSrcweir- if(cur == NULL) { 5252cdf0e10cSrcweir- if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_STOP_ON_EMPTY_NODE) != 0) { 5253cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5254cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 5255cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509IssuerName), 5256cdf0e10cSrcweir- XMLSEC_ERRORS_R_NODE_NOT_FOUND, 5257cdf0e10cSrcweir- "node=%s", 5258cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeGetName(cur))); 5259cdf0e10cSrcweir- return(-1); 5260cdf0e10cSrcweir- } 5261cdf0e10cSrcweir- return(0); 5262cdf0e10cSrcweir- } 5263cdf0e10cSrcweir 5264cdf0e10cSrcweir /* the first is required node X509IssuerName */ 5265cdf0e10cSrcweir- if(!xmlSecCheckNodeName(cur, xmlSecNodeX509IssuerName, xmlSecDSigNs)) { 5266cdf0e10cSrcweir+ if((cur == NULL) || !xmlSecCheckNodeName(cur, xmlSecNodeX509IssuerName, xmlSecDSigNs)) { 5267cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5268cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 5269cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecNodeX509IssuerName), 5270cdf0e10cSrcweir@@ -1336,78 +1211,6 @@ 5271cdf0e10cSrcweir return(0); 5272cdf0e10cSrcweir } 5273cdf0e10cSrcweir 5274cdf0e10cSrcweir-static int 5275cdf0e10cSrcweir-xmlSecNssX509IssuerSerialNodeWrite(CERTCertificate* cert, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx ATTRIBUTE_UNUSED) { 5276cdf0e10cSrcweir- xmlNodePtr cur; 5277cdf0e10cSrcweir- xmlNodePtr issuerNameNode; 5278cdf0e10cSrcweir- xmlNodePtr issuerNumberNode; 5279cdf0e10cSrcweir- xmlChar* buf; 5280cdf0e10cSrcweir- 5281cdf0e10cSrcweir- xmlSecAssert2(cert != NULL, -1); 5282cdf0e10cSrcweir- xmlSecAssert2(node != NULL, -1); 5283cdf0e10cSrcweir- 5284cdf0e10cSrcweir- /* create xml nodes */ 5285cdf0e10cSrcweir- cur = xmlSecAddChild(node, xmlSecNodeX509IssuerSerial, xmlSecDSigNs); 5286cdf0e10cSrcweir- if(cur == NULL) { 5287cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5288cdf0e10cSrcweir- NULL, 5289cdf0e10cSrcweir- "xmlSecAddChild", 5290cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5291cdf0e10cSrcweir- "node=%s", 5292cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509IssuerSerial)); 5293cdf0e10cSrcweir- return(-1); 5294cdf0e10cSrcweir- } 5295cdf0e10cSrcweir- 5296cdf0e10cSrcweir- issuerNameNode = xmlSecAddChild(cur, xmlSecNodeX509IssuerName, xmlSecDSigNs); 5297cdf0e10cSrcweir- if(issuerNameNode == NULL) { 5298cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5299cdf0e10cSrcweir- NULL, 5300cdf0e10cSrcweir- "xmlSecAddChild", 5301cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5302cdf0e10cSrcweir- "node=%s", 5303cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509IssuerName)); 5304cdf0e10cSrcweir- return(-1); 5305cdf0e10cSrcweir- } 5306cdf0e10cSrcweir- 5307cdf0e10cSrcweir- issuerNumberNode = xmlSecAddChild(cur, xmlSecNodeX509SerialNumber, xmlSecDSigNs); 5308cdf0e10cSrcweir- if(issuerNumberNode == NULL) { 5309cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5310cdf0e10cSrcweir- NULL, 5311cdf0e10cSrcweir- "xmlSecAddChild", 5312cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5313cdf0e10cSrcweir- "node=%s", 5314cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509SerialNumber)); 5315cdf0e10cSrcweir- return(-1); 5316cdf0e10cSrcweir- } 5317cdf0e10cSrcweir- 5318cdf0e10cSrcweir- /* write data */ 5319cdf0e10cSrcweir- buf = xmlSecNssX509NameWrite(&(cert->issuer)); 5320cdf0e10cSrcweir- if(buf == NULL) { 5321cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5322cdf0e10cSrcweir- NULL, 5323cdf0e10cSrcweir- "xmlSecNssX509NameWrite(&(cert->issuer))", 5324cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5325cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5326cdf0e10cSrcweir- return(-1); 5327cdf0e10cSrcweir- } 5328cdf0e10cSrcweir- xmlSecNodeEncodeAndSetContent(issuerNameNode, buf); 5329cdf0e10cSrcweir- xmlFree(buf); 5330cdf0e10cSrcweir- 5331cdf0e10cSrcweir- buf = xmlSecNssASN1IntegerWrite(&(cert->serialNumber)); 5332cdf0e10cSrcweir- if(buf == NULL) { 5333cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5334cdf0e10cSrcweir- NULL, 5335cdf0e10cSrcweir- "xmlSecNssASN1IntegerWrite(&(cert->serialNumber))", 5336cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5337cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5338cdf0e10cSrcweir- return(-1); 5339cdf0e10cSrcweir- } 5340cdf0e10cSrcweir- xmlNodeSetContent(issuerNumberNode, buf); 5341cdf0e10cSrcweir- xmlFree(buf); 5342cdf0e10cSrcweir- 5343cdf0e10cSrcweir- return(0); 5344cdf0e10cSrcweir-} 5345cdf0e10cSrcweir- 5346cdf0e10cSrcweir static int 5347cdf0e10cSrcweir xmlSecNssX509SKINodeRead(xmlSecKeyDataPtr data, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 5348cdf0e10cSrcweir xmlSecKeyDataStorePtr x509Store; 5349cdf0e10cSrcweir@@ -1431,11 +1234,7 @@ 5350cdf0e10cSrcweir } 5351cdf0e10cSrcweir 5352cdf0e10cSrcweir ski = xmlNodeGetContent(node); 5353cdf0e10cSrcweir- if((ski == NULL) || (xmlSecIsEmptyString(ski) == 1)) { 5354cdf0e10cSrcweir- if(ski != NULL) { 5355cdf0e10cSrcweir- xmlFree(ski); 5356cdf0e10cSrcweir- } 5357cdf0e10cSrcweir- if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_STOP_ON_EMPTY_NODE) != 0) { 5358cdf0e10cSrcweir+ if(ski == NULL) { 5359cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5360cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 5361cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecNodeGetName(node)), 5362cdf0e10cSrcweir@@ -1443,8 +1242,6 @@ 5363cdf0e10cSrcweir "node=%s", 5364cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecNodeX509SKI)); 5365cdf0e10cSrcweir return(-1); 5366cdf0e10cSrcweir- } 5367cdf0e10cSrcweir- return(0); 5368cdf0e10cSrcweir } 5369cdf0e10cSrcweir 5370cdf0e10cSrcweir cert = xmlSecNssX509StoreFindCert(x509Store, NULL, NULL, NULL, ski, keyInfoCtx); 5371cdf0e10cSrcweir@@ -1479,41 +1276,6 @@ 5372cdf0e10cSrcweir return(0); 5373cdf0e10cSrcweir } 5374cdf0e10cSrcweir 5375cdf0e10cSrcweir-static int 5376cdf0e10cSrcweir-xmlSecNssX509SKINodeWrite(CERTCertificate* cert, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx ATTRIBUTE_UNUSED) { 5377cdf0e10cSrcweir- xmlChar *buf = NULL; 5378cdf0e10cSrcweir- xmlNodePtr cur = NULL; 5379cdf0e10cSrcweir- 5380cdf0e10cSrcweir- xmlSecAssert2(cert != NULL, -1); 5381cdf0e10cSrcweir- xmlSecAssert2(node != NULL, -1); 5382cdf0e10cSrcweir- 5383cdf0e10cSrcweir- buf = xmlSecNssX509SKIWrite(cert); 5384cdf0e10cSrcweir- if(buf == NULL) { 5385cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5386cdf0e10cSrcweir- NULL, 5387cdf0e10cSrcweir- "xmlSecNssX509SKIWrite", 5388cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5389cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5390cdf0e10cSrcweir- return(-1); 5391cdf0e10cSrcweir- } 5392cdf0e10cSrcweir- 5393cdf0e10cSrcweir- cur = xmlSecAddChild(node, xmlSecNodeX509SKI, xmlSecDSigNs); 5394cdf0e10cSrcweir- if(cur == NULL) { 5395cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5396cdf0e10cSrcweir- NULL, 5397cdf0e10cSrcweir- "xmlSecAddChild", 5398cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5399cdf0e10cSrcweir- "new_node=%s", 5400cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509SKI)); 5401cdf0e10cSrcweir- xmlFree(buf); 5402cdf0e10cSrcweir- return(-1); 5403cdf0e10cSrcweir- } 5404cdf0e10cSrcweir- xmlSecNodeEncodeAndSetContent(cur, buf); 5405cdf0e10cSrcweir- xmlFree(buf); 5406cdf0e10cSrcweir- 5407cdf0e10cSrcweir- return(0); 5408cdf0e10cSrcweir-} 5409cdf0e10cSrcweir- 5410cdf0e10cSrcweir static int 5411cdf0e10cSrcweir xmlSecNssX509CRLNodeRead(xmlSecKeyDataPtr data, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 5412cdf0e10cSrcweir xmlChar *content; 5413cdf0e10cSrcweir@@ -1524,19 +1286,13 @@ 5414cdf0e10cSrcweir xmlSecAssert2(keyInfoCtx != NULL, -1); 5415cdf0e10cSrcweir 5416cdf0e10cSrcweir content = xmlNodeGetContent(node); 5417cdf0e10cSrcweir- if((content == NULL) || (xmlSecIsEmptyString(content) == 1)) { 5418cdf0e10cSrcweir- if(content != NULL) { 5419cdf0e10cSrcweir- xmlFree(content); 5420cdf0e10cSrcweir- } 5421cdf0e10cSrcweir- if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_STOP_ON_EMPTY_NODE) != 0) { 5422cdf0e10cSrcweir+ if(content == NULL){ 5423cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5424cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 5425cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecNodeGetName(node)), 5426cdf0e10cSrcweir XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, 5427cdf0e10cSrcweir XMLSEC_ERRORS_NO_MESSAGE); 5428cdf0e10cSrcweir return(-1); 5429cdf0e10cSrcweir- } 5430cdf0e10cSrcweir- return(0); 5431cdf0e10cSrcweir } 5432cdf0e10cSrcweir 5433cdf0e10cSrcweir crl = xmlSecNssX509CrlBase64DerRead(content, keyInfoCtx); 5434cdf0e10cSrcweir@@ -1556,47 +1312,6 @@ 5435cdf0e10cSrcweir } 5436cdf0e10cSrcweir 5437cdf0e10cSrcweir static int 5438cdf0e10cSrcweir-xmlSecNssX509CRLNodeWrite(CERTSignedCrl* crl, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { 5439cdf0e10cSrcweir- xmlChar* buf = NULL; 5440cdf0e10cSrcweir- xmlNodePtr cur = NULL; 5441cdf0e10cSrcweir- 5442cdf0e10cSrcweir- xmlSecAssert2(crl != NULL, -1); 5443cdf0e10cSrcweir- xmlSecAssert2(node != NULL, -1); 5444cdf0e10cSrcweir- xmlSecAssert2(keyInfoCtx != NULL, -1); 5445cdf0e10cSrcweir- 5446cdf0e10cSrcweir- /* set base64 lines size from context */ 5447cdf0e10cSrcweir- buf = xmlSecNssX509CrlBase64DerWrite(crl, keyInfoCtx->base64LineSize); 5448cdf0e10cSrcweir- if(buf == NULL) { 5449cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5450cdf0e10cSrcweir- NULL, 5451cdf0e10cSrcweir- "xmlSecNssX509CrlBase64DerWrite", 5452cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5453cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5454cdf0e10cSrcweir- return(-1); 5455cdf0e10cSrcweir- } 5456cdf0e10cSrcweir- 5457cdf0e10cSrcweir- cur = xmlSecAddChild(node, xmlSecNodeX509CRL, xmlSecDSigNs); 5458cdf0e10cSrcweir- if(cur == NULL) { 5459cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5460cdf0e10cSrcweir- NULL, 5461cdf0e10cSrcweir- "xmlSecAddChild", 5462cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5463cdf0e10cSrcweir- "new_node=%s", 5464cdf0e10cSrcweir- xmlSecErrorsSafeString(xmlSecNodeX509CRL)); 5465cdf0e10cSrcweir- xmlFree(buf); 5466cdf0e10cSrcweir- return(-1); 5467cdf0e10cSrcweir- } 5468cdf0e10cSrcweir- /* todo: add \n around base64 data - from context */ 5469cdf0e10cSrcweir- /* todo: add errors check */ 5470cdf0e10cSrcweir- xmlNodeSetContent(cur, xmlSecStringCR); 5471cdf0e10cSrcweir- xmlNodeSetContent(cur, buf); 5472cdf0e10cSrcweir- xmlFree(buf); 5473cdf0e10cSrcweir- 5474cdf0e10cSrcweir- return(0); 5475cdf0e10cSrcweir-} 5476cdf0e10cSrcweir- 5477cdf0e10cSrcweir- 5478cdf0e10cSrcweir-static int 5479cdf0e10cSrcweir xmlSecNssKeyDataX509VerifyAndExtractKey(xmlSecKeyDataPtr data, xmlSecKeyPtr key, 5480cdf0e10cSrcweir xmlSecKeyInfoCtxPtr keyInfoCtx) { 5481cdf0e10cSrcweir xmlSecNssX509DataCtxPtr ctx; 5482cdf0e10cSrcweir@@ -1604,6 +1319,10 @@ 5483cdf0e10cSrcweir int ret; 5484cdf0e10cSrcweir SECStatus status; 5485cdf0e10cSrcweir PRTime notBefore, notAfter; 5486cdf0e10cSrcweir+ 5487cdf0e10cSrcweir+ PK11SlotInfo* slot ; 5488cdf0e10cSrcweir+ SECKEYPublicKey *pubKey = NULL; 5489cdf0e10cSrcweir+ SECKEYPrivateKey *priKey = NULL; 5490cdf0e10cSrcweir 5491cdf0e10cSrcweir xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataX509Id), -1); 5492cdf0e10cSrcweir xmlSecAssert2(key != NULL, -1); 5493cdf0e10cSrcweir@@ -1636,10 +1355,14 @@ 5494cdf0e10cSrcweir xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), 5495cdf0e10cSrcweir "CERT_DupCertificate", 5496cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 5497cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5498cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 5499cdf0e10cSrcweir return(-1); 5500cdf0e10cSrcweir } 5501cdf0e10cSrcweir- 5502cdf0e10cSrcweir+ 5503cdf0e10cSrcweir+ /*- 5504cdf0e10cSrcweir+ * Get Public key from cert, which does not always work for sign 5505cdf0e10cSrcweir+ * action. 5506cdf0e10cSrcweir+ * 5507cdf0e10cSrcweir keyValue = xmlSecNssX509CertGetKey(ctx->keyCert); 5508cdf0e10cSrcweir if(keyValue == NULL) { 5509cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5510cdf0e10cSrcweir@@ -1649,6 +1372,54 @@ 5511cdf0e10cSrcweir XMLSEC_ERRORS_NO_MESSAGE); 5512cdf0e10cSrcweir return(-1); 5513cdf0e10cSrcweir } 5514cdf0e10cSrcweir+ */ 5515cdf0e10cSrcweir+ /*- 5516cdf0e10cSrcweir+ * I'll search key according to KeyReq. 5517cdf0e10cSrcweir+ */ 5518cdf0e10cSrcweir+ slot = cert->slot ; 5519cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyType & xmlSecKeyDataTypePrivate ) == xmlSecKeyDataTypePrivate ) { 5520cdf0e10cSrcweir+ if( ( priKey = PK11_FindPrivateKeyFromCert( slot , cert , NULL ) ) == NULL ) { 5521cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 5522cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 5523cdf0e10cSrcweir+ "PK11_FindPrivateKeyFromCert" , 5524cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 5525cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 5526cdf0e10cSrcweir+ return -1 ; 5527cdf0e10cSrcweir+ } 5528cdf0e10cSrcweir+ } 5529cdf0e10cSrcweir+ 5530cdf0e10cSrcweir+ if( ( keyInfoCtx->keyReq.keyType & xmlSecKeyDataTypePublic ) == xmlSecKeyDataTypePublic ) { 5531cdf0e10cSrcweir+ if( ( pubKey = CERT_ExtractPublicKey( cert ) ) == NULL ) { 5532cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 5533cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 5534cdf0e10cSrcweir+ "CERT_ExtractPublicKey" , 5535cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 5536cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 5537cdf0e10cSrcweir+ 5538cdf0e10cSrcweir+ 5539cdf0e10cSrcweir+ if( priKey != NULL ) 5540cdf0e10cSrcweir+ SECKEY_DestroyPrivateKey( priKey ) ; 5541cdf0e10cSrcweir+ return -1 ; 5542cdf0e10cSrcweir+ } 5543cdf0e10cSrcweir+ } 5544cdf0e10cSrcweir+ 5545cdf0e10cSrcweir+ keyValue = xmlSecNssPKIAdoptKey(priKey, pubKey); 5546cdf0e10cSrcweir+ if( keyValue == NULL ) { 5547cdf0e10cSrcweir+ xmlSecError( XMLSEC_ERRORS_HERE , 5548cdf0e10cSrcweir+ xmlSecErrorsSafeString( xmlSecKeyDataGetName( data ) ) , 5549cdf0e10cSrcweir+ "xmlSecNssPKIAdoptKey" , 5550cdf0e10cSrcweir+ XMLSEC_ERRORS_R_CRYPTO_FAILED , 5551cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 5552cdf0e10cSrcweir+ 5553cdf0e10cSrcweir+ if( priKey != NULL ) 5554cdf0e10cSrcweir+ SECKEY_DestroyPrivateKey( priKey ) ; 5555cdf0e10cSrcweir+ 5556cdf0e10cSrcweir+ if( pubKey != NULL ) 5557cdf0e10cSrcweir+ SECKEY_DestroyPublicKey( pubKey ) ; 5558cdf0e10cSrcweir+ 5559cdf0e10cSrcweir+ return -1 ; 5560cdf0e10cSrcweir+ } 5561cdf0e10cSrcweir+ /* Modify keyValue get Done */ 5562cdf0e10cSrcweir 5563cdf0e10cSrcweir /* verify that the key matches our expectations */ 5564cdf0e10cSrcweir if(xmlSecKeyReqMatchKeyValue(&(keyInfoCtx->keyReq), keyValue) != 1) { 5565cdf0e10cSrcweir@@ -1950,86 +1721,6 @@ 5566cdf0e10cSrcweir return(res); 5567cdf0e10cSrcweir } 5568cdf0e10cSrcweir 5569cdf0e10cSrcweir-static xmlChar* 5570cdf0e10cSrcweir-xmlSecNssX509NameWrite(CERTName* nm) { 5571cdf0e10cSrcweir- xmlChar *res = NULL; 5572cdf0e10cSrcweir- char *str; 5573cdf0e10cSrcweir- 5574cdf0e10cSrcweir- xmlSecAssert2(nm != NULL, NULL); 5575cdf0e10cSrcweir- 5576cdf0e10cSrcweir- str = CERT_NameToAscii(nm); 5577cdf0e10cSrcweir- if (str == NULL) { 5578cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5579cdf0e10cSrcweir- NULL, 5580cdf0e10cSrcweir- "CERT_NameToAscii", 5581cdf0e10cSrcweir- XMLSEC_ERRORS_R_CRYPTO_FAILED, 5582cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5583cdf0e10cSrcweir- return(NULL); 5584cdf0e10cSrcweir- } 5585cdf0e10cSrcweir- 5586cdf0e10cSrcweir- res = xmlStrdup(BAD_CAST str); 5587cdf0e10cSrcweir- if(res == NULL) { 5588cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5589cdf0e10cSrcweir- NULL, 5590cdf0e10cSrcweir- "xmlStrdup", 5591cdf0e10cSrcweir- XMLSEC_ERRORS_R_MALLOC_FAILED, 5592cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5593cdf0e10cSrcweir- PORT_Free(str); 5594cdf0e10cSrcweir- return(NULL); 5595cdf0e10cSrcweir- } 5596cdf0e10cSrcweir- PORT_Free(str); 5597cdf0e10cSrcweir- return(res); 5598cdf0e10cSrcweir-} 5599cdf0e10cSrcweir- 5600cdf0e10cSrcweir-static xmlChar* 5601cdf0e10cSrcweir-xmlSecNssASN1IntegerWrite(SECItem *num) { 5602cdf0e10cSrcweir- xmlChar *res = NULL; 5603cdf0e10cSrcweir- 5604cdf0e10cSrcweir- xmlSecAssert2(num != NULL, NULL); 5605cdf0e10cSrcweir- 5606cdf0e10cSrcweir- /* TODO : to be implemented after 5607cdf0e10cSrcweir- * NSS bug http://bugzilla.mozilla.org/show_bug.cgi?id=212864 is fixed 5608cdf0e10cSrcweir- */ 5609cdf0e10cSrcweir- return(res); 5610cdf0e10cSrcweir-} 5611cdf0e10cSrcweir- 5612cdf0e10cSrcweir-static xmlChar* 5613cdf0e10cSrcweir-xmlSecNssX509SKIWrite(CERTCertificate* cert) { 5614cdf0e10cSrcweir- xmlChar *res = NULL; 5615cdf0e10cSrcweir- SECItem ski; 5616cdf0e10cSrcweir- SECStatus rv; 5617cdf0e10cSrcweir- 5618cdf0e10cSrcweir- xmlSecAssert2(cert != NULL, NULL); 5619cdf0e10cSrcweir- 5620cdf0e10cSrcweir- memset(&ski, 0, sizeof(ski)); 5621cdf0e10cSrcweir- 5622cdf0e10cSrcweir- rv = CERT_FindSubjectKeyIDExtension(cert, &ski); 5623cdf0e10cSrcweir- if (rv != SECSuccess) { 5624cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5625cdf0e10cSrcweir- NULL, 5626cdf0e10cSrcweir- "CERT_FindSubjectKeyIDExtension", 5627cdf0e10cSrcweir- XMLSEC_ERRORS_R_CRYPTO_FAILED, 5628cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5629cdf0e10cSrcweir- SECITEM_FreeItem(&ski, PR_FALSE); 5630cdf0e10cSrcweir- return(NULL); 5631cdf0e10cSrcweir- } 5632cdf0e10cSrcweir- 5633cdf0e10cSrcweir- res = xmlSecBase64Encode(ski.data, ski.len, 0); 5634cdf0e10cSrcweir- if(res == NULL) { 5635cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5636cdf0e10cSrcweir- NULL, 5637cdf0e10cSrcweir- "xmlSecBase64Encode", 5638cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5639cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5640cdf0e10cSrcweir- SECITEM_FreeItem(&ski, PR_FALSE); 5641cdf0e10cSrcweir- return(NULL); 5642cdf0e10cSrcweir- } 5643cdf0e10cSrcweir- SECITEM_FreeItem(&ski, PR_FALSE); 5644cdf0e10cSrcweir- 5645cdf0e10cSrcweir- return(res); 5646cdf0e10cSrcweir-} 5647cdf0e10cSrcweir- 5648cdf0e10cSrcweir- 5649cdf0e10cSrcweir static void 5650cdf0e10cSrcweir xmlSecNssX509CertDebugDump(CERTCertificate* cert, FILE* output) { 5651cdf0e10cSrcweir SECItem *sn; 5652cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/src/nss/x509vfy.c 2009-06-25 22:53:18.000000000 +0200 5653cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/src/nss/x509vfy.c 2009-09-21 14:02:48.669245207 +0200 5654cdf0e10cSrcweir@@ -30,6 +30,7 @@ 5655cdf0e10cSrcweir #include <xmlsec/keyinfo.h> 5656cdf0e10cSrcweir #include <xmlsec/keysmngr.h> 5657cdf0e10cSrcweir #include <xmlsec/base64.h> 5658cdf0e10cSrcweir+#include <xmlsec/bn.h> 5659cdf0e10cSrcweir #include <xmlsec/errors.h> 5660cdf0e10cSrcweir 5661cdf0e10cSrcweir #include <xmlsec/nss/crypto.h> 5662cdf0e10cSrcweir@@ -61,17 +62,7 @@ 5663cdf0e10cSrcweir 5664cdf0e10cSrcweir static int xmlSecNssX509StoreInitialize (xmlSecKeyDataStorePtr store); 5665cdf0e10cSrcweir static void xmlSecNssX509StoreFinalize (xmlSecKeyDataStorePtr store); 5666cdf0e10cSrcweir-static int xmlSecNssX509NameStringRead (xmlSecByte **str, 5667cdf0e10cSrcweir- int *strLen, 5668cdf0e10cSrcweir- xmlSecByte *res, 5669cdf0e10cSrcweir- int resLen, 5670cdf0e10cSrcweir- xmlSecByte delim, 5671cdf0e10cSrcweir- int ingoreTrailingSpaces); 5672cdf0e10cSrcweir-static xmlSecByte * xmlSecNssX509NameRead (xmlSecByte *str, 5673cdf0e10cSrcweir- int len); 5674cdf0e10cSrcweir- 5675cdf0e10cSrcweir-static void xmlSecNssNumToItem(SECItem *it, unsigned long num); 5676cdf0e10cSrcweir- 5677cdf0e10cSrcweir+static int xmlSecNssIntegerToItem( const xmlChar* integer , SECItem *it ) ; 5678cdf0e10cSrcweir 5679cdf0e10cSrcweir static xmlSecKeyDataStoreKlass xmlSecNssX509StoreKlass = { 5680cdf0e10cSrcweir sizeof(xmlSecKeyDataStoreKlass), 5681cdf0e10cSrcweir@@ -339,40 +330,28 @@ 5682cdf0e10cSrcweir xmlSecNssX509FindCert(xmlChar *subjectName, xmlChar *issuerName, 5683cdf0e10cSrcweir xmlChar *issuerSerial, xmlChar *ski) { 5684cdf0e10cSrcweir CERTCertificate *cert = NULL; 5685cdf0e10cSrcweir- xmlChar *p = NULL; 5686cdf0e10cSrcweir CERTName *name = NULL; 5687cdf0e10cSrcweir SECItem *nameitem = NULL; 5688cdf0e10cSrcweir PRArenaPool *arena = NULL; 5689cdf0e10cSrcweir 5690cdf0e10cSrcweir if (subjectName != NULL) { 5691cdf0e10cSrcweir- p = xmlSecNssX509NameRead(subjectName, xmlStrlen(subjectName)); 5692cdf0e10cSrcweir- if (p == NULL) { 5693cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5694cdf0e10cSrcweir- NULL, 5695cdf0e10cSrcweir- "xmlSecNssX509NameRead", 5696cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5697cdf0e10cSrcweir- "subject=%s", 5698cdf0e10cSrcweir- xmlSecErrorsSafeString(subjectName)); 5699cdf0e10cSrcweir- goto done; 5700cdf0e10cSrcweir- } 5701cdf0e10cSrcweir- 5702cdf0e10cSrcweir arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); 5703cdf0e10cSrcweir if (arena == NULL) { 5704cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5705cdf0e10cSrcweir NULL, 5706cdf0e10cSrcweir "PORT_NewArena", 5707cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 5708cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5709cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 5710cdf0e10cSrcweir goto done; 5711cdf0e10cSrcweir } 5712cdf0e10cSrcweir 5713cdf0e10cSrcweir- name = CERT_AsciiToName((char*)p); 5714cdf0e10cSrcweir+ name = CERT_AsciiToName((char*)subjectName); 5715cdf0e10cSrcweir if (name == NULL) { 5716cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5717cdf0e10cSrcweir NULL, 5718cdf0e10cSrcweir "CERT_AsciiToName", 5719cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 5720cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5721cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 5722cdf0e10cSrcweir goto done; 5723cdf0e10cSrcweir } 5724cdf0e10cSrcweir 5725cdf0e10cSrcweir@@ -394,34 +373,23 @@ 5726cdf0e10cSrcweir if((issuerName != NULL) && (issuerSerial != NULL)) { 5727cdf0e10cSrcweir CERTIssuerAndSN issuerAndSN; 5728cdf0e10cSrcweir 5729cdf0e10cSrcweir- p = xmlSecNssX509NameRead(issuerName, xmlStrlen(issuerName)); 5730cdf0e10cSrcweir- if (p == NULL) { 5731cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5732cdf0e10cSrcweir- NULL, 5733cdf0e10cSrcweir- "xmlSecNssX509NameRead", 5734cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5735cdf0e10cSrcweir- "issuer=%s", 5736cdf0e10cSrcweir- xmlSecErrorsSafeString(issuerName)); 5737cdf0e10cSrcweir- goto done; 5738cdf0e10cSrcweir- } 5739cdf0e10cSrcweir- 5740cdf0e10cSrcweir arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); 5741cdf0e10cSrcweir if (arena == NULL) { 5742cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5743cdf0e10cSrcweir NULL, 5744cdf0e10cSrcweir "PORT_NewArena", 5745cdf0e10cSrcweir XMLSEC_ERRORS_R_CRYPTO_FAILED, 5746cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5747cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 5748cdf0e10cSrcweir goto done; 5749cdf0e10cSrcweir } 5750cdf0e10cSrcweir 5751cdf0e10cSrcweir- name = CERT_AsciiToName((char*)p); 5752cdf0e10cSrcweir+ name = CERT_AsciiToName((char*)issuerName); 5753cdf0e10cSrcweir if (name == NULL) { 5754cdf0e10cSrcweir xmlSecError(XMLSEC_ERRORS_HERE, 5755cdf0e10cSrcweir NULL, 5756cdf0e10cSrcweir "CERT_AsciiToName", 5757cdf0e10cSrcweir XMLSEC_ERRORS_R_XMLSEC_FAILED, 5758cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5759cdf0e10cSrcweir+ "error code=%d", PORT_GetError()); 5760cdf0e10cSrcweir goto done; 5761cdf0e10cSrcweir } 5762cdf0e10cSrcweir 5763cdf0e10cSrcweir@@ -441,8 +409,15 @@ 5764cdf0e10cSrcweir issuerAndSN.derIssuer.data = nameitem->data; 5765cdf0e10cSrcweir issuerAndSN.derIssuer.len = nameitem->len; 5766cdf0e10cSrcweir 5767cdf0e10cSrcweir- /* TBD: serial num can be arbitrarily long */ 5768cdf0e10cSrcweir- xmlSecNssNumToItem(&issuerAndSN.serialNumber, PORT_Atoi((char *)issuerSerial)); 5769cdf0e10cSrcweir+ if( xmlSecNssIntegerToItem( issuerSerial, &issuerAndSN.serialNumber ) < 0 ) { 5770cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 5771cdf0e10cSrcweir+ NULL, 5772cdf0e10cSrcweir+ "xmlSecNssIntegerToItem", 5773cdf0e10cSrcweir+ XMLSEC_ERRORS_R_XMLSEC_FAILED, 5774cdf0e10cSrcweir+ "serial number=%s", 5775cdf0e10cSrcweir+ xmlSecErrorsSafeString(issuerSerial)); 5776cdf0e10cSrcweir+ goto done; 5777cdf0e10cSrcweir+ } 5778cdf0e10cSrcweir 5779cdf0e10cSrcweir cert = CERT_FindCertByIssuerAndSN(CERT_GetDefaultCertDB(), 5780cdf0e10cSrcweir &issuerAndSN); 5781cdf0e10cSrcweir@@ -473,9 +448,6 @@ 5782cdf0e10cSrcweir } 5783cdf0e10cSrcweir 5784cdf0e10cSrcweir done: 5785cdf0e10cSrcweir- if (p != NULL) { 5786cdf0e10cSrcweir- PORT_Free(p); 5787cdf0e10cSrcweir- } 5788cdf0e10cSrcweir if (arena != NULL) { 5789cdf0e10cSrcweir PORT_FreeArena(arena, PR_FALSE); 5790cdf0e10cSrcweir } 5791cdf0e10cSrcweir@@ -486,176 +458,6 @@ 5792cdf0e10cSrcweir return(cert); 5793cdf0e10cSrcweir } 5794cdf0e10cSrcweir 5795cdf0e10cSrcweir-static xmlSecByte * 5796cdf0e10cSrcweir-xmlSecNssX509NameRead(xmlSecByte *str, int len) { 5797cdf0e10cSrcweir- xmlSecByte name[256]; 5798cdf0e10cSrcweir- xmlSecByte value[256]; 5799cdf0e10cSrcweir- xmlSecByte *retval = NULL; 5800cdf0e10cSrcweir- xmlSecByte *p = NULL; 5801cdf0e10cSrcweir- int nameLen, valueLen; 5802cdf0e10cSrcweir- 5803cdf0e10cSrcweir- xmlSecAssert2(str != NULL, NULL); 5804cdf0e10cSrcweir- 5805cdf0e10cSrcweir- /* return string should be no longer than input string */ 5806cdf0e10cSrcweir- retval = (xmlSecByte *)PORT_Alloc(len+1); 5807cdf0e10cSrcweir- if(retval == NULL) { 5808cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5809cdf0e10cSrcweir- NULL, 5810cdf0e10cSrcweir- "PORT_Alloc", 5811cdf0e10cSrcweir- XMLSEC_ERRORS_R_MALLOC_FAILED, 5812cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5813cdf0e10cSrcweir- return(NULL); 5814cdf0e10cSrcweir- } 5815cdf0e10cSrcweir- p = retval; 5816cdf0e10cSrcweir- 5817cdf0e10cSrcweir- while(len > 0) { 5818cdf0e10cSrcweir- /* skip spaces after comma or semicolon */ 5819cdf0e10cSrcweir- while((len > 0) && isspace(*str)) { 5820cdf0e10cSrcweir- ++str; --len; 5821cdf0e10cSrcweir- } 5822cdf0e10cSrcweir- 5823cdf0e10cSrcweir- nameLen = xmlSecNssX509NameStringRead(&str, &len, name, sizeof(name), '=', 0); 5824cdf0e10cSrcweir- if(nameLen < 0) { 5825cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5826cdf0e10cSrcweir- NULL, 5827cdf0e10cSrcweir- "xmlSecNssX509NameStringRead", 5828cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5829cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5830cdf0e10cSrcweir- goto done; 5831cdf0e10cSrcweir- } 5832cdf0e10cSrcweir- memcpy(p, name, nameLen); 5833cdf0e10cSrcweir- p+=nameLen; 5834cdf0e10cSrcweir- *p++='='; 5835cdf0e10cSrcweir- if(len > 0) { 5836cdf0e10cSrcweir- ++str; --len; 5837cdf0e10cSrcweir- if((*str) == '\"') { 5838cdf0e10cSrcweir- valueLen = xmlSecNssX509NameStringRead(&str, &len, 5839cdf0e10cSrcweir- value, sizeof(value), '"', 1); 5840cdf0e10cSrcweir- if(valueLen < 0) { 5841cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5842cdf0e10cSrcweir- NULL, 5843cdf0e10cSrcweir- "xmlSecNssX509NameStringRead", 5844cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5845cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5846cdf0e10cSrcweir- goto done; 5847cdf0e10cSrcweir- } 5848cdf0e10cSrcweir- /* skip spaces before comma or semicolon */ 5849cdf0e10cSrcweir- while((len > 0) && isspace(*str)) { 5850cdf0e10cSrcweir- ++str; --len; 5851cdf0e10cSrcweir- } 5852cdf0e10cSrcweir- if((len > 0) && ((*str) != ',')) { 5853cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5854cdf0e10cSrcweir- NULL, 5855cdf0e10cSrcweir- NULL, 5856cdf0e10cSrcweir- XMLSEC_ERRORS_R_INVALID_DATA, 5857cdf0e10cSrcweir- "comma is expected"); 5858cdf0e10cSrcweir- goto done; 5859cdf0e10cSrcweir- } 5860cdf0e10cSrcweir- if(len > 0) { 5861cdf0e10cSrcweir- ++str; --len; 5862cdf0e10cSrcweir- } 5863cdf0e10cSrcweir- *p++='\"'; 5864cdf0e10cSrcweir- memcpy(p, value, valueLen); 5865cdf0e10cSrcweir- p+=valueLen; 5866cdf0e10cSrcweir- *p++='\"'; 5867cdf0e10cSrcweir- } else if((*str) == '#') { 5868cdf0e10cSrcweir- /* TODO: read octect values */ 5869cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5870cdf0e10cSrcweir- NULL, 5871cdf0e10cSrcweir- NULL, 5872cdf0e10cSrcweir- XMLSEC_ERRORS_R_INVALID_DATA, 5873cdf0e10cSrcweir- "reading octect values is not implemented yet"); 5874cdf0e10cSrcweir- goto done; 5875cdf0e10cSrcweir- } else { 5876cdf0e10cSrcweir- valueLen = xmlSecNssX509NameStringRead(&str, &len, 5877cdf0e10cSrcweir- value, sizeof(value), ',', 1); 5878cdf0e10cSrcweir- if(valueLen < 0) { 5879cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5880cdf0e10cSrcweir- NULL, 5881cdf0e10cSrcweir- "xmlSecNssX509NameStringRead", 5882cdf0e10cSrcweir- XMLSEC_ERRORS_R_XMLSEC_FAILED, 5883cdf0e10cSrcweir- XMLSEC_ERRORS_NO_MESSAGE); 5884cdf0e10cSrcweir- goto done; 5885cdf0e10cSrcweir- } 5886cdf0e10cSrcweir- memcpy(p, value, valueLen); 5887cdf0e10cSrcweir- p+=valueLen; 5888cdf0e10cSrcweir- if (len > 0) 5889cdf0e10cSrcweir- *p++=','; 5890cdf0e10cSrcweir- } 5891cdf0e10cSrcweir- } else { 5892cdf0e10cSrcweir- valueLen = 0; 5893cdf0e10cSrcweir- } 5894cdf0e10cSrcweir- if(len > 0) { 5895cdf0e10cSrcweir- ++str; --len; 5896cdf0e10cSrcweir- } 5897cdf0e10cSrcweir- } 5898cdf0e10cSrcweir- 5899cdf0e10cSrcweir- *p = 0; 5900cdf0e10cSrcweir- return(retval); 5901cdf0e10cSrcweir- 5902cdf0e10cSrcweir-done: 5903cdf0e10cSrcweir- PORT_Free(retval); 5904cdf0e10cSrcweir- return (NULL); 5905cdf0e10cSrcweir-} 5906cdf0e10cSrcweir- 5907cdf0e10cSrcweir-static int 5908cdf0e10cSrcweir-xmlSecNssX509NameStringRead(xmlSecByte **str, int *strLen, 5909cdf0e10cSrcweir- xmlSecByte *res, int resLen, 5910cdf0e10cSrcweir- xmlSecByte delim, int ingoreTrailingSpaces) { 5911cdf0e10cSrcweir- xmlSecByte *p, *q, *nonSpace; 5912cdf0e10cSrcweir- 5913cdf0e10cSrcweir- xmlSecAssert2(str != NULL, -1); 5914cdf0e10cSrcweir- xmlSecAssert2(strLen != NULL, -1); 5915cdf0e10cSrcweir- xmlSecAssert2(res != NULL, -1); 5916cdf0e10cSrcweir- 5917cdf0e10cSrcweir- p = (*str); 5918cdf0e10cSrcweir- nonSpace = q = res; 5919cdf0e10cSrcweir- while(((p - (*str)) < (*strLen)) && ((*p) != delim) && ((q - res) < resLen)) { 5920cdf0e10cSrcweir- if((*p) != '\\') { 5921cdf0e10cSrcweir- if(ingoreTrailingSpaces && !isspace(*p)) { 5922cdf0e10cSrcweir- nonSpace = q; 5923cdf0e10cSrcweir- } 5924cdf0e10cSrcweir- *(q++) = *(p++); 5925cdf0e10cSrcweir- } else { 5926cdf0e10cSrcweir- ++p; 5927cdf0e10cSrcweir- nonSpace = q; 5928cdf0e10cSrcweir- if(xmlSecIsHex((*p))) { 5929cdf0e10cSrcweir- if((p - (*str) + 1) >= (*strLen)) { 5930cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5931cdf0e10cSrcweir- NULL, 5932cdf0e10cSrcweir- NULL, 5933cdf0e10cSrcweir- XMLSEC_ERRORS_R_INVALID_DATA, 5934cdf0e10cSrcweir- "two hex digits expected"); 5935cdf0e10cSrcweir- return(-1); 5936cdf0e10cSrcweir- } 5937cdf0e10cSrcweir- *(q++) = xmlSecGetHex(p[0]) * 16 + xmlSecGetHex(p[1]); 5938cdf0e10cSrcweir- p += 2; 5939cdf0e10cSrcweir- } else { 5940cdf0e10cSrcweir- if(((++p) - (*str)) >= (*strLen)) { 5941cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5942cdf0e10cSrcweir- NULL, 5943cdf0e10cSrcweir- NULL, 5944cdf0e10cSrcweir- XMLSEC_ERRORS_R_INVALID_DATA, 5945cdf0e10cSrcweir- "escaped symbol missed"); 5946cdf0e10cSrcweir- return(-1); 5947cdf0e10cSrcweir- } 5948cdf0e10cSrcweir- *(q++) = *(p++); 5949cdf0e10cSrcweir- } 5950cdf0e10cSrcweir- } 5951cdf0e10cSrcweir- } 5952cdf0e10cSrcweir- if(((p - (*str)) < (*strLen)) && ((*p) != delim)) { 5953cdf0e10cSrcweir- xmlSecError(XMLSEC_ERRORS_HERE, 5954cdf0e10cSrcweir- NULL, 5955cdf0e10cSrcweir- NULL, 5956cdf0e10cSrcweir- XMLSEC_ERRORS_R_INVALID_SIZE, 5957cdf0e10cSrcweir- "buffer is too small"); 5958cdf0e10cSrcweir- return(-1); 5959cdf0e10cSrcweir- } 5960cdf0e10cSrcweir- (*strLen) -= (p - (*str)); 5961cdf0e10cSrcweir- (*str) = p; 5962cdf0e10cSrcweir- return((ingoreTrailingSpaces) ? nonSpace - res + 1 : q - res); 5963cdf0e10cSrcweir-} 5964cdf0e10cSrcweir- 5965cdf0e10cSrcweir /* code lifted from NSS */ 5966cdf0e10cSrcweir static void 5967cdf0e10cSrcweir xmlSecNssNumToItem(SECItem *it, unsigned long ui) 5968cdf0e10cSrcweir@@ -699,6 +501,77 @@ 5969cdf0e10cSrcweir it->len = len; 5970cdf0e10cSrcweir PORT_Memcpy(it->data, bb + (sizeof(bb) - len), len); 5971cdf0e10cSrcweir } 5972cdf0e10cSrcweir+ 5973cdf0e10cSrcweir+static int 5974cdf0e10cSrcweir+xmlSecNssIntegerToItem( 5975cdf0e10cSrcweir+ const xmlChar* integer , 5976cdf0e10cSrcweir+ SECItem *item 5977cdf0e10cSrcweir+) { 5978cdf0e10cSrcweir+ xmlSecBn bn ; 5979cdf0e10cSrcweir+ xmlSecSize i, length ; 5980cdf0e10cSrcweir+ const xmlSecByte* bnInteger ; 5981cdf0e10cSrcweir+ 5982cdf0e10cSrcweir+ xmlSecAssert2( integer != NULL, -1 ) ; 5983cdf0e10cSrcweir+ xmlSecAssert2( item != NULL, -1 ) ; 5984cdf0e10cSrcweir+ 5985cdf0e10cSrcweir+ if( xmlSecBnInitialize( &bn, 0 ) < 0 ) { 5986cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 5987cdf0e10cSrcweir+ NULL, 5988cdf0e10cSrcweir+ "xmlSecBnInitialize", 5989cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_DATA, 5990cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 5991cdf0e10cSrcweir+ return -1 ; 5992cdf0e10cSrcweir+ } 5993cdf0e10cSrcweir+ 5994cdf0e10cSrcweir+ if( xmlSecBnFromDecString( &bn, integer ) < 0 ) { 5995cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 5996cdf0e10cSrcweir+ NULL, 5997cdf0e10cSrcweir+ "xmlSecBnFromDecString", 5998cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_DATA, 5999cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 6000cdf0e10cSrcweir+ xmlSecBnFinalize( &bn ) ; 6001cdf0e10cSrcweir+ return -1 ; 6002cdf0e10cSrcweir+ } 6003cdf0e10cSrcweir+ 6004cdf0e10cSrcweir+ length = xmlSecBnGetSize( &bn ) ; 6005cdf0e10cSrcweir+ if( length <= 0 ) { 6006cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 6007cdf0e10cSrcweir+ NULL, 6008cdf0e10cSrcweir+ "xmlSecBnGetSize", 6009cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_DATA, 6010cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE); 6011cdf0e10cSrcweir+ } 6012cdf0e10cSrcweir+ 6013cdf0e10cSrcweir+ bnInteger = xmlSecBnGetData( &bn ) ; 6014cdf0e10cSrcweir+ if( bnInteger == NULL ) { 6015cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 6016cdf0e10cSrcweir+ NULL, 6017cdf0e10cSrcweir+ "xmlSecBnGetData", 6018cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_DATA, 6019cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 6020cdf0e10cSrcweir+ xmlSecBnFinalize( &bn ) ; 6021cdf0e10cSrcweir+ return -1 ; 6022cdf0e10cSrcweir+ } 6023cdf0e10cSrcweir+ 6024cdf0e10cSrcweir+ item->data = ( unsigned char * )PORT_Alloc( length ); 6025cdf0e10cSrcweir+ if( item->data == NULL ) { 6026cdf0e10cSrcweir+ xmlSecError(XMLSEC_ERRORS_HERE, 6027cdf0e10cSrcweir+ NULL, 6028cdf0e10cSrcweir+ "PORT_Alloc", 6029cdf0e10cSrcweir+ XMLSEC_ERRORS_R_INVALID_DATA, 6030cdf0e10cSrcweir+ XMLSEC_ERRORS_NO_MESSAGE ) ; 6031cdf0e10cSrcweir+ xmlSecBnFinalize( &bn ) ; 6032cdf0e10cSrcweir+ return -1 ; 6033cdf0e10cSrcweir+ } 6034cdf0e10cSrcweir+ 6035cdf0e10cSrcweir+ item->len = length; 6036cdf0e10cSrcweir+ for( i = 0 ; i < length ; i ++ ) 6037cdf0e10cSrcweir+ item->data[i] = *( bnInteger + i ) ; 6038cdf0e10cSrcweir+ 6039cdf0e10cSrcweir+ xmlSecBnFinalize( &bn ) ; 6040cdf0e10cSrcweir+ 6041cdf0e10cSrcweir+ return 0 ; 6042cdf0e10cSrcweir+} 6043cdf0e10cSrcweir #endif /* XMLSEC_NO_X509 */ 6044cdf0e10cSrcweir 6045cdf0e10cSrcweir 6046cdf0e10cSrcweir--- misc/xmlsec1-1.2.14/win32/Makefile.msvc 2009-06-25 22:53:18.000000000 +0200 6047cdf0e10cSrcweir+++ misc/build/xmlsec1-1.2.14/win32/Makefile.msvc 2009-09-21 14:02:48.607277908 +0200 6048cdf0e10cSrcweir@@ -218,6 +218,9 @@ 6049cdf0e10cSrcweir $(XMLSEC_OPENSSL_INTDIR_A)\x509vfy.obj 6050cdf0e10cSrcweir 6051cdf0e10cSrcweir XMLSEC_NSS_OBJS = \ 6052cdf0e10cSrcweir+ $(XMLSEC_NSS_INTDIR)\akmngr.obj\ 6053cdf0e10cSrcweir+ $(XMLSEC_NSS_INTDIR)\keywrapers.obj\ 6054cdf0e10cSrcweir+ $(XMLSEC_NSS_INTDIR)\tokens.obj\ 6055cdf0e10cSrcweir $(XMLSEC_NSS_INTDIR)\app.obj\ 6056cdf0e10cSrcweir $(XMLSEC_NSS_INTDIR)\bignum.obj\ 6057cdf0e10cSrcweir $(XMLSEC_NSS_INTDIR)\ciphers.obj \ 6058cdf0e10cSrcweir@@ -253,6 +256,7 @@ 6059cdf0e10cSrcweir $(XMLSEC_NSS_INTDIR_A)\strings.obj 6060cdf0e10cSrcweir 6061cdf0e10cSrcweir XMLSEC_MSCRYPTO_OBJS = \ 6062cdf0e10cSrcweir+ $(XMLSEC_MSCRYPTO_INTDIR)\akmngr.obj\ 6063cdf0e10cSrcweir $(XMLSEC_MSCRYPTO_INTDIR)\app.obj\ 6064cdf0e10cSrcweir $(XMLSEC_MSCRYPTO_INTDIR)\crypto.obj \ 6065cdf0e10cSrcweir $(XMLSEC_MSCRYPTO_INTDIR)\ciphers.obj \ 6066