|
30 | 30 | oidFriendlyName = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 20})
|
31 | 31 | oidLocalKeyID = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 21})
|
32 | 32 | oidMicrosoftCSPName = asn1.ObjectIdentifier([]int{1, 3, 6, 1, 4, 1, 311, 17, 1})
|
| 33 | + |
| 34 | + errUnknownAttributeOID = errors.New("pkcs12: unknown attribute OID") |
33 | 35 | )
|
34 | 36 |
|
35 | 37 | type pfxPdu struct {
|
@@ -104,6 +106,7 @@ func unmarshal(in []byte, out interface{}) error {
|
104 | 106 | }
|
105 | 107 |
|
106 | 108 | // ToPEM converts all "safe bags" contained in pfxData to PEM blocks.
|
| 109 | +// Unknown attributes are discarded. |
107 | 110 | //
|
108 | 111 | // Note that although the returned PEM blocks for private keys have type
|
109 | 112 | // "PRIVATE KEY", the bytes are not encoded according to PKCS #8, but according
|
@@ -139,6 +142,9 @@ func convertBag(bag *safeBag, password []byte) (*pem.Block, error) {
|
139 | 142 |
|
140 | 143 | for _, attribute := range bag.Attributes {
|
141 | 144 | k, v, err := convertAttribute(&attribute)
|
| 145 | + if err == errUnknownAttributeOID { |
| 146 | + continue |
| 147 | + } |
142 | 148 | if err != nil {
|
143 | 149 | return nil, err
|
144 | 150 | }
|
@@ -192,7 +198,7 @@ func convertAttribute(attribute *pkcs12Attribute) (key, value string, err error)
|
192 | 198 | key = "Microsoft CSP Name"
|
193 | 199 | isString = true
|
194 | 200 | default:
|
195 |
| - return "", "", errors.New("pkcs12: unknown attribute with OID " + attribute.Id.String()) |
| 201 | + return "", "", errUnknownAttributeOID |
196 | 202 | }
|
197 | 203 |
|
198 | 204 | if isString {
|
|
0 commit comments