@bedrock/kms-http 22.0.0 → 23.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/lib/helpers.js +5 -6
- package/lib/http.js +1 -1
- package/lib/middleware.js +3 -40
- package/package.json +2 -2
package/lib/helpers.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
4
5
|
import forwarded from 'forwarded';
|
|
5
6
|
import ipaddr from 'ipaddr.js';
|
|
6
7
|
|
|
7
|
-
export function getKeystoreId({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return `https://${host}${routes.keystores}/${localId}`;
|
|
8
|
+
export function getKeystoreId({localId, routes}) {
|
|
9
|
+
const {baseUri} = bedrock.config.server;
|
|
10
|
+
return `${baseUri}${routes.keystores}/${localId}`;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export function verifyRequestIp({keystoreConfig, req}) {
|
package/lib/http.js
CHANGED
|
@@ -110,7 +110,7 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
|
|
|
110
110
|
|
|
111
111
|
// create a keystore for the controller
|
|
112
112
|
const random = await generateRandom();
|
|
113
|
-
const id = helpers.getKeystoreId({
|
|
113
|
+
const id = helpers.getKeystoreId({localId: random, routes});
|
|
114
114
|
const config = {id, meterId, ...req.body};
|
|
115
115
|
const record = await keystores.insert({config});
|
|
116
116
|
res.status(201).location(id).json(record.config);
|
package/lib/middleware.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as brZCapStorage from '@bedrock/zcap-storage';
|
|
@@ -20,6 +20,7 @@ import {defaultModuleManager as moduleManager} from '@bedrock/kms';
|
|
|
20
20
|
import {reportOperationUsage} from './metering.js';
|
|
21
21
|
|
|
22
22
|
const {config, util: {BedrockError}} = bedrock;
|
|
23
|
+
const {helpers: {inspectCapabilityChain}} = brZCapStorage;
|
|
23
24
|
|
|
24
25
|
const FIVE_MINUTES = 1000 * 60 * 5;
|
|
25
26
|
|
|
@@ -31,7 +32,7 @@ export function createGetKeystoreConfig({routes}) {
|
|
|
31
32
|
return asyncHandler(async function _getKeystoreConfig(req, res, next) {
|
|
32
33
|
if(!req.webkms) {
|
|
33
34
|
const keystoreId = helpers.getKeystoreId(
|
|
34
|
-
{
|
|
35
|
+
{localId: req.params.keystoreId, routes});
|
|
35
36
|
const configRecord = await storage.get({
|
|
36
37
|
id: keystoreId, req, returnRecord: true
|
|
37
38
|
});
|
|
@@ -200,44 +201,6 @@ async function getVerifier({keyId, documentLoader}) {
|
|
|
200
201
|
return {verifier, verificationMethod};
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
async function inspectCapabilityChain({
|
|
204
|
-
capabilityChain, capabilityChainMeta
|
|
205
|
-
}) {
|
|
206
|
-
// if capability chain has only root, there's nothing to check as root
|
|
207
|
-
// zcaps cannot be revoked
|
|
208
|
-
if(capabilityChain.length === 1) {
|
|
209
|
-
return {valid: true};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// collect capability IDs and delegators for all delegated capabilities in
|
|
213
|
-
// chain (skip root) so they can be checked for revocation
|
|
214
|
-
const capabilities = [];
|
|
215
|
-
for(const [i, capability] of capabilityChain.entries()) {
|
|
216
|
-
// skip root zcap, it cannot be revoked
|
|
217
|
-
if(i === 0) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const [{purposeResult}] = capabilityChainMeta[i].verifyResult.results;
|
|
221
|
-
if(purposeResult && purposeResult.delegator) {
|
|
222
|
-
capabilities.push({
|
|
223
|
-
capabilityId: capability.id,
|
|
224
|
-
delegator: purposeResult.delegator.id,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const revoked = await brZCapStorage.revocations.isRevoked({capabilities});
|
|
230
|
-
if(revoked) {
|
|
231
|
-
return {
|
|
232
|
-
valid: false,
|
|
233
|
-
error: new Error(
|
|
234
|
-
'One or more capabilities in the chain have been revoked.')
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return {valid: true};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
204
|
function onError({error}) {
|
|
242
205
|
if(!(error instanceof BedrockError)) {
|
|
243
206
|
// always expose cause message and name; expose cause details as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/kms-http",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "23.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bedrock KMS HTTP API",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@bedrock/security-context": "^9.0.0",
|
|
50
50
|
"@bedrock/validation": "^7.1.1",
|
|
51
51
|
"@bedrock/veres-one-context": "^16.0.0",
|
|
52
|
-
"@bedrock/zcap-storage": "^9.
|
|
52
|
+
"@bedrock/zcap-storage": "^9.3.0"
|
|
53
53
|
},
|
|
54
54
|
"directories": {
|
|
55
55
|
"lib": "./lib"
|