WIP crypto prototyping
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
|
||||
"github.com/k4lipso/pentapass/storage"
|
||||
"github.com/k4lipso/pentapass/crypto/age"
|
||||
"github.com/k4lipso/pentapass/crypto"
|
||||
)
|
||||
|
||||
@@ -33,12 +34,24 @@ var (
|
||||
|
||||
|
||||
func main() {
|
||||
crypto.Encrypt()
|
||||
|
||||
flag.Parse()
|
||||
ctx := context.Background()
|
||||
data := *dbPath
|
||||
|
||||
key, err := age.LoadOrGenerateKeys(*dbPath + "/age.key")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("AgeKey: %s\n", key.String())
|
||||
fmt.Printf("AgePublicKey: %s\n", key.Recipient().String())
|
||||
|
||||
cipher, err := age.Encrypt([]byte("Test Message"), []string{key.Recipient().String()})
|
||||
fmt.Printf("Encrypted: %s\n", cipher)
|
||||
decrypted, err := age.Decrypt(cipher, key)
|
||||
fmt.Printf("Decrypted: %s\n", decrypted)
|
||||
|
||||
h, dht, err := storage.SetupLibp2pHost(ctx, *dbPath)
|
||||
|
||||
pid := h.ID().String()
|
||||
@@ -77,6 +90,7 @@ func main() {
|
||||
Host: h,
|
||||
Ipfs: ipfs,
|
||||
PubSub: ps,
|
||||
Key: key,
|
||||
}
|
||||
|
||||
Cfg := storage.NewConfig()
|
||||
@@ -214,6 +228,43 @@ Commands:
|
||||
}
|
||||
|
||||
fmt.Printf("[%s] -> %s\n", k, string(v))
|
||||
case "generate":
|
||||
if len(fields) < 3 {
|
||||
fmt.Println("generate <namespace> <Service>")
|
||||
fmt.Println("> ")
|
||||
continue
|
||||
}
|
||||
|
||||
namespace := fields[1]
|
||||
|
||||
val, ok := Namespaces[namespace]
|
||||
|
||||
if !ok {
|
||||
fmt.Println("Namespace does not exist")
|
||||
continue
|
||||
}
|
||||
|
||||
service := fields[2]
|
||||
password := crypto.NewPassword()
|
||||
password.Service = service
|
||||
|
||||
data, err := password.ToJson()
|
||||
if err != nil {
|
||||
printErr(err)
|
||||
continue
|
||||
}
|
||||
|
||||
encryptedPassword, err := age.Encrypt(data, []string{key.Recipient().String()})
|
||||
if err != nil {
|
||||
printErr(err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = val.Put(password.Id.String(), string(encryptedPassword))
|
||||
if err != nil {
|
||||
printErr(err)
|
||||
continue
|
||||
}
|
||||
case "put":
|
||||
if len(fields) < 4 {
|
||||
fmt.Println("put <namespace> <key> <value>")
|
||||
|
||||
Reference in New Issue
Block a user