summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DSIG.go8
-rw-r--r--H005.go45
-rw-r--r--order.go95
-rw-r--r--order_test.go27
-rw-r--r--xml.go4
-rw-r--r--xmldsig.go53
6 files changed, 222 insertions, 10 deletions
diff --git a/DSIG.go b/DSIG.go
deleted file mode 100644
index 8dca0ab..0000000
--- a/DSIG.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package libebics
-
-import "encoding/xml"
-
-type DSIGX509Data struct {
- XMLName xml.Name `xml:"ds:X509Data"`
- DSIGX509Certificate string `xml:"ds:X509Certificate"` // TODO Properly marshal this
-}
diff --git a/H005.go b/H005.go
index 83f48d7..1b9740e 100644
--- a/H005.go
+++ b/H005.go
@@ -1,6 +1,9 @@
package libebics
-import "encoding/xml"
+import (
+ "encoding/xml"
+ "time"
+)
type H005UnsecuredRequest struct {
XMLName xml.Name `xml:"ebicsUnsecuredRequest"`
@@ -75,3 +78,43 @@ type H005EncryptionPubKeyInfo struct {
X509Data DSIGX509Data `xml:"ds:X509Data"`
EncryptionVersion EbicsCertificateType `xml:"EncryptionVersion"`
}
+
+type H005NoPubKeyDigestsRequest struct {
+ XMLName xml.Name `xml:"ebicsNoPubKeyDigestsRequest"`
+ Xmlns string `xml:"xmlns,attr"`
+ Ds string `xml:"xmlns:ds,attr"`
+ Version string `xml:"Version,attr"`
+ Revision string `xml:"Revision,attr"`
+ Header H005NoPubKeyDigestsRequestHeader `xml:"header"`
+ AuthSignature DSIGSignatureType `xml:"AuthSignature"` // TODO Base64 marshalling
+ Body H005NoPubKeyDigestsRequestBody `xml:"body"` // TODO Cannot be correct
+
+}
+
+type H005NoPubKeyDigestsRequestHeader struct {
+ XMLName xml.Name `xml:"header"`
+ Authenticate bool `xml:"authenticate,attr"`
+ Static H005NoPubKeyDigestsRequestStaticHeaderType `xml:"static"`
+ Mutable H005EmptyMutableHeaderType `xml:"mutable"`
+}
+
+type H005NoPubKeyDigestsRequestStaticHeaderType struct {
+ XMLName xml.Name `xml:"static"`
+ HostID string `xml:"HostID"`
+ Nonce string `xml:"Nonce"`
+ Timestamp time.Time `xml:"Timestamp"`
+ PartnerID string `xml:"PartnerID"`
+ UserID string `xml:"UserID"`
+ Product H005ProductElementType `xml:"Product"`
+ OrderDetails H005NoPubKeyDigestsReqOrderDetailsType `xml:"OrderDetails"`
+ SecurityMedium string `xml:"SecurityMedium"`
+}
+
+type H005NoPubKeyDigestsReqOrderDetailsType struct {
+ XMLName xml.Name `xml:"OrderDetails"`
+ AdminOrderType string `xml:"AdminOrderType"`
+}
+
+type H005NoPubKeyDigestsRequestBody struct {
+ XMLName xml.Name `xml:"body"`
+}
diff --git a/order.go b/order.go
index 273f7ff..c9d939b 100644
--- a/order.go
+++ b/order.go
@@ -3,9 +3,11 @@ package libebics
import (
"bytes"
"compress/zlib"
+ "crypto/rand"
"encoding/base64"
"encoding/xml"
"fmt"
+ "time"
)
func GenerateIniRequest(signatureCertificate EbicsCertificate) (string, error) {
@@ -156,3 +158,96 @@ func GenerateHiaRequest(authenticationCertificate EbicsCertificate, encryptionCe
return (xml.Header + string(marshal)), err
}
+
+func GenerateHpbRequest(signatureCertificate EbicsCertificate) (string, error) {
+
+ if signatureCertificate.ebicsCertificateType != A005 &&
+ signatureCertificate.ebicsCertificateType != A006 {
+ return "", fmt.Errorf("signature certificate has invalid certificate type %s", signatureCertificate.ebicsCertificateType.String())
+ }
+ /*
+ var zlibWriterBuffer bytes.Buffer
+ zlibWriter := zlib.NewWriter(&zlibWriterBuffer)
+
+ orderData := S002SignaturePubKeyOrderDataType{
+ Esig: "http://www.ebics.org/S002",
+ Ds: "http://www.w3.org/2000/09/xmldsig#",
+ SignaturePubKeyInfo: S002SignaturePubKeyInfoType{
+ X509Data: DSIGX509Data{
+ DSIGX509Certificate: base64.StdEncoding.EncodeToString(
+ signatureCertificate.x509Certificate, // TODO Proper Base64 Marshalling
+ ),
+ },
+ SignatureVersion: signatureCertificate.ebicsCertificateType,
+ },
+ PartnerID: "MV008078",
+ UserID: "SCHOLZ01",
+ }
+
+ orderData_xml, err := xml.Marshal(orderData)
+ if err != nil {
+ return "", err
+ }
+
+ fmt.Print(string(orderData_xml))
+ zlibWriter.Write(orderData_xml)
+ zlibWriter.Close()
+ */
+
+ token := make([]byte, 16)
+ rand.Read(token)
+
+ hpb := H005NoPubKeyDigestsRequest{
+ Xmlns: "urn:org:ebics:H005",
+ Ds: "http://www.w3.org/2000/09/xmldsig#",
+ Version: "H005",
+ Revision: "1",
+ Header: H005NoPubKeyDigestsRequestHeader{
+ Authenticate: true,
+ Static: H005NoPubKeyDigestsRequestStaticHeaderType{
+ HostID: "MULTIVIA",
+ Nonce: fmt.Sprintf("%X", token),
+ Timestamp: time.Now(),
+ PartnerID: "MV008078",
+ UserID: "SCHOLZ01",
+ Product: H005ProductElementType{
+ Language: "en",
+ Name: "libebics",
+ },
+ OrderDetails: H005NoPubKeyDigestsReqOrderDetailsType{
+ AdminOrderType: "HPB",
+ },
+ SecurityMedium: "0000",
+ },
+ Mutable: H005EmptyMutableHeaderType{},
+ },
+ AuthSignature: DSIGSignatureType{
+ SignedInfo: DSIGSignedInfo{
+ CanonicalizationMethod: DSIGCanonicalizationMethod{
+ Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", // TODO const
+ },
+ SignatureMethod: DSIGSignatureMethod{
+ Algorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", // TODO const
+ },
+ Reference: DSIGReference{
+ URI: "#xpointer(//*[@authenticate='true'])", // TODO const
+ Transforms: DSIGTransforms{
+ Transform: DSIGTransform{
+ Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
+ },
+ },
+ DigestMethod: DSIGDigestMethod{
+ Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256",
+ },
+ DigestValue: "",
+ },
+ },
+ SignatureValue: "",
+ },
+ Body: H005NoPubKeyDigestsRequestBody{},
+ }
+
+ marshal, err := xml.MarshalIndent(hpb, "", " ")
+
+ return (xml.Header + string(marshal)), err
+}
diff --git a/order_test.go b/order_test.go
index ff8119c..a780961 100644
--- a/order_test.go
+++ b/order_test.go
@@ -66,3 +66,30 @@ func TestSendHiaRequest(t *testing.T) {
body, err := io.ReadAll(resp.Body)
t.Log(string(body))
}
+
+func TestSendHpbRequest(t *testing.T) {
+ signatureCertificate, err := ReadCertificateFromFile(filepath.Join("certs", "signature_cert.pem"), A005)
+ if err != nil {
+ t.Error(err.Error())
+ }
+
+ hpb, err := GenerateHpbRequest(*signatureCertificate)
+ if err != nil {
+ t.Error(err.Error())
+ }
+
+ t.Log(hpb)
+
+ resp, err := http.Post(
+ "https://ebics-test.multivia-suite.de/MVB_ENT/ebicsweb",
+ "text/xml; charset=UTF-8",
+ strings.NewReader(hpb),
+ )
+ if err != nil {
+ t.Error(err.Error())
+ }
+ defer resp.Body.Close()
+
+ body, err := io.ReadAll(resp.Body)
+ t.Log(string(body))
+}
diff --git a/xml.go b/xml.go
index d528dde..eacacfa 100644
--- a/xml.go
+++ b/xml.go
@@ -1,6 +1,8 @@
package libebics
-import "encoding/xml"
+import (
+ "encoding/xml"
+)
func (t EbicsCertificateType) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(t.String(), start)
diff --git a/xmldsig.go b/xmldsig.go
new file mode 100644
index 0000000..663f147
--- /dev/null
+++ b/xmldsig.go
@@ -0,0 +1,53 @@
+package libebics
+
+import "encoding/xml"
+
+type DSIGX509Data struct {
+ XMLName xml.Name `xml:"ds:X509Data"`
+ DSIGX509Certificate string `xml:"ds:X509Certificate"` // TODO Properly marshal this
+}
+
+type DSIGSignatureType struct {
+ SignedInfo DSIGSignedInfo `xml:"ds:SignedInfo"`
+ SignatureValue string `xml:"ds:SignatureValue"` // TODO Properly marshal this
+}
+
+type DSIGSignedInfo struct {
+ XMLName xml.Name `xml:"ds:SignedInfo"`
+ CanonicalizationMethod DSIGCanonicalizationMethod `xml:"ds:CanonicalizationMethod"`
+ SignatureMethod DSIGSignatureMethod `xml:"ds:SignatureMethod"`
+ Reference DSIGReference `xml:"ds:Reference"`
+}
+
+type DSIGCanonicalizationMethod struct {
+ XMLName xml.Name `xml:"ds:CanonicalizationMethod"`
+ Algorithm string `xml:"Algorithm,attr"`
+}
+
+type DSIGSignatureMethod struct {
+ XMLName xml.Name `xml:"ds:SignatureMethod"`
+ Algorithm string `xml:"Algorithm,attr"`
+}
+
+type DSIGReference struct {
+ XMLName xml.Name `xml:"ds:Reference"`
+ URI string `xml:"URI,attr"`
+ Transforms DSIGTransforms `xml:"ds:Transforms"`
+ DigestMethod DSIGDigestMethod `xml:"ds:DigestMethod"`
+ DigestValue string `xml:"ds:DigestValue"`
+}
+
+type DSIGTransforms struct {
+ XMLName xml.Name `xml:"ds:Transforms"`
+ Transform DSIGTransform `xml:"ds:Transform"` // TODO make proper list
+}
+
+type DSIGTransform struct {
+ XMLName xml.Name `xml:"ds:Transform"`
+ Algorithm string `xml:"Algorithm,attr"`
+}
+
+type DSIGDigestMethod struct {
+ XMLName xml.Name `xml:"ds:DigestMethod"`
+ Algorithm string `xml:"Algorithm,attr"`
+}