Documentation ¶
Overview ¶
Package bifrost contains an API client for the Bifrost CA service.
Package bifrost provides simple Public Key Infrastructure (PKI) services.
Bifrost identifies clients by their private keys. Keys are deterministically mapped to UUIDs by hashing them with the namespace UUID. The same key maps to different UUIDs in different namespaces. Clients can request certificates for their UUIDs. The certificates are signed by a root CA.
Index ¶
- Constants
- Variables
- func CertificateRequestTemplate(ns uuid.UUID, key *PublicKey) *x509.CertificateRequest
- func GetNamespace(ctx context.Context, caUrl string) (uuid.UUID, error)
- func HTTPClient(caUrl string, ns uuid.UUID, privkey *PrivateKey, roots *x509.CertPool, ...) (*http.Client, error)
- func UUID(ns uuid.UUID, pubkey *PublicKey) uuid.UUID
- func X509ToTLSCertificate(cert *x509.Certificate, key *ecdsa.PrivateKey) *tls.Certificate
- type Certificate
- type CertificateRequest
- type Identity
- type PrivateKey
- func (p PrivateKey) MarshalBinary() ([]byte, error)
- func (p PrivateKey) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)
- func (p PrivateKey) MarshalJSON() ([]byte, error)
- func (p PrivateKey) MarshalText() ([]byte, error)
- func (p PrivateKey) PublicKey() *PublicKey
- func (p PrivateKey) UUID(ns uuid.UUID) uuid.UUID
- func (p *PrivateKey) UnmarshalBinary(data []byte) error
- func (p *PrivateKey) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error
- func (p *PrivateKey) UnmarshalJSON(data []byte) error
- func (p *PrivateKey) UnmarshalText(text []byte) error
- type PublicKey
- func (p *PublicKey) Equal(other *PublicKey) bool
- func (p PublicKey) MarshalBinary() ([]byte, error)
- func (p PublicKey) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)
- func (p PublicKey) MarshalJSON() ([]byte, error)
- func (p PublicKey) MarshalText() ([]byte, error)
- func (p PublicKey) UUID(ns uuid.UUID) uuid.UUID
- func (p *PublicKey) UnmarshalBinary(data []byte) error
- func (p *PublicKey) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error
- func (p *PublicKey) UnmarshalJSON(data []byte) error
- func (p *PublicKey) UnmarshalText(text []byte) error
Examples ¶
Constants ¶
const ( SignatureAlgorithm = x509.ECDSAWithSHA256 PublicKeyAlgorithm = x509.ECDSA )
Signature and Public Key Algorithms.
const Version = `dev`
Variables ¶
var ( // ErrCertificateInvalid is returned when an invalid certificate is parsed. ErrCertificateInvalid = errors.New("bifrost: certificate invalid") // ErrRequestDenied is returned when a certificate request is denied by the CA Gauntlet. ErrRequestDenied = errors.New("bifrost: certificate request denied") // ErrRequestInvalid is returned when an invalid certificate request is parsed. ErrRequestInvalid = errors.New("bifrost: certificate request invalid") // ErrRequestAborted is returned when the CA Gauntlet function times out or panics. ErrRequestAborted = errors.New("bifrost: certificate request aborted") )
Errors.
var StatsForNerds = metrics.NewSet()
StatsForNerds captures metrics from various bifrost processes.
Functions ¶
func CertificateRequestTemplate ¶ added in v1.19.0
func CertificateRequestTemplate(ns uuid.UUID, key *PublicKey) *x509.CertificateRequest
CertificateRequestTemplate returns a bifrost certificate request template for a namespace and public key.
func GetNamespace ¶ added in v1.20.1
GetNamespace returns the namespace from the CA at url.
func HTTPClient ¶ added in v0.0.6
func HTTPClient( caUrl string, ns uuid.UUID, privkey *PrivateKey, roots *x509.CertPool, ssllog io.Writer, ) (*http.Client, error)
HTTPClient returns a http.Client set up for TLS Client Authentication (mTLS). The client will request a new certificate from the bifrost caUrl when needed. If roots is not nil, then only those Root CAs are used to authenticate server certs. If ssllog is not nil, the client will log TLS key material to it.
func UUID ¶
UUID returns a unique identifier derived from the namespace and the client's public key identity. The UUID is generated by SHA-1 hashing the namesapce UUID with the big endian bytes of the X and Y curve points from the public key.
func X509ToTLSCertificate ¶
func X509ToTLSCertificate(cert *x509.Certificate, key *ecdsa.PrivateKey) *tls.Certificate
X509ToTLSCertificate puts an x509.Certificate inside a tls.Certificate.
Types ¶
type Certificate ¶ added in v1.11.0
Certificate is a bifrost certificate. It embeds the x509 certificate and adds the bifrost ID, namespace, and public key.
func NewCertificate ¶ added in v1.16.0
func NewCertificate(cert *x509.Certificate) (*Certificate, error)
NewCertificate creates a bifrost certificate from an x509 certificate. It checks for the correct signature algorithm, identity namespace, and identity. On success, it sets the ID, Namespace, and PublicKey fields.
func ParseCertificate ¶
func ParseCertificate(asn1Data []byte) (*Certificate, error)
ParseCertificate parses a DER encoded certificate and validates it. On success, it returns the bifrost certificate.
func RequestCertificate ¶
func RequestCertificate( ctx context.Context, caUrl string, namespace uuid.UUID, key *PrivateKey, ) (*Certificate, error)
RequestCertificate sends a certificate request over HTTP to url and returns the signed certificate. The returned error wraps ErrCertificateRequestInvalid or ErrCertificateRequestDenied if the request is invalid or denied.
Example ¶
const timeout = 5 * time.Second exampleNS := uuid.MustParse("228b9676-998e-489a-8468-92d46a94a32d") ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() key, err := NewPrivateKey() if err != nil { panic(err) } cert, err := RequestCertificate(ctx, "https://bifrost-ca", exampleNS, key) if errors.Is(err, ErrRequestInvalid) { // This error is returned when the wrong namespace is used in the CSR, // or if the CSR is invalid. fmt.Println("namespace mismatch or invalid csr") } else if errors.Is(err, ErrRequestDenied) { // This error is returned when the request is denied by the CA gauntlet function. fmt.Println("csr denied") } // Success. fmt.Println(cert.Subject)
Output:
func (Certificate) IsCA ¶ added in v1.16.7
func (c Certificate) IsCA() bool
IsCA returns true if the certificate can be used as a certificate authority.
func (*Certificate) IssuedTo ¶ added in v1.16.0
func (c *Certificate) IssuedTo(key *PublicKey) bool
IssuedTo returns true if the certificate was issued to the given public key.
func (Certificate) ToTLSCertificate ¶ added in v1.11.0
func (c Certificate) ToTLSCertificate(key PrivateKey) (*tls.Certificate, error)
ToTLSCertificate returns a tls.Certificate from a bifrost certificate and private key.
type CertificateRequest ¶ added in v1.11.0
type CertificateRequest struct { *x509.CertificateRequest ID uuid.UUID Namespace uuid.UUID PublicKey *PublicKey }
CertificateRequest is a bifrost certificate request. It embeds the x509 certificate request and adds the bifrost ID, namespace, and public key.
func NewCertificateRequest ¶ added in v1.16.0
func NewCertificateRequest(cert *x509.CertificateRequest) (*CertificateRequest, error)
NewCertificateRequest creates a bifrost certificate request from an x509 certificate request. It checks for the correct signature algorithm, identity namespace, and identity. On success, it sets the ID, Namespace, and PublicKey fields.
func ParseCertificateRequest ¶ added in v1.5.2
func ParseCertificateRequest(asn1Data []byte) (*CertificateRequest, error)
ParseCertificateRequest parses a DER encoded certificate request and validates it. On success, it returns the bifrost namespace, certificate request, and certificate public key.
type Identity ¶ added in v1.16.6
Identity represents a unique identity in the system.
func ParseIdentity ¶ added in v1.16.6
ParseIdentity parses a Bifrost identity from a PEM-encoded block. The block may contain a private key, public key, certificate, or certificate request.
If the block contains a private or a public key, the returned identity will contain the public key. If the block contains a certificate or certificate request, the returned identity will contain the public key and namespace.
type PrivateKey ¶ added in v1.15.3
type PrivateKey struct {
*ecdsa.PrivateKey
}
PrivateKey is a wrapper around an ECDSA private key. PrivateKey implements the Marshaler and Unmarshaler interfaces for binary, text, JSON, and DynamoDB. Keys are generated using the P-256 elliptic curve. Keys are serialised in PKCS #8, ASN.1 DER form.
func NewPrivateKey ¶ added in v1.15.0
func NewPrivateKey() (*PrivateKey, error)
NewPrivateKey generates a new bifrost private key.
func (PrivateKey) MarshalBinary ¶ added in v1.18.0
func (p PrivateKey) MarshalBinary() ([]byte, error)
MarshalBinary converts a private key to PKCS #8, ASN.1 DER form.
func (PrivateKey) MarshalDynamoDBAttributeValue ¶ added in v1.15.3
func (p PrivateKey) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)
MarshalDynamoDBAttributeValue marshals the private key to PKCS #8, ASN.1 DER form.
func (PrivateKey) MarshalJSON ¶ added in v1.15.3
func (p PrivateKey) MarshalJSON() ([]byte, error)
MarshalJSON marshals the key to a JSON string containing PEM encoded PKCS #8, ASN.1 DER form.
func (PrivateKey) MarshalText ¶ added in v1.18.0
func (p PrivateKey) MarshalText() ([]byte, error)
MarshalText marshals the key to a PEM encoded PKCS #8, ASN.1 DER form.
func (PrivateKey) PublicKey ¶ added in v1.15.3
func (p PrivateKey) PublicKey() *PublicKey
PublicKey returns the public key corresponding to p.
func (PrivateKey) UUID ¶ added in v1.15.3
func (p PrivateKey) UUID(ns uuid.UUID) uuid.UUID
UUID returns the bifrost identifier for p in the given namespace.
func (*PrivateKey) UnmarshalBinary ¶ added in v1.18.0
func (p *PrivateKey) UnmarshalBinary(data []byte) error
UnmarshalBinary parses an unencrypted private key in PKCS #8, ASN.1 DER form. Unmarshal also supports private keys in SEC.1, ASN.1 DER form for backward compatibility.
func (*PrivateKey) UnmarshalDynamoDBAttributeValue ¶ added in v1.15.3
func (p *PrivateKey) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error
UnmarshalDynamoDBAttributeValue unmarshals the private key from PKCS #8, ASN.1 DER form.
func (*PrivateKey) UnmarshalJSON ¶ added in v1.15.3
func (p *PrivateKey) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the private key from PEM encoded PKCS #8, ASN.1 DER form.
func (*PrivateKey) UnmarshalText ¶ added in v1.18.0
func (p *PrivateKey) UnmarshalText(text []byte) error
UnmarshalText unmarshals the private key from PEM encoded PKCS #8, ASN.1 DER form. Unmarshal also supports EC PRIVATE KEY PEM blocks for backward compatibility.
type PublicKey ¶ added in v1.15.0
PublicKey is a wrapper around an ECDSA public key. It implements the Marshaler and Unmarshaler interfaces for binary, text, JSON, and DynamoDB. Keys are serialsed in PKIX, ASN.1 DER form.
func (PublicKey) MarshalBinary ¶ added in v1.18.0
MarshalBinary marshals a public key to PKIX, ASN.1 DER form.
func (PublicKey) MarshalDynamoDBAttributeValue ¶ added in v1.15.0
func (p PublicKey) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)
MarshalDynamoDBAttributeValue marshals the public key to PKIX, ASN.1 DER form.
func (PublicKey) MarshalJSON ¶ added in v1.15.0
MarshalJSON marshals the public key to a JSON string containing PEM encoded PKIX, ASN.1 DER form.
func (PublicKey) MarshalText ¶ added in v1.18.0
MarshalText marshals the public key to a PEM encoded PKIX Public Key in ASN.1 DER form.
func (PublicKey) UUID ¶ added in v1.15.0
UUID returns a unique identifier derived from the namespace and the client's public key.
func (*PublicKey) UnmarshalBinary ¶ added in v1.18.0
UnmarshalBinary unmarshals a public key from PKIX, ASN.1 DER form.
func (*PublicKey) UnmarshalDynamoDBAttributeValue ¶ added in v1.15.0
func (p *PublicKey) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error
UnmarshalDynamoDBAttributeValue unmarshals the public key from PKIX, ASN.1 DER form.
func (*PublicKey) UnmarshalJSON ¶ added in v1.15.0
UnmarshalJSON unmarshals the public key as a JSON string containing PEM encoded PKIX Public Key, ASN.1 DER form.
func (*PublicKey) UnmarshalText ¶ added in v1.18.0
UnmarshalText unmarshals the public key from a PEM encoded PKIX Public Key in ASN.1 DER form.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package asgard provides middleware for use in HTTP API servers that require client certificate (mTLS) authentication.
|
Package asgard provides middleware for use in HTTP API servers that require client certificate (mTLS) authentication. |
cafiles can fetch CA certificate and private key PEM files from many storage backends.
|
cafiles can fetch CA certificate and private key PEM files from many storage backends. |
cmd
|
|
internal
|
|
Package tinyca implements a small and flexible Certificate Authority.
|
Package tinyca implements a small and flexible Certificate Authority. |