41 authParams = { |
41 authParams = { |
42 "x509":[ |
42 "x509":[ |
43 ("Certificate", "certificate.der"), |
43 ("Certificate", "certificate.der"), |
44 ("PrivateKey", "private_key.pem"), |
44 ("PrivateKey", "private_key.pem"), |
45 ("Policy", "Basic256Sha256"), |
45 ("Policy", "Basic256Sha256"), |
46 ("Mode", "SignAndEncrypt")], |
46 ("Mode", "SignAndEncrypt"), |
|
47 ("ApplicationUri", "")], |
47 "UserPassword":[ |
48 "UserPassword":[ |
48 ("User", None), |
49 ("User", None), |
49 ("Password", None)]} |
50 ("Password", None)]} |
50 |
51 |
51 class OPCUASubListModel(dv.DataViewIndexListModel): |
52 class OPCUASubListModel(dv.DataViewIndexListModel): |
316 self.client.set_user(config["User"]) |
317 self.client.set_user(config["User"]) |
317 self.client.set_password(config["Password"]) |
318 self.client.set_password(config["Password"]) |
318 elif AuthType=="x509": |
319 elif AuthType=="x509": |
319 self.client.set_security_string( |
320 self.client.set_security_string( |
320 "{Policy},{Mode},{Certificate},{PrivateKey}".format(**config)) |
321 "{Policy},{Mode},{Certificate},{PrivateKey}".format(**config)) |
|
322 self.client.application_uri = config["ApplicationUri"] |
321 |
323 |
322 self.client.connect() |
324 self.client.connect() |
323 self.client.load_type_definitions() # load definition of server specific structures/extension objects |
325 self.client.load_type_definitions() # load definition of server specific structures/extension objects |
324 rootnode = self.client.get_root_node() |
326 rootnode = self.client.get_root_node() |
325 |
327 |
570 LogInfo("OPC-UA Init no auth"); \\ |
572 LogInfo("OPC-UA Init no auth"); \\ |
571 UA_ClientConfig_setDefault(cc); \\ |
573 UA_ClientConfig_setDefault(cc); \\ |
572 retval = UA_Client_connect(client, uri); |
574 retval = UA_Client_connect(client, uri); |
573 |
575 |
574 /* Note : Policy is ignored here since open62541 client supports all policies by default */ |
576 /* Note : Policy is ignored here since open62541 client supports all policies by default */ |
575 #define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate) \\ |
577 #define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate, ApplicationUri) \\ |
576 LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \\ |
578 LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \\ |
577 \\ |
579 \\ |
578 UA_ByteString certificate = loadFile(Certificate); \\ |
580 UA_ByteString certificate = loadFile(Certificate); \\ |
579 UA_ByteString privateKey = loadFile(PrivateKey); \\ |
581 UA_ByteString privateKey = loadFile(PrivateKey); \\ |
580 \\ |
582 \\ |
581 cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode; \\ |
583 cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode; \\ |
|
584 UA_String_clear(&cc->clientDescription.applicationUri); \\ |
|
585 cc->clientDescription.applicationUri = UA_STRING_ALLOC(ApplicationUri); \\ |
582 UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); \\ |
586 UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); \\ |
583 \\ |
587 \\ |
584 retval = UA_Client_connect(client, uri); \\ |
588 retval = UA_Client_connect(client, uri); \\ |
585 \\ |
589 \\ |
586 UA_ByteString_clear(&certificate); \\ |
590 UA_ByteString_clear(&certificate); \\ |
650 ) |
654 ) |
651 |
655 |
652 AuthType = config["AuthType"] |
656 AuthType = config["AuthType"] |
653 if AuthType == "x509": |
657 if AuthType == "x509": |
654 config["UpperCaseMode"] = config["Mode"].upper() |
658 config["UpperCaseMode"] = config["Mode"].upper() |
|
659 if not config["ApplicationUri"]: |
|
660 config["ApplicationUri"] = config["URI"] |
655 formatdict["init"] += """ |
661 formatdict["init"] += """ |
656 INIT_x509({Policy}, {UpperCaseMode}, "{PrivateKey}", "{Certificate}")""".format(**config) |
662 INIT_x509({Policy}, {UpperCaseMode}, "{PrivateKey}", "{Certificate}", "{ApplicationUri}")""".format(**config) |
657 elif AuthType == "UserPassword": |
663 elif AuthType == "UserPassword": |
658 formatdict["init"] += """ |
664 formatdict["init"] += """ |
659 INIT_UserPassword("{User}", "{Password}")""".format(**config) |
665 INIT_UserPassword("{User}", "{Password}")""".format(**config) |
660 else: |
666 else: |
661 formatdict["init"] += """ |
667 formatdict["init"] += """ |