MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / set_security

Method set_security

opcua/client/client.py:194–211  ·  view source on GitHub ↗

Set SecureConnection mode. Call this before connect()

(self, policy, certificate_path, private_key_path,
                     server_certificate_path=None,
                     mode=ua.MessageSecurityMode.SignAndEncrypt)

Source from the content-addressed store, hash-verified

192 parts[4] if len(parts) >= 5 else None, mode)
193
194 def set_security(self, policy, certificate_path, private_key_path,
195 server_certificate_path=None,
196 mode=ua.MessageSecurityMode.SignAndEncrypt):
197 """
198 Set SecureConnection mode.
199 Call this before connect()
200 """
201 if server_certificate_path is None:
202 # load certificate from server's list of endpoints
203 endpoints = self.connect_and_get_server_endpoints()
204 endpoint = Client.find_endpoint(endpoints, mode, policy.URI)
205 server_cert = uacrypto.x509_from_der(endpoint.ServerCertificate)
206 else:
207 server_cert = uacrypto.load_certificate(server_certificate_path)
208 cert = uacrypto.load_certificate(certificate_path)
209 pk = uacrypto.load_private_key(private_key_path)
210 self.security_policy = policy(server_cert, cert, pk, mode)
211 self.uaclient.set_security(self.security_policy)
212
213 def load_client_certificate(self, path):
214 """

Calls 4

find_endpointMethod · 0.80
load_certificateMethod · 0.80
load_private_keyMethod · 0.45