当前位置: 首页>>代码示例>>Python>>正文


Python Server.load_certificate方法代码示例

本文整理汇总了Python中opcua.Server.load_certificate方法的典型用法代码示例。如果您正苦于以下问题:Python Server.load_certificate方法的具体用法?Python Server.load_certificate怎么用?Python Server.load_certificate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opcua.Server的用法示例。


在下文中一共展示了Server.load_certificate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCryptoConnect

# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import load_certificate [as 别名]
class TestCryptoConnect(unittest.TestCase):

    '''
    Test connectino with a server supporting crypto 

    '''
    @classmethod
    def setUpClass(self):
        # start our own server
        self.srv_crypto = Server()
        self.uri_crypto = 'opc.tcp://localhost:%d' % port_num1
        self.srv_crypto.set_endpoint(self.uri_crypto)
        # load server certificate and private key. This enables endpoints
        # with signing and encryption.
        self.srv_crypto.load_certificate("examples/certificate-example.der")
        self.srv_crypto.load_private_key("examples/private-key-example.pem")
        self.srv_crypto.start()

        # start a server without crypto
        self.srv_no_crypto = Server()
        self.uri_no_crypto = 'opc.tcp://localhost:%d' % port_num2
        self.srv_no_crypto.set_endpoint(self.uri_no_crypto)
        self.srv_no_crypto.start()

    @classmethod
    def tearDownClass(self):
        # stop the server 
        self.srv_no_crypto.stop()
        self.srv_crypto.stop()

    def test_nocrypto(self):
        clt = Client(self.uri_no_crypto)
        clt.connect()
        try:
            clt.get_objects_node().get_children()
        finally:
            clt.disconnect()

    def test_nocrypto_feil(self):
        clt = Client(self.uri_no_crypto)
        with self.assertRaises(ua.UaError):
            clt.set_security_string("Basic256,Sign,examples/certificate-example.der,examples/private-key-example.pem")

    def test_basic256(self):
        clt = Client(self.uri_crypto)
        try:
            clt.set_security_string("Basic256,Sign,examples/certificate-example.der,examples/private-key-example.pem")
            clt.connect()
            self.assertTrue(clt.get_objects_node().get_children())
        finally:
            clt.disconnect()

    def test_basic256_encrypt(self):
        clt = Client(self.uri_crypto)
        try:
            clt.set_security_string("Basic256,SignAndEncrypt,examples/certificate-example.der,examples/private-key-example.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/certificate-example.der,examples/private-key-example.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/certificate-example.der,examples/private-key-example.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/certificate-example.der',
                             'examples/private-key-example.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/certificate-example.der',
                             'examples/private-key-example.pem',
#.........这里部分代码省略.........
开发者ID:JonSyuGithub,项目名称:python-opcua,代码行数:103,代码来源:tests_crypto_connect.py

示例2: uaserver

# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import load_certificate [as 别名]
def uaserver():
    parser = argparse.ArgumentParser(description="Run an example OPC-UA server. By importing xml definition and using uawrite command line, it is even possible to expose real data using this server")
    # we setup a server, this is a bit different from other tool so we do not reuse common arguments
    parser.add_argument("-u",
                        "--url",
                        help="URL of OPC UA server, default is opc.tcp://0.0.0.0:4840",
                        default='opc.tcp://0.0.0.0:4840',
                        metavar="URL")
    parser.add_argument("-v",
                        "--verbose",
                        dest="loglevel",
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
                        default='WARNING',
                        help="Set log level")
    parser.add_argument("-x",
                        "--xml",
                        metavar="XML_FILE",
                        help="Populate address space with nodes defined in XML")
    parser.add_argument("-p",
                        "--populate",
                        action="store_true",
                        help="Populate address space with some sample nodes")
    parser.add_argument("-c",
                        "--disable-clock",
                        action="store_true",
                        help="Disable clock, to avoid seeing many write if debugging an application")
    parser.add_argument("-s",
                        "--shell",
                        action="store_true",
                        help="Start python shell instead of randomly changing node values")
    parser.add_argument("--certificate",
                        help="set server certificate")
    parser.add_argument("--private_key",
                        help="set server private key")
    args = parser.parse_args()
    logging.basicConfig(format="%(levelname)s: %(message)s", level=getattr(logging, args.loglevel))

    server = Server()
    server.set_endpoint(args.url)
    if args.certificate:
        server.load_certificate(args.certificate)
    if args.private_key:
        server.load_private_key(args.private_key)
    server.disable_clock(args.disable_clock)
    server.set_server_name("FreeOpcUa Example Server")
    if args.xml:
        server.import_xml(args.xml)
    if args.populate:
        @uamethod
        def multiply(parent, x, y):
            print("multiply method call with parameters: ", x, y)
            return x * y

        uri = "http://examples.freeopcua.github.io"
        idx = server.register_namespace(uri)
        objects = server.get_objects_node()
        myobj = objects.add_object(idx, "MyObject")
        mywritablevar = myobj.add_variable(idx, "MyWritableVariable", 6.7)
        mywritablevar.set_writable()    # Set MyVariable to be writable by clients
        myvar = myobj.add_variable(idx, "MyVariable", 6.7)
        myarrayvar = myobj.add_variable(idx, "MyVarArray", [6.7, 7.9])
        myprop = myobj.add_property(idx, "MyProperty", "I am a property")
        mymethod = myobj.add_method(idx, "MyMethod", multiply, [ua.VariantType.Double, ua.VariantType.Int64], [ua.VariantType.Double])

    server.start()
    try:
        if args.shell:
            embed()
        elif args.populate:
            count = 0
            while True:
                time.sleep(1)
                myvar.set_value(math.sin(count / 10))
                myarrayvar.set_value([math.sin(count / 10), math.sin(count / 100)])
                count += 1
        else:
            while True:
                time.sleep(1)
    finally:
        server.stop()
    sys.exit(0)
开发者ID:sightmachine,项目名称:python-opcua,代码行数:83,代码来源:tools.py

示例3: Server

# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import load_certificate [as 别名]
import time

sys.path.insert(0, "..")

from opcua import ua, Server


if __name__ == "__main__":

    # setup our server
    server = Server()
    server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")

    # load server certificate and private key. This enables endpoints
    # with signing and encryption.
    server.load_certificate("certificate-example.der")
    server.load_private_key("private-key-example.pem")

    # setup our own namespace, not really necessary but should as spec
    uri = "http://examples.freeopcua.github.io"
    idx = server.register_namespace(uri)

    # get Objects node, this is where we should put our custom stuff
    objects = server.get_objects_node()

    # populating our address space
    myobj = objects.add_object(idx, "MyObject")
    myvar = myobj.add_variable(idx, "MyVariable", 6.7)
    myvar.set_writable()    # Set MyVariable to be writable by clients

    # starting!
开发者ID:Johen8,项目名称:python-opcua,代码行数:33,代码来源:server-with-encryption.py

示例4: Server

# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import load_certificate [as 别名]
sys.path.insert(0, "..")
import time


from opcua import ua, Server


if __name__ == "__main__":

    # setup our server
    server = Server()
    server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")

    # load server certificate and private key. This enables endpoints
    # with signing and encryption.
    server.load_certificate("example-certificate.der")
    server.load_private_key("example-private-key.pem")

    # setup our own namespace, not really necessary but should as spec
    uri = "http://examples.freeopcua.github.io"
    idx = server.register_namespace(uri)

    # get Objects node, this is where we should put our custom stuff
    objects = server.get_objects_node()

    # populating our address space
    myobj = objects.add_object(idx, "MyObject")
    myvar = myobj.add_variable(idx, "MyVariable", 6.7)
    myvar.set_writable()    # Set MyVariable to be writable by clients

    # starting!
开发者ID:karmicthreat,项目名称:python-opcua,代码行数:33,代码来源:minimal-server-with-encryption.py

示例5: MyLogger

# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import load_certificate [as 别名]
logger.addHandler(handler)
sys.stdout = MyLogger(logger, logging.INFO)




if __name__ == "__main__":
    #Creamos una instancia del servidor OPC UA
    server = Server()
    # Establecemos la comunicación de nuestro servidor opc ua 
    # load server certificate and private key. This enables endpoints
    #Cargamos el certificado del servidor y la clave privada
    #esto activa la comunicación con firma y cifrado.
    if len(sys.argv) == 2:
        server.set_endpoint("opc.tcp://%s" % sys.argv[1] )
        server.load_certificate("certificate-example.der")
        server.load_private_key("private-key-example.pem")
    elif len(sys.argv) == 3:
        server.set_endpoint("opc.tcp://%s" % sys.argv[1] )
        server.load_certificate("%s/certificate-example.der" % sys.argv[2])
        server.load_private_key("%s/private-key-example.pem" % sys.argv[2])
    else:
        a = len(sys.argv)
        print ("Numero de argumentos inexperado: %s" %a)
        print "opcua_server.py ip:puerto (rutacertificado)"
        sys.exit(1)

    # Declaración del espacio de nombres (no necesario)
    uri = "SERVIDOR OPC-UA - ARDUINO:FreeOpcUa:python-opcua"
    idx = server.register_namespace(uri)
    # Cargamos los objetos 
开发者ID:fabio6,项目名称:freeopcua-ARD-UI,代码行数:33,代码来源:opcua_server.py


注:本文中的opcua.Server.load_certificate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。