summaryrefslogtreecommitdiff
path: root/src/mscrypto/certkeys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscrypto/certkeys.c')
-rw-r--r--src/mscrypto/certkeys.c1290
1 files changed, 719 insertions, 571 deletions
diff --git a/src/mscrypto/certkeys.c b/src/mscrypto/certkeys.c
index 1cf0e554..226e9c80 100644
--- a/src/mscrypto/certkeys.c
+++ b/src/mscrypto/certkeys.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:certkeys
+ * @Short_description: Certificate keys support functions for Microsoft Crypto API.
+ * @Stability: Stable
+ *
+ */
+
#include "globals.h"
#include <string.h>
@@ -50,7 +58,7 @@ typedef struct _xmlSecMSCryptoKeyDataCtx xmlSecMSCryptoKeyDataCtx,
#ifdef XMLSEC_MSCRYPTO_NT4
/*-
- * A wrapper of HCRYPTKEY, a reference countor is introduced, the function is
+ * A wrapper of HCRYPTKEY, a reference counter is introduced, the function is
* the same as CryptDuplicateKey. Because the CryptDuplicateKey is not support
* by WINNT 4.0, the wrapper will enable the library work on WINNT 4.0
*/
@@ -60,7 +68,7 @@ struct _mscrypt_key {
} ;
/*-
- * A wrapper of HCRYPTPROV, a reference countor is introduced, the function is
+ * A wrapper of HCRYPTPROV, a reference counter is introduced, the function is
* the same as CryptContextAddRef. Because the CryptContextAddRef is not support
* by WINNT 4.0, the wrapper will enable the library work on WINNT 4.0
*/
@@ -98,12 +106,13 @@ struct _xmlSecMSCryptoKeyDataCtx {
/******************************** Provider *****************************************/
#define xmlSecMSCryptoKeyDataCtxGetProvider(ctx) (ctx)->hProv
-static void
+static int
xmlSecMSCryptoKeyDataCtxCreateProvider(xmlSecMSCryptoKeyDataCtxPtr ctx) {
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
- ctx->hProv = 0;
- ctx->fCallerFreeProv = FALSE;
+ ctx->hProv = 0;
+ ctx->fCallerFreeProv = FALSE;
+ return(0);
}
static void
@@ -111,20 +120,21 @@ xmlSecMSCryptoKeyDataCtxDestroyProvider(xmlSecMSCryptoKeyDataCtxPtr ctx) {
xmlSecAssert(ctx != NULL);
if ((ctx->hProv != 0) && (ctx->fCallerFreeProv)) {
- CryptReleaseContext(ctx->hProv, 0);
+ CryptReleaseContext(ctx->hProv, 0);
}
- ctx->hProv = 0;
- ctx->fCallerFreeProv = FALSE;
+ ctx->hProv = 0;
+ ctx->fCallerFreeProv = FALSE;
}
-static void
+static int
xmlSecMSCryptoKeyDataCtxSetProvider(xmlSecMSCryptoKeyDataCtxPtr ctx, HCRYPTPROV hProv, BOOL fCallerFreeProv)
{
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
xmlSecMSCryptoKeyDataCtxDestroyProvider(ctx);
ctx->hProv = hProv;
ctx->fCallerFreeProv = fCallerFreeProv;
+ return(0);
}
static int
@@ -136,11 +146,7 @@ xmlSecMSCryptoKeyDataCtxDuplicateProvider(xmlSecMSCryptoKeyDataCtxPtr ctxDst, xm
if(ctxSrc->hProv != 0) {
if(!CryptContextAddRef(ctxSrc->hProv, NULL, 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptContextAddRef",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptContextAddRef", NULL);
return(-1);
}
@@ -154,11 +160,12 @@ xmlSecMSCryptoKeyDataCtxDuplicateProvider(xmlSecMSCryptoKeyDataCtxPtr ctxDst, xm
/******************************** Key *****************************************/
#define xmlSecMSCryptoKeyDataCtxGetKey(ctx) ((ctx)->hKey)
-static void
+static int
xmlSecMSCryptoKeyDataCtxCreateKey(xmlSecMSCryptoKeyDataCtxPtr ctx) {
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
ctx->hKey = 0;
+ return(0);
}
static void
@@ -171,12 +178,13 @@ xmlSecMSCryptoKeyDataCtxDestroyKey(xmlSecMSCryptoKeyDataCtxPtr ctx) {
ctx->hKey = 0;
}
-static void
+static int
xmlSecMSCryptoKeyDataCtxSetKey(xmlSecMSCryptoKeyDataCtxPtr ctx, HCRYPTKEY hKey) {
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
xmlSecMSCryptoKeyDataCtxDestroyKey(ctx);
ctx->hKey = hKey;
+ return(0);
}
static int
@@ -187,11 +195,7 @@ xmlSecMSCryptoKeyDataCtxDuplicateKey(xmlSecMSCryptoKeyDataCtxPtr ctxDst, xmlSecM
xmlSecMSCryptoKeyDataCtxDestroyKey(ctxDst);
if (ctxSrc->hKey != 0) {
if (!CryptDuplicateKey(ctxSrc->hKey, NULL, 0, &(ctxDst->hKey))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptDuplicateKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptDuplicateKey", NULL);
return(-1);
}
}
@@ -204,58 +208,62 @@ xmlSecMSCryptoKeyDataCtxDuplicateKey(xmlSecMSCryptoKeyDataCtxPtr ctxDst, xmlSecM
/******************************** Provider *****************************************/
#define xmlSecMSCryptoKeyDataCtxGetProvider(ctx) (((ctx)->p_prov) ? ((ctx)->p_prov->hProv) : 0)
-static void
+static int
xmlSecMSCryptoKeyDataCtxCreateProvider(xmlSecMSCryptoKeyDataCtxPtr ctx) {
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
- ctx->p_prov = (struct _mscrypt_prov*)xmlMalloc(sizeof(struct _mscrypt_prov));
- if(ctx->p_prov == NULL ) {
- xmlSecError( XMLSEC_ERRORS_HERE,
- "mscrypt_create_prov" ,
- NULL,
- XMLSEC_ERRORS_R_MALLOC_FAILED ,
- XMLSEC_ERRORS_NO_MESSAGE
- );
- }
+ ctx->p_prov = (struct _mscrypt_prov*)xmlMalloc(sizeof(struct _mscrypt_prov));
+ if(ctx->p_prov == NULL) {
+ xmlSecMallocError(sizeof(struct _mscrypt_prov), NULL);
+ return(-1);
+ }
memset(ctx->p_prov, 0, sizeof(struct _mscrypt_prov));
+ return(0);
}
static void
xmlSecMSCryptoKeyDataCtxDestroyProvider(xmlSecMSCryptoKeyDataCtxPtr ctx) {
xmlSecAssert(ctx != NULL);
- if(ctx->p_prov != NULL) {
- if(InterlockedDecrement(&(ctx->p_prov->refcnt)) <= 0) {
- if((ctx->p_prov->hProv != 0) && (ctx->p_prov->fCallerFreeProv)) {
- CryptReleaseContext(ctx->p_prov->hProv, 0) ;
- }
+ if(ctx->p_prov != NULL) {
+ if(InterlockedDecrement(&(ctx->p_prov->refcnt)) <= 0) {
+ if((ctx->p_prov->hProv != 0) && (ctx->p_prov->fCallerFreeProv)) {
+ CryptReleaseContext(ctx->p_prov->hProv, 0) ;
+ }
memset(ctx->p_prov, 0, sizeof(struct _mscrypt_prov));
- xmlFree(ctx->p_prov) ;
- }
- ctx->p_prov = NULL;
+ xmlFree(ctx->p_prov) ;
}
+ ctx->p_prov = NULL;
+ }
}
-static void
+static int
xmlSecMSCryptoKeyDataCtxSetProvider(xmlSecMSCryptoKeyDataCtxPtr ctx, HCRYPTPROV hProv, BOOL fCallerFreeProv)
{
- xmlSecAssert(ctx != NULL);
+ int ret;
+
+ xmlSecAssert2(ctx != NULL, -1);
xmlSecMSCryptoKeyDataCtxDestroyProvider(ctx);
if((ctx->p_prov != NULL) && (ctx->p_prov->refcnt == 1)) {
- if((ctx->p_prov->hProv != 0) && (ctx->p_prov->fCallerFreeProv)) {
- CryptReleaseContext(ctx->p_prov->hProv, 0) ;
- }
+ if((ctx->p_prov->hProv != 0) && (ctx->p_prov->fCallerFreeProv)) {
+ CryptReleaseContext(ctx->p_prov->hProv, 0) ;
+ }
memset(ctx->p_prov, 0, sizeof(struct _mscrypt_prov));
} else {
xmlSecMSCryptoKeyDataCtxDestroyProvider(ctx);
- xmlSecMSCryptoKeyDataCtxCreateProvider(ctx);
+ ret = xmlSecMSCryptoKeyDataCtxCreateProvider(ctx);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxCreateProvider", NULL);
+ return(-1);
+ }
}
ctx->p_prov->hProv = hProv;
ctx->p_prov->fCallerFreeProv = fCallerFreeProv;
ctx->p_prov->refcnt = 1;
+ return(0);
}
static int
@@ -276,20 +284,17 @@ xmlSecMSCryptoKeyDataCtxDuplicateProvider(xmlSecMSCryptoKeyDataCtxPtr ctxDst, xm
/******************************** Key *****************************************/
#define xmlSecMSCryptoKeyDataCtxGetKey(ctx) (((ctx)->p_key) ? ((ctx)->p_key->hKey) : 0)
-static void
+static int
xmlSecMSCryptoKeyDataCtxCreateKey(xmlSecMSCryptoKeyDataCtxPtr ctx) {
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
- ctx->p_key = (struct _mscrypt_key*)xmlMalloc(sizeof(struct _mscrypt_key));
- if(ctx->p_key == NULL ) {
- xmlSecError( XMLSEC_ERRORS_HERE,
- "mscrypt_create_key" ,
- NULL,
- XMLSEC_ERRORS_R_MALLOC_FAILED ,
- XMLSEC_ERRORS_NO_MESSAGE
- );
- }
+ ctx->p_key = (struct _mscrypt_key*)xmlMalloc(sizeof(struct _mscrypt_key));
+ if(ctx->p_key == NULL ) {
+ xmlSecMallocError(sizeof(struct _mscrypt_key), NULL);
+ return(-1);
+ }
memset(ctx->p_key, 0, sizeof(struct _mscrypt_key));
+ return(0);
}
static void
@@ -308,21 +313,27 @@ xmlSecMSCryptoKeyDataCtxDestroyKey(xmlSecMSCryptoKeyDataCtxPtr ctx) {
}
}
-static void
+static int
xmlSecMSCryptoKeyDataCtxSetKey(xmlSecMSCryptoKeyDataCtxPtr ctx, HCRYPTKEY hKey) {
- xmlSecAssert(ctx != NULL);
+ int ret;
+ xmlSecAssert2(ctx != NULL, -1);
if((ctx->p_key != NULL) && (ctx->p_key->refcnt == 1)) {
- if(ctx->p_key->hKey != 0) {
- CryptDestroyKey(ctx->p_key->hKey) ;
- }
+ if(ctx->p_key->hKey != 0) {
+ CryptDestroyKey(ctx->p_key->hKey) ;
+ }
memset(ctx->p_key, 0, sizeof(struct _mscrypt_key));
} else {
xmlSecMSCryptoKeyDataCtxDestroyKey(ctx);
- xmlSecMSCryptoKeyDataCtxCreateKey(ctx);
+ ret = xmlSecMSCryptoKeyDataCtxCreateKey(ctx);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxCreateKey", NULL);
+ return(-1);
+ }
}
ctx->p_key->hKey = hKey;
ctx->p_key->refcnt = 1;
+ return(0);
}
static int
@@ -361,12 +372,13 @@ xmlSecMSCryptoKeyDataCtxDestroyCert(xmlSecMSCryptoKeyDataCtxPtr ctx) {
ctx->pCert = NULL;
}
-static void
+static int
xmlSecMSCryptoKeyDataCtxSetCert(xmlSecMSCryptoKeyDataCtxPtr ctx, PCCERT_CONTEXT pCert) {
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
xmlSecMSCryptoKeyDataCtxDestroyCert(ctx);
ctx->pCert = pCert;
+ return(0);
}
static int
@@ -378,11 +390,7 @@ xmlSecMSCryptoKeyDataCtxDuplicateCert(xmlSecMSCryptoKeyDataCtxPtr ctxDst, xmlSec
if(ctxSrc->pCert != NULL) {
ctxDst->pCert = xmlSecMSCryptoCertDup(ctxSrc->pCert);
if(ctxDst->pCert == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecMSCryptoPCCDup",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoPCCDup", NULL);
return(-1);
}
}
@@ -416,6 +424,7 @@ static int
xmlSecMSCryptoKeyDataAdoptCert(xmlSecKeyDataPtr data, PCCERT_CONTEXT pCert, xmlSecKeyDataType type) {
xmlSecMSCryptoKeyDataCtxPtr ctx;
HCRYPTKEY hKey = 0;
+ int ret;
xmlSecAssert2(xmlSecKeyDataIsValid(data), -1);
xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecMSCryptoKeyDataSize), -1);
@@ -445,34 +454,30 @@ xmlSecMSCryptoKeyDataAdoptCert(xmlSecKeyDataPtr data, PCCERT_CONTEXT pCert, xmlS
&hProv,
&(ctx->dwKeySpec),
&fCallerFreeProv)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptAcquireCertificatePrivateKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptAcquireCertificatePrivateKey", NULL);
return(-1);
}
- xmlSecMSCryptoKeyDataCtxSetProvider(ctx, hProv, fCallerFreeProv);
+ ret = xmlSecMSCryptoKeyDataCtxSetProvider(ctx, hProv, fCallerFreeProv);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetProvider", NULL);
+ return(-1);
+ }
} else if((type & xmlSecKeyDataTypePublic) != 0){
HCRYPTPROV hProv;
hProv = xmlSecMSCryptoFindProvider(ctx->providers, NULL, CRYPT_VERIFYCONTEXT, FALSE);
if (hProv == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecMSCryptoFindProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoFindProvider", NULL);
+ return(-1);
+ }
+ ret = xmlSecMSCryptoKeyDataCtxSetProvider(ctx, hProv, TRUE);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetProvider", NULL);
return(-1);
}
- xmlSecMSCryptoKeyDataCtxSetProvider(ctx, hProv, TRUE);
ctx->dwKeySpec = 0;
} else {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "Unsupported keytype");
+ xmlSecInvalidIntegerTypeError("keytype", type, "supported keytype", NULL);
return(-1);
}
@@ -480,23 +485,27 @@ xmlSecMSCryptoKeyDataAdoptCert(xmlSecKeyDataPtr data, PCCERT_CONTEXT pCert, xmlS
* is needed. The key handle is needed for de/encrypting and for
* verifying of a signature, *not* for signing. We could call
* CryptImportPublicKeyInfo in xmlSecMSCryptoKeyDataGetKey instead
- * so no unnessecary calls to CryptImportPublicKeyInfo are being
+ * so no unnecessary calls to CryptImportPublicKeyInfo are being
* made. WK
*/
if(!CryptImportPublicKeyInfo(xmlSecMSCryptoKeyDataCtxGetProvider(ctx),
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
&(pCert->pCertInfo->SubjectPublicKeyInfo),
&hKey)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptImportPublicKeyInfo",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptImportPublicKeyInfo", NULL);
return(-1);
}
- xmlSecMSCryptoKeyDataCtxSetKey(ctx, hKey);
- xmlSecMSCryptoKeyDataCtxSetCert(ctx, pCert);
+ ret = xmlSecMSCryptoKeyDataCtxSetKey(ctx, hKey);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetKey", NULL);
+ return(-1);
+ }
+ ret = xmlSecMSCryptoKeyDataCtxSetCert(ctx, pCert);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetCert", NULL);
+ return(-1);
+ }
return(0);
}
@@ -508,6 +517,7 @@ xmlSecMSCryptoKeyDataAdoptKey(xmlSecKeyDataPtr data,
DWORD dwKeySpec,
xmlSecKeyDataType type) {
xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
xmlSecAssert2(xmlSecKeyDataIsValid(data), -1);
xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecMSCryptoKeyDataSize), -1);
@@ -517,9 +527,21 @@ xmlSecMSCryptoKeyDataAdoptKey(xmlSecKeyDataPtr data,
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
xmlSecAssert2(ctx != NULL, -1);
- xmlSecMSCryptoKeyDataCtxSetProvider(ctx, hProv, fCallerFreeProv);
- xmlSecMSCryptoKeyDataCtxSetKey(ctx, hKey);
- xmlSecMSCryptoKeyDataCtxSetCert(ctx, NULL);
+ ret = xmlSecMSCryptoKeyDataCtxSetProvider(ctx, hProv, fCallerFreeProv);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetProvider", NULL);
+ return(-1);
+ }
+ ret = xmlSecMSCryptoKeyDataCtxSetKey(ctx, hKey);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetKey", NULL);
+ return(-1);
+ }
+ ret = xmlSecMSCryptoKeyDataCtxSetCert(ctx, NULL);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxSetCert", NULL);
+ return(-1);
+ }
ctx->dwKeySpec = dwKeySpec;
ctx->type = type;
@@ -546,6 +568,7 @@ xmlSecMSCryptoKeyDataGetKey(xmlSecKeyDataPtr data, xmlSecKeyDataType type) {
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
xmlSecAssert2(ctx != NULL, 0);
+ UNREFERENCED_PARAMETER(type);
return(xmlSecMSCryptoKeyDataCtxGetKey(ctx));
}
@@ -571,11 +594,7 @@ xmlSecMSCryptoKeyDataGetDecryptKey(xmlSecKeyDataPtr data) {
xmlSecAssert2(ctx != NULL, 0);
if( !CryptGetUserKey(xmlSecMSCryptoKeyDataCtxGetProvider(ctx), AT_KEYEXCHANGE, &(hKey))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptGetUserKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptGetUserKey", NULL);
return(0);
}
return (hKey);
@@ -645,6 +664,44 @@ xmlSecMSCryptoKeyDataGetMSCryptoKeySpec(xmlSecKeyDataPtr data) {
return(ctx->dwKeySpec);
}
+/**
+ * xmlSecMSCryptoKeyDataGetMSCryptoProviderInfo:
+ * @data: the key data
+ *
+ * Gets key provider info.
+ *
+ * Returns: the key provider info.
+ */
+PCRYPT_KEY_PROV_INFO
+xmlSecMSCryptoKeyDataGetMSCryptoProviderInfo(xmlSecKeyDataPtr data) {
+ xmlSecMSCryptoKeyDataCtxPtr ctx;
+ LPBYTE pInfoData = NULL;
+ DWORD dwInfoDataLength = 0;
+
+ xmlSecAssert2(data != NULL, NULL);
+
+ ctx = xmlSecMSCryptoKeyDataGetCtx(data);
+ xmlSecAssert2(ctx != NULL, NULL);
+ xmlSecAssert2(ctx->pCert != NULL, NULL);
+
+ if(!CertGetCertificateContextProperty(ctx->pCert, CERT_KEY_PROV_INFO_PROP_ID, NULL, &dwInfoDataLength)) {
+ xmlSecMSCryptoError("CertGetCertificateContextProperty", NULL);
+ return NULL;
+ }
+
+ if(dwInfoDataLength > 0) {
+ pInfoData = malloc(dwInfoDataLength * sizeof(BYTE));
+
+ if(!CertGetCertificateContextProperty(ctx->pCert, CERT_KEY_PROV_INFO_PROP_ID, pInfoData, &dwInfoDataLength)) {
+ xmlSecMSCryptoError("CertGetCertificateContextProperty", NULL);
+ free(pInfoData);
+ return NULL;
+ }
+ }
+
+ return (PCRYPT_KEY_PROV_INFO)pInfoData;
+}
+
static int
xmlSecMSCryptoKeyDataDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
xmlSecMSCryptoKeyDataCtxPtr ctxDst;
@@ -662,29 +719,20 @@ xmlSecMSCryptoKeyDataDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
xmlSecAssert2(ctxSrc != NULL, -1);
if(xmlSecMSCryptoKeyDataCtxDuplicateProvider(ctxDst, ctxSrc) < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(dst)),
- "xmlSecMSCryptoKeyDataCtxDuplicateProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxDuplicateProvider",
+ xmlSecKeyDataGetName(dst));
return(-1);
}
if(xmlSecMSCryptoKeyDataCtxDuplicateKey(ctxDst, ctxSrc) < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(dst)),
- "xmlSecMSCryptoKeyDataCtxDuplicateKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxDuplicateKey",
+ xmlSecKeyDataGetName(dst));
return(-1);
}
if(xmlSecMSCryptoKeyDataCtxDuplicateCert(ctxDst, ctxSrc) < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(dst)),
- "xmlSecMSCryptoKeyDataCtxDuplicateCert",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxDuplicateCert",
+ xmlSecKeyDataGetName(dst));
return(-1);
}
@@ -695,21 +743,31 @@ xmlSecMSCryptoKeyDataDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
return(0);
}
-static void
+static int
xmlSecMSCryptoKeyDataInitialize(xmlSecKeyDataPtr data) {
xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
- xmlSecAssert(xmlSecKeyDataIsValid(data));
- xmlSecAssert(xmlSecKeyDataCheckSize(data, xmlSecMSCryptoKeyDataSize));
+ xmlSecAssert2(xmlSecKeyDataIsValid(data), -1);
+ xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecMSCryptoKeyDataSize), -1);
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
- xmlSecAssert(ctx != NULL);
+ xmlSecAssert2(ctx != NULL, -1);
memset(ctx, 0, sizeof(xmlSecMSCryptoKeyDataCtx));
- xmlSecMSCryptoKeyDataCtxCreateProvider(ctx);
- xmlSecMSCryptoKeyDataCtxCreateKey(ctx);
+ ret = xmlSecMSCryptoKeyDataCtxCreateProvider(ctx);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxCreateProvider", NULL);
+ return(-1);
+ }
+ ret = xmlSecMSCryptoKeyDataCtxCreateKey(ctx);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataCtxCreateKey", NULL);
+ return(-1);
+ }
xmlSecMSCryptoKeyDataCtxCreateCert(ctx);
+ return(0);
}
static void
@@ -748,11 +806,7 @@ xmlSecMSCryptoKeyDataGetSize(xmlSecKeyDataPtr data) {
DWORD lenlen = sizeof(DWORD);
if (!CryptGetKeyParam(xmlSecMSCryptoKeyDataCtxGetKey(ctx), KP_KEYLEN, (BYTE *)&length, &lenlen, 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CertDuplicateCertificateContext",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CertDuplicateCertificateContext", NULL);
return(0);
}
return(length);
@@ -795,11 +849,7 @@ PCCERT_CONTEXT xmlSecMSCryptoCertDup(PCCERT_CONTEXT pCert) {
ret = CertDuplicateCertificateContext(pCert);
if(ret == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CertDuplicateCertificateContext",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CertDuplicateCertificateContext", NULL);
return(NULL);
}
@@ -829,11 +879,7 @@ xmlSecMSCryptoCertAdopt(PCCERT_CONTEXT pCert, xmlSecKeyDataType type) {
if (!strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_RSA_RSA)) {
data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataRsaId);
if(data == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyDataCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "xmlSecMSCryptoDataRsaId");
+ xmlSecInternalError("xmlSecKeyDataCreate(KeyDataRsaId)", NULL);
return(NULL);
}
}
@@ -843,11 +889,7 @@ xmlSecMSCryptoCertAdopt(PCCERT_CONTEXT pCert, xmlSecKeyDataType type) {
if (!strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_X957_DSA /*szOID_DSALG_SIGN*/)) {
data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataDsaId);
if(data == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyDataCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "xmlSecMSCryptoKeyDataDsaId");
+ xmlSecInternalError("xmlSecKeyDataCreate(KeyDataDsaId)", NULL);
return(NULL);
}
}
@@ -859,22 +901,34 @@ xmlSecMSCryptoCertAdopt(PCCERT_CONTEXT pCert, xmlSecKeyDataType type) {
!strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_MAGPRO_PUBKEY_SIGN_R3410_94_CP)) {
data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataGost2001Id);
if(data == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyDataCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "xmlSecMSCryptoKeyDataGost2001Id");
+ xmlSecInternalError("xmlSecKeyDataCreate(KeyDataGost2001Id)", NULL);
return(NULL);
}
}
#endif /* XMLSEC_NO_GOST*/
+#ifndef XMLSEC_NO_GOST2012
+ if (!strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_CP_GOST_R3410_12_256) ||
+ !strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_CP_GOST_R3411_12_256_R3410)) {
+ data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataGost2012_256Id);
+ if(data == NULL) {
+ xmlSecInternalError("xmlSecKeyDataCreate(KeyDataGost2012_256Id)", NULL);
+ return(NULL);
+ }
+ }
+ if (!strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_CP_GOST_R3410_12_512) ||
+ !strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, szOID_CP_GOST_R3411_12_512_R3410)) {
+ data = xmlSecKeyDataCreate(xmlSecMSCryptoKeyDataGost2012_512Id);
+ if(data == NULL) {
+ xmlSecInternalError("xmlSecKeyDataCreate(KeyDataGost2012_512Id)", NULL);
+ return(NULL);
+ }
+ }
+#endif /* XMLSEC_NO_GOST2012 */
if (NULL == data) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_INVALID_TYPE,
- "PCCERT_CONTEXT key type %s not supported", pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId);
+ xmlSecInvalidStringTypeError("PCCERT_CONTEXT key type",
+ pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId,
+ "unsupported keytype", NULL);
return(NULL);
}
@@ -882,11 +936,7 @@ xmlSecMSCryptoCertAdopt(PCCERT_CONTEXT pCert, xmlSecKeyDataType type) {
ret = xmlSecMSCryptoKeyDataAdoptCert(data, pCert, type);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecMSCryptoPCCDataAdoptPCC",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoPCCDataAdoptPCC", NULL);
xmlSecKeyDataDestroy(data);
return(NULL);
}
@@ -1023,10 +1073,15 @@ xmlSecMSCryptoKeyDataRsaGetKlass(void) {
static int
xmlSecMSCryptoKeyDataRsaInitialize(xmlSecKeyDataPtr data) {
xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataRsaId), xmlSecKeyDataTypeUnknown);
- xmlSecMSCryptoKeyDataInitialize(data);
+ ret = xmlSecMSCryptoKeyDataInitialize(data);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataInitialize", NULL);
+ return(-1);
+ }
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
xmlSecAssert2(ctx != NULL, -1);
@@ -1072,43 +1127,32 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
xmlSecAssert2(keyInfoCtx != NULL, -1);
if(xmlSecKeyGetValue(key) != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_KEY_DATA,
- "key already has a value");
+ xmlSecOtherError(XMLSEC_ERRORS_R_INVALID_KEY_DATA,
+ xmlSecKeyDataKlassGetName(id),
+ "key already has a value");
return(-1);
}
/* initialize buffers */
ret = xmlSecBnInitialize(&modulus, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "modulus");
+ xmlSecInternalError("xmlSecBnInitialize(modulus)",
+ xmlSecKeyDataKlassGetName(id));;
return(-1);
}
ret = xmlSecBnInitialize(&exponent, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "exponent");
+ xmlSecInternalError("xmlSecBnInitialize(exponent)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBnFinalize(&modulus);
return(-1);
}
ret = xmlSecBufferInitialize(&blob, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBufferInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "blob");
+ xmlSecInternalError("xmlSecBufferInitialize(blob)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBnFinalize(&modulus);
xmlSecBnFinalize(&exponent);
return(-1);
@@ -1119,45 +1163,28 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* first is Modulus node. It is REQUIRED because we do not support Seed and PgenCounter*/
if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeRSAModulus, xmlSecDSigNs))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAModulus));
+ xmlSecInvalidNodeError(cur, xmlSecNodeRSAModulus,
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecBnGetNodeValue(&modulus, cur, xmlSecBnBase64, 1);
- if((ret < 0) || (xmlSecBnGetSize(&modulus) == 0)){
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecBnGetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAModulus));
+ if((ret < 0) || (xmlSecBnGetSize(&modulus) == 0)) {
+ xmlSecInternalError("xmlSecBnGetNodeValue(modulus)",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
/* next is Exponent node. It is REQUIRED because we do not support Seed and PgenCounter*/
- if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeRSAExponent, xmlSecDSigNs))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAExponent));
+ if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeRSAExponent, xmlSecDSigNs))) {
+ xmlSecInvalidNodeError(cur, xmlSecNodeRSAExponent, xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecBnGetNodeValue(&exponent, cur, xmlSecBnBase64, 1);
if((ret < 0) || (xmlSecBnGetSize(&exponent) == 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecBnGetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAExponent));
+ xmlSecInternalError("xmlSecBnGetNodeValue(exponent)",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
@@ -1169,11 +1196,7 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
}
if(cur != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "no nodes expected");
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyDataKlassGetName(id));
goto done;
}
@@ -1181,11 +1204,9 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
blobBufferLen = sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY) + xmlSecBnGetSize(&modulus);
ret = xmlSecBufferSetSize(&blob, blobBufferLen);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecBufferSetSize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%d", blobBufferLen);
+ xmlSecInternalError2("xmlSecBufferSetSize",
+ xmlSecKeyDataKlassGetName(id),
+ "size=%d", blobBufferLen);
goto done;
}
@@ -1202,12 +1223,9 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
pubKey->bitlen = xmlSecBnGetSize(&modulus) * 8; /* Number of bits in prime modulus */
pubKey->pubexp = 0;
if(sizeof(pubKey->pubexp) < xmlSecBnGetSize(&exponent)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "exponent size=%d",
- xmlSecBnGetSize(&exponent));
+ xmlSecInvalidSizeLessThanError("exponent size",
+ sizeof(pubKey->pubexp), xmlSecBnGetSize(&exponent),
+ NULL);
goto done;
}
xmlSecAssert2(xmlSecBnGetData(&exponent) != NULL, -1);
@@ -1220,40 +1238,28 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* Now that we have the blob, import */
hProv = xmlSecMSCryptoFindProvider(xmlSecMSCryptoProviderInfo_Rsa, NULL, CRYPT_VERIFYCONTEXT, TRUE);
if(hProv == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecMSCryptoFindProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoFindProvider",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
if (!CryptImportKey(hProv, xmlSecBufferGetData(&blob), xmlSecBufferGetSize(&blob), 0, 0, &hKey)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "CryptImportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptImportKey",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
data = xmlSecKeyDataCreate(id);
if(data == NULL ) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyDataCreate",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecMSCryptoKeyDataAdoptKey(data, hProv, TRUE, hKey, 0, xmlSecKeyDataTypePublic);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecMSCryptoKeyDataAdoptKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataAdoptKey",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
hProv = 0;
@@ -1261,11 +1267,8 @@ xmlSecMSCryptoKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecKeySetValue(key, data);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeySetValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeySetValue",
+ xmlSecKeyDataKlassGetName(id));
xmlSecKeyDataDestroy(data);
goto done;
}
@@ -1315,40 +1318,29 @@ xmlSecMSCryptoKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
xmlSecAssert2(xmlSecMSCryptoKeyDataCtxGetKey(ctx) != 0, -1);
if (!CryptExportKey(xmlSecMSCryptoKeyDataCtxGetKey(ctx), 0, PUBLICKEYBLOB, 0, NULL, &dwBlobLen)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id));
return(-1);
}
ret = xmlSecBufferInitialize(&buf, dwBlobLen);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBufferInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%ld", dwBlobLen);
+ xmlSecInternalError2("xmlSecBufferInitialize",
+ xmlSecKeyDataKlassGetName(id),
+ "size=%ld", dwBlobLen);
return(-1);
}
blob = xmlSecBufferGetData(&buf);
if (!CryptExportKey(xmlSecMSCryptoKeyDataCtxGetKey(ctx), 0, PUBLICKEYBLOB, 0, blob, &dwBlobLen)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
if (dwBlobLen < sizeof(PUBLICKEYSTRUC)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_DATA,
- "blobLen=%ld", dwBlobLen);
+ xmlSecInvalidSizeLessThanError("Key blob", dwBlobLen, sizeof(PUBLICKEYSTRUC),
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -1356,20 +1348,18 @@ xmlSecMSCryptoKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* check PUBLICKEYSTRUC */
pubKeyStruc = (PUBLICKEYSTRUC*)blob;
if(pubKeyStruc->bVersion != 0x02) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "pubKeyStruc->bVersion=%d", pubKeyStruc->bVersion);
+ xmlSecMSCryptoError2("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id),
+ "pubKeyStruc->bVersion=%ld",
+ (long int)pubKeyStruc->bVersion);
xmlSecBufferFinalize(&buf);
return(-1);
}
if(pubKeyStruc->bType != PUBLICKEYBLOB) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "pubKeyStruc->bType=%d", (int)pubKeyStruc->bType);
+ xmlSecMSCryptoError2("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id),
+ "pubKeyStruc->bType=%ld",
+ (long int)pubKeyStruc->bType);
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -1377,22 +1367,19 @@ xmlSecMSCryptoKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* check RSAPUBKEY */
pubKey = (RSAPUBKEY *)(blob + sizeof(PUBLICKEYSTRUC));
if(pubKey->magic != 0x31415352) { /* RSA public key magic */
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "pubKey->magic=0x%08lx", pubKey->magic);
+ xmlSecMSCryptoError2("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id),
+ "pubKey->magic=0x%08lx",
+ (long int)pubKey->magic);
xmlSecBufferFinalize(&buf);
return(-1);
}
modulusLen = pubKey->bitlen / 8;
if (dwBlobLen < sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY) + modulusLen) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_DATA,
- "blobLen=%ld; modulusLen=%d", dwBlobLen, modulusLen);
+ xmlSecInvalidSizeLessThanError("Key blob",
+ dwBlobLen, sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY) + modulusLen,
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -1401,24 +1388,16 @@ xmlSecMSCryptoKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* first is Modulus node */
cur = xmlSecAddChild(node, xmlSecNodeRSAModulus, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAModulus));
+ xmlSecInternalError("xmlSecAddChild(NodeRSAModulus)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
ret = xmlSecBnBlobSetNodeValue(blob, modulusLen, cur, xmlSecBnBase64, 1, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnBlobSetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAModulus));
+ xmlSecInternalError("xmlSecBnBlobSetNodeValue(NodeRSAModulus)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -1426,12 +1405,8 @@ xmlSecMSCryptoKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* next is Exponent node. */
cur = xmlSecAddChild(node, xmlSecNodeRSAExponent, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAExponent));
+ xmlSecInternalError("xmlSecAddChild(NodeRSAExponent)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -1445,18 +1420,15 @@ xmlSecMSCryptoKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecBnBlobSetNodeValue(blob, exponentLen, cur, xmlSecBnBase64, 1, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnBlobSetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeRSAExponent));
+ xmlSecInternalError("xmlSecBnBlobSetNodeValue(NodeRSAExponent)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
/* next is PrivateExponent node: not supported in MSCrypto */
+ /* done */
xmlSecBufferFinalize(&buf);
return(0);
}
@@ -1476,6 +1448,7 @@ xmlSecMSCryptoKeyDataRsaGenerate(xmlSecKeyDataPtr data, xmlSecSize sizeBits,
xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecMSCryptoKeyDataSize), xmlSecKeyDataTypeUnknown);
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataRsaId), -1);
xmlSecAssert2(sizeBits > 0, -1);
+ UNREFERENCED_PARAMETER(type);
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
xmlSecAssert2(ctx != NULL, -1);
@@ -1483,33 +1456,24 @@ xmlSecMSCryptoKeyDataRsaGenerate(xmlSecKeyDataPtr data, xmlSecSize sizeBits,
/* get provider */
hProv = xmlSecMSCryptoFindProvider(ctx->providers, NULL, CRYPT_VERIFYCONTEXT, TRUE);
if(hProv == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "xmlSecMSCryptoFindProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoFindProvider",
+ xmlSecKeyDataGetName(data));
goto done;
}
dwKeySpec = AT_KEYEXCHANGE | AT_SIGNATURE;
dwSize = ((sizeBits << 16) | CRYPT_EXPORTABLE);
if (!CryptGenKey(hProv, CALG_RSA_SIGN, dwSize, &hKey)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "CryptGenKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptGenKey",
+ xmlSecKeyDataGetName(data));
goto done;
}
ret = xmlSecMSCryptoKeyDataAdoptKey(data, hProv, TRUE, hKey, dwKeySpec,
xmlSecKeyDataTypePublic | xmlSecKeyDataTypePrivate);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "xmlSecMSCryptoKeyDataAdoptKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataAdoptKey",
+ xmlSecKeyDataGetName(data));
goto done;
}
hProv = 0;
@@ -1723,10 +1687,15 @@ xmlSecMSCryptoKeyDataDsaGetKlass(void) {
static int
xmlSecMSCryptoKeyDataDsaInitialize(xmlSecKeyDataPtr data) {
xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataDsaId), xmlSecKeyDataTypeUnknown);
- xmlSecMSCryptoKeyDataInitialize(data);
+ ret = xmlSecMSCryptoKeyDataInitialize(data);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataInitialize", NULL);
+ return(-1);
+ }
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
xmlSecAssert2(ctx != NULL, -1);
@@ -1774,43 +1743,32 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
xmlSecAssert2(keyInfoCtx != NULL, -1);
if(xmlSecKeyGetValue(key) != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_KEY_DATA,
- "key already has a value");
+ xmlSecOtherError(XMLSEC_ERRORS_R_INVALID_KEY_DATA,
+ xmlSecKeyDataKlassGetName(id),
+ "key already has a value");
return(-1);
}
/* initialize buffers */
ret = xmlSecBnInitialize(&p, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "p");
+ xmlSecInternalError("xmlSecBnInitialize(p)",
+ xmlSecKeyDataKlassGetName(id));
return(-1);
}
ret = xmlSecBnInitialize(&q, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "q");
+ xmlSecInternalError("xmlSecBnInitialize(q)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBnFinalize(&p);
return(-1);
}
ret = xmlSecBnInitialize(&g, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "g");
+ xmlSecInternalError("xmlSecBnInitialize(g)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBnFinalize(&p);
xmlSecBnFinalize(&q);
return(-1);
@@ -1818,11 +1776,8 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecBnInitialize(&y, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "y");
+ xmlSecInternalError("xmlSecBnInitialize(y)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBnFinalize(&p);
xmlSecBnFinalize(&q);
xmlSecBnFinalize(&g);
@@ -1831,11 +1786,8 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecBufferInitialize(&blob, 0);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBufferInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "blob");
+ xmlSecInternalError("xmlSecBufferInitialize(blob)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBnFinalize(&p);
xmlSecBnFinalize(&q);
xmlSecBnFinalize(&g);
@@ -1848,67 +1800,40 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* first is P node. It is REQUIRED because we do not support Seed and PgenCounter*/
if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAP, xmlSecDSigNs))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAP));
+ xmlSecInvalidNodeError(cur, xmlSecNodeDSAP, xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecBnGetNodeValue(&p, cur, xmlSecBnBase64, 1);
- if((ret < 0) || (xmlSecBnGetSize(&p) == 0)){
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnGetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAP));
+ if((ret < 0) || (xmlSecBnGetSize(&p) == 0)) {
+ xmlSecInternalError("xmlSecBnGetNodeValue(p)",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
/* next is Q node. It is REQUIRED because we do not support Seed and PgenCounter*/
if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAQ, xmlSecDSigNs))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAQ));
+ xmlSecInvalidNodeError(cur, xmlSecNodeDSAQ, xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecBnGetNodeValue(&q, cur, xmlSecBnBase64, 1);
- if((ret < 0) || (xmlSecBnGetSize(&q) == 0)){
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnGetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAQ));
+ if((ret < 0) || (xmlSecBnGetSize(&q) == 0)) {
+ xmlSecInternalError("xmlSecBnGetNodeValue(q)",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
/* next is G node. It is REQUIRED because we do not support Seed and PgenCounter*/
if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAG, xmlSecDSigNs))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAG));
+ xmlSecInvalidNodeError(cur, xmlSecNodeDSAG, xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecBnGetNodeValue(&g, cur, xmlSecBnBase64, 1);
if((ret < 0) || (xmlSecBnGetSize(&q) == 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnGetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAG));
+ xmlSecInternalError("xmlSecBnGetNodeValue(g)",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
@@ -1922,21 +1847,13 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* next is Y node. */
if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAY, xmlSecDSigNs))) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAY));
+ xmlSecInvalidNodeError(cur, xmlSecNodeDSAY, xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecBnGetNodeValue(&y, cur, xmlSecBnBase64, 1);
if((ret < 0) || (xmlSecBnGetSize(&y) == 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnGetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s", xmlSecErrorsSafeString(xmlSecNodeDSAY));
+ xmlSecInternalError("xmlSecBnGetNodeValue(y)",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
@@ -1957,11 +1874,7 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
}
if(cur != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_UNEXPECTED_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyDataKlassGetName(id))
goto done;
}
@@ -1969,11 +1882,7 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
blobBufferLen = sizeof(PUBLICKEYSTRUC) + sizeof(DSSPUBKEY) + 3 * xmlSecBnGetSize(&p) + 0x14 + sizeof(DSSSEED);
ret = xmlSecBufferSetSize(&blob, blobBufferLen);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecBufferSetSize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%d", blobBufferLen);
+ xmlSecInternalError2("xmlSecBufferSetSize", NULL, "size=%d", blobBufferLen);
goto done;
}
@@ -1999,11 +1908,8 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* set q */
if(xmlSecBnGetSize(&q) > 0x14) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "q",
- XMLSEC_ERRORS_R_INVALID_SIZE,
- "size=%d > 0x14", xmlSecBnGetSize(&q));
+ xmlSecInvalidSizeLessThanError("DSA key q",
+ xmlSecBnGetSize(&q), 0x14, NULL);
goto done;
}
xmlSecAssert2(xmlSecBnGetData(&q) != NULL, -1);
@@ -2017,13 +1923,10 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* set generator */
if(xmlSecBnGetSize(&g) > xmlSecBnGetSize(&p)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "g",
- XMLSEC_ERRORS_R_INVALID_SIZE,
- "size=%d > %d",
- xmlSecBnGetSize(&g),
- xmlSecBnGetSize(&p));
+ xmlSecInvalidSizeMoreThanError("DSA key g",
+ xmlSecBnGetSize(&g),
+ xmlSecBnGetSize(&p),
+ NULL);
goto done;
}
xmlSecAssert2(xmlSecBnGetData(&g) != NULL, -1);
@@ -2036,13 +1939,10 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* Public key */
if(xmlSecBnGetSize(&y) > xmlSecBnGetSize(&p)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "y",
- XMLSEC_ERRORS_R_INVALID_SIZE,
- "size=%d > %d",
- xmlSecBnGetSize(&y),
- xmlSecBnGetSize(&p));
+ xmlSecInvalidSizeMoreThanError("DSA key y",
+ xmlSecBnGetSize(&y),
+ xmlSecBnGetSize(&p),
+ NULL);
goto done;
}
xmlSecAssert2(xmlSecBnGetData(&y) != NULL, -1);
@@ -2060,41 +1960,29 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
hProv = xmlSecMSCryptoFindProvider(xmlSecMSCryptoProviderInfo_Dss, NULL, CRYPT_VERIFYCONTEXT, TRUE);
if(hProv == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecMSCryptoFindProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoFindProvider",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
/* import the key blob */
if (!CryptImportKey(hProv, xmlSecBufferGetData(&blob), xmlSecBufferGetSize(&blob), 0, 0, &hKey)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "CryptImportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptImportKey",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
data = xmlSecKeyDataCreate(id);
if(data == NULL ) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyDataCreate",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecMSCryptoKeyDataAdoptKey(data, hProv, TRUE, hKey, 0, xmlSecKeyDataTypePublic);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "xmlSecMSCryptoKeyDataAdoptKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataAdoptKey",
+ xmlSecKeyDataGetName(data));
goto done;
}
hProv = 0;
@@ -2102,11 +1990,8 @@ xmlSecMSCryptoKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecKeySetValue(key, data);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "xmlSecKeySetValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeySetValue",
+ xmlSecKeyDataGetName(data));
goto done;
}
data = NULL;
@@ -2159,40 +2044,29 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
xmlSecAssert2(xmlSecMSCryptoKeyDataCtxGetKey(ctx) != 0, -1);
if (!CryptExportKey(xmlSecMSCryptoKeyDataCtxGetKey(ctx), 0, PUBLICKEYBLOB, 0, NULL, &dwBlobLen)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "CryptExportKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id));
return(-1);
}
ret = xmlSecBufferInitialize(&buf, dwBlobLen);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBufferInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%ld", dwBlobLen);
+ xmlSecInternalError2("xmlSecBufferInitialize",
+ xmlSecKeyDataKlassGetName(id),
+ "size=%ld", dwBlobLen);
return(-1);
}
blob = xmlSecBufferGetData(&buf);
if (!CryptExportKey(xmlSecMSCryptoKeyDataCtxGetKey(ctx), 0, PUBLICKEYBLOB, 0, blob, &dwBlobLen)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
if (dwBlobLen < sizeof(PUBLICKEYSTRUC)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_DATA,
- "blobLen=%ld", dwBlobLen);
+ xmlSecInvalidSizeLessThanError("Key blob", dwBlobLen, sizeof(PUBLICKEYSTRUC),
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2200,20 +2074,18 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* check PUBLICKEYSTRUC */
pubKeyStruc = (PUBLICKEYSTRUC*)blob;
if(pubKeyStruc->bVersion != 0x02) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "pubKeyStruc->bVersion=%d", pubKeyStruc->bVersion);
+ xmlSecMSCryptoError2("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id),
+ "pubKeyStruc->bVersion=%ld",
+ (long int)pubKeyStruc->bVersion);
xmlSecBufferFinalize(&buf);
return(-1);
}
if(pubKeyStruc->bType != PUBLICKEYBLOB) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "pubKeyStruc->bType=%d", (int)pubKeyStruc->bType);
+ xmlSecMSCryptoError2("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id),
+ "pubKeyStruc->bType=%ld",
+ (long int)pubKeyStruc->bType);
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2221,11 +2093,10 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* check DSSPUBKEY */
pubKey = (DSSPUBKEY*)(blob + sizeof(PUBLICKEYSTRUC));
if(pubKey->magic != 0x31535344) { /* DSS key magic */
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "CryptExportKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "pubKey->magic=0x%08lx", pubKey->magic);
+ xmlSecMSCryptoError2("CryptExportKey",
+ xmlSecKeyDataKlassGetName(id),
+ "pubKey->magic=0x%08lx",
+ (long int)pubKey->magic);
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2233,11 +2104,9 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* we assume that sizeof(q) < 0x14, sizeof(g) <= sizeof(p) and sizeof(y) <= sizeof(p) */
if (dwBlobLen < sizeof(PUBLICKEYSTRUC) + sizeof(DSSPUBKEY) + 3 * keyLen + 0x14 + sizeof(DSSSEED)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_DATA,
- "blobLen=%ld; keyLen=%d", dwBlobLen, keyLen);
+ xmlSecInvalidSizeLessThanError("Key blob",
+ dwBlobLen, sizeof(PUBLICKEYSTRUC) + sizeof(DSSPUBKEY) + 3 * keyLen + 0x14 + sizeof(DSSSEED),
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2246,24 +2115,16 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* first is P node */
cur = xmlSecAddChild(node, xmlSecNodeDSAP, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAP));
+ xmlSecInternalError("xmlSecAddChild(NodeDSAP)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
ret = xmlSecBnBlobSetNodeValue(blob, keyLen, cur, xmlSecBnBase64, 1, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnBlobSetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAP));
+ xmlSecInternalError("xmlSecBnBlobSetNodeValue(NodeDSAP)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2272,12 +2133,8 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* next is Q node. */
cur = xmlSecAddChild(node, xmlSecNodeDSAQ, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAQ));
+ xmlSecInternalError("xmlSecAddChild(NodeDSAQ)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2287,12 +2144,8 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecBnBlobSetNodeValue(blob, len, cur, xmlSecBnBase64, 1, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnBlobSetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAQ));
+ xmlSecInternalError("xmlSecBnBlobSetNodeValue(NodeDSAQ)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2301,12 +2154,8 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* next is G node. */
cur = xmlSecAddChild(node, xmlSecNodeDSAG, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAG));
+ xmlSecInternalError("xmlSecAddChild(NodeDSAG)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2316,12 +2165,8 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecBnBlobSetNodeValue(blob, len, cur, xmlSecBnBase64, 1, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnBlobSetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAG));
+ xmlSecInternalError("xmlSecBnBlobSetNodeValue(NodeDSAG)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2332,12 +2177,8 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
/* next is Y node. */
cur = xmlSecAddChild(node, xmlSecNodeDSAY, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAY));
+ xmlSecInternalError("xmlSecAddChild(NodeDSAY)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2347,12 +2188,8 @@ xmlSecMSCryptoKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
ret = xmlSecBnBlobSetNodeValue(blob, len, cur, xmlSecBnBase64, 1, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecBnBlobSetNodeValue",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeDSAY));
+ xmlSecInternalError("xmlSecBnBlobSetNodeValue(NodeDSAY)",
+ xmlSecKeyDataKlassGetName(id));
xmlSecBufferFinalize(&buf);
return(-1);
}
@@ -2376,38 +2213,30 @@ xmlSecMSCryptoKeyDataDsaGenerate(xmlSecKeyDataPtr data, xmlSecSize sizeBits, xml
xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecMSCryptoKeyDataSize), xmlSecKeyDataTypeUnknown);
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataDsaId), -1);
xmlSecAssert2(sizeBits > 0, -1);
+ UNREFERENCED_PARAMETER(type);
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
hProv = xmlSecMSCryptoFindProvider(ctx->providers, NULL, CRYPT_VERIFYCONTEXT, TRUE);
if(hProv == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "xmlSecMSCryptoFindProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoFindProvider",
+ xmlSecKeyDataGetName(data));
return(-1);
}
dwKeySpec = AT_SIGNATURE;
dwSize = ((sizeBits << 16) | CRYPT_EXPORTABLE);
if (!CryptGenKey(hProv, CALG_DSS_SIGN, dwSize, &hKey)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "CryptGenKey",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptGenKey",
+ xmlSecKeyDataGetName(data));
goto done;
}
ret = xmlSecMSCryptoKeyDataAdoptKey(data, hProv, TRUE, hKey, dwKeySpec,
xmlSecKeyDataTypePublic | xmlSecKeyDataTypePrivate);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)),
- "xmlSecMSCryptoKeyDataAdoptKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoKeyDataAdoptKey",
+ xmlSecKeyDataGetName(data));
goto done;
}
hProv = 0;
@@ -2555,10 +2384,15 @@ xmlSecMSCryptoKeyDataGost2001GetKlass(void) {
static int
xmlSecMSCryptoKeyDataGost2001Initialize(xmlSecKeyDataPtr data) {
xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2001Id), xmlSecKeyDataTypeUnknown);
- xmlSecMSCryptoKeyDataInitialize(data);
+ ret = xmlSecMSCryptoKeyDataInitialize(data);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataInitialize", NULL);
+ return(-1);
+ }
ctx = xmlSecMSCryptoKeyDataGetCtx(data);
xmlSecAssert2(ctx != NULL, -1);
@@ -2612,4 +2446,318 @@ xmlSecMSCryptoKeyDataGost2001DebugXmlDump(xmlSecKeyDataPtr data, FILE* output) {
xmlSecMSCryptoKeyDataGost2001GetSize(data));
}
-#endif /* XMLSEC_NO_GOST*/
+#endif /* XMLSEC_NO_GOST */
+
+
+#ifndef XMLSEC_NO_GOST2012
+
+/**************************************************************************
+ *
+ * GOST2012 256 xml key representation processing.
+ *
+ *************************************************************************/
+static int xmlSecMSCryptoKeyDataGost2012_256Initialize(xmlSecKeyDataPtr data);
+static int xmlSecMSCryptoKeyDataGost2012_256Duplicate(xmlSecKeyDataPtr dst,
+ xmlSecKeyDataPtr src);
+static void xmlSecMSCryptoKeyDataGost2012_256Finalize(xmlSecKeyDataPtr data);
+static int xmlSecMSCryptoKeyDataGost2012_256XmlRead (xmlSecKeyDataId id,
+ xmlSecKeyPtr key,
+ xmlNodePtr node,
+ xmlSecKeyInfoCtxPtr keyInfoCtx);
+static int xmlSecMSCryptoKeyDataGost2012_256XmlWrite(xmlSecKeyDataId id,
+ xmlSecKeyPtr key,
+ xmlNodePtr node,
+ xmlSecKeyInfoCtxPtr keyInfoCtx);
+static int xmlSecMSCryptoKeyDataGost2012_256Generate(xmlSecKeyDataPtr data,
+ xmlSecSize sizeBits,
+ xmlSecKeyDataType type);
+
+static xmlSecKeyDataType xmlSecMSCryptoKeyDataGost2012_256GetType(xmlSecKeyDataPtr data);
+static xmlSecSize xmlSecMSCryptoKeyDataGost2012_256GetSize(xmlSecKeyDataPtr data);
+static void xmlSecMSCryptoKeyDataGost2012_256DebugDump(xmlSecKeyDataPtr data,
+ FILE* output);
+static void xmlSecMSCryptoKeyDataGost2012_256DebugXmlDump(xmlSecKeyDataPtr data,
+ FILE* output);
+
+static xmlSecKeyDataKlass xmlSecMSCryptoKeyDataGost2012_256Klass = {
+ sizeof(xmlSecKeyDataKlass),
+ xmlSecMSCryptoKeyDataSize,
+
+ /* data */
+ xmlSecNameGostR3410_2012_256KeyValue,
+ xmlSecKeyDataUsageKeyValueNode | xmlSecKeyDataUsageRetrievalMethodNodeXml,
+ /* xmlSecKeyDataUsage usage; */
+ xmlSecHrefGostR3410_2012_256KeyValue, /* const xmlChar* href; */
+ xmlSecNodeGostR3410_2012_256KeyValue, /* const xmlChar* dataNodeName; */
+ xmlSecDSigNs, /* const xmlChar* dataNodeNs; */
+
+ /* constructors/destructor */
+ xmlSecMSCryptoKeyDataGost2012_256Initialize, /* xmlSecKeyDataInitializeMethod initialize; */
+ xmlSecMSCryptoKeyDataGost2012_256Duplicate, /* xmlSecKeyDataDuplicateMethod duplicate; */
+ xmlSecMSCryptoKeyDataGost2012_256Finalize, /* xmlSecKeyDataFinalizeMethod finalize; */
+ NULL, /* xmlSecMSCryptoKeyDataGost2001Generate,*/ /* xmlSecKeyDataGenerateMethod generate; */
+
+ /* get info */
+ xmlSecMSCryptoKeyDataGost2012_256GetType, /* xmlSecKeyDataGetTypeMethod getType; */
+ xmlSecMSCryptoKeyDataGost2012_256GetSize, /* xmlSecKeyDataGetSizeMethod getSize; */
+ NULL, /* xmlSecKeyDataGetIdentifier getIdentifier; */
+
+ /* read/write */
+ NULL, /* xmlSecKeyDataXmlReadMethod xmlRead; */
+ NULL, /* xmlSecKeyDataXmlWriteMethod xmlWrite; */
+ NULL, /* xmlSecKeyDataBinReadMethod binRead; */
+ NULL, /* xmlSecKeyDataBinWriteMethod binWrite; */
+
+ /* debug */
+ xmlSecMSCryptoKeyDataGost2012_256DebugDump, /* xmlSecKeyDataDebugDumpMethod debugDump; */
+ xmlSecMSCryptoKeyDataGost2012_256DebugXmlDump,/* xmlSecKeyDataDebugDumpMethod debugXmlDump; */
+
+ /* reserved for the future */
+ NULL, /* void* reserved0; */
+ NULL, /* void* reserved1; */
+};
+
+/* Ordered list of providers to search for algorithm implementation using
+ * xmlSecMSCryptoFindProvider() function
+ *
+ * MUST END with { NULL, 0 } !!!
+ */
+static xmlSecMSCryptoProviderInfo xmlSecMSCryptoProviderInfo_Gost2012_256[] = {
+ { CRYPTOPRO_CSP_256, PROV_GOST_2012_256 },
+ { NULL, 0 }
+};
+
+/**
+ * xmlSecMSCryptoKeyDataGost2001GetKlass:
+ *
+ * The GOST2012_256 key data klass.
+ *
+ * Returns: pointer to GOST2012_256 key data klass.
+ */
+xmlSecKeyDataId
+xmlSecMSCryptoKeyDataGost2012_256GetKlass(void) {
+ return(&xmlSecMSCryptoKeyDataGost2012_256Klass);
+}
+
+
+static int
+xmlSecMSCryptoKeyDataGost2012_256Initialize(xmlSecKeyDataPtr data) {
+ xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
+
+ xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_256Id), xmlSecKeyDataTypeUnknown);
+
+ ret = xmlSecMSCryptoKeyDataInitialize(data);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataInitialize", NULL);
+ return(-1);
+ }
+
+ ctx = xmlSecMSCryptoKeyDataGetCtx(data);
+ xmlSecAssert2(ctx != NULL, -1);
+
+ ctx->providers = xmlSecMSCryptoProviderInfo_Gost2012_256;
+ return(0);
+}
+
+static int
+xmlSecMSCryptoKeyDataGost2012_256Duplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
+ xmlSecAssert2(xmlSecKeyDataCheckId(dst, xmlSecMSCryptoKeyDataGost2012_256Id), -1);
+ xmlSecAssert2(xmlSecKeyDataCheckId(src, xmlSecMSCryptoKeyDataGost2012_256Id), -1);
+
+ return(xmlSecMSCryptoKeyDataDuplicate(dst, src));
+}
+
+static void
+xmlSecMSCryptoKeyDataGost2012_256Finalize(xmlSecKeyDataPtr data) {
+ xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_256Id));
+
+ xmlSecMSCryptoKeyDataFinalize(data);
+}
+
+static xmlSecKeyDataType
+xmlSecMSCryptoKeyDataGost2012_256GetType(xmlSecKeyDataPtr data) {
+ return(xmlSecMSCryptoKeyDataGetType(data));
+}
+
+static xmlSecSize
+xmlSecMSCryptoKeyDataGost2012_256GetSize(xmlSecKeyDataPtr data) {
+ xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_256Id), 0);
+
+ return xmlSecMSCryptoKeyDataGetSize(data);
+}
+
+static void
+xmlSecMSCryptoKeyDataGost2012_256DebugDump(xmlSecKeyDataPtr data, FILE* output) {
+ xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_256Id));
+ xmlSecAssert(output != NULL);
+
+ fprintf(output, "=== dsa key: size = %d\n",
+ xmlSecMSCryptoKeyDataGost2012_256GetSize(data));
+}
+
+static void
+xmlSecMSCryptoKeyDataGost2012_256DebugXmlDump(xmlSecKeyDataPtr data, FILE* output) {
+ xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_256Id));
+ xmlSecAssert(output != NULL);
+
+ fprintf(output, "<GOST2012_256KeyValue size=\"%d\" />\n",
+ xmlSecMSCryptoKeyDataGost2012_256GetSize(data));
+}
+
+
+/**************************************************************************
+ *
+ * GOST2012 512 xml key representation processing.
+ *
+ *************************************************************************/
+static int xmlSecMSCryptoKeyDataGost2012_512Initialize(xmlSecKeyDataPtr data);
+static int xmlSecMSCryptoKeyDataGost2012_512Duplicate(xmlSecKeyDataPtr dst,
+ xmlSecKeyDataPtr src);
+static void xmlSecMSCryptoKeyDataGost2012_512Finalize(xmlSecKeyDataPtr data);
+static int xmlSecMSCryptoKeyDataGost2012_512XmlRead (xmlSecKeyDataId id,
+ xmlSecKeyPtr key,
+ xmlNodePtr node,
+ xmlSecKeyInfoCtxPtr keyInfoCtx);
+static int xmlSecMSCryptoKeyDataGost2012_512XmlWrite(xmlSecKeyDataId id,
+ xmlSecKeyPtr key,
+ xmlNodePtr node,
+ xmlSecKeyInfoCtxPtr keyInfoCtx);
+static int xmlSecMSCryptoKeyDataGost2012_512Generate(xmlSecKeyDataPtr data,
+ xmlSecSize sizeBits,
+ xmlSecKeyDataType type);
+
+static xmlSecKeyDataType xmlSecMSCryptoKeyDataGost2012_512GetType(xmlSecKeyDataPtr data);
+static xmlSecSize xmlSecMSCryptoKeyDataGost2012_512GetSize(xmlSecKeyDataPtr data);
+static void xmlSecMSCryptoKeyDataGost2012_512DebugDump(xmlSecKeyDataPtr data,
+ FILE* output);
+static void xmlSecMSCryptoKeyDataGost2012_512DebugXmlDump(xmlSecKeyDataPtr data,
+ FILE* output);
+
+static xmlSecKeyDataKlass xmlSecMSCryptoKeyDataGost2012_512Klass = {
+ sizeof(xmlSecKeyDataKlass),
+ xmlSecMSCryptoKeyDataSize,
+
+ /* data */
+ xmlSecNameGostR3410_2012_512KeyValue,
+ xmlSecKeyDataUsageKeyValueNode | xmlSecKeyDataUsageRetrievalMethodNodeXml,
+ /* xmlSecKeyDataUsage usage; */
+ xmlSecHrefGostR3410_2012_512KeyValue, /* const xmlChar* href; */
+ xmlSecNodeGostR3410_2012_512KeyValue, /* const xmlChar* dataNodeName; */
+ xmlSecDSigNs, /* const xmlChar* dataNodeNs; */
+
+ /* constructors/destructor */
+ xmlSecMSCryptoKeyDataGost2012_512Initialize, /* xmlSecKeyDataInitializeMethod initialize; */
+ xmlSecMSCryptoKeyDataGost2012_512Duplicate, /* xmlSecKeyDataDuplicateMethod duplicate; */
+ xmlSecMSCryptoKeyDataGost2012_512Finalize, /* xmlSecKeyDataFinalizeMethod finalize; */
+ NULL, /* xmlSecMSCryptoKeyDataGost2001Generate,*/ /* xmlSecKeyDataGenerateMethod generate; */
+
+ /* get info */
+ xmlSecMSCryptoKeyDataGost2012_512GetType, /* xmlSecKeyDataGetTypeMethod getType; */
+ xmlSecMSCryptoKeyDataGost2012_512GetSize, /* xmlSecKeyDataGetSizeMethod getSize; */
+ NULL, /* xmlSecKeyDataGetIdentifier getIdentifier; */
+
+ /* read/write */
+ NULL, /* xmlSecKeyDataXmlReadMethod xmlRead; */
+ NULL, /* xmlSecKeyDataXmlWriteMethod xmlWrite; */
+ NULL, /* xmlSecKeyDataBinReadMethod binRead; */
+ NULL, /* xmlSecKeyDataBinWriteMethod binWrite; */
+
+ /* debug */
+ xmlSecMSCryptoKeyDataGost2012_512DebugDump, /* xmlSecKeyDataDebugDumpMethod debugDump; */
+ xmlSecMSCryptoKeyDataGost2012_512DebugXmlDump,/* xmlSecKeyDataDebugDumpMethod debugXmlDump; */
+
+ /* reserved for the future */
+ NULL, /* void* reserved0; */
+ NULL, /* void* reserved1; */
+};
+
+/* Ordered list of providers to search for algorithm implementation using
+ * xmlSecMSCryptoFindProvider() function
+ *
+ * MUST END with { NULL, 0 } !!!
+ */
+static xmlSecMSCryptoProviderInfo xmlSecMSCryptoProviderInfo_Gost2012_512[] = {
+ { CRYPTOPRO_CSP_512, PROV_GOST_2012_512 },
+ { NULL, 0 }
+};
+
+/**
+ * xmlSecMSCryptoKeyDataGost2001GetKlass:
+ *
+ * The GOST2012_512 key data klass.
+ *
+ * Returns: pointer to GOST2012_512 key data klass.
+ */
+xmlSecKeyDataId
+xmlSecMSCryptoKeyDataGost2012_512GetKlass(void) {
+ return(&xmlSecMSCryptoKeyDataGost2012_512Klass);
+}
+
+
+static int
+xmlSecMSCryptoKeyDataGost2012_512Initialize(xmlSecKeyDataPtr data) {
+ xmlSecMSCryptoKeyDataCtxPtr ctx;
+ int ret;
+
+ xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_512Id), xmlSecKeyDataTypeUnknown);
+
+ ret = xmlSecMSCryptoKeyDataInitialize(data);
+ if(ret != 0) {
+ xmlSecInternalError("xmlSecMSCryptoKeyDataInitialize", NULL);
+ return(-1);
+ }
+
+ ctx = xmlSecMSCryptoKeyDataGetCtx(data);
+ xmlSecAssert2(ctx != NULL, -1);
+
+ ctx->providers = xmlSecMSCryptoProviderInfo_Gost2012_512;
+ return(0);
+}
+
+static int
+xmlSecMSCryptoKeyDataGost2012_512Duplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
+ xmlSecAssert2(xmlSecKeyDataCheckId(dst, xmlSecMSCryptoKeyDataGost2012_512Id), -1);
+ xmlSecAssert2(xmlSecKeyDataCheckId(src, xmlSecMSCryptoKeyDataGost2012_512Id), -1);
+
+ return(xmlSecMSCryptoKeyDataDuplicate(dst, src));
+}
+
+static void
+xmlSecMSCryptoKeyDataGost2012_512Finalize(xmlSecKeyDataPtr data) {
+ xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_512Id));
+
+ xmlSecMSCryptoKeyDataFinalize(data);
+}
+
+static xmlSecKeyDataType
+xmlSecMSCryptoKeyDataGost2012_512GetType(xmlSecKeyDataPtr data) {
+ return(xmlSecMSCryptoKeyDataGetType(data));
+}
+
+static xmlSecSize
+xmlSecMSCryptoKeyDataGost2012_512GetSize(xmlSecKeyDataPtr data) {
+ xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_512Id), 0);
+
+ return xmlSecMSCryptoKeyDataGetSize(data);
+}
+
+static void
+xmlSecMSCryptoKeyDataGost2012_512DebugDump(xmlSecKeyDataPtr data, FILE* output) {
+ xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_512Id));
+ xmlSecAssert(output != NULL);
+
+ fprintf(output, "=== dsa key: size = %d\n",
+ xmlSecMSCryptoKeyDataGost2012_512GetSize(data));
+}
+
+static void
+xmlSecMSCryptoKeyDataGost2012_512DebugXmlDump(xmlSecKeyDataPtr data, FILE* output) {
+ xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecMSCryptoKeyDataGost2012_512Id));
+ xmlSecAssert(output != NULL);
+
+ fprintf(output, "<GOST2012_512KeyValue size=\"%d\" />\n",
+ xmlSecMSCryptoKeyDataGost2012_512GetSize(data));
+}
+
+#endif /* XMLSEC_NO_GOST2012 */