Skip to content

Commit

Permalink
Improve logging to fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
HR committed Oct 29, 2016
1 parent 0bcfb7b commit ccb5881
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 35 deletions.
16 changes: 8 additions & 8 deletions app/index.js
Expand Up @@ -9,14 +9,6 @@ const Db = require('./src/Db')
const MasterPass = require('./src/MasterPass')
const MasterPassKey = require('./src/MasterPassKey')
const _ = require('lodash')
const logger = require('./script/logger')
// change exec path
logger.info(`AppPath: ${app.getAppPath()}`)
logger.info(`UseData Path: ${app.getPath('userData')}`)
process.chdir(app.getAppPath())
logger.info(`Changed cwd to: ${process.cwd()}`)
logger.info(`Electron node v${process.versions.node}`)

// adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')()

Expand All @@ -33,6 +25,14 @@ global.views = {
setup: `file://${__dirname}/static/setup.html`,
crypter: `file://${__dirname}/static/crypter.html`
}
const logger = require('./script/logger')

// change exec path
logger.info(`AppPath: ${app.getAppPath()}`)
logger.info(`UseData Path: ${app.getPath('userData')}`)
process.chdir(app.getAppPath())
logger.info(`Changed cwd to: ${process.cwd()}`)
logger.info(`Electron node v${process.versions.node}`)

/**
* Promisification of initialisation
Expand Down
6 changes: 3 additions & 3 deletions app/script/logger.js
Expand Up @@ -6,16 +6,16 @@
const winston = require('winston')
const moment = require('moment')
const fs = require('fs-extra')
const path = require('path')

let debugDir = path.join(__dirname,'/debug')
let debugDir = `${global.paths.userData}/debug`
fs.ensureDirSync(debugDir)
winston.emitErrs = true
const fileTransport = new (winston.transports.File)({
filename: `${debugDir}/CS_debug_${moment().format('DD.MM@HH:MM').trim()}.log`,
handleExceptions: true,
maxsize: 5242880, // 5MB
colorize: false
colorize: false,
level: 'verbose'
})

module.exports = (!process.env.TEST_RUN) ? new (winston.Logger)({
Expand Down
11 changes: 4 additions & 7 deletions app/src/crypto.js
Expand Up @@ -7,7 +7,7 @@
const fs = require('fs-extra')
const path = require('path')
const scrypto = require('crypto')
const logger = require('../script/logger')
const logger = require('winston')
const Readable = require('stream').Readable
const tar = require('tar-fs')
const CRYPTER_REGEX = /^Crypter(.*)$/igm
Expand All @@ -28,7 +28,6 @@ exports.crypt = function (origpath, masterpass) {
// Resolve the destination path for encrypted file
exports.encrypt(origpath, masterpass)
.then((creds) => {
logger.info(`Encrypt creds: ${JSON.stringify(creds)}`)
resolve({
op: 'Encrypted', // Crypter operation
name: path.basename(origpath), // filename
Expand Down Expand Up @@ -62,7 +61,7 @@ exports.encrypt = function (origpath, mpkey) {
fs.mkdirs(tempd, function (err) {
if (err)
reject(err)
logger.info(`Created ${tempd} successfully`)
logger.verbose(`Created ${tempd} successfully`)
// readstream to read the (unencrypted) file
const origin = fs.createReadStream(origpath)
// create data and creds file
Expand Down Expand Up @@ -119,7 +118,7 @@ exports.encrypt = function (origpath, mpkey) {
if (err)
reject(err)
// return all the credentials and parameters used for encryption
logger.info('Successfully deleted tempd!')
logger.verbose('Successfully deleted tempd!')
resolve({
salt: dcreds.salt,
key: dcreds.key,
Expand Down Expand Up @@ -181,17 +180,15 @@ exports.decrypt = function (origpath, mpkey) {
const iv = new Buffer(creds[1], 'hex')
const authTag = new Buffer(creds[2], 'hex')
const salt = new Buffer(creds[3], 'hex')
logger.info(`iv: ${iv}, authTag: ${authTag}, salt: ${salt}`)
logger.verbose(`Extracted data, iv: ${iv}, authTag: ${authTag}, salt: ${salt}`)
// Read encrypted data stream
const dataOrig = fs.createReadStream(dataOrigPath)
// derive the original encryption key for the file
exports.deriveKey(mpkey, salt, defaults.iterations)
.then((dcreds) => {
try {
logger.info(`Derived encryption key ${dcreds.key.toString('hex')}`)
let decipher = scrypto.createDecipheriv(defaults.algorithm, dcreds.key, iv)
decipher.setAuthTag(authTag)
logger.info(`authTag: ${authTag.toString('hex')}`)
const dataDest = fs.createWriteStream(dataDestPath)
dataOrig.pipe(decipher).pipe(dataDest)

Expand Down
6 changes: 4 additions & 2 deletions app/static/crypter.html
Expand Up @@ -21,7 +21,7 @@ <h1>Crypter</h1>
<!-- TODO: Consider using <input class="fancy" type="file" name="name" value="selectfile"> -->
<div id="fileInput" class="fancy">
<p id="fileInputText">
Select a file
Select or drop file
</p>
</div>
</div>
Expand Down Expand Up @@ -90,7 +90,7 @@ <h3>{{op}} {{name}}</h3>
var dialog = remote.dialog
var BrowserWindow = remote.BrowserWindow
var paths = remote.getGlobal('paths')
var logger = require('../script/logger.js')
var logger = require('winston')
var Handlebars = require('handlebars')
var path = require('path')
var errLabel = $('#errLabel')
Expand All @@ -111,7 +111,9 @@ <h3>{{op}} {{name}}</h3>
fileInputD.ondragleave = fileInputD.ondragend = function () {
return false
}

turnFileInputOn ()

$('.navigationLink').each(function (index) {
$(this).click(function () {
navigate(this.getAttribute('data-target'))
Expand Down
2 changes: 1 addition & 1 deletion app/static/styles/crypter.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ccb5881

Please sign in to comment.