provisioner.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package scep
  2. import (
  3. "context"
  4. "crypto"
  5. "crypto/x509"
  6. "github.com/smallstep/certificates/authority/provisioner"
  7. )
  8. // Provisioner is an interface that embeds the
  9. // provisioner.Interface and adds some SCEP specific
  10. // functions.
  11. type Provisioner interface {
  12. provisioner.Interface
  13. GetOptions() *provisioner.Options
  14. GetCapabilities() []string
  15. ShouldIncludeRootInChain() bool
  16. ShouldIncludeIntermediateInChain() bool
  17. GetDecrypter() (*x509.Certificate, crypto.Decrypter)
  18. GetSigner() (*x509.Certificate, crypto.Signer)
  19. GetContentEncryptionAlgorithm() int
  20. ValidateChallenge(ctx context.Context, csr *x509.CertificateRequest, challenge, transactionID string) error
  21. NotifySuccess(ctx context.Context, csr *x509.CertificateRequest, cert *x509.Certificate, transactionID string) error
  22. NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string, errorCode int, errorDescription string) error
  23. }
  24. // provisionerKey is the key type for storing and searching a
  25. // SCEP provisioner in the context.
  26. type provisionerKey struct{}
  27. // provisionerFromContext searches the context for a SCEP provisioner.
  28. // Returns the provisioner or panics if no SCEP provisioner is found.
  29. func provisionerFromContext(ctx context.Context) Provisioner {
  30. p, ok := ctx.Value(provisionerKey{}).(Provisioner)
  31. if !ok {
  32. panic("SCEP provisioner expected in request context")
  33. }
  34. return p
  35. }
  36. func NewProvisionerContext(ctx context.Context, p Provisioner) context.Context {
  37. return context.WithValue(ctx, provisionerKey{}, p)
  38. }