Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for using activate_session to change users. #1769

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions asyncua/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ async def activate_session(
self._add_certificate_auth(params, user_certificate, challenge)
else:
self._add_user_auth(params, username, password)
return await self.uaclient.activate_session(params)
res = await self.uaclient.activate_session(params)
self._server_nonce = res.ServerNonce
return res

def _add_anonymous_auth(self, params):
params.UserIdentityToken = ua.AnonymousIdentityToken()
Expand All @@ -683,12 +685,12 @@ def _add_user_auth(self, params, username: str, password: str):
# 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 = password.encode("utf8")
params.UserIdentityToken.EncryptionAlgorithm = None
elif self._password:
elif password:
data, uri = self._encrypt_password(password, policy.SecurityPolicyUri)
params.UserIdentityToken.Password = data
params.UserIdentityToken.EncryptionAlgorithm = uri
Expand Down
Loading