1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
package libebics
import (
"bytes"
"compress/zlib"
"encoding/base64"
"encoding/xml"
"fmt"
)
type EbicsUnsecuredRequest struct {
XMLName xml.Name `xml:"ebicsUnsecuredRequest"`
Xmlns string `xml:"xmlns,attr"`
Version string `xml:"Version,attr"`
Revision string `xml:"Revision,attr"`
Header EbicsHeader `xml:"header"`
Body EbicsBody `xml:"body"`
}
type EbicsHeader struct {
XMLName xml.Name `xml:"header"`
Authenticate bool `xml:"authenticate,attr"`
Static EbicsHeaderStatic `xml:"static"`
Mutable EbicsHeaderMutable `xml:"mutable"`
}
type EbicsHeaderStatic struct {
XMLName xml.Name `xml:"static"`
HostID string `xml:"HostID"`
PartnerID string `xml:"PartnerID"`
UserID string `xml:"UserID"`
Product EbicsProduct `xml:"Product"`
OrderDetails EbicsOrderDetails `xml:"OrderDetails"`
SecurityMedium string `xml:"SecurityMedium"`
}
type EbicsProduct struct {
XMLName xml.Name `xml:"Product"`
Language string `xml:"Language,attr"`
Name string `xml:",chardata"`
}
type EbicsOrderDetails struct {
XMLName xml.Name `xml:"OrderDetails"`
AdminOrderType string `xml:"AdminOrderType"`
}
type EbicsHeaderMutable struct {
XMLName xml.Name `xml:"mutable"`
}
type EbicsBody struct {
XMLName xml.Name `xml:"body"`
DataTransfer EbicsDataTransfer `xml:"DataTransfer"`
}
type EbicsDataTransfer struct {
XMLName xml.Name `xml:"DataTransfer"`
OrderData string `xml:"OrderData"` // TODO Properly marshal this
}
type EbicsSignaturePubKeyOrderData struct {
XMLName xml.Name `xml:"esig:SignaturePubKeyOrderData"`
Esig string `xml:"xmlns:esig,attr"`
Ds string `xml:"xmlns:ds,attr"`
SignaturePubKeyInfo EbicsSignaturePubKeyInfo `xml:"esig:SignaturePubKeyInfo"`
PartnerID string `xml:"esig:PartnerID"`
UserID string `xml:"esig:UserID"`
}
type EbicsHiaRequestOrderData struct {
XMLName xml.Name `xml:"HIARequestOrderData"`
Xmlns string `xml:"xmlns,attr"`
Esig string `xml:"xmlns:esig,attr"`
Ds string `xml:"xmlns:ds,attr"`
AuthenticationPubKeyInfo EbicsAuthenticationPubKeyInfo `xml:"AuthenticationPubKeyInfo"`
EncryptionPubKeyInfo EbicsEncryptionPubKeyInfo `xml:"EncryptionPubKeyInfo"`
PartnerID string `xml:"PartnerID"`
UserID string `xml:"UserID"`
}
type EbicsAuthenticationPubKeyInfo struct {
XMLName xml.Name `xml:"AuthenticationPubKeyInfo"`
X509Data EbicsX509Data `xml:"ds:X509Data"`
AuthenticationVersion string `xml:"AuthenticationVersion"` // TODO Use ENUM
}
type EbicsEncryptionPubKeyInfo struct {
XMLName xml.Name `xml:"EncryptionPubKeyInfo"`
X509Data EbicsX509Data `xml:"ds:X509Data"`
EncryptionVersion string `xml:"EncryptionVersion"` // TODO Use ENUM
}
type EbicsSignaturePubKeyInfo struct {
XMLName xml.Name `xml:"esig:SignaturePubKeyInfo"`
X509Data EbicsX509Data `xml:"ds:X509Data"`
SignatureVersion string `xml:"esig:SignatureVersion"` // TODO Use ENUM
}
type EbicsX509Data struct {
XMLName xml.Name `xml:"ds:X509Data"`
X509Certificate string `xml:"ds:X509Certificate"` // TODO Properly marshal this
}
func GenerateIniRequest(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 := EbicsSignaturePubKeyOrderData{
Esig: "http://www.ebics.org/S002",
Ds: "http://www.w3.org/2000/09/xmldsig#",
SignaturePubKeyInfo: EbicsSignaturePubKeyInfo{
X509Data: EbicsX509Data{
X509Certificate: base64.StdEncoding.EncodeToString(
signatureCertificate.x509Certificate, // TODO Proper Base64 Marshalling
),
},
SignatureVersion: signatureCertificate.ebicsCertificateType.String(),
},
PartnerID: "MV008078",
UserID: "SCHOLZ01",
}
orderData_xml, err := xml.Marshal(orderData)
if err != nil {
return "", err
}
zlibWriter.Write(orderData_xml)
zlibWriter.Close()
ini := EbicsUnsecuredRequest{
Xmlns: "urn:org:ebics:H005",
Version: "H005",
Revision: "1",
Header: EbicsHeader{
Authenticate: true,
Static: EbicsHeaderStatic{
HostID: "MULTIVIA",
PartnerID: "MV008078",
UserID: "SCHOLZ01",
Product: EbicsProduct{
Language: "en",
Name: "libebics",
},
OrderDetails: EbicsOrderDetails{
AdminOrderType: "INI",
},
SecurityMedium: "0000",
},
},
Body: EbicsBody{
DataTransfer: EbicsDataTransfer{
OrderData: base64.StdEncoding.EncodeToString(
zlibWriterBuffer.Bytes(),
),
},
},
}
marshal, err := xml.MarshalIndent(ini, "", " ")
return (xml.Header + string(marshal)), err
}
func GenerateHiaRequest(authenticationCertificate EbicsCertificate, encryptionCertificate EbicsCertificate) (string, error) {
if authenticationCertificate.ebicsCertificateType != X002 {
return "", fmt.Errorf("authentication certificate has invalid certificate type %s", authenticationCertificate.ebicsCertificateType.String())
}
if encryptionCertificate.ebicsCertificateType != E002 {
return "", fmt.Errorf("encryption certificate has invalid certificate type %s", encryptionCertificate.ebicsCertificateType.String())
}
var zlibWriterBuffer bytes.Buffer
zlibWriter := zlib.NewWriter(&zlibWriterBuffer)
orderData := EbicsHiaRequestOrderData{
Xmlns: "urn:org:ebics:H005",
Esig: "http://www.ebics.org/S002",
Ds: "http://www.w3.org/2000/09/xmldsig#",
AuthenticationPubKeyInfo: EbicsAuthenticationPubKeyInfo{
X509Data: EbicsX509Data{
X509Certificate: base64.StdEncoding.EncodeToString(
authenticationCertificate.x509Certificate, // TODO Proper Base64 Marshalling
),
},
AuthenticationVersion: authenticationCertificate.ebicsCertificateType.String(),
},
EncryptionPubKeyInfo: EbicsEncryptionPubKeyInfo{
X509Data: EbicsX509Data{
X509Certificate: base64.StdEncoding.EncodeToString(
encryptionCertificate.x509Certificate, // TODO Proper Base64 Marshalling
),
},
EncryptionVersion: encryptionCertificate.ebicsCertificateType.String(),
},
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()
ini := EbicsUnsecuredRequest{
Xmlns: "urn:org:ebics:H005",
Version: "H005",
Revision: "1",
Header: EbicsHeader{
Authenticate: true,
Static: EbicsHeaderStatic{
HostID: "MULTIVIA",
PartnerID: "MV008078",
UserID: "SCHOLZ01",
Product: EbicsProduct{
Language: "en",
Name: "libebics",
},
OrderDetails: EbicsOrderDetails{
AdminOrderType: "HIA",
},
SecurityMedium: "0000",
},
},
Body: EbicsBody{
DataTransfer: EbicsDataTransfer{
OrderData: base64.StdEncoding.EncodeToString(
zlibWriterBuffer.Bytes(),
),
},
},
}
marshal, err := xml.MarshalIndent(ini, "", " ")
return (xml.Header + string(marshal)), err
}
|