attempt ecies for decryption

This commit is contained in:
Jesse de Wit
2022-12-15 15:04:41 +01:00
parent ec3b4d2f0c
commit 8048dae0c5
2 changed files with 36 additions and 21 deletions

28
go.mod
View File

@@ -4,8 +4,8 @@ go 1.19
require (
github.com/aws/aws-sdk-go v1.30.20
github.com/breez/lntest v0.0.8
github.com/btcsuite/btcd v0.23.1
github.com/breez/lntest v0.0.9
github.com/btcsuite/btcd v0.23.3
github.com/btcsuite/btcd/btcec/v2 v2.2.1
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/caddyserver/certmagic v0.11.2
@@ -17,26 +17,28 @@ require (
github.com/jackc/pgtype v1.8.1
github.com/jackc/pgx/v4 v4.13.0
github.com/lightningnetwork/lightning-onion v1.2.0
github.com/lightningnetwork/lnd v0.15.1-beta
github.com/lightningnetwork/lnd v0.15.4-beta
github.com/lightningnetwork/lnd/tlv v1.0.3
github.com/niftynei/glightning v0.8.2
github.com/stretchr/testify v1.8.1
golang.org/x/exp v0.0.0-20221114191408-850992195362
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.50.1
)
require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ethereum/go-ethereum v1.10.17 // indirect
github.com/moby/term v0.0.0-20221120202655-abb19827d345 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/tools v0.2.0 // indirect
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
golang.org/x/net v0.1.0 // indirect
gotest.tools/v3 v3.4.0 // indirect
)
@@ -48,10 +50,10 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.2 // indirect
github.com/btcsuite/btcd/btcutil/psbt v1.1.5 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/btcwallet v0.15.1 // indirect
github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3 // indirect
github.com/btcsuite/btcwallet v0.16.1 // indirect
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 // indirect
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 // indirect
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0 // indirect
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.3 // indirect
github.com/btcsuite/btcwallet/walletdb v1.4.0 // indirect
github.com/btcsuite/btcwallet/wtxmgr v1.5.0 // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
@@ -67,6 +69,7 @@ require (
github.com/dsnet/compress v0.0.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dvyukov/go-fuzz v0.0.0-20210602112143-b1f3d6f4ef4e // indirect
github.com/ecies/go/v2 v2.0.4
github.com/fergusstrange/embedded-postgres v1.10.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/go-acme/lego/v3 v3.7.0 // indirect
@@ -87,7 +90,7 @@ require (
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/puddle v1.1.3 // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/jmespath/go-jmespath v0.3.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/jrick/logrotate v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
@@ -155,7 +158,6 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
@@ -172,6 +174,6 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)
replace github.com/lightningnetwork/lnd v0.15.1-beta => github.com/breez/lnd v0.15.0-beta.rc6.0.20220831104847-00b86a81e57a
replace github.com/lightningnetwork/lnd v0.15.4-beta => github.com/breez/lnd v0.15.0-beta.rc6.0.20220831104847-00b86a81e57a
replace github.com/niftynei/glightning v0.8.2 => github.com/breez/glightning v0.0.0-20221207132824-fb0b6f4f7483

View File

@@ -12,6 +12,7 @@ import (
"github.com/breez/lspd/btceclegacy"
lspdrpc "github.com/breez/lspd/rpc"
ecies "github.com/ecies/go/v2"
"github.com/golang/protobuf/proto"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc"
@@ -49,6 +50,7 @@ var (
client LightningClient
openChannelReqGroup singleflight.Group
privateKey *btcec.PrivateKey
privateKeyBytes []byte
publicKey *btcec.PublicKey
nodeName = os.Getenv("NODE_NAME")
nodePubkey = os.Getenv("NODE_PUBKEY")
@@ -73,11 +75,16 @@ func (s *server) ChannelInformation(ctx context.Context, in *lspdrpc.ChannelInfo
}
func (s *server) RegisterPayment(ctx context.Context, in *lspdrpc.RegisterPaymentRequest) (*lspdrpc.RegisterPaymentReply, error) {
data, err := btceclegacy.Decrypt(privateKey, in.Blob)
data, err := ecies.Decrypt(ecies.NewPrivateKeyFromBytes(privateKeyBytes), in.Blob)
if err != nil {
log.Printf("btcec.Decrypt(%x) error: %v", in.Blob, err)
return nil, fmt.Errorf("btcec.Decrypt(%x) error: %w", in.Blob, err)
log.Printf("ecies.Decrypt(%x) error: %v", in.Blob, err)
data, err = btceclegacy.Decrypt(privateKey, in.Blob)
if err != nil {
log.Printf("btcec.Decrypt(%x) error: %v", in.Blob, err)
return nil, fmt.Errorf("btcec.Decrypt(%x) error: %w", in.Blob, err)
}
}
var pi lspdrpc.PaymentInformation
err = proto.Unmarshal(data, &pi)
if err != nil {
@@ -150,10 +157,14 @@ func (s *server) OpenChannel(ctx context.Context, in *lspdrpc.OpenChannelRequest
}
func getSignedEncryptedData(in *lspdrpc.Encrypted) (string, []byte, error) {
signedBlob, err := btceclegacy.Decrypt(privateKey, in.Data)
signedBlob, err := ecies.Decrypt(ecies.NewPrivateKeyFromBytes(privateKeyBytes), in.Data)
if err != nil {
log.Printf("btcec.Decrypt(%x) error: %v", in.Data, err)
return "", nil, fmt.Errorf("btcec.Decrypt(%x) error: %w", in.Data, err)
log.Printf("ecies.Decrypt(%x) error: %v", in.Data, err)
signedBlob, err = btceclegacy.Decrypt(privateKey, in.Data)
if err != nil {
log.Printf("btcec.Decrypt(%x) error: %v", in.Data, err)
return "", nil, fmt.Errorf("btcec.Decrypt(%x) error: %w", in.Data, err)
}
}
var signed lspdrpc.Signed
err = proto.Unmarshal(signedBlob, &signed)
@@ -249,11 +260,13 @@ func NewGrpcServer() *server {
}
func (s *server) Start() error {
privateKeyBytes, err := hex.DecodeString(os.Getenv("LSPD_PRIVATE_KEY"))
pk, err := hex.DecodeString(os.Getenv("LSPD_PRIVATE_KEY"))
if err != nil {
log.Fatalf("hex.DecodeString(os.Getenv(\"LSPD_PRIVATE_KEY\")=%v) error: %v", os.Getenv("LSPD_PRIVATE_KEY"), err)
}
privateKey, publicKey = btcec.PrivKeyFromBytes(privateKeyBytes)
privateKeyBytes = pk
privateKey, publicKey = btcec.PrivKeyFromBytes(pk)
certmagicDomain := os.Getenv("CERTMAGIC_DOMAIN")
address := os.Getenv("LISTEN_ADDRESS")