Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Move to internal Base64 decoder to handle non-wrapping data
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/xml/security/trunk@351043 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Berin Lautenbach committed Jun 9, 2004
1 parent c0da8bf commit 584df0b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
17 changes: 16 additions & 1 deletion c/src/enc/OpenSSL/OpenSSLCryptoBase64.cpp
Expand Up @@ -32,9 +32,16 @@

#include <xsec/enc/OpenSSL/OpenSSLCryptoBase64.hpp>
#include <xsec/enc/XSECCryptoException.hpp>
#include <xsec/enc/XSCrypt/XSCryptCryptoBase64.hpp>
#include <xsec/framework/XSECError.hpp>

#include <xercesc/util/Janitor.hpp>

#include <openssl/err.h>

XERCES_CPP_NAMESPACE_USE


// --------------------------------------------------------------------------------
// Decoding
// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -160,7 +167,7 @@ BIGNUM * OpenSSLCryptoBase64::b642BN(char * b64in, unsigned int len) {

int bufLen;
unsigned char buf[1024];

/*
EVP_ENCODE_CTX m_dctx;
EVP_DecodeInit(&m_dctx);
int rc = EVP_DecodeUpdate(&m_dctx,
Expand All @@ -179,6 +186,14 @@ BIGNUM * OpenSSLCryptoBase64::b642BN(char * b64in, unsigned int len) {
EVP_DecodeFinal(&m_dctx, &buf[bufLen], &finalLen);
bufLen += finalLen;
*/
XSCryptCryptoBase64 *b64;
XSECnew(b64, XSCryptCryptoBase64);
Janitor<XSCryptCryptoBase64> j_b64(b64);

b64->decodeInit();
bufLen = b64->decode((unsigned char *) b64in, len, buf, len);
bufLen += b64->decodeFinish(&buf[bufLen], len-bufLen);

// Now translate to a bignum
return BN_dup(BN_bin2bn(buf, bufLen, NULL));
Expand Down
19 changes: 17 additions & 2 deletions c/src/enc/OpenSSL/OpenSSLCryptoX509.cpp
Expand Up @@ -34,10 +34,12 @@
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
#include <xsec/enc/XSECCryptoException.hpp>
#include <xsec/enc/XSCrypt/XSCryptCryptoBase64.hpp>

#include <xercesc/util/Janitor.hpp>

XSEC_USING_XERCES(ArrayJanitor);
XSEC_USING_XERCES(Janitor);

#include <openssl/evp.h>

Expand Down Expand Up @@ -106,6 +108,19 @@ void OpenSSLCryptoX509::loadX509Base64Bin(const char * buf, unsigned int len) {
XSECnew(outBuf, unsigned char[len + 1]);
ArrayJanitor<unsigned char> j_outBuf(outBuf);

/* Had to move to our own Base64 decoder because it handles non-wrapped b64
better. Grrr. */

XSCryptCryptoBase64 *b64;
XSECnew(b64, XSCryptCryptoBase64);
Janitor<XSCryptCryptoBase64> j_b64(b64);

b64->decodeInit();
bufLen = b64->decode((unsigned char *) buf, len, outBuf, len);
bufLen += b64->decodeFinish(&outBuf[bufLen], len-bufLen);

/*
EVP_ENCODE_CTX m_dctx;
EVP_DecodeInit(&m_dctx);
Expand All @@ -120,12 +135,12 @@ void OpenSSLCryptoX509::loadX509Base64Bin(const char * buf, unsigned int len) {
throw XSECCryptoException(XSECCryptoException::Base64Error,
"OpenSSL:Base64 - Error during Base64 Decode of X509 Certificate");
}

int finalLen;
EVP_DecodeFinal(&m_dctx, &outBuf[bufLen], &finalLen);
bufLen += finalLen;

*/
if (bufLen > 0) {
mp_X509= d2i_X509(NULL, &outBuf, bufLen);
}
Expand Down

0 comments on commit 584df0b

Please sign in to comment.