fix(#288): Upgrade RSA key size to 4096 bits

Changed modulusLength from 2048 to 4096 in generateKeypair() method
following NIST recommendations for long-term security. Added test to
verify generated keys meet the minimum size requirement.

Security improvement: RSA-4096 provides better protection against
future cryptographic attacks as computational power increases.

Fixes #288

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 21:33:57 -06:00
parent aabf97fe4e
commit ecb33a17fe
2 changed files with 14 additions and 1 deletions

View File

@@ -198,6 +198,18 @@ describe("FederationService", () => {
expect(result1.publicKey).not.toEqual(result2.publicKey);
expect(result1.privateKey).not.toEqual(result2.privateKey);
});
it("should generate RSA-4096 key pairs for future-proof security", () => {
// Act
const result = service.generateKeypair();
// Assert - Verify key size by checking approximate length
// RSA-4096 keys are significantly larger than RSA-2048
// Private key in PKCS8 format: RSA-2048 ≈ 1700 bytes, RSA-4096 ≈ 3200 bytes
// Public key in SPKI format: RSA-2048 ≈ 400 bytes, RSA-4096 ≈ 800 bytes
expect(result.privateKey.length).toBeGreaterThan(3000);
expect(result.publicKey.length).toBeGreaterThan(700);
});
});
describe("regenerateKeypair", () => {

View File

@@ -57,10 +57,11 @@ export class FederationService {
/**
* Generate a new RSA key pair for instance signing
* Uses RSA-4096 for future-proof security (NIST recommendation)
*/
generateKeypair(): KeyPair {
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
modulusLength: 2048,
modulusLength: 4096,
publicKeyEncoding: {
type: "spki",
format: "pem",