|
Post by sajek on Nov 29, 2023 9:38:13 GMT
When I represent redfish using the asyncresp->res.jsonvalue["certchain"] = certificatestring;
Here certificate string is the actual PEM formatted certificate chain.
When I print this certificate using/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/1
This gives back the certificate string with \n characters instead of the actual newline. for eg:- "@odata.id": "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/1",
"@odata.type": "#Certificate.v1_0_0.Certificate",
"CertificateString": "-----BEGIN CERTIFICATE-----\nabcadasdfasdfasdfasdfasdfsdfsadfasdfasdfasdfasdfy75q63q366y\nabcadasdfasdfasdfasdfasdfsdfsadfasdfasdfasdfasdfy75q63q366y\nabcadasdfasdfasdfasdfasdfsdfsadfasdfasdfasdfasdfy75q63q366y\nabcadasdfasdfasdfasdfasdfsdfsadfasdfasdfasdfasdfy75q63q366y\nabcadasdfasdfasdfasdfasdfsdfsadfasdfasdfasdfasdfy75q63q366y\nC\nabcadasdfasdfasdfasdfasdfsdfsadfasdfasdfasdfasdfy75q63q366yVdWg=\n-----END CERTIFICATE-----\n",
"Description": "HTTPS Certificate",
How to transform it programmatically, so that the new line characters will be displayed as new line instead of new line characters as mentioned above.
|
|
|
Post by mraineri on Nov 29, 2023 13:56:20 GMT
You would need to deserialize the string from the JSON object. In JSON, new lines are encoded with \n, and when you deserialize it into your application, the \n sequences will be replaced with whatever native new lines are for your environment. So, for example, if you were to consume the resource in Python, you can do something like this (where "response" is the raw HTTP response body string):
import json
json_unpacked = json.loads(response) print(json_unpacked["CertificateString"])
|
|
|
Post by sajek on Dec 1, 2023 8:12:41 GMT
Thanks for your reply.
As I am using C++ in my application, I need to deserialize this string by using appropriate calls. This issue may be an implementation specific one.
The issue I am facing is, I will store all the necessary string values such as data.id, type, name etc are in asyncResp structure and finally dumps this entire structure as it is. When I encountered the new line issue in the JSON object, I was able to print it properly using the get<std::string>(). But when I assign it back to the same structure, it will not work. Like the snippet shown below.
asyncResp->res.jsonValue["CertificateChain"] = asyncResp->res.jsonValue["CertificateString"].get<std::string>();
Is there anyway, I can deserialize the string and store it back to the original structure, so that I can print the ayncResp without formatting it further?
|
|
|
Post by mraineri on Dec 1, 2023 13:08:13 GMT
No, because the asyncResp object will always be the JSON-encoded structure. When you perform an assignment like that, it will serialize the string into a JSON string, which will bring you back to the original issue.
If you're printing a JSON object like that, you will always see those escaped characters simply because that's how those strings are represented in raw JSON.
|
|
|
Post by sajek on Dec 2, 2023 11:04:59 GMT
Thanks for your reply and suggestions. I need to try some other methods to print the certificate chain in the proper format.
|
|