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
|
package dialog
import (
"encoding/base64"
"github.com/mitch000001/go-hbci/domain"
"github.com/mitch000001/go-hbci/internal"
"github.com/mitch000001/go-hbci/message"
"github.com/mitch000001/go-hbci/segment"
"github.com/mitch000001/go-hbci/transport"
https "github.com/mitch000001/go-hbci/transport/https"
middleware "github.com/mitch000001/go-hbci/transport/middleware"
)
// Config contains the configuration of a PinTanDialog
type Config struct {
BankID domain.BankID
HBCIURL string
UserID string
HBCIVersion segment.HBCIVersion
Transport transport.Transport
}
// NewPinTanDialog creates a new dialog to use for pin/tan transport
func NewPinTanDialog(config Config) *PinTanDialog {
pinKey := domain.NewPinKey("", domain.NewPinTanKeyName(config.BankID, config.UserID, domain.KeyTypeSigning))
signatureProvider := message.NewPinTanSignatureProvider(pinKey, initialClientSystemID)
pinKey = domain.NewPinKey("", domain.NewPinTanKeyName(config.BankID, config.UserID, domain.KeyTypeEncryption))
cryptoProvider := message.NewPinTanCryptoProvider(pinKey, initialClientSystemID)
d := &PinTanDialog{
dialog: newDialog(
config.BankID,
config.HBCIURL,
config.UserID,
config.HBCIVersion,
signatureProvider,
cryptoProvider,
),
}
var dialogTransport transport.Transport
if config.Transport == nil {
dialogTransport = https.New()
} else {
dialogTransport = config.Transport
}
dialogTransport = middleware.Base64Encoding(base64.StdEncoding)(dialogTransport)
dialogTransport = middleware.Logging(internal.Debug, cryptoProvider)(dialogTransport)
d.transport = dialogTransport
return d
}
// PinTanDialog represents a dialog to use in pin/tan flow with HTTPS transport
type PinTanDialog struct {
*dialog
}
// SetPin lets the user reset the pin after creation
func (d *PinTanDialog) SetPin(pin string) {
pinKey := domain.NewPinKey(pin, domain.NewPinTanKeyName(d.BankID, d.UserID, domain.KeyTypeSigning))
d.signatureProvider = message.NewPinTanSignatureProvider(pinKey, d.ClientSystemID)
pinKey = domain.NewPinKey(pin, domain.NewPinTanKeyName(d.BankID, d.UserID, domain.KeyTypeEncryption))
d.cryptoProvider = message.NewPinTanCryptoProvider(pinKey, d.ClientSystemID)
}
|