Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
4498a5ca
Commit
4498a5ca
authored
Feb 20, 2016
by
ORD
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #138 from alkor/fix-password-encryption
Support passwords with SecurityPolicy#None (plain text)
parents
be502ffb
bdc8c205
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
opcua/client/client.py
opcua/client/client.py
+11
-2
opcua/crypto/security_policies.py
opcua/crypto/security_policies.py
+5
-0
No files found.
opcua/client/client.py
View file @
4498a5ca
...
...
@@ -381,14 +381,23 @@ class Client(object):
else
:
params
.
UserIdentityToken
=
ua
.
UserNameIdentityToken
()
params
.
UserIdentityToken
.
UserName
=
username
if
self
.
server_url
.
password
:
policy_uri
=
self
.
server_policy_uri
(
ua
.
UserTokenType
.
UserName
)
if
not
policy_uri
or
policy_uri
==
security_policies
.
POLICY_NONE_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
.
server_url
.
password
:
self
.
logger
.
warning
(
"Sending plain-text password"
)
params
.
UserIdentityToken
.
Password
=
password
params
.
UserIdentityToken
.
EncryptionAlgorithm
=
''
elif
self
.
server_url
.
password
:
pubkey
=
uacrypto
.
x509_from_der
(
self
.
security_policy
.
server_certificate
).
public_key
()
# see specs part 4, 7.36.3: if the token is encrypted, password
# shall be converted to UTF-8 and serialized with server nonce
etoken
=
ua
.
pack_bytes
(
bytes
(
password
,
"utf8"
)
+
self
.
_server_nonce
)
(
data
,
uri
)
=
security_policies
.
encrypt_asymmetric
(
pubkey
,
etoken
,
self
.
server_policy_uri
(
ua
.
UserTokenType
.
UserName
)
)
policy_uri
)
params
.
UserIdentityToken
.
Password
=
data
params
.
UserIdentityToken
.
EncryptionAlgorithm
=
uri
params
.
UserIdentityToken
.
PolicyId
=
self
.
server_policy_id
(
ua
.
UserTokenType
.
UserName
,
b"username_basic256"
)
...
...
opcua/crypto/security_policies.py
View file @
4498a5ca
...
...
@@ -9,6 +9,9 @@ except ImportError:
CRYPTOGRAPHY_AVAILABLE
=
False
POLICY_NONE_URI
=
'http://opcfoundation.org/UA/SecurityPolicy#None'
def
require_cryptography
(
obj
):
"""
Raise exception if cryptography module is not available.
...
...
@@ -448,4 +451,6 @@ def encrypt_asymmetric(pubkey, data, policy_uri):
if
policy_uri
==
cls
.
URI
:
return
(
cls
.
encrypt_asymmetric
(
pubkey
,
data
),
cls
.
AsymmetricEncryptionURI
)
if
not
policy_uri
or
policy_uri
==
POLICY_NONE_URI
:
return
(
data
,
''
)
raise
UaError
(
"Unsupported security policy `{}`"
.
format
(
policy_uri
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment