Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fda during init_dpki #58

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
89 changes: 52 additions & 37 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const path = require('path')
const { Config } = require('@holochain/tryorama')
const {
Config
} = require('@holochain/tryorama')

const dnaName = "DeepKey"
const dnaId = "dpki_happ"
Expand All @@ -14,36 +16,39 @@ const networkType = process.env.APP_SPEC_NETWORK_TYPE || "sim2h"
let network = {}
// override the transport_config if we are in the Final Exam context!
if (process.env.HC_TRANSPORT_CONFIG) {
network=require(process.env.HC_TRANSPORT_CONFIG)
network = require(process.env.HC_TRANSPORT_CONFIG)
} else {
network =
( networkType === 'websocket'
? Config.network('websocket')
network =
(networkType === 'websocket' ?
Config.network('websocket')

: networkType === 'memory'
? Config.network('memory')
:
networkType === 'memory' ?
Config.network('memory')

: networkType === 'sim1h'
? {
type: 'sim1h',
dynamo_url: 'http://localhost:8000'
}
:
networkType === 'sim1h' ? {
type: 'sim1h',
dynamo_url: 'http://localhost:8000'
}

: networkType === 'sim2h'
? {
type: 'sim2h',
sim2h_url: 'ws://localhost:9000'
}
:
networkType === 'sim2h' ? {
type: 'sim2h',
sim2h_url: 'ws://localhost:9000'
}

: (() => {throw new Error(`Unsupported network type: ${networkType}`)})()
)
:
(() => {
throw new Error(`Unsupported network type: ${networkType}`)
})()
)
}

const logger = {
type: 'debug',
rules: {
rules: [
{
rules: [{
exclude: true,
pattern: '.*parity.*'
},
Expand Down Expand Up @@ -91,11 +96,16 @@ const logger = {
const commonConfig = {
logger,
network,
passphrase_service: {type:'mock',passphrase:""}
passphrase_service: {
type: 'mock',
passphrase: ""
}
}


const simple_conductor_config = (agent) => Config.gen(({uuid}) => [{
const simple_conductor_config = (agent) => Config.gen(({
uuid
}) => [{
id: 'dpki_happ',
agent: {
id: `${agent}`,
Expand All @@ -109,14 +119,16 @@ const simple_conductor_config = (agent) => Config.gen(({uuid}) => [{
uuid,
}
}],
commonConfig
// dpki: {
// instance_id: 'dpki_happ',
// init_params: {"revocation_key": "HcSCiPdMkst9geux7y7kPoVx3W54Ebwkk6fFWjH9V6oIbqi77H4i9qGXRsDcdbi","signed_auth_key":"zJkRXrrbvbzbH96SpapO5lDWoElpzB1rDE+4zbo/VthM/mp9qNKaVsGiVKnHkqT4f5J4MGN+q18xP/hwQUKyDA=="}
// }
)
commonConfig
// dpki: {
// instance_id: 'dpki_happ',
// init_params: {"revocation_key": "HcSCiPdMkst9geux7y7kPoVx3W54Ebwkk6fFWjH9V6oIbqi77H4i9qGXRsDcdbi","signed_auth_key":"zJkRXrrbvbzbH96SpapO5lDWoElpzB1rDE+4zbo/VthM/mp9qNKaVsGiVKnHkqT4f5J4MGN+q18xP/hwQUKyDA=="}
// }
)

const simple_2_conductor_config = (agent) => Config.gen(({uuid}) => [{
const simple_2_conductor_config = (agent) => Config.gen(({
uuid
}) => [{
id: 'dpki_happ',
agent: {
id: `${agent}`,
Expand All @@ -130,11 +142,14 @@ const simple_2_conductor_config = (agent) => Config.gen(({uuid}) => [{
uuid,
}
}],
commonConfig,
// dpki: {
// instance_id: 'dpki_happ',
// init_params: {"revocation_key": "HcSCI7fRqt5wb7r6i46f5AeGW6zcNuq3i94fQVtFOPromhzoukr9DabcZqzxzir","signed_auth_key":"bQNCtt9Xa7Ii4mCgOGSt8InVLA6HbrFjhYBoc4lDKMtxbY65kQoMNR/mHCuBq5rBYtyaZXG9Jpa9o8WD2eSrCw=="}
// }
)
commonConfig,
// dpki: {
// instance_id: 'dpki_happ',
// init_params: {"revocation_key": "HcSCI7fRqt5wb7r6i46f5AeGW6zcNuq3i94fQVtFOPromhzoukr9DabcZqzxzir","signed_auth_key":"bQNCtt9Xa7Ii4mCgOGSt8InVLA6HbrFjhYBoc4lDKMtxbY65kQoMNR/mHCuBq5rBYtyaZXG9Jpa9o8WD2eSrCw=="}
// }
)

module.exports = { simple_conductor_config, simple_2_conductor_config }
module.exports = {
simple_conductor_config,
simple_2_conductor_config
}
15 changes: 10 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const { Orchestrator, tapeExecutor, combine, callSync, localOnly } = require('@holochain/tryorama')
const {
Orchestrator,
tapeExecutor,
combine,
callSync,
localOnly
} = require('@holochain/tryorama')

const MIN_EXPECTED_SCENARIOS = 1

Expand Down Expand Up @@ -30,17 +36,16 @@ require('./unit_test/manual_dpki/update_auth_entries')(orchestrator.registerScen
require('./unit_test/manual_dpki/set_up_conductor')(orchestrator.registerScenario)
require('./unit_test/manual_dpki/revoke_rev_key')(orchestrator.registerScenario)
require('./unit_test/manual_dpki/test_init')(orchestrator.registerScenario)
require('./unit_test/manual_dpki/notification')(orchestrator.registerScenario)
require('./unit_test/manual_dpki/manual_device_handshake')(orchestrator.registerScenario)

const num = orchestrator.numRegistered()
if (num < MIN_EXPECTED_SCENARIOS) {
console.error(`Expected at least ${MIN_EXPECTED_SCENARIOS} scenarios, but only ${num} were registered!`)
process.exit(1)
}
else {
} else {
console.log(`Registered ${num} scenarios (at least ${MIN_EXPECTED_SCENARIOS} were expected)`)
}

orchestrator.run().then(stats => {
console.log("All done.")
})
})
29 changes: 16 additions & 13 deletions test/manual.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const test = require('tape');
const { Conductor, DnaInstance } = require("@holochain/holochain-nodejs")
const {
Conductor,
DnaInstance
} = require("@holochain/holochain-nodejs")


const toml = `
Expand Down Expand Up @@ -42,18 +45,18 @@ init_params = "{}"


test('Initial test (run)', t => {
Conductor.run(toml, (stop, conductor) => {
Conductor.run(toml, (stop, conductor) => {

const instance = new DnaInstance('deepkey_instance', conductor)
const keyset_root_address = instance.call("dpki", "init_dpki", {})
// console.log("keyset_root->",keyset_root_address);
t.ok(keyset_root_address.Ok)
const instance = new DnaInstance('deepkey_instance', conductor)
const keyset_root_address = instance.call("dpki", "init_dpki", {})
// console.log("keyset_root->",keyset_root_address);
t.ok(keyset_root_address.Ok)

const get_root_address = instance.call("dpki", "get_initialization_data", {})
// console.log("->",get_root_address);
t.ok(get_root_address.Ok)
const get_root_address = instance.call("dpki", "get_initialization_data", {})
// console.log("->",get_root_address);
t.ok(get_root_address.Ok)

stop()
t.end()
})
})
stop()
t.end()
})
})
2 changes: 1 addition & 1 deletion test/unit_test/auto_dpki/test_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// await liza.kill()
// await jack.kill()
// })
// }
// }
54 changes: 54 additions & 0 deletions test/unit_test/manual_dpki/manual_device_handshake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const {
simple_conductor_config,
simple_2_conductor_config
} = require('../../config')

async function liza_conductor_init(agent) {
return await agent.callSync('dpki_happ', "dpki", "init_dpki", {
params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"
})
}

async function jack_conductor_init(agent) {
return await agent.callSync("dpki_happ", "dpki", "init_dpki", {
params: "{\"signed_auth_key\":\"sCkN1Yqaxeso1JicovXBruDXtx20Sofa+I6A6xpe3LjJQ6zvqwrJ3qbbDgLmFIPqF5RAKWTSMI7BZr6+06k/DA==\"}"
})
}

// THis Scenario was wirten to demonstrate manually trying to handshake
// note for Jacks conductor the `init_dpki` only passes signed_auth_key and no FDA
// In this situation you would have to make a manual handshake as demonstrated bellow
module.exports = (scenario) => {
scenario("testing the notification to device handshaking", async (s, t) => {
const {
liza,
jack
} = await s.players({
liza: simple_conductor_config("liza"),
jack: simple_2_conductor_config("jack")
}, true)

await s.consistency()

let a = await liza_conductor_init(liza)
t.ok(a.Ok)
a = await jack_conductor_init(jack)
t.ok(a.Err)
t.equal(a.Err.Internal, "DeepKey Error: init() was successfull but you have to still handshake with your FirstDeepKeyAgent")
const jack_receives = await jack.callSync("dpki_happ", "dpki", "send_handshake_notify", {
to: liza.info('dpki_happ').agentAddress
})
console.log("jack_receives:: ", jack_receives);
t.ok(jack_receives.Ok)

const is_authorized = await liza.callSync("dpki_happ", "dpki", "authorize_device", {
new_agent_hash: jack.info('dpki_happ').agentAddress,
new_agent_signed_xor: jack_receives.Ok
})
console.log("is_authorized:: ", is_authorized);
t.deepEqual(is_authorized.Ok, null)

await liza.kill()
await jack.kill()
})
}
33 changes: 0 additions & 33 deletions test/unit_test/manual_dpki/notification.js

This file was deleted.

51 changes: 33 additions & 18 deletions test/unit_test/manual_dpki/revoke_rev_key.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
const { simple_conductor_config } = require('../../config')
const {
simple_conductor_config
} = require('../../config')

const REVOCATION_KEY = "HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi";
const NEW_REVOCATION_KEY = "HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi";
const REV_SIGNED_BY_REV_KEY = "xLD9u9XLBqr295xacnsaS9MTRmDAAzIpzvIOrR+2wvDOWezD6aFyEGsUoml/MKKga1i718uVmwL//Rze300CAA==";
const BAD_SIGNED_REV_KEY = "Jkz3AWHO5bEZ11OpsNeotTIr3CGH3wZcyqUAae+xEVy+MwXhrAS1lfzUbWSRQgsSMWUNSjYTtE9NNUHXPkQkBg=="

async function conductor_init (liza){
return await liza.callSync('dpki_happ', "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"})
async function conductor_init(liza) {
return await liza.callSync('dpki_happ', "dpki", "init_dpki", {
params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"
})
}

module.exports = (scenario) => {
scenario("testing the initial set up process and trying to update it", async(s, t) => {
const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true)
scenario("testing the initial set up process and trying to update it", async (s, t) => {
const {
liza
} = await s.players({
liza: simple_conductor_config('liza')
}, true)

await s.consistency()

await conductor_init(liza)

// Check if your getting the right hash
// Check if your getting the right hash
const my_rules = await liza.call('dpki_happ', "dpki", "get_rules", {})
console.log("My Rules: ",my_rules.Ok[0]);
t.ok(my_rules.Ok[0].entry.revocationKey,REVOCATION_KEY)

// The signature should not match and throw an error
const err_on_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", {revocation_key:NEW_REVOCATION_KEY, signed_old_revocation_key:BAD_SIGNED_REV_KEY})
console.log("My Rules: ", my_rules.Ok[0]);
t.ok(my_rules.Ok[0].entry.revocationKey, REVOCATION_KEY)

// The signature should not match and throw an error
const err_on_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", {
revocation_key: NEW_REVOCATION_KEY,
signed_old_revocation_key: BAD_SIGNED_REV_KEY
})
console.log(err_on_commit);
t.ok(err_on_commit.Err )
t.ok(err_on_commit.Err)

const sucessfull_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", {revocation_key:NEW_REVOCATION_KEY, signed_old_revocation_key:REV_SIGNED_BY_REV_KEY})
t.ok(sucessfull_commit.Ok )
const sucessfull_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", {
revocation_key: NEW_REVOCATION_KEY,
signed_old_revocation_key: REV_SIGNED_BY_REV_KEY
})
t.ok(sucessfull_commit.Ok)

// Check if your getting the right hash

// Check if your getting the right hash
const my_updated_rules = await liza.call('dpki_happ', "dpki", "get_rules", {})
console.log("My Updated Rules: ",my_updated_rules.Ok[0]);
t.deepEqual(my_updated_rules.Ok[0].entry.revocationKey,NEW_REVOCATION_KEY )
console.log("My Updated Rules: ", my_updated_rules.Ok[0]);
t.deepEqual(my_updated_rules.Ok[0].entry.revocationKey, NEW_REVOCATION_KEY)

await liza.kill()
})
}
}
Loading