Documentation
¶
Index ¶
- Constants
- Variables
- func Health(service, instanceID string) http.HandlerFunc
- func RegisterCertsServiceServer(s grpc.ServiceRegistrar, srv CertsServiceServer)
- type Agent
- type CA
- type CSR
- type CSRMetadata
- type CSRPage
- type CertType
- type Certificate
- type CertificatePage
- type CertsServiceClient
- type CertsServiceServer
- 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 ( 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") ErrUpdateEntity = errors.New("update entity failed") ErrDeleteEntity = errors.New("delete 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") ErrFailedCertCreation = errors.New("failed to create certificate") 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 Agent ¶ added in v0.18.0
type Agent interface {
Issue(ttl string, ipAddrs []string, options SubjectOptions) (Certificate, error)
View(serialNumber string) (Certificate, error)
Revoke(serialNumber string) error
ListCerts(pm PageMetadata) (CertificatePage, error)
GetCA() ([]byte, error)
GetCAChain() ([]byte, error)
GetCRL() ([]byte, error)
SignCSR(csr []byte, ttl string) (Certificate, error)
Renew(cert Certificate, increment string) (Certificate, error)
OCSP(serialNumber string, ocspRequestDER []byte) ([]byte, error)
}
Agent represents the PKI interface that all PKI implementations must satisfy.
type CA ¶
type CA struct {
Type CertType
Certificate *x509.Certificate
PrivateKey *rsa.PrivateKey
SerialNumber string
}
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 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 {
// SaveCertEntityMapping saves the mapping between certificate serial number and entity ID.
SaveCertEntityMapping(ctx context.Context, serialNumber, entityID string) error
// GetEntityIDBySerial retrieves the entity ID for a given certificate serial number.
GetEntityIDBySerial(ctx context.Context, serialNumber string) (string, error)
// ListCertsByEntityID lists all certificate serial numbers for a given entity ID.
ListCertsByEntityID(ctx context.Context, entityID string) ([]string, error)
// RemoveCertEntityMapping removes the mapping between certificate and entity ID.
RemoveCertEntityMapping(ctx context.Context, serialNumber 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 by issuing a new certificate with the same parameters.
// Returns the new certificate with extended TTL and a new serial number.
RenewCert(ctx context.Context, session authn.Session, serialNumber string) (Certificate, error)
// RevokeBySerial revokes a single certificate by its serial number.
RevokeBySerial(ctx context.Context, session authn.Session, serialNumber string) error
// RevokeAll revokes all certificates for a given entity ID.
RevokeAll(ctx context.Context, session authn.Session, entityID string) error
// ViewCert retrieves a certificate record from the database.
ViewCert(ctx context.Context, session authn.Session, serialNumber string) (Certificate, error)
// ListCerts retrieves the certificates from the database while applying filters.
ListCerts(ctx context.Context, session authn.Session, pm PageMetadata) (CertificatePage, error)
// IssueCert issues a certificate from the database.
IssueCert(ctx context.Context, session authn.Session, entityID, ttl string, ipAddrs []string, option SubjectOptions) (Certificate, error)
// OCSP forwards OCSP requests to OpenBao's OCSP endpoint.
// If ocspRequestDER is provided, it will be used directly; otherwise, a request will be built from the serialNumber.
OCSP(ctx context.Context, serialNumber string, ocspRequestDER []byte) ([]byte, 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) ([]byte, error)
// RetrieveCAChain retrieves the chain of CA i.e. root and intermediate cert concat together.
RetrieveCAChain(ctx context.Context) (Certificate, error)
// IssueFromCSR creates a certificate from a given CSR.
IssueFromCSR(ctx context.Context, session authn.Session, entityID, ttl string, csr CSR) (Certificate, error)
// IssueFromCSRInternal creates a certificate from a given CSR using agent token authentication.
IssueFromCSRInternal(ctx context.Context, entityID, ttl string, csr CSR) (Certificate, error)
}
func NewService ¶
type SubjectOptions ¶
type SubjectOptions 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 []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.