asn1parse genstr question

Wim Lewis wiml at omnigroup.com
Mon Apr 22 18:35:43 UTC 2019


On Apr 21, 2019, at 8:58 AM, Dmitry Belyavsky <beldmit at gmail.com> wrote:
> openssl asn1parse -genstr "UTF8String:ф" -out content
> 
> I get a 6-byte file. If I understand correctly, it starts with a 2-byte header indicating the content length and then contains an encoded letter 'ф' I want. But the encoding of it is not UTF8, as the utf8 encoding of a cyrillic letter is 2 bytes long. 

When I do that I get the 6-byte file "0c 04 c3 91 c2 84", which looks like 'ф' is getting UTF-8 encoded twice (more exactly, asn1parse is receiving a utf8-encoded value but interpreting it as Latin-1, and then encoding that as UTF8, which produces nonsense).

The format of the "genstr" option is described in the ASN1_generate_nconf man page, which says you can prepend the format modifier "UTF8" to the specifier in order to tell genstr to interpret the value correctly. So this produces the output you want:

   FORMAT:UTF8,UTF8String:ф

(Oddly, you can't use HEX with UTF8String. It seems like it would be convenient to be able to do so.)




More information about the openssl-users mailing list