|
@@ -30,6 +30,8 @@ var (
|
|
oidFriendlyName = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 20})
|
|
oidFriendlyName = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 20})
|
|
oidLocalKeyID = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 21})
|
|
oidLocalKeyID = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 21})
|
|
oidMicrosoftCSPName = asn1.ObjectIdentifier([]int{1, 3, 6, 1, 4, 1, 311, 17, 1})
|
|
oidMicrosoftCSPName = asn1.ObjectIdentifier([]int{1, 3, 6, 1, 4, 1, 311, 17, 1})
|
|
|
|
+
|
|
|
|
+ errUnknownAttributeOID = errors.New("pkcs12: unknown attribute OID")
|
|
)
|
|
)
|
|
|
|
|
|
type pfxPdu struct {
|
|
type pfxPdu struct {
|
|
@@ -104,6 +106,11 @@ func unmarshal(in []byte, out interface{}) error {
|
|
}
|
|
}
|
|
|
|
|
|
// ToPEM converts all "safe bags" contained in pfxData to PEM blocks.
|
|
// ToPEM converts all "safe bags" contained in pfxData to PEM blocks.
|
|
|
|
+// Unknown attributes are discarded.
|
|
|
|
+//
|
|
|
|
+// Note that although the returned PEM blocks for private keys have type
|
|
|
|
+// "PRIVATE KEY", the bytes are not encoded according to PKCS #8, but according
|
|
|
|
+// to PKCS #1 for RSA keys and SEC 1 for ECDSA keys.
|
|
func ToPEM(pfxData []byte, password string) ([]*pem.Block, error) {
|
|
func ToPEM(pfxData []byte, password string) ([]*pem.Block, error) {
|
|
encodedPassword, err := bmpString(password)
|
|
encodedPassword, err := bmpString(password)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -135,6 +142,9 @@ func convertBag(bag *safeBag, password []byte) (*pem.Block, error) {
|
|
|
|
|
|
for _, attribute := range bag.Attributes {
|
|
for _, attribute := range bag.Attributes {
|
|
k, v, err := convertAttribute(&attribute)
|
|
k, v, err := convertAttribute(&attribute)
|
|
|
|
+ if err == errUnknownAttributeOID {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -188,7 +198,7 @@ func convertAttribute(attribute *pkcs12Attribute) (key, value string, err error)
|
|
key = "Microsoft CSP Name"
|
|
key = "Microsoft CSP Name"
|
|
isString = true
|
|
isString = true
|
|
default:
|
|
default:
|
|
- return "", "", errors.New("pkcs12: unknown attribute with OID " + attribute.Id.String())
|
|
|
|
|
|
+ return "", "", errUnknownAttributeOID
|
|
}
|
|
}
|
|
|
|
|
|
if isString {
|
|
if isString {
|