Skip to content

Commit 07cec9f

Browse files
committed
WIP
1 parent 2725b3d commit 07cec9f

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ the following parameters configured:
7878
> [!NOTE]
7979
> The module has been tested with and supports SQLite, PostgreSQL, and MySQL databases.
8080
81-
### Create Protocol / Federation RSA key pairs
81+
### Create Protocol / Federation pairs
8282

8383
During the authentication flow, the generated ID Token and Access Token will be in the form of signed JSON Web Tokens (JWS).
8484
For signing these tokens, you need to create a public/private RSA key pair, referred to as "OIDC protocol" keys.
8585

8686
If you plan to use OpenID Federation capabilities, you should create a separate key pair dedicated to OpenID Federation
8787
operations, such as signing Entity Statement JWS.
8888

89+
#### RSA key pair generation
8990
Below are sample commands to create key pairs with default file names for both "protocol" and "federation" purposes:
9091

9192
To generate the private keys without a passphrase:
@@ -112,6 +113,37 @@ With passphrase:
112113

113114
If you use different file names or a passphrase, be sure to update these settings in the `module_oidc.php` configuration file.
114115

116+
#### EC key pair generation
117+
118+
If you prefer to use Elliptic Curve Cryptography (ECC) instead of RSA, you can generate the key pair using the
119+
following commands:
120+
121+
To generate the private keys without a passphrase:
122+
123+
openssl ecparam -name prime256v1 -genkey -noout -out cert/oidc_module.key
124+
openssl ecparam -name prime256v1 -genkey -noout -out cert/oidc_module_federation.key
125+
126+
To generate the private keys with a passphrase:
127+
128+
openssl ecparam -genkey -name secp384r1 -noout -out cert/oidc_module.key -passout pass:myPassPhrase
129+
openssl ecparam -genkey -name secp384r1 -noout -out cert/oidc_module_federation.key -passout pass:myPassPhrase
130+
131+
Next, extract the public key from each private key:
132+
133+
Without passphrase:
134+
135+
openssl ec -in cert/oidc_module.key -pubout -out cert/oidc_module.crt
136+
openssl ec -in cert/oidc_module_federation.key -pubout -out cert/oidc_module_federation.crt
137+
138+
With passphrase:
139+
140+
openssl ec -in cert/oidc_module.key -passin pass:myPassPhrase -pubout -out cert/oidc_module.crt
141+
openssl ec -in cert/oidc_module.key -passin pass:myPassPhrase -pubout -out cert/oidc_module.crt
142+
143+
If you use different file names or a passphrase, be sure to update these settings in the `module_oidc.php`
144+
configuration file.
145+
146+
115147
### Enabling the module
116148

117149
To enable the module, add `'oidc' => true` to the list of enabled modules in the main SimpleSAMLphp

src/Controllers/VerifiableCredentials/CredentialIssuerCredentialController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function credential(Request $request): Response
7272

7373
$verifiableCredential = $this->verifiableCredentials->jwtVcJsonFactory()->fromData(
7474
$jwk,
75-
SignatureAlgorithmEnum::RS256,
75+
SignatureAlgorithmEnum::from($this->moduleConfig->getProtocolSigner()->algorithmId()),
7676
[
7777
ClaimsEnum::Vc->value => [
7878
ClaimsEnum::AtContext->value => [

src/Server/Validators/BearerTokenValidator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
1919
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface as OAuth2AccessTokenRepositoryInterface;
2020
use Psr\Http\Message\ServerRequestInterface;
21+
use SimpleSAML\Module\oidc\ModuleConfig;
2122
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
2223
use SimpleSAML\Module\oidc\Services\LoggerService;
2324

@@ -44,6 +45,7 @@ class BearerTokenValidator extends OAuth2BearerTokenValidator
4445
public function __construct(
4546
AccessTokenRepositoryInterface $accessTokenRepository,
4647
CryptKey $publicKey,
48+
protected readonly ModuleConfig $moduleConfig,
4749
?DateInterval $jwtValidAtDateLeeway = null,
4850
protected LoggerService $loggerService = new LoggerService(),
4951
) {
@@ -72,15 +74,15 @@ public function setPublicKey(CryptKey $key): void
7274
protected function initJwtConfiguration(): void
7375
{
7476
$this->jwtConfiguration = Configuration::forSymmetricSigner(
75-
new Sha256(),
77+
$this->moduleConfig->getProtocolSigner(),
7678
InMemory::plainText('empty', 'empty'),
7779
);
7880

7981
/** @psalm-suppress DeprecatedMethod, ArgumentTypeCoercion */
8082
$this->jwtConfiguration->setValidationConstraints(
8183
new StrictValidAt(new SystemClock(new DateTimeZone(date_default_timezone_get()))),
8284
new SignedWith(
83-
new Sha256(),
85+
$this->moduleConfig->getProtocolSigner(),
8486
InMemory::plainText($this->publicKey->getKeyContents(), $this->publicKey->getPassPhrase() ?? ''),
8587
),
8688
);

0 commit comments

Comments
 (0)