-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All: Add new encryption methods based on native crypto libraries #10696
Changes from 8 commits
71f0204
17aa0fd
a2be9f1
17badd5
80a764b
4c8c2f3
8387c96
0276041
832e589
373ecac
d3bd657
e4eb58c
f2ed473
0182cce
48b54ec
70db354
52f8244
7b7595f
26faf26
63f6ce9
295ef6f
9d39eb7
bfc3ecb
73b4c5a
bf0f126
61dd12d
1536a04
8b20d12
04dfc8b
b912dca
2adf438
95281e7
d780b09
cbf2563
d7a3b9c
885a4b6
b96bd0d
b99f9fc
7026dc2
bca6e4d
d9d8eae
bb69f50
bc9605e
91f9c9b
b329c0c
d0140da
41e7918
6087f77
72366e2
dfefff7
2fc951d
1f9525d
10c185f
d56dfc0
ab22f04
701c313
b637071
58aec1d
cb9b077
1a2c3d2
2855ec7
7dc4eec
9a7b310
2b42bbf
8cfd6dd
6de1015
bf0d512
8def1be
115b502
8fcc8ee
edd2a90
a786478
d8f243a
e78cc10
5934ccb
9e22379
002f7de
98acc2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Crypto, CryptoBuffer } from '@joplin/lib/services/e2ee/types'; | ||
import crypto from 'react-native-quick-crypto'; | ||
import { HashAlgorithm } from 'react-native-quick-crypto/lib/typescript/keys'; | ||
|
||
const cryptoLib: Crypto = { | ||
|
||
getCiphers: (): string[] => { | ||
return crypto.getCiphers(); | ||
}, | ||
|
||
getHashes: (): string[] => { | ||
return crypto.getHashes(); | ||
}, | ||
|
||
randomBytes: async (size: number): Promise<CryptoBuffer> => { | ||
return new Promise((resolve, reject) => { | ||
crypto.randomBytes(size, (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}, | ||
|
||
pbkdf2Raw: async (password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: string): Promise<CryptoBuffer> => { | ||
const digestMap: { [key: string]: HashAlgorithm } = { | ||
'sha1': 'SHA-1', | ||
'sha224': 'SHA-224', | ||
'sha256': 'SHA-256', | ||
'sha384': 'SHA-384', | ||
'sha512': 'SHA-512', | ||
'ripemd160': 'RIPEMD-160', | ||
}; | ||
const digestAlgorithm: string = digestMap[digest.toLowerCase()] || digest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also not recommended. See https://joplinapp.org/help/dev/coding_style#dont-set-the-type-when-it-can-be-inferred There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
return new Promise((resolve, reject) => { | ||
crypto.pbkdf2(password, salt, iterations, keylen, digestAlgorithm as HashAlgorithm, (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}, | ||
}; | ||
|
||
export default cryptoLib; | ||
laurent22 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Crypto } from './types'; | ||
import { promisify } from 'util'; | ||
import crypto = require('crypto'); | ||
|
||
const cryptoLib: Crypto = { | ||
|
||
getCiphers: (): string[] => { | ||
return crypto.getCiphers(); | ||
}, | ||
|
||
getHashes: (): string[] => { | ||
return crypto.getHashes(); | ||
}, | ||
|
||
randomBytes: async (size: number): Promise<Buffer> => { | ||
const randomBytesAsync = promisify(crypto.randomBytes); | ||
return randomBytesAsync(size); | ||
}, | ||
|
||
pbkdf2Raw: async (password: string, salt: Buffer, iterations: number, keylen: number, digest: string): Promise<Buffer> => { | ||
const digestMap: { [key: string]: string } = { | ||
'sha-1': 'sha1', | ||
'sha-224': 'sha224', | ||
'sha-256': 'sha256', | ||
'sha-384': 'sha384', | ||
'sha-512': 'sha512', | ||
'ripemd-160': 'ripemd160', | ||
}; | ||
const digestAlgorithm: string = digestMap[digest.toLowerCase()] || digest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really get this part - are the digestMap the list of supported digests? In that case shouldn't that be exposed to the library user? In other words, it seems there should be an enum that tells the list of supported digests. And Also please don't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
const pbkdf2Async = promisify(crypto.pbkdf2); | ||
return pbkdf2Async(password, salt, iterations, keylen, digestAlgorithm); | ||
}, | ||
}; | ||
|
||
export default cryptoLib; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,4 +110,5 @@ ENOTFOUND | |
Scaleway | ||
Inkscape | ||
Ionicon | ||
Stormlikes | ||
Stormlikes | ||
ripemd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again please read the coding style guide, we explicitly ask not to set types this way. See https://joplinapp.org/help/dev/coding_style#avoid-inline-types
I really shouldn't have to keep reminding you to read it. It's understandable to miss a few details here and there but for this PR that's what, the third or fourth time that I remind you to read it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I only checked the method declaration. I will change it later.