2020-09-09 02:26:32 +00:00
|
|
|
package apiv1
|
|
|
|
|
2020-09-10 23:19:18 +00:00
|
|
|
import (
|
2021-09-08 22:33:34 +00:00
|
|
|
"crypto/x509"
|
2021-03-22 19:56:12 +00:00
|
|
|
"net/http"
|
2020-09-10 23:19:18 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-09-09 02:26:32 +00:00
|
|
|
// CertificateAuthorityService is the interface implemented to support external
|
|
|
|
// certificate authorities.
|
|
|
|
type CertificateAuthorityService interface {
|
|
|
|
CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error)
|
|
|
|
RenewCertificate(req *RenewCertificateRequest) (*RenewCertificateResponse, error)
|
|
|
|
RevokeCertificate(req *RevokeCertificateRequest) (*RevokeCertificateResponse, error)
|
|
|
|
}
|
|
|
|
|
2021-10-30 07:52:50 +00:00
|
|
|
// CertificateAuthorityCRLGenerator is an optional interface implemented by CertificateAuthorityService
|
|
|
|
// that has a method to create a CRL
|
|
|
|
type CertificateAuthorityCRLGenerator interface {
|
2021-11-04 06:05:07 +00:00
|
|
|
CreateCRL(req *CreateCRLRequest) (*CreateCRLResponse, error)
|
2021-10-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 22:27:20 +00:00
|
|
|
// CertificateAuthorityGetter is an interface implemented by a
|
|
|
|
// CertificateAuthorityService that has a method to get the root certificate.
|
|
|
|
type CertificateAuthorityGetter interface {
|
|
|
|
GetCertificateAuthority(req *GetCertificateAuthorityRequest) (*GetCertificateAuthorityResponse, error)
|
|
|
|
}
|
|
|
|
|
2020-10-23 22:04:09 +00:00
|
|
|
// CertificateAuthorityCreator is an interface implamented by a
|
|
|
|
// CertificateAuthorityService that has a method to create a new certificate
|
|
|
|
// authority.
|
|
|
|
type CertificateAuthorityCreator interface {
|
|
|
|
CreateCertificateAuthority(req *CreateCertificateAuthorityRequest) (*CreateCertificateAuthorityResponse, error)
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:33:34 +00:00
|
|
|
// SignatureAlgorithmGetter is an optional implementation in a crypto.Signer
|
|
|
|
// that returns the SignatureAlgorithm to use.
|
|
|
|
type SignatureAlgorithmGetter interface {
|
|
|
|
SignatureAlgorithm() x509.SignatureAlgorithm
|
|
|
|
}
|
|
|
|
|
2020-09-11 02:09:46 +00:00
|
|
|
// Type represents the CAS type used.
|
2020-09-09 02:26:32 +00:00
|
|
|
type Type string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DefaultCAS is a CertificateAuthorityService using software.
|
|
|
|
DefaultCAS = ""
|
|
|
|
// SoftCAS is a CertificateAuthorityService using software.
|
2020-09-11 02:09:46 +00:00
|
|
|
SoftCAS = "softcas"
|
2020-09-09 02:26:32 +00:00
|
|
|
// CloudCAS is a CertificateAuthorityService using Google Cloud CAS.
|
2020-09-11 02:09:46 +00:00
|
|
|
CloudCAS = "cloudcas"
|
2021-03-18 02:33:35 +00:00
|
|
|
// StepCAS is a CertificateAuthorityService using another step-ca instance.
|
|
|
|
StepCAS = "stepcas"
|
2022-01-14 17:56:17 +00:00
|
|
|
// VaultCAS is a CertificateAuthorityService using Hasicorp Vault PKI.
|
|
|
|
VaultCAS = "vaultcas"
|
2020-09-09 02:26:32 +00:00
|
|
|
)
|
2020-09-10 23:19:18 +00:00
|
|
|
|
2020-09-11 02:09:46 +00:00
|
|
|
// String returns a string from the type. It will always return the lower case
|
|
|
|
// version of the Type, as we need a standard type to compare and use as the
|
|
|
|
// registry key.
|
2020-09-10 23:19:18 +00:00
|
|
|
func (t Type) String() string {
|
|
|
|
if t == "" {
|
|
|
|
return SoftCAS
|
|
|
|
}
|
2020-09-11 02:09:46 +00:00
|
|
|
return strings.ToLower(string(t))
|
2020-09-10 23:19:18 +00:00
|
|
|
}
|
2021-03-22 19:56:12 +00:00
|
|
|
|
2022-09-20 22:54:59 +00:00
|
|
|
// NotImplementedError is the type of error returned if an operation is not implemented.
|
2022-09-20 23:32:49 +00:00
|
|
|
type NotImplementedError struct {
|
2021-03-22 19:56:12 +00:00
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
2022-11-07 23:37:17 +00:00
|
|
|
// Error implements the error interface.
|
2022-09-20 22:54:59 +00:00
|
|
|
func (e NotImplementedError) Error() string {
|
2021-03-22 19:56:12 +00:00
|
|
|
if e.Message != "" {
|
|
|
|
return e.Message
|
|
|
|
}
|
|
|
|
return "not implemented"
|
|
|
|
}
|
|
|
|
|
|
|
|
// StatusCode implements the StatusCoder interface and returns the HTTP 501
|
|
|
|
// error.
|
2022-09-20 22:54:59 +00:00
|
|
|
func (e NotImplementedError) StatusCode() int {
|
2021-03-22 19:56:12 +00:00
|
|
|
return http.StatusNotImplemented
|
|
|
|
}
|
2022-11-04 23:42:07 +00:00
|
|
|
|
|
|
|
// ValidationError is the type of error returned if request is not properly
|
|
|
|
// validated.
|
|
|
|
type ValidationError struct {
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NotImplementedError implements the error interface.
|
|
|
|
func (e ValidationError) Error() string {
|
|
|
|
if e.Message != "" {
|
|
|
|
return e.Message
|
|
|
|
}
|
|
|
|
return "bad request"
|
|
|
|
}
|
|
|
|
|
|
|
|
// StatusCode implements the StatusCoder interface and returns the HTTP 400
|
|
|
|
// error.
|
|
|
|
func (e ValidationError) StatusCode() int {
|
|
|
|
return http.StatusBadRequest
|
|
|
|
}
|