4
0

scep.go 4.5 KB

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