2019-05-27 00:41:10 +00:00
|
|
|
package acme
|
|
|
|
|
|
|
|
import (
|
2020-05-07 03:18:12 +00:00
|
|
|
"context"
|
2019-05-27 00:41:10 +00:00
|
|
|
"crypto/x509"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
|
|
|
)
|
|
|
|
|
2021-03-05 07:10:46 +00:00
|
|
|
// CertificateAuthority is the interface implemented by a CA authority.
|
|
|
|
type CertificateAuthority interface {
|
|
|
|
Sign(cr *x509.CertificateRequest, opts provisioner.SignOptions, signOpts ...provisioner.SignOption) ([]*x509.Certificate, error)
|
|
|
|
LoadProvisionerByID(string) (provisioner.Interface, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clock that returns time in UTC rounded to seconds.
|
2021-03-29 19:04:14 +00:00
|
|
|
type Clock struct{}
|
2021-03-05 07:10:46 +00:00
|
|
|
|
|
|
|
// Now returns the UTC time rounded to seconds.
|
|
|
|
func (c *Clock) Now() time.Time {
|
|
|
|
return time.Now().UTC().Round(time.Second)
|
|
|
|
}
|
|
|
|
|
2021-03-29 19:04:14 +00:00
|
|
|
var clock Clock
|
2021-03-05 07:10:46 +00:00
|
|
|
|
2020-05-20 01:44:55 +00:00
|
|
|
// Provisioner is an interface that implements a subset of the provisioner.Interface --
|
|
|
|
// only those methods required by the ACME api/authority.
|
|
|
|
type Provisioner interface {
|
|
|
|
AuthorizeSign(ctx context.Context, token string) ([]provisioner.SignOption, error)
|
2021-02-28 01:05:37 +00:00
|
|
|
GetID() string
|
2020-05-20 01:44:55 +00:00
|
|
|
GetName() string
|
|
|
|
DefaultTLSCertDuration() time.Duration
|
2020-07-23 01:24:45 +00:00
|
|
|
GetOptions() *provisioner.Options
|
2020-05-20 01:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MockProvisioner for testing
|
|
|
|
type MockProvisioner struct {
|
|
|
|
Mret1 interface{}
|
|
|
|
Merr error
|
2021-02-28 01:05:37 +00:00
|
|
|
MgetID func() string
|
2020-05-20 01:44:55 +00:00
|
|
|
MgetName func() string
|
|
|
|
MauthorizeSign func(ctx context.Context, ott string) ([]provisioner.SignOption, error)
|
|
|
|
MdefaultTLSCertDuration func() time.Duration
|
2020-07-23 01:24:45 +00:00
|
|
|
MgetOptions func() *provisioner.Options
|
2020-05-20 01:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetName mock
|
|
|
|
func (m *MockProvisioner) GetName() string {
|
|
|
|
if m.MgetName != nil {
|
|
|
|
return m.MgetName()
|
|
|
|
}
|
|
|
|
return m.Mret1.(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuthorizeSign mock
|
|
|
|
func (m *MockProvisioner) AuthorizeSign(ctx context.Context, ott string) ([]provisioner.SignOption, error) {
|
|
|
|
if m.MauthorizeSign != nil {
|
|
|
|
return m.MauthorizeSign(ctx, ott)
|
|
|
|
}
|
|
|
|
return m.Mret1.([]provisioner.SignOption), m.Merr
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultTLSCertDuration mock
|
|
|
|
func (m *MockProvisioner) DefaultTLSCertDuration() time.Duration {
|
|
|
|
if m.MdefaultTLSCertDuration != nil {
|
|
|
|
return m.MdefaultTLSCertDuration()
|
|
|
|
}
|
|
|
|
return m.Mret1.(time.Duration)
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:05:37 +00:00
|
|
|
// GetOptions mock
|
2020-07-23 01:24:45 +00:00
|
|
|
func (m *MockProvisioner) GetOptions() *provisioner.Options {
|
2020-07-21 02:01:43 +00:00
|
|
|
if m.MgetOptions != nil {
|
|
|
|
return m.MgetOptions()
|
|
|
|
}
|
2020-07-23 01:24:45 +00:00
|
|
|
return m.Mret1.(*provisioner.Options)
|
2020-07-21 02:01:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:05:37 +00:00
|
|
|
// GetID mock
|
|
|
|
func (m *MockProvisioner) GetID() string {
|
|
|
|
if m.MgetID != nil {
|
|
|
|
return m.MgetID()
|
|
|
|
}
|
|
|
|
return m.Mret1.(string)
|
|
|
|
}
|