Skip to content

Commit

Permalink
chore: add strfry binary verification to strfry29 relay install and t…
Browse files Browse the repository at this point in the history
…urn server tokens off for nginx http server when redirecting to https
  • Loading branch information
jchiarulli committed Nov 19, 2024
1 parent a7b78f8 commit f9e3941
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 48 deletions.
10 changes: 5 additions & 5 deletions pkg/relays/khatru29/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary() {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s binary...", RelayName))

// Determine the file name from the URL
tmpFileName := filepath.Base(DownloadURL)
Expand All @@ -26,12 +26,12 @@ func InstallRelayBinary() {
// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)

downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
downloadSpinner.Success(fmt.Sprintf("%s binary downloaded", RelayName))

// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
verification.VerifyRelayBinary(RelayName, tmpFilePath)

installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s binary...", RelayName))

// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
Expand All @@ -56,5 +56,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
installSpinner.Success(fmt.Sprintf("%s binary installed", RelayName))
}
3 changes: 3 additions & 0 deletions pkg/relays/khatru29/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ server {
location / {
return 301 https://%s$request_uri;
}
# Only return Nginx in server header
server_tokens off;
}
`, domainName, network.WWWDirPath, domainName, network.AcmeChallengeDirPath, network.CertificateDirPath, domainName, network.FullchainFile, network.CertificateDirPath, domainName, network.PrivkeyFile, network.CertificateDirPath, domainName, network.ChainFile, domainName, network.WWWDirPath, domainName, domainName)

Expand Down
10 changes: 5 additions & 5 deletions pkg/relays/khatru_pyramid/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary(pubKey string) {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s binary...", RelayName))

// Determine the file name from the URL
tmpFileName := filepath.Base(DownloadURL)
Expand All @@ -27,12 +27,12 @@ func InstallRelayBinary(pubKey string) {
// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)

downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
downloadSpinner.Success(fmt.Sprintf("%s binary downloaded", RelayName))

// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
verification.VerifyRelayBinary(RelayName, tmpFilePath)

installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s binary...", RelayName))

// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
Expand Down Expand Up @@ -72,5 +72,5 @@ func InstallRelayBinary(pubKey string) {
// Make the file executable
files.SetPermissions(destPath, 0755)

installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
installSpinner.Success(fmt.Sprintf("%s binary installed", RelayName))
}
3 changes: 3 additions & 0 deletions pkg/relays/khatru_pyramid/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ server {
location / {
return 301 https://%s$request_uri;
}
# Only return Nginx in server header
server_tokens off;
}
`, domainName, network.WWWDirPath, domainName, network.AcmeChallengeDirPath, network.CertificateDirPath, domainName, network.FullchainFile, network.CertificateDirPath, domainName, network.PrivkeyFile, network.CertificateDirPath, domainName, network.ChainFile, domainName, network.WWWDirPath, domainName, domainName)

Expand Down
10 changes: 5 additions & 5 deletions pkg/relays/nostr_rs_relay/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary() {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s binary...", RelayName))

// Check for and remove existing git repository
directories.RemoveDirectory(GitRepoTmpDirPath)
Expand All @@ -36,12 +36,12 @@ func InstallRelayBinary() {
// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)

downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
downloadSpinner.Success(fmt.Sprintf("%s binary downloaded", RelayName))

// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
verification.VerifyRelayBinary(RelayName, tmpFilePath)

installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s binary...", RelayName))

// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
Expand All @@ -66,5 +66,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
installSpinner.Success(fmt.Sprintf("%s binary installed", RelayName))
}
3 changes: 3 additions & 0 deletions pkg/relays/nostr_rs_relay/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ server {
location / {
return 301 https://%s$request_uri;
}
# Only return Nginx in server header
server_tokens off;
}
`, domainName, network.WWWDirPath, domainName, network.AcmeChallengeDirPath, network.CertificateDirPath, domainName, network.FullchainFile, network.CertificateDirPath, domainName, network.PrivkeyFile, network.CertificateDirPath, domainName, network.ChainFile, domainName, network.WWWDirPath, domainName, domainName)

Expand Down
10 changes: 5 additions & 5 deletions pkg/relays/strfry/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary() {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s binary...", RelayName))

// Check for and remove existing git repository
directories.RemoveDirectory(GitRepoTmpDirPath)
Expand All @@ -37,12 +37,12 @@ func InstallRelayBinary() {
// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)

downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
downloadSpinner.Success(fmt.Sprintf("%s binary downloaded", RelayName))

// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
verification.VerifyRelayBinary(RelayName, tmpFilePath)

installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s binary...", RelayName))

// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
Expand All @@ -67,5 +67,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
installSpinner.Success(fmt.Sprintf("%s binary installed", RelayName))
}
3 changes: 3 additions & 0 deletions pkg/relays/strfry/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ server {
location / {
return 301 https://%s$request_uri;
}
# Only return Nginx in server header
server_tokens off;
}
`, domainName, network.WWWDirPath, domainName, network.AcmeChallengeDirPath, network.CertificateDirPath, domainName, network.FullchainFile, network.CertificateDirPath, domainName, network.PrivkeyFile, network.CertificateDirPath, domainName, network.ChainFile, domainName, network.WWWDirPath, domainName, domainName)

Expand Down
41 changes: 22 additions & 19 deletions pkg/relays/strfry29/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"path/filepath"
)

// Function to download and make the binary executable
// Function to download and make the binary and plugin binary executable
func InstallRelayBinary() {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s binaries...", RelayName))

// Check for and remove existing git repository
directories.RemoveDirectory(GitRepoTmpDirPath)
Expand All @@ -26,38 +26,38 @@ func InstallRelayBinary() {

// Install
// Determine the file name from the URL
tmpFileName := filepath.Base(DownloadURL)
tmpBinaryFileName := filepath.Base(DownloadURL)

// Temporary file path
tmpFilePath := fmt.Sprintf("%s/%s", relays.TmpDirPath, tmpFileName)
tmpBinaryFilePath := fmt.Sprintf("%s/%s", relays.TmpDirPath, tmpBinaryFileName)

// Check if the temporary file exists and remove it if it does
files.RemoveFile(tmpFilePath)
files.RemoveFile(tmpBinaryFilePath)

// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)

// Extract binary
files.ExtractFile(tmpFilePath, relays.BinaryDestDir)
files.DownloadAndCopyFile(tmpBinaryFilePath, DownloadURL)

// Determine the file name from the URL
tmpFileName = filepath.Base(BinaryPluginDownloadURL)
tmpBinaryPluginFileName := filepath.Base(BinaryPluginDownloadURL)

// Temporary file path
tmpFilePath = fmt.Sprintf("%s/%s", relays.TmpDirPath, tmpFileName)
tmpBinaryPluginFilePath := fmt.Sprintf("%s/%s", relays.TmpDirPath, tmpBinaryPluginFileName)

// Check if the temporary file exists and remove it if it does
files.RemoveFile(tmpFilePath)
files.RemoveFile(tmpBinaryPluginFilePath)

// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, BinaryPluginDownloadURL)
files.DownloadAndCopyFile(tmpBinaryPluginFilePath, BinaryPluginDownloadURL)

downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
downloadSpinner.Success(fmt.Sprintf("%s binaries downloaded", RelayName))

// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
verification.VerifyRelayBinary(BinaryName, tmpBinaryFilePath)

// Verify relay binary plugin
verification.VerifyRelayBinary(fmt.Sprintf("%s plugin", RelayName), tmpBinaryPluginFilePath)

installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s binaries...", RelayName))

// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
Expand All @@ -69,8 +69,11 @@ func InstallRelayBinary() {
installSpinner.UpdateText("Service file not found...")
}

// Extract binary
files.ExtractFile(tmpFilePath, relays.BinaryDestDir)
// Extract relay binary
files.ExtractFile(tmpBinaryFilePath, relays.BinaryDestDir)

// Extract relay binary plugin
files.ExtractFile(tmpBinaryPluginFilePath, relays.BinaryDestDir)

// TODO
// Currently, the downloaded binary is expected to have a name that matches the BinaryName variable
Expand All @@ -88,5 +91,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
installSpinner.Success(fmt.Sprintf("%s binaries installed", RelayName))
}
3 changes: 3 additions & 0 deletions pkg/relays/strfry29/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ server {
location / {
return 301 https://%s$request_uri;
}
# Only return Nginx in server header
server_tokens off;
}
`, domainName, network.WWWDirPath, domainName, network.AcmeChallengeDirPath, network.CertificateDirPath, domainName, network.FullchainFile, network.CertificateDirPath, domainName, network.PrivkeyFile, network.CertificateDirPath, domainName, network.ChainFile, domainName, network.WWWDirPath, domainName, domainName)

Expand Down
10 changes: 5 additions & 5 deletions pkg/relays/wot_relay/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary(pubKey string) {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s binary...", RelayName))

// Check for and remove existing git repository
directories.RemoveDirectory(GitRepoTmpDirPath)
Expand All @@ -36,12 +36,12 @@ func InstallRelayBinary(pubKey string) {
// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)

downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
downloadSpinner.Success(fmt.Sprintf("%s binary downloaded", RelayName))

// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
verification.VerifyRelayBinary(RelayName, tmpFilePath)

installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s binary...", RelayName))

// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
Expand Down Expand Up @@ -81,5 +81,5 @@ func InstallRelayBinary(pubKey string) {
// Make the file executable
files.SetPermissions(destPath, 0755)

installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
installSpinner.Success(fmt.Sprintf("%s binary installed", RelayName))
}
3 changes: 3 additions & 0 deletions pkg/relays/wot_relay/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ server {
location / {
return 301 https://%s$request_uri;
}
# Only return Nginx in server header
server_tokens off;
}
`, domainName, network.WWWDirPath, domainName, network.AcmeChallengeDirPath, network.CertificateDirPath, domainName, network.FullchainFile, network.CertificateDirPath, domainName, network.PrivkeyFile, network.CertificateDirPath, domainName, network.ChainFile, domainName, network.WWWDirPath, domainName, domainName)

Expand Down
7 changes: 3 additions & 4 deletions pkg/verification/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
)

// Function to verify relay binaries
func VerifyRelayBinary(path string) {
spinner, _ := pterm.DefaultSpinner.Start("Verifying relay binary...")
pterm.Println()
func VerifyRelayBinary(relayName, path string) {
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Verifying %s binary...", relayName))

// Import NODE-TEC PGP key
commands.PipeTwoCommands(exec.Command("curl", NodeTecKeybasePGPKeyURL), exec.Command("gpg", "--import"), "Failed to import NODE-TEC PGP key:")
Expand Down Expand Up @@ -88,7 +87,7 @@ func VerifyRelayBinary(path string) {
// Search the manifest file for the hash
if strings.Contains(string(data), sha512Hash) {
spinner.UpdateText(fmt.Sprintf("Verified the SHA512 hash of the %s file", path))
spinner.Success("Relay binary verified")
spinner.Success(fmt.Sprintf("%s binary verified", relayName))
} else {
pterm.Println()
pterm.Error.Println(fmt.Sprintf("Failed to verify the %s file, the SHA512 hash doesn't match the SHA512 hash in the %s file", path, relaysManifestFilePath))
Expand Down

0 comments on commit f9e3941

Please sign in to comment.