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
|
2022-03-10 02:43:45 +00:00
|
|
|
ID string `json:"-"`
|
|
|
|
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"`
|
2022-03-10 02:43:45 +00:00
|
|
|
|
2022-01-19 10:31:33 +00:00
|
|
|
// IncludeRoot makes the provisioner return the CA root in addition to the
|
|
|
|
// intermediate in the GetCACerts response
|
|
|
|
IncludeRoot bool `json:"includeRoot,omitempty"`
|
2022-03-10 02:43:45 +00:00
|
|
|
|
2021-05-06 20:56:28 +00:00
|
|
|
// MinimumPublicKeyLength is the minimum length for public keys in CSRs
|
2022-01-14 09:48:23 +00:00
|
|
|
MinimumPublicKeyLength int `json:"minimumPublicKeyLength,omitempty"`
|
2022-03-10 02:43:45 +00:00
|
|
|
|
2022-01-14 09:48:23 +00:00
|
|
|
// Numerical identifier for the ContentEncryptionAlgorithm as defined in github.com/mozilla-services/pkcs7
|
|
|
|
// at https://github.com/mozilla-services/pkcs7/blob/33d05740a3526e382af6395d3513e73d4e66d1cb/encrypt.go#L63
|
2022-01-18 14:54:18 +00:00
|
|
|
// Defaults to 0, being DES-CBC
|
|
|
|
EncryptionAlgorithmIdentifier int `json:"encryptionAlgorithmIdentifier,omitempty"`
|
2022-01-14 09:48:23 +00:00
|
|
|
Options *Options `json:"options,omitempty"`
|
|
|
|
Claims *Claims `json:"claims,omitempty"`
|
2022-03-24 11:36:12 +00:00
|
|
|
ctl *Controller
|
2022-01-31 13:43:46 +00:00
|
|
|
secretChallengePassword string
|
|
|
|
encryptionAlgorithm int
|
2021-02-12 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 11:03:08 +00:00
|
|
|
// GetID returns the provisioner unique identifier.
|
2021-05-03 19:48:20 +00:00
|
|
|
func (s *SCEP) GetID() string {
|
|
|
|
if s.ID != "" {
|
|
|
|
return s.ID
|
|
|
|
}
|
|
|
|
return s.GetIDForToken()
|
|
|
|
}
|
|
|
|
|
2021-07-03 03:22:35 +00:00
|
|
|
// GetIDForToken returns an identifier that will be used to load the provisioner
|
|
|
|
// from a token.
|
|
|
|
func (s *SCEP) GetIDForToken() string {
|
2021-02-12 11:03:08 +00:00
|
|
|
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 {
|
2022-03-10 02:43:45 +00:00
|
|
|
return s.ctl.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-04-16 13:49:33 +00:00
|
|
|
// Mask the actual challenge value, so it won't be marshaled
|
2021-04-16 12:09:34 +00:00
|
|
|
s.secretChallengePassword = s.ChallengePassword
|
|
|
|
s.ChallengePassword = "*** redacted ***"
|
|
|
|
|
2021-05-06 20:56:28 +00:00
|
|
|
// Default to 2048 bits minimum public key length (for CSRs) if not set
|
|
|
|
if s.MinimumPublicKeyLength == 0 {
|
|
|
|
s.MinimumPublicKeyLength = 2048
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.MinimumPublicKeyLength%8 != 0 {
|
2022-01-18 14:54:18 +00:00
|
|
|
return errors.Errorf("%d bits is not exactly divisible by 8", s.MinimumPublicKeyLength)
|
2021-05-06 20:56:28 +00:00
|
|
|
}
|
|
|
|
|
2022-01-19 10:31:33 +00:00
|
|
|
s.encryptionAlgorithm = s.EncryptionAlgorithmIdentifier // TODO(hs): we might want to upgrade the default security to AES-CBC?
|
2022-01-18 14:54:18 +00:00
|
|
|
if s.encryptionAlgorithm < 0 || s.encryptionAlgorithm > 4 {
|
|
|
|
return errors.New("only encryption algorithm identifiers from 0 to 4 are valid")
|
2021-05-06 20:56:28 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 23:32:21 +00:00
|
|
|
// TODO: add other, SCEP specific, options?
|
|
|
|
|
2022-04-21 23:20:38 +00:00
|
|
|
s.ctl, err = NewController(s, s.Claims, config, s.Options)
|
2022-03-10 02:43:45 +00:00
|
|
|
return
|
2021-02-12 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
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{
|
2022-03-22 02:21:40 +00:00
|
|
|
s,
|
2021-02-26 13:00:47 +00:00
|
|
|
// modifiers / withOptions
|
|
|
|
newProvisionerExtensionOption(TypeSCEP, s.Name, ""),
|
|
|
|
newForceCNOption(s.ForceCN),
|
2022-03-10 02:43:45 +00:00
|
|
|
profileDefaultDuration(s.ctl.Claimer.DefaultTLSCertDuration()),
|
2021-02-26 13:00:47 +00:00
|
|
|
// validators
|
2021-05-06 20:56:28 +00:00
|
|
|
newPublicKeyMinimumLengthValidator(s.MinimumPublicKeyLength),
|
2022-03-10 02:43:45 +00:00
|
|
|
newValidityValidator(s.ctl.Claimer.MinTLSCertDuration(), s.ctl.Claimer.MaxTLSCertDuration()),
|
2022-05-05 10:32:53 +00:00
|
|
|
newX509NamePolicyValidator(s.ctl.getPolicy().getX509()),
|
2021-02-26 13:00:47 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:30:37 +00:00
|
|
|
// GetChallengePassword returns the challenge password
|
|
|
|
func (s *SCEP) GetChallengePassword() string {
|
2021-04-16 12:09:34 +00:00
|
|
|
return s.secretChallengePassword
|
2021-03-06 23:30:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 23:50:00 +00:00
|
|
|
// GetCapabilities returns the CA capabilities
|
|
|
|
func (s *SCEP) GetCapabilities() []string {
|
|
|
|
return s.Capabilities
|
|
|
|
}
|
2022-01-14 09:48:23 +00:00
|
|
|
|
2022-01-19 10:31:33 +00:00
|
|
|
// ShouldIncludeRootInChain indicates if the CA should
|
2022-01-14 09:48:23 +00:00
|
|
|
// return its intermediate, which is currently used for
|
2022-01-19 10:31:33 +00:00
|
|
|
// both signing and decryption, as well as the root in
|
|
|
|
// its chain.
|
|
|
|
func (s *SCEP) ShouldIncludeRootInChain() bool {
|
|
|
|
return s.IncludeRoot
|
2022-01-14 09:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetContentEncryptionAlgorithm returns the numeric identifier
|
|
|
|
// for the pkcs7 package encryption algorithm to use.
|
|
|
|
func (s *SCEP) GetContentEncryptionAlgorithm() int {
|
|
|
|
return s.encryptionAlgorithm
|
|
|
|
}
|