diff options
Diffstat (limited to 'src/openssl/crypto.c')
-rw-r--r-- | src/openssl/crypto.c | 78 |
1 files changed, 28 insertions, 50 deletions
diff --git a/src/openssl/crypto.c b/src/openssl/crypto.c index b70eb731..5be249fa 100644 --- a/src/openssl/crypto.c +++ b/src/openssl/crypto.c @@ -1,18 +1,23 @@ -/** - * XMLSec library +/* + * XML Security Library (http://www.aleksey.com/xmlsec). + * * * This is free software; see Copyright file in the source * distribution for preciese wording. * * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. */ +/** + * SECTION:crypto + * @Short_description: Crypto transforms implementation for OpenSSL. + * @Stability: Stable + * + */ + #include "globals.h" #include <string.h> -#include <openssl/evp.h> -#include <openssl/rand.h> - #include <xmlsec/xmlsec.h> #include <xmlsec/keys.h> #include <xmlsec/keysmngr.h> @@ -21,6 +26,9 @@ #include <xmlsec/dl.h> #include <xmlsec/private.h> +#include <openssl/x509.h> +#include <openssl/evp.h> +#include <openssl/rand.h> #include <xmlsec/openssl/app.h> #include <xmlsec/openssl/crypto.h> #include <xmlsec/openssl/x509.h> @@ -120,6 +128,9 @@ xmlSecCryptoGetFunctions_openssl(void) { gXmlSecOpenSSLFunctions->transformAes128CbcGetKlass = xmlSecOpenSSLTransformAes128CbcGetKlass; gXmlSecOpenSSLFunctions->transformAes192CbcGetKlass = xmlSecOpenSSLTransformAes192CbcGetKlass; gXmlSecOpenSSLFunctions->transformAes256CbcGetKlass = xmlSecOpenSSLTransformAes256CbcGetKlass; + gXmlSecOpenSSLFunctions->transformAes128GcmGetKlass = xmlSecOpenSSLTransformAes128GcmGetKlass; + gXmlSecOpenSSLFunctions->transformAes192GcmGetKlass = xmlSecOpenSSLTransformAes192GcmGetKlass; + gXmlSecOpenSSLFunctions->transformAes256GcmGetKlass = xmlSecOpenSSLTransformAes256GcmGetKlass; gXmlSecOpenSSLFunctions->transformKWAes128GetKlass = xmlSecOpenSSLTransformKWAes128GetKlass; gXmlSecOpenSSLFunctions->transformKWAes192GetKlass = xmlSecOpenSSLTransformKWAes192GetKlass; gXmlSecOpenSSLFunctions->transformKWAes256GetKlass = xmlSecOpenSSLTransformKWAes256GetKlass; @@ -318,30 +329,18 @@ int xmlSecOpenSSLInit (void) { /* Check loaded xmlsec library version */ if(xmlSecCheckVersionExact() != 1) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCheckVersionExact", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecCheckVersionExact", NULL); return(-1); } if(xmlSecOpenSSLErrorsInit() < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecOpenSSLErrorsInit", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecOpenSSLErrorsInit", NULL); return(-1); } /* register our klasses */ if(xmlSecCryptoDLFunctionsRegisterKeyDataAndTransforms(xmlSecCryptoGetFunctions_openssl()) < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoDLFunctionsRegisterKeyDataAndTransforms", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecCryptoDLFunctionsRegisterKeyDataAndTransforms", NULL); return(-1); } @@ -382,21 +381,13 @@ xmlSecOpenSSLKeysMngrInit(xmlSecKeysMngrPtr mngr) { x509Store = xmlSecKeyDataStoreCreate(xmlSecOpenSSLX509StoreId); if(x509Store == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyDataStoreCreate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "xmlSecOpenSSLX509StoreId"); + xmlSecInternalError("xmlSecKeyDataStoreCreate(xmlSecOpenSSLX509StoreId)", NULL); return(-1); } ret = xmlSecKeysMngrAdoptDataStore(mngr, x509Store); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeysMngrAdoptDataStore", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeysMngrAdoptDataStore", NULL); xmlSecKeyDataStoreDestroy(x509Store); return(-1); } @@ -423,22 +414,15 @@ xmlSecOpenSSLGenerateRandom(xmlSecBufferPtr buffer, xmlSecSize size) { ret = xmlSecBufferSetSize(buffer, size); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); + xmlSecInternalError2("xmlSecBufferSetSize", NULL, "size=%d", size); return(-1); } /* get random data */ ret = RAND_bytes((xmlSecByte*)xmlSecBufferGetData(buffer), size); if(ret != 1) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "RAND_bytes", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "size=%d", size); + xmlSecOpenSSLError2("RAND_bytes", NULL, + "size=%lu", (unsigned long)size); return(-1); } return(0); @@ -454,13 +438,12 @@ xmlSecOpenSSLGenerateRandom(xmlSecBufferPtr buffer, xmlSecSize size) { * @reason: the error code. * @msg: the additional error message. * - * The default OpenSSL errors reporting callback function. + * The errors reporting callback function. */ void xmlSecOpenSSLErrorsDefaultCallback(const char* file, int line, const char* func, const char* errorObject, const char* errorSubject, int reason, const char* msg) { - ERR_put_error(XMLSEC_OPENSSL_ERRORS_LIB, XMLSEC_OPENSSL_ERRORS_FUNCTION, reason, file, line); @@ -471,6 +454,7 @@ xmlSecOpenSSLErrorsDefaultCallback(const char* file, int line, const char* func, static int xmlSecOpenSSLErrorsInit(void) { +#ifndef OPENSSL_IS_BORINGSSL static ERR_STRING_DATA xmlSecOpenSSLStrReasons[XMLSEC_ERRORS_MAX_NUMBER + 1]; static ERR_STRING_DATA xmlSecOpenSSLStrLib[]= { { ERR_PACK(XMLSEC_OPENSSL_ERRORS_LIB,0,0), "xmlsec routines"}, @@ -493,6 +477,7 @@ xmlSecOpenSSLErrorsInit(void) { ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrLib); /* define xmlsec lib name */ ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrDefReason); /* define default reason */ ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrReasons); +#endif /* OPENSSL_IS_BORINGSSL */ /* and set default errors callback for xmlsec to us */ xmlSecErrorsSetCallback(xmlSecOpenSSLErrorsDefaultCallback); @@ -518,11 +503,7 @@ xmlSecOpenSSLSetDefaultTrustedCertsFolder(const xmlChar* path) { if(path != NULL) { gXmlSecOpenSSLTrustedCertsFolder = xmlStrdup(BAD_CAST path); if(gXmlSecOpenSSLTrustedCertsFolder == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlStrdup", - XMLSEC_ERRORS_R_MALLOC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecStrdupError(BAD_CAST path, NULL); return(-1); } } @@ -541,6 +522,3 @@ const xmlChar* xmlSecOpenSSLGetDefaultTrustedCertsFolder(void) { return(gXmlSecOpenSSLTrustedCertsFolder); } - - - |