Created
January 22, 2020 18:12
-
-
Save ZuZuD/dd64116a885fb0260573dc90b51c9cb9 to your computer and use it in GitHub Desktop.
Testing opcua Client.Signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==== Server ==== | |
In [1]: from opcua import ua, server | |
...: | |
...: s = server.server.Server() | |
...: s.load_certificate("/etc/pki/tls/certs/mycert.pem") | |
...: s.load_private_key("/etc/pki/tls/certs/mykey.key.der") | |
...: | |
...: # allow Basic256Sha256_SignAndEncrypt | |
...: # s.get_endpoint() would return only that security policy | |
...: # and clients are restricted to it. | |
...: s.set_security_policy([ | |
...: ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt, | |
...: ]) | |
...: | |
...: # get Objects node, this is where we should put our custom stuff | |
...: objects = s.get_objects_node() | |
...: print("I got objects folder: ", objects) | |
...: | |
...: # now adding some object to our addresse space | |
...: idx = s.register_namespace(uri) | |
...: myobject = objects.add_object(idx, "NewObject") | |
...: myvar = myobject.add_variable(idx, "MyVariable", [16, 56]) | |
...: myprop = myobject.add_property(idx, "myprop", 9.9) | |
...: myfolder = myobject.add_folder(idx, "myfolder") | |
...: s.start() | |
I got objects folder: Node(TwoByteNodeId(i=85)) | |
Listening on 0.0.0.0:4840 | |
In [2]: | |
Creating SecurityPolicy: <class 'opcua.crypto.security_policies.SecurityPolicyBasic256Sha256'> 3 <Certificate(subject=<Name(CN=mycert)>, ...)> | |
Creating SecurityPolicy: <class 'opcua.crypto.security_policies.SecurityPolicyBasic256Sha256'> 3 <Certificate(subject=<Name(CN=mycert)>, ...)> | |
Creating SecurityPolicy: <class 'opcua.crypto.security_policies.SecurityPolicyBasic256Sha256'> 3 <Certificate(subject=<Name(CN=mycert)>, ...)> | |
Creating SecurityPolicy: <class 'opcua.crypto.security_policies.SecurityPolicyBasic256Sha256'> 3 <Certificate(subject=<Name(CN=mycert)>, ...)> | |
==== Client ===== | |
In [1]: from opcua import ua | |
...: from opcua import client | |
...: | |
...: c = client.client.Client(url="opc.tcp://0.0.0.0:4840/freeopcua/server/") | |
...: c.set_security_string("Basic256Sha256,SignAndEncrypt,/etc/pki/tls/certs/mycert.pem,/etc/pk | |
...: i/tls/certs/mykey.key.der") | |
...: | |
...: c.connect() | |
...: | |
...: # create a subcription and sub to a node created previously | |
...: sub = c.create_subscription(1000,1) | |
...: sub.subscribe_data_change(c.get_node("ns=2;i=3")) | |
Sending publish message | |
Sending publish message | |
Out[1]: 112 | |
DataChange subscription created but handler has no datachange_notification method | |
Sending publish message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment