Initial encryption test is working on Chrome and iOS.
This commit is contained in:
parent
7209800b3c
commit
e215ecfb52
4 changed files with 145 additions and 7 deletions
10
Gruntfile.js
10
Gruntfile.js
|
|
@ -175,6 +175,16 @@ module.exports = function(grunt) {
|
||||||
'src/js/trezor-url.js',
|
'src/js/trezor-url.js',
|
||||||
'bower_components/trezor-connect/connect.js',
|
'bower_components/trezor-connect/connect.js',
|
||||||
'node_modules/bezier-easing/dist/bezier-easing.min.js',
|
'node_modules/bezier-easing/dist/bezier-easing.min.js',
|
||||||
|
|
||||||
|
'bower_components/crypto-js/core.js',
|
||||||
|
'bower_components/crypto-js/enc-base64.js',
|
||||||
|
'bower_components/crypto-js/hmac.js',
|
||||||
|
'bower_components/crypto-js/md5.js',
|
||||||
|
'bower_components/crypto-js/sha1.js',
|
||||||
|
'bower_components/crypto-js/evpkdf.js',
|
||||||
|
'bower_components/crypto-js/cipher-core.js',
|
||||||
|
'bower_components/crypto-js/aes.js',
|
||||||
|
|
||||||
'node_modules/cordova-plugin-qrscanner/dist/cordova-plugin-qrscanner-lib.min.js'
|
'node_modules/cordova-plugin-qrscanner/dist/cordova-plugin-qrscanner-lib.min.js'
|
||||||
],
|
],
|
||||||
dest: 'www/js/app.js'
|
dest: 'www/js/app.js'
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
"angular-gettext": "2.2.1",
|
"angular-gettext": "2.2.1",
|
||||||
"angular-moment": "0.10.1",
|
"angular-moment": "0.10.1",
|
||||||
"angular-qrcode": "bitpay/angular-qrcode#~6.3.0",
|
"angular-qrcode": "bitpay/angular-qrcode#~6.3.0",
|
||||||
|
"crypto-js": "^3.1.9",
|
||||||
"ionic": "https://github.com/ionic-team/ionic-v1.git",
|
"ionic": "https://github.com/ionic-team/ionic-v1.git",
|
||||||
"moment": "2.10.3",
|
"moment": "2.10.3",
|
||||||
"ng-lodash": "0.2.3",
|
"ng-lodash": "0.2.3",
|
||||||
|
|
|
||||||
86
src/js/services/encryptionService.js
Normal file
86
src/js/services/encryptionService.js
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services').factory('encryptionService', function($log) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
//lazy creation of cipher and decipher?
|
||||||
|
|
||||||
|
// need a function to get the key
|
||||||
|
var password = 'password';
|
||||||
|
|
||||||
|
function _getGetOrCreateKey() {
|
||||||
|
|
||||||
|
//crytpo.scrypt()
|
||||||
|
//crypto.createCipheriv()
|
||||||
|
};
|
||||||
|
|
||||||
|
function encryptUsingcrypto(str) {
|
||||||
|
var cipher = crypto.createCipher('aes256', password);
|
||||||
|
|
||||||
|
cipher.on('readable', () => {
|
||||||
|
var data = cipher.read();
|
||||||
|
if (data) {
|
||||||
|
encrypted += data.toString('hex');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cipher.on('end', () => {
|
||||||
|
console.log('Encrypted 1: ' + encrypted);
|
||||||
|
//cb();
|
||||||
|
});
|
||||||
|
|
||||||
|
//cipher.write(str);
|
||||||
|
cipher.write(str);
|
||||||
|
cipher.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
function encryptUsingCryptoJS(str) {
|
||||||
|
var ciphertext = CryptoJS.AES.encrypt(str, password);
|
||||||
|
$log.debug('cipherText: ' + ciphertext);
|
||||||
|
}
|
||||||
|
|
||||||
|
root.encrypt = function(str, cb) {
|
||||||
|
$log.debug('*** crypto exists: ' + !!crypto);
|
||||||
|
$log.debug('*** CryptoJS exists: ' + !!CryptoJS);
|
||||||
|
|
||||||
|
encryptUsingCryptoJS('I am a secret.');
|
||||||
|
|
||||||
|
/*
|
||||||
|
// var ciphertext = CryptoJS.AES.encrypt(str, password);
|
||||||
|
var cipher = crypto.createCipher('aes256', password);
|
||||||
|
|
||||||
|
cipher.on('readable', () => {
|
||||||
|
var data = cipher.read();
|
||||||
|
if (data) {
|
||||||
|
encrypted += data.toString('hex');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cipher.on('end', () => {
|
||||||
|
console.log('Encrypted: ' + encrypted);
|
||||||
|
//cb();
|
||||||
|
});
|
||||||
|
|
||||||
|
//cipher.write(str);
|
||||||
|
cipher.write('I am secret');
|
||||||
|
cipher.end();
|
||||||
|
*/
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
root.encryptedObjectFromString = function(str) {
|
||||||
|
try {
|
||||||
|
var parsed = JSON.parse(str);
|
||||||
|
} catch(e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.encryptionVersion) {
|
||||||
|
return parsed;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('storageService', function(appConfigService, logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
|
.factory('storageService', function(appConfigService, encryptionService, logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
var storage;
|
var storage;
|
||||||
|
|
@ -32,7 +32,7 @@ angular.module('copayApp.services')
|
||||||
// This is only used in Copay, we used to encrypt profile
|
// This is only used in Copay, we used to encrypt profile
|
||||||
// using device's UUID.
|
// using device's UUID.
|
||||||
|
|
||||||
var decryptOnMobile = function(text, cb) {
|
var copayDecryptOnMobile = function(text, cb) {
|
||||||
var json;
|
var json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(text);
|
json = JSON.parse(text);
|
||||||
|
|
@ -121,11 +121,11 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.storeProfile = function(profile, cb) {
|
root.storeProfile = function(profile, cb) {
|
||||||
var profileString = profile.toObj();
|
var profileString = profile.toObj();
|
||||||
if (platformInfo.isNW) {
|
//if (platformInfo.isNW) {
|
||||||
storage.set('profile', profileString, cb);
|
storage.set('profile', profileString, cb);
|
||||||
} else {
|
//} else {
|
||||||
secureStorageService.set('profile', profileString, cb);
|
// secureStorageService.set('profile', profileString, cb);
|
||||||
}
|
//}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,7 +150,7 @@ angular.module('copayApp.services')
|
||||||
return cb(null, null);
|
return cb(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
decryptOnMobile(profileStr, function(decryptErr, decryptedStr) {
|
copayDecryptOnMobile(profileStr, function(decryptErr, decryptedStr) {
|
||||||
if (decryptErr) return cb(decryptErr, null);
|
if (decryptErr) return cb(decryptErr, null);
|
||||||
var profile;
|
var profile;
|
||||||
try {
|
try {
|
||||||
|
|
@ -205,6 +205,46 @@ angular.module('copayApp.services')
|
||||||
* @param {getProfileCallback} cb
|
* @param {getProfileCallback} cb
|
||||||
*/
|
*/
|
||||||
root.getProfile = function(cb) {
|
root.getProfile = function(cb) {
|
||||||
|
$log.debug('getProfile()');
|
||||||
|
storage.get('profile', function onProfileRetrieved(getErr, profileStr){
|
||||||
|
if (getErr) {
|
||||||
|
$log.error(getErr);
|
||||||
|
return cb(getErr, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!profileStr) {
|
||||||
|
$log.debug('No string loaded, returning nothing.');
|
||||||
|
return cb(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
var encryptedProfile = encryptionService.encryptedObjectFromString(profileStr);
|
||||||
|
if (!encryptedProfile) {
|
||||||
|
|
||||||
|
copayDecryptOnMobile(profileStr, function(decryptErr, decryptedStr) {
|
||||||
|
if (decryptErr) return cb(decryptErr, null);
|
||||||
|
var profile;
|
||||||
|
try {
|
||||||
|
profile = Profile.fromString(decryptedStr);
|
||||||
|
} catch (e) {
|
||||||
|
$log.debug('Could not read profile:', e);
|
||||||
|
return cb(new Error('Could not read profile.'), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedProfile = encryptionService.encrypt(profile);
|
||||||
|
$log.debug('encryptedProfile');
|
||||||
|
|
||||||
|
//cb(null, profile)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$log.debug('profile was encrypted.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
if (platformInfo.isNW) {
|
if (platformInfo.isNW) {
|
||||||
storage.get('profile', function(getErr, getStr) {
|
storage.get('profile', function(getErr, getStr) {
|
||||||
_onOldProfileRetrieved(getErr, getStr, cb);
|
_onOldProfileRetrieved(getErr, getStr, cb);
|
||||||
|
|
@ -248,6 +288,7 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setFeedbackInfo = function(feedbackValues, cb) {
|
root.setFeedbackInfo = function(feedbackValues, cb) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue