mirror of https://github.com/moparisthebest/mail
Merge pull request #41 from whiteout-io/dev/optional-passphrase
Dev/optional passphrase
This commit is contained in:
commit
d6c038d6fd
|
@ -127,11 +127,6 @@ define(function(require) {
|
||||||
console.log('IMAP reconnecting...');
|
console.log('IMAP reconnecting...');
|
||||||
// re-init client modules on error
|
// re-init client modules on error
|
||||||
self.onConnect(function(err) {
|
self.onConnect(function(err) {
|
||||||
if (!self._initialized) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('IMAP reconnect failed!', err);
|
console.error('IMAP reconnect failed!', err);
|
||||||
return;
|
return;
|
||||||
|
@ -398,15 +393,7 @@ define(function(require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect tcp clients on first startup
|
callback(null, keypair);
|
||||||
self.onConnect(function(err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, keypair);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,8 +2,7 @@ define(function(require) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var appController = require('js/app-controller'),
|
var appController = require('js/app-controller'),
|
||||||
errorUtil = require('js/util/error'),
|
errorUtil = require('js/util/error');
|
||||||
dl = require('js/util/download');
|
|
||||||
|
|
||||||
var LoginInitialCtrl = function($scope, $location) {
|
var LoginInitialCtrl = function($scope, $location) {
|
||||||
var emailDao = appController._emailDao,
|
var emailDao = appController._emailDao,
|
||||||
|
@ -53,12 +52,13 @@ define(function(require) {
|
||||||
return str.substring(0, 1).toLowerCase() + str.substring(1);
|
return str.substring(0, 1).toLowerCase() + str.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passphrase || passphrase.length < 10) {
|
if (!passphrase) {
|
||||||
$scope.passphraseMsg = 'Too short';
|
// no rating for empty passphrase
|
||||||
|
$scope.passphraseMsg = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SAME.test(passphrase)) {
|
if (passphrase.length < 8 || SAME.test(passphrase)) {
|
||||||
$scope.passphraseMsg = 'Very weak';
|
$scope.passphraseMsg = 'Very weak';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -85,14 +85,14 @@ define(function(require) {
|
||||||
var passphrase = $scope.state.passphrase,
|
var passphrase = $scope.state.passphrase,
|
||||||
confirmation = $scope.state.confirmation;
|
confirmation = $scope.state.confirmation;
|
||||||
|
|
||||||
if (!passphrase || passphrase !== confirmation) {
|
if (passphrase !== confirmation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.setState(states.PROCESSING);
|
$scope.setState(states.PROCESSING);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
emailDao.unlock({
|
emailDao.unlock({
|
||||||
passphrase: passphrase
|
passphrase: (passphrase) ? passphrase : undefined
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
$scope.setState(states.IDLE);
|
$scope.setState(states.IDLE);
|
||||||
|
@ -100,42 +100,12 @@ define(function(require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.setState(states.DONE);
|
$location.path('/desktop');
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.exportKeypair = function() {
|
|
||||||
// export keys from keychain
|
|
||||||
emailDao._crypto.exportKeys(function(err, keys) {
|
|
||||||
if (err) {
|
|
||||||
$scope.onError(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var id = keys.keyId.substring(8, keys.keyId.length);
|
|
||||||
dl.createDownload({
|
|
||||||
content: keys.publicKeyArmored + keys.privateKeyArmored,
|
|
||||||
filename: 'whiteout_mail_' + emailDao._account.emailAddress + '_' + id + '.asc',
|
|
||||||
contentType: 'text/plain'
|
|
||||||
}, onSave);
|
|
||||||
});
|
|
||||||
|
|
||||||
function onSave(err) {
|
|
||||||
if (err) {
|
|
||||||
$scope.onError(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$scope.proceed();
|
|
||||||
$scope.$apply();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.proceed = function() {
|
|
||||||
$location.path('/desktop');
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.setState = function(state) {
|
$scope.setState = function(state) {
|
||||||
$scope.state.ui = state;
|
$scope.state.ui = state;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,11 +17,6 @@ define(function(require) {
|
||||||
$scope.incorrect = false;
|
$scope.incorrect = false;
|
||||||
|
|
||||||
$scope.confirmPassphrase = function() {
|
$scope.confirmPassphrase = function() {
|
||||||
if (!$scope.passphrase) {
|
|
||||||
$scope.incorrect = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.incorrect = false;
|
$scope.incorrect = false;
|
||||||
unlockCrypto();
|
unlockCrypto();
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,7 +35,7 @@ define(function(require) {
|
||||||
|
|
||||||
// check if account needs to be selected
|
// check if account needs to be selected
|
||||||
if (!emailAddress) {
|
if (!emailAddress) {
|
||||||
firstLogin();
|
goTo('/add-account');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,23 +53,32 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function firstLogin() {
|
|
||||||
$location.path('/add-account');
|
|
||||||
$scope.$apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
function redirect(availableKeys) {
|
function redirect(availableKeys) {
|
||||||
// redirect if needed
|
// redirect if needed
|
||||||
if (typeof availableKeys === 'undefined') {
|
if (typeof availableKeys === 'undefined') {
|
||||||
// no public key available, start onboarding process
|
// no public key available, start onboarding process
|
||||||
$location.path('/login-initial');
|
goTo('/login-initial');
|
||||||
} else if (!availableKeys.privateKey) {
|
} else if (!availableKeys.privateKey) {
|
||||||
// no private key, import key
|
// no private key, import key
|
||||||
$location.path('/login-new-device');
|
goTo('/login-new-device');
|
||||||
} else {
|
} else {
|
||||||
// public and private key available, just login
|
// public and private key available, try empty passphrase
|
||||||
$location.path('/login-existing');
|
appController._emailDao.unlock({
|
||||||
|
keypair: availableKeys,
|
||||||
|
passphrase: undefined
|
||||||
|
}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
goTo('/login-existing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
goTo('/desktop');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function goTo(location) {
|
||||||
|
$location.path(location);
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,9 +19,6 @@ define(function(require) {
|
||||||
// attach global error handler
|
// attach global error handler
|
||||||
errorUtil.attachHandler($scope);
|
errorUtil.attachHandler($scope);
|
||||||
|
|
||||||
// app controller is initialized
|
|
||||||
appController._initialized = true;
|
|
||||||
|
|
||||||
emailDao = appController._emailDao;
|
emailDao = appController._emailDao;
|
||||||
outboxBo = appController._outboxBo;
|
outboxBo = appController._outboxBo;
|
||||||
|
|
||||||
|
@ -69,7 +66,21 @@ define(function(require) {
|
||||||
// init folders
|
// init folders
|
||||||
initFolders();
|
initFolders();
|
||||||
// select inbox as the current folder on init
|
// select inbox as the current folder on init
|
||||||
$scope.openFolder($scope.account.folders[0]);
|
if ($scope.account.folders && $scope.account.folders.length > 0) {
|
||||||
|
$scope.openFolder($scope.account.folders[0]);
|
||||||
|
}
|
||||||
|
// connect imap/smtp clients on first startup
|
||||||
|
appController.onConnect(function(err) {
|
||||||
|
if (err) {
|
||||||
|
$scope.onError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// select inbox if not yet selected
|
||||||
|
if (!$scope.state.nav.currentFolder) {
|
||||||
|
$scope.openFolder($scope.account.folders[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
// helper functions
|
// helper functions
|
||||||
|
|
|
@ -19,7 +19,7 @@ define(function(require) {
|
||||||
PGP.prototype.generateKeys = function(options, callback) {
|
PGP.prototype.generateKeys = function(options, callback) {
|
||||||
var userId;
|
var userId;
|
||||||
|
|
||||||
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize || typeof options.passphrase !== 'string') {
|
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Crypto init failed. Not all options set!'
|
errMsg: 'Crypto init failed. Not all options set!'
|
||||||
});
|
});
|
||||||
|
@ -119,7 +119,7 @@ define(function(require) {
|
||||||
var pubKeyId, privKeyId, self = this;
|
var pubKeyId, privKeyId, self = this;
|
||||||
|
|
||||||
// check options
|
// check options
|
||||||
if (typeof options.passphrase !== 'string' || !options.privateKeyArmored || !options.publicKeyArmored) {
|
if (!options.privateKeyArmored || !options.publicKeyArmored) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Importing keys failed. Not all options set!'
|
errMsg: 'Importing keys failed. Not all options set!'
|
||||||
});
|
});
|
||||||
|
@ -184,6 +184,55 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the passphrase of an ascii armored private key.
|
||||||
|
*/
|
||||||
|
PGP.prototype.changePassphrase = function(options, callback) {
|
||||||
|
var privKey, packets;
|
||||||
|
|
||||||
|
if (!options.privateKeyArmored ||
|
||||||
|
typeof options.oldPassphrase !== 'string' ||
|
||||||
|
typeof options.newPassphrase !== 'string') {
|
||||||
|
callback({
|
||||||
|
errMsg: 'Could not export keys!'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read armored key
|
||||||
|
try {
|
||||||
|
privKey = openpgp.key.readArmored(options.privateKeyArmored).keys[0];
|
||||||
|
} catch (e) {
|
||||||
|
callback({
|
||||||
|
errMsg: 'Importing key failed. Parsing error!'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrypt private key with passphrase
|
||||||
|
if (!privKey.decrypt(options.oldPassphrase)) {
|
||||||
|
callback({
|
||||||
|
errMsg: 'Old passphrase incorrect!'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// encrypt key with new passphrase
|
||||||
|
try {
|
||||||
|
packets = privKey.getAllKeyPackets();
|
||||||
|
for (var i = 0; i < packets.length; i++) {
|
||||||
|
packets[i].encrypt(options.newPassphrase);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
callback({
|
||||||
|
errMsg: 'Setting new passphrase failed!'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, privKey.armor());
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt and sign a pgp message for a list of receivers
|
* Encrypt and sign a pgp message for a list of receivers
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -74,6 +74,7 @@ define(function(require) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self._account.folders = folders;
|
self._account.folders = folders;
|
||||||
|
|
||||||
callback(null, keypair);
|
callback(null, keypair);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -114,13 +115,6 @@ define(function(require) {
|
||||||
// set status to online
|
// set status to online
|
||||||
self._account.online = true;
|
self._account.online = true;
|
||||||
|
|
||||||
// check memory
|
|
||||||
if (self._account.folders) {
|
|
||||||
// no need to init folder again on connect... already in memory
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// init folders
|
// init folders
|
||||||
self._imapListFolders(function(err, folders) {
|
self._imapListFolders(function(err, folders) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -6,28 +6,22 @@
|
||||||
<div class="content" ng-switch on="state.ui">
|
<div class="content" ng-switch on="state.ui">
|
||||||
|
|
||||||
<div ng-switch-when="1">
|
<div ng-switch-when="1">
|
||||||
<p><b>Generate PGP key.</b> Choose a passphrase to protect your new key. If you forget it at a later time you will not be able to read past messages.</p><p>Alternatively you can also <a href="#" ng-click="$event.preventDefault(); importKey()">import an existing PGP key</a>.</p>
|
<p><b>Generate PGP key.</b> You can set a passphrase to protect your key on disk. This must be entered everytime you start the app. For no passphrase just press continue.</p><p>Alternatively you can also <a href="#" ng-click="$event.preventDefault(); importKey()">import an existing PGP key</a>.</p>
|
||||||
<form>
|
<form>
|
||||||
<div>
|
<div>
|
||||||
<label class="input-error-message" ng-class="{'passphrase-label-ok': passphraseRating >= 2}">{{passphraseMsg}}</label><br>
|
<label class="input-error-message" ng-class="{'passphrase-label-ok': passphraseRating >= 2}">{{passphraseMsg}}</label><br>
|
||||||
<input class="input-text" ng-class="{'input-text-error': passphraseRating < 2}" type="password" ng-model="state.passphrase" ng-change="checkPassphraseQuality()" placeholder="Enter passphrase" tabindex="1" focus-me="true">
|
<input class="input-text" type="password" ng-model="state.passphrase" ng-change="checkPassphraseQuality()" placeholder="Enter passphrase" tabindex="1" focus-me="true">
|
||||||
<input class="input-text" type="password" ng-model="state.confirmation" ng-class="{'input-text-error': state.confirmation && state.confirmation !== state.passphrase}" placeholder="Confirm passphrase" tabindex="2">
|
<input class="input-text" type="password" ng-model="state.confirmation" ng-class="{'input-text-error': (state.confirmation || state.passphrase) && state.confirmation !== state.passphrase}" placeholder="Confirm passphrase" tabindex="2">
|
||||||
<span class="popover-info" data-icon-append="" popover="#passphrase-info"></span>
|
<span class="popover-info" data-icon-append="" popover="#passphrase-info"></span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button type="submit" ng-click="confirmPassphrase()" class="btn" ng-disabled="!state.passphrase || passphraseRating < 2 || state.passphrase !== state.confirmation" tabindex="3">Generate keypair</button>
|
<button type="submit" ng-click="confirmPassphrase()" class="btn" ng-disabled="(state.confirmation || state.passphrase) && state.confirmation !== state.passphrase" tabindex="3">Continue</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-switch-when="2">
|
<div ng-switch-when="2">
|
||||||
<p><b>Generating keypair.</b> Please stand by. This can take a while...</p>
|
<p><b>Generating key.</b> Please stand by. This can take a while...</p>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div ng-switch-when="4">
|
|
||||||
<p><b>Keypair generated.</b> Your personal keypair has been generated. You can export it (e.g. to a USB flash drive) to setup Whiteout Mail on another computer or as a backup.</p>
|
|
||||||
<button ng-click="exportKeypair()" class="btn" tabindex="4">Export now</button>
|
|
||||||
<button ng-click="proceed()" class="btn btn-alt" tabindex="5">Do it later</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div><!--/content-->
|
</div><!--/content-->
|
||||||
|
@ -43,9 +37,8 @@
|
||||||
<div class="arrow"></div>
|
<div class="arrow"></div>
|
||||||
<div class="popover-title"><b>What is this?</b></div>
|
<div class="popover-title"><b>What is this?</b></div>
|
||||||
<div class="popover-content">
|
<div class="popover-content">
|
||||||
<p>A passphrase is like a password but longer.</p>
|
<p>A passphrase is like a password that protects your PGP key.</p>
|
||||||
<p>If your device is lost or stolen the passphrase protects the contents of your mailbox.</p>
|
<p>If your device is lost or stolen the passphrase protects the contents of your mailbox.</p>
|
||||||
<p>It must be at least 10 characters long and contain one special character or digit.</p>
|
|
||||||
<p>You cannot change your passphrase at a later time.</p>
|
<p>You cannot change your passphrase at a later time.</p>
|
||||||
</div>
|
</div>
|
||||||
</div><!--/.popover-->
|
</div><!--/.popover-->
|
|
@ -291,32 +291,11 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail due to error in onConnect', function(done) {
|
|
||||||
devicestorageStub.init.yields();
|
|
||||||
updateHandlerStub.update.yields();
|
|
||||||
emailDaoStub.init.yields();
|
|
||||||
|
|
||||||
onConnectStub.yields({});
|
|
||||||
|
|
||||||
controller.init({
|
|
||||||
emailAddress: emailAddress
|
|
||||||
}, function(err) {
|
|
||||||
expect(err).to.exist;
|
|
||||||
expect(updateHandlerStub.update.calledOnce).to.be.true;
|
|
||||||
expect(emailDaoStub.init.calledOnce).to.be.true;
|
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
|
||||||
expect(onConnectStub.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should work and return a keypair', function(done) {
|
it('should work and return a keypair', function(done) {
|
||||||
devicestorageStub.init.withArgs(emailAddress).yields();
|
devicestorageStub.init.withArgs(emailAddress).yields();
|
||||||
emailDaoStub.init.yields(null, {});
|
emailDaoStub.init.yields(null, {});
|
||||||
updateHandlerStub.update.yields();
|
updateHandlerStub.update.yields();
|
||||||
|
|
||||||
onConnectStub.yields();
|
|
||||||
|
|
||||||
controller.init({
|
controller.init({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
}, function(err, keypair) {
|
}, function(err, keypair) {
|
||||||
|
@ -325,7 +304,6 @@ define(function(require) {
|
||||||
expect(updateHandlerStub.update.calledOnce).to.be.true;
|
expect(updateHandlerStub.update.calledOnce).to.be.true;
|
||||||
expect(emailDaoStub.init.calledOnce).to.be.true;
|
expect(emailDaoStub.init.calledOnce).to.be.true;
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
||||||
expect(onConnectStub.calledOnce).to.be.true;
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -133,14 +133,18 @@ define(function(require) {
|
||||||
dao._account.folders = [];
|
dao._account.folders = [];
|
||||||
imapClientStub.login.yields();
|
imapClientStub.login.yields();
|
||||||
|
|
||||||
|
var listFolderStub = sinon.stub(dao, '_imapListFolders').yields(null, []);
|
||||||
|
|
||||||
dao.onConnect({
|
dao.onConnect({
|
||||||
imapClient: imapClientStub,
|
imapClient: imapClientStub,
|
||||||
pgpMailer: pgpMailerStub
|
pgpMailer: pgpMailerStub
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
expect(dao._account.online).to.be.true;
|
expect(dao._account.online).to.be.true;
|
||||||
|
expect(dao._account.folders).to.deep.equal([]);
|
||||||
expect(dao._imapClient).to.equal(dao._imapClient);
|
expect(dao._imapClient).to.equal(dao._imapClient);
|
||||||
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
||||||
|
listFolderStub.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -306,23 +310,7 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when folder already initiated', function(done) {
|
it('should work', function(done) {
|
||||||
dao._account.folders = [];
|
|
||||||
imapLoginStub.yields();
|
|
||||||
|
|
||||||
dao.onConnect({
|
|
||||||
imapClient: imapClientStub,
|
|
||||||
pgpMailer: pgpMailerStub
|
|
||||||
}, function(err) {
|
|
||||||
expect(err).to.not.exist;
|
|
||||||
expect(dao._account.online).to.be.true;
|
|
||||||
expect(dao._imapClient).to.equal(dao._imapClient);
|
|
||||||
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should work when folder not yet initiated', function(done) {
|
|
||||||
var folders = [];
|
var folders = [];
|
||||||
imapLoginStub.yields();
|
imapLoginStub.yields();
|
||||||
imapListFoldersStub.yields(null, folders);
|
imapListFoldersStub.yields(null, folders);
|
||||||
|
|
|
@ -60,13 +60,55 @@ define(function(require) {
|
||||||
initStub.restore();
|
initStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should forward to existing user login', function(done) {
|
it('should forward directly to desktop for empty passphrase', function(done) {
|
||||||
startAppStub.yields();
|
var testKeys = {
|
||||||
getEmailAddressStub.yields(null, emailAddress);
|
|
||||||
initStub.yields(null, {
|
|
||||||
privateKey: 'a',
|
privateKey: 'a',
|
||||||
publicKey: 'b'
|
publicKey: 'b'
|
||||||
|
};
|
||||||
|
|
||||||
|
startAppStub.yields();
|
||||||
|
getEmailAddressStub.yields(null, emailAddress);
|
||||||
|
initStub.yields(null, testKeys);
|
||||||
|
|
||||||
|
emailDaoMock.unlock.withArgs({
|
||||||
|
keypair: testKeys,
|
||||||
|
passphrase: undefined
|
||||||
|
}).yields();
|
||||||
|
|
||||||
|
angular.module('logintest', []);
|
||||||
|
mocks.module('logintest');
|
||||||
|
mocks.inject(function($controller, $rootScope, $location) {
|
||||||
|
location = $location;
|
||||||
|
sinon.stub(location, 'path', function(path) {
|
||||||
|
expect(path).to.equal('/desktop');
|
||||||
|
expect(startAppStub.calledOnce).to.be.true;
|
||||||
|
expect(checkForUpdateStub.calledOnce).to.be.true;
|
||||||
|
expect(getEmailAddressStub.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
scope.state = {};
|
||||||
|
ctrl = $controller(LoginCtrl, {
|
||||||
|
$location: location,
|
||||||
|
$scope: scope
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should forward to existing user login', function(done) {
|
||||||
|
var testKeys = {
|
||||||
|
privateKey: 'a',
|
||||||
|
publicKey: 'b'
|
||||||
|
};
|
||||||
|
|
||||||
|
startAppStub.yields();
|
||||||
|
getEmailAddressStub.yields(null, emailAddress);
|
||||||
|
initStub.yields(null, testKeys);
|
||||||
|
|
||||||
|
emailDaoMock.unlock.withArgs({
|
||||||
|
keypair: testKeys,
|
||||||
|
passphrase: undefined
|
||||||
|
}).yields({});
|
||||||
|
|
||||||
angular.module('logintest', []);
|
angular.module('logintest', []);
|
||||||
mocks.module('logintest');
|
mocks.module('logintest');
|
||||||
|
|
|
@ -5,7 +5,6 @@ define(function(require) {
|
||||||
angular = require('angular'),
|
angular = require('angular'),
|
||||||
mocks = require('angularMocks'),
|
mocks = require('angularMocks'),
|
||||||
LoginInitialCtrl = require('js/controller/login-initial'),
|
LoginInitialCtrl = require('js/controller/login-initial'),
|
||||||
dl = require('js/util/download'),
|
|
||||||
PGP = require('js/crypto/pgp'),
|
PGP = require('js/crypto/pgp'),
|
||||||
EmailDAO = require('js/dao/email-dao'),
|
EmailDAO = require('js/dao/email-dao'),
|
||||||
appController = require('js/app-controller');
|
appController = require('js/app-controller');
|
||||||
|
@ -54,8 +53,6 @@ define(function(require) {
|
||||||
|
|
||||||
describe('initial state', function() {
|
describe('initial state', function() {
|
||||||
it('should be well defined', function() {
|
it('should be well defined', function() {
|
||||||
expect(scope.proceed).to.exist;
|
|
||||||
expect(scope.exportKeypair).to.exist;
|
|
||||||
expect(scope.confirmPassphrase).to.exist;
|
expect(scope.confirmPassphrase).to.exist;
|
||||||
expect(scope.state.ui).to.equal(1);
|
expect(scope.state.ui).to.equal(1);
|
||||||
});
|
});
|
||||||
|
@ -63,10 +60,10 @@ define(function(require) {
|
||||||
|
|
||||||
describe('check passphrase quality', function() {
|
describe('check passphrase quality', function() {
|
||||||
it('should be too short', function() {
|
it('should be too short', function() {
|
||||||
scope.state.passphrase = '&§DG36abc';
|
scope.state.passphrase = '&§DG36';
|
||||||
scope.checkPassphraseQuality();
|
scope.checkPassphraseQuality();
|
||||||
|
|
||||||
expect(scope.passphraseMsg).to.equal('Too short');
|
expect(scope.passphraseMsg).to.equal('Very weak');
|
||||||
expect(scope.passphraseRating).to.equal(0);
|
expect(scope.passphraseRating).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -112,16 +109,12 @@ define(function(require) {
|
||||||
emailDaoMock.unlock.withArgs({
|
emailDaoMock.unlock.withArgs({
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).yields();
|
}).yields();
|
||||||
setStateStub = sinon.stub(scope, 'setState', function(state) {
|
|
||||||
if (setStateStub.calledOnce) {
|
scope.$apply = function() {
|
||||||
expect(state).to.equal(2);
|
expect(location.$$path).to.equal('/desktop');
|
||||||
} else if (setStateStub.calledTwice) {
|
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
||||||
expect(state).to.equal(4);
|
done();
|
||||||
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
};
|
||||||
scope.setState.restore();
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
scope.confirmPassphrase();
|
||||||
});
|
});
|
||||||
|
@ -139,6 +132,7 @@ define(function(require) {
|
||||||
emailDaoMock.unlock.withArgs({
|
emailDaoMock.unlock.withArgs({
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).yields(new Error('asd'));
|
}).yields(new Error('asd'));
|
||||||
|
|
||||||
setStateStub = sinon.stub(scope, 'setState', function(state) {
|
setStateStub = sinon.stub(scope, 'setState', function(state) {
|
||||||
if (setStateStub.calledOnce) {
|
if (setStateStub.calledOnce) {
|
||||||
expect(state).to.equal(2);
|
expect(state).to.equal(2);
|
||||||
|
@ -154,64 +148,5 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('proceed', function() {
|
|
||||||
it('should forward', function() {
|
|
||||||
var locationSpy = sinon.spy(location, 'path');
|
|
||||||
|
|
||||||
scope.proceed();
|
|
||||||
|
|
||||||
expect(locationSpy.calledWith('/desktop')).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('export keypair', function() {
|
|
||||||
it('should work', function() {
|
|
||||||
var locationSpy, createDownloadMock;
|
|
||||||
|
|
||||||
createDownloadMock = sinon.stub(dl, 'createDownload');
|
|
||||||
cryptoMock.exportKeys.yields(null, {
|
|
||||||
publicKeyArmored: 'a',
|
|
||||||
privateKeyArmored: 'b',
|
|
||||||
keyId: keyId
|
|
||||||
});
|
|
||||||
createDownloadMock.withArgs(sinon.match(function(arg) {
|
|
||||||
return arg.content === 'ab' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
|
||||||
})).yields();
|
|
||||||
|
|
||||||
locationSpy = sinon.spy(location, 'path');
|
|
||||||
|
|
||||||
scope.exportKeypair();
|
|
||||||
|
|
||||||
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
|
||||||
expect(createDownloadMock.calledOnce).to.be.true;
|
|
||||||
expect(locationSpy.calledWith('/desktop')).to.be.true;
|
|
||||||
dl.createDownload.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not work when download fails', function() {
|
|
||||||
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
|
||||||
cryptoMock.exportKeys.yields(null, {
|
|
||||||
publicKeyArmored: 'a',
|
|
||||||
privateKeyArmored: 'b',
|
|
||||||
keyId: keyId
|
|
||||||
});
|
|
||||||
createDownloadMock.yields({
|
|
||||||
errMsg: 'snafu.'
|
|
||||||
});
|
|
||||||
scope.exportKeypair();
|
|
||||||
|
|
||||||
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
|
||||||
expect(createDownloadMock.calledOnce).to.be.true;
|
|
||||||
dl.createDownload.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not work when export fails', function() {
|
|
||||||
cryptoMock.exportKeys.yields(new Error('snafu.'));
|
|
||||||
|
|
||||||
scope.exportKeypair();
|
|
||||||
|
|
||||||
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -98,14 +98,6 @@ define(function(require) {
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not do anything without passphrase', function() {
|
|
||||||
scope.state.passphrase = '';
|
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
expect(scope.incorrect).to.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not work when keypair upload fails', function() {
|
it('should not work when keypair upload fails', function() {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
|
|
|
@ -120,6 +120,28 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Change passphrase of private key', function() {
|
||||||
|
it('should work', function(done) {
|
||||||
|
pgp.changePassphrase({
|
||||||
|
privateKeyArmored: privkey,
|
||||||
|
oldPassphrase: passphrase,
|
||||||
|
newPassphrase: 'yxcv'
|
||||||
|
}, function(err, reEncryptedKey) {
|
||||||
|
expect(err).to.not.exist;
|
||||||
|
expect(reEncryptedKey).to.exist;
|
||||||
|
|
||||||
|
pgp.importKeys({
|
||||||
|
passphrase: 'yxcv',
|
||||||
|
privateKeyArmored: reEncryptedKey,
|
||||||
|
publicKeyArmored: pubkey
|
||||||
|
}, function(err) {
|
||||||
|
expect(err).to.not.exist;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Encrypt/Sign/Decrypt/Verify', function() {
|
describe('Encrypt/Sign/Decrypt/Verify', function() {
|
||||||
var message = 'asdfs\n\nThursday, Nov 21, 2013 7:38 PM asdf@example.com wrote:\n' +
|
var message = 'asdfs\n\nThursday, Nov 21, 2013 7:38 PM asdf@example.com wrote:\n' +
|
||||||
'> asdf\n' +
|
'> asdf\n' +
|
||||||
|
|
Loading…
Reference in New Issue