您应该在WifiClientSecure模块中提供哪种格式的证书(和密钥)?存在 NO 示例或其使用文档。
我正在关注Arduino(ESP32)WiFiClientSecure示例代码 - 并在指定CA证书时尝试连接,例如:
client.connect(server, 443, test_ca_cert, test_client_cert, test_client_key)
(test_client_cert
和test_client_key
是NULL指针)。如果test_ca_cert
是NULL指针,则SSL连接正常。
如果我尝试指定自己的test_ca_cert
,我总是得到:
CA cert: mbedtls_x509_crt_parse returned -0x2180
(这是&#34的错误代码;格式无效")
我为test_ca_cert
尝试了很多东西,例如带有PEM格式(明文)base64编码证书的字符串,以及DER格式证书的字节数组。似乎没什么用。
应该指定此证书的格式是什么?
答案 0 :(得分:3)
我通过蛮力和梳理some mbedtls code online来解决这个问题。证书必须以完全的格式指定,如下所示 - 即通过在数组中嵌入您自己的换行符:
unsigned char test_ca_cert[] =
"-----BEGIN CERTIFICATE-----\n"
"MIIDpDCCAowCCQC7mCk5Iu3YmDANBgkqhkiG9w0BAQUFADCBkzELMAkGA1UEBhMC\n"
"VVMxFjAUBgNVBAgMDU5ldyBIYW1wc2hpcmUxDzANBgNVBAcMBk5hc2h1YTEYMBYG\n"
"A1UECgwPYnJhZGdvb2RtYW4uY29tMR0wGwYDVQQDDBRCcmFkIEdvb2RtYW4gUm9v\n"
"dCBDQTEiMCAGCSqGSIb3DQEJARYTYnJhZEBicmFkZ29kbWFuLmNvbTAeFw0xNDEy\n"
"MDgwMTM2NDJaFw0yNDEyMDUwMTM2NDJaMIGTMQswCQYDVQQGEwJVUzEWMBQGA1UE\n"
"CAwNTmV3IEhhbXBzaGlyZTEPMA0GA1UEBwwGTmFzaHVhMRgwFgYDVQQKDA9icmFk\n"
"Z29vZG1hbi5jb20xHTAbBgNVBAMMFEJyYWQgR29vZG1hbiBSb290IENBMSIwIAYJ\n"
"KoZIhvcNAQkBFhNicmFkQGJyYWRnb2RtYW4uY29tMIIBIjANBgkqhkiG9w0BAQEF\n"
"AAOCAQ8AMIIBCgKCAQEAq0TfPz/2eH1vMhs5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