diff options
Diffstat (limited to 'src/mscrypto/app.c')
-rw-r--r-- | src/mscrypto/app.c | 523 |
1 files changed, 151 insertions, 372 deletions
diff --git a/src/mscrypto/app.c b/src/mscrypto/app.c index bcb0ea19..3f5ab179 100644 --- a/src/mscrypto/app.c +++ b/src/mscrypto/app.c @@ -1,5 +1,6 @@ -/** - * XMLSec library +/* + * XML Security Library (http://www.aleksey.com/xmlsec). + * * * This is free software; see Copyright file in the source * distribution for preciese wording. @@ -7,6 +8,13 @@ * Copyright (C) 2003 Cordys R&D BV, All rights reserved. * Copyright (C) 2003-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. */ +/** + * SECTION:app + * @Short_description: Application support functions for Microsoft Crypto API. + * @Stability: Stable + * + */ + #include "globals.h" #include <string.h> @@ -18,6 +26,8 @@ #include <xmlsec/keys.h> #include <xmlsec/transforms.h> #include <xmlsec/errors.h> +#include <xmlsec/keysdata.h> +#include <xmlsec/xmltree.h> #include <xmlsec/mscrypto/app.h> #include <xmlsec/mscrypto/crypto.h> @@ -26,6 +36,10 @@ #include <xmlsec/mscrypto/x509.h> #include "private.h" +#ifndef PKCS12_NO_PERSIST_KEY +/* Windows Server 2003 and Windows XP: This value is not supported. */ +# define PKCS12_NO_PERSIST_KEY 0x00008000 +#endif /* I don't see any other way then to use a global var to get the * config info to the mscrypto keysstore :( WK @@ -52,38 +66,18 @@ xmlSecMSCryptoAppInit(const char* config) { if (NULL != config && strlen(config) > 0) { if (gXmlSecMSCryptoAppCertStoreName != NULL) { /* This should not happen, initialize twice */ - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "config=%s, config already set", - xmlSecErrorsSafeString(config)); + xmlSecOtherError2(XMLSEC_ERRORS_R_INVALID_CONFIG, NULL, + "config=%s, config already set", + xmlSecErrorsSafeString(config)); return (-1); } -#ifdef UNICODE - gXmlSecMSCryptoAppCertStoreName = xmlSecMSCryptoConvertLocaleToUnicode(config); + gXmlSecMSCryptoAppCertStoreName = xmlSecWin32ConvertUtf8ToTstr((const xmlChar *)config); if (gXmlSecMSCryptoAppCertStoreName == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - "xmlSecMSCryptoConvertLocaleToUnicode", - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "config=%s", - xmlSecErrorsSafeString(config)); + xmlSecInternalError2("xmlSecWin32ConvertUtf8ToTstr", NULL, + "config=%s", xmlSecErrorsSafeString(config)); return (-1); } -#else /* UNICODE */ - gXmlSecMSCryptoAppCertStoreName = xmlStrdup(config); - if (gXmlSecMSCryptoAppCertStoreName == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - "xmlStrdup", - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "config=%s", - xmlSecErrorsSafeString(config)); - return (-1); - } -#endif /* UNICODE */ } return(0); @@ -150,33 +144,21 @@ xmlSecMSCryptoAppKeyLoad(const char *filename, xmlSecKeyDataFormat format, case xmlSecKeyDataFormatPkcs12: key = xmlSecMSCryptoAppPkcs12Load(filename, pwd, pwdCallback, pwdCallbackCtx); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoAppPkcs12Load", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoAppPkcs12Load", NULL); return(NULL); } break; case xmlSecKeyDataFormatCertDer: ret = xmlSecBufferInitialize(&buffer, 0); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecBufferInitialize", NULL); return(NULL); } ret = xmlSecBufferReadFile(&buffer, filename); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferReadFile", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename=%s", - xmlSecErrorsSafeString(filename)); + xmlSecInternalError2("xmlSecBufferReadFile", NULL, + "filename=%s", xmlSecErrorsSafeString(filename)); xmlSecBufferFinalize(&buffer); return (NULL); } @@ -185,11 +167,7 @@ xmlSecMSCryptoAppKeyLoad(const char *filename, xmlSecKeyDataFormat format, xmlSecBufferGetSize(&buffer), format, pwd, pwdCallback, pwdCallbackCtx); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoAppKeyLoadMemory", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoAppKeyLoadMemory", NULL); xmlSecBufferFinalize(&buffer); return(NULL); } @@ -197,11 +175,8 @@ xmlSecMSCryptoAppKeyLoad(const char *filename, xmlSecKeyDataFormat format, break; default: /* Any other format like PEM keys is currently not supported */ - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_FORMAT, - "format=%d", format); + xmlSecOtherError2(XMLSEC_ERRORS_R_INVALID_FORMAT, NULL, + "format=%d", (int)format); return(NULL); } @@ -235,47 +210,33 @@ xmlSecMSCryptoAppKeyLoadMemory(const xmlSecByte* data, xmlSecSize dataSize, xmlS xmlSecAssert2(data != NULL, NULL); xmlSecAssert2(dataSize > 0, NULL); xmlSecAssert2(format == xmlSecKeyDataFormatCertDer, NULL); + UNREFERENCED_PARAMETER(pwd); + UNREFERENCED_PARAMETER(pwdCallback); + UNREFERENCED_PARAMETER(pwdCallbackCtx); pCert = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, data, dataSize); if (NULL == pCert) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertCreateCertificateContext", - XMLSEC_ERRORS_R_IO_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecMSCryptoError("CertCreateCertificateContext", NULL); goto done; } x509Data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataX509Id); if(x509Data == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyDataCreate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "transform=%s", - xmlSecErrorsSafeString(xmlSecTransformKlassGetName(xmlSecMSCryptoKeyDataX509Id))); + xmlSecInternalError("xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataX509Id)", NULL); goto done; } tmpcert = CertDuplicateCertificateContext(pCert); if(tmpcert == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertDuplicateCertificateContext", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecMSCryptoError("CertDuplicateCertificateContext", + xmlSecKeyDataGetName(x509Data)); goto done; } ret = xmlSecMSCryptoKeyDataX509AdoptKeyCert(x509Data, tmpcert); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeyDataX509AdoptKeyCert", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecMSCryptoKeyDataX509AdoptKeyCert", + xmlSecKeyDataGetName(x509Data)); CertFreeCertificateContext(tmpcert); goto done; } @@ -283,45 +244,31 @@ xmlSecMSCryptoAppKeyLoadMemory(const xmlSecByte* data, xmlSecSize dataSize, xmlS keyData = xmlSecMSCryptoCertAdopt(pCert, xmlSecKeyDataTypePublic); if(keyData == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoCertAdopt", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoCertAdopt", + xmlSecKeyDataGetName(x509Data)); goto done; } pCert = NULL; key = xmlSecKeyCreate(); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyCreate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeyCreate", + xmlSecKeyDataGetName(x509Data)); goto done; } ret = xmlSecKeySetValue(key, keyData); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeySetValue", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecKeySetValue", + xmlSecKeyDataGetName(x509Data)); goto done; } keyData = NULL; ret = xmlSecKeyAdoptData(key, x509Data); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyAdoptData", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecKeyAdoptData", + xmlSecKeyDataGetName(x509Data)); goto done; } x509Data = NULL; @@ -378,22 +325,14 @@ xmlSecMSCryptoAppKeyCertLoad(xmlSecKeyPtr key, const char* filename, ret = xmlSecBufferInitialize(&buffer, 0); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecBufferInitialize", NULL); return(-1); } ret = xmlSecBufferReadFile(&buffer, filename); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferReadFile", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename=%s", - xmlSecErrorsSafeString(filename)); + xmlSecInternalError2("xmlSecBufferReadFile", NULL, + "filename=%s", xmlSecErrorsSafeString(filename)); xmlSecBufferFinalize(&buffer); return (-1); } @@ -401,11 +340,7 @@ xmlSecMSCryptoAppKeyCertLoad(xmlSecKeyPtr key, const char* filename, ret = xmlSecMSCryptoAppKeyCertLoadMemory(key, xmlSecBufferGetData(&buffer), xmlSecBufferGetSize(&buffer), format); if (ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoAppKeyCertLoadMemory", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoAppKeyCertLoadMemory", NULL); xmlSecBufferFinalize(&buffer); return(-1); } @@ -438,12 +373,7 @@ xmlSecMSCryptoAppKeyCertLoadMemory(xmlSecKeyPtr key, const xmlSecByte* data, xml kdata = xmlSecKeyEnsureData(key, xmlSecMSCryptoKeyDataX509Id); if(kdata == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyEnsureData", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "transform=%s", - xmlSecErrorsSafeString(xmlSecTransformKlassGetName(xmlSecMSCryptoKeyDataX509Id))); + xmlSecInternalError("xmlSecKeyEnsureData(xmlSecMSCryptoKeyDataX509Id)", NULL); return(-1); } @@ -454,32 +384,22 @@ xmlSecMSCryptoAppKeyCertLoadMemory(xmlSecKeyPtr key, const xmlSecByte* data, xml case xmlSecKeyDataFormatCertDer: pCert = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, data, dataSize); if (NULL == pCert) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertCreateCertificateContext", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "format=%d", format); + xmlSecInternalError2("CertCreateCertificateContext", NULL, + "format=%d", format); return(-1); } ret = xmlSecMSCryptoKeyDataX509AdoptCert(kdata, pCert); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeyDataX509AdoptCert", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(kdata))); + xmlSecInternalError("xmlSecMSCryptoKeyDataX509AdoptCert", + xmlSecKeyDataGetName(kdata)); CertFreeCertificateContext(pCert); return(-1); } break; default: - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_FORMAT, - "format=%d", (int)format); + xmlSecOtherError2(XMLSEC_ERRORS_R_INVALID_FORMAT, NULL, + "format=%d", (int)format); return(-1); } @@ -511,31 +431,19 @@ xmlSecMSCryptoAppPkcs12Load(const char *filename, ret = xmlSecBufferInitialize(&buffer, 0); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecBufferInitialize", NULL); return(NULL); } ret = xmlSecBufferReadFile(&buffer, filename); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferReadFile", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename=%s", - xmlSecErrorsSafeString(filename)); + xmlSecInternalError2("xmlSecBufferReadFile", NULL, + "filename=%s", xmlSecErrorsSafeString(filename)); xmlSecBufferFinalize(&buffer); return (NULL); } if(xmlSecBufferGetData(&buffer) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInvalidDataError("data buffer is empty", NULL); xmlSecBufferFinalize(&buffer); return(NULL); } @@ -544,11 +452,7 @@ xmlSecMSCryptoAppPkcs12Load(const char *filename, xmlSecBufferGetSize(&buffer), pwd, pwdCallback, pwdCallbackCtx); if (key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoAppPkcs12LoadMemory", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoAppPkcs12LoadMemory", NULL); xmlSecBufferFinalize(&buffer); return(NULL); } @@ -580,116 +484,93 @@ xmlSecMSCryptoAppPkcs12LoadMemory(const xmlSecByte* data, PCCERT_CONTEXT tmpcert = NULL; PCCERT_CONTEXT pCert = NULL; WCHAR* wcPwd = NULL; + DWORD dwFlags; xmlSecKeyDataPtr x509Data = NULL; xmlSecKeyDataPtr keyData = NULL; xmlSecKeyPtr key = NULL; - int ret; + int ret; + DWORD dwData = 0; + DWORD dwDataLen; xmlSecAssert2(data != NULL, NULL); xmlSecAssert2(dataSize > 1, NULL); xmlSecAssert2(pwd != NULL, NULL); + UNREFERENCED_PARAMETER(pwdCallback); + UNREFERENCED_PARAMETER(pwdCallbackCtx); memset(&pfx, 0, sizeof(pfx)); pfx.pbData = (BYTE *)data; pfx.cbData = dataSize; if(FALSE == PFXIsPFXBlob(&pfx)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "PFXIsPFXBlob", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "size=%ld", - pfx.cbData); + xmlSecMSCryptoError2("PFXIsPFXBlob", NULL, + "size=%ld", (long int)pfx.cbData); goto done; } - wcPwd = xmlSecMSCryptoConvertLocaleToUnicode(pwd); + wcPwd = xmlSecWin32ConvertLocaleToUnicode(pwd); if (wcPwd == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoConvertLocaleToUnicode", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "wcPwd"); + xmlSecInternalError("xmlSecWin32ConvertLocaleToUnicode(pw)", NULL); goto done; } if (FALSE == PFXVerifyPassword(&pfx, wcPwd, 0)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "PFXVerifyPassword", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecMSCryptoError("PFXVerifyPassword", NULL); goto done; } - hCertStore = PFXImportCertStore(&pfx, wcPwd, CRYPT_EXPORTABLE | PKCS12_NO_PERSIST_KEY); + dwFlags = CRYPT_EXPORTABLE; + if (!xmlSecImportGetPersistKey()) { + dwFlags |= PKCS12_NO_PERSIST_KEY; + } + hCertStore = PFXImportCertStore(&pfx, wcPwd, dwFlags); if (NULL == hCertStore) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "PFXImportCertStore", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecMSCryptoError("PFXImportCertStore", NULL); goto done; } x509Data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataX509Id); if(x509Data == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyDataCreate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "transform=%s", - xmlSecErrorsSafeString(xmlSecTransformKlassGetName(xmlSecMSCryptoKeyDataX509Id))); + xmlSecInternalError("xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataX509Id)", NULL); goto done; } - while (pCert = CertEnumCertificatesInStore(hCertStore, pCert)) { - DWORD dwData = 0; - DWORD dwDataLen = sizeof(DWORD); + while (1) { + pCert = CertEnumCertificatesInStore(hCertStore, pCert); + if(pCert == NULL) { + break; + } + dwDataLen = sizeof(DWORD); + dwData = 0; /* Find the certificate that has the private key */ if((TRUE == CertGetCertificateContextProperty(pCert, CERT_KEY_SPEC_PROP_ID, &dwData, &dwDataLen)) && (dwData > 0)) { tmpcert = CertDuplicateCertificateContext(pCert); if(tmpcert == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertDuplicateCertificateContext", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecMSCryptoError("CertDuplicateCertificateContext", + xmlSecKeyDataGetName(x509Data)); goto done; } keyData = xmlSecMSCryptoCertAdopt(tmpcert, xmlSecKeyDataTypePrivate | xmlSecKeyDataTypePublic); if(keyData == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoCertAdopt", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoCertAdopt", + xmlSecKeyDataGetName(x509Data)); goto done; } - tmpcert = NULL; + tmpcert = NULL; tmpcert = CertDuplicateCertificateContext(pCert); if(tmpcert == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertDuplicateCertificateContext", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecMSCryptoError("CertDuplicateCertificateContext", + xmlSecKeyDataGetName(x509Data)); goto done; } ret = xmlSecMSCryptoKeyDataX509AdoptKeyCert(x509Data, tmpcert); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeyDataX509AdoptKeyCert", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecMSCryptoKeyDataX509AdoptKeyCert", + xmlSecKeyDataGetName(x509Data)); goto done; } tmpcert = NULL; @@ -698,55 +579,39 @@ xmlSecMSCryptoAppPkcs12LoadMemory(const xmlSecByte* data, /* load certificate in the x509 key data */ tmpcert = CertDuplicateCertificateContext(pCert); if(tmpcert == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertDuplicateCertificateContext", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecMSCryptoError("CertDuplicateCertificateContext", + xmlSecKeyDataGetName(x509Data)); goto done; } ret = xmlSecMSCryptoKeyDataX509AdoptCert(x509Data, tmpcert); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeyDataX509AdoptCert", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecMSCryptoKeyDataX509AdoptCert", + xmlSecKeyDataGetName(x509Data)); goto done; } tmpcert = NULL; } if (keyData == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoAppPkcs12Load", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "private key not found in PKCS12 file"); + /* private key not found in PKCS12 file */ + xmlSecInternalError2("xmlSecMSCryptoAppPkcs12Load", + xmlSecKeyDataGetName(x509Data), + "private key not found in PKCS12 file", NULL); goto done; } key = xmlSecKeyCreate(); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyCreate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeyCreate", + xmlSecKeyDataGetName(x509Data)); goto done; } ret = xmlSecKeySetValue(key, keyData); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeySetValue", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecKeySetValue", + xmlSecKeyDataGetName(x509Data)); xmlSecKeyDestroy(key); key = NULL; goto done; @@ -755,12 +620,8 @@ xmlSecMSCryptoAppPkcs12LoadMemory(const xmlSecByte* data, ret = xmlSecKeyAdoptData(key, x509Data); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyAdoptData", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "data=%s", - xmlSecErrorsSafeString(xmlSecKeyDataGetName(x509Data))); + xmlSecInternalError("xmlSecKeyAdoptData", + xmlSecKeyDataGetName(x509Data)); xmlSecKeyDestroy(key); key = NULL; goto done; @@ -812,22 +673,14 @@ xmlSecMSCryptoAppKeysMngrCertLoad(xmlSecKeysMngrPtr mngr, const char *filename, ret = xmlSecBufferInitialize(&buffer, 0); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecBufferInitialize", NULL); return(-1); } ret = xmlSecBufferReadFile(&buffer, filename); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferReadFile", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename=%s", - xmlSecErrorsSafeString(filename)); + xmlSecInternalError2("xmlSecBufferReadFile", NULL, + "filename=%s", xmlSecErrorsSafeString(filename)); xmlSecBufferFinalize(&buffer); return (-1); } @@ -835,12 +688,8 @@ xmlSecMSCryptoAppKeysMngrCertLoad(xmlSecKeysMngrPtr mngr, const char *filename, ret = xmlSecMSCryptoAppKeysMngrCertLoadMemory(mngr, xmlSecBufferGetData(&buffer), xmlSecBufferGetSize(&buffer), format, type); if (ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoAppKeysMngrCertLoadMemory", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename=%s", - xmlSecErrorsSafeString(filename)); + xmlSecInternalError2("xmlSecMSCryptoAppKeysMngrCertLoadMemory", NULL, + "filename=%s", xmlSecErrorsSafeString(filename)); xmlSecBufferFinalize(&buffer); return(-1); } @@ -878,11 +727,7 @@ xmlSecMSCryptoAppKeysMngrCertLoadMemory(xmlSecKeysMngrPtr mngr, const xmlSecByte x509Store = xmlSecKeysMngrGetDataStore(mngr, xmlSecMSCryptoX509StoreId); if(x509Store == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeysMngrGetDataStore", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "xmlSecMSCryptoX509StoreId"); + xmlSecInternalError("xmlSecKeysMngrGetDataStore(xmlSecMSCryptoX509StoreId)", NULL); return(-1); } @@ -892,31 +737,20 @@ xmlSecMSCryptoAppKeysMngrCertLoadMemory(xmlSecKeysMngrPtr mngr, const xmlSecByte pCert = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, data, dataSize); if (NULL == pCert) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "CertCreateCertificateContext", - XMLSEC_ERRORS_R_CRYPTO_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecMSCryptoError("CertCreateCertificateContext", NULL); return (-1); } break; default: - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_FORMAT, - "format=%d", format); + xmlSecOtherError2(XMLSEC_ERRORS_R_INVALID_FORMAT, NULL, + "format=%d", (int)format); return(-1); } xmlSecAssert2(pCert != NULL, -1); ret = xmlSecMSCryptoX509StoreAdoptCert(x509Store, pCert, type); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoX509StoreAdoptCert", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoX509StoreAdoptCert", NULL); CertFreeCertificateContext(pCert); return(-1); } @@ -943,21 +777,14 @@ xmlSecMSCryptoAppDefaultKeysMngrAdoptKeyStore(xmlSecKeysMngrPtr mngr, HCERTSTORE x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId) ; if( x509Store == NULL ) { - xmlSecError( XMLSEC_ERRORS_HERE , - NULL , - "xmlSecKeysMngrGetDataStore" , - XMLSEC_ERRORS_R_XMLSEC_FAILED , - XMLSEC_ERRORS_NO_MESSAGE ) ; - return(-1) ; + xmlSecInternalError("xmlSecKeysMngrGetDataStore(xmlSecMSCryptoX509StoreId)", NULL); + return(-1) ; } if( xmlSecMSCryptoX509StoreAdoptKeyStore( x509Store, keyStore ) < 0 ) { - xmlSecError( XMLSEC_ERRORS_HERE , - xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) , - "xmlSecMSCryptoX509StoreAdoptKeyStore" , - XMLSEC_ERRORS_R_XMLSEC_FAILED , - XMLSEC_ERRORS_NO_MESSAGE ) ; - return(-1) ; + xmlSecInternalError("xmlSecMSCryptoX509StoreAdoptKeyStore", + xmlSecKeyDataStoreGetName(x509Store)); + return(-1) ; } return (0) ; @@ -982,21 +809,14 @@ xmlSecMSCryptoAppDefaultKeysMngrAdoptTrustedStore(xmlSecKeysMngrPtr mngr, HCERTS x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ; if( x509Store == NULL ) { - xmlSecError( XMLSEC_ERRORS_HERE , - NULL , - "xmlSecKeysMngrGetDataStore" , - XMLSEC_ERRORS_R_XMLSEC_FAILED , - XMLSEC_ERRORS_NO_MESSAGE ) ; - return(-1) ; + xmlSecInternalError("xmlSecKeysMngrGetDataStore", NULL); + return(-1) ; } if( xmlSecMSCryptoX509StoreAdoptTrustedStore( x509Store, trustedStore ) < 0 ) { - xmlSecError( XMLSEC_ERRORS_HERE , - xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) , - "xmlSecMSCryptoX509StoreAdoptKeyStore" , - XMLSEC_ERRORS_R_XMLSEC_FAILED , - XMLSEC_ERRORS_NO_MESSAGE ) ; - return(-1) ; + xmlSecInternalError("xmlSecMSCryptoX509StoreAdoptKeyStore", + xmlSecKeyDataStoreGetName(x509Store)); + return(-1) ; } return(0); @@ -1020,25 +840,18 @@ xmlSecMSCryptoAppDefaultKeysMngrAdoptUntrustedStore(xmlSecKeysMngrPtr mngr, HCER xmlSecAssert2( untrustedStore != NULL, -1 ) ; x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId); - if( x509Store == NULL ) { - xmlSecError( XMLSEC_ERRORS_HERE , - NULL , - "xmlSecKeysMngrGetDataStore" , - XMLSEC_ERRORS_R_XMLSEC_FAILED , - XMLSEC_ERRORS_NO_MESSAGE ) ; - return(-1); - } + if(x509Store == NULL) { + xmlSecInternalError("xmlSecKeysMngrGetDataStore", NULL); + return(-1); + } - if( xmlSecMSCryptoX509StoreAdoptUntrustedStore( x509Store, untrustedStore ) < 0) { - xmlSecError( XMLSEC_ERRORS_HERE , - xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) , - "xmlSecMSCryptoX509StoreAdoptKeyStore" , - XMLSEC_ERRORS_R_XMLSEC_FAILED , - XMLSEC_ERRORS_NO_MESSAGE ) ; - return(-1); - } + if(xmlSecMSCryptoX509StoreAdoptUntrustedStore(x509Store, untrustedStore) < 0) { + xmlSecInternalError("xmlSecMSCryptoX509StoreAdoptKeyStore", + xmlSecKeyDataStoreGetName(x509Store)); + return(-1); + } - return(0) ; + return(0) ; } #endif /* XMLSEC_NO_X509 */ @@ -1064,21 +877,13 @@ xmlSecMSCryptoAppDefaultKeysMngrInit(xmlSecKeysMngrPtr mngr) { keysStore = xmlSecKeyStoreCreate(xmlSecMSCryptoKeysStoreId); if(keysStore == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyStoreCreate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "xmlSecMSCryptoKeysStoreId"); + xmlSecInternalError("xmlSecKeyStoreCreate(xmlSecMSCryptoX509StoreId)", NULL); return(-1); } ret = xmlSecKeysMngrAdoptKeysStore(mngr, keysStore); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeysMngrAdoptKeysStore", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeysMngrAdoptKeysStore", NULL); xmlSecKeyStoreDestroy(keysStore); return(-1); } @@ -1086,11 +891,7 @@ xmlSecMSCryptoAppDefaultKeysMngrInit(xmlSecKeysMngrPtr mngr) { ret = xmlSecMSCryptoKeysMngrInit(mngr); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeysMngrInit", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoKeysMngrInit", NULL); return(-1); } @@ -1118,21 +919,13 @@ xmlSecMSCryptoAppDefaultKeysMngrAdoptKey(xmlSecKeysMngrPtr mngr, xmlSecKeyPtr ke store = xmlSecKeysMngrGetKeysStore(mngr); if(store == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeysMngrGetKeysStore", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeysMngrGetKeysStore", NULL); return(-1); } ret = xmlSecMSCryptoKeysStoreAdoptKey(store, key); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeysStoreAdoptKey", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecMSCryptoKeysStoreAdoptKey", NULL); return(-1); } @@ -1159,21 +952,14 @@ xmlSecMSCryptoAppDefaultKeysMngrLoad(xmlSecKeysMngrPtr mngr, const char* uri) { store = xmlSecKeysMngrGetKeysStore(mngr); if(store == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeysMngrGetKeysStore", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeysMngrGetKeysStore", NULL); return(-1); } ret = xmlSecMSCryptoKeysStoreLoad(store, uri, mngr); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeysStoreLoad", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "uri=%s", xmlSecErrorsSafeString(uri)); + xmlSecInternalError2("xmlSecMSCryptoKeysStoreLoad", NULL, + "uri=%s", xmlSecErrorsSafeString(uri)); return(-1); } @@ -1200,21 +986,14 @@ xmlSecMSCryptoAppDefaultKeysMngrSave(xmlSecKeysMngrPtr mngr, const char* filenam store = xmlSecKeysMngrGetKeysStore(mngr); if(store == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeysMngrGetKeysStore", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecKeysMngrGetKeysStore", NULL); return(-1); } ret = xmlSecMSCryptoKeysStoreSave(store, filename, type); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecMSCryptoKeysStoreSave", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename%s", xmlSecErrorsSafeString(filename)); + xmlSecInternalError2("xmlSecMSCryptoKeysStoreSave", NULL, + "filename%s", xmlSecErrorsSafeString(filename)); return(-1); } |