|
@@ -305,14 +305,21 @@ func PKIOperation(ctx context.Context, req request) (Response, error) {
|
|
|
return Response{}, err
|
|
return Response{}, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // NOTE: at this point we have sufficient information for returning nicely signed CertReps
|
|
|
|
|
- csr := msg.CSRReqMessage.CSR
|
|
|
|
|
-
|
|
|
|
|
prov, err := scep.ProvisionerFromContext(ctx)
|
|
prov, err := scep.ProvisionerFromContext(ctx)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return Response{}, err
|
|
return Response{}, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ scepProv, ok := prov.(*provisioner.SCEP)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return Response{}, errors.New("wrong type of provisioner in context")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // NOTE: at this point we have sufficient information for returning nicely signed CertReps
|
|
|
|
|
+ csr := msg.CSRReqMessage.CSR
|
|
|
|
|
+ transactionID := string(msg.TransactionID)
|
|
|
|
|
+ challengePassword := msg.CSRReqMessage.ChallengePassword
|
|
|
|
|
+
|
|
|
// NOTE: we're blocking the RenewalReq if the challenge does not match, because otherwise we don't have any authentication.
|
|
// NOTE: we're blocking the RenewalReq if the challenge does not match, because otherwise we don't have any authentication.
|
|
|
// The macOS SCEP client performs renewals using PKCSreq. The CertNanny SCEP client will use PKCSreq with challenge too, it seems,
|
|
// The macOS SCEP client performs renewals using PKCSreq. The CertNanny SCEP client will use PKCSreq with challenge too, it seems,
|
|
|
// even if using the renewal flow as described in the README.md. MicroMDM SCEP client also only does PKCSreq by default, unless
|
|
// even if using the renewal flow as described in the README.md. MicroMDM SCEP client also only does PKCSreq by default, unless
|
|
@@ -323,22 +330,22 @@ func PKIOperation(ctx context.Context, req request) (Response, error) {
|
|
|
// auth.MatchChallengePassword interface/method. Will need to think about methods
|
|
// auth.MatchChallengePassword interface/method. Will need to think about methods
|
|
|
// that don't just check the password, but do different things on success and
|
|
// that don't just check the password, but do different things on success and
|
|
|
// failure too.
|
|
// failure too.
|
|
|
- switch selectValidationMethod(prov) {
|
|
|
|
|
|
|
+ switch selectValidationMethod(scepProv) {
|
|
|
case validationMethodWebhook:
|
|
case validationMethodWebhook:
|
|
|
- c, err := webhook.New(prov.GetOptions().GetWebhooks())
|
|
|
|
|
|
|
+ c, err := webhook.New(scepProv.GetOptions().GetWebhooks())
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("failed creating SCEP validation webhook controller"))
|
|
return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("failed creating SCEP validation webhook controller"))
|
|
|
}
|
|
}
|
|
|
- if err := c.Validate(ctx, msg.CSRReqMessage.ChallengePassword); err != nil {
|
|
|
|
|
|
|
+ if err := c.Validate(ctx, challengePassword, transactionID); err != nil {
|
|
|
if errors.Is(err, provisioner.ErrWebhookDenied) {
|
|
if errors.Is(err, provisioner.ErrWebhookDenied) {
|
|
|
return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("invalid challenge password provided"))
|
|
return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("invalid challenge password provided"))
|
|
|
}
|
|
}
|
|
|
return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("failed validating challenge password"))
|
|
return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("failed validating challenge password"))
|
|
|
}
|
|
}
|
|
|
default:
|
|
default:
|
|
|
- challengeMatches, err := auth.MatchChallengePassword(ctx, msg.CSRReqMessage.ChallengePassword)
|
|
|
|
|
|
|
+ challengeMatches, err := auth.MatchChallengePassword(ctx, challengePassword)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("error when checking password"))
|
|
|
|
|
|
|
+ return createFailureResponse(ctx, csr, msg, microscep.BadRequest, errors.New("failed checking password"))
|
|
|
}
|
|
}
|
|
|
if !challengeMatches {
|
|
if !challengeMatches {
|
|
|
// TODO: can this be returned safely to the client? In the end, if the password was correct, that gains a bit of info too.
|
|
// TODO: can this be returned safely to the client? In the end, if the password was correct, that gains a bit of info too.
|
|
@@ -372,6 +379,7 @@ func PKIOperation(ctx context.Context, req request) (Response, error) {
|
|
|
type validationMethod string
|
|
type validationMethod string
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
|
|
|
+ validationMethodNone validationMethod = "none"
|
|
|
validationMethodStatic validationMethod = "static"
|
|
validationMethodStatic validationMethod = "static"
|
|
|
validationMethodWebhook validationMethod = "webhook"
|
|
validationMethodWebhook validationMethod = "webhook"
|
|
|
)
|
|
)
|
|
@@ -380,15 +388,19 @@ const (
|
|
|
// challenges. If a webhook is configured with kind `SCEPCHALLENGE`,
|
|
// challenges. If a webhook is configured with kind `SCEPCHALLENGE`,
|
|
|
// the webhook will be used. Otherwise it will default to the
|
|
// the webhook will be used. Otherwise it will default to the
|
|
|
// static challenge value.
|
|
// static challenge value.
|
|
|
-func selectValidationMethod(p scep.Provisioner) validationMethod {
|
|
|
|
|
|
|
+func selectValidationMethod(p *provisioner.SCEP) validationMethod {
|
|
|
for _, wh := range p.GetOptions().GetWebhooks() {
|
|
for _, wh := range p.GetOptions().GetWebhooks() {
|
|
|
- // if there's at least one webhook for validating SCEP challenges, the
|
|
|
|
|
- // webhook will be used to perform challenge validation.
|
|
|
|
|
|
|
+ // if at least one webhook for validating SCEP challenges has
|
|
|
|
|
+ // been configured, that will be used to perform challenge
|
|
|
|
|
+ // validation.
|
|
|
if wh.Kind == linkedca.Webhook_SCEPCHALLENGE.String() {
|
|
if wh.Kind == linkedca.Webhook_SCEPCHALLENGE.String() {
|
|
|
return validationMethodWebhook
|
|
return validationMethodWebhook
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return validationMethodStatic
|
|
|
|
|
|
|
+ if challenge := p.GetChallengePassword(); challenge != "" {
|
|
|
|
|
+ return validationMethodStatic
|
|
|
|
|
+ }
|
|
|
|
|
+ return validationMethodNone
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func formatCapabilities(caps []string) []byte {
|
|
func formatCapabilities(caps []string) []byte {
|