...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package xmldsig
18
19 import (
20 "crypto"
21 "encoding/xml"
22 )
23
24 const (
25 NsXMLDsig = "http://www.w3.org/2000/09/xmldsig#"
26 NsXMLDsigMore = "http://www.w3.org/2001/04/xmldsig-more#"
27 NsXMLEnc = "http://www.w3.org/2001/04/xmlenc#"
28 NsXsi = "http://www.w3.org/2001/XMLSchema-instance"
29 AlgXMLExcC14n = "http://www.w3.org/2001/10/xml-exc-c14n#"
30 AlgXMLExcC14nRec = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
31
32 AlgDsigEnvelopedSignature = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
33 )
34
35
36 var nsPrefixes = []string{NsXMLDsig, NsXMLDsigMore, NsXMLEnc}
37
38 var hashNames = map[crypto.Hash]string{
39 crypto.SHA1: "sha1",
40 crypto.SHA224: "sha224",
41 crypto.SHA256: "sha256",
42 crypto.SHA384: "sha384",
43 crypto.SHA512: "sha512",
44 }
45
46 var HashUris = map[crypto.Hash]string{
47 crypto.SHA1: NsXMLDsig + "sha1",
48 crypto.SHA224: NsXMLDsigMore + "sha224",
49 crypto.SHA256: NsXMLEnc + "sha256",
50 crypto.SHA384: NsXMLDsigMore + "sha384",
51 crypto.SHA512: NsXMLEnc + "sha512",
52 }
53
54 type signature struct {
55 XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"`
56
57 CanonicalizationMethod method `xml:"SignedInfo>CanonicalizationMethod"`
58 SignatureMethod method `xml:"SignedInfo>SignatureMethod"`
59 Reference reference `xml:"SignedInfo>Reference"`
60 SignatureValue string `xml:"SignatureValue"`
61 KeyName string `xml:"KeyInfo>KeyName,omitempty"`
62 KeyValue *keyValue `xml:"KeyInfo>KeyValue,omitempty"`
63 X509Certificates []string `xml:"KeyInfo>X509Data>X509Certificate,omitempty"`
64 }
65
66 type reference struct {
67 URI string `xml:",attr"`
68 Transforms []method `xml:"Transforms>Transform"`
69 DigestMethod method
70 DigestValue string
71 }
72
73 type method struct {
74 Algorithm string `xml:",attr"`
75 }
76
77 type keyValue struct {
78 Modulus string `xml:"RSAKeyValue>Modulus,omitempty"`
79 Exponent string `xml:"RSAKeyValue>Exponent,omitempty"`
80 NamedCurve namedCurve `xml:"ECDSAKeyValue>DomainParameters>NamedCurve,omitempty"`
81 X pointValue `xml:"ECDSAKeyValue>PublicKey>X,omitempty"`
82 Y pointValue `xml:"ECDSAKeyValue>PublicKey>Y,omitempty"`
83 }
84
85 type namedCurve struct {
86 URN string `xml:",attr"`
87 }
88
89 type pointValue struct {
90 Value string `xml:",attr"`
91 }
92
View as plain text