cert_utils

package module
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

README

cert-utils

Shared utility functions for manipulating certs and keys

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EncryptionTargetKeyExtensionOID = []int{1, 3, 9942, 1, 1}

Functions

func AddEncryptionTargetKey added in v1.1.0

func AddEncryptionTargetKey(template *x509.Certificate, key *ecdsa.PublicKey) error

AddEncryptionTargetKey adds a Scott Pass EncryptionTargetKey extension to a certificate template.

func CertHash

func CertHash(cert *x509.Certificate) string

CertHash returns the SHA256 hash of a certificate's DER encoding

func CertToPem

func CertToPem(cert *x509.Certificate) string

CertToPem converts a certificate to a PEM encoded string

func CreateCACert added in v1.5.0

func CreateCACert(accountID string, pub *ecdsa.PublicKey, priv crypto.Signer, now time.Time) (*x509.Certificate, error)

CreateCACert creates a CA certificate

func CreateCACertTemplate added in v1.7.0

func CreateCACertTemplate(accountID string, now time.Time) (*x509.Certificate, error)

CreateCACertTemplate creates a template for a CA certificate

func CreateDeviceCert added in v1.5.0

func CreateDeviceCert(
	caCert *x509.Certificate,
	caSigner crypto.Signer,
	accountID string,
	deviceName string,
	baseUrl *url.URL,
	pub *ecdsa.PublicKey,
	pubEncryption *ecdsa.PublicKey,
	now time.Time,
) (*x509.Certificate, error)

CreateDeviceCert creates a device certificate

func CreateDeviceCertTemplate added in v1.7.0

func CreateDeviceCertTemplate(
	caCert *x509.Certificate,
	accountID string,
	deviceName string,
	baseUrl *url.URL,
	pubEncryption *ecdsa.PublicKey,
	now time.Time,
) (*x509.Certificate, error)

CreateDeviceCertTemplate creates a template for a device certificate

func GenerateSerial added in v1.5.0

func GenerateSerial() (*big.Int, error)

GenerateSerial generates a random serial number for a certificate, using 126s bit of entropy.

func GetEncryptionTargetKey added in v1.1.0

func GetEncryptionTargetKey(cert *x509.Certificate) (*ecdsa.PublicKey, error)

GetEncryptionTargetKey returns the key encoded in the Scott Pass EncryptionTargetKey extension attached to a cert or an error if no such extension is present.

func PemFromPubKey

func PemFromPubKey(pub *ecdsa.PublicKey) (string, error)

PemFromPubKey converts an ECDSA public key to a PEM encoded string

func PemToCert

func PemToCert(s string) (*x509.Certificate, error)

PemToCert converts a PEM encoded string to a certificate

func PubKeyFromPEM

func PubKeyFromPEM(s string) (*ecdsa.PublicKey, error)

PubKeyFromPEM converts a PEM encoded public key to an ECDSA public key

func PubKeyHash

func PubKeyHash(key *ecdsa.PublicKey) (string, error)

PubKeyHash returns the SHA256 hash of a public key's DER encoding

func UniqueHashes added in v1.3.0

func UniqueHashes(hashes ...string) bool

func VerifyDeviceSignature added in v1.12.0

func VerifyDeviceSignature(ca *x509.Certificate, cert *x509.Certificate, now time.Time) error

Types

This section is empty.

Directories

Path Synopsis
crypto

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL