使用vs2013 x86命令构建openssl 1.1.1g
perl Configure VC-WIN32
这段代码在Linux上运行良好,但在Windows上不起作用。怎么了?
声明:
...
typedef struct SES_Signature_0031_st {
TBS_Sign_0031* toSign;
ASN1_BIT_STRING* signature;
} SES_Signature_0031;
DECLARE_ASN1_FUNCTIONS(SES_Signature_0031)
实施:
...
ASN1_SEQUENCE(SES_Signature_0031) = {
ASN1_SIMPLE(SES_Signature_0031, toSign, TBS_Sign_0031),
ASN1_SIMPLE(SES_Signature_0031, signature, ASN1_BIT_STRING)
}ASN1_SEQUENCE_END(SES_Signature_0031)
IMPLEMENT_ASN1_FUNCTIONS(SES_Signature_0031)
使用:
//work well
std::string cert = read_file("./signer.cer", "rb+");
const unsigned char *p_cert_buffer = (unsigned char *)cert.c_str();
X509 *x509 = d2i_X509(nullptr, &p_cert_buffer, cert.length());
ASN1_INTEGER *serial_number = X509_get_serialNumber(x509);
std::cout << to_hex_string(serial_number->data, serial_number->length) << "n";
自定义流:
std::string signed_value = read_file("./SignedValue.dat", "rb+");
const unsigned char *p_signed_value_buffer = (unsigned char *)signed_value.c_str();
//crashed when d2i
SES_Signature_0031 *signature_0031 = d2i_SES_Signature_0031(nullptr, &p_signed_value_buffer, signed_value.length());
堆栈信息:
libcrypto-1_1.dll!ASN1_item_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it)
libcrypto-1_1.dll!ASN1_item_ex_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it, int tag, int aclass, char opt, ASN1_TLC_st * ctx)
libcrypto-1_1.dll!asn1_item_embed_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it, int tag, int aclass, char opt, ASN1_TLC_st * ctx, int depth)
libcrypto-1_1.dll!ASN1_item_ex_new(ASN1_VALUE_st * * pval, const ASN1_ITEM_st * it)
libcrypto-1_1.dll!asn1_item_embed_new(ASN1_VALUE_st * * pval, const ASN1_ITEM_st * it, int embed)
libcrypto-1_1.dll!asn1_template_new(ASN1_VALUE_st * * pval, const ASN1_TEMPLATE_st * tt) line 204
tasn_new.c第204行:
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
另一种用法:
std::string signed_value = read_file("./SignedValue.dat", "rb+");
unsigned char signed_value_buffer[10000] = { 0 };
int signed_value_buffer_len = 10000;
signed_value_buffer_len = signed_value.length();
memcpy(signed_value_buffer, signed_value.c_str(), signed_value.length());
//crashed when d2i
SES_Signature_0031 *signature_0031_2 = d2i_SES_Signature_0031(nullptr, (const unsigned char**)&signed_value_buffer, signed_value_buffer_len);
堆栈信息:
libcrypto-1_1.dll!ASN1_item_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it)
libcrypto-1_1.dll!ASN1_item_ex_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it, int tag, int aclass, char opt, ASN1_TLC_st * ctx)
libcrypto-1_1.dll!asn1_item_embed_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it, int tag, int aclass, char opt, ASN1_TLC_st * ctx, int depth)
libcrypto-1_1.dll!asn1_check_tlen(long * olen, int * otag, unsigned char * oclass, char * inf, char * cst, const unsigned char * * in, long len, int exptag, int expclass, char opt, ASN1_TLC_st * ctx)
libcrypto-1_1.dll!ASN1_get_object(const unsigned char * * pp, long * plength, int * ptag, int * pclass, long omax) line 55
asn1_lib.c第55行:
ret = (*p & V_ASN1_CONSTRUCTED);
使用了不正确的Linux 64位头文件。在替换VC-Win32编译和安装头文件后,解决了该解决方案