From e44e32869eea30c552d2ab45b8585c756a6fd8fe Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 6 Nov 2013 16:20:49 +0100 Subject: [PATCH] [WO-56] display account information --- src/js/controller/account.js | 11 +++++++++++ src/js/crypto/pgp.js | 32 ++++++++++++++++++++++++++++++++ src/sass/all.scss | 1 + src/sass/views/_account.scss | 29 +++++++++++++++++++++++++++++ src/tpl/account.html | 28 +++++++++++++++++++++++++--- test/new-unit/pgp-test.js | 14 ++++++++++++++ 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 src/sass/views/_account.scss diff --git a/src/js/controller/account.js b/src/js/controller/account.js index a05f95a..0457db1 100644 --- a/src/js/controller/account.js +++ b/src/js/controller/account.js @@ -12,6 +12,17 @@ define(function(require) { var AccountCtrl = function($scope) { emailDao = appController._emailDao; + // + // scope variables + // + + var fpr = emailDao._crypto.getFingerprint(), + keyId = emailDao._crypto.getKeyId(); + $scope.eMail = emailDao._account.emailAddress; + $scope.keyId = keyId.slice(0,4) + ' ' + keyId.slice(4,8) + ' ' + keyId.slice(8,12) + ' ' + keyId.slice(12); + $scope.fingerprint = fpr.slice(0,4) + ' ' + fpr.slice(4,8) + ' ' + fpr.slice(8,12) + ' ' + fpr.slice(12,16) + ' ' + fpr.slice(16,20) + ' ' + fpr.slice(20,24) + ' ' + fpr.slice(24,28) + ' ' + fpr.slice(28,32) + ' ' + fpr.slice(32,36) + ' ' + fpr.slice(36); + $scope.keysize = emailDao._account.asymKeySize; + // // scope functions // diff --git a/src/js/crypto/pgp.js b/src/js/crypto/pgp.js index 8640e18..36e9587 100644 --- a/src/js/crypto/pgp.js +++ b/src/js/crypto/pgp.js @@ -43,6 +43,38 @@ define(function(require) { }); }; + /** + * Show a user's fingerprint + */ + PGP.prototype.getFingerprint = function() { + var publicKey, privateKey; + + privateKey = openpgp.keyring.exportPrivateKey(0); + if (privateKey && privateKey.keyId) { + publicKey = openpgp.keyring.getPublicKeysForKeyId(privateKey.keyId)[0]; + } + + if (!privateKey || !privateKey.keyId || !privateKey.armored || !publicKey || !publicKey.armored) { + console.error('Public key not available!'); + return ''; + } + + return util.hexstrdump(publicKey.obj.getFingerprint()).toUpperCase(); + }; + + /** + * Show a user's key id + */ + PGP.prototype.getKeyId = function() { + var privateKey = openpgp.keyring.exportPrivateKey(0); + if (!privateKey || !privateKey.keyId) { + console.error('Public key not available!'); + return ''; + } + + return util.hexstrdump(privateKey.keyId).toUpperCase(); + }; + /** * Import the user's key pair */ diff --git a/src/sass/all.scss b/src/sass/all.scss index 9379eae..91d6a5f 100755 --- a/src/sass/all.scss +++ b/src/sass/all.scss @@ -20,6 +20,7 @@ // Views @import "views/shared"; +@import "views/account"; @import "views/navigation"; @import "views/mail-list"; @import "views/read"; diff --git a/src/sass/views/_account.scss b/src/sass/views/_account.scss new file mode 100644 index 0000000..42704f0 --- /dev/null +++ b/src/sass/views/_account.scss @@ -0,0 +1,29 @@ +.view-account { + padding: 0px; + color: $color-grey-dark; + + @include respond-to(mobile) { + height: 100%; + } + + table { + margin: 50px auto 100px auto; + + td { + padding-top: 15px; + + &:first-child { + text-align: right; + padding-right: 15px; + font-weight: bold; + } + } + } + + button { + border: 0!important; + position: absolute; + bottom: 15px; + right: 15px; + } +} \ No newline at end of file diff --git a/src/tpl/account.html b/src/tpl/account.html index f32ee9b..1ed38ff 100644 --- a/src/tpl/account.html +++ b/src/tpl/account.html @@ -5,6 +5,28 @@
- -
- \ No newline at end of file +
+ + + + + + + + + + + + + + + + + + + +
Account{{eMail}}
PGP Key ID{{keyId}}
PGP Key Fingerprint{{fingerprint}}
PGP Key Size{{keysize}} bit
+ +
+ + \ No newline at end of file diff --git a/test/new-unit/pgp-test.js b/test/new-unit/pgp-test.js index 0a33d29..62fa570 100644 --- a/test/new-unit/pgp-test.js +++ b/test/new-unit/pgp-test.js @@ -132,6 +132,20 @@ define(function(require) { }); }); + describe('Get KeyId', function() { + it('should work', function() { + var keyId = pgp.getKeyId(); + expect(keyId).to.equal('F6F60E9B42CDFF4C'); + }); + }); + + describe('Get Fingerprint', function() { + it('should work', function() { + var fingerprint = pgp.getFingerprint(); + expect(fingerprint).to.equal('5856CEF789C3A307E8A1B976F6F60E9B42CDFF4C'); + }); + }); + describe('Encrypt', function() { it('should work', function(done) { pgp.encrypt(message, [pubkey], function(err, ct) {