@bedrock/kms-http 14.5.0 → 16.0.0
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/README.md +7 -7
- package/lib/BedrockKeystoreConfigStorage.js +1 -3
- package/lib/helpers.js +14 -11
- package/lib/http.js +8 -10
- package/lib/metering.js +3 -3
- package/lib/middleware.js +13 -15
- package/package.json +21 -16
- package/schemas/bedrock-kms-http.js +1 -8
- package/.eslintrc.cjs +0 -12
- package/.github/workflows/main.yml +0 -77
- package/CHANGELOG.md +0 -386
- package/test/mocha/.eslintrc +0 -9
- package/test/mocha/10-keystore.js +0 -670
- package/test/mocha/11-keystore-kms-client.js +0 -242
- package/test/mocha/20-revocation.js +0 -545
- package/test/mocha/21-revocation-ip-allow-list.js +0 -143
- package/test/mocha/30-operations-generate-key.js +0 -180
- package/test/mocha/31-operations-hmac.js +0 -176
- package/test/mocha/helpers.js +0 -163
- package/test/mocha/mock.data.js +0 -40
- package/test/package.json +0 -64
- package/test/test.config.js +0 -36
- package/test/test.js +0 -31
- package/test/web/.eslintrc +0 -9
- package/test/web/10-api.js +0 -108
- package/test/web/helpers.js +0 -84
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Bedrock Key Management System API module _(bedrock
|
|
1
|
+
# Bedrock Key Management System API module _(@bedrock/kms-http)_
|
|
2
2
|
> HTTP APIs for Bedrock Key Management.
|
|
3
3
|
|
|
4
4
|
## Table of Contents
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
13
|
|
|
14
|
-
- Node.js
|
|
14
|
+
- Node.js 16+ is required.
|
|
15
15
|
|
|
16
16
|
### NPM
|
|
17
17
|
|
|
18
18
|
To install via NPM:
|
|
19
19
|
|
|
20
20
|
```
|
|
21
|
-
npm install
|
|
21
|
+
npm install @bedrock/kms-http
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Development
|
|
@@ -50,7 +50,7 @@ This module exposes the following API endpoints.
|
|
|
50
50
|
{
|
|
51
51
|
sequence: 0,
|
|
52
52
|
controller: 'did:key:z6MkoyZVQSetDxU66AsfinUPzgSEu5N9Jf1anHEY4YCzcE54',
|
|
53
|
-
meterId: 'https://localhost:18443/meters/
|
|
53
|
+
meterId: 'https://localhost:18443/meters/z19ygjQcNmQ9AbG7hCF39Kizs',
|
|
54
54
|
kmsModule: 'ssm-v1'
|
|
55
55
|
}
|
|
56
56
|
```
|
|
@@ -71,7 +71,7 @@ This module exposes the following API endpoints.
|
|
|
71
71
|
```
|
|
72
72
|
{
|
|
73
73
|
id: 'https://localhost:18443/kms/keystores/z1AByGXEmfZnyG8rgM3aVpYxG',
|
|
74
|
-
meterId: 'https://localhost:18443/meters/
|
|
74
|
+
meterId: 'https://localhost:18443/meters/z19ygjQcNmQ9AbG7hCF39Kizs',
|
|
75
75
|
sequence: 0,
|
|
76
76
|
controller: 'did:key:z6MkoyZVQSetDxU66AsfinUPzgSEu5N9Jf1anHEY4YCzcE54',
|
|
77
77
|
kmsModule: 'ssm-v1'
|
|
@@ -109,7 +109,7 @@ This module exposes the following API endpoints.
|
|
|
109
109
|
controller: 'did:key:z6MknP29cPcQ7G76MWmnsuEEdeFya8ij3fXvJcTJYLXadmp9',
|
|
110
110
|
id: 'https://localhost:18443/kms/keystores/z19xPXyqB3dnqKZ7BtVFvqSLH',
|
|
111
111
|
sequence: 1,
|
|
112
|
-
meterId: 'https://localhost:18443/meters/
|
|
112
|
+
meterId: 'https://localhost:18443/meters/z19zMxFgrtXrR3RArhogVQ78T',
|
|
113
113
|
kmsModule: 'ssm-v1'
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -133,7 +133,7 @@ This module exposes the following API endpoints.
|
|
|
133
133
|
```
|
|
134
134
|
{
|
|
135
135
|
id: 'https://localhost:18443/kms/keystores/z1A2Dahs56An4rttS3t2QKi69',
|
|
136
|
-
meterId: 'https://localhost:18443/meters/
|
|
136
|
+
meterId: 'https://localhost:18443/meters/z19zMxFgrtXrR3RArhogVQ78T',
|
|
137
137
|
sequence: 0,
|
|
138
138
|
controller: 'did:key:z6MkoyZVQSetDxU66AsfinUPzgSEu5N9Jf1anHEY4YCzcE54',
|
|
139
139
|
kmsModule: 'ssm-v1'
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as helpers from './helpers.js';
|
|
6
|
-
import {
|
|
6
|
+
import {KeystoreConfigStorage} from '@digitalbazaar/webkms-switch';
|
|
7
7
|
import {keystores} from '@bedrock/kms';
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
|
-
const {KeystoreConfigStorage} = require('@digitalbazaar/webkms-switch');
|
|
10
8
|
|
|
11
9
|
const {util: {BedrockError}} = bedrock;
|
|
12
10
|
|
package/lib/helpers.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
import forwarded from 'forwarded';
|
|
5
|
-
import
|
|
5
|
+
import ipaddr from 'ipaddr.js';
|
|
6
6
|
|
|
7
7
|
export function getKeystoreId({host, req, localId, routes}) {
|
|
8
8
|
if(!host) {
|
|
@@ -12,6 +12,7 @@ export function getKeystoreId({host, req, localId, routes}) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function verifyRequestIp({keystoreConfig, req}) {
|
|
15
|
+
// skip check if no IP allow list configured
|
|
15
16
|
const {ipAllowList} = keystoreConfig;
|
|
16
17
|
if(!ipAllowList) {
|
|
17
18
|
return {verified: true};
|
|
@@ -22,15 +23,17 @@ export function verifyRequestIp({keystoreConfig, req}) {
|
|
|
22
23
|
// IPs will be from the `x-forwarded-for` header.
|
|
23
24
|
const sourceAddresses = forwarded(req);
|
|
24
25
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
// build list of allowed IP ranges from IPv4/IPv6 CIDRs
|
|
27
|
+
const ipAllowRangeList = {
|
|
28
|
+
allow: ipAllowList.map(cidr => ipaddr.parseCIDR(cidr))
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// check if any source address allowed
|
|
32
|
+
const verified = sourceAddresses.some(address => {
|
|
33
|
+
const ip = ipaddr.parse(address);
|
|
34
|
+
// check if in allow list, else deny
|
|
35
|
+
return ipaddr.subnetMatch(ip, ipAllowRangeList, 'deny') === 'allow';
|
|
36
|
+
});
|
|
34
37
|
|
|
35
|
-
return {verified
|
|
38
|
+
return {verified};
|
|
36
39
|
}
|
package/lib/http.js
CHANGED
|
@@ -5,22 +5,20 @@ import * as bedrock from '@bedrock/core';
|
|
|
5
5
|
import * as brZCapStorage from '@bedrock/zcap-storage';
|
|
6
6
|
import * as helpers from './helpers.js';
|
|
7
7
|
import * as middleware from './middleware.js';
|
|
8
|
-
import {asyncHandler} from '@bedrock/express';
|
|
9
|
-
import {createRequire} from 'node:module';
|
|
10
|
-
import {createValidateMiddleware as validate} from '@bedrock/validation';
|
|
11
8
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
keystores,
|
|
10
|
+
defaultModuleManager as moduleManager
|
|
14
11
|
} from '@bedrock/kms';
|
|
15
|
-
import {meters} from '@bedrock/meter-usage-reporter';
|
|
16
12
|
import {
|
|
17
13
|
postKeystoreBody,
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
postRevocationBody,
|
|
15
|
+
updateKeystoreConfigBody
|
|
20
16
|
} from '../schemas/bedrock-kms-http.js';
|
|
21
17
|
import {reportOperationUsage, SERVICE_TYPE} from './metering.js';
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
import {asyncHandler} from '@bedrock/express';
|
|
19
|
+
import {generateRandom} from '@digitalbazaar/webkms-switch';
|
|
20
|
+
import {meters} from '@bedrock/meter-usage-reporter';
|
|
21
|
+
import {createValidateMiddleware as validate} from '@bedrock/validation';
|
|
24
22
|
|
|
25
23
|
const {config, util: {BedrockError}} = bedrock;
|
|
26
24
|
const {cors} = middleware;
|
package/lib/metering.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as brZCapStorage from '@bedrock/zcap-storage';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
keystores,
|
|
8
|
+
defaultModuleManager as moduleManager
|
|
9
9
|
} from '@bedrock/kms';
|
|
10
|
-
import {meters} from '@bedrock/meter-usage-reporter';
|
|
11
10
|
import {logger} from './logger.js';
|
|
11
|
+
import {meters} from '@bedrock/meter-usage-reporter';
|
|
12
12
|
|
|
13
13
|
// configure usage aggregator for webkms meters
|
|
14
14
|
export const SERVICE_TYPE = 'webkms';
|
package/lib/middleware.js
CHANGED
|
@@ -4,27 +4,25 @@
|
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as brZCapStorage from '@bedrock/zcap-storage';
|
|
6
6
|
import * as helpers from './helpers.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
authorizeZcapInvocation as _authorizeZcapInvocation,
|
|
9
|
+
authorizeZcapRevocation as _authorizeZcapRevocation
|
|
10
|
+
} from '@digitalbazaar/ezcap-express';
|
|
11
11
|
import {
|
|
12
12
|
defaultDocumentLoader as documentLoader,
|
|
13
13
|
defaultModuleManager as moduleManager
|
|
14
14
|
} from '@bedrock/kms';
|
|
15
|
+
import {default as _cors} from 'cors';
|
|
16
|
+
import {asyncHandler} from '@bedrock/express';
|
|
17
|
+
import {BedrockKeystoreConfigStorage} from './BedrockKeystoreConfigStorage.js';
|
|
18
|
+
import {createOperationMiddleware} from '@digitalbazaar/webkms-switch';
|
|
19
|
+
import {CryptoLD} from 'crypto-ld';
|
|
20
|
+
import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020';
|
|
21
|
+
import {
|
|
22
|
+
Ed25519VerificationKey2020
|
|
23
|
+
} from '@digitalbazaar/ed25519-verification-key-2020';
|
|
15
24
|
import {logger} from './logger.js';
|
|
16
25
|
import {reportOperationUsage} from './metering.js';
|
|
17
|
-
const require = createRequire(import.meta.url);
|
|
18
|
-
const {
|
|
19
|
-
authorizeZcapInvocation: _authorizeZcapInvocation,
|
|
20
|
-
authorizeZcapRevocation: _authorizeZcapRevocation
|
|
21
|
-
} = require('@digitalbazaar/ezcap-express');
|
|
22
|
-
const {createOperationMiddleware} = require('@digitalbazaar/webkms-switch');
|
|
23
|
-
const {CryptoLD} = require('crypto-ld');
|
|
24
|
-
const {Ed25519Signature2020} =
|
|
25
|
-
require('@digitalbazaar/ed25519-signature-2020');
|
|
26
|
-
const {Ed25519VerificationKey2020} =
|
|
27
|
-
require('@digitalbazaar/ed25519-verification-key-2020');
|
|
28
26
|
|
|
29
27
|
const {config, util: {BedrockError}} = bedrock;
|
|
30
28
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/kms-http",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bedrock KMS HTTP API",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*.js",
|
|
9
|
+
"schemas/**/*.js"
|
|
10
|
+
],
|
|
7
11
|
"scripts": {
|
|
8
12
|
"lint": "eslint ."
|
|
9
13
|
},
|
|
@@ -24,35 +28,36 @@
|
|
|
24
28
|
},
|
|
25
29
|
"homepage": "https://github.com/digitalbazaar/bedrock-kms-http",
|
|
26
30
|
"dependencies": {
|
|
27
|
-
"@digitalbazaar/ed25519-signature-2020": "^
|
|
28
|
-
"@digitalbazaar/ed25519-verification-key-2020": "^
|
|
29
|
-
"@digitalbazaar/ezcap-express": "^
|
|
30
|
-
"@digitalbazaar/webkms-switch": "^
|
|
31
|
+
"@digitalbazaar/ed25519-signature-2020": "^4.0.1",
|
|
32
|
+
"@digitalbazaar/ed25519-verification-key-2020": "^4.0.0",
|
|
33
|
+
"@digitalbazaar/ezcap-express": "^7.0.0",
|
|
34
|
+
"@digitalbazaar/webkms-switch": "^11.0.0",
|
|
31
35
|
"cidr-regex": "^3.1.1",
|
|
32
36
|
"cors": "^2.8.5",
|
|
33
|
-
"crypto-ld": "^
|
|
37
|
+
"crypto-ld": "^7.0.0",
|
|
34
38
|
"forwarded": "^0.2.0",
|
|
35
|
-
"
|
|
39
|
+
"ipaddr.js": "^2.0.1"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
|
-
"@bedrock/app-identity": "^
|
|
39
|
-
"@bedrock/core": "^6.0.
|
|
42
|
+
"@bedrock/app-identity": "^4.0.0",
|
|
43
|
+
"@bedrock/core": "^6.0.1",
|
|
40
44
|
"@bedrock/express": "^8.0.0",
|
|
41
|
-
"@bedrock/kms": "^
|
|
42
|
-
"@bedrock/meter-usage-reporter": "^
|
|
45
|
+
"@bedrock/kms": "^12.0.0",
|
|
46
|
+
"@bedrock/meter-usage-reporter": "^8.0.0",
|
|
43
47
|
"@bedrock/validation": "^7.0.0",
|
|
44
|
-
"@bedrock/zcap-storage": "^
|
|
48
|
+
"@bedrock/zcap-storage": "^8.0.0"
|
|
45
49
|
},
|
|
46
50
|
"directories": {
|
|
47
51
|
"lib": "./lib"
|
|
48
52
|
},
|
|
49
53
|
"devDependencies": {
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"eslint-config-digitalbazaar": "^
|
|
52
|
-
"eslint-plugin-jsdoc": "^39.
|
|
54
|
+
"eslint": "^8.18.0",
|
|
55
|
+
"eslint-config-digitalbazaar": "^4.0.1",
|
|
56
|
+
"eslint-plugin-jsdoc": "^39.3.3",
|
|
57
|
+
"eslint-plugin-unicorn": "^43.0.0",
|
|
53
58
|
"jsdoc-to-markdown": "^7.1.1"
|
|
54
59
|
},
|
|
55
60
|
"engines": {
|
|
56
|
-
"node": ">=
|
|
61
|
+
"node": ">=16"
|
|
57
62
|
}
|
|
58
63
|
}
|
|
@@ -13,11 +13,6 @@ const id = {
|
|
|
13
13
|
type: 'string'
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const referenceId = {
|
|
17
|
-
title: 'referenceId',
|
|
18
|
-
type: 'string'
|
|
19
|
-
};
|
|
20
|
-
|
|
21
16
|
const delegatedZcap = {
|
|
22
17
|
title: 'delegatedZcap',
|
|
23
18
|
type: 'object',
|
|
@@ -114,7 +109,7 @@ const ipAllowList = {
|
|
|
114
109
|
items: {
|
|
115
110
|
type: 'string',
|
|
116
111
|
// leading and trailing slashes in regex must be removed
|
|
117
|
-
pattern: cidrRegex
|
|
112
|
+
pattern: cidrRegex({exact: true}).toString().slice(1, -1),
|
|
118
113
|
}
|
|
119
114
|
};
|
|
120
115
|
|
|
@@ -138,7 +133,6 @@ const postKeystoreBody = {
|
|
|
138
133
|
properties: {
|
|
139
134
|
controller,
|
|
140
135
|
ipAllowList,
|
|
141
|
-
referenceId,
|
|
142
136
|
sequence,
|
|
143
137
|
kmsModule,
|
|
144
138
|
meterId
|
|
@@ -158,7 +152,6 @@ const updateKeystoreConfigBody = {
|
|
|
158
152
|
controller,
|
|
159
153
|
id,
|
|
160
154
|
ipAllowList,
|
|
161
|
-
referenceId,
|
|
162
155
|
sequence,
|
|
163
156
|
kmsModule,
|
|
164
157
|
meterId
|
package/.eslintrc.cjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
name: Bedrock Node.js CI
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
lint:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
timeout-minutes: 10
|
|
9
|
-
strategy:
|
|
10
|
-
matrix:
|
|
11
|
-
node-version: [16.x]
|
|
12
|
-
steps:
|
|
13
|
-
- uses: actions/checkout@v2
|
|
14
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
15
|
-
uses: actions/setup-node@v1
|
|
16
|
-
with:
|
|
17
|
-
node-version: ${{ matrix.node-version }}
|
|
18
|
-
- run: npm install
|
|
19
|
-
- name: Run eslint
|
|
20
|
-
run: npm run lint
|
|
21
|
-
test-node:
|
|
22
|
-
needs: [lint]
|
|
23
|
-
runs-on: ubuntu-latest
|
|
24
|
-
timeout-minutes: 10
|
|
25
|
-
services:
|
|
26
|
-
mongodb:
|
|
27
|
-
image: mongo:4.4
|
|
28
|
-
ports:
|
|
29
|
-
- 27017:27017
|
|
30
|
-
strategy:
|
|
31
|
-
matrix:
|
|
32
|
-
node-version: [14.x, 16.x]
|
|
33
|
-
steps:
|
|
34
|
-
- uses: actions/checkout@v2
|
|
35
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
36
|
-
uses: actions/setup-node@v1
|
|
37
|
-
with:
|
|
38
|
-
node-version: ${{ matrix.node-version }}
|
|
39
|
-
- run: |
|
|
40
|
-
npm install
|
|
41
|
-
cd test
|
|
42
|
-
npm install
|
|
43
|
-
- name: Run test with Node.js ${{ matrix.node-version }}
|
|
44
|
-
run: |
|
|
45
|
-
cd test
|
|
46
|
-
npm test
|
|
47
|
-
coverage:
|
|
48
|
-
needs: [test-node]
|
|
49
|
-
runs-on: ubuntu-latest
|
|
50
|
-
timeout-minutes: 10
|
|
51
|
-
services:
|
|
52
|
-
mongodb:
|
|
53
|
-
image: mongo:4.4
|
|
54
|
-
ports:
|
|
55
|
-
- 27017:27017
|
|
56
|
-
strategy:
|
|
57
|
-
matrix:
|
|
58
|
-
node-version: [16.x]
|
|
59
|
-
steps:
|
|
60
|
-
- uses: actions/checkout@v2
|
|
61
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
62
|
-
uses: actions/setup-node@v1
|
|
63
|
-
with:
|
|
64
|
-
node-version: ${{ matrix.node-version }}
|
|
65
|
-
- run: |
|
|
66
|
-
npm install
|
|
67
|
-
cd test
|
|
68
|
-
npm install
|
|
69
|
-
- name: Generate coverage report
|
|
70
|
-
run: |
|
|
71
|
-
cd test
|
|
72
|
-
npm run coverage-ci
|
|
73
|
-
- name: Upload coverage to Codecov
|
|
74
|
-
uses: codecov/codecov-action@v2
|
|
75
|
-
with:
|
|
76
|
-
file: ./test/coverage/lcov.info
|
|
77
|
-
fail_ci_if_error: true
|