Skip to content

Commit bd4468f

Browse files
authored
Listen host (#2072)
* Add scheme to provision * Add support for listen_host
1 parent c9c250a commit bd4468f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

nvflare/lighter/dummy_project.yml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ participants:
1212
- name: site-1
1313
type: client
1414
org: nvidia
15+
# listening_host will enable creating one pair of cert/private key for this client
16+
# so it can behave like a server for client api. The value must be a hostname that
17+
# client api can reach via network.
18+
# listening_host: site-1-lh
1519
- name: site-2
1620
type: client
1721
org: nvidia

nvflare/lighter/ha_project.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ participants:
2424
- name: site-1
2525
type: client
2626
org: nvidia
27+
# listening_host will enable creating one pair of cert/private key for this client
28+
# so it can behave like a server for client api. The value must be a hostname that
29+
# client api can reach via network.
30+
# listening_host: site-1-lh
2731
- name: site-2
2832
type: client
2933
org: nvidia

nvflare/lighter/impl/cert.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from cryptography.hazmat.primitives.asymmetric import rsa
2323
from cryptography.x509.oid import NameOID
2424

25-
from nvflare.lighter.spec import Builder
25+
from nvflare.lighter.spec import Builder, Participant
2626

2727

2828
def serialize_pri_key(pri_key):
@@ -97,6 +97,14 @@ def _build_write_cert_pair(self, participant, base_name, ctx):
9797
f.write(serialize_cert(cert))
9898
with open(os.path.join(dest_dir, f"{base_name}.key"), "wb") as f:
9999
f.write(serialize_pri_key(pri_key))
100+
if base_name == "client" and (listening_host := participant.props.get("listening_host")):
101+
tmp_participant = Participant("server", listening_host, participant.org)
102+
tmp_pri_key, tmp_cert = self.get_pri_key_cert(tmp_participant)
103+
with open(os.path.join(dest_dir, "server.crt"), "wb") as f:
104+
f.write(serialize_cert(tmp_cert))
105+
with open(os.path.join(dest_dir, "server.key"), "wb") as f:
106+
f.write(serialize_pri_key(tmp_pri_key))
107+
100108
pkcs12 = serialization.pkcs12.serialize_key_and_certificates(
101109
subject.encode("ascii"), pri_key, cert, None, serialization.BestAvailableEncryption(subject.encode("ascii"))
102110
)

0 commit comments

Comments
 (0)