当前位置: 首页 > news >正文

从PkiAsn1Decode函数到ASN1Dec_SignedDataWithBlobs函数

从PkiAsn1Decode函数到ASN1Dec_SignedDataWithBlobs函数

第一部分:

//+-------------------------------------------------------------------------
//  Update for decoding a signed message
//--------------------------------------------------------------------------
BOOL
WINAPI
ICM_UpdateDecodingSignedData(
IN OUT PCRYPT_MSG_INFO pcmi,
IN const BYTE *pbData,
IN DWORD cbData)
{
DWORD               dwError = ERROR_SUCCESS;
BOOL                fRet;
SignedDataWithBlobs *psdb = NULL;
PBYTE               pb = NULL;
DWORD               cb;
ASN1error_e         Asn1Err;
ASN1decoding_t      pDec = ICM_GetDecoder();
PBYTE               pbDER = NULL;
DWORD               cbDER;
ICM_HASH_INFO       HashInfo;       ZEROSTRUCT(HashInfo);

    DWORD dwExceptionCode;

  // Handle MappedFile Exceptions
__try {

    if (PHASE_FIRST_FINAL == pcmi->dwPhase) {
if (0 != (Asn1Err = PkiAsn1Decode(
pDec,
(void **)&psdb,
SignedDataWithBlobs_PDU,
pbData,
cbData)))

第二部分:


//+-------------------------------------------------------------------------
//  Asn1 Decode function. The allocated, decoded structure, **pvAsn1Info, must
//  be freed by calling PkiAsn1FreeDecoded().
//--------------------------------------------------------------------------
ASN1error_e
WINAPI
PkiAsn1Decode(
IN ASN1decoding_t pDec,
OUT void **ppvAsn1Info,
IN ASN1uint32_t id,
IN const BYTE *pbEncoded,
IN DWORD cbEncoded
)
{
ASN1error_e Asn1Err;

    *ppvAsn1Info = NULL;
Asn1Err = ASN1_Decode(
pDec,
ppvAsn1Info,
id,
ASN1DECODE_SETBUFFER,
(BYTE *) pbEncoded,
cbEncoded
);
if (ASN1_SUCCEEDED(Asn1Err))
Asn1Err = ASN1_SUCCESS;
else {
if (ASN1_ERR_BADARGS == Asn1Err)
Asn1Err = ASN1_ERR_EOD;
*ppvAsn1Info = NULL;
}
return Asn1Err;
}

第三部分:

/* decode a value */
ASN1error_e ASN1_Decode
(
ASN1decoding_t      dec,
void              **valref,
ASN1uint32_t        id,
ASN1uint32_t        flags,
ASN1octet_t        *pbBuf,
ASN1uint32_t        cbBufSize
)
{


else
if (ASN1_BER_RULE & dec->eRule)
{
ASN1BerDecFun_t pfnBER;
/* decode value */
if (NULL != (pfnBER = dec->module->BER.apfnDecoder[id]))
{
if ((*pfnBER)(dec, 0, *valref)) // lonchanc: tag is 0 to make it compiled
{
ASN1BERDecFlush(dec);
}


第四部分:


ASN1module_t ASN1_CreateModule
(
ASN1uint32_t            version,
ASN1encodingrule_e      eEncodingRule,
ASN1uint32_t            dwFlags,
ASN1uint32_t            cPDUs,
const ASN1GenericFun_t  apfnEncoder[],
const ASN1GenericFun_t  apfnDecoder[],
const ASN1FreeFun_t     apfnFreeMemory[],
const ASN1uint32_t      acbStructSize[],
ASN1magic_t             nModuleName
)
{
ASN1module_t module = NULL;

    /* compiler output and library version match together? */
if (
// version <= ASN1_THIS_VERSION &&
NULL != apfnEncoder             &&
NULL != apfnDecoder             &&
NULL != apfnFreeMemory          &&
NULL != acbStructSize)
{
if (NULL != (module = (ASN1module_t)MemAlloc(sizeof(*module), nModuleName)))
{
module->nModuleName = nModuleName;
module->eRule = eEncodingRule;
module->dwFlags = dwFlags;
module->cPDUs = cPDUs;

            module->apfnFreeMemory = apfnFreeMemory;
module->acbStructSize = acbStructSize;

            if (ASN1_PER_RULE & eEncodingRule)
{
module->PER.apfnEncoder = (const ASN1PerEncFun_t *) apfnEncoder;
module->PER.apfnDecoder = (const ASN1PerDecFun_t *) apfnDecoder;
}
#ifdef ENABLE_BER
else
if (ASN1_BER_RULE & eEncodingRule)
{
module->BER.apfnEncoder = (const ASN1BerEncFun_t *) apfnEncoder;
module->BER.apfnDecoder = (const ASN1BerDecFun_t *) apfnDecoder;
}
#endif // ENABLE_BER
}
}
return module;
}

第五部分:


void ASN1CALL PKCS_Module_Startup(void)
{
PKCS_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 48, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x73636b70);
}

第六部分:


};
typedef ASN1BerDecFun_t ASN1DecFun_t;
static const ASN1DecFun_t decfntab[48] = {
(ASN1DecFun_t) ASN1Dec_ObjectID,                            0
(ASN1DecFun_t) ASN1Dec_ObjectIdentifierType,
(ASN1DecFun_t) ASN1Dec_OctetStringType,
(ASN1DecFun_t) ASN1Dec_IntegerType,
(ASN1DecFun_t) ASN1Dec_HugeIntegerType,
(ASN1DecFun_t) ASN1Dec_AlgorithmIdentifier,
(ASN1DecFun_t) ASN1Dec_AlgorithmIdentifierNC2,
(ASN1DecFun_t) ASN1Dec_AlgorithmIdentifiers,
(ASN1DecFun_t) ASN1Dec_AttributeSetValue,
(ASN1DecFun_t) ASN1Dec_AttributeSetValueNC,
(ASN1DecFun_t) ASN1Dec_SetOfAny,                            10
(ASN1DecFun_t) ASN1Dec_AttributeNC2,
(ASN1DecFun_t) ASN1Dec_Attributes,
(ASN1DecFun_t) ASN1Dec_AttributesNC,
(ASN1DecFun_t) ASN1Dec_AttributesNC2,
(ASN1DecFun_t) ASN1Dec_CrlsNC,
(ASN1DecFun_t) ASN1Dec_CertificatesNC,
(ASN1DecFun_t) ASN1Dec_IssuerAndSerialNumber,
(ASN1DecFun_t) ASN1Dec_ContentInfo,
(ASN1DecFun_t) ASN1Dec_ContentInfoNC,                        19
(ASN1DecFun_t) ASN1Dec_DigestAlgorithmIdentifiersNC,            20
(ASN1DecFun_t) ASN1Dec_SignerInfos,
(ASN1DecFun_t) ASN1Dec_DigestAlgorithmBlobs,
(ASN1DecFun_t) ASN1Dec_SignerInfosNC,
(ASN1DecFun_t) ASN1Dec_SignerInfoWithAABlobs,
(ASN1DecFun_t) ASN1Dec_SignerInfoWithAABlob,
(ASN1DecFun_t) ASN1Dec_SignerInfoWithAttrBlobs,
(ASN1DecFun_t) ASN1Dec_SignerInfoWithBlobs,
(ASN1DecFun_t) ASN1Dec_RecipientInfos,
(ASN1DecFun_t) ASN1Dec_EncryptedContentInfo,
(ASN1DecFun_t) ASN1Dec_RecipientInfo,                        30
(ASN1DecFun_t) ASN1Dec_SignedAndEnvelopedData,
(ASN1DecFun_t) ASN1Dec_DigestedData,
(ASN1DecFun_t) ASN1Dec_EncryptedData,
(ASN1DecFun_t) ASN1Dec_CertIdentifier,
(ASN1DecFun_t) ASN1Dec_OriginatorInfo,
(ASN1DecFun_t) ASN1Dec_OriginatorInfoNC,
(ASN1DecFun_t) ASN1Dec_CmsRecipientInfos,
(ASN1DecFun_t) ASN1Dec_KeyTransRecipientInfo,
(ASN1DecFun_t) ASN1Dec_DigestInfo,
(ASN1DecFun_t) ASN1Dec_SignedData,                        40
(ASN1DecFun_t) ASN1Dec_SignerInfo,
(ASN1DecFun_t) ASN1Dec_SignedDataWithBlobs,                42
(ASN1DecFun_t) ASN1Dec_EnvelopedData,
(ASN1DecFun_t) ASN1Dec_CmsEnvelopedData,
(ASN1DecFun_t) ASN1Dec_MailListRecipientInfo,
(ASN1DecFun_t) ASN1Dec_KeyAgreeRecipientInfo,
(ASN1DecFun_t) ASN1Dec_CmsRecipientInfo,
};


第七部分:

chenghao@chenghaodeiMac srv03rtm % grep "SignedDataWithBlobs_PDU" -nr ./ds/security/cryptoapi |grep -v "inary"
./ds/security/cryptoapi/pki/wincrmsg/wincrmsg.cpp:9789:                SignedDataWithBlobs_PDU,
./ds/security/cryptoapi/pki/wincrmsg/wincrmsg.cpp:9850:    PkiAsn1FreeInfo(pDec, SignedDataWithBlobs_PDU, psdb);
./ds/security/cryptoapi/pki/wincrmsg/wincrmsg.cpp:16372:            SignedDataWithBlobs_PDU,
./ds/security/cryptoapi/pki/wincrmsg/pkcs.h:535:#define SignedDataWithBlobs_PDU 42
chenghao@chenghaodeiMac srv03rtm % 


第八部分:


static int ASN1CALL ASN1Dec_SignedDataWithBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignedDataWithBlobs *val)
{
ASN1decoding_t dd;
ASN1octet_t *di;
ASN1uint32_t t;
if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
return 0;
ZeroMemory((val)->o, 1);
if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
return 0;
if (!ASN1Dec_DigestAlgorithmIdentifiersNC(dd, 0, &(val)->digestAlgorithms))
return 0;
if (!ASN1Dec_ContentInfoNC(dd, 0, &(val)->contentInfo))
return 0;
ASN1BERDecPeekTag(dd, &t);
if (t == 0x80000000) {
(val)->o[0] |= 0x80;
if (!ASN1Dec_CertificatesNC(dd, 0x80000000, &(val)->certificates))
return 0;
}
ASN1BERDecPeekTag(dd, &t);
if (t == 0x80000001) {
(val)->o[0] |= 0x40;
if (!ASN1Dec_CrlsNC(dd, 0x80000001, &(val)->crls))
return 0;
}
if (!ASN1Dec_SignerInfosNC(dd, 0, &(val)->signerInfos))
return 0;
if (!ASN1BERDecEndOfContents(dec, dd, di))
return 0;
return 1;
}

第九部分:第二个例子A:


BOOL
WINAPI
#ifdef DEBUG_CRYPT_ASN1_MASTER
ICMTest_NewCryptMsgUpdate(
#else
CryptMsgUpdate(
#endif
IN HCRYPTMSG    hCryptMsg,
IN const BYTE   *pbData,
IN DWORD        cbData,
IN BOOL         fFinal)
{

        if ((PHASE_FIRST_FINAL == pcmi->dwPhase) &&
(0 == pcmi->dwMsgType)) {
if (0 != (Asn1Err = PkiAsn1Decode(
pDec,
(void **)&pci,
ContentInfoNC_PDU,
pbData,
cbData)))

第十部分:第二个例子B:


static int ASN1CALL ASN1Dec_ContentInfoNC(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfoNC *val)
{
ASN1decoding_t dd;
ASN1octet_t *di;
ASN1uint32_t t;
ASN1decoding_t dd0;
ASN1octet_t *di0;
if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
return 0;
ZeroMemory((val)->o, 1);
if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
return 0;
if (ASN1BERDecPeekTag(dd, &t)) {
if (t == 0x80000000) {
(val)->o[0] |= 0x80;
if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
return 0;
if (!ASN1BERDecOpenType2(dd0, &(val)->content))
return 0;
if (!ASN1BERDecEndOfContents(dd, dd0, di0))
return 0;
}
}
if (!ASN1BERDecEndOfContents(dec, dd, di))
return 0;
return 1;
}

http://www.dtcms.com/a/365843.html

相关文章:

  • 中山AI搜索优化实践:技术干货解析与金拓智能案例
  • select, poll, epoll
  • 【108】基于51单片机智能输液监测系统【Proteus仿真+Keil程序+报告+原理图】
  • 详尽 | Deeplabv3+结构理解
  • CSS中使用 HSL(Hue, Saturation, Lightness) 动态生成色值
  • 二叉树结尾——销毁,层序遍历与判断完全二叉树
  • python如何解决html格式不规范问题
  • windows系统服务器测试部署springboot+vue+mysql项目
  • 使用 Acme.sh 获取和管理免费 SSL 证书
  • vue2头部布局示例
  • Anaconda3出现Fatal error in launcher: Unable to create process using.....问题
  • python 连接数据库进行文件查重(SAP版本)
  • RoPE位置编码缩放因子的最优解:频率维度与位置敏感度的精妙权衡
  • TypeScript:Promise的详细用法讲解
  • 面试复习题--kotlin的设计模式
  • shell内置命令
  • UART更好的封装 添加容错代码
  • Qt6用Chart模块做数据可视化?别再用老套路,看看这套35张图背后的秘密
  • [密码学实战](GBT 15843.2-2017)Java实现基于SM4的实体鉴别机制(四十八)
  • MinIO祭了,RustFS来了!
  • 关于node中的一些用到的读取文件方法
  • Dubbo3单端口多协议源码分析
  • 员工拍照泄密?U盘偷拷资料?终端数据安全如何守护?
  • G1垃圾收集器
  • 【高级】系统架构师 | 信息系统战略规划、EAI 与新技术
  • 攻防世界secret-galaxy-300
  • 深度学习----卷积神经网络的数据增强
  • 如何给JavaScript语句添加注释?
  • 19.JS
  • Jmeter怎么实现接口关联?