github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/smime/envelope.go (about) 1 package smime 2 3 /* 4 type EnvelopedData struct { 5 Version int 6 7 OriginatorCerts []interface{} 8 OriginatorCRLs []*pkix.CertificateList 9 10 RecipientInfos []interface{} 11 12 EncryptedContent []byte 13 EncryptionAlgorithm EncryptionAlgorithm 14 } 15 16 type KeyTransfer struct { 17 RAWRid []byte 18 19 Issuer pkix.Name 20 IssuerSerialNumber *big.Int 21 SubjectKeyIdentifier []byte 22 23 EncryptionAlgorithm EncryptionAlgorithm 24 EncryptedKey []byte 25 } 26 27 type KeyAgreement struct { 28 } 29 30 // RFC 5652 6.1 31 32 // EnvelopedData ::= SEQUENCE { 33 // version CMSVersion, 34 // originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL, 35 // recipientInfos RecipientInfos, 36 // encryptedContentInfo EncryptedContentInfo, 37 // unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL } 38 // 39 // RecipientInfos ::= SET SIZE (1..MAX) OF RecipientInfo 40 type envelopedData struct { 41 Version int 42 43 OriginatorInfo originatorInfo `asn1:"optional,tag:0"` 44 RecipientInfos []asn1.RawValue `asn1:"set"` 45 46 EncryptedContentInfo encryptedContentInfo 47 UnprotectedAttrs []pkix.AttributeTypeAndValue `asn1:"optional,set,tag:1"` 48 } 49 50 // OriginatorInfo ::= SEQUENCE { 51 // certs [0] IMPLICIT CertificateSet OPTIONAL, 52 // crls [1] IMPLICIT RevocationInfoChoices OPTIONAL } 53 type originatorInfo struct { 54 Certs []asn1.RawValue `asn:"optional,set,tag:0"` 55 Crls []asn1.RawValue `asn:"optional,set,tag:1"` 56 } 57 58 // EncryptedContentInfo ::= SEQUENCE { 59 // contentType ContentType, 60 // contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier, 61 // encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL } 62 type encryptedContentInfo struct { 63 ContentType asn1.ObjectIdentifier 64 ContentEncryptionAlgorithm pkix.AlgorithmIdentifier 65 EncryptedContent asn1.RawValue `asn:"optional,tag:0"` 66 } 67 68 func parseEnvelopedData(data []byte) (interface{}, error) { 69 env := envelopedData{} 70 _, err := asn1.Unmarshal(data, &env) 71 if err != nil { 72 return nil, err 73 } 74 75 envelope := &EnvelopedData{} 76 envelope.Version = env.Version 77 78 for _, v := range env.OriginatorInfo.Certs { 79 cert, err := parseCertificateChoice(v.FullBytes) 80 if err != nil { 81 return nil, err 82 } 83 envelope.OriginatorCerts = append(envelope.OriginatorCerts, cert) 84 } 85 86 for _, v := range env.OriginatorInfo.Crls { 87 crl, err := x509.ParseCRL(v.FullBytes) 88 if err != nil { 89 return nil, err 90 } 91 envelope.OriginatorCRLs = append(envelope.OriginatorCRLs, crl) 92 } 93 94 for _, info := range env.RecipientInfos { 95 rinfo, err := parseRecipientInfo(info) 96 if err != nil { 97 return nil, err 98 } 99 100 envelope.RecipientInfos = append(envelope.RecipientInfos, rinfo) 101 102 } 103 104 envelope.EncryptionAlgorithm = getEncryptionAlgorithmFromOID(env.EncryptedContentInfo.ContentEncryptionAlgorithm.Algorithm) 105 envelope.EncryptedContent = env.EncryptedContentInfo.EncryptedContent.Bytes 106 107 return envelope, nil 108 } 109 */