LEFT | RIGHT |
(no file at all) | |
1 package config | 1 package config |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "crypto/tls" | 5 "crypto/tls" |
6 "crypto/x509" | 6 "crypto/x509" |
7 "encoding/pem" | 7 "encoding/pem" |
8 "fmt" | 8 "fmt" |
9 "io/ioutil" | 9 "io/ioutil" |
10 "os" | 10 "os" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 firstError = fmt.Errorf("no public ssh keys found") | 57 firstError = fmt.Errorf("no public ssh keys found") |
58 } | 58 } |
59 return "", firstError | 59 return "", firstError |
60 } | 60 } |
61 return string(keyData), nil | 61 return string(keyData), nil |
62 } | 62 } |
63 | 63 |
64 // verifyKeyPair verifies that the certificate and key parse correctly. | 64 // verifyKeyPair verifies that the certificate and key parse correctly. |
65 // The key is optional - if it is provided, we also check that the key | 65 // The key is optional - if it is provided, we also check that the key |
66 // matches the certificate. | 66 // matches the certificate. |
67 func verifyKeyPair(certPEM, keyPEM []byte) error { | 67 func verifyKeyPair(cert, key []byte) error { |
68 » if keyPEM != nil { | 68 » if key != nil { |
69 » » _, err := tls.X509KeyPair(certPEM, keyPEM) | 69 » » _, err := tls.X509KeyPair(cert, key) |
70 return err | 70 return err |
71 } | 71 } |
72 » for len(certPEM) > 0 { | 72 » for len(cert) > 0 { |
73 var certBlock *pem.Block | 73 var certBlock *pem.Block |
74 » » certBlock, certPEM = pem.Decode(certPEM) | 74 » » certBlock, cert = pem.Decode(cert) |
75 if certBlock == nil { | 75 if certBlock == nil { |
76 break | 76 break |
77 } | 77 } |
78 if certBlock.Type == "CERTIFICATE" { | 78 if certBlock.Type == "CERTIFICATE" { |
79 _, err := x509.ParseCertificate(certBlock.Bytes) | 79 _, err := x509.ParseCertificate(certBlock.Bytes) |
80 return err | 80 return err |
81 } | 81 } |
82 } | 82 } |
83 return fmt.Errorf("no certificates found") | 83 return fmt.Errorf("no certificates found") |
84 } | 84 } |
LEFT | RIGHT |