无法使用 d2i_SSL_SESSION 反序列化 SSL_SESSION
我想重用 SSL_SESSION,因此我使用 i2d_SSL_SESSION() 对其进行序列化,并使用 d2i_SSL_SESSION 进行反序列化。但是d2i_SSL_SESSION失败了,测试代码很简单:
ssl握手完成后
SSL_SESSION *session = SSL_get1_session(ssl);
int len = i2d_SSL_SESSION(session, NULL);
unsigned char *pp = new unsigned char[len];
len = i2d_SSL_SESSION(session, &pp);
SSL_SESSION *s_new = d2i_SSL_SESSION(NULL, (const unsigned char **)&pp, len);
ERR_print_errors_fp(stderr);
cout << "s_new = " << s_new << endl;
i2d_SSL_SESSION没问题,len = 2205
但是d2i_SSL_SESSION失败了,s_new为NULL,错误信息为: 3078067960:错误:0D06703D:asn1编码例程:a2i_ASN1_STRING:期望asn1序列:ssl_asn1.c:370:地址= 3219682277偏移= 0
我错过了什么吗?
I want to reuse SSL_SESSION, so I use i2d_SSL_SESSION() to serialise it, and d2i_SSL_SESSION to unserialise. But the d2i_SSL_SESSION failed, the test code is very simple:
after the ssl handshake finished
SSL_SESSION *session = SSL_get1_session(ssl);
int len = i2d_SSL_SESSION(session, NULL);
unsigned char *pp = new unsigned char[len];
len = i2d_SSL_SESSION(session, &pp);
SSL_SESSION *s_new = d2i_SSL_SESSION(NULL, (const unsigned char **)&pp, len);
ERR_print_errors_fp(stderr);
cout << "s_new = " << s_new << endl;
the i2d_SSL_SESSION is ok, and the len = 2205
but d2i_SSL_SESSION failed, the s_new is NULL, the error message is:
3078067960:error:0D06703D:asn1 encoding routines:a2i_ASN1_STRING:expecting an asn1 sequence:ssl_asn1.c:370:address=3219682277 offset=0
Do I miss something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
i2d_SSL_SESSION
增加pp
指向的指针,使其指向保存的数据后的一个字节(不幸的是,手册页在这一点上不是很清楚)。请尝试改为:
请注意,
d2i_SSL_SESSION()
以相同的方式递增传递的指针。d2i_X509()
手册页是有关 OpenSSL 中所有d2i_*()
和i2d_*()
函数一般行为的最佳文档。i2d_SSL_SESSION
increments the pointer pointed to bypp
to point one byte after the saved data (unfortunately, the man page isn't very clear on this point).Try instead:
Note that
d2i_SSL_SESSION()
increments the passed pointer in the same way. Thed2i_X509()
man page is the best documentation on the general behaviour of all thed2i_*()
andi2d_*()
functions in OpenSSL.