scep.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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,omitempty"`
  19. ChallengePassword string `json:"challenge,omitempty"`
  20. Capabilities []string `json:"capabilities,omitempty"`
  21. IncludeRoot bool `json:"includeRoot,omitempty"`
  22. ExcludeIntermediate bool `json:"excludeIntermediate,omitempty"`
  23. MinimumPublicKeyLength int `json:"minimumPublicKeyLength,omitempty"`
  24. DecrypterCertificate string `json:"decrypterCertificate"`
  25. DecrypterKey string `json:"decrypterKey"`
  26. DecrypterKeyPassword string `json:"decrypterKeyPassword"`
  27. EncryptionAlgorithmIdentifier int `json:"encryptionAlgorithmIdentifier,omitempty"`
  28. Options *provisioner.Options `json:"options,omitempty"`
  29. Claims *provisioner.Claims `json:"claims,omitempty"`
  30. }
  31. // GetID returns the provisioner unique identifier.
  32. func (s *SCEP) GetID() string {
  33. if s.ID != "" {
  34. return s.ID
  35. }
  36. return s.GetIDForToken()
  37. }
  38. // GetIDForToken returns an identifier that will be used to load the provisioner
  39. // from a token.
  40. func (s *SCEP) GetIDForToken() string {
  41. return "scep/" + s.Name
  42. }
  43. // GetName returns the name of the provisioner.
  44. func (s *SCEP) GetName() string {
  45. return s.Name
  46. }
  47. // GetType returns the type of provisioner.
  48. func (s *SCEP) GetType() provisioner.Type {
  49. return provisioner.TypeSCEP
  50. }
  51. // GetEncryptedKey returns the base provisioner encrypted key if it's defined.
  52. func (s *SCEP) GetEncryptedKey() (string, string, bool) {
  53. return "", "", false
  54. }
  55. // GetTokenID returns the identifier of the token.
  56. func (s *SCEP) GetTokenID(string) (string, error) {
  57. return "", errDummyImplementation
  58. }
  59. // Init initializes and validates the fields of a SCEP type.
  60. func (s *SCEP) Init(_ provisioner.Config) (err error) {
  61. return errDummyImplementation
  62. }
  63. // AuthorizeSign returns an unimplemented error. Provisioners should overwrite
  64. // this method if they will support authorizing tokens for signing x509 Certificates.
  65. func (s *SCEP) AuthorizeSign(context.Context, string) ([]provisioner.SignOption, error) {
  66. return nil, errDummyImplementation
  67. }
  68. // AuthorizeRevoke returns an unimplemented error. Provisioners should overwrite
  69. // this method if they will support authorizing tokens for revoking x509 Certificates.
  70. func (s *SCEP) AuthorizeRevoke(context.Context, string) error {
  71. return errDummyImplementation
  72. }
  73. // AuthorizeRenew returns an unimplemented error. Provisioners should overwrite
  74. // this method if they will support authorizing tokens for renewing x509 Certificates.
  75. func (s *SCEP) AuthorizeRenew(context.Context, *x509.Certificate) error {
  76. return errDummyImplementation
  77. }
  78. // AuthorizeSSHSign returns an unimplemented error. Provisioners should overwrite
  79. // this method if they will support authorizing tokens for signing SSH Certificates.
  80. func (s *SCEP) AuthorizeSSHSign(context.Context, string) ([]provisioner.SignOption, error) {
  81. return nil, errDummyImplementation
  82. }
  83. // AuthorizeRevoke returns an unimplemented error. Provisioners should overwrite
  84. // this method if they will support authorizing tokens for revoking SSH Certificates.
  85. func (s *SCEP) AuthorizeSSHRevoke(context.Context, string) error {
  86. return errDummyImplementation
  87. }
  88. // AuthorizeSSHRenew returns an unimplemented error. Provisioners should overwrite
  89. // this method if they will support authorizing tokens for renewing SSH Certificates.
  90. func (s *SCEP) AuthorizeSSHRenew(context.Context, string) (*ssh.Certificate, error) {
  91. return nil, errDummyImplementation
  92. }
  93. // AuthorizeSSHRekey returns an unimplemented error. Provisioners should overwrite
  94. // this method if they will support authorizing tokens for rekeying SSH Certificates.
  95. func (s *SCEP) AuthorizeSSHRekey(context.Context, string) (*ssh.Certificate, []provisioner.SignOption, error) {
  96. return nil, nil, errDummyImplementation
  97. }
  98. var _ provisioner.Interface = (*SCEP)(nil)