-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not authenticate using SecurityPolicy Basic256 #13
Comments
Security for session activation (secrets exchange) was fixed to Basic128Rsa15 according to the spec when implemented ~2015, but I'll take a look and see what the current behaviour is now. |
The latest OPC Foundation reference server doesn't seem to expose Basic256 as a security policy for its endpoint. I've tested an older version which did and it works. Although the latest OPC Foundation policy may have changed, the previous behaviour was for any security policy other than None, Basic128Rsa15 is used to exchange the secret key used for further encryption according to the selected policy. Could you please share the client code that you are using until the line that fails, and a zipped version of source for the UA server so I can investigate the point at which it rejects the request? |
For reference, to connect as Basic256:
The following code allows me to connect:
|
For the server I just take the latest server code from the OPC Foundation, but I added
to the server config to enable the Basic256 security policy. This is part of the client code I'm using: Where activeRes2 equals BadUnkownResponse with the existing libua. When changing the libua code into using Basic256 as the security policy in the activate session method, the response equals Good and everything works OK |
The code I pasted here works for me after adding that security configuration XML to the latest OPC Foundation reference server: #13 (comment) Please confirm that it works for you, or let me know modification made it to work for you and I can merge it in. |
Your code worked for me as well. However, you are using the UserIdentityAnonymousToken, while I'm trying to authenticate using the UserIdentityUsernameToken. The OPC reference server accepts every user as long as the password is not IsNullOrEmpty, so it doesn't really matter what you use to authenticate. The modification I made to let this work is a change the ActivateSession method of client.cs. I've replaced all occurrences (2) of "SecurityPolicy.Basic128Rsa15" with "config.SecurityPolicy". This works when I'm using the Basic256 security policy, but I'm not sure this will work with e.g. the Basic256sha256 security policy. |
I'm not sure that this is intended behaviour because according to the specification, security policy defines the transport layer security, not for encrypting an identity token. I'll verify compatibility again and commit a change if there's an issue. By the way, I have started adding Basic256Sha256 as a security mode. The current source now fully supports this on the server side. |
Yes I've seen you've added Basic256Sha256 as a security mode. I'm trying it now, but I'm once again unable to connect to the reference server of the OPC foundation. It's complaining about the CertificateThumbprintSize length which should be 20 but is 32. I'm looking into it right now. By the way, have you tried using your code from 3 days ago to connect to the reference server and change the activate session argument into using a user identity token instead of the anonymous token? |
The reference server seemed to accept and ignore it, although I didn't expect that the SecurityPolicy would affect anything above the transport layer. If CertificateThumbprintSize length is wrong, try using Basic128Rsa15, or if not, Basic256Sha256 Let me know what works there. Different UA servers seem to have different policies and don't all work with the OPC Foundation client/servers, so I've added an optional parameter userIdentitySecurityPolicy to Client.ActivateSession. |
When trying to get Basic256Sha256 to work in my own code, I still had some changes left from trying to get the authentication to work when using SecurityPolicy Basic256. They conflicted which each other, which resulted in both not working. I went back to using your master branch and both now work fine. Basic256Sha256 is working and I'm able to authenticate. However, I went back to try and use the version of April 19th, and the authentication did not work with that version when using Basic256 as a SecurityPolicy. Somehow after adding the Basic256Sha256 SecurityPolicy the authentication now works for both security policies. I think this issue can now be closed. Thanks for the help. |
Was probably a bug I fixed while cleaning up the security code. Sometimes the UA specification can get confusing between whether to use the security policy for symmetric wrapping or Basic128Rsa15 as the asymmetric wrapping policy in places. Glad it works for you now. |
I was unable to authenticate using the SecurityPolicy Basic256 and the reference server of the OPC foundation.
I was able to open a secure channel and creating a session using:
m_client.OpenSecureChannel(MessageSecurityMode.SignAndEncrypt, SecurityPolicy.Basic256, serverCert);
m_client.CreateSession(appDesc, "urn:Application", 2);
But activating the session using:
m_client.ActivateSession( new UserIdentityUsernameToken(usernamePolicyDesc, "Name", (new UTF8Encoding()).GetBytes("password"), "http://www.w3.org/2001/04/xmlenc#rsa-oaep"), new[] { "en" });
did not work.
After looking at the code to activate the session, shouldn't the actual SecurityPolicy (which is available in the config member) be used when calculating the padding size and when encrypting the password instead of the hard coded Basic128Rsa15 SecurityPolicy?
The text was updated successfully, but these errors were encountered: