~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/crypto/x509/pkcs8.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        "fmt"
12
12
)
13
13
 
14
 
// pkcs8 reflects an ASN.1, PKCS#8 PrivateKey. See 
15
 
// ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-8/pkcs-8v1_2.asn.
 
14
// pkcs8 reflects an ASN.1, PKCS#8 PrivateKey. See
 
15
// ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-8/pkcs-8v1_2.asn
 
16
// and RFC5208.
16
17
type pkcs8 struct {
17
18
        Version    int
18
19
        Algo       pkix.AlgorithmIdentifier
21
22
}
22
23
 
23
24
// ParsePKCS8PrivateKey parses an unencrypted, PKCS#8 private key. See
24
 
// http://www.rsa.com/rsalabs/node.asp?id=2130
 
25
// http://www.rsa.com/rsalabs/node.asp?id=2130 and RFC5208.
25
26
func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) {
26
27
        var privKey pkcs8
27
28
        if _, err := asn1.Unmarshal(der, &privKey); err != nil {
28
29
                return nil, err
29
30
        }
30
31
        switch {
31
 
        case privKey.Algo.Algorithm.Equal(oidRSA):
 
32
        case privKey.Algo.Algorithm.Equal(oidPublicKeyRSA):
32
33
                key, err = ParsePKCS1PrivateKey(privKey.PrivateKey)
33
34
                if err != nil {
34
35
                        return nil, errors.New("crypto/x509: failed to parse RSA private key embedded in PKCS#8: " + err.Error())
35
36
                }
36
37
                return key, nil
 
38
 
 
39
        case privKey.Algo.Algorithm.Equal(oidPublicKeyECDSA):
 
40
                bytes := privKey.Algo.Parameters.FullBytes
 
41
                namedCurveOID := new(asn1.ObjectIdentifier)
 
42
                if _, err := asn1.Unmarshal(bytes, namedCurveOID); err != nil {
 
43
                        namedCurveOID = nil
 
44
                }
 
45
                key, err = parseECPrivateKey(namedCurveOID, privKey.PrivateKey)
 
46
                if err != nil {
 
47
                        return nil, errors.New("crypto/x509: failed to parse EC private key embedded in PKCS#8: " + err.Error())
 
48
                }
 
49
                return key, nil
 
50
 
37
51
        default:
38
52
                return nil, fmt.Errorf("crypto/x509: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm)
39
53
        }
40
 
 
41
 
        panic("unreachable")
42
54
}