@@ -110,7 +110,6 @@ def __init__(self, iserver: InternalServer = None, user_manager=None):
110
110
]
111
111
# allow all certificates by default
112
112
self ._permission_ruleset = SimpleRoleRuleset ()
113
- self ._policyIDs = ["Anonymous" , "Basic256Sha256" , "Username" , "Aes128Sha256RsaOaep" , "Aes256Sha256RsaPss" ]
114
113
self .certificate : Optional [x509 .Certificate ] = None
115
114
# Use acceptable limits
116
115
buffer_sz = 65535
@@ -349,19 +348,29 @@ def set_security_policy(self, security_policy, permission_ruleset=None):
349
348
350
349
def set_security_IDs (self , policy_ids ):
351
350
"""
352
- Method setting up the security endpoints for identification
353
- of clients. During server object initialization, all possible
354
- endpoints are enabled:
355
-
356
- self._policyIDs = ["Anonymous", "Basic256Sha256", "Username"]
351
+ DEPRECATED!
352
+ Only available for backwards compatibility.
353
+ Use set_identity_tokens instead.
354
+ """
355
+ _logger .warning ("set_security_IDs is deprecated, use set_identity_tokens instead!" )
356
+ tokens = []
357
+ if "Anonymous" in policy_ids :
358
+ tokens .append (ua .AnonymousIdentityToken )
359
+ if "Basic256Sha256" in policy_ids :
360
+ tokens .append (ua .X509IdentityToken )
361
+ if "Username" in policy_ids :
362
+ tokens .append (ua .UserNameIdentityToken )
363
+ self .set_identity_tokens (tokens )
357
364
358
- E.g. to limit the number of IDs and disable anonymous clients:
365
+ def set_identity_tokens (self , tokens ):
366
+ """
367
+ Method setting up allowed identity token types for authentication.
359
368
360
- set_security_IDs(["Basic256Sha256"])
369
+ E.g. to disable anonymous clients:
361
370
362
- (Implementation for ID check is currently not finalized... )
371
+ set_identity_tokens([ua.X509IdentityToken, ua.UserNameIdentityToken] )
363
372
"""
364
- self ._policyIDs = policy_ids
373
+ self .iserver . supported_tokens = tuple ( tokens )
365
374
366
375
async def _setup_server_nodes (self ):
367
376
# to be called just before starting server since it needs all parameters to be setup
@@ -492,30 +501,27 @@ def determine_security_level(security_policy_uri: str, security_mode: ua.Message
492
501
493
502
def _set_endpoints (self , policy = ua .SecurityPolicy , mode = ua .MessageSecurityMode .None_ ):
494
503
idtokens = []
495
- supported_token_classes = []
496
- if "Anonymous" in self . _policyIDs :
504
+ tokens = self . iserver . supported_tokens
505
+ if ua . AnonymousIdentityToken in tokens :
497
506
idtoken = ua .UserTokenPolicy ()
498
507
idtoken .PolicyId = "anonymous"
499
508
idtoken .TokenType = ua .UserTokenType .Anonymous
500
509
idtoken .SecurityPolicyUri = policy .URI
501
510
idtokens .append (idtoken )
502
- supported_token_classes .append (ua .AnonymousIdentityToken )
503
511
504
- if "Basic256Sha256" in self . _policyIDs :
512
+ if ua . X509IdentityToken in tokens :
505
513
idtoken = ua .UserTokenPolicy ()
506
514
idtoken .PolicyId = 'certificate_basic256sha256'
507
515
idtoken .TokenType = ua .UserTokenType .Certificate
508
516
idtoken .SecurityPolicyUri = policy .URI
509
517
idtokens .append (idtoken )
510
- supported_token_classes .append (ua .X509IdentityToken )
511
518
512
- if "Username" in self . _policyIDs :
519
+ if ua . UserNameIdentityToken in tokens :
513
520
idtoken = ua .UserTokenPolicy ()
514
521
idtoken .PolicyId = "username"
515
522
idtoken .TokenType = ua .UserTokenType .UserName
516
523
idtoken .SecurityPolicyUri = policy .URI
517
524
idtokens .append (idtoken )
518
- supported_token_classes .append (ua .UserNameIdentityToken )
519
525
520
526
appdesc = ua .ApplicationDescription ()
521
527
appdesc .ApplicationName = ua .LocalizedText (self .name )
@@ -535,7 +541,6 @@ def _set_endpoints(self, policy=ua.SecurityPolicy, mode=ua.MessageSecurityMode.N
535
541
edp .TransportProfileUri = "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary"
536
542
edp .SecurityLevel = Server .determine_security_level (policy .URI , mode )
537
543
self .iserver .add_endpoint (edp )
538
- self .iserver .supported_tokens = tuple (supported_token_classes )
539
544
540
545
def set_server_name (self , name ):
541
546
self .name = name
0 commit comments