First Starting debug

This commit is contained in:
mr
2026-02-02 09:05:58 +01:00
parent 562d86125e
commit c3352499fa
13 changed files with 74 additions and 29 deletions

View File

@@ -2,7 +2,10 @@ package common
import (
"bytes"
"crypto/ed25519"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"errors"
"fmt"
"oc-discovery/conf"
@@ -44,36 +47,47 @@ func Verify(pub crypto.PubKey, data, sig []byte) (bool, error) {
return pub.Verify(data, sig)
}
func LoadKeyFromFile(isPublic bool) (crypto.PrivKey, error) {
func LoadKeyFromFilePrivate() (crypto.PrivKey, error) {
path := conf.GetConfig().PrivateKeyPath
if isPublic {
path = conf.GetConfig().PublicKeyPath
}
fmt.Println("extract " + path)
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
// Try to unmarshal as libp2p private key (supports ed25519, rsa, etc.)
priv, err := crypto.UnmarshalPrivateKey(data)
fmt.Println(data)
block, _ := pem.Decode(data)
fmt.Println(block.Bytes)
keyAny, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return nil, err
}
return priv, nil
edKey, ok := keyAny.(ed25519.PrivateKey)
if !ok {
return nil, fmt.Errorf("not an ed25519 key")
}
return crypto.UnmarshalEd25519PrivateKey(edKey)
}
func VerifyPubWithPriv() bool {
priv, err := LoadKeyFromFile(false)
func LoadKeyFromFilePublic() (crypto.PubKey, error) {
path := conf.GetConfig().PublicKeyPath
fmt.Println("extract " + path)
data, err := os.ReadFile(path)
if err != nil {
fmt.Println(err)
return false
return nil, err
}
pub, err := LoadKeyFromFile(true)
block, _ := pem.Decode(data)
keyAny, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
fmt.Println(err)
return false
return nil, err
}
return priv.GetPublic().Equals(pub)
edKey, ok := keyAny.(ed25519.PublicKey)
if !ok {
return nil, fmt.Errorf("not an ed25519 key")
}
// Try to unmarshal as libp2p private key (supports ed25519, rsa, etc.)
return crypto.UnmarshalEd25519PublicKey(edKey)
}
func LoadPSKFromFile() (pnet.PSK, error) {
@@ -82,11 +96,12 @@ func LoadPSKFromFile() (pnet.PSK, error) {
if err != nil {
return nil, err
}
// Try to unmarshal as libp2p private key (supports ed25519, rsa, etc.)
fmt.Println("sqqdsqsqd")
psk, err := pnet.DecodeV1PSK(bytes.NewReader(data))
if err != nil {
return nil, err
}
fmt.Println("PSK found.")
return psk, nil
}