Skip to content

Commit ee89096

Browse files
committed
test encrypted responses
1 parent 2f7fcc0 commit ee89096

5 files changed

Lines changed: 28 additions & 25 deletions

File tree

public/app.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function main(){
6666
callTime2.start()
6767

6868
const echoReply2 = await party.comms.call('secure-echo', {t:(new Date()).getTime()}, {
69-
expectClearTextReply: true,
69+
expectClearTextReply: false,
7070
sendClearTextRequest: false,
7171
useSessions: false
7272
})
@@ -75,10 +75,11 @@ async function main(){
7575
complete++
7676

7777
const text = `call deltaMs=<i>${callTime2.deltaMs}</i>ms complete ${complete}`
78-
document.getElementById("console").innerHTML = text
78+
document.getElementById("secure-echo-speed").innerHTML = text
7979

80-
}, 150)
80+
}, 250)
8181

82+
8283
setInterval(async ()=>{
8384
//console.log('send')
8485

@@ -97,9 +98,9 @@ async function main(){
9798
complete++
9899

99100
const text = `call deltaMs=<i>${callTime2.deltaMs}</i>ms complete ${complete}`
100-
document.getElementById("console").innerHTML = text
101+
document.getElementById("echo-speed").innerHTML = text
101102

102-
}, 75)
103+
}, 100)
103104

104105
}
105106

public/crypto-test.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77

88
<body>
9-
<p id="console"></p>
9+
<div>
10+
<i>/echo</i> <p id="echo-speed"></p>
11+
</div>
12+
<br/>
13+
<div>
14+
<i>/secure-echo</i> <p id="secure-echo-speed"></p>
15+
</div>
1016
</body>
1117
</html>

src/service/endpoints/secure-echo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = class SecureEchoEndpoint extends IEndpoint {
2323
validate: Joi.object().keys(null).description('any input allowed'),
2424
},
2525
post: {
26-
encrypt: false,
26+
encrypt: true,
2727
validate: Joi.object().keys(null).description('any output allowed')
2828
}
2929
}

src/service/middleware/post/encrypt.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Joi = require('@hapi/joi')
22
const Hoek = require('@hapi/hoek')
3-
const {Message, Routines} = require('@dataparty/crypto')
3+
const {Message, Identity} = require('@dataparty/crypto')
44
const debug = require('debug')('dataparty.middleware.post.encrypt')
55

66
const IMiddleware = require('../../imiddleware')
@@ -27,25 +27,20 @@ module.exports = class Encrypt extends IMiddleware {
2727

2828
}
2929

30-
static async run(context){
30+
static async run(ctx){
3131

32-
if (!Hoek.reach(context, 'endpoint.MiddlewareConfig.post.encrypt', false)){
33-
return
34-
}
32+
if (!Config){ return }
3533

3634

37-
const msg = new Message(context.input)
38-
const jsonContent = await msg.decrpyt(this.serviceParty.privateIdentity)
39-
const publicKeys = Routines.extractPublicKeys(msg.enc)
35+
const senderStr = JSON.stringify({key: ctx.senderKey})
4036

41-
context.setInputSession(jsonContent.session)
37+
const reply = new Message({msg: ctx.output})
38+
const sender = Identity.fromString(senderStr)
39+
40+
const payload = await reply.encrypt(ctx.party.privateIdentity, sender.key)
41+
42+
ctx.debug('setting payload', payload)
43+
ctx.setOutput(payload)
4244

43-
return {
44-
input: Hoek.reach(content, 'data'),
45-
sender: {
46-
type: 'ecdsa',
47-
public: publicKeys
48-
}
49-
}
5045
}
5146
}

src/service/service-runner.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ class ServiceRunner {
164164

165165
await this.runMiddleware(middlewareCfg, context, 'post')
166166

167-
debug('result', result)
167+
/*debug('ctx.log', context._debugContent)*/
168+
debug('result', context.output)
168169

169-
context.res.send(result)
170+
context.res.send(context.output)
170171

171172
}
172173
catch(err){

0 commit comments

Comments
 (0)