18 lines
764 B
Python
18 lines
764 B
Python
from asyncua.crypto.security_policies import SecurityPolicyBasic256Sha256
|
|
|
|
SESSION_TIMEOUT_MS = 600_000 # 10 min; tune per server (Samarco: long sessions degrade)
|
|
|
|
|
|
async def apply_security(client, server_uri, cert_path, private_key_path, server_cert_path):
|
|
"""Apply Basic256Sha256 + certificate auth (1879 §1) and set channel > session
|
|
lifetime (1879 §3: secure_channel_timeout = session_timeout * 1.25)."""
|
|
client.application_uri = server_uri
|
|
await client.set_security(
|
|
SecurityPolicyBasic256Sha256,
|
|
certificate=cert_path,
|
|
private_key=private_key_path,
|
|
server_certificate=server_cert_path,
|
|
)
|
|
client.session_timeout = SESSION_TIMEOUT_MS
|
|
client.secure_channel_timeout = int(SESSION_TIMEOUT_MS * 1.25)
|