Skip to content

Commit

Permalink
Rename var KeyRing to Keyring.
Browse files Browse the repository at this point in the history
Move __VERSION__ from entity Bank to entity Keyring.
Store version in keyring-file.
  • Loading branch information
andrew-svirin committed May 9, 2024
1 parent 6749bb7 commit 468e44a
Show file tree
Hide file tree
Showing 50 changed files with 702 additions and 675 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.2
* Change signature for KeyringManagerInterface. Moved version from Bank to Keyring.
* Remove UTF-8 encoding for content.
* Support EBICS TS mode.
* Add 'xml_files' parser for order data.
* Added support for EBICS version 2.4.

## 2.1

* Up supported PHP version to >= 7.4
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ use AndrewSvirin\Ebics\EbicsClient;

// Prepare `workspace` dir in the __PATH_TO_WORKSPACES_DIR__ manually.
$keyringRealPath = __PATH_TO_WORKSPACES_DIR__ . '/workspace/keyring.json';
// Use __IS_CERTIFIED__ true for French banks, otherwise use false.
$keyringManager = new FileKeyRingManager();
$keyring = $keyringManager->loadKeyRing($keyringRealPath, __PASSWORD__);
$bank = new Bank(__HOST_ID__, __HOST_URL__, __EBICS_SERVER_VERSION___);
// Use __IS_CERTIFIED__ true for EBICS 3.0 and/or French banks, otherwise use false.
$keyringManager = new FileKeyringManager();
$keyring = $keyringManager->loadKeyring($keyringRealPath, __PASSWORD__, __EBICS_VERSION__);
$bank = new Bank(__HOST_ID__, __HOST_URL__);
$bank->setIsCertified(__IS_CERTIFIED__);
$user = new User(__PARTNER_ID__, __USER_ID__);
$client = new EbicsClient($bank, $user, $keyring);
Expand Down Expand Up @@ -101,8 +101,8 @@ use AndrewSvirin\Ebics\Contracts\EbicsResponseExceptionInterface;
try {
$client->INI();
/* @var \AndrewSvirin\Ebics\Services\FileKeyringManager $keyringManager */
/* @var \AndrewSvirin\Ebics\Models\KeyRing $keyring */
$keyringManager->saveKeyRing($keyring, $keyringRealPath);
/* @var \AndrewSvirin\Ebics\Models\Keyring $keyring */
$keyringManager->saveKeyring($keyring, $keyringRealPath);
} catch (EbicsResponseExceptionInterface $exception) {
echo sprintf(
"INI request failed. EBICS Error code : %s\nMessage : %s\nMeaning : %s",
Expand All @@ -114,7 +114,7 @@ try {

try {
$client->HIA();
$keyringManager->saveKeyRing($keyring, $keyringRealPath);
$keyringManager->saveKeyring($keyring, $keyringRealPath);
} catch (EbicsResponseExceptionInterface $exception) {
echo sprintf(
"HIA request failed. EBICS Error code : %s\nMessage : %s\nMeaning : %s",
Expand All @@ -134,7 +134,7 @@ $ebicsBankLetter = new \AndrewSvirin\Ebics\EbicsBankLetter();
$bankLetter = $ebicsBankLetter->prepareBankLetter(
$client->getBank(),
$client->getUser(),
$client->getKeyRing()
$client->getKeyring()
);

$pdf = $ebicsBankLetter->formatBankLetter($bankLetter, $ebicsBankLetter->createPdfBankLetterFormatter());
Expand All @@ -150,8 +150,8 @@ try {
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
$client->HPB();
/* @var \AndrewSvirin\Ebics\Services\FileKeyringManager $keyringManager */
/* @var \AndrewSvirin\Ebics\Models\KeyRing $keyring */
$keyringManager->saveKeyRing($keyring, $keyringRealPath);
/* @var \AndrewSvirin\Ebics\Models\Keyring $keyring */
$keyringManager->saveKeyring($keyring, $keyringRealPath);
} catch (EbicsResponseExceptionInterface $exception) {
echo sprintf(
"HPB request failed. EBICS Error code : %s\nMessage : %s\nMeaning : %s",
Expand Down
14 changes: 7 additions & 7 deletions src/Builders/Request/DataEncryptionInfoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace AndrewSvirin\Ebics\Builders\Request;

use AndrewSvirin\Ebics\Exceptions\SignatureEbicsException;
use AndrewSvirin\Ebics\Models\KeyRing;
use AndrewSvirin\Ebics\Models\Keyring;
use AndrewSvirin\Ebics\Services\CryptService;
use DOMDocument;
use DOMElement;
Expand Down Expand Up @@ -42,22 +42,22 @@ public function createInstance(): DataEncryptionInfoBuilder
/**
* Uses bank signature.
*
* @param KeyRing $keyRing
* @param Keyring $keyring
* @param string $algorithm
*
* @return $this
* @throws SignatureEbicsException
*/
public function addEncryptionPubKeyDigest(KeyRing $keyRing, string $algorithm = 'sha256'): DataEncryptionInfoBuilder
public function addEncryptionPubKeyDigest(Keyring $keyring, string $algorithm = 'sha256'): DataEncryptionInfoBuilder
{
if (!($signatureE = $keyRing->getBankSignatureE())) {
if (!($signatureE = $keyring->getBankSignatureE())) {
throw new SignatureEbicsException('Bank Certificate E is empty.');
}
$certificateEDigest = $this->cryptService->calculateDigest($signatureE, $algorithm);
$encryptionPubKeyDigestNodeValue = base64_encode($certificateEDigest);

$xmlEncryptionPubKeyDigest = $this->dom->createElement('EncryptionPubKeyDigest');
$xmlEncryptionPubKeyDigest->setAttribute('Version', $keyRing->getBankSignatureEVersion());
$xmlEncryptionPubKeyDigest->setAttribute('Version', $keyring->getBankSignatureEVersion());
$xmlEncryptionPubKeyDigest->setAttribute(
'Algorithm',
sprintf('http://www.w3.org/2001/04/xmlenc#%s', $algorithm)
Expand All @@ -68,10 +68,10 @@ public function addEncryptionPubKeyDigest(KeyRing $keyRing, string $algorithm =
return $this;
}

public function addTransactionKey(string $transactionKey, KeyRing $keyRing): DataEncryptionInfoBuilder
public function addTransactionKey(string $transactionKey, Keyring $keyring): DataEncryptionInfoBuilder
{
$transactionKeyEncrypted = $this->cryptService->encryptTransactionKey(
$keyRing->getBankSignatureE()->getPublicKey(),
$keyring->getBankSignatureE()->getPublicKey(),
$transactionKey
);
$transactionKeyNodeValue = base64_encode($transactionKeyEncrypted);
Expand Down
12 changes: 6 additions & 6 deletions src/Contexts/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use AndrewSvirin\Ebics\Contracts\SignatureDataInterface;
use AndrewSvirin\Ebics\Models\Bank;
use AndrewSvirin\Ebics\Models\KeyRing;
use AndrewSvirin\Ebics\Models\Keyring;
use AndrewSvirin\Ebics\Models\User;
use DateTimeInterface;

Expand All @@ -18,7 +18,7 @@ final class RequestContext
{
private Bank $bank;
private User $user;
private KeyRing $keyRing;
private Keyring $keyring;
private DateTimeInterface $dateTime;
private ?DateTimeInterface $startDateTime;
private ?DateTimeInterface $endDateTime;
Expand Down Expand Up @@ -65,16 +65,16 @@ public function getUser(): User
return $this->user;
}

public function setKeyRing(KeyRing $keyRing): RequestContext
public function setKeyring(Keyring $keyring): RequestContext
{
$this->keyRing = $keyRing;
$this->keyring = $keyring;

return $this;
}

public function getKeyRing(): KeyRing
public function getKeyring(): Keyring
{
return $this->keyRing;
return $this->keyring;
}

public function setDateTime(DateTimeInterface $dateTime): RequestContext
Expand Down
8 changes: 4 additions & 4 deletions src/Contracts/EbicsClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function HEV(): Response;
/**
* Make INI request.
* Send to the bank public signature of signature A00X.
* Prepare A00X signature for KeyRing.
* Prepare A00X signature for Keyring.
*
* @param DateTimeInterface|null $dateTime current date
*
Expand All @@ -49,7 +49,7 @@ public function INI(DateTimeInterface $dateTime = null): Response;
/**
* Make HIA request.
* Send to the bank public signatures of authentication (X002) and encryption (E002).
* Prepare E002 and X002 user signatures for KeyRing.
* Prepare E002 and X002 user signatures for Keyring.
*
* @param DateTimeInterface|null $dateTime current date
*
Expand All @@ -60,7 +60,7 @@ public function HIA(DateTimeInterface $dateTime = null): Response;
/**
* Make H3K request.
* Send to the bank public signatures of signature (A00X), authentication (X002) and encryption (E002).
* Prepare A00X, E002 and X002 user signatures for KeyRing.
* Prepare A00X, E002 and X002 user signatures for Keyring.
*
* @param DateTimeInterface|null $dateTime current date
*
Expand All @@ -72,7 +72,7 @@ public function H3K(DateTimeInterface $dateTime = null): Response;

/**
* Download the Bank public signatures authentication (X002) and encryption (E002).
* Prepare E002 and X002 bank signatures for KeyRing.
* Prepare E002 and X002 bank signatures for Keyring.
*
* @param DateTimeInterface|null $dateTime current date
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

namespace AndrewSvirin\Ebics\Contracts;

use AndrewSvirin\Ebics\Models\KeyRing;
use AndrewSvirin\Ebics\Models\Keyring;

/**
* EBICS KeyRingManager representation.
* EBICS KeyringManager representation.
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Andrew Svirin
*/
interface KeyRingManagerInterface
interface KeyringManagerInterface
{
/**
* Load Keyring from the saved file or create new one.
* @param array|string $resource Array with key or filepath to key.
* @param string $passphrase Passphrase.
* @param string $defaultVersion Default keyring version.
*/
public function loadKeyRing($resource, string $passphrase): KeyRing;
public function loadKeyring($resource, string $passphrase, string $defaultVersion = Keyring::VERSION_25): Keyring;

/**
* Save KeyRing to file.
* @param KeyRing $keyRing Array with key or filepath to key.
* Save Keyring to file.
* @param Keyring $keyring Array with key or filepath to key.
* @param array|string $resource Array with key or filepath to key.
*/
public function saveKeyRing(KeyRing $keyRing, &$resource): void;
public function saveKeyring(Keyring $keyring, &$resource): void;
}
24 changes: 12 additions & 12 deletions src/EbicsBankLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use AndrewSvirin\Ebics\Factories\BankLetterFactory;
use AndrewSvirin\Ebics\Models\Bank;
use AndrewSvirin\Ebics\Models\BankLetter;
use AndrewSvirin\Ebics\Models\KeyRing;
use AndrewSvirin\Ebics\Models\Keyring;
use AndrewSvirin\Ebics\Models\User;
use AndrewSvirin\Ebics\Services\BankLetter\Formatter\HtmlBankLetterFormatter;
use AndrewSvirin\Ebics\Services\BankLetter\Formatter\PdfBankLetterFormatter;
Expand Down Expand Up @@ -42,19 +42,19 @@ public function __construct()
*
* @param Bank $bank
* @param User $user
* @param KeyRing $keyRing
* @param Keyring $keyring
*
* @return BankLetter
*/
public function prepareBankLetter(Bank $bank, User $user, KeyRing $keyRing): BankLetter
public function prepareBankLetter(Bank $bank, User $user, Keyring $keyring): BankLetter
{
if ($bank->isCertified()) {
if (Bank::VERSION_25 === $bank->getVersion()) {
if (Keyring::VERSION_25 === $keyring->getVersion()) {
$digestResolver = new DigestResolverV2();
} elseif (Bank::VERSION_30 === $bank->getVersion()) {
} elseif (Keyring::VERSION_30 === $keyring->getVersion()) {
$digestResolver = new DigestResolverV3();
} else {
throw new LogicException(sprintf('Version "%s" is not implemented', $bank->getVersion()));
throw new LogicException(sprintf('Version "%s" is not implemented', $keyring->getVersion()));
}
$hashGenerator = new CertificateHashGenerator($digestResolver);
} else {
Expand All @@ -65,18 +65,18 @@ public function prepareBankLetter(Bank $bank, User $user, KeyRing $keyRing): Ban
$bank,
$user,
$this->bankLetterService->formatSignatureForBankLetter(
$keyRing->getUserSignatureA(),
$keyRing->getUserSignatureAVersion(),
$keyring->getUserSignatureA(),
$keyring->getUserSignatureAVersion(),
$hashGenerator
),
$this->bankLetterService->formatSignatureForBankLetter(
$keyRing->getUserSignatureE(),
$keyRing->getUserSignatureEVersion(),
$keyring->getUserSignatureE(),
$keyring->getUserSignatureEVersion(),
$hashGenerator
),
$this->bankLetterService->formatSignatureForBankLetter(
$keyRing->getUserSignatureX(),
$keyRing->getUserSignatureXVersion(),
$keyring->getUserSignatureX(),
$keyring->getUserSignatureXVersion(),
$hashGenerator
)
);
Expand Down
Loading

0 comments on commit 468e44a

Please sign in to comment.