You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2010/10/26 02:34:35 UTC

svn commit: r1027325 - /santuario/trunk/c/xsec/enc/NSS/NSSCryptoKeyRSA.cpp

Author: scantor
Date: Tue Oct 26 00:34:35 2010
New Revision: 1027325

URL: http://svn.apache.org/viewvc?rev=1027325&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=49660

Modified:
    santuario/trunk/c/xsec/enc/NSS/NSSCryptoKeyRSA.cpp

Modified: santuario/trunk/c/xsec/enc/NSS/NSSCryptoKeyRSA.cpp
URL: http://svn.apache.org/viewvc/santuario/trunk/c/xsec/enc/NSS/NSSCryptoKeyRSA.cpp?rev=1027325&r1=1027324&r2=1027325&view=diff
==============================================================================
--- santuario/trunk/c/xsec/enc/NSS/NSSCryptoKeyRSA.cpp (original)
+++ santuario/trunk/c/xsec/enc/NSS/NSSCryptoKeyRSA.cpp Tue Oct 26 00:34:35 2010
@@ -272,9 +272,59 @@ bool NSSCryptoKeyRSA::verifySHA1PKCS1Bas
   signature.len = rawSigLen;
 
   SECItem data; 
-  data.type = siBuffer;
-  data.data = (unsigned char *)hashBuf;
-  data.len = hashLen;
+  data.data = 0;
+  data.len = 0;
+  SECOidTag hashalg;
+  PRArenaPool * arena = 0;
+  SGNDigestInfo *di = 0;
+  SECItem * res;
+
+  switch (hm) {
+
+  case (HASH_MD5):
+      hashalg = SEC_OID_MD5;
+      break;
+  case (HASH_SHA1):
+      hashalg = SEC_OID_SHA1;
+      break;
+  case (HASH_SHA256):
+      hashalg = SEC_OID_SHA256;
+      break;
+  case (HASH_SHA384):
+      hashalg = SEC_OID_SHA384;
+      break;
+  case (HASH_SHA512):
+      hashalg = SEC_OID_SHA512;
+      break;
+  default:
+      throw XSECCryptoException(XSECCryptoException::RSAError,
+          "NSS:RSA - Unsupported hash algorithm in RSA sign");
+  }
+
+  arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
+  if (!arena) {
+      throw XSECCryptoException(XSECCryptoException::RSAError,
+          "NSS:RSA - Error creating arena");
+  }
+
+  di = SGN_CreateDigestInfo(hashalg, (unsigned char * )hashBuf, hashLen);
+  if (di == NULL) {
+
+      PORT_FreeArena(arena, PR_FALSE);
+
+      throw XSECCryptoException(XSECCryptoException::RSAError,
+          "NSS:RSA - Error creating digest info");
+  }
+
+  res = SEC_ASN1EncodeItem(arena, &data, di, NSS_Get_sgn_DigestInfoTemplate(NULL, 0));
+
+  if (!res) {
+      SGN_DestroyDigestInfo(di);
+      PORT_FreeArena(arena, PR_FALSE);
+
+      throw XSECCryptoException(XSECCryptoException::RSAError,
+          "NSS:RSA - Error encoding digest info for RSA sign");
+  }
 
 	// Verify signature
 	SECStatus s = PK11_Verify(mp_pubkey, &signature, &data, NULL);