From 546af162c1ad036aafc4c495aff8a895d94700b1 Mon Sep 17 00:00:00 2001 From: alee Date: Thu, 18 Jun 2009 15:29:36 +0000 Subject: Bugzilla Bug 500698 - TPS/CA/TKS : segmentation fault after many(30000) enrollments git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@626 c9f7a03b-bd48-0410-a16d-cbbf54688b0b --- pki/base/symkey/src/com/netscape/symkey/SymKey.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'pki/base/symkey/src/com/netscape') diff --git a/pki/base/symkey/src/com/netscape/symkey/SymKey.cpp b/pki/base/symkey/src/com/netscape/symkey/SymKey.cpp index 11e363436..70a3dfbc6 100644 --- a/pki/base/symkey/src/com/netscape/symkey/SymKey.cpp +++ b/pki/base/symkey/src/com/netscape/symkey/SymKey.cpp @@ -440,6 +440,12 @@ PK11SymKey *ComputeCardKey(PK11SymKey *masterKey, unsigned char *data, PK11SlotI keyData[i] = 0x0; } + if (masterKey == NULL) + { + printf("ComputeCardKey: master key is null\n"); + goto done; + } + context = PK11_CreateContextBySymKey(CKM_DES3_ECB, CKA_ENCRYPT, masterKey, &noParams); @@ -482,10 +488,20 @@ PK11SymKey *ComputeCardKey(PK11SymKey *masterKey, unsigned char *data, PK11SlotI (CKF_WRAP | CKF_UNWRAP | CKF_ENCRYPT | CKF_DECRYPT) & CKF_KEY_OPERATION_FLAGS, PR_FALSE, &pwdata); + if (tmpkey == NULL) { + printf("failed to keygen \n"); + goto done; + } + context = PK11_CreateContextBySymKey(CKM_DES3_ECB, CKA_ENCRYPT, tmpkey, &noParams); + if (context == NULL) { + printf("failed to set context \n"); + goto done; + } + /* encrypt the key with the master key */ s = PK11_CipherOp(context, wrappedkey, &len, 24, keyData, 24); if (s != SECSuccess) @@ -512,6 +528,11 @@ done: PK11_DestroyContext(context, PR_TRUE); context = NULL; } + if (tmpkey != NULL) + { + PK11_FreeSymKey(tmpkey); + tmpkey = NULL; + } return key; } @@ -536,6 +557,11 @@ PRStatus EncryptDataWithCardKey(PK11SymKey *card_key, Buffer &input, Buffer &out static SECItem noParams = { siBuffer, 0, 0 }; unsigned char result[8]; + if (card_key == NULL) { + printf("EncryptDataWithCardKey: card_key is null\n"); + goto done; + } + context = PK11_CreateContextBySymKey(CKM_DES3_ECB, CKA_ENCRYPT, card_key, &noParams); if (context == NULL) @@ -603,6 +629,7 @@ PRStatus EncryptData(Buffer &kek_key, Buffer &input, Buffer &output) CKF_ENCRYPT, PR_FALSE, 0); if( master == NULL) { + printf("EncryptData: master is null\n"); goto done; } -- cgit