When interfacing with the Huawei NB-IoT platform, the HTTPS connection was used, and Huawei provided a CRT-format certificate file, but the official only gave the Java paradigm, and C # had a problem referencing the certificate, the following is the pit:
Nb_iot platform interface debugging, HTTPS authentication mode
- First, add in the code
1 New Remotecertificatevalidationcallback (CheckValidationResult);
callback function returns true without validating the certificate
- When only one certificate was used to study the HTTPS authentication method, it was discovered that both "checksum" and "Device-side certificate" were required, and then two certificates were imported
1 New X509Certificate (@ "C:\ca.crt"); 2 WebRequest. Clientcertificates.add (CER2);
Later found that there is a problem with the server address of the connection changed the connection address, return "Cryptographicexception" exception, find a workaround, add code
1 servicepointmanager.securityprotocol = SECURITYPROTOCOLTYPE.TLS;
To use TLS encryption mode. (note here that you need to upgrade to more than. NET framework4.5 for TLS encryption)
- Tried to try another format of the certificate, but are not available, using the JKS format of the certificate, generated direct error "Cannot find the requested object", suspect that the certificate format C # does not support, it seems that JKs is a Java tool specifically used in the format. After you have used another format, you can generate a certificate, but the return display " Failed to create SSL/TLS secure channel "
- Change X509Certificate to X509Certificate2 return 400 error stating certificate validation passed but request format problematic cause to be analyzed
- The next morning (April 12) found that the "Content-type" in the HTTPS header more than a space "Content -type", resulting in a malformed, pure hand mistakenly do not know how to enter the space, remove the space after the request succeeded.
HTTPS requests in C #. Net