boho 0.0.7 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boho.cjs +2 -2
- package/dist/boho.esm.js +2 -2
- package/dist/boho.esm.js.map +1 -1
- package/dist/boho.min.js +2 -2
- package/dist/boho.min.js.map +1 -1
- package/dist/boho.mjs +2 -2
- package/package.json +8 -7
- package/test/AUTH_process_CJS.cjs +92 -0
- package/test/AUTH_process_ESM.js +87 -0
- package/test/ENC_PACK_CJS.cjs +23 -0
- package/test/ENC_PACK_ESM.js +22 -0
- package/test/RAND_CJS.cjs +15 -0
- package/test/{RAND.js → RAND_ESM.js} +1 -1
- package/test-browser/index.html +151 -26
- package/test-browser/loader.html +31 -0
- package/test/AUTH_process.js +0 -118
- package/test/ENC_PACK.js +0 -24
package/test-browser/index.html
CHANGED
|
@@ -1,30 +1,155 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.log('min.js: sha256.hash("hi")', boho.sha256.hash('hi'))
|
|
19
|
-
console.log('min.js: MBP', boho.MBP.Buffer.alloc(33))
|
|
20
|
-
console.log('min.js: RAND', boho.RAND(33))
|
|
21
|
-
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>Mocha Tests</title>
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="mocha"></div>
|
|
11
|
+
|
|
12
|
+
<script src="https://unpkg.com/chai/chai.js"></script>
|
|
13
|
+
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
|
14
|
+
|
|
15
|
+
<script class="mocha-init">
|
|
16
|
+
mocha.setup('bdd');
|
|
17
|
+
mocha.checkLeaks();
|
|
22
18
|
</script>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
<script src="../dist/boho.min.js"></script>
|
|
20
|
+
<script>
|
|
21
|
+
|
|
22
|
+
let assert = chai.assert;
|
|
23
|
+
const RAND = BOHO.RAND
|
|
24
|
+
const Boho = BOHO.Boho
|
|
25
|
+
const MBP = BOHO.MBP
|
|
26
|
+
const MetaSize = BOHO.MetaSize
|
|
27
|
+
const BohoMsg = BOHO.BohoMsg
|
|
28
|
+
const Meta = BOHO.Meta
|
|
29
|
+
|
|
30
|
+
describe('RAND browser', function () {
|
|
31
|
+
describe('for number', function () {
|
|
32
|
+
const num = 16
|
|
33
|
+
it('should return Uint8Array', function () {
|
|
34
|
+
assert.ok(RAND(num) instanceof Uint8Array)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should return number-bytes size of Uint8Array', function () {
|
|
38
|
+
assert.ok(RAND(num).byteLength === num)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('ENC_PACK CJS', function () {
|
|
44
|
+
describe('encryption and decryption', function () {
|
|
45
|
+
const plainData = 'aaaaa'
|
|
46
|
+
const key = 'key'
|
|
47
|
+
|
|
48
|
+
it('should decryptPack.data property has same buffer of origin.', function () {
|
|
49
|
+
const boho = new Boho()
|
|
50
|
+
boho.set_key(key)
|
|
51
|
+
|
|
52
|
+
const encData = boho.encryptPack(plainData)
|
|
53
|
+
const decObj = boho.decryptPack(encData)
|
|
54
|
+
|
|
55
|
+
const srcBuffer = MBP.B8(plainData)
|
|
56
|
+
const resultBuffer = MBP.B8(decObj.data)
|
|
57
|
+
|
|
58
|
+
assert.ok(MBP.equal(srcBuffer, resultBuffer))
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
describe('AUTH process', function () {
|
|
65
|
+
const id = 'id'
|
|
66
|
+
const key = 'key'
|
|
67
|
+
|
|
68
|
+
// client side
|
|
69
|
+
const c = new Boho()
|
|
70
|
+
c.set_id8(id)
|
|
71
|
+
c.set_key(key)
|
|
72
|
+
|
|
73
|
+
// server side
|
|
74
|
+
const s = new Boho()
|
|
75
|
+
const auth_nonce_buffer = s.auth_nonce()
|
|
76
|
+
const auth_hmac_buffer = c.auth_hmac(auth_nonce_buffer)
|
|
77
|
+
|
|
78
|
+
const unpack = MBP.unpack(auth_hmac_buffer, Meta.AUTH_HMAC)
|
|
79
|
+
|
|
80
|
+
// Find hashID8 from DATABASE then set the id and key.
|
|
81
|
+
s.set_id8(id)
|
|
82
|
+
|
|
83
|
+
s.set_key('wrong-key') // if key is wrong.
|
|
84
|
+
const check_auth_hmack_fail = s.check_auth_hmac(unpack)
|
|
85
|
+
|
|
86
|
+
s.set_key(key) // if correct.
|
|
87
|
+
const auth_ack_buffer = s.check_auth_hmac(unpack)
|
|
88
|
+
|
|
89
|
+
const auth_ack_buffer_with_incorrect_hmac = MBP.Buffer.alloc(9)
|
|
90
|
+
const isCorrectSeverHMAC = c.check_auth_ack_hmac(auth_ack_buffer)
|
|
91
|
+
|
|
92
|
+
auth_ack_buffer.copy(auth_ack_buffer_with_incorrect_hmac)
|
|
93
|
+
auth_ack_buffer_with_incorrect_hmac[2] ^= 0x55 // change hmac
|
|
94
|
+
const wrongSeverHMACResult = c.check_auth_ack_hmac(auth_ack_buffer_with_incorrect_hmac)
|
|
95
|
+
|
|
96
|
+
// 1. client send AUTH_REQ first
|
|
97
|
+
|
|
98
|
+
describe('2. sever reply AUTH_NONCE', function () {
|
|
99
|
+
it('should return static size buffer', function () {
|
|
100
|
+
assert.equal(auth_nonce_buffer.byteLength, MetaSize.AUTH_NONCE)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should pack[0] is header type ', function () {
|
|
104
|
+
assert.ok(auth_nonce_buffer[0], BohoMsg.AUTH_NONCE)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('3. client reply AUTH_HMAC', function () {
|
|
109
|
+
it('should return static size buffer', function () {
|
|
110
|
+
assert.equal(auth_hmac_buffer.byteLength, MetaSize.AUTH_HMAC)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should pack[0] is header type ', function () {
|
|
114
|
+
assert.ok(auth_hmac_buffer[0], BohoMsg.AUTH_HMAC)
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
describe('3. sever check AUTH_HMACK pack', function () {
|
|
119
|
+
it('3.1. should success unpack', function () {
|
|
120
|
+
assert.ok(typeof unpack === 'object')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
describe('3.2. check_auth_hmac(obj) ', function () {
|
|
124
|
+
// wrong key of id.
|
|
125
|
+
it('3.2.1. should return false when wrong key', function () {
|
|
126
|
+
assert.ok(!check_auth_hmack_fail)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// correct id and key
|
|
130
|
+
it('3-2.2. should return AUTH_ACK buffer pack when correct key', function () {
|
|
131
|
+
assert.equal(auth_ack_buffer[0], BohoMsg.AUTH_ACK)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
describe('4. client process', function () {
|
|
137
|
+
describe('4.1 check_auth_ack_hmac()', function () {
|
|
138
|
+
it('should return true when correct AUTH_ACK ', function () {
|
|
139
|
+
assert.ok(isCorrectSeverHMAC)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('should return false when AUTH_ACK has wrong hmac', function () {
|
|
143
|
+
assert.ok(!wrongSeverHMACResult)
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<script class="mocha-exec">
|
|
152
|
+
mocha.run();
|
|
153
|
+
</script>
|
|
154
|
+
</body>
|
|
30
155
|
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<h1>loading test1: boho.min.js</h1>
|
|
11
|
+
<p>use global name: boho </p>
|
|
12
|
+
<p>boho has RAND, MBP , Meta,,, </p>
|
|
13
|
+
<h1>loading test2: boho.esm.js</h1>
|
|
14
|
+
<p>embed esm module loader script. check the console.</p>
|
|
15
|
+
<p>this index.html include module two times. </p>
|
|
16
|
+
<script src="../dist/boho.min.js"></script>
|
|
17
|
+
<script>
|
|
18
|
+
console.log('min.js: sha256.hash("hi")', BOHO.sha256.hash('hi'))
|
|
19
|
+
console.log('min.js: MBP', BOHO.MBP.Buffer.alloc(33))
|
|
20
|
+
console.log('min.js: RAND', BOHO.RAND(33))
|
|
21
|
+
console.log('min.js: isSecureContext', isSecureContext)
|
|
22
|
+
|
|
23
|
+
</script>
|
|
24
|
+
<script type="module">
|
|
25
|
+
import { MBP ,sha256 ,RAND } from "../dist/boho.esm.js"
|
|
26
|
+
console.log('esm: sha256.hash("hi")', sha256.hash('hi'))
|
|
27
|
+
console.log('esm: MBP', MBP.Buffer.alloc(33))
|
|
28
|
+
console.log('esm: RAND', RAND(33))
|
|
29
|
+
</script>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
package/test/AUTH_process.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import assert from 'assert/strict'
|
|
2
|
-
import { Boho , MBP , MetaSize, BohoMsg ,Meta } from 'boho'
|
|
3
|
-
|
|
4
|
-
describe('AUTH process', function () {
|
|
5
|
-
|
|
6
|
-
const id = "id"
|
|
7
|
-
const key = "key"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//client side
|
|
11
|
-
let c = new Boho()
|
|
12
|
-
c.set_id8( id )
|
|
13
|
-
c.set_key( key )
|
|
14
|
-
|
|
15
|
-
let s = new Boho() //server side
|
|
16
|
-
|
|
17
|
-
let auth_nonce_buffer = s.auth_nonce()
|
|
18
|
-
let auth_hmac_buffer = c.auth_hmac( auth_nonce_buffer )
|
|
19
|
-
|
|
20
|
-
let unpack = MBP.unpack( auth_hmac_buffer, Meta.AUTH_HMAC )
|
|
21
|
-
|
|
22
|
-
// Find hashID8 from DATABASE then set the id and key.
|
|
23
|
-
s.set_id8( id )
|
|
24
|
-
|
|
25
|
-
s.set_key('wrong-key') // if key is wrong.
|
|
26
|
-
let check_auth_hmack_fail = s.check_auth_hmac( unpack )
|
|
27
|
-
|
|
28
|
-
s.set_key( key ); // if correct.
|
|
29
|
-
let auth_ack_buffer = s.check_auth_hmac( unpack )
|
|
30
|
-
// console.log('auth_ack_buffer', auth_ack_buffer )
|
|
31
|
-
|
|
32
|
-
let auth_ack_buffer_with_incorrect_hmac = MBP.Buffer.alloc(9)
|
|
33
|
-
let isCorrectSeverHMAC = c.check_auth_ack_hmac( auth_ack_buffer )
|
|
34
|
-
|
|
35
|
-
auth_ack_buffer.copy( auth_ack_buffer_with_incorrect_hmac)
|
|
36
|
-
auth_ack_buffer_with_incorrect_hmac[2] ^= 0x55 // change hmac
|
|
37
|
-
let wrongSeverHMACResult = c.check_auth_ack_hmac( auth_ack_buffer_with_incorrect_hmac )
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// 1. client send AUTH_REQ first
|
|
41
|
-
|
|
42
|
-
describe('2. sever reply AUTH_NONCE', function () {
|
|
43
|
-
|
|
44
|
-
it('should return static size buffer', function () {
|
|
45
|
-
// console.log( 'auth-req', auth_nonce_buffer )
|
|
46
|
-
assert.equal( auth_nonce_buffer.byteLength , MetaSize.AUTH_NONCE )
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('should pack[0] is header type ', function () {
|
|
50
|
-
// console.log( 'auth-req', auth_nonce_buffer )
|
|
51
|
-
assert.ok( auth_nonce_buffer[0] , BohoMsg.AUTH_NONCE )
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
describe('3. client reply AUTH_HMAC', function () {
|
|
58
|
-
|
|
59
|
-
it('should return static size buffer', function () {
|
|
60
|
-
// console.log( 'auth-hmac', auth_hmac_buffer )
|
|
61
|
-
assert.equal( auth_hmac_buffer.byteLength , MetaSize.AUTH_HMAC )
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('should pack[0] is header type ', function () {
|
|
65
|
-
// console.log( 'auth-hmac', auth_hmac_buffer )
|
|
66
|
-
assert.ok( auth_hmac_buffer[0] , BohoMsg.AUTH_HMAC )
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
describe('3. sever check AUTH_HMACK pack', function () {
|
|
72
|
-
|
|
73
|
-
it('3.1. should success unpack', function () {
|
|
74
|
-
// console.log( 'unpack object of auth-hmac', unpack )
|
|
75
|
-
assert.ok( typeof unpack === 'object' )
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
describe('3.2. check_auth_hmac(obj) ', function () {
|
|
79
|
-
|
|
80
|
-
// wrong key of id.
|
|
81
|
-
it('3.2.1. should return false when wrong key', function () {
|
|
82
|
-
// console.log( 'auth-fail', check_auth_hmack_fail )
|
|
83
|
-
assert.ok( !check_auth_hmack_fail )
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
// correct id and key
|
|
87
|
-
it('3-2.2. should return AUTH_ACK buffer pack when correct key', function () {
|
|
88
|
-
// console.log( 'auth-ack', auth_ack_buffer )
|
|
89
|
-
assert.equal( auth_ack_buffer[0] , BohoMsg.AUTH_ACK )
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
describe('4. client process', function () {
|
|
98
|
-
|
|
99
|
-
describe('4.1 check_auth_ack_hmac()', function () {
|
|
100
|
-
|
|
101
|
-
it('should return true when correct AUTH_ACK ', function () {
|
|
102
|
-
// console.log( 'auth-ack', auth_ack_buffer )
|
|
103
|
-
assert.ok( isCorrectSeverHMAC )
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('should return false when AUTH_ACK has wrong hmac', function () {
|
|
107
|
-
// console.log( 'auth-ack with wrong hmac', auth_ack_buffer_with_incorrect_hmac )
|
|
108
|
-
assert.ok( !wrongSeverHMACResult )
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
})
|
package/test/ENC_PACK.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import assert from 'assert/strict'
|
|
2
|
-
import { Boho , MBP } from 'boho'
|
|
3
|
-
|
|
4
|
-
describe('ENC_PACK', function () {
|
|
5
|
-
describe('encryption and decryption', function () {
|
|
6
|
-
const plainData = 'aaaaa'
|
|
7
|
-
const key = 'key'
|
|
8
|
-
|
|
9
|
-
it('should decryptPack.data property has same buffer of origin.', function () {
|
|
10
|
-
let boho = new Boho()
|
|
11
|
-
boho.set_key( key )
|
|
12
|
-
|
|
13
|
-
let encData = boho.encryptPack( plainData )
|
|
14
|
-
let decObj = boho.decryptPack( encData )
|
|
15
|
-
|
|
16
|
-
let srcBuffer = MBP.B8( plainData )
|
|
17
|
-
let resultBuffer = MBP.B8( decObj.data )
|
|
18
|
-
// console.log( srcBuffer, resultBuffer )
|
|
19
|
-
|
|
20
|
-
assert.ok( MBP.equal( srcBuffer, resultBuffer) )
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
})
|