Browse Source

remove keyPair fn

Kieran Gibb 1 year ago
parent
commit
b90577e34f
No known key found for this signature in database
5 changed files with 37 additions and 84 deletions
  1. 0
    10
      index.js
  2. 0
    27
      lib/keys.js
  3. 0
    1
      package.json
  4. 37
    37
      test/index.test.js
  5. 0
    9
      yarn.lock

+ 0
- 10
index.js View File

@@ -5,8 +5,6 @@ const os = require('os')
5 5
 const mkdirp = require('mkdirp')
6 6
 const crypto = require('cobox-crypto')
7 7
 const constants = require('cobox-constants')
8
-const { loadParentKey, saveParentKey } = require('./lib/keys')
9
-const sodium = require('sodium-native')
10 8
 
11 9
 const CONFIG_FILE = 'config.yml'
12 10
 
@@ -42,14 +40,6 @@ class CoBoxConfig {
42 40
       this.load()
43 41
     }
44 42
 
45
-    this.deriveKeyPair = (id, context) => {
46
-      var parentKey = loadParentKey(this.root) || crypto.masterKey()
47
-      saveParentKey(this.root, parentKey)
48
-      var keyPair = crypto.keyPair(parentKey, id, context)
49
-      sodium.sodium_memzero(parentKey)
50
-      return keyPair
51
-    }
52
-
53 43
     this.groups = KeyHandler(this._groups)
54 44
     this.replicators = KeyHandler(this._replicators)
55 45
     this.devices = KeyHandler(this._devices)

+ 0
- 27
lib/keys.js View File

@@ -1,27 +0,0 @@
1
-const mkdirp = require('mkdirp')
2
-const fs = require('fs')
3
-const path = require('path')
4
-const assert = require('assert')
5
-
6
-function saveParentKey (storage, encryptionKey) {
7
-  var keyPath = path.join(storage, 'parent_key')
8
-  if (!fs.existsSync(keyPath)) {
9
-    mkdirp.sync(path.dirname(keyPath))
10
-    fs.writeFileSync(keyPath, encryptionKey, {
11
-      mode: fs.constants.S_IRUSR
12
-    })
13
-  }
14
-
15
-  assert(fs.existsSync(keyPath), 'failed to store parent_key')
16
-}
17
-
18
-function loadParentKey (storage) {
19
-  try { return fs.readFileSync(path.join(storage, 'parent_key')) }
20
-  catch (err) { return }
21
-}
22
-
23
-module.exports = {
24
-  loadParentKey,
25
-  saveParentKey
26
-}
27
-

+ 0
- 1
package.json View File

@@ -16,7 +16,6 @@
16 16
     "pino": "^5.13.2",
17 17
     "proxyquire": "^2.1.3",
18 18
     "sinon": "^8.1.1",
19
-    "sodium-native": "^2.4.9",
20 19
     "urlsafe-base64": "^1.0.0"
21 20
   },
22 21
   "devDependencies": {

+ 37
- 37
test/index.test.js View File

@@ -21,55 +21,55 @@ describe('load', (context) => {
21 21
   })
22 22
 })
23 23
 
24
-describe('parent_key', (context) => {
25
-  context('constructor() - generates and saves new parent_key', (assert, next) => {
26
-    var storage = tmp()
27
-    var spy = sinon.spy(crypto)
28
-    var saveStub = sinon.stub().returns(true)
24
+// describe('parent_key', (context) => {
25
+//   context('constructor() - generates and saves new parent_key', (assert, next) => {
26
+//     var storage = tmp()
27
+//     var spy = sinon.spy(crypto)
28
+//     var saveStub = sinon.stub().returns(true)
29 29
 
30
-    var ProxyConfig = proxyquire('../', {
31
-      'cobox-crypto': spy,
32
-      './lib/keys': { saveParentKey: saveStub }
33
-    })
30
+//     var ProxyConfig = proxyquire('../', {
31
+//       'cobox-crypto': spy,
32
+//       './lib/keys': { saveParentKey: saveStub }
33
+//     })
34 34
 
35
-    var config = ProxyConfig(storage)
35
+//     var config = ProxyConfig(storage)
36 36
 
37
-    assert.ok(config, 'config created')
37
+//     assert.ok(config, 'config created')
38 38
 
39
-    config.deriveKeyPair(1, 'hello')
39
+//     config.deriveKeyPair(1, 'hello')
40 40
 
41
-    assert.ok(spy.masterKey.calledOnce, 'calls crypto.masterKey()')
42
-    assert.ok(saveStub.calledOnce, 'saves parent key')
41
+//     assert.ok(spy.masterKey.calledOnce, 'calls crypto.masterKey()')
42
+//     assert.ok(saveStub.calledOnce, 'saves parent key')
43 43
 
44
-    cleanup(storage, next)
45
-  })
44
+//     cleanup(storage, next)
45
+//   })
46 46
 
47
-  context('constructor() - loads parent_key from path', (assert, next) => {
48
-    var storage = tmp()
49
-    var address = crypto.address()
50
-    var parentKey = crypto.masterKey()
47
+//   context('constructor() - loads parent_key from path', (assert, next) => {
48
+//     var storage = tmp()
49
+//     var address = crypto.address()
50
+//     var parentKey = crypto.masterKey()
51 51
 
52
-    var keyPath = path.join(storage, 'parent_key')
53
-    mkdirp.sync(path.dirname(keyPath))
54
-    fs.writeFileSync(keyPath, parentKey, { mode: fs.constants.S_IRUSR })
52
+//     var keyPath = path.join(storage, 'parent_key')
53
+//     mkdirp.sync(path.dirname(keyPath))
54
+//     fs.writeFileSync(keyPath, parentKey, { mode: fs.constants.S_IRUSR })
55 55
 
56
-    var loadStub = sinon.stub().returns(parentKey)
57
-    var saveStub = sinon.stub().returns(true)
56
+//     var loadStub = sinon.stub().returns(parentKey)
57
+//     var saveStub = sinon.stub().returns(true)
58 58
 
59
-    var ProxyConfig = proxyquire('../', { './lib/keys': {
60
-      loadParentKey: loadStub,
61
-      saveParentKey: saveStub
62
-    }
63
-    })
59
+//     var ProxyConfig = proxyquire('../', { './lib/keys': {
60
+//       loadParentKey: loadStub,
61
+//       saveParentKey: saveStub
62
+//     }
63
+//     })
64 64
 
65
-    var config = ProxyConfig(storage, address)
66
-    config.deriveKeyPair(1, 'hello')
65
+//     var config = ProxyConfig(storage, address)
66
+//     config.deriveKeyPair(1, 'hello')
67 67
 
68
-    assert.ok(loadStub.calledWith(storage), 'key is loaded')
69
-    assert.ok(saveStub.calledWith(storage, parentKey), 'key is saved')
70
-    cleanup(storage, next)
71
-  })
72
-})
68
+//     assert.ok(loadStub.calledWith(storage), 'key is loaded')
69
+//     assert.ok(saveStub.calledWith(storage, parentKey), 'key is saved')
70
+//     cleanup(storage, next)
71
+//   })
72
+// })
73 73
 
74 74
 describe('options', (context) => {
75 75
   context('reload', (assert, next) => {

+ 0
- 9
yarn.lock View File

@@ -1492,15 +1492,6 @@ sodium-native@^2.0.0, sodium-native@^2.4.2:
1492 1492
     nan "^2.14.0"
1493 1493
     node-gyp-build "^4.1.0"
1494 1494
 
1495
-sodium-native@^2.4.9:
1496
-  version "2.4.9"
1497
-  resolved "https://registry.yarnpkg.com/sodium-native/-/sodium-native-2.4.9.tgz#7a7beb997efdbd2c773a385fb959f0cead5f5162"
1498
-  integrity sha512-mbkiyA2clyfwAyOFIzMvsV6ny2KrKEIhFVASJxWfsmgfUEymgLIS2MLHHcGIQMkrcKhPErRaMR5Dzv0EEn+BWg==
1499
-  dependencies:
1500
-    ini "^1.3.5"
1501
-    nan "^2.14.0"
1502
-    node-gyp-build "^4.1.0"
1503
-
1504 1495
 sodium-universal@^2.0.0:
1505 1496
   version "2.0.0"
1506 1497
   resolved "https://registry.yarnpkg.com/sodium-universal/-/sodium-universal-2.0.0.tgz#cfb4e1a9c4afece4382b2c23c53439b443bd2af3"