mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-02 18:17:46 +01:00
decrypt and list sites
This commit is contained in:
parent
a7c8dec730
commit
27667a3086
@ -1,4 +1,4 @@
|
|||||||
var FolderData = function (response, userId) {
|
var FolderData = function (response, userId) {
|
||||||
var data = null;
|
var data = null;
|
||||||
if (response instanceof FolderResponse) {
|
if (response instanceof FolderResponse) {
|
||||||
data = response;
|
data = response;
|
||||||
@ -10,10 +10,10 @@
|
|||||||
throw 'unsupported instance';
|
throw 'unsupported instance';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.id = response.Id;
|
this.id = response.id;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.name = data.Name;
|
this.name = data.name;
|
||||||
this.revisionDate = response.RevisionDate;
|
this.revisionDate = response.revisionDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
var SiteData = function (response, userId) {
|
var SiteData = function (response, userId) {
|
||||||
@ -28,14 +28,14 @@ var SiteData = function (response, userId) {
|
|||||||
throw 'unsupported instance';
|
throw 'unsupported instance';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.id = response.Id;
|
this.id = response.id;
|
||||||
this.folderId = response.FolderId;
|
this.folderId = response.folderId;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.name = data.Name;
|
this.name = data.name;
|
||||||
this.uri = data.Uri;
|
this.uri = data.uri;
|
||||||
this.username = data.Username;
|
this.username = data.username;
|
||||||
this.password = data.Password;
|
this.password = data.password;
|
||||||
this.notes = data.Notes;
|
this.notes = data.notes;
|
||||||
this.favorite = response.Favorite;
|
this.favorite = response.favorite;
|
||||||
this.revisionDate = response.RevisionDate;
|
this.revisionDate = response.revisionDate;
|
||||||
};
|
};
|
||||||
|
@ -18,40 +18,41 @@ var CipherString = function (encryptedString) {
|
|||||||
callback(_decryptedValue);
|
callback(_decryptedValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
callback(_decryptedValue);
|
callback(_decryptedValue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
var Site = function (obj, alreadyEncrypted) {
|
var Site = function (obj, alreadyEncrypted) {
|
||||||
this.id = obj.id;
|
this.id = obj.id ? obj.id : null;
|
||||||
this.folderId = obj.folderId;
|
this.folderId = obj.folderId ? obj.folderId : null;
|
||||||
|
|
||||||
if (alreadyEncrypted === true) {
|
if (alreadyEncrypted === true) {
|
||||||
this.name = obj.name;
|
this.name = obj.name ? obj.name : null;
|
||||||
this.uri = obj.uri;
|
this.uri = obj.uri ? obj.uri : null;
|
||||||
this.username = obj.username;
|
this.username = obj.username ? obj.username : null;
|
||||||
this.password = obj.password;
|
this.password = obj.password ? obj.password : null;
|
||||||
this.notes = obj.notes;
|
this.notes = obj.notes ? obj.notes : null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.name = new CipherString(obj.name);
|
this.name = obj.name ? new CipherString(obj.name) : null;
|
||||||
this.uri = new CipherString(obj.uri);
|
this.uri = obj.uri ? new CipherString(obj.uri) : null;
|
||||||
this.username = new CipherString(obj.username);
|
this.username = obj.username ? new CipherString(obj.username) : null;
|
||||||
this.password = new CipherString(obj.password);
|
this.password = obj.password ? new CipherString(obj.password) : null;
|
||||||
this.notes = new CipherString(obj.notes);
|
this.notes = obj.notes ? new CipherString(obj.notes) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.favorite = obj.favorite ? true : false;
|
this.favorite = obj.favorite ? true : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
var Folder = function (obj, alreadyEncrypted) {
|
var Folder = function (obj, alreadyEncrypted) {
|
||||||
this.id = obj.id;
|
this.id = obj.id ? obj.id : null;
|
||||||
|
|
||||||
if (alreadyEncrypted === true) {
|
if (alreadyEncrypted === true) {
|
||||||
this.name = obj.name;
|
this.name = obj.name ? obj.name : null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.name = new CipherString(obj.name);
|
this.name = obj.name ? new CipherString(obj.name) : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
angular
|
angular
|
||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.controller('vaultController', function ($scope, $ionicModal, siteService, folderService) {
|
.controller('vaultController', function ($scope, $ionicModal, siteService, folderService, $q) {
|
||||||
$scope.parentScope = $scope;
|
$scope.parentScope = $scope;
|
||||||
$scope.sites = [];
|
$scope.sites = [];
|
||||||
$scope.folders = [];
|
$scope.folders = [];
|
||||||
@ -14,14 +14,16 @@
|
|||||||
|
|
||||||
folderService.getAll(function (folders) {
|
folderService.getAll(function (folders) {
|
||||||
siteService.getAll(function (sites) {
|
siteService.getAll(function (sites) {
|
||||||
|
var promises = [];
|
||||||
|
|
||||||
for (var i = 0; i < folders.length; i++) {
|
for (var i = 0; i < folders.length; i++) {
|
||||||
decFolders.push({
|
decFolders.push({
|
||||||
id: folders[i].id
|
id: folders[i].id
|
||||||
});
|
});
|
||||||
|
|
||||||
folders[i].name.decrypt(function (name) {
|
promises.push(decrypt(folders[j].name, i).then(function (obj) {
|
||||||
decFolders.name = name;
|
decFolders[obj.index].name = obj.val;
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j = 0; j < sites.length; j++) {
|
for (var j = 0; j < sites.length; j++) {
|
||||||
@ -31,24 +33,35 @@
|
|||||||
favorite: sites[j].favorite
|
favorite: sites[j].favorite
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sites[j].name && sites[j].name.encryptedString) {
|
promises.push(decrypt(sites[j].name, j).then(function (obj) {
|
||||||
sites[j].name.decrypt(function (name) {
|
decSites[obj.index].name = obj.val;
|
||||||
decSites.name = name;
|
}));
|
||||||
});
|
|
||||||
}
|
promises.push(decrypt(sites[j].username, j).then(function (obj) {
|
||||||
|
decSites[obj.index].username = obj.val;
|
||||||
if (sites[j].username && sites[j].username.encryptedString) {
|
}));
|
||||||
sites[j].username.decrypt(function (username) {
|
|
||||||
decSites.username = username;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.sites = decSites;
|
$q.all(promises).then(function () {
|
||||||
$scope.folders = decFolders;
|
$scope.sites = decSites;
|
||||||
|
$scope.folders = decFolders;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function decrypt(cipherString, index) {
|
||||||
|
return $q(function(resolve, reject) {
|
||||||
|
if (!cipherString) {
|
||||||
|
resolve({val: null, index: index});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cipherString.decrypt(function (decString) {
|
||||||
|
resolve({ val: decString, index: index });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$scope.addSite = function () {
|
$scope.addSite = function () {
|
||||||
$ionicModal.fromTemplateUrl('app/vault/views/vaultAddSite.html', {
|
$ionicModal.fromTemplateUrl('app/vault/views/vaultAddSite.html', {
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
|
@ -4,10 +4,16 @@
|
|||||||
</ion-nav-buttons>
|
</ion-nav-buttons>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<div class="list">
|
<div class="list">
|
||||||
<div class="item item-button-right">
|
<ng-repeat ng-repeat="folder in folders | orderBy: folderSort" ng-show="folders.length">
|
||||||
Site 1
|
<div class="item item-divider">
|
||||||
<button class="button button-clear button-dark"><i class="icon ion-more"></i></button>
|
{{folder.name}}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="item item-button-right" ng-repeat="site in folderSites = (sites | filter: { folderId: folder.id } | orderBy: ['name', 'username'])">
|
||||||
|
{{site.name}}<br />
|
||||||
|
{{site.username}}
|
||||||
|
<button class="button button-clear button-dark"><i class="icon ion-more"></i></button>
|
||||||
|
</div>
|
||||||
|
</ng-repeat>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-view>
|
</ion-view>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
function CryptoService() {
|
function CryptoService() {
|
||||||
initCryptoService();
|
initCryptoService();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,6 +105,7 @@ function initCryptoService() {
|
|||||||
|
|
||||||
if (plaintextValue === null || plaintextValue === undefined) {
|
if (plaintextValue === null || plaintextValue === undefined) {
|
||||||
callback(null);
|
callback(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getKey(false, function (key) {
|
this.getKey(false, function (key) {
|
||||||
@ -123,7 +124,8 @@ function initCryptoService() {
|
|||||||
var ct = ctJson.match(/"ct":"([^"]*)"/)[1];
|
var ct = ctJson.match(/"ct":"([^"]*)"/)[1];
|
||||||
var iv = sjcl.codec.base64.fromBits(response.iv);
|
var iv = sjcl.codec.base64.fromBits(response.iv);
|
||||||
|
|
||||||
callback(new CipherString(iv + "|" + ct));
|
var cs = new CipherString(iv + "|" + ct);
|
||||||
|
callback(cs);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -145,7 +147,8 @@ function initCryptoService() {
|
|||||||
var ctBits = sjcl.codec.base64.toBits(cipherString.cipherText);
|
var ctBits = sjcl.codec.base64.toBits(cipherString.cipherText);
|
||||||
|
|
||||||
var decBits = sjcl.mode.cbc.decrypt(aes, ctBits, ivBits, null);
|
var decBits = sjcl.mode.cbc.decrypt(aes, ctBits, ivBits, null);
|
||||||
callback(sjcl.codec.utf8String.fromBits(decBits));
|
var decValue = sjcl.codec.utf8String.fromBits(decBits);
|
||||||
|
callback(decValue);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user