Skip to content

Commit

Permalink
Don't set _password and _username in activate_session.
Browse files Browse the repository at this point in the history
  • Loading branch information
mver-al authored and oroulet committed Jan 8, 2025
1 parent 78a86a9 commit b1cfae3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions asyncua/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ def set_user(self, username: str) -> None:
"""
self._username = username

def set_password(self, pwd: str | None) -> None:
def set_password(self, pwd: str) -> None:
"""
Set user password for the connection.
initial password from the URL will be overwritten
"""
if pwd is not None and not isinstance(pwd, str):
if not isinstance(pwd, str):
raise TypeError(f"Password must be a string, got {pwd} of type {type(pwd)}")
self._password = pwd

Expand Down Expand Up @@ -678,23 +678,20 @@ def _add_certificate_auth(self, params, certificate, challenge):
params.UserTokenSignature.Signature = sig

def _add_user_auth(self, params, username: str, password: str):
self.set_user(username)
self.set_password(password)

params.UserIdentityToken = ua.UserNameIdentityToken()
params.UserIdentityToken.UserName = self._username
params.UserIdentityToken.UserName = username
policy = self.server_policy(ua.UserTokenType.UserName)
if not policy.SecurityPolicyUri or policy.SecurityPolicyUri == security_policies.SecurityPolicyNone.URI:
# see specs part 4, 7.36.3: if the token is NOT encrypted,
# then the password only contains UTF-8 encoded password
# and EncryptionAlgorithm is null
if self._password:
if password:
if self.security_policy.Mode != ua.MessageSecurityMode.SignAndEncrypt:
_logger.warning("Sending plain-text password")
params.UserIdentityToken.Password = self._password.encode("utf8")
params.UserIdentityToken.Password = password.encode("utf8")
params.UserIdentityToken.EncryptionAlgorithm = None
elif self._password:
data, uri = self._encrypt_password(self._password, policy.SecurityPolicyUri)
elif password:
data, uri = self._encrypt_password(password, policy.SecurityPolicyUri)
params.UserIdentityToken.Password = data
params.UserIdentityToken.EncryptionAlgorithm = uri
params.UserIdentityToken.PolicyId = policy.PolicyId
Expand Down

0 comments on commit b1cfae3

Please sign in to comment.