SEARCH-154 & SEARCH-116

1. Hardcoded the key and userId for now
This commit is contained in:
Keerthi Niranjan 2017-08-22 16:34:57 +05:30 committed by Keerthi Niranjan
parent 1f2939545b
commit 8d73e930ed
4 changed files with 24 additions and 22 deletions

View File

@ -99,7 +99,7 @@
</div> </div>
<script> <script>
var search = new ssf.Search("testUser1"); var search = new ssf.Search("user_data");
var buttonEl = document.getElementById('search'); var buttonEl = document.getElementById('search');
var merge = document.getElementById('merge'); var merge = document.getElementById('merge');
var buttonIndex = document.getElementById('index'); var buttonIndex = document.getElementById('index');

View File

@ -27,7 +27,6 @@ class Crypto {
this.permanentIndexFolderName = 'search_index_' + userId + '_' + INDEX_VERSION; this.permanentIndexFolderName = 'search_index_' + userId + '_' + INDEX_VERSION;
this.dump = TEMPORARY_PATH; this.dump = TEMPORARY_PATH;
this.extractToPath = `${TEMPORARY_PATH}/data/${this.permanentIndexFolderName}`; this.extractToPath = `${TEMPORARY_PATH}/data/${this.permanentIndexFolderName}`;
this.key = "XrwVgWR4czB1a9scwvgRUNbXiN3W0oWq7oUBenyq7bo="; // temporary only
this.encryptedIndex = `${INDEX_DATA_FOLDER + '_' + userId + '_' + INDEX_VERSION}.enc`; this.encryptedIndex = `${INDEX_DATA_FOLDER + '_' + userId + '_' + INDEX_VERSION}.enc`;
this.zipErrored = false; this.zipErrored = false;
} }
@ -37,7 +36,7 @@ class Crypto {
* removing the data folder and the dump files * removing the data folder and the dump files
* @returns {Promise} * @returns {Promise}
*/ */
encryption() { encryption(key) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!fs.existsSync(this.indexDataFolder)){ if (!fs.existsSync(this.indexDataFolder)){
@ -60,7 +59,7 @@ class Crypto {
const input = fs.createReadStream(`${this.dump}/${this.permanentIndexFolderName}.zip`); const input = fs.createReadStream(`${this.dump}/${this.permanentIndexFolderName}.zip`);
const outputEncryption = fs.createWriteStream(this.encryptedIndex); const outputEncryption = fs.createWriteStream(this.encryptedIndex);
let config = { let config = {
key: this.key key: key
}; };
const encrypt = crypto.encrypt(config); const encrypt = crypto.encrypt(config);
@ -99,7 +98,7 @@ class Crypto {
* removing the .enc file and the dump files * removing the .enc file and the dump files
* @returns {Promise} * @returns {Promise}
*/ */
decryption() { decryption(key) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!fs.existsSync(this.encryptedIndex)){ if (!fs.existsSync(this.encryptedIndex)){
@ -111,7 +110,7 @@ class Crypto {
const input = fs.createReadStream(this.encryptedIndex); const input = fs.createReadStream(this.encryptedIndex);
const output = fs.createWriteStream(`${this.dump}/decrypted.zip`); const output = fs.createWriteStream(`${this.dump}/decrypted.zip`);
let config = { let config = {
key: this.key key: key
}; };
const decrypt = crypto.decrypt(config); const decrypt = crypto.decrypt(config);

View File

@ -71,19 +71,6 @@ if (isMac) {
}); });
} }
/**
* This is for demo purpose only
* will be removing this after implementing
* in the client-app
*/
crypto.decryption()
.then(function () {
// will be handling after implementing client app
})
.catch(function () {
// will be handling after implementing client app
});
/** /**
* This method will be called when Electron has finished * This method will be called when Electron has finished
* initialization and is ready to create browser windows. * initialization and is ready to create browser windows.
@ -111,7 +98,9 @@ app.on('will-quit', function (e) {
* will be removing this after implementing * will be removing this after implementing
* in client-app * in client-app
*/ */
crypto.encryption() // Will be handling this in SEARCH-206
let key = "XrwVgWR4czB1a9scwvgRUNbXiN3W0oWq7oUBenyq7bo="; // temporary only
crypto.encryption(key)
.then(function () { .then(function () {
// will be handling after implementing in client app // will be handling after implementing in client app
app.exit(); app.exit();

View File

@ -12,6 +12,10 @@ const isMac = require('../utils/misc.js').isMac;
// Search library // Search library
const libSymphonySearch = require('./searchLibrary'); const libSymphonySearch = require('./searchLibrary');
// Crypto Library
const Cryotp = require('../cryptoLib');
const crypto = new Cryotp();
// Path for the exec file and the user data folder // Path for the exec file and the user data folder
const userData = path.join(app.getPath('userData')); const userData = path.join(app.getPath('userData'));
const execPath = path.dirname(app.getPath('exe')); const execPath = path.dirname(app.getPath('exe'));
@ -48,14 +52,24 @@ class Search {
*/ */
constructor(userId) { constructor(userId) {
this.isInitialized = false; this.isInitialized = false;
this.userId = userId; this.userId = 'user_data';
// Will be handling this in SEARCH-206
this.key = "XrwVgWR4czB1a9scwvgRUNbXiN3W0oWq7oUBenyq7bo="; // temporary only
this.startIndexingFromDate = (new Date().getTime() - SEARCH_PERIOD_SUBTRACTOR).toString(); this.startIndexingFromDate = (new Date().getTime() - SEARCH_PERIOD_SUBTRACTOR).toString();
this.indexFolderName = INDEX_PREFIX + '_' + userId + '_' + INDEX_VERSION; this.indexFolderName = INDEX_PREFIX + '_' + userId + '_' + INDEX_VERSION;
this.dataFolder = INDEX_DATA_FOLDER; this.dataFolder = INDEX_DATA_FOLDER;
this.realTimeIndex = TEMP_REAL_TIME_INDEX; this.realTimeIndex = TEMP_REAL_TIME_INDEX;
this.batchIndex = TEMP_BATCH_INDEX_FOLDER; this.batchIndex = TEMP_BATCH_INDEX_FOLDER;
this.messageData = []; this.messageData = [];
this.decryptAndInit();
}
decryptAndInit() {
crypto.decryption(this.key).then(() => {
this.init(); this.init();
}).catch(() => {
this.init();
});
} }
/** /**