Documentation ¶
Overview ¶
Bifrost is an mTLS authentication toolkit.
Index ¶
- Constants
- Variables
- func HTTPClient(clientCert tls.Certificate, roots *x509.CertPool, ssllog io.Writer) *http.Client
- func NewIdentity() (*ecdsa.PrivateKey, []byte, error)
- func UUID(ns uuid.UUID, pubkey *ecdsa.PublicKey) uuid.UUID
- func X509ToTLSCertificate(cert *x509.Certificate, key *ecdsa.PrivateKey) *tls.Certificate
- type Certificate
- type CertificateRequest
Examples ¶
Constants ¶
const ( SignatureAlgorithm = x509.ECDSAWithSHA256 PublicKeyAlgorithm = x509.ECDSA )
Signature and Public Key Algorithms
Variables ¶
var ( ErrCertificateInvalid = errors.New("certificate invalid") ErrCertificateRequestInvalid = errors.New("certificate request invalid") ErrIncorrectMismatch = errors.New("namespace mismatch") )
Errors.
Functions ¶
func HTTPClient ¶ added in v0.0.6
HTTPClient returns a http.Client set up for TLS Client Authentication (mTLS). 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 NewIdentity ¶ added in v0.0.8
func NewIdentity() (*ecdsa.PrivateKey, []byte, error)
NewIdentity generates a new ECDSA private key. The private key is also returned as a PEM encoded DER bytes in the second return value.
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
type Certificate struct { *x509.Certificate Id uuid.UUID Namespace uuid.UUID PublicKey *ecdsa.PublicKey }
Certificate is a bifrost certificate. It embeds the x509 certificate and adds the bifrost ID, namespace, and public key.
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, url string, ns uuid.UUID, key *ecdsa.PrivateKey, ) (*Certificate, error)
RequestCertificate sends a certificate request to url and returns the signed certificate.
Example ¶
exampleNS := uuid.MustParse("228b9676-998e-489a-8468-92d46a94a32d") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() // TODO: handle errors key, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) cert, _ := RequestCertificate(ctx, "https://bifrost-ca", exampleNS, key) fmt.Println(cert.Subject)
Output:
func (Certificate) ToTLSCertificate ¶ added in v1.11.0
func (c Certificate) ToTLSCertificate(key *ecdsa.PrivateKey) (*tls.Certificate, error)
ToTLSCertificate puts a bifrost certificate inside a tls.Certificate.
func (*Certificate) Verify ¶ added in v1.11.0
func (c *Certificate) Verify() error
Verify validates a bifrost certificate. It checks for the correct signature algorithm, identity namespace, and identity. On success, it sets the ID, Namespace, and PublicKey fields.
type CertificateRequest ¶ added in v1.11.0
type CertificateRequest struct { *x509.CertificateRequest Id uuid.UUID Namespace uuid.UUID PublicKey *ecdsa.PublicKey }
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.
func (*CertificateRequest) Verify ¶ added in v1.11.0
func (c *CertificateRequest) Verify() error
Verify validates a bifrost certificate request.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
cafiles
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. |
pkg
|
|
asgard
Package asgard provides middleware for use in HTTP API servers.
|
Package asgard provides middleware for use in HTTP API servers. |
tinyca
Package tinyca implements a Certificate Authority that issues certificates for client authentication.
|
Package tinyca implements a Certificate Authority that issues certificates for client authentication. |
Package web embeds static website files that webservers can serve up to clients.
|
Package web embeds static website files that webservers can serve up to clients. |