forked from cossacklabs/acra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
andrey
committed
Nov 28, 2016
1 parent
d5fc8ee
commit 567f904
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var acra = require('acra'); | ||
var pg = require('pg'); | ||
var request = require('sync-request'); | ||
|
||
var res = request('GET', 'http://127.0.0.1:9191/getNewZone'); | ||
var zone = JSON.parse(res.getBody().toString('utf8')); | ||
console.log(zone); | ||
|
||
var raw_data = 'Test Message'; | ||
|
||
var config = { | ||
user: 'andrey', | ||
database: 'acra', | ||
password: 'andrey', | ||
host: 'localhost', | ||
port: 9494, | ||
max: 10, | ||
idleTimeoutMillis: 30000, | ||
}; | ||
|
||
var pool = new pg.Pool(config); | ||
pool.connect(function(err, client, done) { | ||
if(err) { | ||
return console.error('error fetching client from pool', err); | ||
} | ||
client.query('CREATE TABLE IF NOT EXISTS testjs(id SERIAL PRIMARY KEY, zone BYTEA, data BYTEA, raw_data TEXT)', [], function(err, res) { | ||
done(); | ||
if(err) { | ||
return console.error('error running query', err); | ||
} | ||
}); | ||
client.query('insert into testjs (zone, data, raw_data) values ($1, $2, $3)', [zone.id, acra.create_acra_struct(raw_data, new Buffer(zone.public_key, 'base64'), zone.id), raw_data], function(err, res) { | ||
done(); | ||
if(err) { | ||
return console.error('error running query', err); | ||
} | ||
}); | ||
|
||
client.query('select zone, data, raw_data from testjs', [], function(err, res) { | ||
done(); | ||
if(err) { | ||
return console.error('error running query', err); | ||
} | ||
for(i=0;i<res.rows.length;i++){ | ||
console.log(res.rows[i].zone.toString('utf8')); | ||
console.log(res.rows[i].data.toString('utf8')); | ||
console.log(res.rows[i].raw_data.toString('utf8')); | ||
console.log(" "); | ||
} | ||
}); | ||
done(); | ||
}); | ||
|
||
pool.on('error', function (err, client) { | ||
console.error('idle client error', err.message, err.stack) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var themis = require('jsthemis'); | ||
var int64 = require('int64-buffer').Uint64LE | ||
|
||
|
||
module.exports = { | ||
|
||
create_acra_struct: function(data, acra_public_key, context){ | ||
var data_buffer = Buffer.isBuffer(data)?data:(new Buffer(data)); | ||
var context_buffer = Buffer.isBuffer(context)?context:(new Buffer(context)); | ||
var random_keypair = new themis.KeyPair(); | ||
var sm = new themis.SecureMessage(random_keypair.private(), acra_public_key); | ||
var random_key = require('crypto').randomBytes(32); | ||
var wrapped_random_key = sm.encrypt(random_key); | ||
var sc = new themis.SecureCellSeal(random_key); | ||
var encrypted_data = context?sc.encrypt(data_buffer, context_buffer):sc.encrypt(data_buffer); | ||
var begin_tag = new Buffer([133,32,251]); | ||
var encrypted_data_length = new int64(encrypted_data.length).toBuffer(); | ||
console.log(encrypted_data_length); | ||
return Buffer.concat([begin_tag, random_keypair.public(), wrapped_random_key, encrypted_data_length, encrypted_data]); | ||
} | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "acra", | ||
"version": "1.0.0", | ||
"description": "node.js binding for creating acra struct", | ||
"main": "acra.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cossacklabs/acra/wrappers/nodejs/" | ||
}, | ||
"keywords": [ | ||
"themis", | ||
"acra" | ||
], | ||
"author": { | ||
"name": "Cossack Labs", | ||
"email": "dev@cossacklabs.com", | ||
"url": "http://cossacklabs.com/" | ||
}, | ||
"dependencies": { | ||
"jsthemis": "*", | ||
"int64-buffer": "*" | ||
}, | ||
"license": "Apache-2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var acra = require('./acra'); | ||
var themis = require('jsthemis'); | ||
|
||
|
||
var key_pair = new themis.KeyPair(); | ||
var acra_struct = acra.create_acra_struct('andrey', key_pair.public(), 'context') | ||
console.log(acra_struct.length); | ||
|
||
|
||
|