Skip to content

Commit 6c013ab

Browse files
nievasdevdependabot[bot]AugustinMauroy
authored
feat(crypto): add RSA-PSS codemod for DEP0154 (#164)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Augustin Mauroy <[email protected]>
1 parent 1d5f37b commit 6c013ab

38 files changed

+1624
-0
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# crypto-rsa-pss-update
2+
3+
Codemod to handle Node.js crypto deprecation DEP0154 by transforming deprecated RSA-PSS key generation options.
4+
5+
## What it does
6+
7+
This codemod transforms deprecated RSA-PSS crypto options in `crypto.generateKeyPair()` and `crypto.generateKeyPairSync()` calls:
8+
9+
- `hash``hashAlgorithm`
10+
- `mgf1Hash``mgf1HashAlgorithm`
11+
12+
The transformation only applies to calls with `'rsa-pss'` as the key type.
13+
14+
## Examples
15+
16+
**Before**
17+
18+
```js
19+
const crypto = require("node:crypto");
20+
21+
crypto.generateKeyPair(
22+
"rsa-pss",
23+
{
24+
modulusLength: 2048,
25+
hash: "sha256",
26+
mgf1Hash: "sha1",
27+
saltLength: 32,
28+
},
29+
(err, publicKey, privateKey) => {
30+
// callback
31+
},
32+
);
33+
34+
crypto.generateKeyPairSync("rsa-pss", {
35+
modulusLength: 2048,
36+
hash: "sha256",
37+
});
38+
```
39+
40+
**After**
41+
42+
```js
43+
const crypto = require("crypto");
44+
45+
crypto.generateKeyPair(
46+
"rsa-pss",
47+
{
48+
modulusLength: 2048,
49+
hashAlgorithm: "sha256",
50+
mgf1HashAlgorithm: "sha1",
51+
saltLength: 32,
52+
},
53+
(err, publicKey, privateKey) => {
54+
// callback
55+
},
56+
);
57+
58+
crypto.generateKeyPairSync("rsa-pss", {
59+
modulusLength: 2048,
60+
hashAlgorithm: "sha256",
61+
});
62+
```
63+
64+
## Usage
65+
66+
```bash
67+
npx codemod @nodejs/crypto-rsa-pss-update
68+
```
69+
70+
## Supports
71+
72+
- Both `crypto.generateKeyPair()` and `crypto.generateKeyPairSync()`
73+
- Destructured imports: `const { generateKeyPair } = require('crypto')`
74+
- Variable references: `const options = { hash: 'sha256' }`
75+
- Function calls: `getKeyOptions()` returning crypto options
76+
- This property patterns: `this.options = { hash: 'sha256' }`
77+
- Only transforms `'rsa-pss'` key type calls
78+
- Preserves all other options and call structure
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
schema_version: "1.0"
2+
name: "@nodejs/crypto-rsa-pss-update"
3+
version: 1.0.0
4+
description: >-
5+
Handle DEP0154 via transforming deprecated RSA-PSS crypto options `hash` to
6+
`hashAlgorithm` and `mgf1Hash` to `mgf1HashAlgorithm`
7+
author: Mauro Nievas
8+
license: MIT
9+
workflow: workflow.yaml
10+
category: migration
11+
12+
targets:
13+
languages:
14+
- javascript
15+
- typescript
16+
17+
keywords:
18+
- transformation
19+
- migration
20+
- crypto
21+
- rsa-pss
22+
23+
registry:
24+
access: public
25+
visibility: public
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@nodejs/crypto-rsa-pss-update",
3+
"version": "1.0.0",
4+
"description": "Handle DEP0154 via transforming deprecated RSA-PSS crypto options `hash` to `hashAlgorithm` and `mgf1Hash` to `mgf1HashAlgorithm`.",
5+
"type": "module",
6+
"scripts": {
7+
"test": "npx codemod jssg test -l typescript ./src/workflow.ts ./"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/nodejs/userland-migrations.git",
12+
"directory": "recipes/crypto-rsa-pss-update",
13+
"bugs": "https://github.com/nodejs/userland-migrations/issues"
14+
},
15+
"author": "Mauro Nievas",
16+
"license": "MIT",
17+
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/crypto-rsa-pss-update/README.md",
18+
"devDependencies": {
19+
"@codemod.com/jssg-types": "^1.0.3"
20+
},
21+
"dependencies": {
22+
"@nodejs/codemod-utils": "*"
23+
}
24+
}

0 commit comments

Comments
 (0)