| 1 | package dialog |
| 2 | |
| 3 | import ( |
| 4 | "encoding/base64" |
| 5 | |
| 6 | "github.com/mitch000001/go-hbci/domain" |
| 7 | "github.com/mitch000001/go-hbci/internal" |
| 8 | "github.com/mitch000001/go-hbci/message" |
| 9 | "github.com/mitch000001/go-hbci/segment" |
| 10 | "github.com/mitch000001/go-hbci/transport" |
| 11 | https "github.com/mitch000001/go-hbci/transport/https" |
| 12 | middleware "github.com/mitch000001/go-hbci/transport/middleware" |
| 13 | ) |
| 14 | |
| 15 | // Config contains the configuration of a PinTanDialog |
| 16 | type Config struct { |
| 17 | BankID domain.BankID |
| 18 | HBCIURL string |
| 19 | UserID string |
| 20 | HBCIVersion segment.HBCIVersion |
| 21 | Transport transport.Transport |
| 22 | } |
| 23 | |
| 24 | // NewPinTanDialog creates a new dialog to use for pin/tan transport |
| 25 | func NewPinTanDialog(config Config) *PinTanDialog { |
| 26 | pinKey := domain.NewPinKey("", domain.NewPinTanKeyName(config.BankID, config.UserID, domain.KeyTypeSigning)) |
| 27 | signatureProvider := message.NewPinTanSignatureProvider(pinKey, initialClientSystemID) |
| 28 | pinKey = domain.NewPinKey("", domain.NewPinTanKeyName(config.BankID, config.UserID, domain.KeyTypeEncryption)) |
| 29 | cryptoProvider := message.NewPinTanCryptoProvider(pinKey, initialClientSystemID) |
| 30 | d := &PinTanDialog{ |
| 31 | dialog: newDialog( |
| 32 | config.BankID, |
| 33 | config.HBCIURL, |
| 34 | config.UserID, |
| 35 | config.HBCIVersion, |
| 36 | signatureProvider, |
| 37 | cryptoProvider, |
| 38 | ), |
| 39 | } |
| 40 | |
| 41 | var dialogTransport transport.Transport |
| 42 | if config.Transport == nil { |
| 43 | dialogTransport = https.New() |
| 44 | } else { |
| 45 | dialogTransport = config.Transport |
| 46 | } |
| 47 | dialogTransport = middleware.Base64Encoding(base64.StdEncoding)(dialogTransport) |
| 48 | dialogTransport = middleware.Logging(internal.Debug, cryptoProvider)(dialogTransport) |
| 49 | d.transport = dialogTransport |
| 50 | return d |
| 51 | } |
| 52 | |
| 53 | // PinTanDialog represents a dialog to use in pin/tan flow with HTTPS transport |
| 54 | type PinTanDialog struct { |
| 55 | *dialog |
| 56 | } |
| 57 | |
| 58 | // SetPin lets the user reset the pin after creation |
| 59 | func (d *PinTanDialog) SetPin(pin string) { |
| 60 | pinKey := domain.NewPinKey(pin, domain.NewPinTanKeyName(d.BankID, d.UserID, domain.KeyTypeSigning)) |
| 61 | d.signatureProvider = message.NewPinTanSignatureProvider(pinKey, d.ClientSystemID) |
| 62 | pinKey = domain.NewPinKey(pin, domain.NewPinTanKeyName(d.BankID, d.UserID, domain.KeyTypeEncryption)) |
| 63 | d.cryptoProvider = message.NewPinTanCryptoProvider(pinKey, d.ClientSystemID) |
| 64 | } |