Skip to content

Commit 21dcdae

Browse files
committed
increase key lifetime to one hour, add comments on when/why we refresh
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 8a9fbbc commit 21dcdae

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/Service/JwkService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class JwkService {
2222

2323
public const PEM_SIG_KEY_SETTINGS_KEY = 'pemSignatureKey';
2424
public const PEM_SIG_KEY_EXPIRES_AT_SETTINGS_KEY = 'pemSignatureKeyExpiresAt';
25-
public const PEM_SIG_KEY_EXPIRES_IN_SECONDS = 60 * 2;
25+
public const PEM_SIG_KEY_EXPIRES_IN_SECONDS = 60 * 60;
2626

2727
public const PEM_ENC_KEY_SETTINGS_KEY = 'pemEncryptionKey';
2828
public const PEM_ENC_KEY_EXPIRES_AT_SETTINGS_KEY = 'pemEncryptionKeyExpiresAt';
29-
public const PEM_ENC_KEY_EXPIRES_IN_SECONDS = 60 * 2;
29+
public const PEM_ENC_KEY_EXPIRES_IN_SECONDS = 60 * 60;
3030

3131
public function __construct(
3232
private IAppConfig $appConfig,
@@ -105,6 +105,7 @@ public function generatePemPrivateKey(): string {
105105
* @throws AppConfigTypeConflictException
106106
*/
107107
public function getJwks(): array {
108+
// we don't refresh here to make sure the IdP will get the key that was used to sign the client assertion
108109
$myPemSignatureKey = $this->getMyPemSignatureKey(false);
109110
$sslSignatureKey = openssl_pkey_get_private($myPemSignatureKey);
110111
$sslSignatureKeyDetails = openssl_pkey_get_details($sslSignatureKey);
@@ -166,6 +167,7 @@ public function createJwt(array $payload, \OpenSSLAsymmetricKey $key, string $ke
166167
}
167168

168169
public function generateClientAssertion(Provider $provider, string $discoveryIssuer, ?string $code = null): string {
170+
// we refresh (if needed) here to make sure we use a key that will be served to the IdP in a few seconds
169171
$myPemPrivateKey = $this->getMyPemSignatureKey();
170172
$sslPrivateKey = openssl_pkey_get_private($myPemPrivateKey);
171173
$pemPrivateKeyExpiresAt = $this->appConfig->getAppValueInt(self::PEM_SIG_KEY_EXPIRES_AT_SETTINGS_KEY, lazy: true);

0 commit comments

Comments
 (0)