2021-02-12 11:03:08 +00:00
|
|
|
package provisioner
|
|
|
|
|
|
|
|
import (
|
2021-02-26 13:00:47 +00:00
|
|
|
"context"
|
2021-02-12 16:02:39 +00:00
|
|
|
"time"
|
2021-02-12 11:03:08 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SCEP is the SCEP provisioner type, an entity that can authorize the
|
|
|
|
// SCEP provisioning flow
|
|
|
|
type SCEP struct {
|
|
|
|
*base
|
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
2021-03-06 23:30:37 +00:00
|
|
|
ForceCN bool `json:"forceCN,omitempty"`
|
|
|
|
ChallengePassword string `json:"challenge,omitempty"`
|
2021-03-06 23:50:00 +00:00
|
|
|
Capabilities []string `json:"capabilities,omitempty"`
|
2021-03-06 23:30:37 +00:00
|
|
|
Options *Options `json:"options,omitempty"`
|
|
|
|
Claims *Claims `json:"claims,omitempty"`
|
|
|
|
claimer *Claimer
|
2021-02-12 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetID returns the provisioner unique identifier.
|
|
|
|
func (s SCEP) GetID() string {
|
|
|
|
return "scep/" + s.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetName returns the name of the provisioner.
|
|
|
|
func (s *SCEP) GetName() string {
|
|
|
|
return s.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetType returns the type of provisioner.
|
|
|
|
func (s *SCEP) GetType() Type {
|
|
|
|
return TypeSCEP
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetEncryptedKey returns the base provisioner encrypted key if it's defined.
|
|
|
|
func (s *SCEP) GetEncryptedKey() (string, string, bool) {
|
|
|
|
return "", "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTokenID returns the identifier of the token.
|
|
|
|
func (s *SCEP) GetTokenID(ott string) (string, error) {
|
|
|
|
return "", errors.New("scep provisioner does not implement GetTokenID")
|
|
|
|
}
|
|
|
|
|
2021-02-12 16:02:39 +00:00
|
|
|
// GetOptions returns the configured provisioner options.
|
|
|
|
func (s *SCEP) GetOptions() *Options {
|
|
|
|
return s.Options
|
2021-02-12 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 16:02:39 +00:00
|
|
|
// DefaultTLSCertDuration returns the default TLS cert duration enforced by
|
|
|
|
// the provisioner.
|
|
|
|
func (s *SCEP) DefaultTLSCertDuration() time.Duration {
|
|
|
|
return s.claimer.DefaultTLSCertDuration()
|
2021-02-12 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 23:32:21 +00:00
|
|
|
// Init initializes and validates the fields of a SCEP type.
|
2021-02-12 11:03:08 +00:00
|
|
|
func (s *SCEP) Init(config Config) (err error) {
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case s.Type == "":
|
|
|
|
return errors.New("provisioner type cannot be empty")
|
|
|
|
case s.Name == "":
|
|
|
|
return errors.New("provisioner name cannot be empty")
|
|
|
|
}
|
|
|
|
|
2021-02-12 16:02:39 +00:00
|
|
|
// Update claims with global ones
|
|
|
|
if s.claimer, err = NewClaimer(s.Claims, config.Claims); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-12 11:03:08 +00:00
|
|
|
|
2021-02-25 23:32:21 +00:00
|
|
|
// TODO: add other, SCEP specific, options?
|
|
|
|
|
2021-02-12 11:03:08 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:30:37 +00:00
|
|
|
// AuthorizeSign does not do any verification, because all verification is handled
|
2021-02-26 13:00:47 +00:00
|
|
|
// in the SCEP protocol. This method returns a list of modifiers / constraints
|
|
|
|
// on the resulting certificate.
|
|
|
|
func (s *SCEP) AuthorizeSign(ctx context.Context, token string) ([]SignOption, error) {
|
|
|
|
return []SignOption{
|
|
|
|
// modifiers / withOptions
|
|
|
|
newProvisionerExtensionOption(TypeSCEP, s.Name, ""),
|
|
|
|
newForceCNOption(s.ForceCN),
|
|
|
|
profileDefaultDuration(s.claimer.DefaultTLSCertDuration()),
|
|
|
|
// validators
|
|
|
|
defaultPublicKeyValidator{},
|
|
|
|
newValidityValidator(s.claimer.MinTLSCertDuration(), s.claimer.MaxTLSCertDuration()),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:30:37 +00:00
|
|
|
// GetChallengePassword returns the challenge password
|
|
|
|
func (s *SCEP) GetChallengePassword() string {
|
|
|
|
return s.ChallengePassword
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:50:00 +00:00
|
|
|
// GetCapabilities returns the CA capabilities
|
|
|
|
func (s *SCEP) GetCapabilities() []string {
|
|
|
|
return s.Capabilities
|
|
|
|
}
|
|
|
|
|
2021-02-12 11:03:08 +00:00
|
|
|
// Interface guards
|
|
|
|
var (
|
|
|
|
_ Interface = (*SCEP)(nil)
|
|
|
|
//_ scep.Provisioner = (*SCEP)(nil)
|
|
|
|
)
|