|
@@ -93,6 +93,12 @@ func withDefaultASN1DN(def *config.ASN1DN) provisioner.CertificateModifierFunc {
|
|
|
|
|
|
|
|
// Sign creates a signed certificate from a certificate signing request.
|
|
// Sign creates a signed certificate from a certificate signing request.
|
|
|
func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.SignOptions, extraOpts ...provisioner.SignOption) ([]*x509.Certificate, error) {
|
|
func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.SignOptions, extraOpts ...provisioner.SignOption) ([]*x509.Certificate, error) {
|
|
|
|
|
+ chain, prov, err := a.signX509(csr, signOpts, extraOpts...)
|
|
|
|
|
+ a.meter.X509Signed(prov, err)
|
|
|
|
|
+ return chain, err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (a *Authority) signX509(csr *x509.CertificateRequest, signOpts provisioner.SignOptions, extraOpts ...provisioner.SignOption) ([]*x509.Certificate, provisioner.Interface, error) {
|
|
|
var (
|
|
var (
|
|
|
certOptions []x509util.Option
|
|
certOptions []x509util.Option
|
|
|
certValidators []provisioner.CertificateValidator
|
|
certValidators []provisioner.CertificateValidator
|
|
@@ -100,9 +106,9 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
certEnforcers []provisioner.CertificateEnforcer
|
|
certEnforcers []provisioner.CertificateEnforcer
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- opts := []interface{}{errs.WithKeyVal("csr", csr), errs.WithKeyVal("signOptions", signOpts)}
|
|
|
|
|
|
|
+ opts := []any{errs.WithKeyVal("csr", csr), errs.WithKeyVal("signOptions", signOpts)}
|
|
|
if err := csr.CheckSignature(); err != nil {
|
|
if err := csr.CheckSignature(); err != nil {
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ return nil, nil, errs.ApplyOptions(
|
|
|
errs.BadRequestErr(err, "invalid certificate request"),
|
|
errs.BadRequestErr(err, "invalid certificate request"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -111,10 +117,12 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
// Set backdate with the configured value
|
|
// Set backdate with the configured value
|
|
|
signOpts.Backdate = a.config.AuthorityConfig.Backdate.Duration
|
|
signOpts.Backdate = a.config.AuthorityConfig.Backdate.Duration
|
|
|
|
|
|
|
|
- var prov provisioner.Interface
|
|
|
|
|
- var pInfo *casapi.ProvisionerInfo
|
|
|
|
|
- var attData *provisioner.AttestationData
|
|
|
|
|
- var webhookCtl webhookController
|
|
|
|
|
|
|
+ var (
|
|
|
|
|
+ prov provisioner.Interface
|
|
|
|
|
+ pInfo *casapi.ProvisionerInfo
|
|
|
|
|
+ attData *provisioner.AttestationData
|
|
|
|
|
+ webhookCtl webhookController
|
|
|
|
|
+ )
|
|
|
for _, op := range extraOpts {
|
|
for _, op := range extraOpts {
|
|
|
switch k := op.(type) {
|
|
switch k := op.(type) {
|
|
|
// Capture current provisioner
|
|
// Capture current provisioner
|
|
@@ -132,7 +140,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
// Validate the given certificate request.
|
|
// Validate the given certificate request.
|
|
|
case provisioner.CertificateRequestValidator:
|
|
case provisioner.CertificateRequestValidator:
|
|
|
if err := k.Valid(csr); err != nil {
|
|
if err := k.Valid(csr); err != nil {
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error validating certificate request"),
|
|
errs.ForbiddenErr(err, "error validating certificate request"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -159,45 +167,46 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
webhookCtl = k
|
|
webhookCtl = k
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
- return nil, errs.InternalServer("authority.Sign; invalid extra option type %T", append([]interface{}{k}, opts...)...)
|
|
|
|
|
|
|
+ return nil, prov, errs.InternalServer("authority.Sign; invalid extra option type %T", append([]any{k}, opts...)...)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if err := callEnrichingWebhooksX509(webhookCtl, attData, csr); err != nil {
|
|
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ if err := a.callEnrichingWebhooksX509(prov, webhookCtl, attData, csr); err != nil {
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, err.Error()),
|
|
errs.ForbiddenErr(err, err.Error()),
|
|
|
errs.WithKeyVal("csr", csr),
|
|
errs.WithKeyVal("csr", csr),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cert, err := x509util.NewCertificate(csr, certOptions...)
|
|
|
|
|
|
|
+ crt, err := x509util.NewCertificate(csr, certOptions...)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
var te *x509util.TemplateError
|
|
var te *x509util.TemplateError
|
|
|
- if errors.As(err, &te) {
|
|
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ switch {
|
|
|
|
|
+ case errors.As(err, &te):
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.BadRequestErr(err, err.Error()),
|
|
errs.BadRequestErr(err, err.Error()),
|
|
|
errs.WithKeyVal("csr", csr),
|
|
errs.WithKeyVal("csr", csr),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
)
|
|
)
|
|
|
- }
|
|
|
|
|
- // explicitly check for unmarshaling errors, which are most probably caused by JSON template (syntax) errors
|
|
|
|
|
- if strings.HasPrefix(err.Error(), "error unmarshaling certificate") {
|
|
|
|
|
- return nil, errs.InternalServerErr(templatingError(err),
|
|
|
|
|
|
|
+ case strings.HasPrefix(err.Error(), "error unmarshaling certificate"):
|
|
|
|
|
+ // explicitly check for unmarshaling errors, which are most probably caused by JSON template (syntax) errors
|
|
|
|
|
+ return nil, prov, errs.InternalServerErr(templatingError(err),
|
|
|
errs.WithKeyVal("csr", csr),
|
|
errs.WithKeyVal("csr", csr),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
errs.WithMessage("error applying certificate template"),
|
|
errs.WithMessage("error applying certificate template"),
|
|
|
)
|
|
)
|
|
|
|
|
+ default:
|
|
|
|
|
+ return nil, prov, errs.Wrap(http.StatusInternalServerError, err, "authority.Sign", opts...)
|
|
|
}
|
|
}
|
|
|
- return nil, errs.Wrap(http.StatusInternalServerError, err, "authority.Sign", opts...)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Certificate modifiers before validation
|
|
// Certificate modifiers before validation
|
|
|
- leaf := cert.GetCertificate()
|
|
|
|
|
|
|
+ leaf := crt.GetCertificate()
|
|
|
|
|
|
|
|
// Set default subject
|
|
// Set default subject
|
|
|
if err := withDefaultASN1DN(a.config.AuthorityConfig.Template).Modify(leaf, signOpts); err != nil {
|
|
if err := withDefaultASN1DN(a.config.AuthorityConfig.Template).Modify(leaf, signOpts); err != nil {
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -205,7 +214,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
|
|
|
|
|
for _, m := range certModifiers {
|
|
for _, m := range certModifiers {
|
|
|
if err := m.Modify(leaf, signOpts); err != nil {
|
|
if err := m.Modify(leaf, signOpts); err != nil {
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -215,7 +224,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
// Certificate validation.
|
|
// Certificate validation.
|
|
|
for _, v := range certValidators {
|
|
for _, v := range certValidators {
|
|
|
if err := v.Valid(leaf, signOpts); err != nil {
|
|
if err := v.Valid(leaf, signOpts); err != nil {
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error validating certificate"),
|
|
errs.ForbiddenErr(err, "error validating certificate"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -224,8 +233,8 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
|
|
|
|
|
// Certificate modifiers after validation
|
|
// Certificate modifiers after validation
|
|
|
for _, m := range certEnforcers {
|
|
for _, m := range certEnforcers {
|
|
|
- if err := m.Enforce(leaf); err != nil {
|
|
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ if err = m.Enforce(leaf); err != nil {
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -234,8 +243,8 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
|
|
|
|
|
// Process injected modifiers after validation
|
|
// Process injected modifiers after validation
|
|
|
for _, m := range a.x509Enforcers {
|
|
for _, m := range a.x509Enforcers {
|
|
|
- if err := m.Enforce(leaf); err != nil {
|
|
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ if err = m.Enforce(leaf); err != nil {
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -243,12 +252,12 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check if authority is allowed to sign the certificate
|
|
// Check if authority is allowed to sign the certificate
|
|
|
- if err := a.isAllowedToSignX509Certificate(leaf); err != nil {
|
|
|
|
|
|
|
+ if err = a.isAllowedToSignX509Certificate(leaf); err != nil {
|
|
|
var ee *errs.Error
|
|
var ee *errs.Error
|
|
|
if errors.As(err, &ee) {
|
|
if errors.As(err, &ee) {
|
|
|
- return nil, errs.ApplyOptions(ee, opts...)
|
|
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(ee, opts...)
|
|
|
}
|
|
}
|
|
|
- return nil, errs.InternalServerErr(err,
|
|
|
|
|
|
|
+ return nil, prov, errs.InternalServerErr(err,
|
|
|
errs.WithKeyVal("csr", csr),
|
|
errs.WithKeyVal("csr", csr),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
errs.WithMessage("error creating certificate"),
|
|
errs.WithMessage("error creating certificate"),
|
|
@@ -256,8 +265,8 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Send certificate to webhooks for authorization
|
|
// Send certificate to webhooks for authorization
|
|
|
- if err := callAuthorizingWebhooksX509(webhookCtl, cert, leaf, attData); err != nil {
|
|
|
|
|
- return nil, errs.ApplyOptions(
|
|
|
|
|
|
|
+ if err := a.callAuthorizingWebhooksX509(prov, webhookCtl, crt, leaf, attData); err != nil {
|
|
|
|
|
+ return nil, prov, errs.ApplyOptions(
|
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
errs.ForbiddenErr(err, "error creating certificate"),
|
|
|
opts...,
|
|
opts...,
|
|
|
)
|
|
)
|
|
@@ -265,6 +274,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
|
|
|
|
|
// Sign certificate
|
|
// Sign certificate
|
|
|
lifetime := leaf.NotAfter.Sub(leaf.NotBefore.Add(signOpts.Backdate))
|
|
lifetime := leaf.NotAfter.Sub(leaf.NotBefore.Add(signOpts.Backdate))
|
|
|
|
|
+
|
|
|
resp, err := a.x509CAService.CreateCertificate(&casapi.CreateCertificateRequest{
|
|
resp, err := a.x509CAService.CreateCertificate(&casapi.CreateCertificateRequest{
|
|
|
Template: leaf,
|
|
Template: leaf,
|
|
|
CSR: csr,
|
|
CSR: csr,
|
|
@@ -273,23 +283,22 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
|
|
|
Provisioner: pInfo,
|
|
Provisioner: pInfo,
|
|
|
})
|
|
})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, errs.Wrap(http.StatusInternalServerError, err, "authority.Sign; error creating certificate", opts...)
|
|
|
|
|
|
|
+ return nil, prov, errs.Wrap(http.StatusInternalServerError, err, "authority.Sign; error creating certificate", opts...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fullchain := append([]*x509.Certificate{resp.Certificate}, resp.CertificateChain...)
|
|
|
|
|
|
|
+ chain := append([]*x509.Certificate{resp.Certificate}, resp.CertificateChain...)
|
|
|
|
|
|
|
|
- // Wrap provisioner with extra information.
|
|
|
|
|
- prov = wrapProvisioner(prov, attData)
|
|
|
|
|
|
|
+ // Wrap provisioner with extra information, if not nil
|
|
|
|
|
+ if prov != nil {
|
|
|
|
|
+ prov = wrapProvisioner(prov, attData)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Store certificate in the db.
|
|
// Store certificate in the db.
|
|
|
- if err = a.storeCertificate(prov, fullchain); err != nil {
|
|
|
|
|
- if !errors.Is(err, db.ErrNotImplemented) {
|
|
|
|
|
- return nil, errs.Wrap(http.StatusInternalServerError, err,
|
|
|
|
|
- "authority.Sign; error storing certificate in db", opts...)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if err := a.storeCertificate(prov, chain); err != nil && !errors.Is(err, db.ErrNotImplemented) {
|
|
|
|
|
+ return nil, prov, errs.Wrap(http.StatusInternalServerError, err, "authority.Sign; error storing certificate in db", opts...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return fullchain, nil
|
|
|
|
|
|
|
+ return chain, prov, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// isAllowedToSignX509Certificate checks if the Authority is allowed
|
|
// isAllowedToSignX509Certificate checks if the Authority is allowed
|
|
@@ -337,14 +346,25 @@ func (a *Authority) Rekey(oldCert *x509.Certificate, pk crypto.PublicKey) ([]*x5
|
|
|
// of rekey), and 'NotBefore/NotAfter' (the validity duration of the new
|
|
// of rekey), and 'NotBefore/NotAfter' (the validity duration of the new
|
|
|
// certificate should be equal to the old one, but starting 'now').
|
|
// certificate should be equal to the old one, but starting 'now').
|
|
|
func (a *Authority) RenewContext(ctx context.Context, oldCert *x509.Certificate, pk crypto.PublicKey) ([]*x509.Certificate, error) {
|
|
func (a *Authority) RenewContext(ctx context.Context, oldCert *x509.Certificate, pk crypto.PublicKey) ([]*x509.Certificate, error) {
|
|
|
|
|
+ chain, prov, err := a.renewContext(ctx, oldCert, pk)
|
|
|
|
|
+ if pk == nil {
|
|
|
|
|
+ a.meter.X509Renewed(prov, err)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ a.meter.X509Rekeyed(prov, err)
|
|
|
|
|
+ }
|
|
|
|
|
+ return chain, err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (a *Authority) renewContext(ctx context.Context, oldCert *x509.Certificate, pk crypto.PublicKey) ([]*x509.Certificate, provisioner.Interface, error) {
|
|
|
isRekey := (pk != nil)
|
|
isRekey := (pk != nil)
|
|
|
opts := []errs.Option{
|
|
opts := []errs.Option{
|
|
|
errs.WithKeyVal("serialNumber", oldCert.SerialNumber.String()),
|
|
errs.WithKeyVal("serialNumber", oldCert.SerialNumber.String()),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check step provisioner extensions
|
|
// Check step provisioner extensions
|
|
|
- if err := a.authorizeRenew(ctx, oldCert); err != nil {
|
|
|
|
|
- return nil, errs.StatusCodeError(http.StatusInternalServerError, err, opts...)
|
|
|
|
|
|
|
+ prov, err := a.authorizeRenew(ctx, oldCert)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, prov, errs.StatusCodeError(http.StatusInternalServerError, err, opts...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Durations
|
|
// Durations
|
|
@@ -414,15 +434,17 @@ func (a *Authority) RenewContext(ctx context.Context, oldCert *x509.Certificate,
|
|
|
//
|
|
//
|
|
|
// TODO(hslatman,maraino): consider adding policies too and consider if
|
|
// TODO(hslatman,maraino): consider adding policies too and consider if
|
|
|
// RenewSSH should check policies.
|
|
// RenewSSH should check policies.
|
|
|
- if err := a.constraintsEngine.ValidateCertificate(newCert); err != nil {
|
|
|
|
|
|
|
+ if err = a.constraintsEngine.ValidateCertificate(newCert); err != nil {
|
|
|
var ee *errs.Error
|
|
var ee *errs.Error
|
|
|
- if errors.As(err, &ee) {
|
|
|
|
|
- return nil, errs.StatusCodeError(ee.StatusCode(), err, opts...)
|
|
|
|
|
|
|
+ switch {
|
|
|
|
|
+ case errors.As(err, &ee):
|
|
|
|
|
+ return nil, prov, errs.StatusCodeError(ee.StatusCode(), err, opts...)
|
|
|
|
|
+ default:
|
|
|
|
|
+ return nil, prov, errs.InternalServerErr(err,
|
|
|
|
|
+ errs.WithKeyVal("serialNumber", oldCert.SerialNumber.String()),
|
|
|
|
|
+ errs.WithMessage("error renewing certificate"),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
- return nil, errs.InternalServerErr(err,
|
|
|
|
|
- errs.WithKeyVal("serialNumber", oldCert.SerialNumber.String()),
|
|
|
|
|
- errs.WithMessage("error renewing certificate"),
|
|
|
|
|
- )
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// The token can optionally be in the context. If the CA is running in RA
|
|
// The token can optionally be in the context. If the CA is running in RA
|
|
@@ -436,17 +458,16 @@ func (a *Authority) RenewContext(ctx context.Context, oldCert *x509.Certificate,
|
|
|
Token: token,
|
|
Token: token,
|
|
|
})
|
|
})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, errs.StatusCodeError(http.StatusInternalServerError, err, opts...)
|
|
|
|
|
|
|
+ return nil, prov, errs.StatusCodeError(http.StatusInternalServerError, err, opts...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fullchain := append([]*x509.Certificate{resp.Certificate}, resp.CertificateChain...)
|
|
|
|
|
- if err = a.storeRenewedCertificate(oldCert, fullchain); err != nil {
|
|
|
|
|
- if !errors.Is(err, db.ErrNotImplemented) {
|
|
|
|
|
- return nil, errs.StatusCodeError(http.StatusInternalServerError, err, opts...)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ chain := append([]*x509.Certificate{resp.Certificate}, resp.CertificateChain...)
|
|
|
|
|
+
|
|
|
|
|
+ if err = a.storeRenewedCertificate(oldCert, chain); err != nil && !errors.Is(err, db.ErrNotImplemented) {
|
|
|
|
|
+ return nil, prov, errs.StatusCodeError(http.StatusInternalServerError, err, opts...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return fullchain, nil
|
|
|
|
|
|
|
+ return chain, prov, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// storeCertificate allows to use an extension of the db.AuthDB interface that
|
|
// storeCertificate allows to use an extension of the db.AuthDB interface that
|
|
@@ -952,42 +973,52 @@ func templatingError(err error) error {
|
|
|
return errors.Wrap(cause, "error applying certificate template")
|
|
return errors.Wrap(cause, "error applying certificate template")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func callEnrichingWebhooksX509(webhookCtl webhookController, attData *provisioner.AttestationData, csr *x509.CertificateRequest) error {
|
|
|
|
|
|
|
+func (a *Authority) callEnrichingWebhooksX509(prov provisioner.Interface, webhookCtl webhookController, attData *provisioner.AttestationData, csr *x509.CertificateRequest) (err error) {
|
|
|
if webhookCtl == nil {
|
|
if webhookCtl == nil {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
var attested *webhook.AttestationData
|
|
var attested *webhook.AttestationData
|
|
|
if attData != nil {
|
|
if attData != nil {
|
|
|
attested = &webhook.AttestationData{
|
|
attested = &webhook.AttestationData{
|
|
|
PermanentIdentifier: attData.PermanentIdentifier,
|
|
PermanentIdentifier: attData.PermanentIdentifier,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- whEnrichReq, err := webhook.NewRequestBody(
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var whEnrichReq *webhook.RequestBody
|
|
|
|
|
+ if whEnrichReq, err = webhook.NewRequestBody(
|
|
|
webhook.WithX509CertificateRequest(csr),
|
|
webhook.WithX509CertificateRequest(csr),
|
|
|
webhook.WithAttestationData(attested),
|
|
webhook.WithAttestationData(attested),
|
|
|
- )
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
|
|
+ ); err == nil {
|
|
|
|
|
+ err = webhookCtl.Enrich(whEnrichReq)
|
|
|
|
|
+
|
|
|
|
|
+ a.meter.X509WebhookEnriched(prov, err)
|
|
|
}
|
|
}
|
|
|
- return webhookCtl.Enrich(whEnrichReq)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func callAuthorizingWebhooksX509(webhookCtl webhookController, cert *x509util.Certificate, leaf *x509.Certificate, attData *provisioner.AttestationData) error {
|
|
|
|
|
|
|
+func (a *Authority) callAuthorizingWebhooksX509(prov provisioner.Interface, webhookCtl webhookController, cert *x509util.Certificate, leaf *x509.Certificate, attData *provisioner.AttestationData) (err error) {
|
|
|
if webhookCtl == nil {
|
|
if webhookCtl == nil {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
var attested *webhook.AttestationData
|
|
var attested *webhook.AttestationData
|
|
|
if attData != nil {
|
|
if attData != nil {
|
|
|
attested = &webhook.AttestationData{
|
|
attested = &webhook.AttestationData{
|
|
|
PermanentIdentifier: attData.PermanentIdentifier,
|
|
PermanentIdentifier: attData.PermanentIdentifier,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- whAuthBody, err := webhook.NewRequestBody(
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var whAuthBody *webhook.RequestBody
|
|
|
|
|
+ if whAuthBody, err = webhook.NewRequestBody(
|
|
|
webhook.WithX509Certificate(cert, leaf),
|
|
webhook.WithX509Certificate(cert, leaf),
|
|
|
webhook.WithAttestationData(attested),
|
|
webhook.WithAttestationData(attested),
|
|
|
- )
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
|
|
+ ); err == nil {
|
|
|
|
|
+ err = webhookCtl.Authorize(whAuthBody)
|
|
|
|
|
+
|
|
|
|
|
+ a.meter.X509WebhookAuthorized(prov, err)
|
|
|
}
|
|
}
|
|
|
- return webhookCtl.Authorize(whAuthBody)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|