Статус: Новичок
Группы: Участники
Зарегистрирован: 01.03.2016(UTC) Сообщений: 3  Откуда: Санкт-Петербург
|
Добрый день. Пытаюсь создать подпись CADES_BES. Получаю 80070057 Кусок кода: Код:
if not CryptAcquireCertificatePrivateKey(Cert, CRYPT_ACQUIRE_CACHE_FLAG, nil, hProvider, @dwKeyType, @bReleaseContext) then
raise Exception.Create('CryptAcquireCertificatePrivateKey');
if Password <> NullString then
begin
sPasswd:= cStrPas(Password)+#0;
Passwd:= AllocMem(Length(sPasswd));
Move(sPasswd[1], Passwd^, Length(sPasswd));
if not CryptSetProvParam(hProvider, PP_KEYEXCHANGE_PIN, Passwd, 0) then
raise Exception.Create('CryptSetProvParam');
Freemem(Passwd);
Passwd:=nil;
end;
end;
FillChar(SignParam, SizeOf(SignParam), 0);
SignParam.cbSize:= SizeOf(SignParam);
SignParam.dwMsgEncodingType:=MY_ENCODING;
SignParam.pSigningCert:=Cert;
SignParam.HashAlgorithm.pszObjId:= szOID_CP_GOST_R3411;
//SignParam.cMsgCert:= 1;
//SignParam.rgpMsgCert:=@Cert;
{$ifdef unix}
//SignParam.dwFlags:=CRYPT_MESSAGE_SILENT_KEYSET_FLAG;
{$endif}
FillChar(cadesSignPara, sizeof(cadesSignPara), 0);
FillChar(tspPara, sizeof(tspPara), 0);
FillChar(para, SizeOf(para), 0);
cadesSignPara.dwSize := sizeof(cadesSignPara);
if ATSPLink = '' then
cadesSignPara.dwCadesType := CADES_BES
else
begin
cadesSignPara.dwCadesType := CADES_X_LONG_TYPE_1;
tspPara.dwSize := sizeof(tspPara);
tspPara.wszUri := PWideChar(ATSPLink);
cadesSignPara.pTspConnectionPara := @tspPara;
end;
para.dwSize := sizeof(para);
para.pSignMessagePara := @SignParam;
para.pCadesSignPara := @cadesSignPara;
pOutBuf := nil;
pbMessage:=AInBuffer;
cbMessage:=AInBufferSize;
try
MessageArray[0] := pbMessage;
MessageSize[0] := cbMessage;
cbSignMessage:= 0;
if not CadesSignMessage(@para, True, 1, @MessageArray, @MessageSize, pOutBuf) then
raise Exception.CreateFmt('CadesSignMessage %s', [IntToHex(GetLastError(), 10)]);
AOutSize := pOutBuf^.cbData;
AOutBuffer := AllocMem(AOutSize);
move(pOutBuf^.pbData^, AOutBuffer^, AOutSize);
CadesFreeBlob(pOutBuf);
Result := True;
finally
if bReleaseContext and (hProvider > 0) then
CryptReleaseContext(hProvider, 0);
end;
Лог: Код:
1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesSignMessage (pSignPara=0x0x7fffffffdfe8, fDetachedSignature=1, cToBeSigned=1, rgpbToBeSigned=0x0x7fffffffe048, rgcbToBeSigned=0x0x7fffffffe044, ppSignedBlob=0x0x7fffffffdfc8)
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesSignMessageImpl Signer updating start
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesSignMessageImpl #011Hash algorithm deduced
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: AttributeExists (pAttr=0)
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: UpdateSignedAttributes #011Signer does not have any of signing-certificate attributes
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: UpdateSignedAttributes #011Attributes copied
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: UpdateSignedAttributes #011signing-certificate(-v2) attribute assembled
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: UpdateSignedAttributes #011Signer is updated successfully
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncode (dwMsgEncodingType=0x00010001, dwFlags=0x00000004, pvMsgEncodeInfo=0x0x7fffffffdb80, pszInnerContentObjID=0, pStreamInfo=0x(nil))
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl Start
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl Input parameters checked
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl Copy of input structures is ready
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl Signers updating start
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl Signer #0
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CheckAlgorithms #011Public key info is exported successfully
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CheckAlgorithms #011Signature algoritm OID info is found: 1.2.643.2.2.3
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl #011Certificates equality checked
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: DeduceHashAlgorithm (szHashAlgorithm=1.2.643.2.2.9)
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl #011Hash algorithm deduced
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: AttributeExists (pAttr->pszObjId=1.2.840.113549.1.9.16.2.47)
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncodeImpl Calling CryptMsgOpenToEncode()
Mar 1 10:19:03 prosoftVBU pcsc[8006]: cades: CadesMsgOpenToEncode (hMsg=0x0xe93590, GetLastError=0x00000000)
Mar 1 10:19:04 prosoftVBU pcsc[8006]: capi20: CryptMsgGetParam () Exception :'������ 0xea: More data is available.' at file:'/dailybuildsbranches/CSP_3_6r4/CSPbuild/CSP/capilite/CMSMessage.h' line:155
Mar 1 10:19:04 prosoftVBU pcsc[8006]: cades: copy Assert FAILED: sizeof(_CADES_SIGN_PARA) >= src.dwSize
Mar 1 10:19:04 prosoftVBU pcsc[8006]: cades: CadesSignMessage CAtlException, m_hr=0x80070057
Mar 1 10:19:04 prosoftVBU pcsc[8006]: cades: CadesSignMessage (res=0, GetLastError=0x80070057
Что я делаю не так?
|