diff --git a/src/PolykeyAgent.ts b/src/PolykeyAgent.ts index 31ec74f3b..1e7e23db8 100644 --- a/src/PolykeyAgent.ts +++ b/src/PolykeyAgent.ts @@ -322,7 +322,6 @@ class PolykeyAgent { (await Sigchain.createSigchain({ db, keyRing, - certManager, logger: logger.getChild(Sigchain.name), fresh, })); @@ -370,7 +369,6 @@ class PolykeyAgent { new NodeConnectionManager({ keyRing, nodeGraph, - certManager, tlsConfig, seedNodes: optionsDefaulted.seedNodes, connectionFindConcurrencyLimit: @@ -397,7 +395,6 @@ class PolykeyAgent { nodeConnectionManager, taskManager, gestaltGraph, - certManager, logger: logger.getChild(NodeManager.name), }); await nodeManager.start(); @@ -621,11 +618,15 @@ class PolykeyAgent { await this.status.updateStatusLive({ nodeId: data.nodeId, }); + await this.nodeManager.resetBuckets(); + // Update the sigchain + await this.sigchain.onKeyRingChange(); const tlsConfig: TLSConfig = { keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey), certChainPem: await this.certManager.getCertPEMsChainPEM(), }; this.webSocketServerClient.setTlsConfig(tlsConfig); + this.nodeConnectionManager.updateTlsConfig(tlsConfig); this.logger.info(`${KeyRing.name} change propagated`); }; diff --git a/src/bootstrap/utils.ts b/src/bootstrap/utils.ts index ea98c8bdd..77d2552b2 100644 --- a/src/bootstrap/utils.ts +++ b/src/bootstrap/utils.ts @@ -161,7 +161,6 @@ async function bootstrapState({ const sigchain = await Sigchain.createSigchain({ db, keyRing, - certManager, logger: logger.getChild(Sigchain.name), fresh, }); diff --git a/src/nodes/NodeConnectionManager.ts b/src/nodes/NodeConnectionManager.ts index d11fb63f2..cfcbee250 100644 --- a/src/nodes/NodeConnectionManager.ts +++ b/src/nodes/NodeConnectionManager.ts @@ -12,7 +12,6 @@ import type { SeedNodes, } from './types'; import type KeyRing from '../keys/KeyRing'; -import type CertManager from '../keys/CertManager'; import type { Key, CertificatePEM } from '../keys/types'; import type { ConnectionData, Host, Hostname, Port } from '../network/types'; import type { TLSConfig } from '../network/types'; @@ -37,7 +36,6 @@ import * as networkUtils from '../network/utils'; import { clientManifest as agentClientManifest } from '../agent/handlers/clientManifest'; import * as utils from '../utils'; import config from '../config'; -import * as keysEvents from '../keys/events'; type AgentClientManifest = typeof agentClientManifest; @@ -125,7 +123,6 @@ class NodeConnectionManager { protected logger: Logger; protected keyRing: KeyRing; protected nodeGraph: NodeGraph; - protected certManager?: CertManager; protected tlsConfig: TLSConfig; protected seedNodes: SeedNodes; @@ -177,21 +174,9 @@ class NodeConnectionManager { this.dispatchEvent(event.clone()); }; - protected handleEventsCertManagerCertChange = async ( - evt: keysEvents.EventsCertManagerCertChange, - ) => { - const data = evt.detail; - const tlsConfig: TLSConfig = { - keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey), - certChainPem: await this.certManager!.getCertPEMsChainPEM(), - }; - this.updateTlsConfig(tlsConfig); - }; - public constructor({ keyRing, nodeGraph, - certManager, tlsConfig, seedNodes = {}, connectionFindConcurrencyLimit = config.defaultsSystem @@ -210,7 +195,6 @@ class NodeConnectionManager { }: { keyRing: KeyRing; nodeGraph: NodeGraph; - certManager?: CertManager; tlsConfig: TLSConfig; seedNodes?: SeedNodes; connectionFindConcurrencyLimit?: number; @@ -224,7 +208,6 @@ class NodeConnectionManager { this.logger = logger ?? new Logger(this.constructor.name); this.keyRing = keyRing; this.nodeGraph = nodeGraph; - this.certManager = certManager; this.tlsConfig = tlsConfig; // Filter out own node ID const nodeIdEncodedOwn = nodesUtils.encodeNodeId(keyRing.getNodeId()); @@ -356,10 +339,6 @@ class NodeConnectionManager { EventDefault.name, this.handleQUICServerEvents, ); - this.certManager?.addEventListener( - keysEvents.EventsCertManagerCertChange.name, - this.handleEventsCertManagerCertChange, - ); this.logger.info(`Started ${this.constructor.name}`); } @@ -367,10 +346,6 @@ class NodeConnectionManager { public async stop() { this.logger.info(`Stop ${this.constructor.name}`); - this.certManager?.removeEventListener( - keysEvents.EventsCertManagerCertChange.name, - this.handleEventsCertManagerCertChange, - ); this.quicServer.removeEventListener( EventDefault.name, this.handleQUICServerEvents, diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index a2d968b4a..1e994ada6 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -2,7 +2,6 @@ import type { DB, DBTransaction } from '@matrixai/db'; import type NodeConnectionManager from './NodeConnectionManager'; import type NodeGraph from './NodeGraph'; import type KeyRing from '../keys/KeyRing'; -import type CertManager from '../keys/CertManager'; import type Sigchain from '../sigchain/Sigchain'; import type { NodeId, @@ -22,7 +21,6 @@ import type GestaltGraph from '../gestalts/GestaltGraph'; import type { TaskHandler, TaskHandlerId, Task } from '../tasks/types'; import type { ContextTimed } from '@matrixai/contexts'; import type { PromiseCancellable } from '@matrixai/async-cancellable'; -import type { ContextTimedInput } from '@matrixai/contexts/dist/types'; import type { Host, Port } from '../network/types'; import type { SignedTokenEncoded } from '../tokens/types'; import type { ClaimLinkNode } from '../claims/payloads/index'; @@ -31,6 +29,7 @@ import type { AgentRPCRequestParams, AgentRPCResponseResult, } from '../agent/types'; +import type { ContextTimedInput } from '@matrixai/contexts/dist/types'; import Logger from '@matrixai/logger'; import { StartStop, ready } from '@matrixai/async-init/dist/StartStop'; import { Semaphore, Lock } from '@matrixai/async-locks'; @@ -43,7 +42,6 @@ import * as claimsUtils from '../claims/utils'; import * as tasksErrors from '../tasks/errors'; import * as claimsErrors from '../claims/errors'; import * as keysUtils from '../keys/utils'; -import * as keysEvents from '../keys/events'; import { never, promise } from '../utils/utils'; import { decodeClaimId, @@ -62,7 +60,6 @@ class NodeManager { protected logger: Logger; protected sigchain: Sigchain; protected keyRing: KeyRing; - protected certManager?: CertManager; protected nodeConnectionManager: NodeConnectionManager; protected nodeGraph: NodeGraph; protected taskManager: TaskManager; @@ -213,10 +210,6 @@ class NodeManager { ); }; - protected handleEventsCertManagerCertChange = async () => { - await this.resetBuckets(); - }; - constructor({ db, keyRing, @@ -225,7 +218,6 @@ class NodeManager { nodeGraph, taskManager, gestaltGraph, - certManager, refreshBucketDelay = 3600000, // 1 hour in milliseconds refreshBucketDelayJitter = 0.5, // Multiple of refreshBucketDelay to jitter by retrySeedConnectionsDelay = 120000, // 2 minuets @@ -238,7 +230,6 @@ class NodeManager { nodeGraph: NodeGraph; taskManager: TaskManager; gestaltGraph: GestaltGraph; - certManager?: CertManager; refreshBucketDelay?: number; refreshBucketDelayJitter?: number; retrySeedConnectionsDelay?: number; @@ -253,7 +244,6 @@ class NodeManager { this.nodeGraph = nodeGraph; this.taskManager = taskManager; this.gestaltGraph = gestaltGraph; - this.certManager = certManager; this.refreshBucketDelay = refreshBucketDelay; // Clamped from 0 to 1 inclusive this.refreshBucketDelayJitter = Math.max( @@ -294,20 +284,12 @@ class NodeManager { nodesEvents.EventNodeConnectionManagerConnection.name, this.handleNodeConnectionEvent, ); - this.certManager?.addEventListener( - keysEvents.EventsCertManagerCertChange.name, - this.handleEventsCertManagerCertChange, - ); this.logger.info(`Started ${this.constructor.name}`); } public async stop() { this.logger.info(`Stopping ${this.constructor.name}`); // Remove handling for connections - this.certManager?.removeEventListener( - keysEvents.EventsCertManagerCertChange.name, - this.handleEventsCertManagerCertChange, - ); this.nodeConnectionManager.removeEventListener( nodesEvents.EventNodeConnectionManagerConnection.name, this.handleNodeConnectionEvent, diff --git a/src/sigchain/Sigchain.ts b/src/sigchain/Sigchain.ts index 65aa2b2dc..7b920d530 100644 --- a/src/sigchain/Sigchain.ts +++ b/src/sigchain/Sigchain.ts @@ -1,7 +1,6 @@ import type { DB, DBTransaction, LevelPath, KeyPath } from '@matrixai/db'; import type { ClaimInput } from './types'; import type KeyRing from '../keys/KeyRing'; -import type CertManager from '../keys/CertManager'; import type { TokenSignature, TokenHeaderSignatureJSON } from '../tokens/types'; import type { ClaimId, @@ -19,7 +18,6 @@ import * as sigchainErrors from './errors'; import Token from '../tokens/Token'; import * as claimsUtils from '../claims/utils'; import * as utils from '../utils'; -import * as keysEvents from '../keys/events'; interface Sigchain extends CreateDestroyStartStop {} @CreateDestroyStartStop( @@ -30,23 +28,16 @@ class Sigchain { public static async createSigchain({ db, keyRing, - certManager, logger = new Logger(this.name), fresh = false, }: { db: DB; keyRing: KeyRing; - certManager: CertManager; logger?: Logger; fresh?: boolean; }): Promise { logger.info(`Creating ${this.name}`); - const sigchain = new this({ - db, - keyRing, - certManager, - logger, - }); + const sigchain = new this({ db, keyRing, logger }); await sigchain.start({ fresh }); logger.info(`Created ${this.name}`); return sigchain; @@ -55,7 +46,6 @@ class Sigchain { protected logger: Logger; protected keyRing: KeyRing; protected db: DB; - protected certManager?: CertManager; protected generateClaimId: () => ClaimId; protected generateSequenceNumber: () => number; protected dbPath: LevelPath = [this.constructor.name]; @@ -84,25 +74,18 @@ class Sigchain { 'lastSequenceNumber', ]; - protected handleEventsCertManagerCertChange = async () => { - await this.onKeyRingChange(); - }; - constructor({ db, keyRing, - certManager, logger, }: { db: DB; keyRing: KeyRing; - certManager?: CertManager; logger: Logger; }) { + this.logger = logger; this.db = db; this.keyRing = keyRing; - this.certManager = certManager; - this.logger = logger; } public async start({ @@ -124,19 +107,11 @@ class Sigchain { lastSequenceNumber += 1; return lastSequenceNumber; }; - this.certManager?.addEventListener( - keysEvents.EventsCertManagerCertChange.name, - this.handleEventsCertManagerCertChange, - ); this.logger.info(`Started ${this.constructor.name}`); } public async stop() { this.logger.info(`Stopping ${this.constructor.name}`); - this.certManager?.removeEventListener( - keysEvents.EventsCertManagerCertChange.name, - this.handleEventsCertManagerCertChange, - ); this.logger.info(`Stopped ${this.constructor.name}`); }