On segunda-feira, 28 de novembro de 2016 14:02:16 PST Max Kholmyansky wrote:
> Hi,
>
> I am trying to "decrypt" the *.dat files used by IoTivity, by converting
> them into JSON format using CBOR playground: http://cbor.me/
>
> JSON files convert to CBOR: OK.
>
> CBOR tp JSON: here I am stuck.
You can use the cbordump tool that comes with TinyCBOR, if you pass the -j
option. But here's the thing: the file you attached contains CBOR Binary Text,
which can't be represented properly in JSON. So converting to JSON requires
knowing what format the JSON reader expects to read the binary data in. The
cbordump tool assumes that it's base64url encoded.
That's probably not what you want.
The resource/csdk/security/tool/json2cbor.c tool is not a pure JSON-to-CBOR
converter. It actually encodes the data in inside each entry in CBOR again and
saves as one binary text sequence. Don't ask me why, this makes no sense to
me. I'd expect an on-disk file file format to be more efficient, easier to
seek,
etc. Encoding as CBOR looks like convenience; encoding the inner CBOR payloads
as binary text is just weird...
Anyway, you need to take each of the contents between the h'' from the left
side and paste on the right side. Then you get a decode like:
{"creds": [{"credid": 1, "subjectuuid":
"6a757374-776f-726b-4465-765575696430", "credtype": 1, "privatedata":
{"encoding": "oic.sec.encoding.base64", "data": "Jk7A76L67hlkRmCtFmzK2g=="}},
{"credid": 2, "subjectuuid": "72616e64-5069-6e44-6576-557569643030",
"credtype": 1, "privatedata": {"encoding": "oic.sec.encoding.base64", "data":
"J5830NHNkkH8S4vKJJBIXg=="}}], "rowneruuid":
"61646d69-6e44-6576-6963-655575696430", "rt": ["oic.r.cred"], "if":
["oic.if.baseline"]}
(this was the "cred" entry)
Note how this code contains base64 data, which is... inefficient. If it's using
CBOR binary for the outer payload, why not for the inner too? Also, the string
'oic.sec.encoding.base64" is extremely long... all we needed was a digit.
> On Ubuntu, I am taking a DAT file from IoTivity samples (like, attached).
> Then, trying to dump the byte sequence, like: (tried multiple ways)
>
> - hexdump -e '16/1 "%02x " "\n"' oic_svr_db_client.dat
> - xxd -p oic_svr_db_client.dat
>
> "Pasted" the output (from the command window, or from file) into the right
> side ( "Byte sequence") of cbor.me screen, and press green arrow nearby.
>
> Unfortunately, it doesn't get convertedinto JSON.
> Attaching what I see on the left and on the right.
That's because the site does not convert to JSON. It converts to CBOR's "debug
format" (the same one that you'd have got with the cbordump tool without the
-j option).
See above what I said about Binary Text.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center