Skip to content

Commit 41eb69b

Browse files
committed
feat: require verification of primary key and subkey fingerprints for relay binaries and fix certbot spinner output
1 parent 864ccf4 commit 41eb69b

File tree

2 files changed

+15
-54
lines changed

2 files changed

+15
-54
lines changed

pkg/network/certbot.go

-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func GetCertificates(domainName string) bool {
9191
var email string
9292

9393
if strings.Contains(certbotAccountData, "Email contact: none") {
94-
pterm.Println()
9594
certbotSpinner.Info("Certbot email currently set to none.")
9695

9796
pterm.Println()
@@ -111,7 +110,6 @@ func GetCertificates(domainName string) bool {
111110
}
112111
} else {
113112
_, currentEmail, _ := strings.Cut(certbotAccountData, "Email contact: ")
114-
pterm.Println()
115113
certbotSpinner.Info(fmt.Sprintf("Email used with Certbot account: %s", currentEmail))
116114

117115
prompt := pterm.InteractiveContinuePrinter{

pkg/verification/verify.go

+15-52
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ import (
1414

1515
// Function to verify relay binaries
1616
func VerifyRelayBinary(path string) {
17-
ThemeDefault := pterm.ThemeDefault
18-
19-
prompt := pterm.InteractiveContinuePrinter{
20-
DefaultValueIndex: 0,
21-
DefaultText: "Do you want to continue with the installation?",
22-
TextStyle: &ThemeDefault.PrimaryStyle,
23-
Options: []string{"no", "yes"},
24-
OptionsStyle: &ThemeDefault.SuccessMessageStyle,
25-
SuffixStyle: &ThemeDefault.SecondaryStyle,
26-
Delimiter: ": ",
27-
}
28-
2917
spinner, _ := pterm.DefaultSpinner.Start("Verifying relay binary...")
3018
pterm.Println()
3119

@@ -58,7 +46,8 @@ func VerifyRelayBinary(path string) {
5846
// Download and copy the file
5947
files.DownloadAndCopyFile(relaysManifestFilePath, RelaysManifestFileURL)
6048

61-
cmd := exec.Command("gpg", "--verify", relaysManifestSigFilePath)
49+
// Use GPG to verify the manifest signature file and output the primary key and signature subkey fingerprints
50+
cmd := exec.Command("gpg", "--verify", "--with-fingerprint", "--with-subkey-fingerprints", relaysManifestSigFilePath)
6251

6352
out, err := cmd.CombinedOutput()
6453
if err != nil {
@@ -71,33 +60,24 @@ func VerifyRelayBinary(path string) {
7160

7261
goodSig := strings.Contains(gpgVerifyOutput, NodeTecGoodSigMsg)
7362

74-
// Extract the formatted primary key and subkey fingerprints from the output
75-
_, formattedPrimaryAndSubKeyFingerprints, foundPrimaryKeyText := strings.Cut(gpgVerifyOutput, "Primary key fingerprint: ")
63+
// Extract the formatted primary key and formatted signature subkey fingerprints from the output
64+
_, formattedPrimaryAndSubKeyFingerprints, _ := strings.Cut(gpgVerifyOutput, "Primary key fingerprint: ")
7665

77-
formattedPrimaryKeyFingerprint, formattedSubkeyFingerprint, foundSubkeyText := strings.Cut(formattedPrimaryAndSubKeyFingerprints, "Subkey fingerprint: ")
66+
formattedPrimaryKeyFingerprint, formattedSubkeyFingerprint, _ := strings.Cut(formattedPrimaryAndSubKeyFingerprints, "Subkey fingerprint: ")
7867

79-
if foundPrimaryKeyText && foundSubkeyText {
80-
formattedPrimaryKeyFingerprint = strings.ReplaceAll(formattedPrimaryKeyFingerprint, " ", "")
81-
formattedSubkeyFingerprint = strings.ReplaceAll(formattedSubkeyFingerprint, " ", "")
68+
// Remove the spaces and new line characters from the formatted primary key and formatted signature subkey fingerprints
69+
formattedPrimaryKeyFingerprint = strings.ReplaceAll(formattedPrimaryKeyFingerprint, " ", "")
70+
formattedSubkeyFingerprint = strings.ReplaceAll(formattedSubkeyFingerprint, " ", "")
8271

83-
primaryKeyFingerprint := strings.ReplaceAll(formattedPrimaryKeyFingerprint, "\n", "")
84-
subkeyFingerprint := strings.ReplaceAll(formattedSubkeyFingerprint, "\n", "")
72+
primaryKeyFingerprint := strings.ReplaceAll(formattedPrimaryKeyFingerprint, "\n", "")
73+
subkeyFingerprint := strings.ReplaceAll(formattedSubkeyFingerprint, "\n", "")
8574

86-
if goodSig && primaryKeyFingerprint == NodeTecPrimaryKeyFingerprint && subkeyFingerprint == NodeTecSigningSubkeyFingerprint {
87-
spinner.UpdateText(fmt.Sprintf("Verified the signature of the %s file and the fingerprints", relaysManifestFilePath))
88-
} else {
89-
pterm.Println()
90-
pterm.Error.Println(fmt.Sprintf("Failed to verify the signature of the %s file", relaysManifestFilePath))
91-
os.Exit(1)
92-
}
75+
if goodSig && primaryKeyFingerprint == NodeTecPrimaryKeyFingerprint && subkeyFingerprint == NodeTecSigningSubkeyFingerprint {
76+
spinner.UpdateText(fmt.Sprintf("Verified the signature of the %s file and the fingerprints", relaysManifestFilePath))
9377
} else {
94-
if goodSig {
95-
spinner.UpdateText(fmt.Sprintf("Verified the signature of the %s file", relaysManifestFilePath))
96-
} else {
97-
pterm.Println()
98-
pterm.Error.Println(fmt.Sprintf("Failed to verify the signature of the %s file", relaysManifestFilePath))
99-
os.Exit(1)
100-
}
78+
pterm.Println()
79+
pterm.Error.Println(fmt.Sprintf("Failed to verify the signature of the %s file and/or the fingerprints", relaysManifestFilePath))
80+
os.Exit(1)
10181
}
10282

10383
// Compute the SHA512 hash of the compressed relay binary file
@@ -123,23 +103,6 @@ func VerifyRelayBinary(path string) {
123103
// Search the manifest file for the hash
124104
if strings.Contains(string(data), sha512Hash) {
125105
spinner.UpdateText(fmt.Sprintf("Verified the SHA512 hash of the %s file", path))
126-
pterm.Println()
127-
128-
// Prompt user if they want to continue with installation without verifying fingerprints
129-
if !foundPrimaryKeyText || !foundSubkeyText {
130-
pterm.Println()
131-
spinner.Warning(fmt.Sprintf("Warning: The signature of the %s file was valid but the fingerprints were not checked.", relaysManifestFilePath))
132-
133-
pterm.Println()
134-
135-
result, _ := prompt.Show()
136-
137-
if result == "no" {
138-
os.Exit(1)
139-
}
140-
}
141-
142-
pterm.Println()
143106
spinner.Success("Relay binary verified")
144107
} else {
145108
pterm.Println()

0 commit comments

Comments
 (0)