Skip to content

Commit

Permalink
Make it possible to send the productName
Browse files Browse the repository at this point in the history
With PSD2 banks now require registration of programs (rather than libraries)
with "Die Deutsche Kreditwirtschaft" on https://www.hbci-zka.de. You are given
a key that needs to be passed in the product name field for access to be
granted. Everyone can apply for this key for their program.
  • Loading branch information
pkern committed Sep 19, 2019
1 parent 3cb5fbd commit 793edc6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
PIN string `json:"pin"`
URL string `json:"url"`
HBCIVersion int `json:"hbci_version"`
ProductName string `json:"product_name"`
Transport transport.Transport
}

Expand Down Expand Up @@ -71,6 +72,7 @@ func New(config Config) (*Client, error) {
HBCIURL: url,
UserID: config.AccountID,
HBCIVersion: hbciVersion,
ProductName: config.ProductName,
Transport: config.Transport,
}

Expand Down
9 changes: 6 additions & 3 deletions dialog/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func newDialog(
hbciURL string,
userID string,
hbciVersion segment.HBCIVersion,
productName string,
signatureProvider message.SignatureProvider,
cryptoProvider message.CryptoProvider,
) *dialog {
Expand All @@ -49,6 +50,7 @@ func newDialog(
cryptoProvider: cryptoProvider,
dialogID: initialDialogID,
hbciVersion: hbciVersion,
productName: productName,
}
}

Expand All @@ -69,6 +71,7 @@ type dialog struct {
cryptoProvider message.CryptoProvider
BankParameterData domain.BankParameterData
hbciVersion segment.HBCIVersion
productName string
supportedSegments []segment.VersionedSegment
}

Expand Down Expand Up @@ -134,7 +137,7 @@ func (d *dialog) SendMessage(clientMessage message.HBCIMessage) (message.BankMes
func (d *dialog) SyncClientSystemID() (string, error) {
syncMessage := message.NewSynchronisationMessage(d.hbciVersion)
syncMessage.Identification = segment.NewIdentificationSegment(d.BankID, d.clientID, initialClientSystemID, true)
syncMessage.ProcessingPreparation = segment.NewProcessingPreparationSegment(0, 0, 1)
syncMessage.ProcessingPreparation = segment.NewProcessingPreparationSegment(0, 0, 1, d.productName)
syncMessage.Sync = d.hbciVersion.SynchronisationRequest(segment.SyncModeAquireClientID)
syncMessage.BasicMessage = d.newBasicMessage(syncMessage)
signedSyncMessage, err := syncMessage.Sign(d.signatureProvider)
Expand Down Expand Up @@ -233,7 +236,7 @@ func (d *dialog) anonymousInit() error {
d.messageCount = 0
initMessage := message.NewDialogInitializationClientMessage(d.hbciVersion)
initMessage.Identification = segment.NewIdentificationSegment(d.BankID, anonymousClientID, initialClientSystemID, false)
initMessage.ProcessingPreparation = segment.NewProcessingPreparationSegment(d.BankParameterDataVersion(), d.UserParameterDataVersion(), d.Language)
initMessage.ProcessingPreparation = segment.NewProcessingPreparationSegment(d.BankParameterDataVersion(), d.UserParameterDataVersion(), d.Language, d.productName)
initMessage.BasicMessage = d.newBasicMessage(initMessage)
initMessage.SetNumbers()
bankMessage, err := d.request(initMessage)
Expand Down Expand Up @@ -314,7 +317,7 @@ func (d *dialog) init() error {
d.messageCount = 0
initMessage := message.NewDialogInitializationClientMessage(d.hbciVersion)
initMessage.Identification = segment.NewIdentificationSegment(d.BankID, d.clientID, d.ClientSystemID, true)
initMessage.ProcessingPreparation = segment.NewProcessingPreparationSegment(d.BankParameterDataVersion(), d.UserParameterDataVersion(), d.Language)
initMessage.ProcessingPreparation = segment.NewProcessingPreparationSegment(d.BankParameterDataVersion(), d.UserParameterDataVersion(), d.Language, d.productName)
initMessage.BasicMessage = d.newBasicMessage(initMessage)
signedInitMessage, err := initMessage.Sign(d.signatureProvider)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions dialog/pin_tan_dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Config struct {
HBCIURL string
UserID string
HBCIVersion segment.HBCIVersion
ProductName string
Transport transport.Transport
}

Expand All @@ -33,6 +34,7 @@ func NewPinTanDialog(config Config) *PinTanDialog {
config.HBCIURL,
config.UserID,
config.HBCIVersion,
config.ProductName,
signatureProvider,
cryptoProvider,
),
Expand Down
4 changes: 2 additions & 2 deletions dialog/rdh_dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

// NewRDHDialog creates a dialog to use with cardreader flow
func NewRDHDialog(bankID domain.BankID, hbciURL string, clientID string, hbciVersion segment.HBCIVersion) Dialog {
func NewRDHDialog(bankID domain.BankID, hbciURL string, clientID string, hbciVersion segment.HBCIVersion, productName string) Dialog {
key, err := domain.GenerateSigningKey()
if err != nil {
panic(err)
}
signingKey := domain.NewRSAKey(key, domain.NewInitialKeyName(bankID.CountryCode, bankID.ID, clientID, "S"))
provider := message.NewRDHSignatureProvider(signingKey, 12345)
d := &rdhDialog{
dialog: newDialog(bankID, hbciURL, clientID, hbciVersion, provider, nil),
dialog: newDialog(bankID, hbciURL, clientID, hbciVersion, productName, provider, nil),
}
return d
}
Expand Down
11 changes: 7 additions & 4 deletions segment/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/mitch000001/go-hbci/element"
)

const productName = "go-hbci library"
const productVersion = hbci.Version
const defaultProductName = "go-hbci library"
const defaultProductVersion = hbci.Version

func NewDialogEndSegment(dialogId string) *DialogEndSegment {
d := &DialogEndSegment{
Expand All @@ -33,13 +33,16 @@ func (d *DialogEndSegment) elements() []element.DataElement {
}
}

func NewProcessingPreparationSegment(bdpVersion int, udpVersion int, language domain.Language) *ProcessingPreparationSegment {
func NewProcessingPreparationSegment(bdpVersion int, udpVersion int, language domain.Language, productName string) *ProcessingPreparationSegment {
if productName == "" {
productName = defaultProductName
}
p := &ProcessingPreparationSegment{
BPDVersion: element.NewNumber(bdpVersion, 3),
UPDVersion: element.NewNumber(udpVersion, 3),
DialogLanguage: element.NewNumber(int(language), 3),
ProductName: element.NewAlphaNumeric(productName, 25),
ProductVersion: element.NewAlphaNumeric(productVersion, 5),
ProductVersion: element.NewAlphaNumeric(defaultProductVersion, 5),
}
p.ClientSegment = NewBasicSegment(4, p)
return p
Expand Down

0 comments on commit 793edc6

Please sign in to comment.