Documentation ¶
Overview ¶
Package signedxml transforms and validates signedxml documents
Index ¶
- Variables
- func InsertTextIntoSignatureTemplate(xmlSignatureTemplate string, text string, unindent bool, ...) (out string, e error)
- func InsertXMLintoSignatureTemplate(xmlSignatureTemplate string, xmlToBeInserted string, unindent bool, ...) (out string, e error)
- func PrepPKCS8PrivateKey(PEMKeyBytes []byte) (key any, e error)
- type CanonicalizationAlgorithm
- type EnvelopedSignature
- func (e EnvelopedSignature) Process(inputXML string, transformXML string) (outputXML string, err error)
- func (e EnvelopedSignature) ProcessDocument(doc *etree.Document, transformXML string) (outputXML string, err error)
- func (e EnvelopedSignature) ProcessElement(inputXML *etree.Element, transformXML string) (outputXML string, err error)
- type ExclusiveCanonicalization
- func (e ExclusiveCanonicalization) Process(inputXML string, transformXML string) (outputXML string, err error)
- func (e ExclusiveCanonicalization) ProcessDocument(doc *etree.Document, transformXML string) (outputXML string, err error)
- func (e ExclusiveCanonicalization) ProcessElement(inputXML *etree.Element, transformXML string) (outputXML string, err error)
- type Signer
- type Validator
Constants ¶
This section is empty.
Variables ¶
var CanonicalizationAlgorithms map[string]CanonicalizationAlgorithm
CanonicalizationAlgorithms maps the CanonicalizationMethod or Transform Algorithm URIs to a type that implements the CanonicalizationAlgorithm interface.
Implementations are provided for the following transforms:
http://www.w3.org/2001/10/xml-exc-c14n# (ExclusiveCanonicalization) http://www.w3.org/2001/10/xml-exc-c14n#WithComments (ExclusiveCanonicalizationWithComments) http://www.w3.org/2000/09/xmldsig#enveloped-signature (EnvelopedSignature)
Custom implementations can be added to the map
Functions ¶
func InsertXMLintoSignatureTemplate ¶
func InsertXMLintoSignatureTemplate(xmlSignatureTemplate string, xmlToBeInserted string, unindent bool, addProcessInstructions bool) (out string, e error)
Inserts an XML document into the XML template - both inputs in the form of a string. Returns a XML string document prepared for signing. No transforms are done.
Returns error, if something goes wrong. Typically, a missing <Signature> or <Object> tag in the template.. or Object "Id" attribute missing.
Params: xmlSignatureTemplate - the template to be used, i.e. where the document is inserted into; xmlToBeInserted - the XML document to be inserted into the template unindent - unindent/minify resulting document; addProcessInstructions - add processing instructions for at the header of the XML, i.e. `version="1.0" encoding="UTF-8"`
func PrepPKCS8PrivateKey ¶
Decodes private key bytes in the PEM format and parses it into PKCS #8, ASN.1 DER form, which then can be used by signer.Sign(key)
Types ¶
type CanonicalizationAlgorithm ¶
type CanonicalizationAlgorithm interface { // ProcessElement is called to transform an XML Element within an XML Document // using the implementing algorithm ProcessElement(inputXML *etree.Element, transformXML string) (outputXML string, err error) // ProcessDocument is called to transform an XML Document using the implementing // algorithm. ProcessDocument(doc *etree.Document, transformXML string) (outputXML string, err error) // Process is called to transform a string containing XML text using the implementing // algorithm. The inputXML parameter should contain a complete XML Document. It is not // correct to use this function on XML fragments. Retained for backward comparability. // Use ProcessElement or ProcessDocument if possible. Process(inputXML string, transformXML string) (outputXML string, err error) }
CanonicalizationAlgorithm defines an interface for processing an XML document into a standard format.
If any child elements are in the Transform node, the entire transform node will be passed to the Process method through the transformXML parameter as an XML string. This is necessary for transforms that need additional processing data, like XPath (http://www.w3.org/TR/xmldsig-core/#sec-XPath). If there are no child elements in Transform (or CanonicalizationMethod), then an empty string will be passed through.
type EnvelopedSignature ¶
type EnvelopedSignature struct{}
EnvelopedSignature implements the CanonicalizationAlgorithm interface and is used for processing the http://www.w3.org/2000/09/xmldsig#enveloped-signature transform algorithm
func (EnvelopedSignature) Process ¶
func (e EnvelopedSignature) Process(inputXML string, transformXML string) (outputXML string, err error)
see CanonicalizationAlgorithm.Process
func (EnvelopedSignature) ProcessDocument ¶
func (e EnvelopedSignature) ProcessDocument(doc *etree.Document, transformXML string) (outputXML string, err error)
see CanonicalizationAlgorithm.ProcessDocument
func (EnvelopedSignature) ProcessElement ¶
func (e EnvelopedSignature) ProcessElement(inputXML *etree.Element, transformXML string) (outputXML string, err error)
see CanonicalizationAlgorithm.ProcessElement
type ExclusiveCanonicalization ¶
type ExclusiveCanonicalization struct { WithComments bool // contains filtered or unexported fields }
ExclusiveCanonicalization implements the CanonicalizationAlgorithm interface and is used for processing the http://www.w3.org/2001/10/xml-exc-c14n# and http://www.w3.org/2001/10/xml-exc-c14n#WithComments transform algorithms
func (ExclusiveCanonicalization) Process ¶
func (e ExclusiveCanonicalization) Process(inputXML string, transformXML string) (outputXML string, err error)
see CanonicalizationAlgorithm.Process
func (ExclusiveCanonicalization) ProcessDocument ¶
func (e ExclusiveCanonicalization) ProcessDocument(doc *etree.Document, transformXML string) (outputXML string, err error)
see CanonicalizationAlgorithm.ProcessDocument
func (ExclusiveCanonicalization) ProcessElement ¶
func (e ExclusiveCanonicalization) ProcessElement(inputXML *etree.Element, transformXML string) (outputXML string, err error)
see CanonicalizationAlgorithm.ProcessElement
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer provides options for signing an XML document
func NewSignerFromDoc ¶
NewSignerFromDoc returns a *Signer for the Document provided
func (*Signer) SetReferenceIDAttribute ¶
SetReferenceIDAttribute set the referenceIDAttribute
func (*Signer) SetSignature ¶
SetSignature can be used to assign an external signature for the XML doc that Validator will verify
type Validator ¶
type Validator struct { Certificates []x509.Certificate // contains filtered or unexported fields }
Validator provides options for verifying a signed XML document
func NewValidator ¶
NewValidator returns a *Validator for the XML provided
func (*Validator) SetReferenceIDAttribute ¶
SetReferenceIDAttribute set the referenceIDAttribute
func (*Validator) SetSignature ¶
SetSignature can be used to assign an external signature for the XML doc that Validator will verify
func (*Validator) SigningCert ¶
func (v *Validator) SigningCert() x509.Certificate
SigningCert returns the certificate, if any, that was used to successfully validate the signature of the XML document. This will be a zero value x509.Certificate before Validator.Validate is successfully called.
func (*Validator) ValidateReferences ¶
ValidateReferences validates the Reference digest values, and the signature value over the SignedInfo.
If the signature is enveloped in the XML, then it will be used. Otherwise, an external signature should be assigned using Validator.SetSignature.
The references returned contain validated XML from the signature and must be used. Callers that ignore the returned references are vulnerable to XML injection.