Documentation
¶
Index ¶
- Constants
- Variables
- func Health(service, instanceID string) http.HandlerFunc
- func RegisterCertsServiceServer(s grpc.ServiceRegistrar, srv CertsServiceServer)
- type CA
- type CAConfig
- type CSR
- type CSRMetadata
- type CSRPage
- type CertType
- type Certificate
- type CertificatePage
- type CertsServiceClient
- type CertsServiceServer
- type Config
- type EntityReq
- type EntityRes
- type HealthInfo
- type PageMetadata
- type Repository
- type RevokeReq
- type Service
- type SubjectOptions
- type UnimplementedCertsServiceServer
- type UnsafeCertsServiceServer
Constants ¶
const ( Root = "RootCA" Inter = "IntermediateCA" Client = "ClientCert" Unknown = "Unknown" )
const ( CertsService_GetEntityID_FullMethodName = "/absmach.certs.CertsService/GetEntityID" CertsService_RevokeCerts_FullMethodName = "/absmach.certs.CertsService/RevokeCerts" )
const ( Organization = "AbstractMacines" PrivateKeyBytes = 2048 RootCAValidityPeriod = time.Hour * 24 * 365 // 365 days IntermediateCAVAlidityPeriod = time.Hour * 24 * 90 // 90 days PrivateKey = "PRIVATE KEY" RSAPrivateKey = "RSA PRIVATE KEY" ECPrivateKey = "EC PRIVATE KEY" PKCS8PrivateKey = "PKCS8 PRIVATE KEY" EDPrivateKey = "ED25519 PRIVATE KEY" )
Variables ¶
var ( // Version represents the last service git tag in git history. // It's meant to be set using go build ldflags. Version = "0.0.0" Commit = "ffffffff" // BuildTime represetns the service build time. // It's meant to be set using go build ldflags. BuildTime = "1970-01-01_00:00:00" )
var ( ErrNotFound = errors.New("entity not found") ErrConflict = errors.New("entity already exists") ErrCreateEntity = errors.New("failed to create entity") ErrViewEntity = errors.New("view entity failed") ErrGetToken = errors.New("failed to get token") ErrUpdateEntity = errors.New("update entity failed") ErrMalformedEntity = errors.New("malformed entity specification") ErrRootCANotFound = errors.New("root CA not found") ErrIntermediateCANotFound = errors.New("intermediate CA not found") ErrCertExpired = errors.New("certificate expired before renewal") ErrCertRevoked = errors.New("certificate has been revoked and cannot be renewed") ErrCertInvalidType = errors.New("invalid cert type") ErrInvalidLength = errors.New("invalid length of serial numbers") ErrPrivKeyType = errors.New("unsupported private key type") ErrPubKeyType = errors.New("unsupported public key type") ErrFailedParse = errors.New("failed to parse key PEM") ErrInvalidIP = errors.New("invalid IP address") )
var CertsService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "absmach.certs.CertsService", HandlerType: (*CertsServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "GetEntityID", Handler: _CertsService_GetEntityID_Handler, }, { MethodName: "RevokeCerts", Handler: _CertsService_RevokeCerts_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "certs.proto", }
CertsService_ServiceDesc is the grpc.ServiceDesc for CertsService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)
var File_certs_proto protoreflect.FileDescriptor
Functions ¶
func Health ¶
func Health(service, instanceID string) http.HandlerFunc
Health exposes an HTTP handler for retrieving service health.
func RegisterCertsServiceServer ¶
func RegisterCertsServiceServer(s grpc.ServiceRegistrar, srv CertsServiceServer)
Types ¶
type CA ¶
type CA struct {
Type CertType
Certificate *x509.Certificate
PrivateKey *rsa.PrivateKey
SerialNumber string
}
type CAConfig ¶
type CAConfig struct {
CommonName string `yaml:"common_name"`
Organization []string `yaml:"organization"`
OrganizationalUnit []string `yaml:"organizational_unit"`
Country []string `yaml:"country"`
Province []string `yaml:"province"`
Locality []string `yaml:"locality"`
StreetAddress []string `yaml:"street_address"`
PostalCode []string `yaml:"postal_code"`
DNSNames []string `yaml:"dns_names"`
IPAddresses []string `yaml:"ip_addresses"`
ValidityPeriod string `yaml:"validity_period"`
}
type CSRMetadata ¶
type CSRMetadata struct {
CommonName string `json:"common_name"`
Organization []string `json:"organization"`
OrganizationalUnit []string `json:"organizational_unit"`
Country []string `json:"country"`
Province []string `json:"province"`
Locality []string `json:"locality"`
StreetAddress []string `json:"street_address"`
PostalCode []string `json:"postal_code"`
DNSNames []string `json:"dns_names"`
IPAddresses []string `json:"ip_addresses"`
EmailAddresses []string `json:"email_addresses"`
ExtraExtensions []pkix.Extension `json:"extra_extensions"`
}
type CSRPage ¶
type CSRPage struct {
PageMetadata
CSRs []CSR `json:"csrs,omitempty"`
}
type Certificate ¶
type CertificatePage ¶
type CertificatePage struct {
PageMetadata
Certificates []Certificate
}
type CertsServiceClient ¶
type CertsServiceClient interface {
GetEntityID(ctx context.Context, in *EntityReq, opts ...grpc.CallOption) (*EntityRes, error)
RevokeCerts(ctx context.Context, in *RevokeReq, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
CertsServiceClient is the client API for CertsService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewCertsServiceClient ¶
func NewCertsServiceClient(cc grpc.ClientConnInterface) CertsServiceClient
type CertsServiceServer ¶
type CertsServiceServer interface {
GetEntityID(context.Context, *EntityReq) (*EntityRes, error)
RevokeCerts(context.Context, *RevokeReq) (*emptypb.Empty, error)
// contains filtered or unexported methods
}
CertsServiceServer is the server API for CertsService service. All implementations must embed UnimplementedCertsServiceServer for forward compatibility.
type Config ¶
type Config struct {
CommonName string `yaml:"common_name"`
Organization []string `yaml:"organization"`
OrganizationalUnit []string `yaml:"organizational_unit"`
Country []string `yaml:"country"`
Province []string `yaml:"province"`
Locality []string `yaml:"locality"`
StreetAddress []string `yaml:"street_address"`
PostalCode []string `yaml:"postal_code"`
DNSNames []string `yaml:"dns_names"`
IPAddresses []net.IP `yaml:"ip_addresses"`
ValidityPeriod string `yaml:"validity_period"`
}
func LoadConfig ¶
type EntityReq ¶
type EntityReq struct {
SerialNumber string `protobuf:"bytes,1,opt,name=serial_number,json=serialNumber,proto3" json:"serial_number,omitempty"`
// contains filtered or unexported fields
}
func (*EntityReq) Descriptor
deprecated
func (*EntityReq) GetSerialNumber ¶
func (*EntityReq) ProtoMessage ¶
func (*EntityReq) ProtoMessage()
func (*EntityReq) ProtoReflect ¶
func (x *EntityReq) ProtoReflect() protoreflect.Message
type EntityRes ¶
type EntityRes struct {
EntityId string `protobuf:"bytes,1,opt,name=entity_id,json=entityId,proto3" json:"entity_id,omitempty"`
// contains filtered or unexported fields
}
func (*EntityRes) Descriptor
deprecated
func (*EntityRes) GetEntityId ¶
func (*EntityRes) ProtoMessage ¶
func (*EntityRes) ProtoMessage()
func (*EntityRes) ProtoReflect ¶
func (x *EntityRes) ProtoReflect() protoreflect.Message
type HealthInfo ¶
type HealthInfo struct {
// Status contains service status.
Status string `json:"status"`
// Version contains current service version.
Version string `json:"version"`
// Commit represents the git hash commit.
Commit string `json:"commit"`
// Description contains service description.
Description string `json:"description"`
// BuildTime contains service build time.
BuildTime string `json:"build_time"`
// InstanceID contains the ID of the current service instance
InstanceID string `json:"instance_id"`
}
HealthInfo contains version endpoint response.
type PageMetadata ¶
type Repository ¶
type Repository interface {
// CreateCert adds a certificate record to the database.
CreateCert(ctx context.Context, cert Certificate) error
// RetrieveCert retrieves a certificate record from the database.
RetrieveCert(ctx context.Context, serialNumber string) (Certificate, error)
// UpdateCert updates a certificate record in the database.
UpdateCert(ctx context.Context, cert Certificate) error
// ListCerts retrieves the certificates from the database while applying filters.
ListCerts(ctx context.Context, pm PageMetadata) (CertificatePage, error)
// GetCAs retrieves rootCA and intermediateCA from database.
GetCAs(ctx context.Context, caType ...CertType) ([]Certificate, error)
// ListRevokedCerts retrieves revoked lists from database.
ListRevokedCerts(ctx context.Context) ([]Certificate, error)
// RemoveCert deletes cert from database.
RemoveCert(ctx context.Context, entityId string) error
// RevokeCertsByEntityID revokes all certificates for a given entity ID.
RevokeCertsByEntityID(ctx context.Context, entityID string) error
}
type RevokeReq ¶
type RevokeReq struct {
EntityId string `protobuf:"bytes,1,opt,name=entity_id,json=entityId,proto3" json:"entity_id,omitempty"`
// contains filtered or unexported fields
}
func (*RevokeReq) Descriptor
deprecated
func (*RevokeReq) GetEntityId ¶
func (*RevokeReq) ProtoMessage ¶
func (*RevokeReq) ProtoMessage()
func (*RevokeReq) ProtoReflect ¶
func (x *RevokeReq) ProtoReflect() protoreflect.Message
type Service ¶
type Service interface {
// RenewCert renews a certificate from the database.
RenewCert(ctx context.Context, serialNumber string) error
// RevokeCert revokes a certificate from the database.
RevokeCert(ctx context.Context, serialNumber string) error
// RetrieveCert retrieves a certificate record from the database.
RetrieveCert(ctx context.Context, token, serialNumber string) (Certificate, []byte, error)
// ViewCert retrieves a certificate record from the database.
ViewCert(ctx context.Context, serialNumber string) (Certificate, error)
// ListCerts retrieves the certificates from the database while applying filters.
ListCerts(ctx context.Context, pm PageMetadata) (CertificatePage, error)
// RetrieveCertDownloadToken generates a certificate download token.
// The token is needed to download the client certificate.
RetrieveCertDownloadToken(ctx context.Context, serialNumber string) (string, error)
// RetrieveCAToken generates a CA download and view token.
// The token is needed to view and download the CA certificate.
RetrieveCAToken(ctx context.Context) (string, error)
// IssueCert issues a certificate from the database.
IssueCert(ctx context.Context, entityID, ttl string, ipAddrs []string, option SubjectOptions) (Certificate, error)
// OCSP retrieves the OCSP response for a certificate.
OCSP(ctx context.Context, serialNumber string) (*Certificate, int, *x509.Certificate, error)
// GetEntityID retrieves the entity ID for a certificate.
GetEntityID(ctx context.Context, serialNumber string) (string, error)
// GenerateCRL creates cert revocation list.
GenerateCRL(ctx context.Context, caType CertType) ([]byte, error)
// GetChainCA retrieves the chain of CA i.e. root and intermediate cert concat together.
GetChainCA(ctx context.Context, token string) (Certificate, error)
// RemoveCert deletes a cert for a provided entityID.
RemoveCert(ctx context.Context, entityId string) error
// IssueFromCSR creates a certificate from a given CSR.
IssueFromCSR(ctx context.Context, entityID, ttl string, csr CSR) (Certificate, error)
// RevokeCerts revokes all certificates for a given entity ID.
RevokeCerts(ctx context.Context, entityID string) error
}
func NewService ¶
type SubjectOptions ¶
type SubjectOptions struct {
CommonName string
Organization []string `json:"organization"`
OrganizationalUnit []string `json:"organizational_unit"`
Country []string `json:"country"`
Province []string `json:"province"`
Locality []string `json:"locality"`
StreetAddress []string `json:"street_address"`
PostalCode []string `json:"postal_code"`
DnsNames []string `json:"dns_names"`
IpAddresses []net.IP `json:"ip_addresses"`
}
type UnimplementedCertsServiceServer ¶
type UnimplementedCertsServiceServer struct{}
UnimplementedCertsServiceServer must be embedded to have forward compatible implementations.
NOTE: this should be embedded by value instead of pointer to avoid a nil pointer dereference when methods are called.
func (UnimplementedCertsServiceServer) GetEntityID ¶
func (UnimplementedCertsServiceServer) RevokeCerts ¶
type UnsafeCertsServiceServer ¶
type UnsafeCertsServiceServer interface {
// contains filtered or unexported methods
}
UnsafeCertsServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to CertsServiceServer will result in compilation errors.