Skip to content

Commit 4a96fc2

Browse files
committed
Changed options for createUserSignatures.
1 parent 91876ae commit 4a96fc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+735
-270
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.5
2+
3+
* Changed `options` for `createUserSignatures`.
4+
15
## 2.4
26

37
* Fixed HVE order type.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use EbicsApi\Ebics\Models\X509\BankX509Generator;
5757
// Prepare `workspace` dir in the __PATH_TO_WORKSPACES_DIR__ manually.
5858
// "__EBICS_VERSION__" should have value "VERSION_30" for EBICS 3.0
5959
$keyringPath = __PATH_TO_WORKSPACES_DIR__ . '/workspace/keyring.json';
60-
$keyringManager = new FileKeyringManager(new KeyringFactory);
60+
$keyringManager = new FileKeyringManager();
6161
if (is_file($keyringPath)) {
6262
$keyring = $keyringManager->loadKeyring($keyringPath, __PASSWORD__, __EBICS_VERSION__);
6363
} else {

src/Builders/CustomerCreditTransfer/CustomerCreditTransferBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function createCreditTransferTransactionElement(
219219
$xmlEndToEndId->nodeValue = $endToEndId;
220220
} else {
221221
$xmlEndToEndId->nodeValue = $this->randomService->uniqueIdWithDate(
222-
'pete'.str_pad((string)$nbOfTxs, 2, '0')
222+
'pete' . str_pad((string)$nbOfTxs, 2, '0')
223223
);
224224
}
225225
$xmlPmtId->appendChild($xmlEndToEndId);
@@ -246,7 +246,7 @@ private function createCreditTransferTransactionElement(
246246
//update PmtInf
247247
$nbOfTxsList = $xpath->query('//CstmrCdtTrfInitn/PmtInf/NbOfTxs');
248248
$xmlNbOfTxs = DOMHelper::safeItem($nbOfTxsList);
249-
$xmlNbOfTxs->nodeValue = (string) $nbOfTxs;
249+
$xmlNbOfTxs->nodeValue = (string)$nbOfTxs;
250250

251251
$ctrlSumList = $xpath->query('//CstmrCdtTrfInitn/PmtInf/CtrlSum');
252252
$xmlCtrlSum = DOMHelper::safeItem($ctrlSumList);

src/Builders/CustomerDirectDebit/CustomerDirectDebitBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function addTransaction(
252252
$xmlEndToEndId->nodeValue = $endToEndId;
253253
} else {
254254
$xmlEndToEndId->nodeValue = $this->randomService->uniqueIdWithDate(
255-
'pete'.str_pad((string)$nbOfTxs, 2, '0')
255+
'pete' . str_pad((string)$nbOfTxs, 2, '0')
256256
);
257257
}
258258

src/Contracts/EbicsClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface EbicsClientInterface
3535

3636
/**
3737
* Create user signatures A, E and X on first launch.
38-
* @param array|null $options Setup to specify custom certificate, private_key and version
38+
* @param array|null $options Setup to specify custom certificate, private, public keys and version
3939
* for Electronic Signature, Authorization and Identification, Encryption details.
4040
*/
4141
public function createUserSignatures(?array $options = null): void;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace EbicsApi\Ebics\Contracts;
4+
5+
use EbicsApi\Ebics\Models\Crypt\Key;
6+
7+
/**
8+
* KeyStorageInterface.
9+
*
10+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
11+
* @author Andrew Svirin
12+
*/
13+
interface KeyStorageInterface
14+
{
15+
/**
16+
* Write public key to storage.
17+
*
18+
* @param Key $key
19+
*
20+
* @return string
21+
*/
22+
public function writePublicKey(Key $key): string;
23+
24+
/**
25+
* Read public key from storage.
26+
*
27+
* @param string $key
28+
*
29+
* @return Key
30+
*/
31+
public function readPublicKey(string $key): Key;
32+
33+
/**
34+
* Write private key to storage.
35+
*
36+
* @param Key $key
37+
*
38+
* @return string
39+
*/
40+
public function writePrivateKey(Key $key): string;
41+
42+
/**
43+
* Read private key from storage.
44+
*
45+
* @param string $key
46+
*
47+
* @return Key
48+
*/
49+
public function readPrivateKey(string $key): Key;
50+
51+
/**
52+
* Write certificate to storage.
53+
*
54+
* @param string $certificate
55+
*
56+
* @return string
57+
*/
58+
public function writeCertificate(string $certificate): string;
59+
60+
/**
61+
* Read certificate from storage.
62+
*
63+
* @param string $certificate
64+
*
65+
* @return string
66+
*/
67+
public function readCertificate(string $certificate): string;
68+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace EbicsApi\Ebics\Contracts;
4+
5+
/**
6+
* KeyStorageLocatorInterface.
7+
*
8+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
9+
* @author Andrew Svirin
10+
*/
11+
interface KeyStorageLocatorInterface
12+
{
13+
public const LOCATE_STRING = 'string';
14+
15+
/**
16+
* Find appropriate key storage.
17+
*
18+
* @param mixed|string $value
19+
*
20+
* @return KeyStorageInterface
21+
*/
22+
public function locate($value): KeyStorageInterface;
23+
24+
/**
25+
* Get key storage.
26+
*
27+
* @param string $key
28+
*
29+
* @return KeyStorageInterface
30+
*/
31+
public function get(string $key): KeyStorageInterface;
32+
}

src/Contracts/SignatureInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace EbicsApi\Ebics\Contracts;
44

5+
use EbicsApi\Ebics\Models\Crypt\Key;
6+
57
/**
68
* EBICS SignatureInterface representation.
79
*
@@ -26,14 +28,14 @@ interface SignatureInterface
2628
public function getType(): string;
2729

2830
/**
29-
* @return string
31+
* @return Key
3032
*/
31-
public function getPublicKey(): string;
33+
public function getPublicKey(): Key;
3234

3335
/**
34-
* @return string|null
36+
* @return Key|null
3537
*/
36-
public function getPrivateKey(): ?string;
38+
public function getPrivateKey(): ?Key;
3739

3840
/**
3941
* @param string|null $certificateContent

src/EbicsBankLetter.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use EbicsApi\Ebics\Contracts\BankLetter\FormatterInterface;
66
use EbicsApi\Ebics\Factories\BankLetterFactory;
77
use EbicsApi\Ebics\Factories\CertificateX509Factory;
8+
use EbicsApi\Ebics\Factories\Crypt\AESFactory;
9+
use EbicsApi\Ebics\Factories\Crypt\RSAFactory;
810
use EbicsApi\Ebics\Factories\EbicsFactoryV24;
911
use EbicsApi\Ebics\Factories\EbicsFactoryV25;
1012
use EbicsApi\Ebics\Factories\EbicsFactoryV30;
@@ -18,6 +20,8 @@
1820
use EbicsApi\Ebics\Services\BankLetter\Formatter\TxtBankLetterFormatter;
1921
use EbicsApi\Ebics\Services\BankLetterService;
2022
use EbicsApi\Ebics\Services\CryptService;
23+
use EbicsApi\Ebics\Services\KeyStorageLocator;
24+
use EbicsApi\Ebics\Services\RandomService;
2125
use LogicException;
2226

2327
/**
@@ -33,9 +37,13 @@ final class EbicsBankLetter
3337
private BankLetterFactory $bankLetterFactory;
3438
private CryptService $cryptService;
3539

36-
public function __construct()
40+
public function __construct(array $options = [])
3741
{
38-
$this->cryptService = new CryptService();
42+
$this->cryptService = new CryptService(
43+
new RSAFactory($options['rsa_class_map'] ?? null),
44+
new AESFactory(),
45+
new RandomService()
46+
);
3947
$this->bankLetterService = new BankLetterService(
4048
$this->cryptService,
4149
new SignatureBankLetterFactory(),

src/EbicsClient.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
use EbicsApi\Ebics\Exceptions\PasswordEbicsException;
2222
use EbicsApi\Ebics\Factories\BufferFactory;
2323
use EbicsApi\Ebics\Factories\CertificateX509Factory;
24+
use EbicsApi\Ebics\Factories\Crypt\AESFactory;
2425
use EbicsApi\Ebics\Factories\Crypt\BigIntegerFactory;
26+
use EbicsApi\Ebics\Factories\Crypt\RSAFactory;
2527
use EbicsApi\Ebics\Factories\DocumentFactory;
2628
use EbicsApi\Ebics\Factories\EbicsExceptionFactory;
2729
use EbicsApi\Ebics\Factories\EbicsFactoryV24;
@@ -35,6 +37,8 @@
3537
use EbicsApi\Ebics\Handlers\OrderDataHandler;
3638
use EbicsApi\Ebics\Handlers\ResponseHandler;
3739
use EbicsApi\Ebics\Models\Bank;
40+
use EbicsApi\Ebics\Models\Crypt\Key;
41+
use EbicsApi\Ebics\Models\Crypt\KeyPair;
3842
use EbicsApi\Ebics\Models\DownloadOrderResult;
3943
use EbicsApi\Ebics\Models\DownloadSegment;
4044
use EbicsApi\Ebics\Models\DownloadTransaction;
@@ -50,6 +54,8 @@
5054
use EbicsApi\Ebics\Models\X509\ContentX509Generator;
5155
use EbicsApi\Ebics\Services\CryptService;
5256
use EbicsApi\Ebics\Services\CurlHttpClient;
57+
use EbicsApi\Ebics\Services\KeyStorageLocator;
58+
use EbicsApi\Ebics\Services\RandomService;
5359
use EbicsApi\Ebics\Services\SchemaValidator;
5460
use EbicsApi\Ebics\Services\XmlService;
5561
use EbicsApi\Ebics\Services\ZipService;
@@ -104,10 +110,12 @@ public function __construct(Bank $bank, User $user, Keyring $keyring, array $opt
104110
throw new LogicException(sprintf('Version "%s" is not implemented', $keyring->getVersion()));
105111
}
106112

113+
$rsaFactory = new RSAFactory($options['rsa_class_map'] ?? null);
114+
107115
$this->segmentFactory = new SegmentFactory();
108-
$this->cryptService = new CryptService();
116+
$this->cryptService = new CryptService($rsaFactory, new AESFactory(), new RandomService());
109117
$this->zipService = new ZipService();
110-
$this->signatureFactory = new SignatureFactory();
118+
$this->signatureFactory = new SignatureFactory($rsaFactory);
111119
$this->bufferFactory = new BufferFactory($options['buffer_filename'] ?? 'php://memory');
112120

113121
$this->orderDataHandler = $ebicsFactory->createOrderDataHandler(
@@ -1330,10 +1338,9 @@ private function createUserSignature(string $type, ?array $details = null): Sign
13301338
$keyPair = $this->cryptService->generateKeyPair($this->keyring->getPassword());
13311339
$certificateGenerator = $this->keyring->getCertificateGenerator();
13321340
} else {
1333-
$keyPair = $this->cryptService->changePrivateKeyPassword(
1334-
$details['privatekey'],
1335-
$details['password'],
1336-
$this->keyring->getPassword()
1341+
$keyPair = new KeyPair(
1342+
new Key($details['publickey'], $details['publickey_type']),
1343+
new Key($details['privatekey'], $details['privatekey_type'])
13371344
);
13381345
$certificateGenerator = new ContentX509Generator();
13391346
$certificateGenerator->setAContent($details['certificate']);
@@ -1393,7 +1400,10 @@ public function checkKeyring(): bool
13931400
public function changeKeyringPassword(string $newPassword): void
13941401
{
13951402
$keyPair = $this->cryptService->changePrivateKeyPassword(
1396-
$this->keyring->getUserSignatureA()->getPrivateKey(),
1403+
new KeyPair(
1404+
$this->keyring->getUserSignatureA()->getPublicKey(),
1405+
$this->keyring->getUserSignatureA()->getPrivateKey()
1406+
),
13971407
$this->keyring->getPassword(),
13981408
$newPassword
13991409
);
@@ -1407,7 +1417,10 @@ public function changeKeyringPassword(string $newPassword): void
14071417
$this->keyring->setUserSignatureA($signature);
14081418

14091419
$keyPair = $this->cryptService->changePrivateKeyPassword(
1410-
$this->keyring->getUserSignatureX()->getPrivateKey(),
1420+
new KeyPair(
1421+
$this->keyring->getUserSignatureX()->getPublicKey(),
1422+
$this->keyring->getUserSignatureX()->getPrivateKey()
1423+
),
14111424
$this->keyring->getPassword(),
14121425
$newPassword
14131426
);
@@ -1421,7 +1434,10 @@ public function changeKeyringPassword(string $newPassword): void
14211434
$this->keyring->setUserSignatureX($signature);
14221435

14231436
$keyPair = $this->cryptService->changePrivateKeyPassword(
1424-
$this->keyring->getUserSignatureE()->getPrivateKey(),
1437+
new KeyPair(
1438+
$this->keyring->getUserSignatureE()->getPublicKey(),
1439+
$this->keyring->getUserSignatureE()->getPrivateKey()
1440+
),
14251441
$this->keyring->getPassword(),
14261442
$newPassword
14271443
);

0 commit comments

Comments
 (0)