-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): implement RSA-based JWT token validation
This commit introduces RSA-based JWT token validation to enable decentralized authentication across microservices. It replaces the existing symmetric key (HS256) approach with asymmetric cryptography (RS256) for enhanced security and scalability. Key changes: - Add CryptoUtil class for managing RSA key pairs - Update JWT utilities to use RS256 algorithm - Add key generation script and initialization process - Make token generation consistently asynchronous - Implement proper error handling for crypto operations - Add key files to .gitignore for security - Add example key templates and setup documentation Technical details: - Use 2048-bit RSA keys for token signing/verification - Store keys in PEM format under /keys directory (not committed) - Initialize crypto keys at application startup - Add proper TypeScript types for crypto operations Breaking changes: - Token validation now requires public key distribution to other services - Token generation is now fully asynchronous - Requires manual key generation/setup Security note: - RSA keys must be generated separately and are not included in version control - See README.md for proper key setup instructions
- Loading branch information
1 parent
d28e92e
commit 83052ca
Showing
12 changed files
with
262 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,7 @@ yarn-error.log* | |
# OS generated files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Crypto keys | ||
/keys | ||
*.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import crypto from "crypto"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const generateKeyPair = () => { | ||
const { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", { | ||
modulusLength: 2048, | ||
publicKeyEncoding: { | ||
type: "spki", | ||
format: "pem", | ||
}, | ||
privateKeyEncoding: { | ||
type: "pkcs8", | ||
format: "pem", | ||
}, | ||
}); | ||
|
||
const keysDir = path.join(process.cwd(), "keys"); | ||
|
||
if (!fs.existsSync(keysDir)) { | ||
fs.mkdirSync(keysDir); | ||
} | ||
|
||
fs.writeFileSync(path.join(keysDir, "private.pem"), privateKey); | ||
fs.writeFileSync(path.join(keysDir, "public.pem"), publicKey); | ||
}; | ||
|
||
generateKeyPair(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.