Documentation ¶
Index ¶
- Constants
- Variables
- func CertificateIsSelfSigned(cert *x509.Certificate) bool
- func DescribeCertificate(cert *x509.Certificate) string
- func EscapeName(name string) string
- func ExtKeyUsageAllNames() []string
- func ExtKeyUsageFromNames(names string) ([]x509.ExtKeyUsage, error)
- func ExtKeyUsageNames(usages []x509.ExtKeyUsage) []string
- func KeyUsageAllNames() []string
- func KeyUsageFromNames(names string) (x509.KeyUsage, error)
- func KeyUsageNames(u x509.KeyUsage) []string
- func KeysMatch(a, b any) bool
- func NameAsString(name *pkix.Name) string
- func PkixNameSplitter(data []byte, atEOF bool) (advance int, token []byte, err error)
- func PublicKeyFingerprint(key any) []byte
- func PublicKeyFor(obj any) crypto.PublicKey
- func SignatureAlgorithmForKey(key any, hash crypto.Hash) x509.SignatureAlgorithm
- func SignatureAlgorithmName(sa x509.SignatureAlgorithm) string
- func StringAsName(str string) (*pkix.Name, error)
- func SubjectKeyId(key any) []byte
- func UnescapeName(name string) string
- func UnmarshalPrivateKey(data []byte) (crypto.PrivateKey, error)
- func UnmarshalPublicKey(data []byte) (crypto.PublicKey, error)
- type ExpectingBlockError
- type PemBuffer
- type PemParser
- type PemUnmarshaler
- func (u *PemUnmarshaler) Expect(pemTypes []string) (*pem.Block, error)
- func (u *PemUnmarshaler) ExpectCSR() (*x509.CertificateRequest, error)
- func (u *PemUnmarshaler) ExpectCertificate() (*x509.Certificate, error)
- func (u *PemUnmarshaler) ExpectPrivateKey() (crypto.PrivateKey, error)
- func (u *PemUnmarshaler) ExpectPublicKeyExtractable() (crypto.PublicKey, error)
- func (u *PemUnmarshaler) NextPem() (*pem.Block, error)
- type PemUnmarshalerOption
Constants ¶
const ( PemTypePrivateKey = "PRIVATE KEY" PemTypeECPrivateKey = "EC PRIVATE KEY" PemTypeRsaPrivateKey = "RSA PRIVATE KEY" PemTypePublicKey = "PUBLIC KEY" PemTypeECPublicKey = "EC PUBLIC KEY" PemTypeRsaPublicKey = "RSA PUBLIC KEY" PemTypeCsr = "CERTIFICATE REQUEST" PemTypeCertificate = "CERTIFICATE" )
const (
DefaultSignatureHash = crypto.SHA512
)
const NoneName = "None"
Variables ¶
var ( PemTypesPrivateKeys = []string{ PemTypePrivateKey, PemTypeECPrivateKey, PemTypeRsaPrivateKey, } PemTypesPublicKeys = []string{ PemTypePublicKey, PemTypeECPublicKey, PemTypeRsaPublicKey, } PemTypesPublicKeyExtractable = append( append( PemTypesPublicKeys, PemTypesPrivateKeys..., ), PemTypeCertificate, PemTypeCsr, ) )
var ErrNoPemFound = errors.New("no PEM block found")
Functions ¶
func CertificateIsSelfSigned ¶
func CertificateIsSelfSigned(cert *x509.Certificate) bool
func DescribeCertificate ¶
func DescribeCertificate(cert *x509.Certificate) string
DescribeCertificate produces a one line description for a human to read. It contains the certificate's subject and SANs.
func EscapeName ¶
func ExtKeyUsageAllNames ¶
func ExtKeyUsageAllNames() []string
func ExtKeyUsageFromNames ¶
func ExtKeyUsageFromNames(names string) ([]x509.ExtKeyUsage, error)
func ExtKeyUsageNames ¶
func ExtKeyUsageNames(usages []x509.ExtKeyUsage) []string
func KeyUsageAllNames ¶
func KeyUsageAllNames() []string
func KeyUsageNames ¶
func NameAsString ¶
NameAsString renders a pkix.Name as a string in the form /OID=Value/…. The first character will be a "/" and OID-value pairs will be separated with a "/". The characters / = \ which are part of the OID or value will be escaped by placing a \ before them. Whereas this function will generate a string representation of the name for all names, the string value of attributes that are not strings may not contain enough information to reverse the process.
func PkixNameSplitter ¶
PkixNameSplitter is a bufio.SplitFunc for use with bufio.Scanner which tokens in the form "/OID" or "=value". Escaped characters will not cause a split. No unesscaping is performed, the user of the Scanner is expected to inspect the first character of the token, remove it, then unescape the rest with UnescapeName().
func PublicKeyFingerprint ¶
PublicKeyFingerprint returns a SHA256 hash of a repeatable encoding of the given key. If a private key is passed, only the public part is considered. On error a zero length byte slice is returned.
func PublicKeyFor ¶
func SignatureAlgorithmForKey ¶
func SignatureAlgorithmForKey(key any, hash crypto.Hash) x509.SignatureAlgorithm
SignatureAlgorithmForKey returns a signature algorithm that will work for the given key. key can be a public or private key of type RSA (crypto/rsa), EC (crypto/ecdsa), or Ed25519 (crypto/ed25519). For RSA and EC keys the appropriate {RSA|ECDSA}WithSHA{1,256,384,512} value will be returned for the corresponding hash value. For Ed25519 keys x509.PureEd25519 will always be returned regardless of the value of hash.
If an unusable hash or key of unknown type is passed in then x509.UnknownSignatureAlgorithm will be returned.
func SignatureAlgorithmName ¶
func SignatureAlgorithmName(sa x509.SignatureAlgorithm) string
SignatureAlgorithmName returns a textual name for a signature algorithm type
func SubjectKeyId ¶
SubjectKeyId is used to generate a SHA1 fingerprint of a public key and is compatible with the algorithm defined in RFC5280. This is the value of the Subject Key ID extension in certificates issued. Unless compatibility with RFC5280 is required, use PublicKeyFingerprint() instead as this uses SHA512_256 which is both faster and more secure.
func UnescapeName ¶
func UnmarshalPrivateKey ¶
func UnmarshalPrivateKey(data []byte) (crypto.PrivateKey, error)
Types ¶
type ExpectingBlockError ¶
type ExpectingBlockError struct {
// contains filtered or unexported fields
}
func (ExpectingBlockError) Error ¶
func (e ExpectingBlockError) Error() string
func (ExpectingBlockError) Is ¶
func (e ExpectingBlockError) Is(err error) bool
type PemBuffer ¶
type PemBuffer struct {
// contains filtered or unexported fields
}
PemBuffer is a sequence of PEM blocks stored in a buffer. It implements PemParser.
func NewPemBuffer ¶
NewPemBuffer stores be in a PemBuffer allowing it to be parsed. Modifying b after this call may affect the parser's results
func NewPemBufferFromStream ¶
NewPemBufferFromStream stores stream and reads it to completion the first call to NextPem(). If the stream implements io.Closer it will be closed.
func (*PemBuffer) RemainingBytes ¶
type PemParser ¶
type PemParser interface { // NextPem returns a PEM block or and error while attempting to retrieve // a PEM block. When no more blocks are available nil should be returned // for both the block and the error. NextPem() (*pem.Block, error) }
PemParser is an object that can source a series of PEM blocks
type PemUnmarshaler ¶
type PemUnmarshaler struct {
// contains filtered or unexported fields
}
func NewPemUnmarshaler ¶
func NewPemUnmarshaler(parser PemParser, options ...PemUnmarshalerOption) *PemUnmarshaler
func UnmarshalFile ¶
func UnmarshalFile(filePath, stdInPrompt string, cryptOptions *pemcrypt.CryptOptions) *PemUnmarshaler
UnmarshalFile is a utility function to use a delayed open file reader and a PemBuffer to read and optionally decrypt some PEM blocks. Errors are delayed until a call the unmarshaler.
func (*PemUnmarshaler) Expect ¶
func (u *PemUnmarshaler) Expect(pemTypes []string) (*pem.Block, error)
Expect returns a PEM block of the expected type or an error. If the block is encrypted and decryption is enabled then an encrypted block of the correct type(s) will be decrypted before being returned. If pemTypes has a length greater than zero then only these types of PEM blocks will be accepted, if an unacceptable block is found an error will be returned.
func (*PemUnmarshaler) ExpectCSR ¶
func (u *PemUnmarshaler) ExpectCSR() (*x509.CertificateRequest, error)
ExpectCSR parses and returns a CSR
func (*PemUnmarshaler) ExpectCertificate ¶
func (u *PemUnmarshaler) ExpectCertificate() (*x509.Certificate, error)
ExpectCertificate parses and returns a certificate
func (*PemUnmarshaler) ExpectPrivateKey ¶
func (u *PemUnmarshaler) ExpectPrivateKey() (crypto.PrivateKey, error)
ExpectPrivateKey parses and returns a private key
func (*PemUnmarshaler) ExpectPublicKeyExtractable ¶
func (u *PemUnmarshaler) ExpectPublicKeyExtractable() (crypto.PublicKey, error)
ExpectPublicKeyExtractable parses any type of block that is an object that contains a public key, then returns the public key from that object.
type PemUnmarshalerOption ¶
type PemUnmarshalerOption func(unmarshaler *PemUnmarshaler)
func WithDecryption ¶
func WithDecryption(decryptionOptions *pemcrypt.CryptOptions) PemUnmarshalerOption
func WithNoDecryption ¶
func WithNoDecryption() PemUnmarshalerOption
func WithUserContext ¶
func WithUserContext(userContext string) PemUnmarshalerOption