government / ratify / ratify.go

@ 7fc9f65a585bd720d0768ecfb4755a050cfd6106 | 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
}

// 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
	}
	return certs, nil
}