Commit 21deb97a3ee7ca191aa07a8ae90da508fd57388b
remove legacy tests, test signObj, verifyObj with hmac
Dominic Tarr committed on 10/3/2016, 8:47:24 PMParent: 433b030af5cc6d76e4737696333b01cfb6b58731
Files changed
test/index.js | changed |
test/index.js | |||
---|---|---|---|
@@ -26,38 +26,35 @@ | |||
26 | 26 … | t.equal(k1.public.toString('hex'), k2.public.toString('hex')) | |
27 | 27 … | t.end() | |
28 | 28 … | }) | |
29 | 29 … | ||
30 | -tape('sign and verify', function (t) { | ||
31 | - var keys = ssbkeys.generate() | ||
32 | - var msg = ssbkeys.hash("HELLO THERE?") | ||
33 | - var sig = ssbkeys.sign(keys, msg) | ||
34 | - console.log('public', keys.public) | ||
35 | - console.log('sig', sig) | ||
36 | - t.ok(sig) | ||
37 | - t.equal(ssbkeys.getTag(sig), 'sig.ed25519') | ||
38 | - t.ok(ssbkeys.verify(keys, sig, msg)) | ||
30 … | +tape('sign and verify a javascript object', function (t) { | ||
39 | 31 … | ||
40 | - t.end() | ||
32 … | + var obj = require('../package.json') | ||
33 … | + var hmac_key = crypto.randomBytes(32) | ||
34 … | + var hmac_key2 = crypto.randomBytes(32) | ||
35 … | + console.log(obj) | ||
41 | 36 … | ||
42 | -}) | ||
43 | - | ||
44 | -tape('sign and verify, call with keys directly', function (t) { | ||
45 | - | ||
46 | 37 … | var keys = ssbkeys.generate() | |
47 | - var msg = ssbkeys.hash("HELLO THERE?") | ||
48 | - var sig = ssbkeys.sign(keys.private, msg) | ||
49 | - console.log('public', keys.public) | ||
50 | - console.log('sig', sig) | ||
38 … | + var sig = ssbkeys.signObj(keys.private, hmac_key, obj) | ||
39 … | + console.log(sig) | ||
51 | 40 … | t.ok(sig) | |
52 | - t.equal(ssbkeys.getTag(sig), 'sig.ed25519') | ||
53 | - t.ok(ssbkeys.verify(keys.public, sig, msg)) | ||
54 | - | ||
41 … | + //verify must be passed the key to correctly verify | ||
42 … | + t.notOk(ssbkeys.verifyObj(keys, sig)) | ||
43 … | + t.notOk(ssbkeys.verifyObj({public: keys.public}, sig)) | ||
44 … | + t.ok(ssbkeys.verifyObj(keys, hmac_key, sig)) | ||
45 … | + t.ok(ssbkeys.verifyObj({public: keys.public}, hmac_key, sig)) | ||
46 … | + //a different hmac_key fails to verify | ||
47 … | + t.notOk(ssbkeys.verifyObj(keys, hmac_key2, sig)) | ||
48 … | + t.notOk(ssbkeys.verifyObj({public: keys.public}, hmac_key2, sig)) | ||
55 | 49 … | t.end() | |
56 | 50 … | ||
57 | 51 … | }) | |
58 | 52 … | ||
59 | -tape('sign and verify a javascript object', function (t) { | ||
53 … | +//allow sign and verify to also take a separate key | ||
54 … | +//so that we can create signatures that cannot be used in other places. | ||
55 … | +//(i.e. testnet) avoiding chosen protocol attacks. | ||
56 … | +tape('sign and verify a hmaced object javascript object', function (t) { | ||
60 | 57 … | ||
61 | 58 … | var obj = require('../package.json') | |
62 | 59 … | ||
63 | 60 … | console.log(obj) | |
@@ -65,61 +62,14 @@ | |||
65 | 62 … | var keys = ssbkeys.generate() | |
66 | 63 … | var sig = ssbkeys.signObj(keys.private, obj) | |
67 | 64 … | console.log(sig) | |
68 | 65 … | t.ok(sig) | |
69 | - t.ok(ssbkeys.verifyObj(keys, sig, obj)) | ||
66 … | + t.ok(ssbkeys.verifyObj(keys, sig)) | ||
67 … | + t.ok(ssbkeys.verifyObj({public: keys.public}, sig)) | ||
70 | 68 … | t.end() | |
71 | 69 … | ||
72 | 70 … | }) | |
73 | 71 … | ||
74 | -//tape('test legacy curve: k256', function (t) { | ||
75 | -// var keys = ssbkeys.generate('k256') | ||
76 | -// | ||
77 | -// var msg = ssbkeys.hash("LEGACY SYSTEMS") | ||
78 | -// var sig = ssbkeys.sign(keys, msg) | ||
79 | -// | ||
80 | -// console.log('public', keys.public) | ||
81 | -// console.log('sig', sig) | ||
82 | -// | ||
83 | -// t.ok(sig) | ||
84 | -// t.equal(ssbkeys.getTag(sig), 'sig.k256') | ||
85 | -// t.ok(ssbkeys.verify(keys, sig, msg)) | ||
86 | -// | ||
87 | -// t.end() | ||
88 | -//}) | ||
89 | -// | ||
90 | -//tape('create and load async, legacy', function (t) { | ||
91 | -// | ||
92 | -// ssbkeys.create(path, 'k256', function(err, k1) { | ||
93 | -// if (err) throw err | ||
94 | -// ssbkeys.load(path, function(err, k2) { | ||
95 | -// if (err) throw err | ||
96 | -// | ||
97 | -// t.equal(k2.curve, 'k256') | ||
98 | -// t.equal(k1.id, k2.id) | ||
99 | -// t.equal(k1.private, k2.private) | ||
100 | -// t.equal(k1.public, k2.public) | ||
101 | -// | ||
102 | -// t.end() | ||
103 | -// }) | ||
104 | -// }) | ||
105 | -//}) | ||
106 | - | ||
107 | -//tape('create and load sync, legacy', function (t) { | ||
108 | -// | ||
109 | -// var k1 = ssbkeys.createSync(path, 'k256', true) | ||
110 | -// var k2 = ssbkeys.loadSync(path) | ||
111 | -// | ||
112 | -// console.log(k2) | ||
113 | -// | ||
114 | -// t.equal(k2.curve, 'k256') | ||
115 | -// t.equal(k1.id, k2.id) | ||
116 | -// t.equal(k1.private, k2.private) | ||
117 | -// t.equal(k1.public, k2.public) | ||
118 | -// | ||
119 | -// t.end() | ||
120 | -//}) | ||
121 | -// | ||
122 | 72 … | tape('seeded keys, ed25519', function (t) { | |
123 | 73 … | ||
124 | 74 … | var seed = crypto.randomBytes(32) | |
125 | 75 … | var k1 = ssbkeys.generate('ed25519', seed) | |
@@ -130,20 +80,8 @@ | |||
130 | 80 … | t.end() | |
131 | 81 … | ||
132 | 82 … | }) | |
133 | 83 … | ||
134 | -//tape('seeded keys, k256', function (t) { | ||
135 | -// | ||
136 | -// var seed = crypto.randomBytes(32) | ||
137 | -// var k1 = ssbkeys.generate('k256', seed) | ||
138 | -// var k2 = ssbkeys.generate('k256', seed) | ||
139 | -// | ||
140 | -// t.deepEqual(k1, k2) | ||
141 | -// | ||
142 | -// t.end() | ||
143 | -// | ||
144 | -//}) | ||
145 | -// | ||
146 | 84 … | tape('ed25519 id === "@" ++ pubkey', function (t) { | |
147 | 85 … | ||
148 | 86 … | var keys = ssbkeys.generate('ed25519') | |
149 | 87 … | t.equal(keys.id, '@' + keys.public) | |
@@ -151,4 +89,12 @@ | |||
151 | 89 … | t.end() | |
152 | 90 … | ||
153 | 91 … | }) | |
154 | 92 … | ||
93 … | + | ||
94 … | + | ||
95 … | + | ||
96 … | + | ||
97 … | + | ||
98 … | + | ||
99 … | + | ||
100 … | + |
Built with git-ssb-web