Skip to content

Conversation

@einarmo
Copy link
Contributor

@einarmo einarmo commented Jan 9, 2026

Currently, we rely on the SecurityPolicy enum to decide on choice of algorithms, keys, etc. for OPC-UA encryption. This breaks down if we want to support elliptic curve cryptography, because the key types will be different.

In order to make this possible, what we'll likely want is some kind of SecureChannelState<T: SecurityPolicy>, where key types are associated types on SecurityPolicy. This takes the first steps towards that, by refactor existing security policies to all implement a new trait SecurityPolicyImpl, which exposes a bunch of different methods we need.

To avoid excessive boilerplate, I also refactor a lot of the existing AES code to use traits for different types of encryption. IMO the result is pretty neat, with each policy just denoting a few core properties and four different algorithms for asymmetric and symmetric encryption and padding.

This is very unlikely to be final, since there are still places where the AES-specific key types leak, but the PR is already large enough, and is nicely self contained.

There are technically some breaking changes here, since I remove some public exports, but for normal users this shouldn't be noticable at all.

This is obviously a scary change, but thankfully it is fundamental enough that if I managed to mess up any of the numbers or types, the tests against the .NET server would certainly break.

In other fun news, I also spent an increasingly frustrating afternoon trying to figure out where I'd messed up before realizing that my problem was that newer versions of OpenSSL actively disables SHA1 unless you set a special environment variable, producing a weird and opaque error message if you try to use it anyway. Since the .NET server uses OpenSSL, I set that in the main function of our external server tests.

Currently, we rely on the `SecurityPolicy` enum to decide on choice of
algorithms, keys, etc. for OPC-UA encryption. This breaks down if we
want to support elliptic curve cryptography, because the key _types_
will be different.

In order to make this possible, what we'll likely want is some kind of
`SecureChannelState<T: SecurityPolicy>`, where key types are associated
types on `SecurityPolicy`. This takes the first steps towards that, by
refactor existing security policies to all implement a new trait
`SecurityPolicyImpl`, which exposes a bunch of different methods we
need.

To avoid excessive boilerplate, I also refactor a lot of the existing
AES code to use traits for different types of encryption. IMO the result
is pretty neat, with each policy just denoting a few core properties and
four different algorithms for asymmetric and symmetric encryption and
padding.

This is very unlikely to be final, since there are still places where
the AES-specific key types leak, but the PR is already large enough, and
is nicely self contained.

There are technically some breaking changes here, since I remove some
public exports, but for normal users this shouldn't be noticable at all.

This is obviously a scary change, but thankfully it is fundamental
enough that if I managed to mess up any of the numbers or types, the
tests against the .NET server would certainly break.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants