root.go 753 B

1234567891011121314151617181920212223242526272829
  1. package authority
  2. import (
  3. "crypto/x509"
  4. "net/http"
  5. "github.com/pkg/errors"
  6. )
  7. // Root returns the certificate corresponding to the given SHA sum argument.
  8. func (a *Authority) Root(sum string) (*x509.Certificate, error) {
  9. val, ok := a.certificates.Load(sum)
  10. if !ok {
  11. return nil, &apiError{errors.Errorf("certificate with fingerprint %s was not found", sum),
  12. http.StatusNotFound, context{}}
  13. }
  14. crt, ok := val.(*x509.Certificate)
  15. if !ok {
  16. return nil, &apiError{errors.Errorf("stored value is not a *cryto/x509.Certificate"),
  17. http.StatusInternalServerError, context{}}
  18. }
  19. return crt, nil
  20. }
  21. // GetRootCertificate returns the server root certificate.
  22. func (a *Authority) GetRootCertificate() *x509.Certificate {
  23. return a.rootX509Crt
  24. }