xmldsig

package module
v0.0.0-...-9d5d737 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

README

go-xmldsig

XML Digital Signature

Installation

Install go-xmldsig using go get:

$ go get -u github.com/deb-ict/go-xmldsig

Reference

This code is based on repository russellhaering/goxmldsig and C# SignedXml.
If u star this repository, please star the original code repository as well!

Purpose

This code is a requirement for the go-peppol project where including mime attachment digest in the signature is required.

Generate a test certificate

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365

Documentation

Index

Constants

View Source
const (
	C14N10ExcNamespaceUri             string = "http://www.w3.org/2001/10/xml-exc-c14n#"
	C14N10ExcWithCommentsNamespaceUri string = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
)
View Source
const (
	C14N10RecNamespaceUri             string = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
	C14N10RecWithCommentsNamespaceUri string = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
)
View Source
const (
	C14N11NamespaceUri             string = "http://www.w3.org/2006/12/xml-c14n11"
	C14N11WithCommentsNamespaceUri string = "http://www.w3.org/2006/12/xml-c14n11#WithComments"
)
View Source
const (
	EnvelopedSignatureTransform string = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
)
View Source
const (
	XmlDSigNamespaceUri string = "http://www.w3.org/2000/09/xmldsig#"
)

Variables

View Source
var (
	ErrInvalidSignatureMethod = errors.New("invalid signature method")
	ErrInvalidDigestMethod    = errors.New("invalid digest method")
)

Functions

func CryptographicEquals

func CryptographicEquals(a, b []byte) bool

func GetReferenceResolverPrefixes

func GetReferenceResolverPrefixes() []string

func RegisterCanonicalizer

func RegisterCanonicalizer(uri string, method CreateCanonicalizerMethod)

func RegisterReferenceElementResolver

func RegisterReferenceElementResolver(prefix string, method ResolveReferenceMethod)

func RegisterTransform

func RegisterTransform(uri string, method CreateTransformMethod)

Types

type Canonicalizer

type Canonicalizer interface {
	GetAlgorithm() string
	Canonicalize(ctx context.Context, el *etree.Element) ([]byte, error)
	LoadXml(el *etree.Element) error
}

func GetCanonicalizer

func GetCanonicalizer(uri string, el *etree.Element) (Canonicalizer, error)

func NewC14N10ExcCanonicalizer

func NewC14N10ExcCanonicalizer() Canonicalizer

func NewC14N10ExcWithCommentsCanonicalizer

func NewC14N10ExcWithCommentsCanonicalizer() Canonicalizer

func NewC14N10RecCanonicalizer

func NewC14N10RecCanonicalizer() Canonicalizer

func NewC14N10RecWithCommentsCanonicalizer

func NewC14N10RecWithCommentsCanonicalizer() Canonicalizer

func NewC14N11Canonicalizer

func NewC14N11Canonicalizer() Canonicalizer

func NewC14N11WithCommentsCanonicalizer

func NewC14N11WithCommentsCanonicalizer() Canonicalizer

type CreateCanonicalizerMethod

type CreateCanonicalizerMethod func() Canonicalizer

type CreateTransformMethod

type CreateTransformMethod func(reference *Reference) Transform

type DigestMethod

type DigestMethod int
const (
	DigestMethod_SHA1 DigestMethod = iota
	DigestMethod_SHA256
	DigestMethod_SHA384
	DigestMethod_SHA512
)

func GetDigestMethod

func GetDigestMethod(uri string) (DigestMethod, error)

func (DigestMethod) CreateHashAlgorithm

func (d DigestMethod) CreateHashAlgorithm() (hash.Hash, error)

func (DigestMethod) GetHashAlgorithm

func (d DigestMethod) GetHashAlgorithm() (crypto.Hash, error)

func (DigestMethod) GetUri

func (d DigestMethod) GetUri() string

type Reference

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

func (*Reference) GetUri

func (ref *Reference) GetUri() string

func (*Reference) GetUriWithoutPrefix

func (ref *Reference) GetUriWithoutPrefix(prefix string) string

type ResolveReferenceMethod

type ResolveReferenceMethod func(ctx context.Context, reference *Reference) (io.Reader, error)

func GetReferenceElementResolver

func GetReferenceElementResolver(prefix string) (ResolveReferenceMethod, bool)

type Signature

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

type SignatureMethod

type SignatureMethod int
const (
	SignatureMethod_RSA_SHA1 SignatureMethod = iota
	SignatureMethod_RSA_SHA256
	SignatureMethod_RSA_SHA384
	SignatureMethod_RSA_SHA512
)

func GetSignatureMethod

func GetSignatureMethod(uri string) (SignatureMethod, error)

func (SignatureMethod) CreateHashAlgorithm

func (s SignatureMethod) CreateHashAlgorithm() (hash.Hash, error)

func (SignatureMethod) GetHashAlgorithm

func (s SignatureMethod) GetHashAlgorithm() (crypto.Hash, error)

func (SignatureMethod) GetSignatureAlgorithm

func (s SignatureMethod) GetSignatureAlgorithm() (x509.SignatureAlgorithm, error)

func (SignatureMethod) GetUri

func (s SignatureMethod) GetUri() string

type SignedInfo

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

type SignedXml

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

func LoadSignedXml

func LoadSignedXml(doc *etree.Document) (*SignedXml, error)

func (*SignedXml) GetCertificate

func (xml *SignedXml) GetCertificate() (*x509.Certificate, error)

func (*SignedXml) ValidateSignature

func (xml *SignedXml) ValidateSignature(ctx context.Context, cert *x509.Certificate) error

type Transform

type Transform interface {
	GetAlgorithm() string
	GetReference() *Reference
	TransformXmlElement(ctx context.Context, el *etree.Element) ([]byte, error)
	TransformData(ctx context.Context, data []byte) ([]byte, error)
	LoadXml(el *etree.Element) error
}

func GetTransform

func GetTransform(uri string, ref *Reference) (Transform, error)

func NewC14N10ExcTransform

func NewC14N10ExcTransform(reference *Reference) Transform

func NewC14N10ExcWithCommentsTransform

func NewC14N10ExcWithCommentsTransform(reference *Reference) Transform

func NewC14N10RecTransform

func NewC14N10RecTransform(reference *Reference) Transform

func NewC14N10RecWithCommentsTransform

func NewC14N10RecWithCommentsTransform(reference *Reference) Transform

func NewC14N11Transform

func NewC14N11Transform(reference *Reference) Transform

func NewC14N11WithCommentsTransform

func NewC14N11WithCommentsTransform(reference *Reference) Transform

func NewEnvelopedSignatureTransform

func NewEnvelopedSignatureTransform(reference *Reference) Transform

Jump to

Keyboard shortcuts

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