didx509

package
v6.2.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MethodName represents the x509 DID method identifier.
	MethodName = "x509"

	// X509CertChainHeader represents the header key for the x509 certificate chain in a JWT.
	X509CertChainHeader = "x5c"
)
View Source
const (

	// HashSha1 represents the SHA-1 hashing algorithm to be used for generating hash values.
	HashSha1 = HashAlgorithm("sha1")

	// HashSha256 represents the SHA-256 hash algorithm constant, used for cryptographic hashing operations.
	HashSha256 = HashAlgorithm("sha256")

	// HashSha384 represents the SHA-384 hash algorithm.
	HashSha384 = HashAlgorithm("sha384")

	// HashSha512 defines the SHA-512 hash algorithm.
	HashSha512 = HashAlgorithm("sha512")
)

Variables

View Source
var (

	// SubjectPolicySerialNumber represents the serial number attribute in the subject field of an X.509 certificate.
	SubjectPolicySerialNumber = PolicyKey{
								// contains filtered or unexported fields
	}

	// SubjectPolicyCommonName represents a policy key for the Common Name (CN) attribute in the subject of an X.509 certificate.
	SubjectPolicyCommonName = PolicyKey{
							// contains filtered or unexported fields
	}

	// SubjectPolicyLocality represents the policy key for the subject's locality attribute in an X.509 certificate.
	SubjectPolicyLocality = PolicyKey{
							// contains filtered or unexported fields
	}

	// SubjectPolicyCountry defines the policy key for the country attribute of the subject in an X.509 certificate.
	SubjectPolicyCountry = PolicyKey{
							// contains filtered or unexported fields
	}

	// SubjectPolicyOrganization represents the policy key for the 'Organization' attribute in the subject of an X.509 certificate.
	SubjectPolicyOrganization = PolicyKey{
								// contains filtered or unexported fields
	}

	// SubjectPolicyOrganizationalUnit represents the policy key for the organizational unit (OU) attribute of the subject
	SubjectPolicyOrganizationalUnit = PolicyKey{
									// contains filtered or unexported fields
	}

	// SubjectPolicyState represents the state or province attribute in the subject of an X.509 certificate.
	SubjectPolicyState = PolicyKey{
						// contains filtered or unexported fields
	}

	// SubjectPolicyStreet is a PolicyKey for the 'streetAddress' attribute in the subject of an X.509 certificate.
	SubjectPolicyStreet = PolicyKey{
						// contains filtered or unexported fields
	}
)
View Source
var (

	// SanPolicyOtherName represents a policy key for the "otherName" attribute within the Subject Alternative Name (SAN) policy.
	SanPolicyOtherName = PolicyKey{
						// contains filtered or unexported fields
	}

	// SanPolicyDNS represents a policy key for the 'dns' attribute in the Subject Alternative Name (SAN) extension of an X.509 certificate.
	SanPolicyDNS = PolicyKey{
					// contains filtered or unexported fields
	}

	// SanPolicyEmail is a PolicyKey for validating the email attribute within the Subject Alternative Name (SAN) of a certificate.
	SanPolicyEmail = PolicyKey{
					// contains filtered or unexported fields
	}

	// SanPolicyIPAddress represents a policy key for IP address in Subject Alternative Name (SAN) validation.
	SanPolicyIPAddress = PolicyKey{
						// contains filtered or unexported fields
	}
)
View Source
var (

	// ErrDidMalformed indicates that the DID (Decentralized Identifier) is malformed and does not adhere to the expected format.
	ErrDidMalformed = errors.New("did:x509 is malformed")

	// ErrDidVersion indicates that the DID:x509 does not have version 0.
	ErrDidVersion = errors.New("did:x509 does not have version 0")

	// ErrDidPolicyMalformed indicates that the did:x509 policy is malformed.
	ErrDidPolicyMalformed = errors.New("did:x509 policy is malformed")

	// ErrUnkPolicyType indicates that the encountered policy type is unknown or unsupported.
	ErrUnkPolicyType = errors.New("unknown policy type")
)
View Source
var (

	// ErrUnsupportedHashAlgorithm indicates that the provided hash algorithm is not supported by the system.
	ErrUnsupportedHashAlgorithm = fmt.Errorf("unsupported hash algorithm")

	// ErrInvalidHash indicates that the provided hash is invalid or improperly formatted.
	ErrInvalidHash = fmt.Errorf("invalid hash")

	// ErrCertificateNotfound indicates that a certificate could not be found with the given hash.
	ErrCertificateNotfound = fmt.Errorf("cannot find a certificate with the given hash")

	// ErrTrailingData indicates that there is trailing data after an X.509 extension, which should not be present.
	ErrTrailingData = errors.New("x509: trailing data after X.509 extension")

	// ErrSanSequenceData indicates an unexpected sequence in the Subject Alternative Name (SAN) extension.
	ErrSanSequenceData = errors.New("unexpected SAN sequence")
)
View Source
var (
	// SubjectAlternativeNameType defines the OID for Subject Alternative Name
	SubjectAlternativeNameType = asn1.ObjectIdentifier{2, 5, 29, 17}
	// OtherNameType defines the OID for Other Name
	OtherNameType = asn1.ObjectIdentifier{2, 5, 5, 5}
)
View Source
var (

	// ErrX509ChainMissing indicates that no x5c header was found in the provided metadata.
	ErrX509ChainMissing = errors.New("no x5c header found")
)

Functions

This section is empty.

Types

type HashAlgorithm

type HashAlgorithm string

type OtherName

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

OtherName represents a structure for other name in ASN.1

type PolicyKey

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

PolicyKey represents a key-value pair where 'name' specifies the policy name and 'key' identifies the specific attribute.

type PolicyName

type PolicyName string

PolicyName represents the name of a policy in an X.509 DID (Decentralized Identifier).

const (

	// PolicyNameSubject specifies that the policy is related to the subject attributes of an X.509 certificate.
	PolicyNameSubject PolicyName = "subject"

	// PolicyNameSan represents a policy for Subject Alternative Name (SAN) in an X.509 DID.
	PolicyNameSan PolicyName = "san"
)

type Resolver

type Resolver struct {
}

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new Resolver.

func (Resolver) Resolve

Resolve resolves a DID document given its identifier and corresponding metadata. The resolve method resolves using the did:x509 v1.0 Draft method specification found at: https://trustoverip.github.io/tswg-did-x509-method-specification/ Given this specification, this implementation diverges from the spec at the following: * Besides the "san" policies "email" / "dns" / "uri", the san policy "otherName" is also implemented. * The policy "subject" also supports "serialNumber", besides the "CN" / "L" / "ST" / "O" / "OU" / "C" / "STREET" fields. * The policy "eku" is not implemented. Resolve does NOT check the CRLs on the certificate chain.

type SanType

SanType is an alias for pkix.AttributeTypeAndValue

type SanTypeName

type SanTypeName string

SanTypeName represents the type name for SAN

type X509DidPolicy

type X509DidPolicy struct {
	Name  PolicyName
	Value string
}

X509DidPolicy represents an X.509 DID policy that includes a policy name and corresponding value.

type X509DidReference

type X509DidReference struct {
	// Method specifies the hash algorithm that was used to generate CAFingerprint from the raw DER bytes of the CA certificate.
	Method HashAlgorithm
	// CAFingerprint is the fingerprint of the CA certificate.
	CAFingerprint string
	// Policies contain the fields that are included in the did:x509, which must be validated against the certificates.
	Policies []X509DidPolicy
}

X509DidReference represents a reference for an X.509 Decentralized Identifier (DID).

func ParseX509Did

func ParseX509Did(id did.DID) (*X509DidReference, error)

ParseX509Did parses a DID (Decentralized Identifier) in the x509 format and returns a corresponding X509DidReference.

Jump to

Keyboard shortcuts

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