chore: update vendor
This commit is contained in:
42
vendor/github.com/google/certificate-transparency-go/x509util/files.go
generated
vendored
42
vendor/github.com/google/certificate-transparency-go/x509util/files.go
generated
vendored
@ -19,7 +19,10 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/google/certificate-transparency-go/x509"
|
||||
)
|
||||
|
||||
// ReadPossiblePEMFile loads data from a file which may be in DER format
|
||||
@ -71,3 +74,42 @@ func dePEM(data []byte, blockname string) [][]byte {
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// ReadFileOrURL returns the data from a target which may be either a filename
|
||||
// or an HTTP(S) URL.
|
||||
func ReadFileOrURL(target string, client *http.Client) ([]byte, error) {
|
||||
u, err := url.Parse(target)
|
||||
if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
|
||||
return ioutil.ReadFile(target)
|
||||
}
|
||||
|
||||
rsp, err := client.Get(u.String())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to http.Get(%q): %v", target, err)
|
||||
}
|
||||
return ioutil.ReadAll(rsp.Body)
|
||||
}
|
||||
|
||||
// GetIssuer attempts to retrieve the issuer for a certificate, by examining
|
||||
// the cert's Authority Information Access extension (if present) for the
|
||||
// issuer's URL and retrieving from there.
|
||||
func GetIssuer(cert *x509.Certificate, client *http.Client) (*x509.Certificate, error) {
|
||||
if len(cert.IssuingCertificateURL) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
issuerURL := cert.IssuingCertificateURL[0]
|
||||
rsp, err := client.Get(issuerURL)
|
||||
if err != nil || rsp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("failed to get issuer from %q: %v", issuerURL, err)
|
||||
}
|
||||
defer rsp.Body.Close()
|
||||
body, err := ioutil.ReadAll(rsp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read issuer from %q: %v", issuerURL, err)
|
||||
}
|
||||
issuers, err := x509.ParseCertificates(body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse issuer cert: %v", err)
|
||||
}
|
||||
return issuers[0], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user