CMS λ Cryptographic Message Syntax μ μ½μλ‘ RFC5652 μ μ μ λ νμ€μ΄λ€.
CMS λͺ
λ Ήμ΄λ λ°μ΄ν μλͺ
μ΄λ λ°μ΄ν μνΈνλ₯Ό μν νμ€ λ°μ΄ν νμμ΄λ€.
μ΄ λ°μ΄νλ PKCS#7 νμμ λ°μ΄ν μ΄λ€.
μμΈν λͺ
λ Ήμ΄ μ€λͺ
μ£Όμμ΄λ€.
https://www.openssl.org/docs/man3.0/man1/openssl-cms.html
CMS λ©μΈμ§ ASN.1 νμ
μλ ASN.1 νμμ CMS λ©μΈμ§μ λν μΌ λΆλΆμ νμ λ΄μ©μ λ³΄μ¬ μ€λ€.
ContentInfo ::= SEQUENCE {
contentType ContentType,
content [0] EXPLICIT ANY DEFINED BY contentType }
ContentType ::= OBJECT IDENTIFIER
SignedData ::= SEQUENCE {
version CMSVersion,
digestAlgorithms DigestAlgorithmIdentifiers,
encapContentInfo EncapsulatedContentInfo,
certificates [0] IMPLICIT CertificateSet OPTIONAL,
crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
signerInfos SignerInfos }
EnvelopedData ::= SEQUENCE {
version CMSVersion,
originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
recipientInfos RecipientInfos,
encryptedContentInfo EncryptedContentInfo,
unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
Signed Data λ©μΈμ§ μμ±
μ΄ λ©μΈμ§λ μλ¬Έμ μ μ μλͺ μ μμ±νκ³ μλ¬Έμ체λ κ·Έλλ‘ λ³΄μ¬ μ€λ€.
openssl cms -sign -in test.txt -out out.msg -signer ecdsa_cert.pem -inkey ecdsa_private_key.pem
out.msg : μμ± λ SignedData λ©μΈμ§ μ΄λ€.
κ²°κ³Ό νμΌμ λ΄μ©μ 보면
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg="sha-256"; boundary="----9200C78F9435257A83D6408C600DC4DF"
This is an S/MIME signed message
------9200C78F9435257A83D6408C600DC4DF
test message^M
------9200C78F9435257A83D6408C600DC4DF
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
MIIDmQYJKoZIhvcNAQcCoIIDijCCA4YCAQExDTALBglghkgBZQMEAgEwCwYJKoZI
hvcNAQcBoIIBwTCCAb0wggFjoAMCAQICCAvGymLEvWh7MAoGCCqGSM49BAMCMEAx
CzAJBgNVBAYTAktSMQ4wDAYDVQQKEwVSYW5peDEOMAwGA1UECxMFRGV2ZWwxETAP
BgNVBAMMCEVDRFNBX0NBMB4XDTIzMDQwNjA5MzYwMFoXDTI0MDQwNjA5MzYwMFow
QjELMAkGA1UEBhMCS1IxDjAMBgNVBAoTBVJhbml4MQ4wDAYDVQQLEwVEZXZlbDET
MBEGA1UEAwwKQ01TX1NpZ25lcjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJUZ
Fpx8Uvbset2RED8HpgHZmPpnuHswjSaDl65sl2JMy43E8ME13LphsOr5B9dd86A4
swfRT9lJ3UPQA761NnqjRTBDMA4GA1UdDwEB/wQEAwID+DAxBgNVHSUEKjAoBggr
BgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDBDAKBggqhkjOPQQD
AgNIADBFAiEA2mqmjaawFtRpEtklxaMjMxVaRySMxA3qsVMNOFO/5CQCICqcaUs+
x4MyBBgFuGqSvIYIRTZdznc1D2VlXBNWHwv9MYIBnjCCAZoCAQEwTDBAMQswCQYD
VQQGEwJLUjEOMAwGA1UEChMFUmFuaXgxDjAMBgNVBAsTBURldmVsMREwDwYDVQQD
DAhFQ0RTQV9DQQIIC8bKYsS9aHswCwYJYIZIAWUDBAIBoIHkMBgGCSqGSIb3DQEJ
AzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTIzMDQwNjA5MzkyNFowLwYJ
KoZIhvcNAQkEMSIEID2+rP15X+LtXg5WMjtDQmjETKwoOsQzZCuW8s/EQ2NbMHkG
CSqGSIb3DQEJDzFsMGowCwYJYIZIAWUDBAEqMAsGCWCGSAFlAwQBFjALBglghkgB
ZQMEAQIwCgYIKoZIhvcNAwcwDgYIKoZIhvcNAwICAgCAMA0GCCqGSIb3DQMCAgFA
MAcGBSsOAwIHMA0GCCqGSIb3DQMCAgEoMAoGCCqGSM49BAMCBEcwRQIhALmYtZhM
r6rLZLUn23FoAOtBmKmB03D8n7NmTRmzXYeYAiAm4aOpdcbYHCy0r5JGYupLl/yX
6PW6lTGMQ14nUMH0og==
------9200C78F9435257A83D6408C600DC4DF--
μ¬κΈ°μ ν΄λΉ λ΄μ©μ BerEditor λ‘ λμ½λ© ν κ·Έλ¦Όμ λ€μκ³Ό κ°λ€.
Signed Data λ©μΈμ§ κ²μ¦
openssl cms -verify -in out.msg -signer ecdsa_cert.pem -CAfile chain.crt -out content.txt
chain.crt : ecdsa_cert.pem μ λν μ²΄μΈ μΈμ¦μ μ λ³΄κ° PEM νμμΌλ‘ μ§μ ν΄μΌ νλ€.
μ²΄μΈ νμΌμ ecdsa_cert.pem μΈμ¦μλ₯Ό λ°κΈν CAμΈμ¦μ λΆν° μ΅μμ RootCA μΈμ¦μλ₯Ό PEM νμμ μΈμ¦μ μ 보λ₯Ό λμ΄ν νμΌμ΄λ€.
Enveloped Data λ©μΈμ§ μμ±
openssl cms -encrypt -in test.txt -recip ecdsa_cert.pem -out enc_data.txt
μμ±λ enc_data.txt νμΌμ μ΄μ΄ 보면 λ€μ μ²λΌ λμ¨λ€.
MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64
MIIBQQYJKoZIhvcNAQcDoIIBMjCCAS4CAQIxgfOhgfACAQOgUaFPMAkGByqGSM49
AgEDQgAEKkl2wlB6iHgqLzzLab5MCcclfuKMQAJBEF9nWoMP0gezqI4SLSW/xSwU
yAbU3X/6wB6/H0d4t4L60anVBpi2OzAcBgkrgQUQhkg/AAIwDwYLKoZIhvcNAQkQ
AwYFADB6MHgwTDBAMQswCQYDVQQGEwJLUjEOMAwGA1UEChMFUmFuaXgxDjAMBgNV
BAsTBURldmVsMREwDwYDVQQDDAhFQ0RTQV9DQQIIC8bKYsS9aHsEKOQzy0VBgpF9
dr2TnmjgGFyHHd7e0wgCgkJm3z/AeaaszvmtYiZoB3YwMwYJKoZIhvcNAQcBMBQG
CCqGSIb3DQMHBAjwK4BkxX3LEIAQPKe81tqYB3KgN3Rdikh5hA==
κ·Έλ¦¬κ³ μμ± λ λ΄μ©μ BerEditor λ‘ λμ½λ© νλ©΄μ΄λ€.
Enveloped Data 볡νΈν
openssl cms -decrypt -in enc_data.txt -inkey ecdsa_pri.pem -out plain_data.txt
μ¬κΈ°μλ κ°λ¨ν SignedData μ EnvelopedData νμμ CMS λ©μΈμ§μ λ§λλκ²μ ν΄λ³΄μλ€.
μ¬μ€ CMS λ PKCS#7 μ κ°μ νμμ΄μ§λ§ λ²μ μ λ°λ₯Έ μμ μ°¨μ΄λ μ‘΄μ¬νλ€.
'Manual > OpenSSL' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[OpenSSL] OCSP μ TSP λͺ λ Ήμ΄ (0) | 2023.04.07 |
---|---|
[OpenSSL] PKCS#12 (PFX) νμΌ λ§λ€κΈ° λͺ λ Ήμ΄ (0) | 2023.04.07 |
[OpenSSL] RSA κ°μΈν€ (PrivateKey) μμ± λͺ λ Ήμ΄ (0) | 2023.04.06 |
[OpenSSL] ECDSA μ© Self-Sign μΈμ¦μ λ§λ€κΈ° (0) | 2023.04.05 |
[OpenSSL] TLS μλ² ν μ€νΈ (0) | 2023.04.05 |