Skip to content

Commit 57c5e3b

Browse files
authored
Add files and V1 Binary
1 parent 8cab8ca commit 57c5e3b

File tree

8 files changed

+392
-48
lines changed

8 files changed

+392
-48
lines changed

Docs/Keycard_API.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Keycard Implementation
2+
3+
## Introduction
4+
5+
This document outlines the process of integrating Keycard into a Java-based application for symmetrically encrypting and decrypting data, particularly focusing on file-based applications with IPFS (InterPlanetary File System) storage.
6+
7+
## Developers: Criteria for Commits
8+
9+
Contributors should follow these guidelines to ensure consistency and security in the codebase.
10+
11+
### Encryption Process:
12+
13+
#### User Passphrase Input:
14+
- Ensure secure input handling.
15+
- Use secure GUI prompts or console inputs that don't echo the passphrase.
16+
17+
#### Signing Passphrase with Keycard:
18+
- Keycards typically sign a hash of data rather than the passphrase directly.
19+
- Use the Keycard to securely generate or sign a hash of the passphrase for encryption.
20+
21+
#### Key Generation and Management:
22+
- Generate a symmetric key based on the signed data, ensuring cryptographic security.
23+
- Securely handle the key in memory and clear it immediately after use.
24+
25+
#### Integration with GPG:
26+
- Pass the symmetric key to GPG securely for encryption.
27+
- Avoid using command-line arguments for key passing.
28+
29+
#### Security Measures:
30+
- Implement measures to prevent memory dumping.
31+
- Ensure secure deletion of temporary files or logs containing sensitive data.
32+
- Use secure file handling libraries in Java.
33+
34+
#### Uploading to IPFS:
35+
- Maintain the integrity and confidentiality of data during the IPFS upload process.
36+
- Securely handle IPFS interactions and manage CIDs appropriately.
37+
38+
### Decryption Process:
39+
40+
#### Retrieve File from IPFS:
41+
- Ensure secure retrieval of the encrypted file from IPFS using the CID.
42+
43+
#### Passphrase Handling:
44+
- Manage passphrase input securely, similar to the encryption process.
45+
46+
#### Keycard Interaction:
47+
- Use the Keycard to generate or retrieve the decryption key securely.
48+
49+
#### Decrypting with GPG:
50+
- Decrypt the file using GPG with the symmetric key derived from the Keycard-signed data.
51+
- Ensure secure handling of key material during decryption.
52+
53+
#### Post-Decryption Security:
54+
- Manage decrypted data securely.
55+
- Clean up any sensitive remnants in memory or temporary storage.
56+
57+
#### Error Handling and Logging:
58+
- Implement robust error handling for Keycard interactions, GPG operations, and IPFS retrieval.
59+
- Avoid storing sensitive information in logs.
60+
61+
### General Considerations:
62+
63+
#### Cryptographic Best Practices:
64+
- Adhere to best practices for key generation, data signing, and symmetric encryption.
65+
66+
#### Code Security:
67+
- Ensure the Java code handling cryptographic operations is secure against common vulnerabilities.
68+
69+
#### User Feedback:
70+
- Provide clear and user-friendly feedback for operations, especially for errors or successful operations.
71+
72+
#### Documentation and Testing:
73+
- Document the process clearly, including prerequisites and configurations.
74+
- Thoroughly test the application for reliability and security.
75+
76+
## Understanding Keycard Capabilities
77+
78+
### Key Storage:
79+
- Keycard is designed for secure storage of private keys, commonly used in digital signatures and transaction authentication.
80+
81+
### Signing Operations:
82+
- Keycard can sign data blocks using stored private keys, adaptable for file-based applications and IPFS storage.
83+
84+
### Encryption/Decryption:
85+
- While not a primary function, Keycard's signing capabilities can be adapted for encryption/decryption processes in file-based applications.
86+
87+
## Implementation Notes
88+
89+
### Data Flow for Encryption and Decryption Using Java Keycard
90+
91+
#### Encryption:
92+
- User enters a passphrase.
93+
- Sign the passphrase with the Keycard.
94+
- Generate a unique key based on the signed passphrase.
95+
- Use the key as string data for GPG encryption.
96+
- Remove sensitive process logs or files to prevent data exposure.
97+
- Encrypt the data with GPG and pass the encrypted file to IPFS.
98+
99+
#### Decryption:
100+
- Retrieve the file from IPFS using its CID.
101+
- User re-enters the passphrase.
102+
- Sign the passphrase with the Keycard to regenerate the decryption key.
103+
- Use the key to decrypt the file with GPG.
104+
- Ensure removal of sensitive logs or temporary files.
105+
106+
## Further Reading for Developers
107+
108+
### Recommended Resources:
109+
110+
- [Official Go API for Keycard](https://github.com/status-im/keycard-go/)
111+
- [Keycard CLI](https://github.com/status-im/keycard-cli)
112+
- [Keycard APDU API](https://keycard.tech/docs/apdu/)
113+
- [Localhost Web3 Application for Keycard](https://keycard.tech/docs/web3.html)
114+
115+
Contributors are encouraged to explore these resources for a deeper understanding of Keycard's capabilities and integration methods.
116+
117+
## Conclusion
118+
119+
By leveraging Keycard's unique capabilities for signing and transaction authentication, developers can create a secure and efficient system for encrypting and decrypting data, particularly for applications involving IPFS storage.
120+

IPFSS_IPFS-Secure

6.73 MB
Binary file not shown.

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A unique IPFS frontend that you can use to push your files through. Encrypt all traffic with a Asymmetric RSA keypair and GPG. Ensure that you can upload private data to IPFS, and only you can receive and view on another machine. The HTTPS of IPFS.
44

5-
**Recommended to use PGPCard, Apex, or yubikey for Multi Factor Authentication (MFA), encrypting and decrypting data. Using IPFS in general.**
5+
**Recommended to use keycard, Apex, or Keycard for Multi Factor Authentication (MFA), encrypting and decrypting data. Using IPFS in general.**
66

77

88
SecureIPFS is an application and library set that integrates the InterPlanetary File System (IPFS) with robust RSA encryption in Go, providing a secure method to store and retrieve files. It encrypts files before uploading to IPFS and decrypts them using a corresponding key pair.
@@ -13,24 +13,29 @@ SecureIPFS is an application and library set that integrates the InterPlanetary
1313
- I can do this but some help would be appreciated.
1414
- Just need to add IPFS Kubo implementation - this is just a front end for IPFS Get and IPFS Add.
1515

16-
2. **Apex /Flex Implementation.**
16+
2. **Keycard Implementation.**
1717
- This is stage two and if you are a developer wanting to help, make a fork, see /Docs/* and add your software, finish / upload with a pull request.
18-
- This integration has been restructured from using keycard due to a rather unorthodox workaround. Instead the project will now focus on using both Keycard and the PGP applet.
18+
- Ive therorised a way to securely use the keycard for encrypting and decrypting data. Since a EDCSA Signature is unique to the signers private key and the data they are signing. This is all we need.
19+
- You just reverse the process, the file is not being signed, the users unique passphrase is. This way the unique EDCSA signature is unique to the user and the application,
20+
- This way an attacker cannot decrypt the IPFS data without the keycard, and they cant just scan the keycard, the need to know the passphrase used for that file, and swipe or otherwise steal the keycard.
21+
- This is a way of using in vivo crypto coprocessors for secure MFA and file privacy / security.
1922

2023

2124
## From Dangerous Things with love.
2225

23-
The Apex Flex and FlexSecure allow us mortal humans to perform cryptographic functions in vivo (under the skin) this fact paired with the above cryptographic MFA (Coupling the GPG key from your card into IPFS), the program provides the user a secure way to keep their data safe.
26+
The Apex Flex and FlexSecure allow us mortal humans to perform cryptographic functions in vivo (under the skin) this fact paired with the above cryptographic MFA, provides the user a secure way to keep their data safe.
2427

2528
![image](https://github.com/SATUNIX/IPFSS_IPFS-Secure/assets/111553838/c28a0a23-1c19-4e04-b621-ef7b76d92f77)
2629

30+
You may be asking **"but satunix why is this so special?" "These implants can do PGP and OTP!!!"** Well, they sure can, but thats it, good luck loading several applets onto your keycard for each purpose, then trying to navigate and use all of the different block positions keys, algorithims.... and whatever tf. Me personally, I kave a FlexSecure loaded with Keycard. Thus, Keycard must be used for this process. This allows even the noobiest of users ease of control and access.
31+
*A load and swipe process.*
2732

2833
>"The ability to carry your OTP authenticator, PGP, and other cryptographic keys, and perform cryptographic functions all in vivo (generate OTP codes, encrypt & decrypt data, etc.) without ever revealing private keys to the NFC interface you are interacting with is a huge step forward for personal digital identity and data security."
2934
3035
## Key Features
3136

3237
- **Asymmetric Encryption**: Utilize RSA encryption to secure your files. Files are encrypted with a public key and can only be decrypted with the corresponding passphrase protected private key.
33-
- **Symmetric Encryption**: Utilize a Apex or FlexSecure implant with to use the Multi Factor Symmetric encryption on your files, supply a passphrase for the key, scan your card, files secured.
38+
- **Symmetric Encryption**: Utilize a Apex or FlexSecure implant with keycard to use Multi Factor Symmetric encryption on your files, supply a passphrase, scan your card, files secured.
3439
- **Decentralized Storage**: Leverage IPFS for secure, encrypted, decentralized, and immutable file storage.
3540
- **Go Implementation**: Built with Go, taking advantage of its powerful concurrency features and efficient data handling.
3641

go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module IPFSS_IPFS-Secure
2+
3+
go 1.21.4
4+
5+
require github.com/status-im/keycard-go v0.3.2
6+
7+
require (
8+
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
9+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
10+
github.com/ethereum/go-ethereum v1.10.26 // indirect
11+
github.com/go-stack/stack v1.8.1 // indirect
12+
golang.org/x/crypto v0.1.0 // indirect
13+
golang.org/x/sys v0.2.0 // indirect
14+
golang.org/x/text v0.4.0 // indirect
15+
)

go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
2+
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
3+
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
4+
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
5+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7+
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
8+
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
9+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
10+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
11+
github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s=
12+
github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
13+
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
14+
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
15+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
16+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17+
github.com/status-im/keycard-go v0.3.2 h1:YusIF/bHx6YZis8UTOJrpZFnTs4IkRBdmJXqdiXkpFE=
18+
github.com/status-im/keycard-go v0.3.2/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
19+
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
20+
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
21+
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
22+
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
23+
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
24+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
25+
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
26+
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
27+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
28+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

ipfs_link/ipfs_link.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package ipfs_link
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"os/exec"
7+
"strings"
8+
)
9+
10+
// AddFileToIPFS adds a file to IPFS and returns the CID (Content Identifier)
11+
func AddFileToIPFS(filePath string) (string, error) {
12+
cmd := exec.Command("ipfs", "add", filePath)
13+
14+
var out bytes.Buffer
15+
cmd.Stdout = &out
16+
err := cmd.Run()
17+
if err != nil {
18+
return "", fmt.Errorf("error adding file to IPFS: %w", err)
19+
}
20+
21+
output := out.String()
22+
// Extract CID from the output
23+
lines := strings.Split(output, "\n")
24+
for _, line := range lines {
25+
if strings.Contains(line, "added") {
26+
parts := strings.Fields(line)
27+
if len(parts) >= 2 {
28+
return parts[1], nil // Assuming the CID is the second part
29+
}
30+
}
31+
}
32+
33+
return "", fmt.Errorf("CID not found in IPFS add output")
34+
}
35+
36+
// GetFileFromIPFS retrieves a file from IPFS using its CID
37+
func GetFileFromIPFS(cid, outputPath string) error {
38+
cmd := exec.Command("ipfs", "get", cid, "-o", outputPath)
39+
40+
err := cmd.Run()
41+
if err != nil {
42+
return fmt.Errorf("error retrieving file from IPFS: %w", err)
43+
}
44+
45+
return nil
46+
}

keycard_link/keycard_link.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package keycard_link
2+
3+
import (
4+
"bufio"
5+
"bytes"
6+
"fmt"
7+
"os"
8+
"os/exec"
9+
"strings"
10+
)
11+
12+
// GetKeycardPublicKey retrieves the public key from the keycard.
13+
func GetKeycardPublicKey() (string, error) {
14+
// Command to execute
15+
cmd := exec.Command("./keycard-linux-amd64", "info")
16+
17+
// Capture the output of the command
18+
var out bytes.Buffer
19+
cmd.Stdout = &out
20+
21+
// Run the command
22+
err := cmd.Run()
23+
if err != nil {
24+
return "", err
25+
}
26+
27+
// Process the output to find the public key
28+
scanner := bufio.NewScanner(&out)
29+
for scanner.Scan() {
30+
line := scanner.Text()
31+
if strings.Contains(line, "PublicKey:") {
32+
// Assuming the public key is the last element in the line, separated by spaces
33+
parts := strings.Fields(line)
34+
if len(parts) > 1 {
35+
return parts[len(parts)-1], nil
36+
}
37+
}
38+
}
39+
40+
if err := scanner.Err(); err != nil {
41+
return "", err
42+
}
43+
44+
return "", fmt.Errorf("public key not found in the output")
45+
}
46+
47+
// ReadPassphrase prompts the user to enter a passphrase.
48+
func ReadPassphrase() (string, error) {
49+
fmt.Print("Enter a unique passphrase for this file upload: ")
50+
reader := bufio.NewReader(os.Stdin)
51+
passphrase, err := reader.ReadString('\n')
52+
if err != nil {
53+
return "", err
54+
}
55+
return strings.TrimSpace(passphrase), nil
56+
}

0 commit comments

Comments
 (0)