Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Obtaining a list of all valid SecurityModes
June 13, 2022
18:35, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

Hi there,

for validation purposes and also for providing the user with a drop down of all security modes to select from, I need to enumerate all possible securityModes, aka combinations of SecurityPolicies and MessageSecurityModes.
I tried 2 different approaches (code snippets are in Kotlin, but should be understandable by Java users as well):

val securityPolicies = SecurityPolicy.values()
val messageSecurityModes = MessageSecurityMode.values()

variant #1:

SecurityMode.combinations(messageSecurityModes.toSet(), securityPolicies.toSet())

resulting in:
[http://opcfoundation.org/UA/SecurityPolicy#Basic256,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#None,None]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss,SignAndEncrypt]

and variant 2#

securityPolicies.flatMap { policy -> messageSecurityModes.map { mode -> SecurityMode(policy, mode)}}

resulting in

[http://opcfoundation.org/UA/SecurityPolicy#None,None]
[http://opcfoundation.org/UA/SecurityPolicy#None,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#None,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15,None]
[http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256,None]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,None]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep,None]
[http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep,SignAndEncrypt]
[http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss,None]
[http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss,Sign]
[http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss,SignAndEncrypt]

Obviously, not all results of the second variant make sense. Should the constructor

SecurityMode(policy, mode)

not throw an InvalidArgumentException (or similar) for any invalid combination of MessageSecurityMode and SecurityPolicy?

Thanks,
Hans-Uwe

June 14, 2022
9:52, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

As mentioned in the documentation of the SecurityMode(SecurityPolicy securityPolicy, MessageSecurityMode messageSecurityMode) constructor: “Note! it is recommended to use the existing constants or the combinations(Set modes, Set policies) methods using the constants of the given classes instead of calling this directly.”

It’s true that the method could verify that the entered combination makes sense, but in general using this method shouldn’t be necessary as combinations method provides a set of valid SecurityModes and the static constant SecurityModes can be used instead of constructing new ones.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
27 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

TimK: 41

Member Stats:

Guest Posters: 0

Members: 682

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

karrimacvitie5, graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1