Skip to content

Commit 05f9d79

Browse files
author
nullagent
committed
aes stream tweaks
1 parent f9e8bf8 commit 05f9d79

7 files changed

Lines changed: 46 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"express-ipfilter": "^1.3.2",
8686
"express-list-routes": "^1.1.9",
8787
"git-repo-info": "^2.1.1",
88-
"joi": "^17.9.1",
88+
"joi": "^17.13.3",
8989
"joi-objectid": "^4.0.2",
9090
"jshashes": "^1.0.8",
9191
"jsonpath-plus": "^0.20.1",

src/comms/host/host-protocol-scheme.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ const OP_HEADER = Joi.object().keys({
1515
).required()
1616
})
1717

18+
const validateUint8Array = (value, helpers)=>{
19+
if(value instanceof Uint8Array){
20+
return value
21+
}
22+
23+
throw new Error('expected Uint8Arry but got ['+typeof value+'] instead')
24+
}
1825

1926
const AUTH_OP = Joi.object().keys({
2027
id: ID_SCHEME.required(),
@@ -37,7 +44,8 @@ const AUTH_OP = Joi.object().keys({
3744
seed: Joi.allow(null)
3845
}).required(),
3946
pqCipherText: Joi.string().required(),
40-
streamNonce: Joi.string().required()
47+
streamNonce: Joi.any().custom(validateUint8Array, 'Uint8Array validation').required(),
48+
mode: Joi.string().required()
4149
}).required(),
4250
signature: Joi.object().keys({
4351
timestamp: Joi.number().required(),

src/comms/isocket-comms.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class ISocketComms extends EventEmitter {
100100
console.log(reply, typeof reply)
101101
console.log(typeof reply.data)
102102

103+
debug('aesStream nonce', this.aesStream.rxNonce)
104+
105+
debug('aesStream key', this.aesStream.key)
106+
107+
103108
let buf = reply.data
104109

105110
if(buf instanceof Blob){
@@ -109,6 +114,8 @@ class ISocketComms extends EventEmitter {
109114
//buf = reply.data
110115
}
111116

117+
debug('decrypt-', buf)
118+
112119
const contentBSON = await this.aesStream.decrypt( new Uint8Array(buf) )
113120
const content = Routines.BSON.parseObject(new Routines.BSON.BaseParser( contentBSON ))
114121

@@ -169,7 +176,7 @@ class ISocketComms extends EventEmitter {
169176
async send(input){
170177
debug('send - ', typeof input, input)
171178

172-
if(typeof input != 'object'){
179+
if(typeof input == 'string'){
173180
input = JSON.parse(input)
174181
}
175182

src/comms/op/auth-op.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const debug = require('debug')('dataparty.op.auth-op')
22
const SocketOp = require('./socket-op')
33

4-
const {Routines} = require('@dataparty/crypto')
4+
const {Routines, AESStream} = require('@dataparty/crypto')
55

66

77
class AuthOp extends SocketOp {
@@ -14,9 +14,9 @@ class AuthOp extends SocketOp {
1414

1515
async run(){
1616
const actor = this.socket.party.privateIdentity
17-
const aesStreamOffer = await actor.createStream( this.socket.remoteIdentity )
18-
19-
this.stream = aesStreamOffer.stream
17+
this.stream = await AESStream.createStream( actor, this.socket.remoteIdentity, true, 'random' )
18+
const aesStreamOffer = this.stream.offer
19+
2020

2121
const offer = {
2222
sender: {
@@ -28,7 +28,8 @@ class AuthOp extends SocketOp {
2828
}
2929
},
3030
pqCipherText: aesStreamOffer.pqCipherText,
31-
streamNonce: aesStreamOffer.streamNonce
31+
streamNonce: aesStreamOffer.streamNonce,
32+
mode: aesStreamOffer.mode
3233
}
3334

3435
const offerBSON = Routines.BSON.serializeBSONWithoutOptimiser( offer )

src/comms/peer-comms.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
const {Routines, Identity} = require('@dataparty/crypto')
2+
const {Routines, Identity, AESStream} = require('@dataparty/crypto')
33
const debug = require('debug')('dataparty.comms.peercomms')
44
const uuidv4 = require('uuid/v4')
55
const HttpMocks = require('node-mocks-http')
@@ -369,7 +369,8 @@ class PeerComms extends ISocketComms {
369369
const offer = {
370370
sender: new Identity(op.input.offer.sender),
371371
pqCipherText: op.input.offer.pqCipherText,
372-
streamNonce: op.input.offer.streamNonce
372+
streamNonce: op.input.offer.streamNonce,
373+
mode: op.input.offer.mode
373374
}
374375

375376
const signature = {
@@ -419,9 +420,18 @@ class PeerComms extends ISocketComms {
419420
}
420421
}
421422

423+
debug('clienr auth op offer -', offer)
422424
debug('ALLOW - allowing client - ', this.remoteIdentity)
423425

424-
this.aesStream = await this.party.privateIdentity.recoverStream(offer, true)
426+
//this.aesStream = await this.party.privateIdentity.recoverStream(offer, true)
427+
428+
this.aesStream = await AESStream.recoverStream(
429+
this.party.privateIdentity,
430+
offer,
431+
true
432+
)
433+
434+
debug('aes-stream', this.aesStream)
425435

426436
clearTimeout(this._host_auth_timeout)
427437
this._host_auth_timeout = null

src/index-browser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
var Buffer = require('buffer/').Buffer
2+
3+
if(!window.Buffer){
4+
window.Buffer = Buffer
5+
}
6+
17
const Comms = require('./comms')
28
const Party = require('./party/index-browser')
39
const Topics = require('./topics')
@@ -26,4 +32,5 @@ let lib = {
2632

2733

2834
module.exports = lib
29-
window.Dataparty = lib
35+
window.Dataparty = lib
36+

src/service/endpoints/service-identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = class ServiceIdentity extends IEndpoint {
2727
id: Joi.string(),
2828
key: {
2929
type: Joi.alternatives().try(
30-
Joi.string().valid('nacl,nacl,ml_kem768,ml_dsa65,slh_dsa_sha2_128f')
30+
Joi.string().valid('nacl,nacl,ml_kem1024,ml_dsa65,slh_dsa_sha2_128f')
3131
),
3232
hash: Joi.string(),
3333
public: Joi.object().keys({

0 commit comments

Comments
 (0)