Skip to content

Commit 864ccf4

Browse files
authored
feat: add relay binary verification #36 (#72)
1 parent 7e82868 commit 864ccf4

File tree

11 files changed

+269
-35
lines changed

11 files changed

+269
-35
lines changed

pkg/manager/apt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func AptInstallPackages(selectedRelayOption string) {
4646

4747
exec.Command("apt", "update", "-qq").Run()
4848

49-
packages := []string{"ufw", "fail2ban", "nginx", "certbot", "python3-certbot-nginx"}
49+
packages := []string{"curl", "gnupg", "ufw", "fail2ban", "nginx", "certbot", "python3-certbot-nginx"}
5050

5151
if selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == strfry.RelayName || selectedRelayOption == wot_relay.RelayName || selectedRelayOption == strfry29.RelayName {
5252
packages = append(packages, "git")

pkg/network/certbot.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package network
22

33
import (
44
"fmt"
5-
"os"
6-
"os/exec"
7-
"strings"
8-
95
"github.com/nodetec/rwz/pkg/utils/directories"
106
"github.com/nodetec/rwz/pkg/utils/files"
117
"github.com/pterm/pterm"
8+
"os"
9+
"os/exec"
10+
"strings"
1211
)
1312

1413
func setDomainCertDirPerms(domainName string) {

pkg/relays/khatru29/install.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"github.com/nodetec/rwz/pkg/relays"
66
"github.com/nodetec/rwz/pkg/utils/files"
77
"github.com/nodetec/rwz/pkg/utils/systemd"
8+
"github.com/nodetec/rwz/pkg/verification"
89
"github.com/pterm/pterm"
910
"path/filepath"
1011
)
1112

1213
// Function to download and make the binary executable
1314
func InstallRelayBinary() {
14-
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))
15+
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
1516

1617
// Determine the file name from the URL
1718
tmpFileName := filepath.Base(DownloadURL)
@@ -25,14 +26,21 @@ func InstallRelayBinary() {
2526
// Download and copy the file
2627
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)
2728

29+
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
30+
31+
// Verify relay binary
32+
verification.VerifyRelayBinary(tmpFilePath)
33+
34+
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
35+
2836
// Check if the service file exists and disable and stop the service if it does
2937
if files.FileExists(ServiceFilePath) {
3038
// Disable and stop the Nostr relay service
31-
spinner.UpdateText("Disabling and stopping service...")
39+
installSpinner.UpdateText("Disabling and stopping service...")
3240
systemd.DisableService(ServiceName)
3341
systemd.StopService(ServiceName)
3442
} else {
35-
spinner.UpdateText("Service file not found...")
43+
installSpinner.UpdateText("Service file not found...")
3644
}
3745

3846
// Extract binary
@@ -48,5 +56,5 @@ func InstallRelayBinary() {
4856
// Make the file executable
4957
files.SetPermissions(destPath, 0755)
5058

51-
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
59+
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
5260
}

pkg/relays/khatru_pyramid/install.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"github.com/nodetec/rwz/pkg/utils/directories"
77
"github.com/nodetec/rwz/pkg/utils/files"
88
"github.com/nodetec/rwz/pkg/utils/systemd"
9+
"github.com/nodetec/rwz/pkg/verification"
910
"github.com/pterm/pterm"
1011
"path/filepath"
1112
)
1213

1314
// Function to download and make the binary executable
1415
func InstallRelayBinary(pubKey string) {
15-
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))
16+
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
1617

1718
// Determine the file name from the URL
1819
tmpFileName := filepath.Base(DownloadURL)
@@ -26,28 +27,35 @@ func InstallRelayBinary(pubKey string) {
2627
// Download and copy the file
2728
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)
2829

30+
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
31+
32+
// Verify relay binary
33+
verification.VerifyRelayBinary(tmpFilePath)
34+
35+
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
36+
2937
// Check if the service file exists and disable and stop the service if it does
3038
if files.FileExists(ServiceFilePath) {
3139
// Disable and stop the Nostr relay service
32-
spinner.UpdateText("Disabling and stopping service...")
40+
installSpinner.UpdateText("Disabling and stopping service...")
3341
systemd.DisableService(ServiceName)
3442
systemd.StopService(ServiceName)
3543
} else {
36-
spinner.UpdateText("Service file not found...")
44+
installSpinner.UpdateText("Service file not found...")
3745
}
3846

3947
// Check if users.json file exists
4048
if files.FileExists(UsersFilePath) {
4149
// Check if the pubKey exists in the users.json file
42-
spinner.UpdateText("Checking for public key in users.json file...")
50+
installSpinner.UpdateText("Checking for public key in users.json file...")
4351
lineExists := files.LineExists(fmt.Sprintf(`"%s":""`, pubKey), UsersFilePath)
4452

4553
// If false remove data directory
4654
if !lineExists {
47-
spinner.UpdateText("Public key not found, removing data directory...")
55+
installSpinner.UpdateText("Public key not found, removing data directory...")
4856
directories.RemoveDirectory(DataDirPath)
4957
} else {
50-
spinner.UpdateText("Public key found, keeping data directory.")
58+
installSpinner.UpdateText("Public key found, keeping data directory.")
5159
}
5260
}
5361

@@ -64,5 +72,5 @@ func InstallRelayBinary(pubKey string) {
6472
// Make the file executable
6573
files.SetPermissions(destPath, 0755)
6674

67-
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
75+
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
6876
}

pkg/relays/nostr_rs_relay/install.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"github.com/nodetec/rwz/pkg/utils/files"
88
"github.com/nodetec/rwz/pkg/utils/git"
99
"github.com/nodetec/rwz/pkg/utils/systemd"
10+
"github.com/nodetec/rwz/pkg/verification"
1011
"github.com/pterm/pterm"
1112
"path/filepath"
1213
)
1314

1415
// Function to download and make the binary executable
1516
func InstallRelayBinary() {
16-
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))
17+
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
1718

1819
// Check for and remove existing git repository
1920
directories.RemoveDirectory(GitRepoTmpDirPath)
@@ -35,14 +36,21 @@ func InstallRelayBinary() {
3536
// Download and copy the file
3637
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)
3738

39+
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
40+
41+
// Verify relay binary
42+
verification.VerifyRelayBinary(tmpFilePath)
43+
44+
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
45+
3846
// Check if the service file exists and disable and stop the service if it does
3947
if files.FileExists(ServiceFilePath) {
4048
// Disable and stop the Nostr relay service
41-
spinner.UpdateText("Disabling and stopping service...")
49+
installSpinner.UpdateText("Disabling and stopping service...")
4250
systemd.DisableService(ServiceName)
4351
systemd.StopService(ServiceName)
4452
} else {
45-
spinner.UpdateText("Service file not found...")
53+
installSpinner.UpdateText("Service file not found...")
4654
}
4755

4856
// Extract binary
@@ -58,5 +66,5 @@ func InstallRelayBinary() {
5866
// Make the file executable
5967
files.SetPermissions(destPath, 0755)
6068

61-
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
69+
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
6270
}

pkg/relays/strfry/install.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"github.com/nodetec/rwz/pkg/utils/files"
88
"github.com/nodetec/rwz/pkg/utils/git"
99
"github.com/nodetec/rwz/pkg/utils/systemd"
10+
"github.com/nodetec/rwz/pkg/verification"
1011
"github.com/pterm/pterm"
1112
"path/filepath"
1213
)
1314

1415
// Function to download and make the binary executable
1516
func InstallRelayBinary() {
16-
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))
17+
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
1718

1819
// Check for and remove existing git repository
1920
directories.RemoveDirectory(GitRepoTmpDirPath)
@@ -36,14 +37,21 @@ func InstallRelayBinary() {
3637
// Download and copy the file
3738
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)
3839

40+
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
41+
42+
// Verify relay binary
43+
verification.VerifyRelayBinary(tmpFilePath)
44+
45+
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
46+
3947
// Check if the service file exists and disable and stop the service if it does
4048
if files.FileExists(ServiceFilePath) {
4149
// Disable and stop the Nostr relay service
42-
spinner.UpdateText("Disabling and stopping service...")
50+
installSpinner.UpdateText("Disabling and stopping service...")
4351
systemd.DisableService(ServiceName)
4452
systemd.StopService(ServiceName)
4553
} else {
46-
spinner.UpdateText("Service file not found...")
54+
installSpinner.UpdateText("Service file not found...")
4755
}
4856

4957
// Extract binary
@@ -59,5 +67,5 @@ func InstallRelayBinary() {
5967
// Make the file executable
6068
files.SetPermissions(destPath, 0755)
6169

62-
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
70+
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
6371
}

pkg/relays/strfry29/install.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"github.com/nodetec/rwz/pkg/utils/files"
88
"github.com/nodetec/rwz/pkg/utils/git"
99
"github.com/nodetec/rwz/pkg/utils/systemd"
10+
"github.com/nodetec/rwz/pkg/verification"
1011
"github.com/pterm/pterm"
1112
"path/filepath"
1213
)
1314

1415
// Function to download and make the binary executable
1516
func InstallRelayBinary() {
16-
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))
17+
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
1718

1819
// Check for and remove existing git repository
1920
directories.RemoveDirectory(GitRepoTmpDirPath)
@@ -51,14 +52,21 @@ func InstallRelayBinary() {
5152
// Download and copy the file
5253
files.DownloadAndCopyFile(tmpFilePath, BinaryPluginDownloadURL)
5354

55+
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
56+
57+
// Verify relay binary
58+
verification.VerifyRelayBinary(tmpFilePath)
59+
60+
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
61+
5462
// Check if the service file exists and disable and stop the service if it does
5563
if files.FileExists(ServiceFilePath) {
5664
// Disable and stop the Nostr relay service
57-
spinner.UpdateText("Disabling and stopping service...")
65+
installSpinner.UpdateText("Disabling and stopping service...")
5866
systemd.DisableService(ServiceName)
5967
systemd.StopService(ServiceName)
6068
} else {
61-
spinner.UpdateText("Service file not found...")
69+
installSpinner.UpdateText("Service file not found...")
6270
}
6371

6472
// Extract binary
@@ -80,5 +88,5 @@ func InstallRelayBinary() {
8088
// Make the file executable
8189
files.SetPermissions(destPath, 0755)
8290

83-
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
91+
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
8492
}

pkg/relays/wot_relay/install.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"github.com/nodetec/rwz/pkg/utils/files"
88
"github.com/nodetec/rwz/pkg/utils/git"
99
"github.com/nodetec/rwz/pkg/utils/systemd"
10+
"github.com/nodetec/rwz/pkg/verification"
1011
"github.com/pterm/pterm"
1112
"path/filepath"
1213
)
1314

1415
// Function to download and make the binary executable
1516
func InstallRelayBinary(pubKey string) {
16-
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s...", RelayName))
17+
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
1718

1819
// Check for and remove existing git repository
1920
directories.RemoveDirectory(GitRepoTmpDirPath)
@@ -35,28 +36,35 @@ func InstallRelayBinary(pubKey string) {
3536
// Download and copy the file
3637
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)
3738

39+
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
40+
41+
// Verify relay binary
42+
verification.VerifyRelayBinary(tmpFilePath)
43+
44+
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
45+
3846
// Check if the service file exists and disable and stop the service if it does
3947
if files.FileExists(ServiceFilePath) {
4048
// Disable and stop the Nostr relay service
41-
spinner.UpdateText("Disabling and stopping service...")
49+
installSpinner.UpdateText("Disabling and stopping service...")
4250
systemd.DisableService(ServiceName)
4351
systemd.StopService(ServiceName)
4452
} else {
45-
spinner.UpdateText("Service file not found...")
53+
installSpinner.UpdateText("Service file not found...")
4654
}
4755

4856
// Check if environment file exists
4957
if files.FileExists(EnvFilePath) {
5058
// Check if the pubKey exists in the environment file
51-
spinner.UpdateText(fmt.Sprintf("Checking for public key in the %s file...", EnvFilePath))
59+
installSpinner.UpdateText(fmt.Sprintf("Checking for public key in the %s file...", EnvFilePath))
5260
lineExists := files.LineExists(fmt.Sprintf(`RELAY_PUBKEY="%s"`, pubKey), EnvFilePath)
5361

5462
// If false remove data directory
5563
if !lineExists {
56-
spinner.UpdateText("Public key not found, removing data directory...")
64+
installSpinner.UpdateText("Public key not found, removing data directory...")
5765
directories.RemoveDirectory(DataDirPath)
5866
} else {
59-
spinner.UpdateText("Public key found, keeping data directory.")
67+
installSpinner.UpdateText("Public key found, keeping data directory.")
6068
}
6169
}
6270

@@ -73,5 +81,5 @@ func InstallRelayBinary(pubKey string) {
7381
// Make the file executable
7482
files.SetPermissions(destPath, 0755)
7583

76-
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
84+
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
7785
}

pkg/utils/commands/utils.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"github.com/pterm/pterm"
6+
"os"
7+
"os/exec"
8+
)
9+
10+
func PipeTwoCommands(commandOne, commandTwo *exec.Cmd, errMsg string) {
11+
r, w, err := os.Pipe()
12+
if err != nil {
13+
pterm.Println()
14+
pterm.Error.Println(fmt.Sprintf("Failed to create pipe: %v", err))
15+
os.Exit(1)
16+
}
17+
defer r.Close()
18+
commandOne.Stdout = w
19+
err = commandOne.Start()
20+
if err != nil {
21+
pterm.Println()
22+
pterm.Error.Println(fmt.Sprintf("%s %v", errMsg, err))
23+
os.Exit(1)
24+
}
25+
defer commandOne.Wait()
26+
w.Close()
27+
commandTwo.Stdin = r
28+
commandTwo.Stdout = os.Stdout
29+
commandTwo.Run()
30+
}

pkg/verification/constants.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package verification
2+
3+
const NodeTecKeybasePGPKeyURL = "https://keybase.io/nodetec/pgp_keys.asc"
4+
const RelaysManifestFileURL = "https://github.com/nodetec/relays/releases/download/v0.4.0/relays-0.4.0-manifest.sha512sum"
5+
const RelaysManifestSigFileURL = "https://github.com/nodetec/relays/releases/download/v0.4.0/relays-0.4.0-manifest.sha512sum.asc"
6+
const NodeTecGoodSigMsg = `Good signature from "NODE-TEC Devs <devs@node-tec.com>"`
7+
const NodeTecPrimaryKeyFingerprint = "04BD8C20598FA5FDDE19BECD8F2469F71314FAD7"
8+
const NodeTecSigningSubkeyFingerprint = "252F57B9DCD920EBF14E6151A8841CC4D10CC288"

0 commit comments

Comments
 (0)