edouard@3543: #!/bin/bash edouard@3543: edouard@3676: echo "Instant encrypted OPC-UA server for test" edouard@3676: edouard@3676: yes "" | openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem \ edouard@3676: -days 355 -nodes -addext "subjectAltName = URI:urn:example.org:FreeOpcUa:python-opcua" edouard@3676: openssl x509 -outform der -in my_cert.pem -out my_cert.der edouard@3676: edouard@3676: PROJECT_FILES_DIR=$BEREMIZPATH/tests/projects/opcua_browse_encrypted/project_files edouard@3676: mkdir $PROJECT_FILES_DIR edouard@3676: cp my_cert.der my_private_key.pem $PROJECT_FILES_DIR edouard@3676: edouard@3676: echo "CERTS READY" edouard@3543: edouard@3549: # Run server edouard@3672: exec $BEREMIZPYTHONPATH - << EOF edouard@3543: edouard@3549: import sys edouard@3549: import time edouard@3549: edouard@3549: from opcua import ua, Server edouard@3549: edouard@3549: server = Server() edouard@3549: server.set_endpoint("opc.tcp://127.0.0.1:4840/freeopcua/server/") edouard@3549: edouard@3676: server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt]) edouard@3676: server.load_certificate("my_cert.der") edouard@3676: server.load_private_key("my_private_key.pem") edouard@3676: edouard@3549: uri = "http://beremiz.github.io" edouard@3549: idx = server.register_namespace(uri) edouard@3549: edouard@3549: objects = server.get_objects_node() edouard@3549: edouard@3549: testobj = objects.add_object(idx, "TestObject") edouard@3549: testvarout = testobj.add_variable(idx, "TestOut", 1.2) edouard@3549: testvar = testobj.add_variable(idx, "TestIn", 5.6) edouard@3549: testvar.set_writable() edouard@3549: edouard@3549: server.start() edouard@3549: edouard@3549: try: edouard@3549: while True: edouard@3549: time.sleep(1) edouard@3672: inval=testvar.get_value() edouard@3672: print inval edouard@3672: testvarout.set_value(inval*2) edouard@3549: sys.stdout.flush() edouard@3549: finally: edouard@3549: server.stop() edouard@3549: EOF