switching to alternate rsa implementation

This commit is contained in:
balzack 2022-12-19 09:11:09 -08:00
parent 7f85bfb66b
commit be43f6829a
6 changed files with 5090 additions and 5192 deletions

View File

@ -328,6 +328,7 @@
"${BUILT_PRODUCTS_DIR}/glog/glog.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
"${BUILT_PRODUCTS_DIR}/react-native-document-picker/react_native_document_picker.framework",
"${BUILT_PRODUCTS_DIR}/react-native-rsa-native/react_native_rsa_native.framework",
"${BUILT_PRODUCTS_DIR}/react-native-safe-area-context/react_native_safe_area_context.framework",
"${BUILT_PRODUCTS_DIR}/react-native-sqlite-storage/react_native_sqlite_storage.framework",
);
@ -376,6 +377,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/glog.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/react_native_document_picker.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/react_native_rsa_native.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/react_native_safe_area_context.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/react_native_sqlite_storage.framework",
);

View File

@ -298,6 +298,8 @@ PODS:
- glog
- react-native-document-picker (8.1.1):
- React-Core
- react-native-rsa-native (2.0.5):
- React
- react-native-safe-area-context (4.3.3):
- RCT-Folly
- RCTRequired
@ -497,6 +499,7 @@ DEPENDENCIES:
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-document-picker (from `../node_modules/react-native-document-picker`)
- react-native-rsa-native (from `../node_modules/react-native-rsa-native`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-sqlite-storage (from `../node_modules/react-native-sqlite-storage`)
- react-native-video (from `../node_modules/react-native-video`)
@ -597,6 +600,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-document-picker:
:path: "../node_modules/react-native-document-picker"
react-native-rsa-native:
:path: "../node_modules/react-native-rsa-native"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
react-native-sqlite-storage:
@ -689,6 +694,7 @@ SPEC CHECKSUMS:
React-jsinspector: e385fb7a1440ae3f3b2cd1a139ca5aadaab43c10
React-logger: 15c734997c06fe9c9b88e528fb7757601e7a56df
react-native-document-picker: f68191637788994baed5f57d12994aa32cf8bf88
react-native-rsa-native: 12132eb627797529fdb1f0d22fd0f8f9678df64a
react-native-safe-area-context: b456e1c40ec86f5593d58b275bd0e9603169daca
react-native-sqlite-storage: f6d515e1c446d1e6d026aa5352908a25d4de3261
react-native-video: c26780b224543c62d5e1b2a7244a5cd1b50e8253

View File

@ -35,6 +35,7 @@
"react-native-gesture-handler": "^2.7.0",
"react-native-image-crop-picker": "^0.38.0",
"react-native-reanimated": "^2.10.0",
"react-native-rsa-native": "^2.0.5",
"react-native-safe-area-context": "^4.3.3",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "^3.18.2",

View File

@ -3,6 +3,7 @@ import { ConversationContext } from 'context/ConversationContext';
import { AccountContext } from 'context/AccountContext';
import CryptoJS from 'crypto-js';
import { JSEncrypt } from 'jsencrypt'
import { RSA } from 'react-native-rsa-native';
export function useConversation() {
@ -33,19 +34,28 @@ export function useConversation() {
setState((s) => ({ ...s, ...value }));
}
const converPem = (str) => {
var result = '';
while (str.length > 0) {
result += str.substring(0, 64) + '\n';
str = str.substring(64);
}
return result;
}
useEffect(() => {
let sealKey;
const { locked, seals } = conversation.state;
if (seals?.length) {
seals.forEach(seal => {
if (seal.publicKey === account.state.sealKey?.public) {
let crypto = new JSEncrypt();
crypto.setPrivateKey(account.state.sealKey.private);
sealKey = crypto.decrypt(seal.sealedKey);
const key = '-----BEGIN RSA PRIVATE KEY-----\n' + account.state.sealKey.private + '\n-----END RSA PRIVATE KEY-----'
RSA.decrypt(seal.sealedKey, key).then(sealKey => {
updateState({ locked, sealKey });
});
}
});
}
updateState({ locked, sealKey });
}, [conversation.state.locked, conversation.state.seals, account.state.sealKey])
useEffect(() => {

View File

@ -7,6 +7,7 @@ import { AppContext } from 'context/AppContext';
import config from 'constants/Config';
import { JSEncrypt } from 'jsencrypt'
import CryptoJS from "crypto-js";
import { RSA } from 'react-native-rsa-native';
export function useProfileBody() {
@ -122,13 +123,12 @@ export function useProfileBody() {
// generate rsa key for sealing channel, delay for activity indicator
await new Promise(r => setTimeout(r, 1000));
const crypto = new JSEncrypt({ default_key_size: 2048 });
const key = crypto.getKey();
const keys = await RSA.generateKeys(2048);
// encrypt private key
const iv = CryptoJS.lib.WordArray.random(128 / 8);
const privateKey = convertPem(crypto.getPrivateKey());
const publicKey = convertPem(crypto.getPublicKey());
const privateKey = convertPem(keys.private);
const publicKey = convertPem(keys.public);
const enc = CryptoJS.AES.encrypt(privateKey, aes, { iv: iv });
const seal = {

File diff suppressed because it is too large Load Diff