[IOT-3301] Change CSR CBOR encoding 21/29821/3
authorOleksii Beketov <ol.beketov@samsung.com>
Fri, 4 Oct 2019 12:16:42 +0000 (15:16 +0300)
committerAleksey Volkov <a.volkov@samsung.com>
Tue, 8 Oct 2019 10:05:12 +0000 (10:05 +0000)
Encode CSR as text string instead of byte string
in case of PEM encoded CSR

Change-Id: I849603f837103742156c4c157be44cce95b3a89b
Signed-off-by: Oleksii Beketov <ol.beketov@samsung.com>
resource/csdk/security/src/csrresource.c

index be90ca7..221b6e3 100644 (file)
@@ -155,7 +155,14 @@ static OCStackResult CSRToCBORPayload(const uint8_t *csr, size_t csrLen, OicEnco
     // Create CSR string entry
     cborEncoderResult = cbor_encode_text_string(&csrRootMap, OIC_JSON_CSR_NAME, strlen(OIC_JSON_CSR_NAME));
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding CSR name.");
-    cborEncoderResult = cbor_encode_byte_string(&csrRootMap, csr, csrLen);
+    if (OIC_ENCODING_PEM == encoding)
+    {
+        cborEncoderResult = cbor_encode_text_string(&csrRootMap, (const char *)csr, csrLen);
+    }
+    else
+    {
+        cborEncoderResult = cbor_encode_byte_string(&csrRootMap, csr, csrLen);
+    }
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding CSR value.");
 
     // Create encoding entry