Commit 673d5a76 authored by Andrew Cohen's avatar Andrew Cohen

public / private key generation, server trackList, matlab client fission/fusion

parent 139ac49c
......@@ -39,3 +39,4 @@ bin/*
*.asv
dist/*
/matlab/buildOutput/*
/digitalKeys/*
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAtHG6Qsr2nl2s8GIQjN5EydC5ciZKUxUne07ezLa+MdEIhmVYLgLh
9FGwsYG0MFFM2F9fb3OM5J5+YbGVhDMZGRil0QZoKMyMGhnZ6hd/oIMrmb0Exaa/
sktqpZHZUl8Gpx04IP32yVfhjYkLIvS4DR+4LHK7IsvZwdVLh1Zxn/smJsZLPN3b
jxyfkR/bw58nAhnAV3cMkslBKzEs7NSz1MazcS6S7z8viKkitFYQBYFOM9n6spBW
OUrn+1fsO8gO4i39sRZEN+V5HfIE1PSQQ9szHPINlaWKIhEGd6XnLogA4aH8bVjL
tm0GWP6iPxDA92uX+QN7XCBfsJQFykc98wIDAQAB
-----END RSA PUBLIC KEY-----
......@@ -3,21 +3,39 @@
/* -------------- command line -------------------------- */
const argv = require('minimist')(process.argv.slice(2));
const path=require('path');
const fs=require('fs')
if (undefined===argv.private || undefined===argv.public) {
console.error('USAGE: node keygen.js --private=/path/to/private_key.pem --public=/path/to/public_key.pem');
if (argv.help) {
console.error('USAGE: node keygen.js [--private=/path/to/private_key.pem] [--public=/path/to/public_key.pem]');
return;
}
var privatePath=argv.private;
var publicPath=argv.public;
if (undefined===privatePath) {
privatePath=path.join(__dirname,'..','digitalKeys','private','leverjsPrivateKey.pem');
}
if (undefined===publicPath) {
publicPath=path.join(__dirname,'..','digitalKeys','leverjsPublicKey.pem');
}
var publicDir=path.dirname(publicPath);
if (!fs.existsSync(publicDir)){
fs.mkdirSync(publicDir);
}
var privateDir=path.dirname(privatePath);
if (!fs.existsSync(privateDir)){
fs.mkdirSync(privateDir);
}
/* -------------- command line -------------------------- */
const keypair=require('keypair');
var pair=keypair();
fs=require('fs')
fs.writeFileSync(privatePath,pair.private)
fs.writeFileSync(publicPath,pair.public)
......
......@@ -544,6 +544,20 @@ class LeverDB {
_getTrackFeatures(this._lDB,trackID,fnCallback);
} // getTrackFeatures
trackList(tMin,fnCallback){
tMin=+tMin;
var cmd='select trackID,count,t0,t1 FROM (select trackID,count(trackID) ' +
' as count,min(time) as t0,max(time) as t1 from tblCells group by trackID) where count> '+tMin;
this.lDB.all(cmd,function(err,rows){
var trackList=[];
if (err)
console.error('leverDB: trackList :'+err);
else {
trackList=rows;
}
fnCallback(trackList);
});
};
leverRead(leverFile, id, ROOT, fnCallback) {
console.time('lever');
if (('undefined' !== typeof IS_NODE) && !IS_NODE) {
......
% detectFissionFusion
SERVER='https://leverjs.net/Dario/'
url=[SERVER 'lever'];
leverList=webread(url);
fissionEvents={[],[]};
fusionEvents={[],[]};
for f=1:length(leverList)
if ~isempty(strfind(leverList{f},'siCTRL'))
idx=1;
else
idx=2;
end
url=[SERVER leverList{f} '/trackList/5'];
trackList=webread(url);
nFusion= length(find([trackList.t0]>1))/length(trackList);
nFission = length(find([trackList.t1]<max([trackList.t1])))/length(trackList);
fissionEvents{idx}=[fissionEvents{idx};nFission];
fusionEvents{idx}=[fusionEvents{idx};nFusion];
nFissionFusion=length(trackList)/length(find([trackList.t0]==1));
end
median(fissionEvents{1})
median(fissionEvents{2})
median(fusionEvents{1})
median(fusionEvents{2})
fname=fullfile('+Client','testSecure.m');
token.sha256=JWT.getHash(fname);
tic;[jwt,opts]=JWT.getJWT(token,'application/json');toc
url='http://localhost:3000/secure'
response=webread(url,opts)
\ No newline at end of file
......@@ -7,12 +7,13 @@ function [jwt,opts]=getJWT(inStruct,mediaType)
if nargin<2
mediaType='text/plain';
end
publicKeyFile=fullfile(getenv('USERPROFILE'),'.ssh/leverjsPrivateKey');
% privateKeyFile=fullfile(getenv('USERPROFILE'),'.ssh/leverjsPrivateKey');
privateKeyFile=fullfile('..','digitalKeys','private','leverjsPrivateKey.pem');
fnJWT = fullfile('..','leverjs','jwt.js');
tokenStr=jsonencode(inStruct);
tokenStr=strrep(tokenStr,'"','\"');
[~, result]=system(['node ' fnJWT ' "' publicKeyFile '" "' tokenStr '"']);
[~, result]=system(['node ' fnJWT ' "' privateKeyFile '" "' tokenStr '"']);
jwt=result(1:end-1);
opts = weboptions('MediaType',mediaType,'ContentType','text','HeaderFields',{'authorization' jwt});
......
......@@ -13,12 +13,13 @@
"license": "UNLICENSED",
"dependencies": {
"electron-log": "^2.2.9",
"electron-updater": "^2.10.1",
"express-jwt": "^5.3.0",
"express.js": "^1.0.0",
"jwks-rsa": "^1.2.0",
"keypair": "^1.0.1",
"minimist": "^1.2.0",
"sqlite3": "^3.1.13",
"electron-updater": "^2.10.1"
"sqlite3": "^3.1.13"
},
"devDependencies": {
"electron": "1.7.8",
......
......@@ -99,7 +99,7 @@ function checkLWT(req,res,next)
var token=req.headers.authorization;
//token=token.substring(7);
try {
publicCert = fs.readFileSync('./PublicKeys/leverjsPublicKey.pem','utf-8'); // get public key
publicCert = fs.readFileSync('./digitalKeys/leverjsPublicKey.pem','utf-8'); // get public key
}
catch(err){
console.log('LWT: public key file not found '+err.message);
......@@ -134,13 +134,22 @@ app.get('/secure', checkLWT, function(req,res){
app.get('/hiFriend', function(req,res){
console.log('hifriend')
res.send('hi');
res.send('hi');
});
app.get('/:LEVER/trackList/:tMin',function(req,res){
var leverFile=req.leverFile;
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB(leverFile);
var tMin=req.params.tMin;
leverDB.trackList(tMin,function(trackList){
res.send(trackList);
});
})
app.post('/:LEVER/createCells/',checkLWT, jsonParser,function(req,res) {
var leverFile=req.leverFile;
const LeverDB=require();
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB(leverFile);
leverDB.createCells(req.body,function(cellIDs){
res.send(cellIDs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment