Skip to content

Commit c266481

Browse files
committed
firewall: obfuscate ConnectPeer
1 parent c944dca commit c266481

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

firewall/privacy_mapper.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ func (p *PrivacyMapper) checkers(db firewalldb.PrivacyMapDB,
303303
handleBatchOpenChannelResponse(db, flags, p.randIntn),
304304
mid.PassThroughErrorHandler,
305305
),
306+
"/lnrpc.Lightning/ConnectPeer": mid.NewRequestRewriter(
307+
&lnrpc.ConnectPeerRequest{},
308+
&lnrpc.ConnectPeerResponse{},
309+
handleConnectPeerRequest(db, flags),
310+
),
306311
}
307312
}
308313

@@ -1132,7 +1137,7 @@ func handleBatchOpenChannelRequest(db firewalldb.PrivacyMapDB,
11321137

11331138
func handleBatchOpenChannelResponse(db firewalldb.PrivacyMapDB,
11341139
flags session.PrivacyFlags,
1135-
randIntn func(int) (int, error)) func(ctx context.Context,
1140+
_ func(int) (int, error)) func(ctx context.Context,
11361141
r *lnrpc.BatchOpenChannelResponse) (proto.Message, error) {
11371142

11381143
return func(_ context.Context, r *lnrpc.BatchOpenChannelResponse) (
@@ -1168,6 +1173,46 @@ func handleBatchOpenChannelResponse(db firewalldb.PrivacyMapDB,
11681173
}
11691174
}
11701175

1176+
func handleConnectPeerRequest(db firewalldb.PrivacyMapDB,
1177+
flags session.PrivacyFlags) func(ctx context.Context,
1178+
r *lnrpc.ConnectPeerRequest) (proto.Message, error) {
1179+
1180+
return func(_ context.Context, r *lnrpc.ConnectPeerRequest) (
1181+
proto.Message, error) {
1182+
1183+
err := db.View(func(tx firewalldb.PrivacyMapTx) error {
1184+
var err error
1185+
// Note, this only works if the pubkey alias was
1186+
// already created via other calls, e.g. via
1187+
// ListChannels or GetNodeInfo.
1188+
if !flags.Contains(session.ClearPubkeys) {
1189+
r.Addr.Pubkey, err = firewalldb.RevealString(
1190+
tx, r.Addr.Pubkey,
1191+
)
1192+
if err != nil {
1193+
return err
1194+
}
1195+
}
1196+
1197+
if !flags.Contains(session.ClearNetworkAddresses) {
1198+
r.Addr.Host, err = firewalldb.RevealString(
1199+
tx, r.Addr.Host,
1200+
)
1201+
if err != nil {
1202+
return err
1203+
}
1204+
}
1205+
1206+
return nil
1207+
})
1208+
if err != nil {
1209+
return nil, err
1210+
}
1211+
1212+
return r, nil
1213+
}
1214+
}
1215+
11711216
// maybeHideAmount hides an amount if the privacy flag is not set.
11721217
func maybeHideAmount(flags session.PrivacyFlags, randIntn func(int) (int, error),
11731218
a int64) (int64, error) {

firewall/privacy_mapper_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestPrivacyMapper(t *testing.T) {
5252
outPoint(clearTxID, 0): outPoint(obfusTxID0, obfusOut0),
5353
outPoint(clearTxID, 1): outPoint(obfusTxID1, obfusOut1),
5454
"01020304": "c8134495",
55+
"secret-host.com": "sksiuekalkdoowurekdf",
5556
}
5657

5758
var (
@@ -526,6 +527,23 @@ func TestPrivacyMapper(t *testing.T) {
526527
},
527528
},
528529
},
530+
{
531+
name: "ConnectPeer Request",
532+
uri: "/lnrpc.Lightning/ConnectPeer",
533+
msgType: rpcperms.TypeRequest,
534+
msg: &lnrpc.ConnectPeerRequest{
535+
Addr: &lnrpc.LightningAddress{
536+
Pubkey: "c8134495",
537+
Host: "sksiuekalkdoowurekdf",
538+
},
539+
},
540+
expectedReplacement: &lnrpc.ConnectPeerRequest{
541+
Addr: &lnrpc.LightningAddress{
542+
Pubkey: "01020304",
543+
Host: "secret-host.com",
544+
},
545+
},
546+
},
529547
}
530548

531549
decodedID := &lnrpc.MacaroonId{

session/privacy_flags.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,22 @@ const (
4949
// ClearClosingTxIds is a privacy flag that indicates that the channel
5050
// closing transaction ids in the API should not be obfuscated.
5151
ClearClosingTxIds PrivacyFlag = 7
52+
53+
// ClearNetworkAddresses is a privacy flag that indicates that the
54+
// network addresses in the API should not be obfuscated.
55+
ClearNetworkAddresses PrivacyFlag = 8
5256
)
5357

5458
var flagMap = map[PrivacyFlag]string{
55-
ClearPubkeys: "ClearPubkeys",
56-
ClearAmounts: "ClearAmounts",
57-
ClearChanIDs: "ClearChanIDs",
58-
ClearTimeStamps: "ClearTimeStamps",
59-
ClearChanInitiator: "ClearChanInitiator",
60-
ClearHTLCs: "ClearHTLCs",
61-
ClearAccountBalances: "ClearAccountBalances",
62-
ClearClosingTxIds: "ClearClosingTxIds",
59+
ClearPubkeys: "ClearPubkeys",
60+
ClearAmounts: "ClearAmounts",
61+
ClearChanIDs: "ClearChanIDs",
62+
ClearTimeStamps: "ClearTimeStamps",
63+
ClearChanInitiator: "ClearChanInitiator",
64+
ClearHTLCs: "ClearHTLCs",
65+
ClearAccountBalances: "ClearAccountBalances",
66+
ClearClosingTxIds: "ClearClosingTxIds",
67+
ClearNetworkAddresses: "ClearNetworkAddresses",
6368
}
6469

6570
// String returns a string representation of the privacy flag.

session/privacy_flags_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ func TestPrivacyFlags(t *testing.T) {
5656
require.True(t, flags.Contains(ClearPubkeys))
5757
require.True(t, flags.Contains(ClearAmounts))
5858
require.False(t, flags.Contains(ClearChanIDs))
59+
60+
autoOpenFlags := PrivacyFlags{ClearPubkeys, ClearNetworkAddresses}
61+
require.NoError(t, err)
62+
require.Equal(t, "ClearPubkeys|ClearNetworkAddresses",
63+
autoOpenFlags.String())
5964
}

0 commit comments

Comments
 (0)