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 2021/10/14 20:39:26 UTC
svn commit: r1894270 -
/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp
Author: scantor
Date: Thu Oct 14 20:39:26 2021
New Revision: 1894270
URL: http://svn.apache.org/viewvc?rev=1894270&view=rev
Log:
SANTUARIO-498 - DSA signature generation is unreliable
https://issues.apache.org/jira/browse/SANTUARIO-498
Modified:
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp?rev=1894270&r1=1894269&r2=1894270&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp Thu Oct 14 20:39:26 2021
@@ -395,25 +395,19 @@ unsigned int OpenSSLCryptoKeyDSA::signBa
DSA_SIG_get0(dsa_sig, &dsaSigR, &dsaSigS);
- unsigned char* rawSigBuf = new unsigned char[(BN_num_bits(dsaSigR) + BN_num_bits(dsaSigS) + 7) / 8];
- ArrayJanitor<unsigned char> j_sigbuf(rawSigBuf);
+ const int DSAsigCompLen = 20; // XMLDSIG spec 6.4.1
+ unsigned char rawSigBuf[2*DSAsigCompLen];
- unsigned int rawLen = BN_bn2bin(dsaSigR, rawSigBuf);
-
- if (rawLen <= 0) {
+ if (BN_bn2binpad(dsaSigR, rawSigBuf, DSAsigCompLen) <= 0) {
throw XSECCryptoException(XSECCryptoException::DSAError,
"OpenSSL:DSA - Error converting signature to raw buffer");
}
- unsigned int rawLenS = BN_bn2bin(dsaSigS, (unsigned char *) &rawSigBuf[rawLen]);
-
- if (rawLenS <= 0) {
+ if (BN_bn2binpad(dsaSigS, rawSigBuf+DSAsigCompLen, DSAsigCompLen) <= 0) {
throw XSECCryptoException(XSECCryptoException::DSAError,
"OpenSSL:DSA - Error converting signature to raw buffer");
}
- rawLen += rawLenS;
-
// Now convert to Base 64
BIO * b64 = BIO_new(BIO_f_base64());
@@ -424,7 +418,7 @@ unsigned int OpenSSLCryptoKeyDSA::signBa
// Translate signature from Base64
- BIO_write(b64, rawSigBuf, rawLen);
+ BIO_write(b64, rawSigBuf, 2*DSAsigCompLen);
BIO_flush(b64);
unsigned int sigValLen = BIO_read(bmem, base64SignatureBuf, base64SignatureBufLen);