add URI attribute to <Reference>
This commit is contained in:
53
signature.go
53
signature.go
@@ -10,6 +10,18 @@ import (
|
|||||||
type Method struct {
|
type Method struct {
|
||||||
Algorithm string `xml:",attr"`
|
Algorithm string `xml:",attr"`
|
||||||
}
|
}
|
||||||
|
type Reference struct {
|
||||||
|
URI string `xml:"URI,attr"`
|
||||||
|
ReferenceTransforms []Method `xml:"Transforms>Transform"`
|
||||||
|
DigestMethod Method `xml:"DigestMethod"`
|
||||||
|
DigestValue string `xml:"DigestValue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SignedInfo struct {
|
||||||
|
CanonicalizationMethod Method `xml:"CanonicalizationMethod"`
|
||||||
|
SignatureMethod Method `xml:"SignatureMethod"`
|
||||||
|
Reference Reference `xml:"Reference"`
|
||||||
|
}
|
||||||
|
|
||||||
// Signature is a model for the Signature object specified by XMLDSIG. This is
|
// Signature is a model for the Signature object specified by XMLDSIG. This is
|
||||||
// convenience object when constructing XML that you'd like to sign. For example:
|
// convenience object when constructing XML that you'd like to sign. For example:
|
||||||
@@ -25,16 +37,11 @@ type Method struct {
|
|||||||
// buf, _ = Sign(key, buf)
|
// buf, _ = Sign(key, buf)
|
||||||
//
|
//
|
||||||
type Signature struct {
|
type Signature struct {
|
||||||
XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"`
|
XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"`
|
||||||
|
SignedInfo SignedInfo
|
||||||
CanonicalizationMethod Method `xml:"SignedInfo>CanonicalizationMethod"`
|
SignatureValue string `xml:"SignatureValue"`
|
||||||
SignatureMethod Method `xml:"SignedInfo>SignatureMethod"`
|
KeyName string `xml:"KeyInfo>KeyName,omitempty"`
|
||||||
ReferenceTransforms []Method `xml:"SignedInfo>Reference>Transforms>Transform"`
|
X509Certificate *SignatureX509Data `xml:"KeyInfo>X509Data,omitempty"`
|
||||||
DigestMethod Method `xml:"SignedInfo>Reference>DigestMethod"`
|
|
||||||
DigestValue string `xml:"SignedInfo>Reference>DigestValue"`
|
|
||||||
SignatureValue string `xml:"SignatureValue"`
|
|
||||||
KeyName string `xml:"KeyInfo>KeyName,omitempty"`
|
|
||||||
X509Certificate *SignatureX509Data `xml:"KeyInfo>X509Data,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignatureX509Data represents the <X509Data> element of <Signature>
|
// SignatureX509Data represents the <X509Data> element of <Signature>
|
||||||
@@ -50,17 +57,21 @@ func DefaultSignature(pemEncodedPublicKey []byte) Signature {
|
|||||||
certStr := base64.StdEncoding.EncodeToString(pemBlock.Bytes)
|
certStr := base64.StdEncoding.EncodeToString(pemBlock.Bytes)
|
||||||
|
|
||||||
return Signature{
|
return Signature{
|
||||||
CanonicalizationMethod: Method{
|
SignedInfo: SignedInfo{
|
||||||
Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
|
CanonicalizationMethod: Method{
|
||||||
},
|
Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
|
||||||
SignatureMethod: Method{
|
},
|
||||||
Algorithm: "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
|
SignatureMethod: Method{
|
||||||
},
|
Algorithm: "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
|
||||||
ReferenceTransforms: []Method{
|
},
|
||||||
Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature"},
|
Reference: Reference{
|
||||||
},
|
ReferenceTransforms: []Method{
|
||||||
DigestMethod: Method{
|
Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature"},
|
||||||
Algorithm: "http://www.w3.org/2000/09/xmldsig#sha1",
|
},
|
||||||
|
DigestMethod: Method{
|
||||||
|
Algorithm: "http://www.w3.org/2000/09/xmldsig#sha1",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
X509Certificate: &SignatureX509Data{
|
X509Certificate: &SignatureX509Data{
|
||||||
X509Certificate: certStr,
|
X509Certificate: certStr,
|
||||||
|
|||||||
Reference in New Issue
Block a user