parlca

package
v0.4.39 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: ISC Imports: 18 Imported by: 0

Documentation

Overview

Package parlca provides a self-signed certificate authority

Index

Constants

View Source
const (
	/*
		NoPassword       PasswordType = "\tnoPassword"
		GeneratePassword PasswordType = "\tgeneratePassword"
		GenerateOnTheFly Strategy     = iota << 0
		UseFileSystem
		DefaultStrategy = GenerateOnTheFly
	*/
	DefaultCountry = "US" // certificate country: US

)

Variables

This section is empty.

Functions

func EnsureClient

func EnsureClient(cert *x509.Certificate)

func EnsureSelfSigned

func EnsureSelfSigned(cert *x509.Certificate)

func EnsureServer

func EnsureServer(cert *x509.Certificate)

func EnsureTemplate

func EnsureTemplate(cert *x509.Certificate)

func LoadCertificate added in v0.4.28

func LoadCertificate(filename string)

221121 don’t know what this is. Make it compile

func LoadFromPem added in v0.4.27

func LoadFromPem(filename string, allowNotFound ...bool) (
	certificate parl.Certificate, privateKey parl.PrivateKey, publicKey parl.PublicKey,
	err error)

func LoadPrivateKeyFromDer added in v0.4.27

func LoadPrivateKeyFromDer(filename string, algo x509.PublicKeyAlgorithm, allowNotFound ...bool) (privateKey parl.PrivateKey, err error)

func NewCertificate added in v0.4.26

func NewCertificate(certificateDer parl.CertificateDer) (certificate parl.Certificate)

func NewEcdsa added in v0.4.26

func NewEcdsa() (privateKey parl.PrivateKey, err error)

func NewEd25519

func NewEd25519() (privateKey parl.PrivateKey, err error)

func NewPrivateKey added in v0.4.26

func NewPrivateKey(algo x509.PublicKeyAlgorithm) (privateKey parl.PrivateKey, err error)

func NewPrivateKey2 added in v0.4.27

func NewPrivateKey2(algo x509.PublicKeyAlgorithm, privateKeyDer parl.PrivateKeyDer) (privateKey parl.PrivateKey, err error)

func NewRsa added in v0.4.26

func NewRsa() (privateKey parl.PrivateKey, err error)

func NewRsaBits added in v0.4.26

func NewRsaBits(bits int) (privateKey parl.PrivateKey, err error)

func NewSelfSigned

func NewSelfSigned(canonicalName string, algo x509.PublicKeyAlgorithm) (ca parl.CertificateAuthority, err error)

func NewSelfSigned2 added in v0.4.27

func NewSelfSigned2(privateKey parl.PrivateKey, certificate parl.Certificate) (ca parl.CertificateAuthority)

func ParsePEM added in v0.4.27

func ParsePEM(pemData []byte) (certificate parl.Certificate, privateKey parl.PrivateKey, publicKey parl.PublicKey, err error)

func ParsePkcs8 added in v0.4.27

func ParsePkcs8(privateKeyDer parl.PrivateKeyDer) (privateKey parl.PrivateKey, err error)

func ParsePkix added in v0.4.27

func ParsePkix(publicKeyDer parl.PublicKeyDer) (publicKey parl.PublicKey, err error)

func PemText added in v0.4.26

func PemText(data ...[]byte) (pemText string)

func ReadFile added in v0.4.27

func ReadFile(filename string, allowNotFound bool) (byts []byte, err error)

Types

type Certificate

type Certificate struct {
	// contains filtered or unexported fields
}

Certificate wraps a der format x509 certificate. A der-format certificate is produced by x509.CreateCertificate. An x509.Certificate can be obtained by using x509.ParseCertificate.

func (*Certificate) DER

func (ca *Certificate) DER() (certificateDer parl.CertificateDer)
func (c *Certificate) IsValid() (isValid bool) {
	if !c.HasPublic() {
		return
	}
	cert := c.Certificate
	if cert.SerialNumber == nil ||
		cert.Issuer.CommonName == "" ||
		len(cert.Issuer.Country) == 0 ||
		cert.NotBefore.IsZero() ||
		cert.NotAfter.IsZero() ||
		cert.KeyUsage == 0 {
		return
	}
	isValid = true
	return
}
func (c *Certificate) HasPublic() (hasPublic bool) {
	if len(c.PublicKeyBytes()) == 0 ||
		c.Certificate.PublicKeyAlgorithm == x509.UnknownPublicKeyAlgorithm {
		return
	}
	hasPublic = true
	return
}
func (c *Certificate) PublicKeyBytes() (bytes []byte) {
	if c == nil {
		return
	}
	cert := c.Certificate
	if cert == nil {
		return
	}
	//ed25519PublicKey, ok := cert.PublicKey.(*rsa.PublicKey)
	ok := false

	//ed25519PublicKey, ok := cert.PublicKey.(ed25519.PublicKey)
	if !ok {
		panic(perrors.Errorf("Bad PublicKey type: %T", cert.PublicKey))
	}
	//bytes = ed25519PublicKey
	return
}

func (*Certificate) PEM added in v0.4.26

func (ca *Certificate) PEM() (pemBytes parl.PemBytes)

func (*Certificate) ParseCertificate added in v0.4.26

func (ca *Certificate) ParseCertificate() (certificate *x509.Certificate, err error)

type EcdsaPrivateKey added in v0.4.26

type EcdsaPrivateKey struct {
	ecdsa.PrivateKey
}

func (*EcdsaPrivateKey) Algo added in v0.4.26

func (key *EcdsaPrivateKey) Algo() (algo x509.PublicKeyAlgorithm)

func (*EcdsaPrivateKey) DER added in v0.4.26

func (key *EcdsaPrivateKey) DER() (bytes parl.PrivateKeyDer, err error)

func (*EcdsaPrivateKey) DERe added in v0.4.26

func (key *EcdsaPrivateKey) DERe() (privateKeyDer parl.PrivateKeyDer)

func (*EcdsaPrivateKey) PEM added in v0.4.26

func (key *EcdsaPrivateKey) PEM() (pemBytes parl.PemBytes, err error)

func (*EcdsaPrivateKey) PEMe added in v0.4.26

func (key *EcdsaPrivateKey) PEMe() (pemBytes parl.PemBytes)

func (*EcdsaPrivateKey) PublicKey added in v0.4.26

func (key *EcdsaPrivateKey) PublicKey() (publicKey parl.PublicKey)

func (*EcdsaPrivateKey) Validate added in v0.4.26

func (key *EcdsaPrivateKey) Validate() (err error)

type EcdsaPublicKey added in v0.4.26

type EcdsaPublicKey struct {
	ecdsa.PublicKey
}

func (*EcdsaPublicKey) Algo added in v0.4.26

func (key *EcdsaPublicKey) Algo() (algo x509.PublicKeyAlgorithm)

func (*EcdsaPublicKey) DER added in v0.4.26

func (key *EcdsaPublicKey) DER() (publicKeyDer parl.PublicKeyDer, err error)

func (*EcdsaPublicKey) DERe added in v0.4.26

func (key *EcdsaPublicKey) DERe() (publicKeyDer parl.PublicKeyDer)

func (*EcdsaPublicKey) PEM added in v0.4.26

func (key *EcdsaPublicKey) PEM() (pemBytes parl.PemBytes, err error)

func (*EcdsaPublicKey) PEMe added in v0.4.26

func (key *EcdsaPublicKey) PEMe() (pemBytes parl.PemBytes)

type Ed25519PrivateKey added in v0.4.26

type Ed25519PrivateKey struct {
	// func (ed25519.PrivateKey).Equal(x crypto.PrivateKey) bool
	// func (ed25519.PrivateKey).Public() crypto.PublicKey
	// func (ed25519.PrivateKey).Seed() []byte
	// func (ed25519.PrivateKey).Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error)
	// implements crypto.Signer: Public, Sign
	ed25519.PrivateKey // type: []byte
}

Ed25519 implements parl.KeyPair for the x509.Ed25519 algorithm.

func (*Ed25519PrivateKey) Algo added in v0.4.26

func (key *Ed25519PrivateKey) Algo() (algo x509.PublicKeyAlgorithm)

func (*Ed25519PrivateKey) DER added in v0.4.26

func (key *Ed25519PrivateKey) DER() (privateKeyDer parl.PrivateKeyDer, err error)

func (*Ed25519PrivateKey) DERe added in v0.4.26

func (key *Ed25519PrivateKey) DERe() (privateKeyDer parl.PrivateKeyDer)

func (*Ed25519PrivateKey) PEM added in v0.4.26

func (key *Ed25519PrivateKey) PEM() (pemBytes parl.PemBytes, err error)

func (*Ed25519PrivateKey) PEMe added in v0.4.26

func (key *Ed25519PrivateKey) PEMe() (pemBytes parl.PemBytes)

func (*Ed25519PrivateKey) PublicKey added in v0.4.26

func (key *Ed25519PrivateKey) PublicKey() (publicKey parl.PublicKey)

func (*Ed25519PrivateKey) Validate added in v0.4.26

func (key *Ed25519PrivateKey) Validate() (err error)

type Ed25519PublicKey added in v0.4.26

type Ed25519PublicKey struct {
	ed25519.PublicKey // Equal()
}

func (*Ed25519PublicKey) Algo added in v0.4.26

func (key *Ed25519PublicKey) Algo() (algo x509.PublicKeyAlgorithm)

func (*Ed25519PublicKey) DER added in v0.4.26

func (key *Ed25519PublicKey) DER() (publicKeyDer parl.PublicKeyDer, err error)

func (*Ed25519PublicKey) DERe added in v0.4.26

func (key *Ed25519PublicKey) DERe() (publicKeyDer parl.PublicKeyDer)

func (*Ed25519PublicKey) PEM added in v0.4.26

func (key *Ed25519PublicKey) PEM() (pemBytes parl.PemBytes, err error)

func (*Ed25519PublicKey) PEMe added in v0.4.26

func (key *Ed25519PublicKey) PEMe() (pemBytes parl.PemBytes)

type RsaPrivateKey added in v0.4.26

type RsaPrivateKey struct {
	// Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
	// Equal(x crypto.PrivateKey) bool
	// Precompute()
	// Public() crypto.PublicKey
	// Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
	// Size() int
	// Validate() error
	rsa.PrivateKey
}

func (*RsaPrivateKey) Algo added in v0.4.26

func (key *RsaPrivateKey) Algo() (algo x509.PublicKeyAlgorithm)

func (*RsaPrivateKey) DER added in v0.4.26

func (key *RsaPrivateKey) DER() (bytes parl.PrivateKeyDer, err error)

func (*RsaPrivateKey) DERe added in v0.4.26

func (key *RsaPrivateKey) DERe() (privateKeyDer parl.PrivateKeyDer)

func (*RsaPrivateKey) PEM added in v0.4.26

func (key *RsaPrivateKey) PEM() (pemBytes parl.PemBytes, err error)

func (*RsaPrivateKey) PEMe added in v0.4.26

func (key *RsaPrivateKey) PEMe() (pemBytes parl.PemBytes)

func (*RsaPrivateKey) PublicKey added in v0.4.26

func (key *RsaPrivateKey) PublicKey() (publicKey parl.PublicKey)

func (*RsaPrivateKey) Validate added in v0.4.26

func (key *RsaPrivateKey) Validate() (err error)

type RsaPublicKey added in v0.4.26

type RsaPublicKey struct {
	rsa.PublicKey
}

func (*RsaPublicKey) Algo added in v0.4.26

func (key *RsaPublicKey) Algo() (algo x509.PublicKeyAlgorithm)

func (*RsaPublicKey) DER added in v0.4.26

func (key *RsaPublicKey) DER() (publicKeyDer parl.PublicKeyDer, err error)

func (*RsaPublicKey) DERe added in v0.4.26

func (key *RsaPublicKey) DERe() (publicKeyDer parl.PublicKeyDer)

func (*RsaPublicKey) PEM added in v0.4.26

func (key *RsaPublicKey) PEM() (pemBytes parl.PemBytes, err error)

func (*RsaPublicKey) PEMe added in v0.4.26

func (key *RsaPublicKey) PEMe() (pemBytes parl.PemBytes)

type SelfSigned

type SelfSigned struct {
	parl.Certificate // DER() PEM()
	PrivateKey       parl.PrivateKey
}

func (*SelfSigned) Check

func (ca *SelfSigned) Check() (cert *x509.Certificate, err error)

func (*SelfSigned) Private added in v0.4.27

func (ca *SelfSigned) Private() (privateKey parl.PrivateKey)

func (*SelfSigned) Sign

func (ca *SelfSigned) Sign(template *x509.Certificate, publicKey crypto.PublicKey) (certDER parl.CertificateDer, err error)

Jump to

Keyboard shortcuts

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