orgnote-api 0.7.13 → 0.7.15
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.
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
decryptViaKeys,
|
|
4
4
|
encryptViaPassword,
|
|
5
5
|
decryptViaPassword,
|
|
6
|
+
NoKeysProvided,
|
|
7
|
+
NoPasswordProvided,
|
|
8
|
+
IncorrectOrMissingPrivateKeyPasswordError,
|
|
6
9
|
} from '../encryption';
|
|
7
10
|
import { test, expect } from 'vitest';
|
|
8
11
|
|
|
@@ -85,3 +88,78 @@ aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
|
85
88
|
'Hello world'
|
|
86
89
|
);
|
|
87
90
|
});
|
|
91
|
+
|
|
92
|
+
test('Should raise incorrect or missing private key error', async () => {
|
|
93
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
94
|
+
|
|
95
|
+
wcFMA/vryg+TTn0rARAAhXuEjOHa856iCNVmdeIGHF+IEoeEwTc5tIcr6Lri
|
|
96
|
+
V6xs//3WnwVwUlyxYrum3yCpx8t5gyWTXFfTNH08VoVqPVP45fkk1H7jdC6Q
|
|
97
|
+
I+tHfn8nXZApdKQlMOku+XMXtRuqvOUQHutqHj4ka3qC+wGIPcOsy2TIoFsS
|
|
98
|
+
xauk13hMggmVHOdQkMzWA1QlxDcz6lFl86SvX18uc7H62s36gHxARmOLZfBd
|
|
99
|
+
nRFdnPgLKNOPGWb6QvYfvxiv03vGSsKlb0tIpwP1Ot0nyZax+yH9CJmIEni/
|
|
100
|
+
rW9Wu/Ph+PRcB2L9kp/X4Opol3RwJ0lI9ilTRw9+GGFipXhCmJcjPJC7WNIg
|
|
101
|
+
vg0/xVUjSmlxQQAZlC9/sefvoXjY0CP+h+djtoZsxLpN4P4iTO1reuoVD0iO
|
|
102
|
+
UwT9JCUR1uDEiNXvh6AmrLlH3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NGrVbbhpx+FDF9Ky9kqb2BJBTFKoCBxbf0dS
|
|
118
|
+
sniNAsC/t/k6ErG8NKNQsNh1aeN6plXnxeVi1vv6SvO2mwZRVvDNT1hg9Cyc
|
|
119
|
+
UO1Pw43TRLO50HgR9+ERNXL491TJA0aCj14oXwsm0Dtg6EOltX0GUDwcPjv6
|
|
120
|
+
6QMreKTATPLytbhCdPO+JOzObsptU/IlsQQWlMz8yKXwqyuN8z8SOaddJIHR
|
|
121
|
+
YQ==
|
|
122
|
+
=f4F1
|
|
123
|
+
-----END PGP MESSAGE-----`;
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
await decryptViaPassword(encryptedMsg, 'password');
|
|
127
|
+
} catch (e) {
|
|
128
|
+
expect(e).toBeInstanceOf(NoKeysProvided);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('Should raise IncorrectOrMissingPrivateKeyPasswordError error when incorrect armored key provided', async () => {
|
|
133
|
+
const password = 'test';
|
|
134
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
135
|
+
|
|
136
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
137
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
138
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
139
|
+
=B4Tc
|
|
140
|
+
-----END PGP MESSAGE-----
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
await decryptViaKeys(encryptedMsg, armoredPublicKey, privateKeyPassphrase);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
expect(e).toBeInstanceOf(IncorrectOrMissingPrivateKeyPasswordError);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('Should raise NoPasswordProvided error when try to use keys instead of password', async () => {
|
|
151
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
152
|
+
|
|
153
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
154
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
155
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
156
|
+
=B4Tc
|
|
157
|
+
-----END PGP MESSAGE-----
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await decryptViaKeys(encryptedMsg, armoredPrivateKey, privateKeyPassphrase);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
expect(e).toBeInstanceOf(NoPasswordProvided);
|
|
164
|
+
}
|
|
165
|
+
});
|
package/encryption/encryption.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
export class IncorrectOrMissingPrivateKeyPasswordError extends Error {}
|
|
12
12
|
export class ImpossibleToDecryptWithProvidedKeysError extends Error {}
|
|
13
13
|
export class IncorrectEncryptionPasswordError extends Error {}
|
|
14
|
+
export class NoKeysProvided extends Error {}
|
|
15
|
+
export class NoPasswordProvided extends Error {}
|
|
14
16
|
|
|
15
17
|
const noPrivateKeyPassphraseProvidedErrorMsg =
|
|
16
18
|
'Error: Signing key is not decrypted.';
|
|
@@ -25,6 +27,15 @@ const decriptionFailedErrorMsg =
|
|
|
25
27
|
const incorrectEncryptionPasswordErrorMsg =
|
|
26
28
|
'Error decrypting message: Modification detected.';
|
|
27
29
|
|
|
30
|
+
const noSymmetricallyEncryptedSessionKeyErrorMsg =
|
|
31
|
+
'Error decrypting message: No symmetrically encrypted session key packet found.';
|
|
32
|
+
|
|
33
|
+
const armoredTextNotTypePrivateKeyErrorMsg =
|
|
34
|
+
'Armored text not of type private key';
|
|
35
|
+
|
|
36
|
+
const notPrivateKeyErrprMsg =
|
|
37
|
+
'Error decrypting message: No public key encrypted session key packet found.';
|
|
38
|
+
|
|
28
39
|
export const encryptViaKeys = withCustomErrors(_encryptViaKeys);
|
|
29
40
|
export const encryptViaPassword = withCustomErrors(_encryptViaPassword);
|
|
30
41
|
export const decryptViaPassword = withCustomErrors(_decryptViaPassword);
|
|
@@ -136,6 +147,7 @@ function withCustomErrors<P extends unknown[], T>(
|
|
|
136
147
|
incorrectPrivateKeyPassphraseErrorMsg,
|
|
137
148
|
corruptedPrivateKeyErrorMsg,
|
|
138
149
|
decryptionKeyIsNotDecryptedErrorMsg,
|
|
150
|
+
armoredTextNotTypePrivateKeyErrorMsg,
|
|
139
151
|
].includes(e.message)
|
|
140
152
|
) {
|
|
141
153
|
throw new IncorrectOrMissingPrivateKeyPasswordError(e.message);
|
|
@@ -146,6 +158,14 @@ function withCustomErrors<P extends unknown[], T>(
|
|
|
146
158
|
if (e.message === incorrectEncryptionPasswordErrorMsg) {
|
|
147
159
|
throw new IncorrectEncryptionPasswordError();
|
|
148
160
|
}
|
|
161
|
+
if (e.message === noSymmetricallyEncryptedSessionKeyErrorMsg) {
|
|
162
|
+
throw new NoKeysProvided();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (e.message === notPrivateKeyErrprMsg) {
|
|
166
|
+
throw new NoPasswordProvided();
|
|
167
|
+
}
|
|
168
|
+
|
|
149
169
|
throw e;
|
|
150
170
|
}
|
|
151
171
|
};
|