Skip to content

Commit

Permalink
FIX: ssv keychange (#1940)
Browse files Browse the repository at this point in the history
Destroy existing ssv db if key changes - affects:
- importSSVEncryptedKeys
- importSSVUnencryptedKeys
- migrateToSSVEncryptedKeys
- createSSVEncryptedKeys
  • Loading branch information
daverolo authored Jul 17, 2024
1 parent 592eb54 commit 98467d3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions launcher/src/backend/NodeConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ export class NodeConnection {
const service_config_dir = totalConfig.ssvServiceConfigDir;
const service_config_file = service_config_dir + "/" + totalConfig.serviceID + ".yaml";
const network_config_dir = totalConfig.ssvNetworkConfigDir;
const network_config_db = network_config_dir + "/db";
const network_config_file = network_config_dir + "/config.yaml";
const secrets_dir = totalConfig.ssvSecretsDir;
const keystore_file = secrets_dir + "/encrypted_private_key.json";
Expand Down Expand Up @@ -829,6 +830,12 @@ export class NodeConnection {
// Set last backed public key
await this.setSSVLastBackedPublicKey(totalConfig.serviceID, newPubKey);

// Remove database
const remove_db = await this.sshService.exec(`rm -rf ${network_config_db}`);
if (SSHService.checkExecError(remove_db, true)) {
throw new Error(SSHService.extractExecError(remove_db));
}

// Write last known public key file
return await this.writeSSVLastKnownPublicKeyFile(
totalConfig.serviceID,
Expand All @@ -850,6 +857,7 @@ export class NodeConnection {
const service_config_file = service_config_dir + "/" + totalConfig.serviceID + ".yaml";
const network_config_dir = totalConfig.ssvNetworkConfigDir;
const network_config_file = network_config_dir + "/config.yaml";
const network_config_db = network_config_dir + "/db";
const secrets_dir = totalConfig.ssvSecretsDir;
const keystore_file = secrets_dir + "/encrypted_private_key.json";
const password_file = secrets_dir + "/password";
Expand Down Expand Up @@ -931,6 +939,12 @@ export class NodeConnection {
// Set last backed public key
await this.setSSVLastBackedPublicKey(totalConfig.serviceID, newPubKey);

// Remove database
const remove_db = await this.sshService.exec(`rm -rf ${network_config_db}`);
if (SSHService.checkExecError(remove_db, true)) {
throw new Error(SSHService.extractExecError(remove_db));
}

// Write last known public key file
return await this.writeSSVLastKnownPublicKeyFile(
totalConfig.serviceID,
Expand All @@ -952,6 +966,7 @@ export class NodeConnection {
const service_config_dir = totalConfig.ssvServiceConfigDir;
const service_config_file = service_config_dir + "/" + totalConfig.serviceID + ".yaml";
const network_config_dir = totalConfig.ssvNetworkConfigDir;
const network_config_db = network_config_dir + "/db";
const network_config_file = network_config_dir + "/config.yaml";
const secrets_dir = totalConfig.ssvSecretsDir;
const keystore_file = secrets_dir + "/encrypted_private_key.json";
Expand Down Expand Up @@ -1058,6 +1073,12 @@ export class NodeConnection {
}
}

// Remove database
const remove_db = await this.sshService.exec(`rm -rf ${network_config_db}`);
if (SSHService.checkExecError(remove_db, true)) {
throw new Error(SSHService.extractExecError(remove_db));
}

// Write last known public key file
return await this.writeSSVLastKnownPublicKeyFile(
totalConfig.serviceID,
Expand All @@ -1079,6 +1100,7 @@ export class NodeConnection {
const service_config_dir = totalConfig.ssvServiceConfigDir;
const service_config_file = service_config_dir + "/" + totalConfig.serviceID + ".yaml";
const network_config_dir = totalConfig.ssvNetworkConfigDir;
const network_config_db = network_config_dir + "/db";
const network_config_file = network_config_dir + "/config.yaml";
const secrets_dir = totalConfig.ssvSecretsDir;
const keystore_file = secrets_dir + "/encrypted_private_key.json";
Expand Down Expand Up @@ -1164,6 +1186,12 @@ export class NodeConnection {
}
}

// Remove database
const remove_db = await this.sshService.exec(`rm -rf ${network_config_db}`);
if (SSHService.checkExecError(remove_db, true)) {
throw new Error(SSHService.extractExecError(remove_db));
}

// Write last known public key file
return await this.writeSSVLastKnownPublicKeyFile(
serviceID,
Expand Down

0 comments on commit 98467d3

Please sign in to comment.