Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions desk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const actions = require( 'desk-base' ),
path = require( 'path' ),
pty = require( 'node-pty' ),
socketIO = require( 'socket.io' );
const { test } = require('shelljs');

const certificateFile = path.join( __dirname, "certificate.pem" ),
deskDir = actions.getRootDir(),
Expand All @@ -31,11 +32,30 @@ actions.include( __dirname + '/extensions' );
function authenticate ( user, pass ) {

if ( id.username === undefined ) return true;
const shasum = crypto.createHash( 'sha1' );
shasum.update( pass );
const sha = shasum.digest( 'hex' );
if ( !user || !pass || user !== id.username || sha !== id.sha ) throw new Error( 'bad auth' );

const pass256 = pass;
const shasum256 = crypto.createHash( 'sha256' );
shasum256.update(pass256);
const sha256 = shasum256.digest( 'hex' );

//If the hash of the password is calculated with SHA-1 then we change it
if ( id.sha) {
const pass1 = pass;
const shasum1 = crypto.createHash( 'sha1' );
shasum1.update( pass1 );
const sha1 = shasum1.digest( 'hex' );
if ( !user || !pass || user !== id.username || sha1 !== id.sha ) { throw new Error( 'bad auth' );}
// We verify that the logins are correct before deleting and addind the hash 256
else if (user && pass && user == id.username && sha1 == id.sha) {
delete id.sha;
id.sha256 = sha256;
fs.writeFileSync( passwordFile, JSON.stringify( id ) );
};
//
} else {
if ( !user || !pass || user !== id.username || sha256 !== id.sha256 ) { throw new Error( 'bad auth' )};
}


}

const app = express()
Expand Down Expand Up @@ -182,9 +202,9 @@ function updatePassword() {
if ( id.password ) {

// convert to secure format
const shasum = crypto.createHash( 'sha1' );
const shasum = crypto.createHash( 'sha256' );
shasum.update( id.password );
id.sha = shasum.digest( 'hex' );
id.sha256 = shasum.digest( 'hex' );
delete id.password;
fs.writeFileSync( passwordFile, JSON.stringify( id ) );

Expand Down Expand Up @@ -219,9 +239,9 @@ io.on( 'connection', socket => {
.on( 'setEmitLog', log => actions.setEmitLog( log ) )
.on( 'password', password => {

const shasum = crypto.createHash( 'sha1' );
const shasum = crypto.createHash( 'sha256' );
shasum.update( password );
id.sha = shasum.digest( 'hex' );
id.sha256 = shasum.digest( 'hex' );
fs.writeFileSync( passwordFile, JSON.stringify( id ) );

} );
Expand Down