diff --git a/app/scripts/util/locale.js b/app/scripts/util/locale.js index 21920feb..1aab2367 100644 --- a/app/scripts/util/locale.js +++ b/app/scripts/util/locale.js @@ -121,6 +121,10 @@ var Locale = { 'Changes you make will not be saved back to file system. ' + 'To get the file with your data, export it from settings.', openLocalFileDontShow: 'Don\'t show this again', + openWrongFile: 'Bad file', + openWrongFileBody: 'This file format is not supported. This app works with KeePass database format files (KDBX).', + openKdbFileBody: 'You are opening an old version format file (KDB). This app supports only new format (KDBX), ' + + 'please use KeePass v2 to convert between them.', detAttDownload: 'Shift-click attachment button to download or ', detAttDelToRemove: 'Delete to remove', diff --git a/app/scripts/views/open-view.js b/app/scripts/views/open-view.js index 243f0ea0..9bec0d90 100644 --- a/app/scripts/views/open-view.js +++ b/app/scripts/views/open-view.js @@ -1,6 +1,7 @@ 'use strict'; var Backbone = require('backbone'), + kdbxweb = require('kdbxweb'), Keys = require('../const/keys'), Alerts = require('../comp/alerts'), SecureInput = require('../comp/secure-input'), @@ -127,6 +128,9 @@ var OpenView = Backbone.View.extend({ reader.onload = (function(e) { switch (this.reading) { case 'fileData': + if (!this.checkOpenFileFormat(e.target.result)) { + return; + } this.params.id = null; this.params.fileData = e.target.result; this.params.name = file.name.replace(/\.\w+$/i, ''); @@ -166,6 +170,23 @@ var OpenView = Backbone.View.extend({ } }, + checkOpenFileFormat: function(fileData) { + var fileSig = new Uint32Array(fileData, 0, 2); + if (fileSig[0] !== kdbxweb.Consts.Signatures.FileMagic) { + Alerts.error({ header: Locale.openWrongFile, body: Locale.openWrongFileBody }); + return false; + } + if (fileSig[1] === kdbxweb.Consts.Signatures.Sig2Kdb) { + Alerts.error({ header: Locale.openWrongFile, body: Locale.openKdbFileBody }); + return false; + } + if (fileSig[1] !== kdbxweb.Consts.Signatures.Sig2Kdbx) { + Alerts.error({ header: Locale.openWrongFile, body: Locale.openWrongFileBody }); + return false; + } + return true; + }, + displayOpenFile: function() { this.$el.addClass('open--file'); this.$el.find('.open__settings-key-file').removeClass('hide'); diff --git a/bower.json b/bower.json index f9658de4..61bf5a32 100644 --- a/bower.json +++ b/bower.json @@ -29,7 +29,7 @@ "dropbox": "antelle/dropbox-js#0.10.6", "font-awesome": "~4.4.0", "install": "~1.0.4", - "kdbxweb": "~0.3.7", + "kdbxweb": "~0.3.8", "normalize.css": "~3.0.3", "pikaday": "~1.3.3", "FileSaver.js": "eligrey/FileSaver.js", diff --git a/release-notes.md b/release-notes.md index b1c17f6f..329ea0c7 100644 --- a/release-notes.md +++ b/release-notes.md @@ -16,6 +16,7 @@ Storage providers, usability improvements `+` shortcuts while the app is in background `+` build for 32-bit linux `+` ability to import xml +`+` warning for kdb files `-` fix #88: capslock indicator `-` fix file settings input behavior