diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-05 10:44:37 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-05 10:44:37 +0100 |
commit | aa0c2f3fc07e3c52e62c570ee9108e4602b3ddbf (patch) | |
tree | b60aeb847ae698dadacb017b7ecf06d51c6c4866 /x509.go | |
parent | 53ad91c63c2788a83d0e80985ffa89ce7cdf203f (diff) |
simplified encoding and decoding
Go's "encoding/json" already takes care of encoding and decoding byte
slices as base64. As such, it need not be done explicitly by us.
Diffstat (limited to 'x509.go')
-rw-r--r-- | x509.go | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -8,7 +8,6 @@ import ( "crypto/rand" "crypto/tls" "crypto/x509" - "encoding/base64" "encoding/pem" "io/ioutil" ) @@ -135,17 +134,13 @@ func ParseChain(rest []byte) ([]*x509.Certificate, error) { return chain, nil } -// ParseB64Chain parses a list of base64 DER-encoded X.509 certificates, such +// ParseDerChain parses a list of base64 DER-encoded X.509 certificates, such // that the first (zero-index) string is interpretted as an end-entity // certificate and the remaining ones as the an intermediate CertPool. -func ParseB64Chain(chain []string) (*x509.Certificate, *x509.CertPool, error) { +func ParseDerChain(chain [][]byte) (*x509.Certificate, *x509.CertPool, error) { var certificate *x509.Certificate intermediatePool := x509.NewCertPool() - for index, cert := range chain { - der, err := base64.StdEncoding.DecodeString(cert) - if err != nil { - return nil, nil, fmt.Errorf("certificate decoding failed: %v", err) - } + for index, der := range chain { c, err := x509.ParseCertificate(der) if err != nil { return nil, nil, fmt.Errorf("certificate decoding failed: %v", err) @@ -163,8 +158,8 @@ func ParseB64Chain(chain []string) (*x509.Certificate, *x509.CertPool, error) { return certificate, intermediatePool, nil } -func buildChainFromB64List(lp *LogParameters, b64chain []string) ([]*x509.Certificate, error) { - certificate, intermediatePool, err := ParseB64Chain(b64chain) +func buildChainFromDerList(lp *LogParameters, derChain [][]byte) ([]*x509.Certificate, error) { + certificate, intermediatePool, err := ParseDerChain(derChain) if err != nil { return nil, err } |