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
f182d979
Commit
f182d979
authored
Feb 18, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one more test for crypto
parent
7dfc174c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
2 deletions
+64
-2
opcua/client/client.py
opcua/client/client.py
+9
-2
tests/tests_crypto_connect.py
tests/tests_crypto_connect.py
+55
-0
No files found.
opcua/client/client.py
View file @
f182d979
...
@@ -125,8 +125,7 @@ class Client(object):
...
@@ -125,8 +125,7 @@ class Client(object):
return
return
parts
=
string
.
split
(
','
)
parts
=
string
.
split
(
','
)
if
len
(
parts
)
<
4
:
if
len
(
parts
)
<
4
:
raise
ua
.
UaError
(
'Wrong format: `{}`, expected at least 4 '
raise
ua
.
UaError
(
'Wrong format: `{}`, expected at least 4 comma-separated values'
.
format
(
string
))
'comma-separated values'
.
format
(
string
))
policy_class
=
getattr
(
security_policies
,
'SecurityPolicy'
+
parts
[
0
])
policy_class
=
getattr
(
security_policies
,
'SecurityPolicy'
+
parts
[
0
])
mode
=
getattr
(
ua
.
MessageSecurityMode
,
parts
[
1
])
mode
=
getattr
(
ua
.
MessageSecurityMode
,
parts
[
1
])
return
self
.
set_security
(
policy_class
,
parts
[
2
],
parts
[
3
],
return
self
.
set_security
(
policy_class
,
parts
[
2
],
parts
[
3
],
...
@@ -158,6 +157,9 @@ class Client(object):
...
@@ -158,6 +157,9 @@ class Client(object):
self
.
user_certificate
=
uacrypto
.
load_certificate
(
path
)
self
.
user_certificate
=
uacrypto
.
load_certificate
(
path
)
def
load_private_key
(
self
,
path
):
def
load_private_key
(
self
,
path
):
"""
Load user private key. This is used for authenticating using certificate
"""
self
.
user_private_key
=
uacrypto
.
load_private_key
(
path
)
self
.
user_private_key
=
uacrypto
.
load_private_key
(
path
)
def
connect_and_get_server_endpoints
(
self
):
def
connect_and_get_server_endpoints
(
self
):
...
@@ -295,6 +297,11 @@ class Client(object):
...
@@ -295,6 +297,11 @@ class Client(object):
return
self
.
uaclient
.
find_servers_on_network
(
params
)
return
self
.
uaclient
.
find_servers_on_network
(
params
)
def
create_session
(
self
):
def
create_session
(
self
):
"""
send a CreateSessionRequest to server with reasonable parameters.
If you want o modify settings look at code of this methods
and make your own
"""
desc
=
ua
.
ApplicationDescription
()
desc
=
ua
.
ApplicationDescription
()
desc
.
ApplicationUri
=
self
.
application_uri
desc
.
ApplicationUri
=
self
.
application_uri
desc
.
ProductUri
=
self
.
product_uri
desc
.
ProductUri
=
self
.
product_uri
...
...
tests/tests_crypto_connect.py
View file @
f182d979
...
@@ -3,6 +3,7 @@ import unittest
...
@@ -3,6 +3,7 @@ import unittest
from
opcua
import
Client
from
opcua
import
Client
from
opcua
import
Server
from
opcua
import
Server
from
opcua
import
ua
from
opcua
import
ua
from
opcua.crypto
import
security_policies
port_num1
=
48515
port_num1
=
48515
port_num2
=
48512
port_num2
=
48512
...
@@ -60,5 +61,59 @@ class TestCryptoConnect(unittest.TestCase):
...
@@ -60,5 +61,59 @@ class TestCryptoConnect(unittest.TestCase):
finally
:
finally
:
clt
.
disconnect
()
clt
.
disconnect
()
def
test_basic256_encrypt
(
self
):
clt
=
Client
(
self
.
uri_crypto
)
try
:
clt
.
set_security_string
(
"Basic256,SignAndEncrypt,examples/example-certificate.der,examples/example-private-key.pem"
)
clt
.
connect
()
self
.
assertTrue
(
clt
.
get_objects_node
().
get_children
())
finally
:
clt
.
disconnect
()
def
test_basic128Rsa15
(
self
):
clt
=
Client
(
self
.
uri_crypto
)
try
:
clt
.
set_security_string
(
"Basic128Rsa15,Sign,examples/example-certificate.der,examples/example-private-key.pem"
)
clt
.
connect
()
self
.
assertTrue
(
clt
.
get_objects_node
().
get_children
())
finally
:
clt
.
disconnect
()
def
test_basic128Rsa15_encrypt
(
self
):
clt
=
Client
(
self
.
uri_crypto
)
try
:
clt
.
set_security_string
(
"Basic128Rsa15,SignAndEncrypt,examples/example-certificate.der,examples/example-private-key.pem"
)
clt
.
connect
()
self
.
assertTrue
(
clt
.
get_objects_node
().
get_children
())
finally
:
clt
.
disconnect
()
def
test_basic256_encrypt_success
(
self
):
clt
=
Client
(
self
.
uri_crypto
)
try
:
clt
.
set_security
(
security_policies
.
SecurityPolicyBasic256
,
'examples/example-certificate.der'
,
'examples/example-private-key.pem'
,
None
,
ua
.
MessageSecurityMode
.
SignAndEncrypt
)
clt
.
connect
()
self
.
assertTrue
(
clt
.
get_objects_node
().
get_children
())
finally
:
clt
.
disconnect
()
def
test_basic256_encrypt_feil
(
self
):
# FIXME: how to make it feil???
clt
=
Client
(
self
.
uri_crypto
)
with
self
.
assertRaises
(
ua
.
UaError
):
clt
.
set_security
(
security_policies
.
SecurityPolicyBasic256
,
'examples/example-certificate.der'
,
'examples/example-private-key.pem'
,
None
,
ua
.
MessageSecurityMode
.
None_
)
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