adding sealing key support to mobile

This commit is contained in:
Roland Osborne 2022-12-07 10:22:16 -08:00
parent dd6198ee7f
commit 1b932aa656
6 changed files with 26427 additions and 5051 deletions

View File

@ -669,7 +669,7 @@ SPEC CHECKSUMS:
FirebaseInstallations: 99d24bac0243cf8b0e96cf5426340d211f0bcc80
FirebaseMessaging: 4487bbff9b9b927ba1dd3ea40d1ceb58e4ee3cb5
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
glog: 3d02b25ca00c2d456734d0bcff864cbc62f6ae1a
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431

21187
app/mobile/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -18,11 +18,13 @@
"@react-navigation/stack": "^6.3.0",
"@stream-io/flat-list-mvcp": "^0.10.2",
"axios": "^1.1.0",
"crypto-js": "^3.3.0",
"expo": "~46.0.9",
"expo-av": "^12.0.4",
"expo-keep-awake": "~10.2.0",
"expo-splash-screen": "~0.16.2",
"expo-status-bar": "~1.4.0",
"jsencrypt": "^3.3.1",
"moment": "^2.29.4",
"react": "18.0.0",
"react-dom": "18.0.0",

View File

@ -143,6 +143,9 @@ export function ProfileBody({ navigation }) {
</TouchableOpacity>
<Switch style={styles.visibleSwitch} value={state.pushEnabled} onValueChange={setNotifications} trackColor={styles.switch}/>
</View>
<TouchableOpacity style={styles.link} onPress={actions.sealTest}>
<Text style={styles.linkText}>Test Seal</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.link} onPress={actions.showLoginEdit}>
<Text style={styles.linkText}>Change Login</Text>
</TouchableOpacity>

View File

@ -5,6 +5,8 @@ import { ProfileContext } from 'context/ProfileContext';
import { AccountContext } from 'context/AccountContext';
import { AppContext } from 'context/AppContext';
import config from 'constants/Config';
import { JSEncrypt } from 'jsencrypt'
import CryptoJS from "crypto-js";
export function useProfileBody() {
@ -73,7 +75,53 @@ export function useProfileBody() {
updateState({ disconnected });
}, [app]);
const convertPem = (pem) => {
var lines = pem.split('\n');
var encoded = '';
for(var i = 0;i < lines.length;i++){
if (lines[i].trim().length > 0 &&
lines[i].indexOf('-BEGIN RSA PRIVATE KEY-') < 0 &&
lines[i].indexOf('-BEGIN RSA PUBLIC KEY-') < 0 &&
lines[i].indexOf('-BEGIN PUBLIC KEY-') < 0 &&
lines[i].indexOf('-END PUBLIC KEY-') < 0 &&
lines[i].indexOf('-END RSA PRIVATE KEY-') < 0 &&
lines[i].indexOf('-END RSA PUBLIC KEY-') < 0) {
encoded += lines[i].trim();
}
}
return encoded
};
const actions = {
sealTest: async () => {
console.log("SEAL TEST");
// generate key to encrypt private key
const salt = CryptoJS.lib.WordArray.random(128 / 8);
const aes = CryptoJS.PBKDF2('testpassword', salt, {
keySize: 256 / 32,
iterations: 1024,
});
// 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();
// encrypt private key
const iv = CryptoJS.lib.WordArray.random(128 / 8);
const privateKey = convertPem(crypto.getPrivateKey());
const enc = CryptoJS.AES.encrypt(privateKey, aes, { iv: iv });
const seal = {
passwordSalt: salt.toString(),
privateKeyIv: iv.toString(),
privateKeyEncrypted: enc.ciphertext.toString(CryptoJS.enc.Base64),
publicKey: convertPem(crypto.getPublicKey()),
}
console.log("SEAL:", seal);
},
logout: () => {
app.actions.logout();
navigate('/');

File diff suppressed because it is too large Load Diff