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

WIP: Client verification #620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
257 changes: 257 additions & 0 deletions examples/XMLSchemas/xml_opc_schema_test1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
<?xml version='1.0' encoding='utf-8'?>
<UANodeSet xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamespaceUris>
<Uri />
<Uri>iab_namespace</Uri>
</NamespaceUris>
<Aliases>
<Alias Alias="Float">i=10</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasProperty">i=46</Alias>
<Alias Alias="HasComponent">i=47</Alias>
</Aliases>
<UAObject BrowseName="2:iab" NodeId="ns=2;i=1" ParentNodeId="i=85">
<DisplayName>iab</DisplayName>
<Description>The base type for all object nodes.</Description>
<References>
<Reference IsForward="false" ReferenceType="Organizes">i=85</Reference>
<Reference ReferenceType="HasTypeDefinition">i=58</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=2</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=3</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=4</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=5</Reference>
</References>
</UAObject>
<UAObject BrowseName="2:Analytics" NodeId="ns=2;i=2" ParentNodeId="ns=2;i=1">
<DisplayName>Analytics</DisplayName>
<Description>The base type for all object nodes.</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=1</Reference>
<Reference ReferenceType="HasTypeDefinition">i=58</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=6</Reference>
</References>
</UAObject>
<UAObject BrowseName="2:cRIO" NodeId="ns=2;i=3" ParentNodeId="ns=2;i=1">
<DisplayName>cRIO</DisplayName>
<Description>The base type for all object nodes.</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=1</Reference>
<Reference ReferenceType="HasTypeDefinition">i=58</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=10</Reference>
</References>
</UAObject>
<UAObject BrowseName="2:Twin" NodeId="ns=2;i=4" ParentNodeId="ns=2;i=1">
<DisplayName>Twin</DisplayName>
<Description>The base type for all object nodes.</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=1</Reference>
<Reference ReferenceType="HasTypeDefinition">i=58</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=19</Reference>
</References>
</UAObject>
<UAObject BrowseName="2:Customer" NodeId="ns=2;i=5" ParentNodeId="ns=2;i=1">
<DisplayName>Customer</DisplayName>
<Description>The base type for all object nodes.</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=1</Reference>
<Reference ReferenceType="HasTypeDefinition">i=58</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=20</Reference>
</References>
</UAObject>
<UAObject BrowseName="2:Measurement_stats" NodeId="ns=2;i=6" ParentNodeId="ns=2;i=2">
<DisplayName>Measurement_stats</DisplayName>
<Description>Measurement_stats</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=2</Reference>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=7</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=21</Reference>
</References>
</UAObject>
<UAVariable AccessLevel="15" BrowseName="2:temp_mean" DataType="Float" NodeId="ns=2;i=7" ParentNodeId="ns=2;i=6" UserAccessLevel="15">
<DisplayName>temp_mean</DisplayName>
<Description>temp_mean</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=6</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=8</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=9</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:aproperty_float" DataType="Float" NodeId="ns=2;i=8" ParentNodeId="ns=2;i=7">
<DisplayName>aproperty_float</DisplayName>
<Description>aproperty_float</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=7</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:aproperty_string" DataType="String" NodeId="ns=2;i=9" ParentNodeId="ns=2;i=7">
<DisplayName>aproperty_string</DisplayName>
<Description>aproperty_string</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=7</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:String>9.99</uax:String>
</Value>
</UAVariable>
<UAObject BrowseName="2:measurements" NodeId="ns=2;i=10" ParentNodeId="ns=2;i=3">
<DisplayName>measurements</DisplayName>
<Description>measurements</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=3</Reference>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=12</Reference>
<Reference ReferenceType="HasComponent">ns=2;i=15</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=18</Reference>
<Reference ReferenceType="HasComponent">ns=2;s=testvariable</Reference>
<Reference ReferenceType="HasComponent">ns=2;s=anothertest</Reference>
</References>
</UAObject>
<UAVariable AccessLevel="15" BrowseName="2:temperature" DataType="Float" Historizing="True" NodeId="ns=2;i=12" ParentNodeId="ns=2;i=10" UserAccessLevel="15">
<DisplayName>temperature</DisplayName>
<Description>temperature</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=10</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=13</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=14</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:range" DataType="Float" NodeId="ns=2;i=13" ParentNodeId="ns=2;i=12">
<DisplayName>range</DisplayName>
<Description>range</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=12</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:accuracy" DataType="Float" NodeId="ns=2;i=14" ParentNodeId="ns=2;i=12">
<DisplayName>accuracy</DisplayName>
<Description>accuracy</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=12</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable AccessLevel="15" BrowseName="2:vibration" DataType="Float" Historizing="True" NodeId="ns=2;i=15" ParentNodeId="ns=2;i=10" UserAccessLevel="15">
<DisplayName>vibration</DisplayName>
<Description>vibration</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=10</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=16</Reference>
<Reference ReferenceType="HasProperty">ns=2;i=17</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:range" DataType="Float" NodeId="ns=2;i=16" ParentNodeId="ns=2;i=15">
<DisplayName>range</DisplayName>
<Description>range</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=15</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:accuracy" DataType="Float" NodeId="ns=2;i=17" ParentNodeId="ns=2;i=15">
<DisplayName>accuracy</DisplayName>
<Description>accuracy</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=15</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:timestep" DataType="Float" NodeId="ns=2;i=18" ParentNodeId="ns=2;i=10">
<DisplayName>timestep</DisplayName>
<Description>timestep</Description>
<References>
<Reference IsForward="false" ReferenceType="HasProperty">ns=2;i=10</Reference>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:testvariable" DataType="Float" NodeId="ns=2;i=19" ParentNodeId="ns=2;i=4">
<DisplayName>testvariable</DisplayName>
<Description>testvariable</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=4</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:testvariable" DataType="Float" NodeId="ns=2;i=20" ParentNodeId="ns=2;i=5">
<DisplayName>testvariable</DisplayName>
<Description>testvariable</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=5</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable AccessLevel="15" BrowseName="2:vibration_something" DataType="Float" NodeId="ns=2;i=21" ParentNodeId="ns=2;i=6" UserAccessLevel="15">
<DisplayName>vibration_something</DisplayName>
<Description>vibration_something</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=6</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:testvariable" DataType="Float" Historizing="True" NodeId="ns=2;s=testvariable" ParentNodeId="ns=2;i=10">
<DisplayName>testvariable</DisplayName>
<Description>testvariable</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=10</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
<UAVariable BrowseName="2:anothertest" DataType="Float" NodeId="ns=2;s=anothertest" ParentNodeId="ns=2;i=10" UserAccessLevel="15">
<DisplayName>anothertest</DisplayName>
<Description>anothertest</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">ns=2;i=10</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Float>9.99</uax:Float>
</Value>
</UAVariable>
</UANodeSet>
15 changes: 15 additions & 0 deletions examples/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN CERTIFICATE-----
MIICWzCCAcSgAwIBAgIJAI2vU+xObjKcMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQwHhcNMTgwNDEwMTIzNzQ5WhcNMTkwNDEwMTIzNzQ5WjBF
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
gQDWxSvyTgs3Dc0wcOk2TwTvozP49fCsV8RfMjuDl4wRJSFWNteH50bBmhUUXhWO
5kFHwjCt0wBujjUfqg3vE3JY0+pa70X2iGXZ0Tk3/XSPUVE/cPa7DQleCTIhR5Di
Mo5leg3O339c0BdskYsV6UvZVv3wO2j/8yhE+CfTkkKAgwIDAQABo1MwUTAdBgNV
HQ4EFgQUqJSdMz0aYGfU5ySIBy2GA433BBMwHwYDVR0jBBgwFoAUqJSdMz0aYGfU
5ySIBy2GA433BBMwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQBp
UU0+r7uisgdTgLEaEMU3acsgbd+VVULHJnvju3QVbPotRuhvjZsTiq934aYv9To0
7V4ydPhi13sRu1tR89GX7u45Z0+uPBZI+yCLxxvCOBrA5THpM9yc2owhAbaIF/br
tVKSYH/9WtFCxMjAXrCGzN7HJnRLmR8Gumkq1t/X3w==
-----END CERTIFICATE-----
36 changes: 36 additions & 0 deletions examples/client_encrypt_malicious.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from opcua import Client
from opcua import ua
import time
import random
import logging
logging.basicConfig(level=logging.DEBUG)

if __name__ == '__main__':
client = Client("opc.tcp://localhost:4841/freeopcua/server/")

## one can set different sets of key/cert for testing

#client.load_private_key('key.pem')
#client.load_client_certificate('cert.pem')
client.load_private_key('private-key-example.pem')
client.load_client_certificate('certificate-example.der')

client.set_security_string("Basic256,SignAndEncrypt,cert.pem,key.pem")
#client.set_security_string("Basic256,SignAndEncrypt,certificate-example.der,private-key-example.pem")

## this doesn't work because this cert.key pair is used for encryption of data
#client.set_security_string("Basic256,SignAndEncrypt,cert.pem,private-key-example.pem")

time.sleep(5)

client.connect()
print("connectedddd")

var_temp = client.get_node("ns=2;i=12")
var_vibration = client.get_node("ns=2;i=15")

while True:
var_temp.get_value()
time.sleep(10)


16 changes: 16 additions & 0 deletions examples/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANbFK/JOCzcNzTBw
6TZPBO+jM/j18KxXxF8yO4OXjBElIVY214fnRsGaFRReFY7mQUfCMK3TAG6ONR+q
De8TcljT6lrvRfaIZdnROTf9dI9RUT9w9rsNCV4JMiFHkOIyjmV6Dc7ff1zQF2yR
ixXpS9lW/fA7aP/zKET4J9OSQoCDAgMBAAECgYEAiTEaiYXhFCH02OTHlLGVbZ7L
LFWuj+jgwA7OhZjhGHKngPM3atEKGdHbdU9EZiwftz8M6XzH4ddlh/yROg8qEvh5
XC6fSr5sCHiwXs3Q22RtHbY1iGoB6oxe2q4U/ds7nGEOYaDKhFb+PjthjTwWSIho
7DoQ+dKRRujyF5afGQECQQDrcUoYh4PIuh/PnwxxqB5OGmnHs9Aek1nUAqZt9l30
Z00L+IDqP0+oFtfJ6k/lcHB2NxkbsOKVN4fydKlwEnNTAkEA6YXONaDLTvdELWF5
fLu0DMyqGg1CsoT1TCtgWpvDsOkqKNgWu2aqxK2hGQhiCVCLqxosFIiW3QQzGjD7
/1DIEQJASLg7HIxupcbnIGeNnmVAxvrdhTMCqw70Bcmzwe8AYgauA26D0tYvMkmr
6M+YUdOCyOCHvsfJlDEMqlRiKR1pxQJBALdgo7XpNr4j3h3k1YnlvFXwwgMDNsUJ
M7dEuL1uZBWgg8LfLbqrvJ4F2uPVeWbnIUaTntnhCNc2XQrMPJcZ0IECQH88VqZU
azRaGQ1jy3HjmiuriFFDcw01vEsI+VIZMTnShixYxWm7n9w9tITyhIPAdt+Kc/4s
dx8pcP9Gst8ldlI=
-----END PRIVATE KEY-----
Loading