x509_cert

package
v0.0.0-...-8982367 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertificateBlockType = "CERTIFICATE"
	RSAPrivKeyBlockType  = "PRIVATE KEY"
)

Variables

View Source
var (
	SubjectAlternativeNameType = asn1.ObjectIdentifier{2, 5, 29, 17}
	PermanentIdentifierType    = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 8, 3}
	OtherNameType              = asn1.ObjectIdentifier{2, 5, 5, 5}
	UraAssigner                = asn1.ObjectIdentifier{2, 16, 528, 1, 1007, 3, 3}
)

SubjectAlternativeNameType represents the ASN.1 Object Identifier for Subject Alternative Name.

View Source
var RegexOtherNameValue = regexp.MustCompile(`^[0-9.]+-\d+-(\d+)-S-(\d+)-00\.000-(\d+)$`)

RegexOtherNameValue matches thee OtherName field: <versie-nr>-<UZI-nr>-<pastype>-<Abonnee-nr>-<rol>-<AGB-code> e.g.: 1-123456789-S-88888801-00.000-12345678 var RegexOtherNameValue = regexp.MustCompile(`2\.16\.528\.1\.1007.\d+\.\d+-\d+-\d+-S-(\d+)-00\.000-\d+`)

Functions

func BuildSelfSignedCertChain

func BuildSelfSignedCertChain(identifier string, permanentIdentifierValue string) (chain []*x509.Certificate, chainPems *cert.Chain, rootCert *x509.Certificate, signingKey *rsa.PrivateKey, signingCert *x509.Certificate, err error)

BuildSelfSignedCertChain generates a certificate chain, including root, intermediate, and signing certificates.

func CertTemplate

func CertTemplate(serialNumber *big.Int, organization string) (*x509.Certificate, error)

CertTemplate generates a template for a x509 certificate with a given serial number. If no serial number is provided, a random one is generated. The certificate is valid for one month and uses SHA256 with RSA for the signature algorithm.

func CreateCert

func CreateCert(template, parent *x509.Certificate, pub interface{}, parentPriv interface{}) (cert *x509.Certificate, certPEM []byte, err error)

CreateCert generates a new x509 certificate using the provided template and parent certificates, public and private keys. It returns the generated certificate, its PEM-encoded version, and any error encountered during the process.

func DebugUnmarshall

func DebugUnmarshall(data []byte, depth int) error

DebugUnmarshall recursively unmarshalls ASN.1 encoded data and prints the structure with parsed values. Keep this method for debug purposes in the future.

func EncodeCertificates

func EncodeCertificates(certs ...*x509.Certificate) ([]byte, error)

func EncodeRSAPrivateKey

func EncodeRSAPrivateKey(key *rsa.PrivateKey) ([]byte, error)

func FindOtherNameValue

func FindOtherNameValue(value []*OtherNameValue, policyType PolicyType, sanTypeName SanTypeName) (string, error)

func FixChainHeaders

func FixChainHeaders(chain *cert.Chain) (*cert.Chain, error)

fixChainHeaders replaces newline characters in the certificate chain headers with escaped newline sequences. It processes each certificate in the provided chain and returns a new chain with the modified headers or an error if any occurs.

func IsRootCa

func IsRootCa(signingCert *x509.Certificate) bool

func ParseCertificates

func ParseCertificates(derChain [][]byte) ([]*x509.Certificate, error)

ParseCertificates parses a slice of DER-encoded byte arrays into a slice of x509.Certificate. It returns an error if any of the certificates cannot be parsed.

func ParsePrivateKey

func ParsePrivateKey(der []byte) (*rsa.PrivateKey, error)

ParsePrivateKey parses a DER-encoded private key into an *rsa.PrivateKey. It returns an error if the key is not in PKCS8 format or not an RSA key.

func ParseUraFromOtherNameValue

func ParseUraFromOtherNameValue(stringValue string) (uzi string, ura string, agb string, err error)

func SigningCertTemplate

func SigningCertTemplate(serialNumber *big.Int, identifier string, permanentIdentifierValue string) (*x509.Certificate, error)

SigningCertTemplate creates a x509.Certificate template for a signing certificate with an optional serial number.

Types

type GenericNameValue

type GenericNameValue struct {
	PolicyType PolicyType
	Type       string
	Value      string
}

type OtherName

type OtherName struct {
	TypeID asn1.ObjectIdentifier
	Value  asn1.RawValue `asn1:"tag:0,explicit"`
}

type OtherNameValue

type OtherNameValue struct {
	PolicyType PolicyType
	Type       SanTypeName
	Value      string
}

func FindSanTypes

func FindSanTypes(certificate *x509.Certificate) ([]*OtherNameValue, error)

func SelectSanTypes

func SelectSanTypes(certificate *x509.Certificate, subjectAttributes ...SanTypeName) ([]*OtherNameValue, error)

type PolicyType

type PolicyType string
const (
	PolicyTypeSan     PolicyType = "san"
	PolicyTypeSubject PolicyType = "subject"
)

type SanType

type SanTypeName

type SanTypeName string
const (
	SanTypeOtherName                   SanTypeName = "otherName"
	SanTypePermanentIdentifierValue    SanTypeName = "permanentIdentifier.value"
	SanTypePermanentIdentifierAssigner SanTypeName = "permanentIdentifier.assigner"
)

type StingAndOid

type StingAndOid struct {
	Value    string
	Assigner asn1.ObjectIdentifier
}

type SubjectTypeName

type SubjectTypeName string
const (
	SubjectTypeCommonName         SubjectTypeName = "CN"
	SubjectTypeOrganization       SubjectTypeName = "O"
	SubjectTypeOrganizationalUnit SubjectTypeName = "OU"
	SubjectTypeCountry            SubjectTypeName = "C"
	SubjectTypeLocality           SubjectTypeName = "L"
	SubjectTypeProvince           SubjectTypeName = "ST"
	SubjectTypeStreetAddress      SubjectTypeName = "STREET"
	SubjectTypeSerialNumber       SubjectTypeName = "serialNumber"
)

type SubjectValue

type SubjectValue struct {
	PolicyType PolicyType
	Type       SubjectTypeName
	Value      string
}

func FindSubjectTypes

func FindSubjectTypes(certificate *x509.Certificate) ([]*SubjectValue, error)

func SelectSubjectTypes

func SelectSubjectTypes(certificate *x509.Certificate, subjectAttributes ...SubjectTypeName) ([]*SubjectValue, error)

Jump to

Keyboard shortcuts

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