Skip to content

Commit 22b9432

Browse files
committed
multi: depricate UIPassword session type
1 parent 5d65a6e commit 22b9432

File tree

3 files changed

+52
-39
lines changed

3 files changed

+52
-39
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,8 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
335335
endpoint := endpoint
336336
tt.Run(endpoint.name+" lit port", func(ttt *testing.T) {
337337
runLNCAuthTest(
338-
ttt, cfg.LitAddr(), cfg.UIPassword,
339-
cfg.TLSCertPath,
340-
endpoint.requestFn,
338+
ttt, cfg.LitAddr(), cfg.TLSCertPath,
339+
cfg.LitMacPath, endpoint.requestFn,
341340
endpoint.successPattern,
342341
endpoint.allowedThroughLNC,
343342
)
@@ -583,7 +582,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
583582

584583
// runLNCAuthTest tests authentication of the given interface when connecting
585584
// through Lightning Node Connect.
586-
func runLNCAuthTest(t *testing.T, hostPort, uiPassword, tlsCertPath string,
585+
func runLNCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
587586
makeRequest requestFn, successContent string, callAllowed bool) {
588587

589588
ctxb := context.Background()
@@ -593,11 +592,14 @@ func runLNCAuthTest(t *testing.T, hostPort, uiPassword, tlsCertPath string,
593592
rawConn, err := connectRPC(ctxt, hostPort, tlsCertPath)
594593
require.NoError(t, err)
595594

595+
macBytes, err := ioutil.ReadFile(macPath)
596+
require.NoError(t, err)
597+
ctxlm := macaroonContext(ctxt, macBytes)
598+
596599
// We first need to create an LNC session that we can use to connect.
597600
// We use the UI password to create the session.
598-
ctxm := uiPasswordContext(ctxt, uiPassword, true)
599601
litClient := litrpc.NewSessionsClient(rawConn)
600-
sessResp, err := litClient.AddSession(ctxm, &litrpc.AddSessionRequest{
602+
sessResp, err := litClient.AddSession(ctxlm, &litrpc.AddSessionRequest{
601603
Label: "integration-test",
602604
SessionType: litrpc.SessionType_TYPE_MACAROON_READONLY,
603605
ExpiryTimestampSeconds: uint64(
@@ -611,13 +613,14 @@ func runLNCAuthTest(t *testing.T, hostPort, uiPassword, tlsCertPath string,
611613
connectPhrase := strings.Split(
612614
sessResp.Session.PairingSecretMnemonic, " ",
613615
)
614-
rawLNCConn, err := connectMailbox(ctxt, connectPhrase)
616+
rawLNCConn, macBytes, err := connectMailbox(ctxt, connectPhrase)
615617
require.NoError(t, err)
616618

617619
// We should be able to make a request via LNC to the given RPC
618620
// endpoint, unless it is explicitly disallowed (we currently don't want
619621
// to support creating more sessions through LNC until we have all
620622
// macaroon permissions properly set up).
623+
ctxm := macaroonContext(ctxt, macBytes)
621624
resp, err := makeRequest(ctxm, rawLNCConn)
622625

623626
// Is this a disallowed call?
@@ -719,7 +722,7 @@ func getServerCertificates(hostPort string) ([]*x509.Certificate, error) {
719722
// connectMailbox tries to establish a connection through LNC using the given
720723
// connect phrase and the test mailbox server.
721724
func connectMailbox(ctx context.Context,
722-
connectPhrase []string) (grpc.ClientConnInterface, error) {
725+
connectPhrase []string) (grpc.ClientConnInterface, []byte, error) {
723726

724727
var mnemonicWords [mailbox.NumPasswordWords]string
725728
copy(mnemonicWords[:], connectPhrase)
@@ -729,13 +732,13 @@ func connectMailbox(ctx context.Context,
729732

730733
privKey, err := btcec.NewPrivateKey(btcec.S256())
731734
if err != nil {
732-
return nil, err
735+
return nil, nil, err
733736
}
734737
ecdh := &keychain.PrivKeyECDH{PrivKey: privKey}
735738

736739
transportConn, err := mailbox.NewClient(ctx, sid)
737740
if err != nil {
738-
return nil, err
741+
return nil, nil, err
739742
}
740743

741744
noiseConn := mailbox.NewNoiseGrpcConn(ecdh, nil, password[:])
@@ -744,9 +747,25 @@ func connectMailbox(ctx context.Context,
744747
grpc.WithContextDialer(transportConn.Dial),
745748
grpc.WithTransportCredentials(noiseConn),
746749
grpc.WithPerRPCCredentials(noiseConn),
750+
grpc.WithBlock(),
751+
}
752+
753+
conn, err := grpc.DialContext(ctx, mailboxServerAddr, dialOpts...)
754+
if err != nil {
755+
return nil, nil, err
756+
}
757+
758+
md, err := noiseConn.GetRequestMetadata(nil, "")
759+
if err != nil {
760+
return nil, nil, err
761+
}
762+
763+
macStr, ok := md[terminal.HeaderMacaroon]
764+
if !ok {
765+
return nil, nil, fmt.Errorf("no macaroon found in the authdata")
747766
}
748767

749-
return grpc.DialContext(ctx, mailboxServerAddr, dialOpts...)
768+
return conn, []byte(macStr), nil
750769
}
751770

752771
func macaroonContext(ctx context.Context, macBytes []byte) context.Context {

itest/litd_mode_remote_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ func testModeRemote(net *NetworkHarness, t *harnessTest) {
137137
endpoint := endpoint
138138
tt.Run(endpoint.name+" lit port", func(ttt *testing.T) {
139139
runLNCAuthTest(
140-
ttt, cfg.LitAddr(), cfg.UIPassword,
141-
cfg.LitTLSCertPath,
142-
endpoint.requestFn,
140+
ttt, cfg.LitAddr(), cfg.LitTLSCertPath,
141+
cfg.LitMacPath, endpoint.requestFn,
143142
endpoint.successPattern,
144143
endpoint.allowedThroughLNC,
145144
)

session_rpcserver.go

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,11 @@ func (s *sessionRpcServer) AddSession(_ context.Context,
119119
return nil, err
120120
}
121121

122-
if typ != session.TypeUIPassword && typ != session.TypeMacaroonAdmin &&
122+
if typ != session.TypeMacaroonAdmin &&
123123
typ != session.TypeMacaroonReadonly {
124124

125-
return nil, fmt.Errorf("invalid session type, only UI " +
126-
"password, admin and readonly macaroon types " +
127-
"supported in LiT")
125+
return nil, fmt.Errorf("invalid session type, only admin " +
126+
"and readonly macaroon types supported in LiT")
128127
}
129128

130129
sess, err := session.NewSession(
@@ -181,33 +180,29 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
181180
return nil
182181
}
183182

184-
var authData []byte
185-
switch sess.Type {
186-
case session.TypeUIPassword:
187-
authData = []byte("Authorization: Basic " + s.cfg.basicAuth)
188-
189-
case session.TypeMacaroonAdmin, session.TypeMacaroonReadonly:
190-
ctx := context.Background()
191-
readOnly := sess.Type == session.TypeMacaroonReadonly
192-
mac, err := s.cfg.superMacBaker(
193-
ctx, sess.MacaroonRootKey, &session.MacaroonRecipe{
194-
Permissions: GetAllPermissions(readOnly),
195-
},
196-
)
197-
if err != nil {
198-
log.Debugf("Not resuming session %x. Could not bake"+
199-
"the necessary macaroon: %w", pubKeyBytes, err)
200-
return nil
201-
}
183+
if sess.Type != session.TypeMacaroonAdmin &&
184+
sess.Type != session.TypeMacaroonReadonly {
202185

203-
authData = []byte(fmt.Sprintf("%s: %s", HeaderMacaroon, mac))
204-
205-
default:
206186
log.Debugf("Not resuming session %x with type %d", pubKeyBytes,
207187
sess.Type)
208188
return nil
209189
}
210190

191+
readOnly := sess.Type == session.TypeMacaroonReadonly
192+
mac, err := s.cfg.superMacBaker(
193+
context.Background(), sess.MacaroonRootKey,
194+
&session.MacaroonRecipe{
195+
Permissions: GetAllPermissions(readOnly),
196+
},
197+
)
198+
if err != nil {
199+
log.Debugf("Not resuming session %x. Could not bake"+
200+
"the necessary macaroon: %w", pubKeyBytes, err)
201+
return nil
202+
}
203+
204+
authData := []byte(fmt.Sprintf("%s: %s", HeaderMacaroon, mac))
205+
211206
sessionClosedSub, err := s.sessionServer.StartSession(sess, authData)
212207
if err != nil {
213208
return err

0 commit comments

Comments
 (0)