Статус: Новичок
Группы: Участники
Зарегистрирован: 09.12.2011(UTC) Сообщений: 3
|
Добрый день! Столкнулся с такой проблемой: Я использую Crypto Pro CSP версии 3.6.64.97. Для работы я взял пример http://www.cryptopro.ru/docs/cp...xample_SigningHash.html . Идея проста: на одной машине подписываются какие-то данные и прикладывается к ним открытый ключ(в формате PUBLICKEYBLOB ) + плюс сама подпись. На другой машине эта подпись проверяется. Мне необходимо получить информацию о подписчике(данные его сертификата). Я импортирую открытый ключ. Соответственно, после этого у меня есть его хэндл(HCryptKey). Код:
if(CryptImportKey(
hProv,
pbKeyBlob,
dwBlobLen,
0,
0,
&hPubKey))
{
printf("The key has been imported.\n");
}
else
{
HandleError("Public key import failed.");
}
Подскажите, пожалуйста, как получить информацию о сертификате по его дескриптору(HCryptKey)? P.s. Пробовал следующим образом: Код:
BYTE* pbCert = NULL;
DWORD pcbCert = 0;
PCCERT_CONTEXT certContext;
IMSCertification_info_struct cert_struct;
CryptGetKeyParam(
hPubKey,//импортированный ключ из BLOB-a
KP_CERTIFICATE,
NULL,
&pcbCert,
0);
pbCert = (BYTE*) malloc(pcbCert);
CryptGetKeyParam(hPubKey,
KP_CERTIFICATE,
pbCert,
&pcbCert,
0);
certContext = CertCreateCertificateContext(
TYPE_DER,
pbCert,
pcbCert);
free(pbCert);
DWORD cbDecoded;
CryptDecodeObjectEx(
certContext->dwCertEncodingType,
X509_NAME,
certContext->pCertInfo->Subject.pbData,
certContext->pCertInfo->Subject.cbData,
CRYPT_DECODE_NOCOPY_FLAG,
NULL,
NULL,
&cbDecoded);
BYTE* pbDecoded = (BYTE *) malloc(cbDecoded);
CryptDecodeObjectEx(
certContext->dwCertEncodingType,
X509_NAME,
certContext->pCertInfo->Subject.pbData,
certContext->pCertInfo->Subject.cbData,
CRYPT_DECODE_NOCOPY_FLAG,
NULL,
pbDecoded,
&cbDecoded);
CERT_NAME_INFO* pDecodedName = (CERT_NAME_INFO *) pbDecoded;
//дальше вытаскиваю все необходимые параметы:
cert_struct.mail = get_certificate_subject_param(pDecodedName, szOID_RSA_emailAddr, _UTF8);
cert_struct.name = get_certificate_subject_param(pDecodedName, szOID_COMMON_NAME, _WCHAR);
cert_struct.country = get_certificate_subject_param(pDecodedName, szOID_COUNTRY_NAME, _UTF8);
QString IMS::GUI4::IMSCrypto_adapter::get_certificate_subject_param(CERT_NAME_INFO* pDecodedName, char* param_type , int codec_type) {
QString res;
CERT_RDN_ATTR* DecodedAttr = CertFindRDNAttr(
param_type,
pDecodedName);
if (DecodedAttr != 0) {
CERT_RDN_VALUE_BLOB AttrValue = DecodedAttr->Value;
BYTE* Value = AttrValue.pbData;
char* chaEAdress = (char*) Value;
if( codec_type == _UTF8) //костыль, пока нет времени разбираться
{
res = QString::fromLatin1((const char*)Value);
}
else if( codec_type == _WCHAR )
{
res = QString::fromWCharArray((const wchar_t*)Value);
}
}
return res;
}
В итоге я получаю информацию о своем сертификате. Подскажите, пожалуйста, пути решения?
|