【发布时间】:2019-11-07 10:13:04
【问题描述】:
我正在编写一个客户端,该客户端通过连接到 Google 服务器的 TCP 套接字发送消息来参与 TLS 1.2 握手。我正在使用 ECDH 密钥交换方法。
我使用this 代码生成了客户端密钥对,现在我想将 ClientKeyExchange 发送到包含公钥的服务器。 为此,我首先需要将 EVP_PKEY 中包含的密钥传输到缓冲区中。我已经对服务器 peerkey 进行了相反的转换,但我现在还没有弄清楚该怎么做。
我的代码是:
void get_buffer(EVP_PKEY * pkey, unsigned char * client_pub_key, int pkeyLen) {
EC_KEY *tempEcKey = NULL;
tempEcKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
if(0 == (EVP_PKEY_set1_EC_KEY(pkey, tempEcKey))){
handleErrors();
}
const EC_GROUP * group = EC_KEY_get0_group(tempEcKey);
point_conversion_form_t form = EC_GROUP_get_point_conversion_form(group);
//write in the buffer
pkeyLen = EC_KEY_key2buf(tempEcKey, form, *client_pub_key, NULL);
if(pkeyLen == 0){
handleErrors();
}
}
代码在调用EVP_PKEY_set1_EC_KEY(pkey, tempEcKey)时导致分段错误。
我做错了什么?
我还查看了EVP_PKEY_get_raw_public_key() 函数,但它也不起作用。 docs
【问题讨论】:
标签: openssl tls1.2 public-key-exchange