【问题标题】:TLS 1.3 handshake Failure - Client reports "Header Too Long"TLS 1.3 握手失败 - 客户端报告“标头过长”
【发布时间】:2021-10-05 07:35:35
【问题描述】:

我正在更新客户端以支持 TLS 1.3。尝试连接到 TLS 1.3 服务器时,客户端报告“内部错误”。 Wireshark 跟踪显示该服务器以 Verify Certificate, Finished 消息响应。但是客户端无法使用以下调用堆栈生成密钥 -

 libcrypto-1_1.dll!ASN1_get_object(const unsigned char * * pp, long * plength, int * ptag, int * pclass, long omax) Line 101
 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) Line 287
 [Inline Frame] libcrypto-1_1.dll!ASN1_item_ex_d2i(ASN1_VALUE_st * *) Line 124
 libcrypto-1_1.dll!ASN1_item_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it) Line 114
 libcrypto-1_1.dll!d2i_X509_SIG(X509_sig_st * * a, const unsigned char * * in, long len) Line 21    
 MyCode.dll!PrivateKeyOperationCallback(ssl_st * pSSL, unsigned int type, unsigned int rsakeysize, const unsigned char * hash, unsigned int hashlen, unsigned char * sig, unsigned int sigmaxlen, unsigned int * siglen)
 [Inline Frame] MyCode.dll!My_RSA_private_encrypt1(ssl_st *)
 MyCode.dll!My_RSA_private_encrypt(int flen, const unsigned char * from, unsigned char * to, rsa_st * rsa, int padding)
 libcrypto-1_1.dll!pkey_rsa_sign(evp_pkey_ctx_st * ctx, unsigned char * sig, unsigned int * siglen, const unsigned char * tbs, unsigned int tbslen) Line 185
 libcrypto-1_1.dll!EVP_PKEY_sign(evp_pkey_ctx_st * ctx, unsigned char * sig, unsigned int * siglen, const unsigned char * tbs, unsigned int tbslen) Line 66
 libcrypto-1_1.dll!EVP_DigestSignFinal(evp_md_ctx_st * ctx, unsigned char * sigret, unsigned int * siglen) Line 148
 libcrypto-1_1.dll!EVP_DigestSign(evp_md_ctx_st * ctx, unsigned char * sigret, unsigned int * siglen, const unsigned char * tbs, unsigned int tbslen) Line 170
 libssl-1_1.dll!tls_construct_cert_verify(ssl_st * s, wpacket_st * pkt) Line 307
 libssl-1_1.dll!write_state_machine(ssl_st * s) Line 843
 libssl-1_1.dll!state_machine(ssl_st * s, int server) Line 443
 libssl-1_1.dll!ossl_statem_connect(ssl_st * s) Line 250
 libssl-1_1.dll!SSL_do_handshake(ssl_st * s) Line 3661
 libssl-1_1.dll!SSL_connect(ssl_st * s) Line 1662

ASN1_get_object 返回“标头过长”。同一个客户端可以使用 TLS 1.2 连接到同一台服务器,甚至可以使用 TLS 1.3 从浏览器连接到同一台服务器。

问题出在 mTLS(与 TLS 无关)。

【问题讨论】:

  • 您说相同的代码在 1.3 上失败并且能够与 1.3 连接。你真的是指别的东西吗,比如 1.2?
  • 错字。已更正。

标签: ssl openssl client-side tls1.3


【解决方案1】:

该代码路径不是 TLS 1.3 独有的,并且在 OpenSSL / libcrypto 中已经存在很长时间了。

发生错误是因为证书中编码的 ASN.1 对象的确定长度超过了所提供数据的长度。证书数据已损坏,或者服务器未发送正确的数据。

如果您自己实现 TLS 1.3 客户端,则您的代码可能无法正确处理证书加密,从而导致将乱码数据发送到 ASN.1 解析代码路径。如果没有更多信息(Wireshark 转储和证书本身),就不可能知道具体的错误是什么。

【讨论】:

  • 什么证书加密?您的意思是构建数字签名吗?
  • TLS 1.3 对 ServerHello 之后的所有内容进行加密。这包括证书。该行为在RFC8446 中进行了描述。
  • 我在这里看不到任何证书的证据。 'MyCode.dll' 被调用来执行 RSA signing (用于歇斯底里的葡萄干的 OpenSSL 有时称为 RSA_private_encrypt)并且出于某种原因调用 d2i_X509_SIG 来解析 DigestInfo(不是整个证书),我看不到 RSA 签名应该解析 DigestInfo 的合理理由——除非它可能从带有 MAC 的 PKCS12 获取私钥。我会查看“MyCode.dll”中的代码。
  • 在高层序列是相同的,但 TLS 1.3 代码在 get_cert_verify_tbs_data 等几个地方和其他几个地方不同。由于浏览器能够使用 TLS 1.3 连接到同一服务器,因此服务器发送损坏或不正确数据的可能性较小。即使服务器发送的数据不正确,浏览器也能很好地处理。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 2019-02-28
  • 2019-08-18
  • 1970-01-01
  • 1970-01-01
  • 2015-12-08
  • 2016-11-19
相关资源
最近更新 更多