nauful / LibUA

Open-source OPC UA client and server library
Apache License 2.0
262 stars 94 forks source link

Cannot connect to SIMATIC WinCC UA #48

Closed IvoFortunov closed 3 years ago

IvoFortunov commented 3 years ago

Hello, I continue exploring your library, and it looks very promissing. The final goal of my project is to connect to SIMATIC WinCC. My application is a server. Everything works fine with clients like UAExpert and other, but when I try to connect from SIMATIC WinCC I've got the following:

  1. With security set to none, SIMATIC sends "CloseSecureChannelRequest" Wireshark log: SecurityNone.zip 2.With security Basic128Rsa15 and the certificate from ERRATA(with the original pem, maybe my mistake) i get BadInternalError WIreshark log: SecurityBasic128Rsa15.zip

The Consume gives (-4), exception is: "Error occurred while decoding OAEP padding". Decoding problem, maybe because the private key is wrong, but I don't have a PEM file for the certificate from ERRATA.

3.With security Basic128Rsa15 and the original certificate i get Unknown error, but things look better WIreshark log: SecurityBasic128Rsa15_org_cert.zip

Please help me solve this issue! Thanks in advance

nauful commented 3 years ago

I can't easily find UA traffic in your dump, could you filter them to only include the ports used for UA traffic?

IvoFortunov commented 3 years ago

I think I've managed to filter them. If you write "opcua" in filter of Wireshark, they are filtered by protocol.

  1. With security Basic128Rsa15 and the original certificate i get Unknown error, but things look better WIreshark log: SecurityBasic128Rsa15_org_cer_opcua.zip

4.With security None, original certificate, previous version of WinCC i get Unknown error, but the communication gets a little bit further WIreshark log: SecurityNone_org_cert_older_WinCC.zip

nauful commented 3 years ago

Seems to expect a specific structure for the read value of Server_ServerStatus_State.

Could you capture traffic from a server-client configuration that works, with None security mode? That same value blob can be reused here.

IvoFortunov commented 3 years ago

Here is working log with Unified Automation Test UA Server and last version of Simatic WinCC Wireshark log: WorkingConnection_new_WinCC.zip

Here is working log with Unified Automation Test UA Server and older version of Simatic WinCC Wireshark log: WorkingConnection_older_WinCC.zip

P.S. If i return the UInt32 - 65536 all values in the second read request (12 values representing OperationLimits), it connects but doesn't browse the items. It browses only "Server node". These values are 0 in the original. Dont'they have values?

P.S. 2 : Maybe it is the datatype with UInt32 - 0, also connects

IvoFortunov commented 3 years ago

Ok I fixed the connection issues. WinCC asks for "ServerCapabilities_OperationLimits" so I've added them to "internalAddressSpaceValues". It also expects UInt32 as an answer. Now it connects and browses "Server Node" but it doesn't browse "Items Node". Can you please help me with this issue? Wireshark log: Connected_Cannot_Browse_Items.zip

P.S. It only browses a small part of Server node BrowseServer

nauful commented 3 years ago

What is the value for MaxNodesPerBrowse? It seems to pick that as 0 and not browse.

IvoFortunov commented 3 years ago

No it is 100(after the fix from the previous post) , and yet another strange thing - it seams to ask for NodeId(0,0) instead of (2,0) when I try to browse Items folder. It looks like that WinCC thinks that Items have nodeId=0 NodeId_0

In the working configuration it seams to ask for the correct NodeId.

nauful commented 3 years ago

Could you make a pull request to merge your fixes into the main library?

From the root, there should be a link to ns=2;i=0 that represents items. It seems that the namespace is dropped? I'm not sure how to fix that.

IvoFortunov commented 3 years ago

I continue investigating, when I finish I will make a pull request with all the fixes.

IvoFortunov commented 3 years ago

It is very strange behaviour. When I've changed NodeId(2,0) for Items to NodeId(2,"Items") - string identifier WinCC started to browse the Items.

nauful commented 3 years ago

Is the browse link from root to items the same i.e. ns=2;i=0 and also updated similarly to ns=2;s="Items"?

I wouldn't use this change for other servers, many (especially embedded) don't allow string identifiers.

IvoFortunov commented 3 years ago

No this change is only for my project! I've just changed ns=2;i=0 to ns=2;s="Items". For now we only have to add ServerCapabilities_OperationLimits" (12 values) to "internalAddressSpaceValues". Now I have other issues, and when I solve them we can decide together what to include in the library.

P.S. Can we communicate by email, when there are things to discuss?

nauful commented 3 years ago

You can email me: github username @gmail

IvoFortunov commented 3 years ago

It finally works: Working WinCC Thanks for the help!