An mTLS client certificate should only be usable with its node We create two instances, each generates its own certs and keys, and then we try to cross the wires.
(node_factory)
| 401 | |
| 402 | |
| 403 | def test_grpc_wrong_auth(node_factory): |
| 404 | """An mTLS client certificate should only be usable with its node |
| 405 | |
| 406 | We create two instances, each generates its own certs and keys, |
| 407 | and then we try to cross the wires. |
| 408 | """ |
| 409 | # These only exist if we have rust! |
| 410 | l1, l2 = node_factory.get_nodes(2, opts=[{"start": False}, {"start": False}]) |
| 411 | l1.start() |
| 412 | wait_for_grpc_start(l1) |
| 413 | |
| 414 | def connect(node): |
| 415 | p = Path(node.daemon.lightning_dir) / TEST_NETWORK |
| 416 | cert, key, ca = [f.read_bytes() for f in [ |
| 417 | p / 'client.pem', |
| 418 | p / 'client-key.pem', |
| 419 | p / "ca.pem"]] |
| 420 | |
| 421 | creds = grpc.ssl_channel_credentials( |
| 422 | root_certificates=ca, |
| 423 | private_key=key, |
| 424 | certificate_chain=cert, |
| 425 | ) |
| 426 | |
| 427 | channel = grpc.secure_channel( |
| 428 | f"localhost:{node.grpc_port}", |
| 429 | creds, |
| 430 | options=(('grpc.ssl_target_name_override', 'cln'),) |
| 431 | ) |
| 432 | return clnpb.NodeStub(channel) |
| 433 | |
| 434 | stub = connect(l1) |
| 435 | # This should work, it's the correct node |
| 436 | stub.Getinfo(clnpb.GetinfoRequest()) |
| 437 | |
| 438 | l1.stop() |
| 439 | l2.start() |
| 440 | wait_for_grpc_start(l2) |
| 441 | |
| 442 | # This should not work, it's a different node |
| 443 | with pytest.raises(Exception, match=r'Socket closed|StatusCode.UNAVAILABLE'): |
| 444 | stub.Getinfo(clnpb.GetinfoRequest()) |
| 445 | |
| 446 | # Now load the correct ones and we should be good to go |
| 447 | stub = connect(l2) |
| 448 | stub.Getinfo(clnpb.GetinfoRequest()) |
| 449 | |
| 450 | |
| 451 | def test_cln_plugin_reentrant(node_factory, executor): |