scep.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package models
  2. import (
  3. "context"
  4. "crypto/x509"
  5. "errors"
  6. "github.com/smallstep/certificates/authority/provisioner"
  7. "golang.org/x/crypto/ssh"
  8. )
  9. var errDummyImplementation = errors.New("dummy implementation")
  10. // SCEP is the SCEP provisioner model used solely in CA API
  11. // responses. All methods for the [provisioner.Interface] interface
  12. // are implemented, but return a dummy error.
  13. // TODO(hs): remove reliance on the interface for the API responses
  14. type SCEP struct {
  15. ID string `json:"-"`
  16. Type string `json:"type"`
  17. Name string `json:"name"`
  18. ForceCN bool `json:"forceCN"`
  19. ChallengePassword string `json:"challenge"`
  20. Capabilities []string `json:"capabilities,omitempty"`
  21. IncludeRoot bool `json:"includeRoot"`
  22. ExcludeIntermediate bool `json:"excludeIntermediate"`
  23. MinimumPublicKeyLength int `json:"minimumPublicKeyLength"`
  24. DecrypterCertificate []byte `json:"decrypterCertificate"`
  25. DecrypterKeyPEM []byte `json:"decrypterKeyPEM"`
  26. DecrypterKeyURI string `json:"decrypterKey"`
  27. DecrypterKeyPassword string `json:"decrypterKeyPassword"`
  28. EncryptionAlgorithmIdentifier int `json:"encryptionAlgorithmIdentifier"`
  29. Options *provisioner.Options `json:"options,omitempty"`
  30. Claims *provisioner.Claims `json:"claims,omitempty"`
  31. }
  32. // GetID returns the provisioner unique identifier.
  33. func (s *SCEP) GetID() string {
  34. if s.ID != "" {
  35. return s.ID
  36. }
  37. return s.GetIDForToken()
  38. }
  39. // GetIDForToken returns an identifier that will be used to load the provisioner
  40. // from a token.
  41. func (s *SCEP) GetIDForToken() string {
  42. return "scep/" + s.Name
  43. }
  44. // GetName returns the name of the provisioner.
  45. func (s *SCEP) GetName() string {
  46. return s.Name
  47. }
  48. // GetType returns the type of provisioner.
  49. func (s *SCEP) GetType() provisioner.Type {
  50. return provisioner.TypeSCEP
  51. }
  52. // GetEncryptedKey returns the base provisioner encrypted key if it's defined.
  53. func (s *SCEP) GetEncryptedKey() (string, string, bool) {
  54. return "", "", false
  55. }
  56. // GetTokenID returns the identifier of the token.
  57. func (s *SCEP) GetTokenID(string) (string, error) {
  58. return "", errDummyImplementation
  59. }
  60. // Init initializes and validates the fields of a SCEP type.
  61. func (s *SCEP) Init(_ provisioner.Config) (err error) {
  62. return errDummyImplementation
  63. }
  64. // AuthorizeSign returns an unimplemented error. Provisioners should overwrite
  65. // this method if they will support authorizing tokens for signing x509 Certificates.
  66. func (s *SCEP) AuthorizeSign(context.Context, string) ([]provisioner.SignOption, error) {
  67. return nil, errDummyImplementation
  68. }
  69. // AuthorizeRevoke returns an unimplemented error. Provisioners should overwrite
  70. // this method if they will support authorizing tokens for revoking x509 Certificates.
  71. func (s *SCEP) AuthorizeRevoke(context.Context, string) error {
  72. return errDummyImplementation
  73. }
  74. // AuthorizeRenew returns an unimplemented error. Provisioners should overwrite
  75. // this method if they will support authorizing tokens for renewing x509 Certificates.
  76. func (s *SCEP) AuthorizeRenew(context.Context, *x509.Certificate) error {
  77. return errDummyImplementation
  78. }
  79. // AuthorizeSSHSign returns an unimplemented error. Provisioners should overwrite
  80. // this method if they will support authorizing tokens for signing SSH Certificates.
  81. func (s *SCEP) AuthorizeSSHSign(context.Context, string) ([]provisioner.SignOption, error) {
  82. return nil, errDummyImplementation
  83. }
  84. // AuthorizeSSHRevoke returns an unimplemented error. Provisioners should overwrite
  85. // this method if they will support authorizing tokens for revoking SSH Certificates.
  86. func (s *SCEP) AuthorizeSSHRevoke(context.Context, string) error {
  87. return errDummyImplementation
  88. }
  89. // AuthorizeSSHRenew returns an unimplemented error. Provisioners should overwrite
  90. // this method if they will support authorizing tokens for renewing SSH Certificates.
  91. func (s *SCEP) AuthorizeSSHRenew(context.Context, string) (*ssh.Certificate, error) {
  92. return nil, errDummyImplementation
  93. }
  94. // AuthorizeSSHRekey returns an unimplemented error. Provisioners should overwrite
  95. // this method if they will support authorizing tokens for rekeying SSH Certificates.
  96. func (s *SCEP) AuthorizeSSHRekey(context.Context, string) (*ssh.Certificate, []provisioner.SignOption, error) {
  97. return nil, nil, errDummyImplementation
  98. }
  99. var _ provisioner.Interface = (*SCEP)(nil)