tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_service.bash
branchwxPython4
changeset 3676 2f79540660f6
parent 3672 230c8b90f3dc
child 3718 7841b651d601
equal deleted inserted replaced
3675:d331eb981b44 3676:2f79540660f6
       
     1 #!/bin/bash
       
     2 
       
     3 echo "Instant encrypted OPC-UA server for test"
       
     4 
       
     5 yes "" | openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem \
       
     6         -days 355 -nodes -addext "subjectAltName = URI:urn:example.org:FreeOpcUa:python-opcua"
       
     7 openssl x509 -outform der -in my_cert.pem -out my_cert.der
       
     8 
       
     9 PROJECT_FILES_DIR=$BEREMIZPATH/tests/projects/opcua_browse_encrypted/project_files
       
    10 mkdir $PROJECT_FILES_DIR
       
    11 cp my_cert.der my_private_key.pem $PROJECT_FILES_DIR
       
    12 
       
    13 echo "CERTS READY"
       
    14 
       
    15 # Run server
       
    16 exec $BEREMIZPYTHONPATH - << EOF
       
    17 
       
    18 import sys
       
    19 import time
       
    20 
       
    21 from opcua import ua, Server
       
    22 
       
    23 server = Server()
       
    24 server.set_endpoint("opc.tcp://127.0.0.1:4840/freeopcua/server/")
       
    25 
       
    26 server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt])
       
    27 server.load_certificate("my_cert.der")
       
    28 server.load_private_key("my_private_key.pem")
       
    29 
       
    30 uri = "http://beremiz.github.io"
       
    31 idx = server.register_namespace(uri)
       
    32 
       
    33 objects = server.get_objects_node()
       
    34 
       
    35 testobj = objects.add_object(idx, "TestObject")
       
    36 testvarout = testobj.add_variable(idx, "TestOut", 1.2)
       
    37 testvar = testobj.add_variable(idx, "TestIn", 5.6)
       
    38 testvar.set_writable()
       
    39 
       
    40 server.start()
       
    41 
       
    42 try:
       
    43     while True:
       
    44         time.sleep(1)
       
    45         inval=testvar.get_value()
       
    46         print inval
       
    47         testvarout.set_value(inval*2)
       
    48         sys.stdout.flush()
       
    49 finally:
       
    50     server.stop()
       
    51 EOF