gpt4 book ai didi

ssl - 将客户端证书插入 HTTPS POST 请求

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

我正在构建连接到 AWS IOT 平台的硬件设备。根据文档,aws iot 平台的身份验证是使用 TLS 完成的。我在授权访问的设备上有根 CA、客户端 key 和客户端证书文件。有没有办法在发出 POST 请求时在 HTTP header 中使用这些文件?如果是这样,如何?到目前为止,这里是 Energia IDE(基于 Arduino IDE)和使用 WiFiClient 方法的代码。

if (client.sslConnect(aws_endpoint, 443))
{
Serial.println("\nConnected to AWS endpoint");

String PostData = "{\"value1\" : \"testValue\", \"value2\" : \"Hello\", \"value3\" : \"World!\" }";

request = "POST /things/";
request += thingname;
request += "/shadow";
request += " HTTP/1.1";
Serial.print("Request:\t"); Serial.println(request);
Serial.print("Post data:\t"); Serial.println(PostData);

client.println(request);
client.println("Host: ");
client.println(aws_endpoint);
client.println(":443");
client.println("User-Agent: Energia/1.1");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.print("Content-Length: "); client.println(PostData.length());
client.println();
client.println(PostData);
client.println();
}
else
{
Serial.println("Connection failed");
}

Serial.println();
Serial.println("Server response:");
Serial.println();

// Capture response from the server. (10 second timeout)
long timeOut = 5000;
long lastTime = millis();

while((millis()-lastTime) < timeOut)
{ // Wait for incoming response from server
while (client.available())
{ // Characters incoming from the server
char c = client.read(); // Read characters
Serial.write(c);
}
}

然而,这给出了身份验证错误:

HTTP/1.1 403 Forbidden
content-type: application/json
content-length: 91
date: Tue, 26 Jul 2016 11:46:59 GMT
x-amzn-RequestId: 4d5388a9-e3c4-460a-b674-c3f971f3330d
connection: Keep-Alive
x-amzn-ErrorType: ForbiddenException:

{"message":"Missing Authentication Token","traceId":"4d5388a9-e3c4-460a-b674-c3f971f3330d"}

最佳答案

TLS 客户端证书将作为您的 client.sslConnect() 调用的一部分发送/使用,不会作为 HTTP 请求的一部分。 TLS 握手(以及客户端和服务器证书的交换/验证)发生在发送任何 HTTP 消息之前。

This AWS forums post建议您可能需要为影子 API 使用端口 8443(不是端口 443)。看起来 TLS 相互身份验证(通过证书)的使用/要求,相对于 AWS SIGv4 header 的使用,是由 AWS IOT 根据使用的端口确定的。

希望这对您有所帮助!

关于ssl - 将客户端证书插入 HTTPS POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38594159/

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