Skip to content

Commit

Permalink
Customize connection, support for propert root CAs
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Nov 14, 2024
1 parent d15e2a0 commit ee4f98e
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 15 deletions.
41 changes: 41 additions & 0 deletions ca/AAPPNR_cert_sha256.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-----BEGIN CERTIFICATE-----
MIIHNzCCBSGgAwIBAgIQJMXIqlZvjuhMvqcFXOFkpDALBgkqhkiG9w0BAQswODEL
MAkGA1UEBhMCRVMxFDASBgNVBAoMC0laRU5QRSBTLkEuMRMwEQYDVQQDDApJemVu
cGUuY29tMB4XDTEwMTAyMDA4MjMzM1oXDTM3MTIxMjIzMDAwMFowgZ0xCzAJBgNV
BAYTAkVTMRQwEgYDVQQKDAtJWkVOUEUgUy5BLjE6MDgGA1UECwwxQVpaIFppdXJ0
YWdpcmkgcHVibGlrb2EgLSBDZXJ0aWZpY2FkbyBwdWJsaWNvIFNDQTE8MDoGA1UE
AwwzRUFFa28gSGVycmkgQWRtaW5pc3RyYXppb2VuIENBIC0gQ0EgQUFQUCBWYXNj
YXMgKDIpMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAoIM7nEdI0N1h
rR5T4xuV/usKDoMIasaiKvfLhbwxaNtTt+a7W/6wV5bv3svQFIy3sUXjjdzV1nG2
To2wo/YSPQiOt8exWvOapvL21ogiof+kelWnXFjWaKJI/vThHYLgIYEMj/y4HdtU
ojI646rZwqsb4YGAopwgmkDfUh5jOhV2IcYE3TgJAYWVkj6jku9PLaIsHiarAHjD
PY8dig8a4SRv0gm5Yk7FXLmW1d14oxQBDeHZ7zOEXfpafxdEDO2SNaRJjpkh8XRr
PGqkg2y1Q3gT6b4537jz+StyDIJ3omylmlJsGCwqT7p8mEqjGJ5kC5I2VnjXKuNn
soShc72khWZVUJiJo5SGuAkNE2ZXqltBVm5Jv6QweQKsX6bkcMc4IZok4a+hx8FM
8I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+G7bDUapjlH1xyv55NC5I6wCXGC6E
3TEP5B/E7dZD0s9E4lS511ubVZivFgOzMYo1DO96diny/N/V1enaTCpRl1qH1OyL
xUYTijV4ph2gL6exwuG7pxfRcVNHYlrRaXWfTz3F6NBKyULxrI3P/y6JAtN1GqT4
VF/+vMygx22n0DufGepBwTQz6/rr1ulSZ+eMnuJiTXgh/BzQnkUsXTb8mHII25iR
0oYF2qAsk6ecWbLiDpkHKIDHmML21MZE13MS8NSvTHoqJO4LyAmDe6SaeNHtrPlK
b6mzE1BN2ug+ZaX8wLA5IMPFaf0jKhb/Cxu8INsxjt00brsErCc9ip1VNaH0M4bi
1tGxfiew2436FaeyUxW7Pl6G5GgkNbuUc7QIoRy06DdU/U38BxW3uyJMY60zwHvS
FlKAn0OvYp4niKhAJwaBVN3kowmJuOU5Rid+TUnfyxbJ9cttSgzaF3hP/N4zgMEM
5tikXUskeckt8LUK96EH0QyssavAMECUEb/xrupyRdYWwjQGvNLq6T5+fViDGyOw
k+lzD44wofy8paAy9uC9Owae0zMEzhcsyRm7
-----END CERTIFICATE-----
34 changes: 34 additions & 0 deletions ca/RAIZ2007_cert_sha256.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-----BEGIN CERTIFICATE-----
MIIF8TCCA9mgAwIBAgIQALC3WhZIX7/hy/WL1xnmfTANBgkqhkiG9w0BAQsFADA4
MQswCQYDVQQGEwJFUzEUMBIGA1UECgwLSVpFTlBFIFMuQS4xEzARBgNVBAMMCkl6
ZW5wZS5jb20wHhcNMDcxMjEzMTMwODI4WhcNMzcxMjEzMDgyNzI1WjA4MQswCQYD
VQQGEwJFUzEUMBIGA1UECgwLSVpFTlBFIFMuQS4xEzARBgNVBAMMCkl6ZW5wZS5j
b20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDJ03rKDx6sp4boFmVq
scIbRTJxldn+EFvMr+eleQGPicPK8lVx93e+d5TzcqQsRNiekpsUOqHnJJAKClaO
xdgmlOHZ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3sb9fbgakEyrkgPH7UIBzg/YsfqikuFgba56
awmqxinuaElnMIAkejEWOVt+8Rwu3WwJrfIxwYJOubv5vr8qhT/AQKM6WfxZSzwo
JNu0FXWuDYi6LnPAvViH5ULy617uHjAimcs30cQhbIHsvm0m5hzkQiCeR7Csg1lw
LDXWrzY0tM07+DKo7+N4ifuNRSzanLh+QBxh5z6ikixL8s36mLYp//Pye6kfLqCT
VyvehQP5aTfLnnhqBbTFMXiJ7HqnheG5ezzevh55hM6fcA5ZwjUukCox2eRFekGk
LhObNA5me0mrZJfQRsN5nXJQY6aYWwa9SG3YOYNw6DXwBdGqvOPbyALqfP2C2sJb
UjWumDqtujWTI6cfSN01RpiyEGjkpTHCClguGYEQyVB1/OpaFs4R1+7vUIgtYf8/
QnMFlEPVjjxOAToZpR9GTnfQXeWBIiGH/pR9hNiTrdZoQ0iy2+tzJOeRf1SktoA+
naM8THLCV8Sg1Mw4J87VBp6iSNnpn86CcDaTmjvfliHjWbcM2pE38P1ZWrOZyGls
QyYBNWNgVYkDOnXYukrZVP/u3oDYLdE41V4tC5h9Pmzb/CaIxw==
-----END CERTIFICATE-----
40 changes: 40 additions & 0 deletions ca/SSLEV_cert_signing_1_2018.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-----BEGIN CERTIFICATE-----
MIIHGjCCBQKgAwIBAgIQaH23FxdE2iNbP2Jac5P4pTANBgkqhkiG9w0BAQsFADA4
MQswCQYDVQQGEwJFUzEUMBIGA1UECgwLSVpFTlBFIFMuQS4xEzARBgNVBAMMCkl6
ZW5wZS5jb20wHhcNMTgwNzA2MTIzNjQxWhcNMjgwNzA2MTIzNjQxWjCBgTELMAkG
A1UEBhMCRVMxFDASBgNVBAoMC0laRU5QRSBTLkEuMTgwNgYDVQQLDC9CWiBaaXVy
dGFnaXJpIHB1Ymxpa29hIC0gQ2VydGlmaWNhZG8gcHVibGljbyBFVjEiMCAGA1UE
AwwZQ0EgZGUgQ2VydGlmaWNhZG9zIFNTT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----
16 changes: 16 additions & 0 deletions ca/ca.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Package ca is used to provide the root certificates used by the TicketBAI
// services. Certificates where sourced from:
//
// - https://www.izenpe.eus/descarga-de-certificados/webize01-cndoctecnica/es/
//
// And converted to PEM format:
//
// openssl x509 -in AAPPNR_cert_sha256.crt -outform PEM -out AAPPNR_cert_sha256.pem
package ca

import "embed"

//go:embed *.pem

// Content contains the root certificates used by the TicketBAI services.
var Content embed.FS
2 changes: 0 additions & 2 deletions internal/gateways/araba.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func newAraba(env Environment, tlsConfig *tls.Config) *ArabaConn {
c.client.SetBaseURL(arabaTestingBaseURL)
}

tlsConfig.InsecureSkipVerify = true
tlsConfig.Renegotiation = tls.RenegotiateOnceAsClient
c.client.SetTLSClientConfig(tlsConfig)
c.client.SetDebug(os.Getenv("DEBUG") == "true")

Check failure on line 69 in internal/gateways/araba.go

View workflow job for this annotation

GitHub Actions / golangci-lint

string `true` has 3 occurrences, make it a constant (goconst)

Expand Down
1 change: 0 additions & 1 deletion internal/gateways/ebizkaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func newEbizkaia(env Environment, tlsConfig *tls.Config) *EBizkaiaConn {
c.client.SetBaseURL(eBizkaiaTestingBaseURL)
}

tlsConfig.InsecureSkipVerify = true
c.client.SetTLSClientConfig(tlsConfig)
c.client.SetDebug(os.Getenv("DEBUG") == "true")

Expand Down
27 changes: 27 additions & 0 deletions internal/gateways/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ package gateways

import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"strings"

"github.com/invopop/gobl.ticketbai/ca"
"github.com/invopop/gobl.ticketbai/doc"
"github.com/invopop/gobl/l10n"
"github.com/invopop/xmldsig"
Expand Down Expand Up @@ -121,6 +124,14 @@ func New(env Environment, zone l10n.Code, cert *xmldsig.Certificate) (Connection
return nil, fmt.Errorf("preparing TLS config: %w", err)
}

certs, err := rootCAPool()
if err != nil {
return nil, fmt.Errorf("preparing cert pool: %w", err)
}

tlsConf.RootCAs = certs
tlsConf.Renegotiation = tls.RenegotiateOnceAsClient

switch zone {
case doc.ZoneBI:
return newEbizkaia(env, tlsConf), nil
Expand All @@ -132,3 +143,19 @@ func New(env Environment, zone l10n.Code, cert *xmldsig.Certificate) (Connection

return nil, fmt.Errorf("zone %s not supported", zone)
}

func rootCAPool() (*x509.CertPool, error) {
certs := x509.NewCertPool()
files, err := ca.Content.ReadDir(".")
if err != nil {
return nil, err
}
for _, f := range files {
data, err := ca.Content.ReadFile(f.Name())
if err != nil {
return nil, err
}
certs.AppendCertsFromPEM(data)
}
return certs, nil
}
2 changes: 0 additions & 2 deletions internal/gateways/gipuzkoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func newGipuzkoa(env Environment, tlsConfig *tls.Config) *GipuzkoaConn {
c.client.SetBaseURL(gipuzkoaTestingBaseURL)
}

tlsConfig.InsecureSkipVerify = true
tlsConfig.Renegotiation = tls.RenegotiateOnceAsClient
c.client.SetTLSClientConfig(tlsConfig)
c.client.SetDebug(os.Getenv("DEBUG") == "true")

Expand Down
14 changes: 4 additions & 10 deletions ticketbai.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,13 @@ func WithCurrentTime(curTime time.Time) Option {
}
}

/*
// WithGateway defines a new gateway connection to use for a specific zone. This
// option can be used multiple times to define multiple gateways. Useful for
// testing.
func WithGateway(code l10n.Code, conn gateways.Connection) Option {
// WithConenction defines a new gateway connection to use for the client.

Check failure on line 53 in ticketbai.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exported: comment on exported function WithConnection should be of the form "WithConnection ..." (revive)
// Useful for testing and mocking the connection responses.
func WithConnection(conn gateways.Connection) Option {
return func(c *Client) {
if c.list == nil {
c.list = new(gateways.List)
}
c.list.Register(code, conn)
c.gw = conn
}
}
*/

// WithSupplierIssuer set the issuer type to supplier. To be used when the
// invoice's supplier, using their own certificate, is issuing the document.
Expand Down

0 comments on commit ee4f98e

Please sign in to comment.