2021-02-12 11:03:08 +00:00
|
|
|
package scep
|
|
|
|
|
|
|
|
import (
|
2021-02-26 13:00:47 +00:00
|
|
|
"context"
|
2023-05-26 21:52:24 +00:00
|
|
|
"crypto"
|
|
|
|
"crypto/x509"
|
2021-02-12 16:02:39 +00:00
|
|
|
|
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
2021-02-12 11:03:08 +00:00
|
|
|
)
|
|
|
|
|
2023-07-26 17:11:51 +00:00
|
|
|
// Provisioner is an interface that embeds the
|
|
|
|
// provisioner.Interface and adds some SCEP specific
|
|
|
|
// functions.
|
2021-02-12 11:03:08 +00:00
|
|
|
type Provisioner interface {
|
2023-07-26 17:11:51 +00:00
|
|
|
provisioner.Interface
|
2021-02-12 16:02:39 +00:00
|
|
|
GetOptions() *provisioner.Options
|
2021-03-06 23:50:00 +00:00
|
|
|
GetCapabilities() []string
|
2022-01-19 10:31:33 +00:00
|
|
|
ShouldIncludeRootInChain() bool
|
2023-09-04 12:55:27 +00:00
|
|
|
ShouldIncludeIntermediateInChain() bool
|
2023-05-26 21:52:24 +00:00
|
|
|
GetDecrypter() (*x509.Certificate, crypto.Decrypter)
|
2023-07-26 22:55:39 +00:00
|
|
|
GetSigner() (*x509.Certificate, crypto.Signer)
|
2022-01-14 09:48:23 +00:00
|
|
|
GetContentEncryptionAlgorithm() int
|
2023-09-07 12:11:53 +00:00
|
|
|
ValidateChallenge(ctx context.Context, csr *x509.CertificateRequest, challenge, transactionID string) error
|
2021-02-12 11:03:08 +00:00
|
|
|
}
|
2023-06-01 13:46:21 +00:00
|
|
|
|
2023-06-01 14:22:00 +00:00
|
|
|
// provisionerKey is the key type for storing and searching a
|
|
|
|
// SCEP provisioner in the context.
|
|
|
|
type provisionerKey struct{}
|
2023-06-01 13:46:21 +00:00
|
|
|
|
|
|
|
// provisionerFromContext searches the context for a SCEP provisioner.
|
2023-06-01 14:22:00 +00:00
|
|
|
// Returns the provisioner or panics if no SCEP provisioner is found.
|
|
|
|
func provisionerFromContext(ctx context.Context) Provisioner {
|
|
|
|
p, ok := ctx.Value(provisionerKey{}).(Provisioner)
|
|
|
|
if !ok {
|
|
|
|
panic("SCEP provisioner expected in request context")
|
2023-06-01 13:46:21 +00:00
|
|
|
}
|
2023-06-01 14:22:00 +00:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProvisionerContext(ctx context.Context, p Provisioner) context.Context {
|
|
|
|
return context.WithValue(ctx, provisionerKey{}, p)
|
2023-06-01 13:46:21 +00:00
|
|
|
}
|