mirror of https://github.com/moparisthebest/mail
Browse Source
* Add copy and paste private key import during setup * Simplify key setup screen (login-initial) import option * Make checkbox background color whitemaster

40 changed files with 962 additions and 2142 deletions
@ -1,155 +0,0 @@
@@ -1,155 +0,0 @@
|
||||
'use strict'; |
||||
|
||||
var util = require('crypto-lib').util; |
||||
|
||||
var PrivateKeyUploadCtrl = function($scope, $q, keychain, pgp, dialog, auth) { |
||||
|
||||
//
|
||||
// scope state
|
||||
//
|
||||
|
||||
$scope.state.privateKeyUpload = { |
||||
toggle: function(to) { |
||||
// open lightbox
|
||||
$scope.state.lightbox = (to) ? 'privatekey-upload' : undefined; |
||||
if (!to) { |
||||
return; |
||||
} |
||||
|
||||
// show syncing status
|
||||
$scope.step = 4; |
||||
// check if key is already synced
|
||||
return $scope.checkServerForKey().then(function(privateKeySynced) { |
||||
if (privateKeySynced) { |
||||
// close lightbox
|
||||
$scope.state.lightbox = undefined; |
||||
// show message
|
||||
return dialog.info({ |
||||
title: 'Info', |
||||
message: 'Your PGP key has already been synced.' |
||||
}); |
||||
} |
||||
|
||||
// show sync ui if key is not synced
|
||||
$scope.displayUploadUi(); |
||||
}); |
||||
} |
||||
}; |
||||
|
||||
//
|
||||
// scope functions
|
||||
//
|
||||
|
||||
$scope.checkServerForKey = function() { |
||||
var keyParams = pgp.getKeyParams(); |
||||
|
||||
return $q(function(resolve) { |
||||
resolve(); |
||||
|
||||
}).then(function() { |
||||
return keychain.hasPrivateKey({ |
||||
userId: keyParams.userId, |
||||
keyId: keyParams._id |
||||
}); |
||||
|
||||
}).then(function(privateKeySynced) { |
||||
return privateKeySynced ? privateKeySynced : undefined; |
||||
|
||||
}).catch(dialog.error); |
||||
}; |
||||
|
||||
$scope.displayUploadUi = function() { |
||||
// go to step 1
|
||||
$scope.step = 1; |
||||
// generate new code for the user
|
||||
$scope.code = util.randomString(24); |
||||
$scope.displayedCode = $scope.code.slice(0, 4) + '-' + $scope.code.slice(4, 8) + '-' + $scope.code.slice(8, 12) + '-' + $scope.code.slice(12, 16) + '-' + $scope.code.slice(16, 20) + '-' + $scope.code.slice(20, 24); |
||||
|
||||
// clear input field of any previous artifacts
|
||||
$scope.inputCode = ''; |
||||
}; |
||||
|
||||
$scope.verifyCode = function() { |
||||
if ($scope.inputCode.toUpperCase() !== $scope.code) { |
||||
var err = new Error('The code does not match. Please go back and check the generated code.'); |
||||
dialog.error(err); |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
$scope.setDeviceName = function() { |
||||
return $q(function(resolve) { |
||||
resolve(); |
||||
|
||||
}).then(function() { |
||||
return keychain.setDeviceName($scope.deviceName); |
||||
}); |
||||
}; |
||||
|
||||
$scope.encryptAndUploadKey = function() { |
||||
var userId = auth.emailAddress; |
||||
var code = $scope.code; |
||||
|
||||
// register device to keychain service
|
||||
return $q(function(resolve) { |
||||
resolve(); |
||||
|
||||
}).then(function() { |
||||
// register the device
|
||||
return keychain.registerDevice({ |
||||
userId: userId |
||||
}); |
||||
|
||||
}).then(function() { |
||||
// encrypt private PGP key using code and upload
|
||||
return keychain.uploadPrivateKey({ |
||||
userId: userId, |
||||
code: code |
||||
}); |
||||
|
||||
}).catch(dialog.error); |
||||
}; |
||||
|
||||
$scope.goBack = function() { |
||||
if ($scope.step > 1) { |
||||
$scope.step--; |
||||
} |
||||
}; |
||||
|
||||
$scope.goForward = function() { |
||||
if ($scope.step < 2) { |
||||
$scope.step++; |
||||
return; |
||||
} |
||||
|
||||
if ($scope.step === 2 && $scope.verifyCode()) { |
||||
$scope.step++; |
||||
return; |
||||
} |
||||
|
||||
if ($scope.step === 3) { |
||||
// set device name to local storage
|
||||
return $scope.setDeviceName().then(function() { |
||||
// show spinner
|
||||
$scope.step++; |
||||
// init key sync
|
||||
return $scope.encryptAndUploadKey(); |
||||
|
||||
}).then(function() { |
||||
// close sync dialog
|
||||
$scope.state.privateKeyUpload.toggle(false); |
||||
// show success message
|
||||
dialog.info({ |
||||
title: 'Success', |
||||
message: 'Whiteout Keychain setup successful!' |
||||
}); |
||||
|
||||
}).catch(dialog.error); |
||||
} |
||||
}; |
||||
|
||||
}; |
||||
|
||||
module.exports = PrivateKeyUploadCtrl; |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
'use strict'; |
||||
|
||||
var util = require('crypto-lib').util; |
||||
|
||||
var LoginPrivateKeyUploadCtrl = function($scope, $location, $routeParams, $q, auth, privateKey) { |
||||
!$routeParams.dev && !auth.isInitialized() && $location.path('/'); // init app
|
||||
|
||||
//
|
||||
// scope state
|
||||
//
|
||||
|
||||
// go to step 1
|
||||
$scope.step = 1; |
||||
// generate new code for the user
|
||||
$scope.code = util.randomString(24); |
||||
$scope.displayedCode = $scope.code.replace(/.{4}/g, "$&-").replace(/-$/, ''); |
||||
// clear input field of any previous artifacts
|
||||
$scope.inputCode = ''; |
||||
|
||||
//
|
||||
// scope functions
|
||||
//
|
||||
|
||||
$scope.encryptAndUploadKey = function() { |
||||
if ($scope.inputCode.toUpperCase() !== $scope.code) { |
||||
$scope.errMsg = 'The code does not match. Please go back and check the generated code.'; |
||||
return; |
||||
} |
||||
|
||||
// register device to keychain service
|
||||
return $q(function(resolve) { |
||||
$scope.busy = true; |
||||
$scope.errMsg = undefined; |
||||
$scope.incorrect = false; |
||||
resolve(); |
||||
|
||||
}).then(function() { |
||||
// login to imap
|
||||
return privateKey.init(); |
||||
|
||||
}).then(function() { |
||||
// encrypt the private key
|
||||
return privateKey.encrypt($scope.code); |
||||
|
||||
}).then(function(encryptedPayload) { |
||||
// set user id to encrypted payload
|
||||
encryptedPayload.userId = auth.emailAddress; |
||||
|
||||
// encrypt private PGP key using code and upload
|
||||
return privateKey.upload(encryptedPayload); |
||||
|
||||
}).then(function() { |
||||
// logout of imap
|
||||
return privateKey.destroy(); |
||||
|
||||
}).then(function() { |
||||
// continue to public key verification
|
||||
$location.path('/login-verify-public-key'); |
||||
|
||||
}).catch(displayError); |
||||
}; |
||||
|
||||
$scope.goForward = function() { |
||||
$scope.step++; |
||||
}; |
||||
|
||||
$scope.goBack = function() { |
||||
if ($scope.step > 1) { |
||||
$scope.step--; |
||||
} |
||||
}; |
||||
|
||||
//
|
||||
// helper functions
|
||||
//
|
||||
|
||||
function displayError(err) { |
||||
$scope.busy = false; |
||||
$scope.incorrect = true; |
||||
$scope.errMsg = err.errMsg || err.message; |
||||
} |
||||
}; |
||||
|
||||
module.exports = LoginPrivateKeyUploadCtrl; |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
'use strict'; |
||||
|
||||
var Mailbuild = require('mailbuild'); |
||||
|
||||
var ngModule = angular.module('woEmail'); |
||||
ngModule.factory('mailbuild', function() { |
||||
return Mailbuild; |
||||
}); |