@ 425eee5ae0d898d1e8c0558a56c41f58d7a05028 | history
package ratify
import (
"crypto/x509"
"time"
)
type Options struct {
// At is the time to check validity at.
At time.Time
// Pin, if set, is the only key the program's anchor may have. Without
// one, the anchor inside the file is trusted, so ratification checks
// that the program is internally consistent, not who wrote it.
Pin Pin
// CRLs are repeal lists to apply, as each file's bytes.
CRLs [][]byte
}
// Ratify loads a .gov file and runs every ratification check that comes
// before policy processing. It returns the certs in depth order.
func Ratify(data []byte, opts Options) ([]*x509.Certificate, error) {
certs, err := Load(data)
if err != nil {
return nil, err
}
certs, err = Order(certs)
if err != nil {
return nil, err
}
if opts.Pin != nil {
if err := CheckPin(certs[0], opts.Pin); err != nil {
return nil, err
}
}
if err := CheckChain(certs); err != nil {
return nil, err
}
if err := CheckValidity(certs, opts.At); err != nil {
return nil, err
}
var crls []*x509.RevocationList
for _, data := range opts.CRLs {
more, err := LoadCRLs(data)
if err != nil {
return nil, err
}
crls = append(crls, more...)
}
if err := CheckRepeals(certs, crls, opts.At); err != nil {
return nil, err
}
return certs, nil
}