Skip to content

Commit

Permalink
Merge pull request #85 from subutai-io/gw-wallet
Browse files Browse the repository at this point in the history
GW wallet
  • Loading branch information
absidish authored Apr 9, 2019
2 parents d4822ee + 47fa585 commit 6050967
Show file tree
Hide file tree
Showing 38 changed files with 117,422 additions and 6,627 deletions.
2 changes: 1 addition & 1 deletion DevEnvironment.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Build instructions

If you don’t have grunt and bower installed, yet:
If you don’t have grunt and bower installed``, yet:

npm install -g grunt-cli bower

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "porto",
"version": "5.0.3",
"version": "6.0.0",
"description": "Porto is a browser extension library for Google Chrome,Firefox and Safari that allows to develop cross platform browser extension with ease.",
"license": "ALS",
"private": true,
Expand Down
5 changes: 3 additions & 2 deletions chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_ext_name__",
"version": "5.0.3",
"version_name": "5.0.3",
"version": "6.0.0",
"version_name": "6.0.0",
"description": "__MSG_ext_description__",
"homepage_url":"https://subutai.io",
"manifest_version": 2,
Expand Down Expand Up @@ -47,6 +47,7 @@
"common/ui/inline/framestyles.css",
"common/ui/inline/dialogs/encryptDialog.html",
"common/ui/inline/dialogs/signDialog.html",
"common/ui/inline/dialogs/gwSignDialog.html",
"common/ui/inline/dialogs/pubkeyDialog.html",
"common/ui/editor/editor.html",
"common/ui/options.html",
Expand Down
10 changes: 10 additions & 0 deletions common/lib/Web3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

define(function(require, exports) {

var Web3 = require('./web3');

var web3 = new Web3();

exports.web3 = web3;
});
78 changes: 64 additions & 14 deletions common/lib/controller/encrypt.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';

define(function(require, exports, module) {
define(function (require, exports, module) {

var sub = require('./sub.controller');
var uiLog = require('../uiLog');
var pwdCache = require('../pwdCache');
var Web3 = require('../web3');
var CryptoJS = require('../crypto-js');
var openpgp = require('openpgp');

function EncryptController(port) {
sub.SubController.call(this, port);
Expand All @@ -16,7 +20,24 @@ define(function(require, exports, module) {

EncryptController.prototype = Object.create(sub.SubController.prototype);

EncryptController.prototype.handlePortMessage = function(msg) {
function encryptPassword(password) {
return CryptoJS.AES.encrypt(password, password).toString();
}

function encryptPrivateKey(privateKey, addressPassword) {
return CryptoJS.AES.encrypt(privateKey, addressPassword).toString();
}

function decryptPassword(encryptedPassword, plainPassword) {
return CryptoJS.AES.decrypt(encryptedPassword, plainPassword).toString(CryptoJS.enc.Utf8);
}

function decryptPrivateKey(privateKey, addressPassword) {
return CryptoJS.AES.decrypt(privateKey, addressPassword).toString(CryptoJS.enc.Utf8);
}


EncryptController.prototype.handlePortMessage = function (msg) {
var that = this;
var localKeyring = this.keyring.getById(this.porto.LOCAL_KEYRING_ID);
//console.log('encrypt.controller::' + msg.event);
Expand All @@ -31,12 +52,20 @@ define(function(require, exports, module) {
break;
case 'sign-dialog-init':
var primary = localKeyring.getAttributes().primary_key;
this.porto.data.load('common/ui/inline/dialogs/templates/sign.html').then(function(content) {
this.porto.data.load('common/ui/inline/dialogs/templates/sign.html').then(function (content) {
var port = that.ports.sDialog;
port.postMessage({event: 'sign-dialog-content', data: content});
port.postMessage({event: 'signing-key-userids', keys: keys, primary: primary});
});
break;
case 'gw_sign-dialog-init':
var goodwillData = JSON.parse(window.localStorage.getItem("goodwill"));
this.porto.data.load('common/ui/inline/dialogs/templates/gwSign.html').then(function (content) {
var port = that.ports.gwsDialog;
port.postMessage({event: 'gw-sign-dialog-content', data: content});
port.postMessage({event: 'gw-signing-data', gwdata: goodwillData});
});
break;
case 'get-signing-keys':
that.ports.eFrame.postMessage({event: 'filter-relevant-key', keys: keys});
break;
Expand Down Expand Up @@ -67,7 +96,7 @@ define(function(require, exports, module) {
break;
case 'encrypt-dialog-init':
// send content
this.porto.data.load('common/ui/inline/dialogs/templates/encrypt.html').then(function(content) {
this.porto.data.load('common/ui/inline/dialogs/templates/encrypt.html').then(function (content) {
//console.log('content rendered', content);
that.ports.eDialog.postMessage({event: 'encrypt-dialog-content', data: content});
// get potential recipients from eFrame
Expand All @@ -84,7 +113,7 @@ define(function(require, exports, module) {
primary = primary && primary.toLowerCase();
}
if (this.recipientsCallback) {
this.recipientsCallback({ keys: userKeys, primary: primary });
this.recipientsCallback({keys: userKeys, primary: primary});
this.recipientsCallback = null;
} else {
this.ports.eDialog.postMessage({event: 'public-key-userids', keys: userKeys, primary: primary});
Expand All @@ -107,15 +136,15 @@ define(function(require, exports, module) {
this.signBuffer.keyringId = this.porto.LOCAL_KEYRING_ID;
this.pwdControl = sub.factory.get('pwdDialog');
this.pwdControl.unlockKey(this.signBuffer)
.then(function() {
.then(function () {
that.ports.eFrame.postMessage({
event: 'email-text',
type: msg.type,
action: 'sign',
fingerprint: msg.fingerprint
});
})
.catch(function(err) {
.catch(function (err) {
if (err.code = 'PWD_DIALOG_CANCEL') {
that.ports.eFrame.postMessage({event: 'sign-dialog-cancel'});
return;
Expand All @@ -124,34 +153,55 @@ define(function(require, exports, module) {
// TODO: propagate error to sign dialog
}
});

break;
case 'gw-sign-dialog-ok':
that.ports.eFrame.postMessage({event: 'gw-signed-message', message: msg});
break;
case 'eframe-email-text':
if (msg.action === 'encrypt') {
// TODO fix error while encrypting message, instead of passing three parameters to
// pgpMode.encryptMessage wrap it into one object with relevant keys
this.model.encryptMessage(msg.data, this.porto.LOCAL_KEYRING_ID, this.keyidBuffer)
.then(function(msg) {
.then(function (msg) {
that.ports.eFrame.postMessage({event: 'encrypted-message', message: msg});
})
.catch(function(error) {
.catch(function (error) {
console.log('model.encryptMessage() error', error);
});
} else if (msg.action === 'sign') {
var fingerprint = msg.fingerprint;
this.model.signMessage(msg.data, this.signBuffer.key)
.then(function(msg) {
.then(function (msg) {
that.ports.eFrame.postMessage({
event: 'signed-message',
message: msg,
fingerprint: fingerprint
});
})
.catch(function(error) {
.catch(function (error) {
console.log('model.signMessage() error', error);
});
} else {
throw new Error('Unknown eframe action:', msg.action);
}

var goodWillAddresses = JSON.parse(window.localStorage.getItem("goodwill"));

for (var i = 0; i < goodWillAddresses.length; i++) {
if (goodWillAddresses[i].id === this.signBuffer.key.primaryKey.fingerprint) {
var prKey = decryptPrivateKey(goodWillAddresses[i].private_key, this.signBuffer.password);

var web3 = new Web3();
var message = web3.eth.accounts.sign("Hello", prKey);

that.ports.eFrame.postMessage({
event: 'gw-signed-message',
message: JSON.stringify ({signature: message.signature, messageHash: message.messageHash, address: goodWillAddresses[i].address})
});
}
}

break;
case 'eframe-textarea-element':
var defaultEncoding = {};
Expand All @@ -174,11 +224,11 @@ define(function(require, exports, module) {
this.editorControl.encrypt({
initText: msg.text,
getRecipients: this.getRecipients.bind(this)
}, function(err, armored) {
}, function (err, armored) {
if (!err) {
// sanitize if content from plain text, rich text already sanitized by editor
if (that.prefs.data().general.editor_type == that.porto.PLAIN_TEXT) {
that.porto.util.parseHTML(armored, function(parsed) {
that.porto.util.parseHTML(armored, function (parsed) {
that.ports.eFrame.postMessage({event: 'set-editor-output', text: parsed});
});
} else {
Expand All @@ -198,7 +248,7 @@ define(function(require, exports, module) {
}
};

EncryptController.prototype.getRecipients = function(callback) {
EncryptController.prototype.getRecipients = function (callback) {
if (this.recipientsCallback) {
throw new Error('Waiting for recipients result.');
}
Expand Down
Loading

0 comments on commit 6050967

Please sign in to comment.