Skip to content

Commit 94740e0

Browse files
authored
Add files via upload
1 parent 1dbb54f commit 94740e0

File tree

2 files changed

+164
-96
lines changed

2 files changed

+164
-96
lines changed

keycard_link/keycard_link.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@ import (
77
"os"
88
"os/exec"
99
"strings"
10+
"net/http"
11+
"path/filepath"
1012
)
1113

14+
// GLOBAL PLATFORM PRO VERSION V20.01.23
15+
16+
const gpJarURL = "https://github.com/martinpaljak/GlobalPlatformPro/releases/download/v20.01.23/gp.jar"
17+
18+
func installKeycard() error {
19+
cmd := exec.Command("./keycard-linux-amd64", "install")
20+
output, err := cmd.CombinedOutput()
21+
if err != nil {
22+
return fmt.Errorf("error executing keycard-linux-amd64 install: %v, output: %s", err, output)
23+
}
24+
fmt.Printf("Output: %s\n", output)
25+
return nil
26+
}
27+
1228
// GetKeycardPublicKey retrieves the public key from the keycard.
1329
func GetKeycardPublicKey() (string, error) {
1430
// Command to execute
@@ -55,3 +71,132 @@ func ReadPassphrase() (string, error) {
5571
}
5672
return strings.TrimSpace(passphrase), nil
5773
}
74+
75+
76+
77+
78+
func JavaDependency() {
79+
// Check if Java is installed
80+
if err := exec.Command("java", "-version").Run(); err == nil {
81+
fmt.Println("Java is already installed.")
82+
return
83+
}
84+
85+
// Determine the operating system
86+
switch os := runtime.GOOS; os {
87+
case "linux":
88+
// Identify Linux distribution
89+
out, err := exec.Command("sh", "-c", "cat /etc/os-release").Output()
90+
if err != nil {
91+
fmt.Printf("Failed to execute command: %s\n", err)
92+
return
93+
}
94+
95+
// Parse /etc/os-release
96+
osRelease := string(out)
97+
if strings.Contains(osRelease, "ID=arch") || strings.Contains(osRelease, "ID_LIKE=arch") {
98+
// Install Java for Arch-based systems
99+
fmt.Println("Installing Java using pacman...")
100+
exec.Command("sudo", "pacman", "-Sy", "--noconfirm", "jdk-openjdk").Run()
101+
102+
// Install pcscd and pcsc-tools using pacman
103+
fmt.Println("Installing pcscd and pcsc-tools using pacman...")
104+
exec.Command("sudo", "pacman", "-Syu", "--noconfirm", "ccid", "libnfc", "acsccid", "pcsclite", "pcsc-tools").Run()
105+
exec.Command("sudo", "systemctl", "enable", "--now", "pcscd").Run()
106+
} else if strings.Contains(osRelease, "ID=debian") || strings.Contains(osRelease, "ID=ubuntu") {
107+
// Install Java for Debian-based systems
108+
fmt.Println("Installing Java using apt...")
109+
exec.Command("sudo", "apt", "update").Run()
110+
exec.Command("sudo", "apt", "install", "-y", "default-jdk").Run()
111+
112+
// Install pcscd and pcsc-tools using apt
113+
fmt.Println("Installing pcscd and pcsc-tools using apt...")
114+
exec.Command("sudo", "apt-get", "update").Run()
115+
exec.Command("sudo", "apt-get", "install", "-y", "pcsc-lite", "pcsc-tools").Run()
116+
exec.Command("sudo", "systemctl", "enable", "pcscd").Run()
117+
exec.Command("sudo", "systemctl", "start", "pcscd").Run()
118+
} else {
119+
fmt.Println("Unsupported Linux distribution")
120+
}
121+
default:
122+
fmt.Printf("%s is not supported by this script\n", os)
123+
}
124+
}
125+
126+
func GlobalPlatformDependency() {
127+
// Define paths to search
128+
paths := []string{"../", os.Getenv("HOME") + "/Downloads/"}
129+
130+
found := false
131+
for _, path := range paths {
132+
found = searchFile(path, "gp.jar")
133+
if found {
134+
fmt.Println("gp.jar found in:", path)
135+
break
136+
}
137+
}
138+
139+
// If not found, download the file
140+
if !found {
141+
fmt.Println("gp.jar not found. Downloading...")
142+
err := downloadFile("gp.jar", gpJarURL)
143+
if err != nil {
144+
fmt.Println("Error downloading gp.jar:", err)
145+
return
146+
}
147+
fmt.Println("Downloaded gp.jar successfully.")
148+
}
149+
}
150+
151+
func searchFile(dir, filename string) bool {
152+
found := false
153+
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
154+
if err != nil {
155+
return err
156+
}
157+
if info.Name() == filename {
158+
found = true
159+
}
160+
return nil
161+
})
162+
return found
163+
}
164+
165+
166+
167+
168+
169+
func downloadFile(filepath string, url string) error {
170+
// Get the data
171+
resp, err := http.Get(url)
172+
if err != nil {
173+
return err
174+
}
175+
defer resp.Body.Close()
176+
177+
// Create the file
178+
out, err := os.Create(filepath)
179+
if err != nil {
180+
return err
181+
}
182+
defer out.Close()
183+
184+
buf := make([]byte, 1024) // buffer size
185+
for {
186+
n, err := resp.Body.Read(buf)
187+
if err != nil && err != io.EOF {
188+
return err
189+
}
190+
if n == 0 {
191+
break
192+
}
193+
194+
if _, writeErr := out.Write(buf[:n]); writeErr != nil {
195+
return writeErr
196+
}
197+
}
198+
199+
return nil
200+
}
201+
202+

main.go

Lines changed: 19 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
var englishTxt embed.FS
2626

2727

28-
2928
func main() {
3029
if !checkKeycardBinaryExists() {
3130
fmt.Println("Keycard binary not found. Downloading...")
@@ -78,12 +77,21 @@ func main() {
7877

7978
fmt.Println("Exiting...")
8079
os.Exit(0)
81-
82-
8380
case "5":
84-
cid := "bafkreie7ohywtosou76tasm7j63yigtzxe7d5zqus4zu3j6oltvgtibeom" // Replace with actual CID
85-
runIPFSTestWithViu(cid)
81+
fmt.Println("Installing Dependencies...")
82+
keycard_link.JavaDependency()
83+
keycard_link.GlobalPlatformDependency()
8684

85+
case "6":
86+
fmt.Println("Installing Keycard...")
87+
err := keycard_link.installKeycard()
88+
if err != nil {
89+
fmt.Println("Error installing keycard:", err)
90+
}
91+
92+
case "7":
93+
fmt.Println("Exiting...")
94+
os.Exit(0)
8795

8896
default:
8997
fmt.Println("Invalid option, please try again.")
@@ -92,7 +100,6 @@ func main() {
92100
}
93101

94102

95-
96103
func qr(){
97104

98105
data, err := os.ReadFile("log_CID.log")
@@ -119,105 +126,21 @@ func qr(){
119126

120127

121128
func menu() (string, error) {
122-
err := art_link.PrintFileSlowly("ipfs.txt")
123-
if err != nil {
124-
fmt.Println("Error displaying ASCII art:", err)
125-
}
129+
126130
fmt.Println("---------------------------------------------")
127-
fmt.Println("IPFS-Secure | NFC Interface for IPFS ")
131+
fmt.Println("IPFS-Secure | NFC Interface for IPFS")
128132
fmt.Println("=============================================")
129-
fmt.Println("What would you like to do? Select 1, 2, or 3")
133+
fmt.Println("What would you like to do?")
130134
fmt.Println("1. Encrypt / upload sensitive data to IPFS.")
131135
fmt.Println("2. Decrypt / pull file with CID.")
132136
fmt.Println("3. Print CID Log to QR code.")
133-
fmt.Println("4. Exit.")
134-
fmt.Println("5. Run IPFS Connection test.")
137+
fmt.Println("4. Install Dependencies (Java and PCSCD)")
138+
fmt.Println("5. Install Keycard onto Implant")
139+
fmt.Println("6. Exit.")
135140
fmt.Println("=============================================")
136141
return generalAskUser("Enter your choice: ")
137142
}
138143

139-
// runIPFSTestWithViu encapsulates the entire process.
140-
func runIPFSTestWithViu(cid string) {
141-
if err := checkAndInstallViu(); err != nil {
142-
fmt.Println("Error installing 'viu':", err)
143-
fmt.Println("IPFS Check failed tests... :(")
144-
return
145-
}
146-
147-
if err := fetchFromIPFS(cid); err != nil {
148-
fmt.Println("Error fetching file from IPFS:", err)
149-
fmt.Println("IPFS Check failed tests... :(")
150-
return
151-
}
152-
153-
if err := displayImage(cid); err != nil {
154-
fmt.Println("Error displaying image:", err)
155-
fmt.Println("IPFS Check failed tests... :(")
156-
return
157-
}
158-
159-
if err := performBasicIPFSTests(); err != nil {
160-
fmt.Println("Error performing basic IPFS tests:", err)
161-
fmt.Println("IPFS Check failed tests... :(")
162-
return
163-
}
164-
165-
fmt.Println("IPFS tests completed successfully.")
166-
}
167-
168-
// checkAndInstallViu checks if 'viu' is installed and installs it if not.
169-
func checkAndInstallViu() error {
170-
_, err := exec.LookPath("viu")
171-
if err != nil {
172-
fmt.Println("Installing 'viu'...")
173-
cmd := exec.Command("sudo", "apt-get", "install", "viu", "-y")
174-
cmd.Stdout = os.Stdout
175-
cmd.Stderr = os.Stderr
176-
return cmd.Run()
177-
}
178-
return nil
179-
}
180-
181-
// fetchFromIPFS fetches a file from IPFS.
182-
func fetchFromIPFS(cid string) error {
183-
fmt.Println("Fetching from IPFS...")
184-
cmd := exec.Command("ipfs", "get", cid)
185-
cmd.Stdout = os.Stdout
186-
cmd.Stderr = os.Stderr
187-
return cmd.Run()
188-
}
189-
190-
// displayImage displays the image using 'viu'.
191-
func displayImage(filename string) error {
192-
fmt.Println("Displaying image...")
193-
cmd := exec.Command("viu", filename)
194-
cmd.Stdout = os.Stdout
195-
cmd.Stderr = os.Stderr
196-
return cmd.Run()
197-
}
198-
199-
// performBasicIPFSTests runs basic IPFS tests including 'ipfs diag sys' and 'ipfs id'.
200-
func performBasicIPFSTests() error {
201-
fmt.Println("Performing basic IPFS tests...")
202-
os.Remove("bafkreie7ohywtosou76tasm7j63yigtzxe7d5zqus4zu3j6oltvgtibeom")
203-
204-
// Test 'ipfs diag sys'
205-
if err := executeIPFSCommand("diag", "sys"); err != nil {
206-
return fmt.Errorf("IPFS diag sys test failed: %w", err)
207-
}
208-
209-
210-
fmt.Println("All basic IPFS tests passed successfully.")
211-
return nil
212-
}
213-
214-
// executeIPFSCommand executes an IPFS command and returns any errors.
215-
func executeIPFSCommand(args ...string) error {
216-
cmd := exec.Command("ipfs", args...)
217-
cmd.Stdout = os.Stdout
218-
cmd.Stderr = os.Stderr
219-
return cmd.Run()
220-
}
221144

222145
func downloadKeycardBinary() error {
223146
url := "https://github.com/status-im/keycard-cli/releases/download/0.7.0/keycard-linux-amd64"

0 commit comments

Comments
 (0)