mirror of
https://github.com/google/go-attestation.git
synced 2025-02-22 09:30:49 +00:00
Add support for multiple certificate directories (#47)
This commit is contained in:
parent
372fcf25d0
commit
5c6b9242df
@ -56,25 +56,27 @@ func (v *EKVerifier) VerifyEKCert(certBytes []byte) (*pb.EkcertVerificationResul
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewEKVerifier returns an EKVerifier initialized using the certificates in the specified
|
// NewEKVerifier returns an EKVerifier initialized using the certificates in the specified
|
||||||
// directory. Directories are resolved recursively.
|
// directories. Directories are resolved recursively.
|
||||||
// The specified directory should be structured in the forms:
|
// The specified directory should be structured in the forms:
|
||||||
// <XXXX>/RootCA/<cert>.{der,cer,crt)
|
// <XXXX>/RootCA/<cert>.{der,cer,crt)
|
||||||
// <XXXX>/IntermediateCA/<cert>.{der,cer,crt)
|
// <XXXX>/IntermediateCA/<cert>.{der,cer,crt)
|
||||||
func NewEKVerifier(certsPath string) (*EKVerifier, error) {
|
func NewEKVerifier(certsPath []string) (*EKVerifier, error) {
|
||||||
roots := x509.NewCertPool()
|
roots := x509.NewCertPool()
|
||||||
intermediates := x509.NewCertPool()
|
intermediates := x509.NewCertPool()
|
||||||
|
|
||||||
root, err := ioutil.ReadDir(certsPath)
|
for _, dir := range certsPath {
|
||||||
if err != nil {
|
root, err := ioutil.ReadDir(dir)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
|
||||||
for _, f := range root {
|
|
||||||
if !f.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := readCertificates(filepath.Join(certsPath, f.Name()), roots, intermediates); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
for _, f := range root {
|
||||||
|
if !f.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := readCertificates(filepath.Join(dir, f.Name()), roots, intermediates); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &EKVerifier{
|
return &EKVerifier{
|
||||||
@ -85,11 +87,13 @@ func NewEKVerifier(certsPath string) (*EKVerifier, error) {
|
|||||||
|
|
||||||
func readCertificates(dir string, roots, intermediates *x509.CertPool) error {
|
func readCertificates(dir string, roots, intermediates *x509.CertPool) error {
|
||||||
rootFiles, err := ioutil.ReadDir(filepath.Join(dir, "RootCA"))
|
rootFiles, err := ioutil.ReadDir(filepath.Join(dir, "RootCA"))
|
||||||
if err != nil {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := parseCertsToPool(filepath.Join(dir, "RootCA"), rootFiles, roots); err != nil {
|
if err == nil {
|
||||||
return err
|
if err := parseCertsToPool(filepath.Join(dir, "RootCA"), rootFiles, roots); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
intermediateFiles, err := ioutil.ReadDir(filepath.Join(dir, "IntermediateCA"))
|
intermediateFiles, err := ioutil.ReadDir(filepath.Join(dir, "IntermediateCA"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user