|
@@ -19,6 +19,7 @@ import (
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
|
|
"github.com/smallstep/certificates/db"
|
|
"github.com/smallstep/certificates/db"
|
|
|
"github.com/smallstep/certificates/errs"
|
|
"github.com/smallstep/certificates/errs"
|
|
|
|
|
+ "github.com/smallstep/certificates/internal/cast"
|
|
|
"github.com/smallstep/certificates/templates"
|
|
"github.com/smallstep/certificates/templates"
|
|
|
"github.com/smallstep/certificates/webhook"
|
|
"github.com/smallstep/certificates/webhook"
|
|
|
)
|
|
)
|
|
@@ -214,7 +215,7 @@ func (a *Authority) signSSH(ctx context.Context, key ssh.PublicKey, opts provisi
|
|
|
for _, v := range keyValidators {
|
|
for _, v := range keyValidators {
|
|
|
if err := v.Valid(key); err != nil {
|
|
if err := v.Valid(key); err != nil {
|
|
|
return nil, nil, errs.ApplyOptions(
|
|
return nil, nil, errs.ApplyOptions(
|
|
|
- errs.ForbiddenErr(err, err.Error()), //nolint:govet // allow non-constant error messages
|
|
|
|
|
|
|
+ errs.ForbiddenErr(err, err.Error()),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -231,7 +232,7 @@ func (a *Authority) signSSH(ctx context.Context, key ssh.PublicKey, opts provisi
|
|
|
// Call enriching webhooks
|
|
// Call enriching webhooks
|
|
|
if err := a.callEnrichingWebhooksSSH(ctx, prov, webhookCtl, cr); err != nil {
|
|
if err := a.callEnrichingWebhooksSSH(ctx, prov, webhookCtl, cr); err != nil {
|
|
|
return nil, prov, errs.ApplyOptions(
|
|
return nil, prov, errs.ApplyOptions(
|
|
|
- errs.ForbiddenErr(err, err.Error()), //nolint:govet // allow non-constant error messages
|
|
|
|
|
|
|
+ errs.ForbiddenErr(err, err.Error()),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -243,7 +244,7 @@ func (a *Authority) signSSH(ctx context.Context, key ssh.PublicKey, opts provisi
|
|
|
switch {
|
|
switch {
|
|
|
case errors.As(err, &te):
|
|
case errors.As(err, &te):
|
|
|
return nil, prov, errs.ApplyOptions(
|
|
return nil, prov, errs.ApplyOptions(
|
|
|
- errs.BadRequestErr(err, err.Error()), //nolint:govet // allow non-constant error messages
|
|
|
|
|
|
|
+ errs.BadRequestErr(err, err.Error()),
|
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
errs.WithKeyVal("signOptions", signOpts),
|
|
|
)
|
|
)
|
|
|
case strings.HasPrefix(err.Error(), "error unmarshaling certificate"):
|
|
case strings.HasPrefix(err.Error(), "error unmarshaling certificate"):
|
|
@@ -263,7 +264,7 @@ func (a *Authority) signSSH(ctx context.Context, key ssh.PublicKey, opts provisi
|
|
|
// Use SignSSHOptions to modify the certificate validity. It will be later
|
|
// Use SignSSHOptions to modify the certificate validity. It will be later
|
|
|
// checked or set if not defined.
|
|
// checked or set if not defined.
|
|
|
if err := opts.ModifyValidity(certTpl); err != nil {
|
|
if err := opts.ModifyValidity(certTpl); err != nil {
|
|
|
- return nil, prov, errs.BadRequestErr(err, err.Error()) //nolint:govet // allow non-constant error messages
|
|
|
|
|
|
|
+ return nil, prov, errs.BadRequestErr(err, err.Error())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Use provisioner modifiers.
|
|
// Use provisioner modifiers.
|
|
@@ -356,7 +357,7 @@ func (a *Authority) renewSSH(ctx context.Context, oldCert *ssh.Certificate) (*ss
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
backdate := a.config.AuthorityConfig.Backdate.Duration
|
|
backdate := a.config.AuthorityConfig.Backdate.Duration
|
|
|
- duration := time.Duration(oldCert.ValidBefore-oldCert.ValidAfter) * time.Second
|
|
|
|
|
|
|
+ duration := time.Duration(cast.Int64(oldCert.ValidBefore-oldCert.ValidAfter)) * time.Second
|
|
|
now := time.Now()
|
|
now := time.Now()
|
|
|
va := now.Add(-1 * backdate)
|
|
va := now.Add(-1 * backdate)
|
|
|
vb := now.Add(duration - backdate)
|
|
vb := now.Add(duration - backdate)
|
|
@@ -370,8 +371,8 @@ func (a *Authority) renewSSH(ctx context.Context, oldCert *ssh.Certificate) (*ss
|
|
|
ValidPrincipals: oldCert.ValidPrincipals,
|
|
ValidPrincipals: oldCert.ValidPrincipals,
|
|
|
Permissions: oldCert.Permissions,
|
|
Permissions: oldCert.Permissions,
|
|
|
Reserved: oldCert.Reserved,
|
|
Reserved: oldCert.Reserved,
|
|
|
- ValidAfter: uint64(va.Unix()),
|
|
|
|
|
- ValidBefore: uint64(vb.Unix()),
|
|
|
|
|
|
|
+ ValidAfter: cast.Uint64(va.Unix()),
|
|
|
|
|
+ ValidBefore: cast.Uint64(vb.Unix()),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get signer from authority keys
|
|
// Get signer from authority keys
|
|
@@ -436,7 +437,7 @@ func (a *Authority) rekeySSH(ctx context.Context, oldCert *ssh.Certificate, pub
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
backdate := a.config.AuthorityConfig.Backdate.Duration
|
|
backdate := a.config.AuthorityConfig.Backdate.Duration
|
|
|
- duration := time.Duration(oldCert.ValidBefore-oldCert.ValidAfter) * time.Second
|
|
|
|
|
|
|
+ duration := time.Duration(cast.Int64(oldCert.ValidBefore-oldCert.ValidAfter)) * time.Second
|
|
|
now := time.Now()
|
|
now := time.Now()
|
|
|
va := now.Add(-1 * backdate)
|
|
va := now.Add(-1 * backdate)
|
|
|
vb := now.Add(duration - backdate)
|
|
vb := now.Add(duration - backdate)
|
|
@@ -450,8 +451,8 @@ func (a *Authority) rekeySSH(ctx context.Context, oldCert *ssh.Certificate, pub
|
|
|
ValidPrincipals: oldCert.ValidPrincipals,
|
|
ValidPrincipals: oldCert.ValidPrincipals,
|
|
|
Permissions: oldCert.Permissions,
|
|
Permissions: oldCert.Permissions,
|
|
|
Reserved: oldCert.Reserved,
|
|
Reserved: oldCert.Reserved,
|
|
|
- ValidAfter: uint64(va.Unix()),
|
|
|
|
|
- ValidBefore: uint64(vb.Unix()),
|
|
|
|
|
|
|
+ ValidAfter: cast.Uint64(va.Unix()),
|
|
|
|
|
+ ValidBefore: cast.Uint64(vb.Unix()),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get signer from authority keys
|
|
// Get signer from authority keys
|