vortez 5.0.0-dev.14 → 5.0.0-dev.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Template.d.ts +1 -1
- package/build/Template.js +1 -1
- package/build/Vortez.d.ts +1 -1
- package/build/Vortez.js +1 -1
- package/build/beta/Beta.d.ts +2 -2
- package/build/beta/Beta.js +2 -2
- package/build/beta/Beta.js.map +1 -1
- package/build/beta/JwtManager/Jwt.d.ts +32 -0
- package/build/beta/JwtManager/Jwt.js +33 -0
- package/build/beta/JwtManager/Jwt.js.map +1 -0
- package/build/beta/JwtManager/JwtManager.d.ts +49 -0
- package/build/beta/JwtManager/JwtManager.js +74 -0
- package/build/beta/JwtManager/JwtManager.js.map +1 -0
- package/build/beta/JwtManager/JwtUtils.d.ts +32 -0
- package/build/beta/JwtManager/JwtUtils.js +50 -0
- package/build/beta/JwtManager/JwtUtils.js.map +1 -0
- package/build/beta/JwtManager/KeyGenerator.d.ts +47 -0
- package/build/beta/JwtManager/KeyGenerator.js +92 -0
- package/build/beta/JwtManager/KeyGenerator.js.map +1 -0
- package/build/beta/JwtManager/algorithm/Algorithm.d.ts +68 -0
- package/build/beta/JwtManager/algorithm/Algorithm.js +82 -0
- package/build/beta/JwtManager/algorithm/Algorithm.js.map +1 -0
- package/build/beta/JwtManager/algorithm/ECDSA.d.ts +18 -0
- package/build/beta/JwtManager/algorithm/ECDSA.js +46 -0
- package/build/beta/JwtManager/algorithm/ECDSA.js.map +1 -0
- package/build/beta/JwtManager/algorithm/HMAC.d.ts +24 -0
- package/build/beta/JwtManager/algorithm/HMAC.js +38 -0
- package/build/beta/JwtManager/algorithm/HMAC.js.map +1 -0
- package/build/beta/JwtManager/algorithm/RSA.d.ts +24 -0
- package/build/beta/JwtManager/algorithm/RSA.js +52 -0
- package/build/beta/JwtManager/algorithm/RSA.js.map +1 -0
- package/build/beta/JwtManager/algorithm/RSAPSS.d.ts +24 -0
- package/build/beta/JwtManager/algorithm/RSAPSS.js +55 -0
- package/build/beta/JwtManager/algorithm/RSAPSS.js.map +1 -0
- package/build/beta/Mail.d.ts +1 -1
- package/build/beta/Mail.js +1 -1
- package/build/logger/Debug.d.ts +1 -1
- package/build/logger/Debug.js +1 -1
- package/build/logger/Logger.d.ts +1 -1
- package/build/logger/Logger.js +1 -1
- package/build/server/BodyParser.d.ts +1 -1
- package/build/server/BodyParser.js +1 -1
- package/build/server/Cookie.d.ts +1 -1
- package/build/server/Cookie.js +1 -1
- package/build/server/LoggerManager.d.ts +1 -1
- package/build/server/LoggerManager.js +1 -1
- package/build/server/Request.d.ts +1 -1
- package/build/server/Request.js +1 -1
- package/build/server/Response.d.ts +1 -1
- package/build/server/Response.js +1 -1
- package/build/server/Server.d.ts +1 -1
- package/build/server/Server.js +1 -1
- package/build/server/ServerDebug.d.ts +1 -1
- package/build/server/ServerDebug.js +1 -1
- package/build/server/Session.d.ts +1 -1
- package/build/server/Session.js +1 -1
- package/build/server/config/Config.d.ts +1 -1
- package/build/server/config/Config.js +1 -1
- package/build/server/config/ConfigLoader.d.ts +1 -1
- package/build/server/config/ConfigLoader.js +1 -1
- package/build/server/config/ConfigValidator.d.ts +1 -1
- package/build/server/config/ConfigValidator.js +1 -1
- package/build/server/router/Router.d.ts +1 -1
- package/build/server/router/Router.js +1 -1
- package/build/server/router/Rule.d.ts +1 -1
- package/build/server/router/Rule.js +1 -1
- package/build/server/router/middleware/HttpMiddleware.d.ts +1 -1
- package/build/server/router/middleware/HttpMiddleware.js +1 -1
- package/build/server/router/middleware/Middleware.d.ts +1 -1
- package/build/server/router/middleware/Middleware.js +1 -1
- package/build/server/router/middleware/WsMiddleware.d.ts +1 -1
- package/build/server/router/middleware/WsMiddleware.js +1 -1
- package/build/server/websocket/Chunk.d.ts +1 -1
- package/build/server/websocket/Chunk.js +1 -1
- package/build/server/websocket/Websocket.d.ts +1 -1
- package/build/server/websocket/Websocket.js +1 -1
- package/build/utilities/ConsoleUI.d.ts +1 -1
- package/build/utilities/ConsoleUI.js +1 -1
- package/build/utilities/DebugUI.d.ts +1 -1
- package/build/utilities/DebugUI.js +1 -1
- package/build/utilities/Utilities.d.ts +1 -1
- package/build/utilities/Utilities.js +1 -1
- package/package.json +12 -8
- package/tests/jwtManager/jwtManager.js +46 -78
- package/build/beta/JwtManager.d.ts +0 -114
- package/build/beta/JwtManager.js +0 -249
- package/build/beta/JwtManager.js.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createPublicKey } from 'crypto';
|
|
2
|
+
export class Algorithm {
|
|
3
|
+
hashLength;
|
|
4
|
+
/** The private key used for signing and verification. */
|
|
5
|
+
key;
|
|
6
|
+
/** The public key used for verification. */
|
|
7
|
+
pub;
|
|
8
|
+
role;
|
|
9
|
+
constructor(hashLength, secret) {
|
|
10
|
+
this.hashLength = hashLength;
|
|
11
|
+
const { key, pub } = this.normalizeKey(secret);
|
|
12
|
+
if (!pub && !key)
|
|
13
|
+
throw new Error('At least one of "key" or "pub" must be provided.');
|
|
14
|
+
this.role = pub && !key ? 'verifier' : 'signer';
|
|
15
|
+
this.key = key;
|
|
16
|
+
this.pub = pub;
|
|
17
|
+
Object.defineProperty(this, 'key', { enumerable: false });
|
|
18
|
+
Object.defineProperty(this, 'pub', { enumerable: false });
|
|
19
|
+
}
|
|
20
|
+
normalizeKey(key) {
|
|
21
|
+
return Algorithm.normalizeKey(key);
|
|
22
|
+
}
|
|
23
|
+
/** Gets the name of the hash algorithm based on the specified hash length. */
|
|
24
|
+
get hashName() { return `SHA-${this.hashLength}`; }
|
|
25
|
+
toJSON() { return {}; }
|
|
26
|
+
toString() { return `Algorithm hash with "${this.hashName}" with role "${this.role}"`; }
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes the provided key input into a consistent format, ensuring that both the private and public keys are available as Buffers.
|
|
29
|
+
* @param key The key input, which can be either a string, a Buffer, or an object containing "key" and/or "pub" properties.
|
|
30
|
+
* @returns An object containing the normalized private key ("key") and public key ("pub") as Buffers. If only one key is provided, it will be used for both.
|
|
31
|
+
*/
|
|
32
|
+
static normalizeKey(key) {
|
|
33
|
+
if (typeof key === 'string')
|
|
34
|
+
return { key, pub: null };
|
|
35
|
+
const priv = key.key || null;
|
|
36
|
+
const pub = key.pub || null;
|
|
37
|
+
if (!pub && !priv)
|
|
38
|
+
throw new Error('At least one of "key" or "pub" must be provided.');
|
|
39
|
+
return { key: priv, pub };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts a key, which can be either a string or a Buffer, into a Buffer format.
|
|
43
|
+
* @param key The key to be converted, which can be a string or a Buffer.
|
|
44
|
+
* @returns The key in Buffer format.
|
|
45
|
+
*/
|
|
46
|
+
static keyToBuffer(key) {
|
|
47
|
+
return Buffer.isBuffer(key) ? key : Buffer.from(key);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Asserts that the provided key is a valid Buffer. If the key is not valid, an error is thrown with the specified message.
|
|
51
|
+
* @param key The key to be validated, which can be of any type.
|
|
52
|
+
* @param message The error message to be thrown if the key is not a valid Buffer.
|
|
53
|
+
* @throws Will throw an error if the key is not provided or if it is not a Buffer.
|
|
54
|
+
*/
|
|
55
|
+
static assertKey(key, message) {
|
|
56
|
+
if (!key)
|
|
57
|
+
throw new Error(message);
|
|
58
|
+
if (typeof key !== 'string')
|
|
59
|
+
throw new Error(message);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Asserts that the provided key is of the expected asymmetric key type (e.g., "rsa", "ec").
|
|
63
|
+
* If the key is not of the expected type, an error is thrown with the specified message.
|
|
64
|
+
* @param key The key to be validated, which should be a Buffer containing the key data.
|
|
65
|
+
* @param expected The expected asymmetric key type (e.g., "rsa", "ec").
|
|
66
|
+
* @param message The error message to be thrown if the key is not of the expected type.
|
|
67
|
+
* @throws Will throw an error if the key is not a valid asymmetric key of the expected type.
|
|
68
|
+
*/
|
|
69
|
+
static assertKeyType(key, expected, message) {
|
|
70
|
+
try {
|
|
71
|
+
const KeyObject = createPublicKey(key);
|
|
72
|
+
if (KeyObject.asymmetricKeyType !== expected)
|
|
73
|
+
throw new Error();
|
|
74
|
+
return KeyObject;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new Error(message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export default Algorithm;
|
|
82
|
+
//# sourceMappingURL=Algorithm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Algorithm.js","sourceRoot":"","sources":["../../../../src/beta/JwtManager/algorithm/Algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgC,MAAM,QAAQ,CAAC;AAEvE,MAAM,OAAgB,SAAS;IAOJ;IANvB,yDAAyD;IACtC,GAAG,CAAuB;IAC7C,4CAA4C;IACzB,GAAG,CAAuB;IAC7B,IAAI,CAAiB;IACrC,YACuB,UAAgC,EACnD,MAA4C;QADzB,eAAU,GAAV,UAAU,CAAsB;QAGnD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtF,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;QAChD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;IACS,YAAY,CAAC,GAAyC;QAC5D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,EAAE,QAA2B,EAAE,OAAe;QACxF,IAAI,CAAC;YACD,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;YACvC,IAAI,SAAS,CAAC,iBAAiB,KAAK,QAAQ;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAC;YAChE,OAAO,SAAS,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAAC,CAAC;IACzC,CAAC;CACJ;AAYD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Algorithm from './Algorithm.js';
|
|
2
|
+
export declare class ECDSA extends Algorithm {
|
|
3
|
+
normalizeKey(key: Algorithm.Key | Algorithm.KeyOptions): Algorithm.KeyObject;
|
|
4
|
+
/**
|
|
5
|
+
* Signs the given payload using the ECDSA algorithm and the provided key.
|
|
6
|
+
* @param payload The payload to be signed.
|
|
7
|
+
* @returns The ECDSA signature of the payload, encoded in base64.
|
|
8
|
+
*/
|
|
9
|
+
sign(payload: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
12
|
+
* @param payload The payload whose signature is to be verified.
|
|
13
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
14
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
15
|
+
*/
|
|
16
|
+
verify(payload: string, signature: string): boolean;
|
|
17
|
+
}
|
|
18
|
+
export default ECDSA;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { sign, verify } from 'crypto';
|
|
2
|
+
import Algorithm from './Algorithm.js';
|
|
3
|
+
export class ECDSA extends Algorithm {
|
|
4
|
+
normalizeKey(key) {
|
|
5
|
+
let { key: priv, pub } = super.normalizeKey(key);
|
|
6
|
+
if (pub)
|
|
7
|
+
Algorithm.assertKeyType(pub, 'ec', 'Provided public key is not an EC key.');
|
|
8
|
+
if (priv) {
|
|
9
|
+
const keyObject = Algorithm.assertKeyType(priv, 'ec', 'Provided private key is not an EC key.');
|
|
10
|
+
if (!pub)
|
|
11
|
+
pub = keyObject.export({ type: 'spki', format: 'pem' });
|
|
12
|
+
}
|
|
13
|
+
return { key: priv, pub };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Signs the given payload using the ECDSA algorithm and the provided key.
|
|
17
|
+
* @param payload The payload to be signed.
|
|
18
|
+
* @returns The ECDSA signature of the payload, encoded in base64.
|
|
19
|
+
*/
|
|
20
|
+
sign(payload) {
|
|
21
|
+
Algorithm.assertKey(this.key, 'No key provided for ECDSA signing');
|
|
22
|
+
const plBuffer = Buffer.from(payload, 'utf-8');
|
|
23
|
+
const signature = sign(this.hashName, plBuffer, {
|
|
24
|
+
key: this.key,
|
|
25
|
+
dsaEncoding: 'ieee-p1363'
|
|
26
|
+
});
|
|
27
|
+
return signature.toString('base64url');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
31
|
+
* @param payload The payload whose signature is to be verified.
|
|
32
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
33
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
34
|
+
*/
|
|
35
|
+
verify(payload, signature) {
|
|
36
|
+
Algorithm.assertKey(this.pub, 'No public key provided for ECDSA verification');
|
|
37
|
+
const plBuffer = Buffer.from(payload, 'utf-8');
|
|
38
|
+
const sigBuffer = Buffer.from(signature, 'base64url');
|
|
39
|
+
return verify(this.hashName, plBuffer, {
|
|
40
|
+
key: this.pub,
|
|
41
|
+
dsaEncoding: 'ieee-p1363'
|
|
42
|
+
}, sigBuffer);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export default ECDSA;
|
|
46
|
+
//# sourceMappingURL=ECDSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ECDSA.js","sourceRoot":"","sources":["../../../../src/beta/JwtManager/algorithm/ECDSA.ts"],"names":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AA+C,CAAC,CAAC;QAE/E,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACtD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE;YACnC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,WAAW,EAAE,YAAY;SAC5B,EAAE,SAAS,CAAC,CAAC;IAClB,CAAC;CACJ;AACD,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Algorithm from './Algorithm.js';
|
|
2
|
+
export declare class HMAC extends Algorithm {
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes the provided key for HMAC operations.
|
|
5
|
+
* Since HMAC uses a single secret key for both signing and verification, this method ensures that the same key is used for both operations.
|
|
6
|
+
* @param key The key to be normalized, which can be either a secret key or an object containing key options.
|
|
7
|
+
* @returns An object containing the normalized key for both signing and verification.
|
|
8
|
+
*/
|
|
9
|
+
protected normalizeKey(key: Algorithm.Key | Algorithm.KeyOptions): Algorithm.KeyObject;
|
|
10
|
+
/**
|
|
11
|
+
* Signs the given payload using the HMAC algorithm and the provided key.
|
|
12
|
+
* @param payload The payload to be signed.
|
|
13
|
+
* @returns The HMAC signature of the payload, encoded in base64.
|
|
14
|
+
*/
|
|
15
|
+
sign(payload: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
18
|
+
* @param payload The payload whose signature is to be verified.
|
|
19
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
20
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
21
|
+
*/
|
|
22
|
+
verify(payload: string, signature: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export default HMAC;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createHmac } from 'crypto';
|
|
2
|
+
import Algorithm from './Algorithm.js';
|
|
3
|
+
export class HMAC extends Algorithm {
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes the provided key for HMAC operations.
|
|
6
|
+
* Since HMAC uses a single secret key for both signing and verification, this method ensures that the same key is used for both operations.
|
|
7
|
+
* @param key The key to be normalized, which can be either a secret key or an object containing key options.
|
|
8
|
+
* @returns An object containing the normalized key for both signing and verification.
|
|
9
|
+
*/
|
|
10
|
+
normalizeKey(key) {
|
|
11
|
+
const { key: priv, pub } = super.normalizeKey(key);
|
|
12
|
+
const secret = priv || pub;
|
|
13
|
+
return { key: secret, pub: secret };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Signs the given payload using the HMAC algorithm and the provided key.
|
|
17
|
+
* @param payload The payload to be signed.
|
|
18
|
+
* @returns The HMAC signature of the payload, encoded in base64.
|
|
19
|
+
*/
|
|
20
|
+
sign(payload) {
|
|
21
|
+
Algorithm.assertKey(this.key, 'No key provided for HMAC signing');
|
|
22
|
+
const hmac = createHmac(this.hashName, this.key);
|
|
23
|
+
hmac.update(payload);
|
|
24
|
+
return hmac.digest('base64url');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
28
|
+
* @param payload The payload whose signature is to be verified.
|
|
29
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
30
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
31
|
+
*/
|
|
32
|
+
verify(payload, signature) {
|
|
33
|
+
const expectedSignature = this.sign(payload);
|
|
34
|
+
return expectedSignature === signature;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default HMAC;
|
|
38
|
+
//# sourceMappingURL=HMAC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HMAC.js","sourceRoot":"","sources":["../../../../src/beta/JwtManager/algorithm/HMAC.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,IAAK,SAAQ,SAAS;IAC/B;;;;;OAKG;IACO,YAAY,CAAC,GAAyC;QAC5D,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,IAAI,IAAI,GAAG,CAAC;QAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IACxC,CAAC;IACD;;;;OAIG;IACI,IAAI,CAAC,OAAe;QACvB,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,kCAAkC,CAAC,CAAC;QAElE,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,OAAe,EAAE,SAAiB;QAC5C,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7C,OAAO,iBAAiB,KAAK,SAAS,CAAC;IAC3C,CAAC;CACJ;AACD,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Algorithm from './Algorithm.js';
|
|
2
|
+
export declare class RSA extends Algorithm {
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes the provided key for RSA operations.
|
|
5
|
+
* This method ensures that the provided keys are valid RSA keys and extracts the public key from the private key if only the private key is provided.
|
|
6
|
+
* @param key The key to be normalized, which can be either a private key, a public key, or an object containing both.
|
|
7
|
+
* @returns An object containing the normalized private key ("key") and public key ("pub") as Buffers. If only the private key is provided, the corresponding public key will be extracted and included in the result.
|
|
8
|
+
*/
|
|
9
|
+
protected normalizeKey(key: Algorithm.Key | Algorithm.KeyOptions): Algorithm.KeyObject;
|
|
10
|
+
/**
|
|
11
|
+
* Signs the given payload using the RSA algorithm and the provided key.
|
|
12
|
+
* @param payload The payload to be signed.
|
|
13
|
+
* @returns The RSA signature of the payload, encoded in base64.
|
|
14
|
+
*/
|
|
15
|
+
sign(payload: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
18
|
+
* @param payload The payload whose signature is to be verified.
|
|
19
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
20
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
21
|
+
*/
|
|
22
|
+
verify(payload: string, signature: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export default RSA;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { sign, verify, constants } from 'crypto';
|
|
2
|
+
import Algorithm from './Algorithm.js';
|
|
3
|
+
export class RSA extends Algorithm {
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes the provided key for RSA operations.
|
|
6
|
+
* This method ensures that the provided keys are valid RSA keys and extracts the public key from the private key if only the private key is provided.
|
|
7
|
+
* @param key The key to be normalized, which can be either a private key, a public key, or an object containing both.
|
|
8
|
+
* @returns An object containing the normalized private key ("key") and public key ("pub") as Buffers. If only the private key is provided, the corresponding public key will be extracted and included in the result.
|
|
9
|
+
*/
|
|
10
|
+
normalizeKey(key) {
|
|
11
|
+
let { key: priv, pub } = super.normalizeKey(key);
|
|
12
|
+
if (pub)
|
|
13
|
+
Algorithm.assertKeyType(pub, 'rsa', 'Provided public key is not an RSA key.');
|
|
14
|
+
if (priv) {
|
|
15
|
+
const keyObject = Algorithm.assertKeyType(priv, 'rsa', 'Provided private key is not an RSA key.');
|
|
16
|
+
if (!pub)
|
|
17
|
+
pub = keyObject.export({ type: 'spki', format: 'pem' });
|
|
18
|
+
}
|
|
19
|
+
return { key: priv, pub };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Signs the given payload using the RSA algorithm and the provided key.
|
|
23
|
+
* @param payload The payload to be signed.
|
|
24
|
+
* @returns The RSA signature of the payload, encoded in base64.
|
|
25
|
+
*/
|
|
26
|
+
sign(payload) {
|
|
27
|
+
Algorithm.assertKey(this.key, 'No key provided for RSA signing');
|
|
28
|
+
const plBuffer = Buffer.from(payload, 'utf-8');
|
|
29
|
+
const signature = sign(this.hashName, plBuffer, {
|
|
30
|
+
key: this.key,
|
|
31
|
+
padding: constants.RSA_PKCS1_PADDING
|
|
32
|
+
});
|
|
33
|
+
return signature.toString('base64url');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
37
|
+
* @param payload The payload whose signature is to be verified.
|
|
38
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
39
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
40
|
+
*/
|
|
41
|
+
verify(payload, signature) {
|
|
42
|
+
Algorithm.assertKey(this.pub, 'No public key provided for RSA verification');
|
|
43
|
+
const plBuffer = Buffer.from(payload, 'utf-8');
|
|
44
|
+
const sigBuffer = Buffer.from(signature, 'base64url');
|
|
45
|
+
return verify(this.hashName, plBuffer, {
|
|
46
|
+
key: this.pub,
|
|
47
|
+
padding: constants.RSA_PKCS1_PADDING
|
|
48
|
+
}, sigBuffer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export default RSA;
|
|
52
|
+
//# sourceMappingURL=RSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RSA.js","sourceRoot":"","sources":["../../../../src/beta/JwtManager/algorithm/RSA.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,GAAI,SAAQ,SAAS;IAC9B;;;;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M,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACtD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE;YACnC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,SAAS,CAAC,iBAAiB;SACvC,EAAE,SAAS,CAAC,CAAC;IAClB,CAAC;CACJ;AACD,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Algorithm from './Algorithm.js';
|
|
2
|
+
export declare class RSAPSS extends Algorithm {
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes the provided key for RSA-PSS operations.
|
|
5
|
+
* This method ensures that the provided keys are valid RSA-PSS keys and extracts the public key from the private key if only the private key is provided.
|
|
6
|
+
* @param key The key to be normalized, which can be either a private key, a public key, or an object containing both.
|
|
7
|
+
* @returns An object containing the normalized private key ("key") and public key ("pub") as Buffers. If only the private key is provided, the corresponding public key will be extracted and included in the result.
|
|
8
|
+
*/
|
|
9
|
+
protected normalizeKey(key: Algorithm.Key | Algorithm.KeyOptions): Algorithm.KeyObject;
|
|
10
|
+
/**
|
|
11
|
+
* Signs the given payload using the RSA-PSS algorithm and the provided key.
|
|
12
|
+
* @param payload The payload to be signed.
|
|
13
|
+
* @returns The RSA-PSS signature of the payload, encoded in base64.
|
|
14
|
+
*/
|
|
15
|
+
sign(payload: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
18
|
+
* @param payload The payload whose signature is to be verified.
|
|
19
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
20
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
21
|
+
*/
|
|
22
|
+
verify(payload: string, signature: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export default RSAPSS;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { sign, verify, constants } from 'crypto';
|
|
2
|
+
import Algorithm from './Algorithm.js';
|
|
3
|
+
export class RSAPSS extends Algorithm {
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes the provided key for RSA-PSS operations.
|
|
6
|
+
* This method ensures that the provided keys are valid RSA-PSS keys and extracts the public key from the private key if only the private key is provided.
|
|
7
|
+
* @param key The key to be normalized, which can be either a private key, a public key, or an object containing both.
|
|
8
|
+
* @returns An object containing the normalized private key ("key") and public key ("pub") as Buffers. If only the private key is provided, the corresponding public key will be extracted and included in the result.
|
|
9
|
+
*/
|
|
10
|
+
normalizeKey(key) {
|
|
11
|
+
// For RSA-PSS, the same key pair is used as for RSA, so we can reuse the normalization logic from the RSA algorithm. more info in file KeyGenerator.ts (method RSAPSS)
|
|
12
|
+
let { key: priv, pub } = super.normalizeKey(key);
|
|
13
|
+
if (pub)
|
|
14
|
+
Algorithm.assertKeyType(pub, /* 'rsa-pss' */ 'rsa', 'Provided public key is not an RSA-PSS key.');
|
|
15
|
+
if (priv) {
|
|
16
|
+
const keyObject = Algorithm.assertKeyType(priv, /* 'rsa-pss' */ 'rsa', 'Provided private key is not an RSA-PSS key.');
|
|
17
|
+
if (!pub)
|
|
18
|
+
pub = keyObject.export({ type: 'spki', format: 'pem' });
|
|
19
|
+
}
|
|
20
|
+
return { key: priv, pub };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Signs the given payload using the RSA-PSS algorithm and the provided key.
|
|
24
|
+
* @param payload The payload to be signed.
|
|
25
|
+
* @returns The RSA-PSS signature of the payload, encoded in base64.
|
|
26
|
+
*/
|
|
27
|
+
sign(payload) {
|
|
28
|
+
Algorithm.assertKey(this.key, 'No key provided for RSA-PSS signing');
|
|
29
|
+
const plBuffer = Buffer.from(payload, 'utf-8');
|
|
30
|
+
const signature = sign(this.hashName, plBuffer, {
|
|
31
|
+
key: this.key,
|
|
32
|
+
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
33
|
+
saltLength: constants.RSA_PSS_SALTLEN_DIGEST
|
|
34
|
+
});
|
|
35
|
+
return signature.toString('base64url');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Verifies that the provided signature matches the expected signature for the given payload.
|
|
39
|
+
* @param payload The payload whose signature is to be verified.
|
|
40
|
+
* @param signature The signature to be verified, encoded in base64.
|
|
41
|
+
* @returns `true` if the signature is valid; otherwise, `false`.
|
|
42
|
+
*/
|
|
43
|
+
verify(payload, signature) {
|
|
44
|
+
Algorithm.assertKey(this.pub, 'No public key provided for RSA-PSS verification');
|
|
45
|
+
const plBuffer = Buffer.from(payload, 'utf-8');
|
|
46
|
+
const sigBuffer = Buffer.from(signature, 'base64url');
|
|
47
|
+
return verify(this.hashName, plBuffer, {
|
|
48
|
+
key: this.pub,
|
|
49
|
+
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
50
|
+
saltLength: constants.RSA_PSS_SALTLEN_DIGEST
|
|
51
|
+
}, sigBuffer);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export default RSAPSS;
|
|
55
|
+
//# sourceMappingURL=RSAPSS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RSAPSS.js","sourceRoot":"","sources":["../../../../src/beta/JwtManager/algorithm/RSAPSS.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,MAAO,SAAQ,SAAS;IACjC;;;;;OAKG;IACO,YAAY,CAAC,GAAyC;QAC5D,uKAAuK;QACvK,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACjD,IAAI,GAAG;YAAE,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,eAAe,CAAC,KAAK,EAAE,4CAA4C,CAAC,CAAC;QAC3G,IAAI,IAAI,EAAE,CAAC;YACP,MAAM,SAAS,GAAG,SAAS,CAAC,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S,CAAC,CAAC;IAClB,CAAC;CACJ;AACD,eAAe,MAAM,CAAC"}
|
package/build/beta/Mail.d.ts
CHANGED
package/build/beta/Mail.js
CHANGED
package/build/logger/Debug.d.ts
CHANGED
package/build/logger/Debug.js
CHANGED
package/build/logger/Logger.d.ts
CHANGED
package/build/logger/Logger.js
CHANGED
package/build/server/Cookie.d.ts
CHANGED
package/build/server/Cookie.js
CHANGED
package/build/server/Request.js
CHANGED
package/build/server/Response.js
CHANGED
package/build/server/Server.d.ts
CHANGED
package/build/server/Server.js
CHANGED
package/build/server/Session.js
CHANGED