Skip to content

Commit f685cca

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
wip: fixing up PolykeyAgent usage
[ci skip]
1 parent c09ab70 commit f685cca

16 files changed

+420
-327
lines changed

src/PolykeyAgent.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ class PolykeyAgent {
267267
keyRing ??
268268
(await KeyRing.createKeyRing({
269269
keysPath,
270+
recoveryCode: optionsDefaulted.keys.recoveryCode,
271+
privateKey: optionsDefaulted.keys.privateKey,
272+
privateKeyPath: optionsDefaulted.keys.privateKeyPath,
270273
passwordOpsLimit: optionsDefaulted.keys.passwordOpsLimit,
271274
passwordMemLimit: optionsDefaulted.keys.passwordMemLimit,
272275
strictMemoryLock: optionsDefaulted.keys.strictMemoryLock,
@@ -701,14 +704,16 @@ class PolykeyAgent {
701704
this.fs = fs;
702705
}
703706

707+
// TODO: add getters for runtime service information?
708+
704709
public async start({
705710
password,
706-
options,
711+
options = {},
707712
workers,
708713
fresh = false,
709714
}: {
710715
password: string;
711-
options: Partial<PolykeyAgentStartOptions>;
716+
options?: Partial<PolykeyAgentStartOptions>;
712717
workers?: number;
713718
fresh?: boolean;
714719
}) {

src/bootstrap/utils.ts

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PasswordMemLimit, PasswordOpsLimit } from '../keys/types';
44
import path from 'path';
55
import Logger from '@matrixai/logger';
66
import { DB } from '@matrixai/db';
7+
import { CertManager } from '@/keys';
78
import * as bootstrapErrors from './errors';
89
import TaskManager from '../tasks/TaskManager';
910
import { IdentitiesManager } from '../identities';
@@ -14,7 +15,7 @@ import { Sigchain } from '../sigchain';
1415
import { ACL } from '../acl';
1516
import { GestaltGraph } from '../gestalts';
1617
import { KeyRing } from '../keys';
17-
import { NodeConnectionManager, NodeGraph, NodeManager } from '../nodes';
18+
import { NodeGraph, NodeManager } from '../nodes';
1819
import { VaultManager } from '../vaults';
1920
import { NotificationsManager } from '../notifications';
2021
import { mkdirExists } from '../utils';
@@ -43,8 +44,6 @@ async function bootstrapState({
4344
// Required parameters
4445
password,
4546
// Optional configuration
46-
// nodePath = config.defaults.nodePath,
47-
// keyRingConfig = {},
4847
options = {},
4948
fresh = false,
5049
// Optional dependencies
@@ -53,30 +52,37 @@ async function bootstrapState({
5352
}: {
5453
password: string;
5554
options?: DeepPartial<BootstrapOptions>;
56-
// NodePath?: string;
57-
// keyRingConfig?: {
58-
// recoveryCode?: RecoveryCode;
59-
// privateKey?: PrivateKey;
60-
// privateKeyPath?: string;
61-
// passwordOpsLimit?: PasswordOpsLimit;
62-
// passwordMemLimit?: PasswordMemLimit;
63-
// };
6455
fresh?: boolean;
6556
fs?: FileSystem;
6657
logger?: Logger;
6758
}): Promise<RecoveryCode | undefined> {
6859
const umask = 0o077;
6960
logger.info(`Setting umask to ${umask.toString(8).padStart(3, '0')}`);
7061
process.umask(umask);
71-
logger.info(`Setting node path to ${nodePath}`);
72-
if (nodePath == null) {
62+
const optionsDefaulted = utils.mergeObjects(options, {
63+
nodePath: config.defaultsUser.nodePath,
64+
keys: {
65+
certDuration: config.defaultsUser.certDuration,
66+
},
67+
});
68+
logger.info(`Setting node path to ${optionsDefaulted.nodePath}`);
69+
if (optionsDefaulted.nodePath == null) {
7370
throw new errors.ErrorUtilsNodePath();
7471
}
75-
await mkdirExists(fs, nodePath);
72+
await mkdirExists(fs, optionsDefaulted.nodePath);
7673
// Setup node path and sub paths
77-
const statusPath = path.join(nodePath, config.paths.statusBase);
78-
const statusLockPath = path.join(nodePath, config.paths.statusLockBase);
79-
const statePath = path.join(nodePath, config.paths.stateBase);
74+
const statusPath = path.join(
75+
optionsDefaulted.nodePath,
76+
config.paths.statusBase,
77+
);
78+
const statusLockPath = path.join(
79+
optionsDefaulted.nodePath,
80+
config.paths.statusLockBase,
81+
);
82+
const statePath = path.join(
83+
optionsDefaulted.nodePath,
84+
config.paths.stateBase,
85+
);
8086
const dbPath = path.join(statePath, config.paths.dbBase);
8187
const keysPath = path.join(statePath, config.paths.keysBase);
8288
const vaultsPath = path.join(statePath, config.paths.vaultsBase);
@@ -90,7 +96,7 @@ async function bootstrapState({
9096
await status.start({ pid: process.pid });
9197
if (!fresh) {
9298
// Check the if number of directory entries is greater than 1 due to status.json and status.lock
93-
if ((await fs.promises.readdir(nodePath)).length > 2) {
99+
if ((await fs.promises.readdir(optionsDefaulted.nodePath)).length > 2) {
94100
throw new bootstrapErrors.ErrorBootstrapExistingState();
95101
}
96102
}
@@ -110,7 +116,12 @@ async function bootstrapState({
110116
fs,
111117
logger: logger.getChild(KeyRing.name),
112118
fresh,
113-
...keyRingConfig,
119+
recoveryCode: optionsDefaulted.recoveryCode,
120+
privateKey: optionsDefaulted.privateKey,
121+
privateKeyPath: optionsDefaulted.privateKeyPath,
122+
passwordOpsLimit: optionsDefaulted.passwordOpsLimit,
123+
passwordMemLimit: optionsDefaulted.passwordMemLimit,
124+
strictMemoryLock: optionsDefaulted.strictMemoryLock,
114125
});
115126
const db = await DB.createDB({
116127
dbPath,
@@ -135,6 +146,19 @@ async function bootstrapState({
135146
},
136147
fresh,
137148
});
149+
const taskManager = await TaskManager.createTaskManager({
150+
db,
151+
logger,
152+
lazy: true,
153+
});
154+
const certManager = await CertManager.createCertManager({
155+
keyRing,
156+
db,
157+
taskManager,
158+
fresh,
159+
logger,
160+
certDuration: optionsDefaulted.certDuration,
161+
});
138162
const sigchain = await Sigchain.createSigchain({
139163
db,
140164
keyRing,
@@ -166,26 +190,12 @@ async function bootstrapState({
166190
keyRing,
167191
logger: logger.getChild(NodeGraph.name),
168192
});
169-
const taskManager = await TaskManager.createTaskManager({
170-
db,
171-
logger,
172-
lazy: true,
173-
});
174-
const nodeConnectionManager = new NodeConnectionManager({
175-
// No streams are created
176-
handleStream: () => {},
177-
keyRing,
178-
nodeGraph,
179-
quicClientConfig: {} as any, // No connections are attempted
180-
crypto: {} as any, // No connections are attempted
181-
quicSocket: {} as any, // No connections are attempted
182-
logger: logger.getChild(NodeConnectionManager.name),
183-
});
193+
184194
const nodeManager = new NodeManager({
185195
db,
186196
keyRing,
187197
nodeGraph,
188-
nodeConnectionManager,
198+
nodeConnectionManager: {} as any, // No connections are attempted
189199
sigchain,
190200
taskManager,
191201
gestaltGraph,
@@ -195,7 +205,7 @@ async function bootstrapState({
195205
await NotificationsManager.createNotificationsManager({
196206
acl,
197207
db,
198-
nodeConnectionManager,
208+
nodeConnectionManager: {} as any, // No connections are attempted
199209
nodeManager,
200210
keyRing,
201211
logger: logger.getChild(NotificationsManager.name),
@@ -206,7 +216,7 @@ async function bootstrapState({
206216
db,
207217
gestaltGraph,
208218
keyRing,
209-
nodeConnectionManager,
219+
nodeConnectionManager: {} as any, // No connections are attempted
210220
vaultsPath,
211221
notificationsManager,
212222
logger: logger.getChild(VaultManager.name),
@@ -227,6 +237,7 @@ async function bootstrapState({
227237
await gestaltGraph.stop();
228238
await acl.stop();
229239
await sigchain.stop();
240+
await certManager.stop();
230241
await taskManager.stop();
231242
await db.stop();
232243
await keyRing.stop();

src/client/handlers/agentStatus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class AgentStatusHandler extends UnaryHandler<
2020
nodeIdEncoded: nodesUtils.encodeNodeId(pkAgent.keyRing.getNodeId()),
2121
clientHost: pkAgent.webSocketServerClient.getHost(),
2222
clientPort: pkAgent.webSocketServerClient.getPort(),
23-
agentHost: pkAgent.quicSocket.host,
24-
agentPort: pkAgent.quicSocket.port,
23+
agentHost: pkAgent.nodeConnectionManager.host,
24+
agentPort: pkAgent.nodeConnectionManager.port,
2525
publicKeyJwk: keysUtils.publicKeyToJWK(pkAgent.keyRing.keyPair.publicKey),
2626
certChainPEM: await pkAgent.certManager.getCertPEMsChainPEM(),
2727
};

0 commit comments

Comments
 (0)