asn1parse genstr question

Viktor Dukhovni openssl-users at dukhovni.org
Mon Apr 22 18:23:02 UTC 2019


On Sun, Apr 21, 2019 at 06:58:53PM +0300, Dmitry Belyavsky wrote:

> When I use a command
> 
> 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.
> 
> Am I wrong? If the behavior I see is desired one, how can I convert the
> result of the encoding to UTF8 using openssl internal API?

By default the input string is assumed to contain single-byte octets,
which are individually encoded as UTF-8.  This is rarely what you
want if your input is not ASCII.  For actual UTF-8 input, you can
use:

    $ openssl asn1parse -out content -genstr 'FORMAT:UTF8,UTF8String:Он врет! Он не знает, КАК НАДО!' # [1]
	0:d=0  hl=2 l=  53 prim: UTF8STRING        :Он врет! Он не знает, КАК НАДО!

The "genstr" format is described in, for example:

    https://www.openssl.org/docs/man1.0.2/man3/ASN1_generate_nconf.html

-- 
	Viktor.

[1]. http://www.mnemosyne.ru/homo/galich-6.html


More information about the openssl-users mailing list