Manual/OpenSSL

[OpenSSL] asn1parse ๋ช…๋ น์–ด

JayKim๐Ÿ™‚ 2023. 5. 15. 15:01

OpenSSL ์—์„œ asn1 ์ธ์ฝ”๋”ฉ ๋””์ฝ”๋”ฉ ๋ช…๋ น์–ด ์‚ฌ์šฉ๋ฒ•์„ ์•Œ์•„ ๋ณด์ž
ํ•ด๋‹น ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ๋ฌธ์„œ ํŽ˜์ด์ง€๋Š” ๋ฉ”๋‰ด์–ผ์„ ์ฐธ๊ณ  ํ•˜์—ฌ ๋งŒ๋“ค์—ˆ๋‹ค.

asn1parse ๋ช…๋ น์–ด๋กœ ๊ฐ„๋‹จํžˆ ๋ฌธ์ž ์ธ์ฝ”๋”ฉ/๋””์ฝ”๋”ฉ์„ ํ• ์ˆ˜ ์žˆ๊ณ 
๋ณต์žกํ•œ ๋ฐ์ดํƒ€๋Š” ์„ค์ •์„ ์ด์šฉํ•ด ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ ASN.1 PEM ํ˜•์‹ ํŒŒ์‹ฑ ํ•ด์„œ ๋ณด๊ธฐ

openssl asn1parse -in file.pem

ASN1 DER ํ˜•์‹ ํŒŒ์ผ ๋ณด๊ธฐ

openssl asn1parse -inform DER -in file.der

UTF8String ๋ฌธ์ž ์ƒ์„ฑํ•˜๊ธฐ

openssl asn1parse -genstr "UTF8:Hello world"

๊ฒฐ๊ณผ ๊ฐ’

0:d=0  hl=2 l=  11 prim: UTF8STRING        :Hello world

UTF8String DER ํŒŒ์ผ๋กœ ์ƒ์„ฑํ•˜๊ธฐ

openssl asn1parse -genstr 'UTF8:Hello World' -noout -out utf8.der

์ƒ์„ฑํ•œ DER ํŒŒ์ผ ๋ณด๊ธฐ

openssl asn1parse -inform DER -in utf8.der
0:d=0  hl=2 l=  11 prim: UTF8STRING        :Hello world

์„ค์ • ํŒŒ์ผ (asn1.cnf) ํŒŒ์ผ ์ด์šฉ DER ์ƒ์„ฑ ํ•˜๊ธฐ
asn1.cnf ์˜ˆ์ œ ๊ฐ’

asn1=SEQUENCE:seq_sect

[seq_sect]

field1=BOOL:TRUE
field2=EXP:0, UTF8:some random string

asn1.der ์ƒ์„ฑ

openssl asn1parse -genconf asn1.cnf -noout -out asn1.der

์ƒ์„ฑํ•œ ๊ฒฐ๊ณผ ๊ฐ’ ๋ณด๊ธฐ

openssl asn1parse -inform DER -in asn1.der

    0:d=0  hl=2 l=  25 cons: SEQUENCE          
    2:d=1  hl=2 l=   1 prim: BOOLEAN           :255
    5:d=1  hl=2 l=  20 cons: cont [ 0 ]        
    7:d=2  hl=2 l=  18 prim: UTF8STRING        :some random string

์ด๋ ‡๊ฒŒ OpenSSL ๋ช…๋ น์–ด๋ฅผ ์ด์šฉ ํ•ด ASN.1 ํŒŒ์ผ DER๋ฅผ ์ธ์ฝ”๋”ฉ/๋””์ฝ”๋”ฉ ํ•  ์ˆ˜ ์žˆ๋‹ค.