gpt4 book ai didi

ssl - 在 ESP8266 (Arduino IDE) 上使用 BearSSL 进行指纹验证

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:25 24 4
gpt4 key购买 nike

我使用的是 Arduino 提供的库中的 BearSSL,即 WiFiSecureClient 类。我使用引用实现在简单的 Python 实现的服务器和作为客户端的 ESP8266 板之间获得安全的 TCP 连接。

我使用 OpenSSL 导出了 key 和证书,并使用它们来提供 Python 套接字 SSL 包装器。一切正常,可以交换消息,但是 WifiSecureClient 无法验证证书。这是节点的部分代码:

void handle() {
// Use WiFiClientSecure class to create TLS connection

WiFiClientSecure client;
client.allowSelfSignedCerts();

Serial.print("connecting to ");
Serial.println(host);

if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}

if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}


client.print("Some Message");
Serial.println("request sent");

String line;
while (client.connected()) {
line = client.readStringUntil('\n');
}

Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
client.stop();
}

如前所述,我可以发送和接收消息(我不知道它们是加密的还是回退未加密的)但是步骤

  if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}

总是失败。指纹是使用 OpenSSL 作为 SHA1 key 导出的。我通过使用另一台 PC 连接到服务器、获取证书并重新计算其指纹来仔细检查了这一点。如果我尝试联系像 api.github.com 这样的公共(public)服务器(在示例中是默认的),代码就可以正常工作。如您所见,我已经通过调用 BearSSL 的适当 API 方法允许自签名证书。

有没有我遗漏的东西,例如我必须有一个完整的 key 扣或什么的吗?

提前致谢!

最佳答案

请注意,verify() 的“主机”参数必须与证书通用名称匹配(在您的情况下为 *.github.com 或 api.github.com):

测试:openssl s_client -connect api.github.com:443

输出:0 s:/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=*.github.com

关于ssl - 在 ESP8266 (Arduino IDE) 上使用 BearSSL 进行指纹验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50786364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com