Skip to content

Commit e60800e

Browse files
[2.6] Support server name longer than 64 chars (#3537)
Fixes # . ### Description This PR adds support of long server name (> 64 chars). See #3528 for details. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Quick tests passed locally by running `./runtest.sh`. - [ ] In-line docstrings updated. - [ ] Documentation updated. --------- Co-authored-by: Holger Roth <[email protected]>
1 parent 8b86722 commit e60800e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

nvflare/lighter/impl/cert.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from nvflare.lighter.spec import Builder
2727
from nvflare.lighter.utils import Identity, generate_cert, generate_keys, serialize_cert, serialize_pri_key
2828

29+
MAX_CN_LENGTH = 64
30+
2931

3032
class _CertState:
3133

@@ -108,7 +110,45 @@ def __init__(self):
108110
self.subject = None
109111
self.issuer = None
110112

113+
@staticmethod
114+
def _fix_server_name(server: Participant):
115+
"""Server Name is used as CN of the cert. But the CN cannot exceed 63 chars. So we have to truncate it
116+
to make the cert.
117+
118+
Server Name also serves as the identity of the server for all clients to verify, and it must match the
119+
CN in the server's cert.
120+
121+
Server Name is also the default host name (unless default host is explicitly specified) for clients to
122+
connect to. Truncated name won't be a valid host name.
123+
124+
We have to accommodate all these factors:
125+
126+
- We truncate the server name and use it for both name and subject of the server. This will satisfy CN
127+
requirement of the cert, and will satisfy server identity validation by clients.
128+
- We check whether the DEFAULT_HOST property is explicitly specified in the server. If not, we explicitly
129+
set it to the original name.
130+
131+
Args:
132+
server: the server to be fixed.
133+
134+
Returns:
135+
"""
136+
original_name = server.name
137+
if len(original_name) > MAX_CN_LENGTH:
138+
truncated_name = original_name[:MAX_CN_LENGTH]
139+
140+
# both name and subject of the server must use the truncated name!
141+
server.name = truncated_name
142+
server.subject = truncated_name
143+
144+
default_host = server.get_prop(PropKey.DEFAULT_HOST)
145+
if not default_host:
146+
# must use the original name as the default host
147+
server.set_prop(PropKey.DEFAULT_HOST, original_name)
148+
111149
def initialize(self, project: Project, ctx: ProvisionContext):
150+
self._fix_server_name(project.get_server())
151+
112152
state_dir = ctx.get_state_dir()
113153
self.persistent_state = _CertState(state_dir)
114154
state = self.persistent_state

0 commit comments

Comments
 (0)