Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@
"devDependencies": {
"@matrixai/errors": "^1.2.0",
"@matrixai/logger": "^3.1.0",
"@matrixai/ws": "1.1.7",
"commander": "^8.3.0",
"polykey": "^1.2.1-alpha.14",
"polykey": "^1.2.1-alpha.17",
"threads": "^1.6.5",
"@swc/core": "1.3.82",
"@swc/jest": "^0.2.29",
Expand Down
30 changes: 6 additions & 24 deletions src/agent/CommandLockAll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import type { WebSocketClient } from '@matrixai/ws';
import path from 'path';
import config from 'polykey/dist/config';
import CommandPolykey from '../CommandPolykey';
Expand All @@ -19,8 +18,6 @@ class CommandLockAll extends CommandPolykey {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const { WebSocketClient } = await import('@matrixai/ws');
const clientUtils = await import('polykey/dist/client/utils');
const { default: Session } = await import(
'polykey/dist/sessions/Session'
);
Expand All @@ -41,37 +38,23 @@ class CommandLockAll extends CommandPolykey {
fs: this.fs,
logger: this.logger.getChild(Session.name),
});
let webSocketClient: WebSocketClient;
let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
if (webSocketClient != null) {
await webSocketClient.destroy({ force: true });
}
});
try {
webSocketClient = await WebSocketClient.createWebSocketClient({
config: {
verifyPeer: true,
verifyCallback: async (certs) => {
await clientUtils.verifyServerCertificateChain(
[clientOptions.nodeId],
certs,
);
},
},
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
logger: this.logger.getChild(WebSocketClient.name),
});
pkClient = await PolykeyClient.createPolykeyClient({
streamFactory: () => webSocketClient.connection.newStream(),
nodePath: options.nodePath,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClientClient.methods.agentLockAll({
pkClient.rpcClient.methods.agentLockAll({
metadata: auth,
}),
auth,
Expand All @@ -80,7 +63,6 @@ class CommandLockAll extends CommandPolykey {
await session.destroy();
} finally {
if (pkClient! != null) await pkClient.stop();
if (webSocketClient! != null) await webSocketClient.destroy();
}
});
}
Expand Down
30 changes: 6 additions & 24 deletions src/agent/CommandStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import type { WebSocketClient } from '@matrixai/ws';
import type { StatusResultMessage } from 'polykey/dist/client/types';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
Expand All @@ -18,8 +17,6 @@ class CommandStatus extends CommandPolykey {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const { WebSocketClient } = await import('@matrixai/ws');
const clientUtils = await import('polykey/dist/client/utils');
const clientStatus = await binProcessors.processClientStatus(
options.nodePath,
options.nodeId,
Expand All @@ -46,45 +43,30 @@ class CommandStatus extends CommandPolykey {
options.passwordFile,
this.fs,
);
let webSocketClient: WebSocketClient;
let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
if (webSocketClient != null) {
await webSocketClient.destroy({ force: true });
}
});
let response: StatusResultMessage;
try {
webSocketClient = await WebSocketClient.createWebSocketClient({
config: {
verifyPeer: true,
verifyCallback: async (certs) => {
await clientUtils.verifyServerCertificateChain(
[clientStatus.nodeId!],
certs,
);
},
},
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientStatus.nodeId!,
host: clientStatus.clientHost!,
port: clientStatus.clientPort!,
logger: this.logger.getChild(WebSocketClient.name),
});
pkClient = await PolykeyClient.createPolykeyClient({
streamFactory: () => webSocketClient.connection.newStream(),
nodePath: options.nodePath,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
response = await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClientClient.methods.agentStatus({
pkClient.rpcClient.methods.agentStatus({
metadata: auth,
}),
auth,
);
} finally {
if (pkClient! != null) await pkClient.stop();
if (webSocketClient! != null) await webSocketClient.destroy();
}
process.stdout.write(
binUtils.outputFormatter({
Expand Down
30 changes: 6 additions & 24 deletions src/agent/CommandStop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import type { WebSocketClient } from '@matrixai/ws';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
Expand All @@ -18,8 +17,6 @@ class CommandStop extends CommandPolykey {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const { WebSocketClient } = await import('@matrixai/ws');
const clientUtils = await import('polykey/dist/client/utils');
const clientStatus = await binProcessors.processClientStatus(
options.nodePath,
options.nodeId,
Expand All @@ -44,45 +41,30 @@ class CommandStop extends CommandPolykey {
);
// Either the statusInfo is undefined or LIVE
// Either way, the connection parameters now exist
let webSocketClient: WebSocketClient;
let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
if (webSocketClient != null) {
await webSocketClient.destroy({ force: true });
}
});
try {
webSocketClient = await WebSocketClient.createWebSocketClient({
config: {
verifyPeer: true,
verifyCallback: async (certs) => {
await clientUtils.verifyServerCertificateChain(
[clientStatus.nodeId!],
certs,
);
},
},
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientStatus.nodeId!,
host: clientStatus.clientHost!,
port: clientStatus.clientPort!,
logger: this.logger.getChild(WebSocketClient.name),
});
pkClient = await PolykeyClient.createPolykeyClient({
streamFactory: () => webSocketClient.connection.newStream(),
nodePath: options.nodePath,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClientClient.methods.agentStop({
pkClient.rpcClient.methods.agentStop({
metadata: auth,
}),
auth,
);
this.logger.info('Stopping Agent');
} finally {
if (pkClient! != null) await pkClient.stop();
if (webSocketClient! != null) await webSocketClient.destroy();
}
});
}
Expand Down
30 changes: 6 additions & 24 deletions src/agent/CommandUnlock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import type { WebSocketClient } from '@matrixai/ws';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
Expand All @@ -17,8 +16,6 @@ class CommandUnlock extends CommandPolykey {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const { WebSocketClient } = await import('@matrixai/ws');
const clientUtils = await import('polykey/dist/client/utils');
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
options.nodeId,
Expand All @@ -31,44 +28,29 @@ class CommandUnlock extends CommandPolykey {
options.passwordFile,
this.fs,
);
let webSocketClient: WebSocketClient;
let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
if (webSocketClient != null) {
await webSocketClient.destroy({ force: true });
}
});
try {
webSocketClient = await WebSocketClient.createWebSocketClient({
config: {
verifyPeer: true,
verifyCallback: async (certs) => {
await clientUtils.verifyServerCertificateChain(
[clientOptions.nodeId],
certs,
);
},
},
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
logger: this.logger.getChild(WebSocketClient.name),
});
pkClient = await PolykeyClient.createPolykeyClient({
streamFactory: () => webSocketClient.connection.newStream(),
nodePath: options.nodePath,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClientClient.methods.agentUnlock({
pkClient.rpcClient.methods.agentUnlock({
metadata: auth,
}),
auth,
);
} finally {
if (pkClient! != null) await pkClient.stop();
if (webSocketClient! != null) await webSocketClient.destroy();
}
});
}
Expand Down
16 changes: 5 additions & 11 deletions src/bootstrap/CommandBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ class CommandBootstrap extends CommandPolykey {
);
const recoveryCodeOut = await bootstrapUtils.bootstrapState({
password,
options: {
nodePath: options.nodePath,
keys: {
recoveryCode: recoveryCodeIn,
privateKeyPath: options.privateKeyFile,
passwordOpsLimit:
keysUtils.passwordOpsLimits[options.passwordOpsLimit],
passwordMemLimit:
keysUtils.passwordMemLimits[options.passwordMemLimit],
},
},
nodePath: options.nodePath,
recoveryCode: recoveryCodeIn,
privateKeyPath: options.privateKeyFile,
passwordOpsLimit: keysUtils.passwordOpsLimits[options.passwordOpsLimit],
passwordMemLimit: keysUtils.passwordMemLimits[options.passwordMemLimit],
fresh: options.fresh,
fs: this.fs,
logger: this.logger,
Expand Down
Loading