Skip to content

Commit b28f318

Browse files
committed
Bump the key size of RSA keys used to generate ephemeral keys and development certificates
1 parent 5c1cda0 commit b28f318

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/OpenIddict.Client/OpenIddictClientBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500Distingui
207207
if (!certificates.Exists(certificate => certificate.NotBefore < now.LocalDateTime && certificate.NotAfter > now.LocalDateTime))
208208
{
209209
#if SUPPORTS_CERTIFICATE_GENERATION
210-
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 2048);
210+
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 4096);
211211

212212
var request = new CertificateRequest(subject, algorithm, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
213213
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.KeyEncipherment, critical: true));
@@ -299,7 +299,7 @@ public OpenIddictClientBuilder AddEphemeralEncryptionKey(string algorithm)
299299
SecurityAlgorithms.RsaOAEP or
300300
SecurityAlgorithms.RsaOaepKeyWrap
301301
=> AddEncryptionCredentials(new EncryptingCredentials(
302-
new RsaSecurityKey(OpenIddictHelpers.CreateRsaKey(size: 2048)),
302+
new RsaSecurityKey(OpenIddictHelpers.CreateRsaKey(size: 4096)),
303303
algorithm, SecurityAlgorithms.Aes256CbcHmacSha512)),
304304

305305
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0058))
@@ -585,7 +585,7 @@ public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500Distinguishe
585585
if (!certificates.Exists(certificate => certificate.NotBefore < now.LocalDateTime && certificate.NotAfter > now.LocalDateTime))
586586
{
587587
#if SUPPORTS_CERTIFICATE_GENERATION
588-
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 2048);
588+
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 4096);
589589

590590
var request = new CertificateRequest(subject, algorithm, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
591591
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, critical: true));
@@ -681,7 +681,7 @@ SecurityAlgorithms.RsaSsaPssSha256Signature or
681681
SecurityAlgorithms.RsaSsaPssSha384Signature or
682682
SecurityAlgorithms.RsaSsaPssSha512Signature
683683
=> AddSigningCredentials(new SigningCredentials(new RsaSecurityKey(
684-
OpenIddictHelpers.CreateRsaKey(size: 2048)), algorithm)),
684+
OpenIddictHelpers.CreateRsaKey(size: 4096)), algorithm)),
685685

686686
#if SUPPORTS_ECDSA
687687
SecurityAlgorithms.EcdsaSha256 or

src/OpenIddict.Server/OpenIddictServerBuilder.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public OpenIddictServerBuilder AddDevelopmentEncryptionCertificate(X500Distingui
218218
if (!certificates.Exists(certificate => certificate.NotBefore < now.LocalDateTime && certificate.NotAfter > now.LocalDateTime))
219219
{
220220
#if SUPPORTS_CERTIFICATE_GENERATION
221-
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 2048);
221+
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 4096);
222222

223223
var request = new CertificateRequest(subject, algorithm, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
224224
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.KeyEncipherment, critical: true));
@@ -310,7 +310,7 @@ public OpenIddictServerBuilder AddEphemeralEncryptionKey(string algorithm)
310310
SecurityAlgorithms.RsaOAEP or
311311
SecurityAlgorithms.RsaOaepKeyWrap
312312
=> AddEncryptionCredentials(new EncryptingCredentials(
313-
new RsaSecurityKey(OpenIddictHelpers.CreateRsaKey(size: 2048)),
313+
new RsaSecurityKey(OpenIddictHelpers.CreateRsaKey(size: 4096)),
314314
algorithm, SecurityAlgorithms.Aes256CbcHmacSha512)),
315315

316316
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0058))
@@ -593,11 +593,10 @@ public OpenIddictServerBuilder AddDevelopmentSigningCertificate(X500Distinguishe
593593
.Cast<X509Certificate2>()
594594
.ToList();
595595

596-
if (!certificates.Exists(certificate =>
597-
certificate.NotBefore < now.LocalDateTime && certificate.NotAfter > now.LocalDateTime))
596+
if (!certificates.Exists(certificate => certificate.NotBefore < now.LocalDateTime && certificate.NotAfter > now.LocalDateTime))
598597
{
599598
#if SUPPORTS_CERTIFICATE_GENERATION
600-
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 2048);
599+
using var algorithm = OpenIddictHelpers.CreateRsaKey(size: 4096);
601600

602601
var request = new CertificateRequest(subject, algorithm, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
603602
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, critical: true));
@@ -693,7 +692,7 @@ SecurityAlgorithms.RsaSsaPssSha256Signature or
693692
SecurityAlgorithms.RsaSsaPssSha384Signature or
694693
SecurityAlgorithms.RsaSsaPssSha512Signature
695694
=> AddSigningCredentials(new SigningCredentials(new RsaSecurityKey(
696-
OpenIddictHelpers.CreateRsaKey(size: 2048)), algorithm)),
695+
OpenIddictHelpers.CreateRsaKey(size: 4096)), algorithm)),
697696

698697
#if SUPPORTS_ECDSA
699698
SecurityAlgorithms.EcdsaSha256 or

0 commit comments

Comments
 (0)