Skip to content

Commit

Permalink
Add additional properties to SCEP notify webhook request body
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Sep 21, 2023
1 parent 63257e0 commit b6c95d7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
11 changes: 5 additions & 6 deletions authority/provisioner/scep.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ func (c *notificationController) Success(ctx context.Context, csr *x509.Certific
return fmt.Errorf("failed creating new webhook request: %w", err)
}
req.X509Certificate.Raw = cert.Raw // adding the full certificate DER bytes

// TODO(hs): more properties required?
req.SCEPTransactionID = transactionID
resp, err := wh.DoWithContext(ctx, c.client, req, nil)
if err != nil {
Expand All @@ -211,14 +209,15 @@ func (c *notificationController) Success(ctx context.Context, csr *x509.Certific
return nil
}

func (c *notificationController) Failure(ctx context.Context, csr *x509.CertificateRequest, transactionID string) error {
func (c *notificationController) Failure(ctx context.Context, csr *x509.CertificateRequest, transactionID string, errorCode int, errorDescription string) error {
for _, wh := range c.webhooks {
req, err := webhook.NewRequestBody(webhook.WithX509CertificateRequest(csr))
if err != nil {
return fmt.Errorf("failed creating new webhook request: %w", err)
}
// TODO(hs): more properties, such as error message / code required?
req.SCEPTransactionID = transactionID
req.SCEPErrorCode = errorCode
req.SCEPErrorDescription = errorDescription
resp, err := wh.DoWithContext(ctx, c.client, req, nil)
if err != nil {
return fmt.Errorf("failed executing webhook request: %w", err)
Expand Down Expand Up @@ -427,11 +426,11 @@ func (s *SCEP) NotifySuccess(ctx context.Context, csr *x509.CertificateRequest,
return s.notificationController.Success(ctx, csr, cert, transactionID)
}

func (s *SCEP) NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string) error {
func (s *SCEP) NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string, errorCode int, errorDescription string) error {
if s.notificationController == nil {
return fmt.Errorf("provisioner %q wasn't initialized", s.Name)
}
return s.notificationController.Failure(ctx, csr, transactionID)
return s.notificationController.Failure(ctx, csr, transactionID, errorCode, errorDescription)
}

type validationMethod string
Expand Down
3 changes: 3 additions & 0 deletions scep/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ func PKIOperation(ctx context.Context, req request) (Response, error) {

certRep, err := auth.SignCSR(ctx, csr, msg)
if err != nil {
// default to ERROR_INTERNAL_ERROR: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d
errorCode := 0x0000054F

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / govulncheck / govulncheck

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (stable)

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (stable)

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (oldstable)

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (oldstable)

errorCode declared and not used

Check failure on line 337 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / build / build (oldstable)

errorCode declared and not used
errorDescription := err.Error()

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / govulncheck / govulncheck

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (stable)

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (stable)

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (oldstable)

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (oldstable)

errorDescription declared and not used

Check failure on line 338 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / build / build (oldstable)

errorDescription declared and not used
if notifyErr := auth.NotifyFailure(ctx, csr, transactionID); notifyErr != nil {

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / govulncheck / govulncheck

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (stable)

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (stable)

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (oldstable)

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / test / test (oldstable)

not enough arguments in call to auth.NotifyFailure

Check failure on line 339 in scep/api/api.go

View workflow job for this annotation

GitHub Actions / ci / build / build (oldstable)

not enough arguments in call to auth.NotifyFailure
// TODO(hs): ignore this error case? It's not critical if the notification fails; but logging it might be good
_ = notifyErr
Expand Down
4 changes: 2 additions & 2 deletions scep/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ func (a *Authority) NotifySuccess(ctx context.Context, csr *x509.CertificateRequ
return p.NotifySuccess(ctx, csr, cert, transactionID)
}

func (a *Authority) NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string) error {
func (a *Authority) NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string, errorCode int, errorDescription string) error {
p := provisionerFromContext(ctx)
return p.NotifyFailure(ctx, csr, transactionID)
return p.NotifyFailure(ctx, csr, transactionID, errorCode, errorDescription)
}

func (a *Authority) selectDecrypter(ctx context.Context) (cert *x509.Certificate, decrypter crypto.Decrypter, err error) {
Expand Down
2 changes: 1 addition & 1 deletion scep/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Provisioner interface {
GetContentEncryptionAlgorithm() int
ValidateChallenge(ctx context.Context, csr *x509.CertificateRequest, challenge, transactionID string) error
NotifySuccess(ctx context.Context, csr *x509.CertificateRequest, cert *x509.Certificate, transactionID string) error
NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string) error
NotifyFailure(ctx context.Context, csr *x509.CertificateRequest, transactionID string, errorCode int, errorDescription string) error
}

// provisionerKey is the key type for storing and searching a
Expand Down
6 changes: 4 additions & 2 deletions webhook/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ type RequestBody struct {
SSHCertificateRequest *SSHCertificateRequest `json:"sshCertificateRequest,omitempty"`
SSHCertificate *SSHCertificate `json:"sshCertificate,omitempty"`
// Only set for SCEP challenge validation requests
SCEPChallenge string `json:"scepChallenge,omitempty"`
SCEPTransactionID string `json:"scepTransactionID,omitempty"`
SCEPChallenge string `json:"scepChallenge,omitempty"`
SCEPTransactionID string `json:"scepTransactionID,omitempty"`
SCEPErrorCode int `json:"scepErrorCode,omitempty"`
SCEPErrorDescription string `json:"scepErrorDescription,omitempty"`
// Only set for X5C provisioners
X5CCertificate *X5CCertificate `json:"x5cCertificate,omitempty"`
// Set for X5C, AWS, GCP, and Azure provisioners
Expand Down

0 comments on commit b6c95d7

Please sign in to comment.