Skip to content
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

Attempt to connect to Arburg proprietary server #135

Closed
mertz3hack opened this issue Feb 17, 2016 · 20 comments
Closed

Attempt to connect to Arburg proprietary server #135

mertz3hack opened this issue Feb 17, 2016 · 20 comments

Comments

@mertz3hack
Copy link

Arburg is an injection molding machine company that runs OPC UA servers on their machines.
I am able to connect to the machine and browse with UAExpert.

Taking any suggestions. Can I set the URI?

I am trying to connect to the server with

import sys
sys.path.insert(0, "..")
from opcua import Client

client = Client("opc.tcp://admin:password@192.168.12.28:4880/Arburg")
client.connect()
client.disconnect()

I get this when I run it

Traceback (most recent call last):

File "minimal-client.py", line 11, in
client.connect()

File "..\opcua\client\client.py", line 208, in connect
self.activate_session(username=self.server_url.username, password=self.server_url.password, certificate=self.user_ce
rtificate)

File "..\opcua\client\client.py", line 384, in activate_session
self.server_policy_uri(ua.UserTokenType.UserName))

File "..\opcua\crypto\security_policies.py", line 451, in encrypt_asymmetric
raise UaError("Unsupported security policy {}".format(uri))
NameError: name 'uri' is not defined
ServiceFault from server received in response to ReadRequest
Exception in thread Thread-2:

Traceback (most recent call last):

File "C:\python\lib\threading.py", line 914, in _bootstrap_inner
self.run()

File "..\opcua\client\client.py", line 51, in run
val = server_state.get_value()

File "..\opcua\common\node.py", line 81, in get_value
result = self.get_data_value()

File "..\opcua\common\node.py", line 90, in get_data_value
return self.get_attribute(ua.AttributeIds.Value)

File "..\opcua\common\node.py", line 155, in get_attribute
result = self.server.read(params)

File "..\opcua\client\ua_client.py", line 267, in read
data = self._uasocket.send_request(request)

File "..\opcua\client\ua_client.py", line 75, in send_request
self.check_answer(data, " in response to " + request.class.name)

File "..\opcua\client\ua_client.py", line 84, in check_answer
hdr.ServiceResult.check()

File "..\opcua\ua\uatypes.py", line 323, in check
raise UaStatusCodeError("{}({})".format(self.doc, self.name))
opcua.common.uaerrors.UaStatusCodeError: The session cannot be used because ActivateSession has not been called.(BadSessionNotActivated)

@oroulet
Copy link
Member

oroulet commented Feb 17, 2016

looks like bug in exception handling here. I will commit a fix, the encryption stuff is missing tests and that king of things happen....
I see we are missing an example client showing how to use encryption.
first call uadiscovery opc.tcp://yourserver to see what encryption your server supports then
call set_security_string() method in client to set correct encryption mode

@joaopmrod
Copy link

I'm experiencing exactly the same problem with Ignition Software's OPC-UA Server.

@oroulet
Copy link
Member

oroulet commented Feb 18, 2016

Can one of you put their server on internet or record a session with wireshark so we understand what is happening.

@mertz3hack
Copy link
Author

@oroulet I am not able to put the server on the internet and wireshark is not recognizing my wireless card via windows on a surface book :/
when I connect with UaExpert it says the security policy is 'http://opcfoundation.org/UA/SecurityPolicy#None' and the ApplicationUri is 'uri://Arburg/App/Selogica/direct'

@oroulet
Copy link
Member

oroulet commented Feb 18, 2016

Then set logging to debug and send terminal output. Maybe we'll see
something there

On Thu, Feb 18, 2016, 22:44 mertz3hack notifications@github.com wrote:

@oroulet https://github.com/oroulet I am not able to put the server on
the internet and wireshark is not recognizing my wireless card via windows
on a surface book :/
when I connect with UaExpert it says the security policy is '
http://opcfoundation.org/UA/SecurityPolicy#None' and the ApplicationUri
is 'uri://Arburg/App/Selogica/direct'


Reply to this email directly or view it on GitHub
#135 (comment)
.

@mertz3hack
Copy link
Author

@oroulet I downgraded to version 1.12.9 of wireshark and it is now seeing my wireless card.
the ip address of 192.168.12.27 is the server I am trying to connect too.
Is this what you were looking for?
attachment removed

@oroulet
Copy link
Member

oroulet commented Feb 19, 2016

the log seems corrupt. I cannot see the request freeopcua sends. But from the responses we see, the connection has succeeded and you read some nodes values then tried to subscribe to a node and that is where something fails. I cannot see what node you are trying to subscribe too, but the server sends a serviceFault response. This looks very different to what you say and the error message you wrote above... How does you code looks like? does it fail even you do not attempt to subcsribe a node? You can only subscribe to variable nodes

@mertz3hack
Copy link
Author

I'm not exactly sure what I should be looking for - i see the server and pc interacting but don't directly see the request
The attached zip shows the initial part of the error using the minimal-client without doing uadiscovery.
There is also a successful connection with UAexpert
Attachment Removed

@oroulet the last wireshark file you were looking at was a successful uaexpert connection and disconnection. If you have some specific code you would like me to try please let me know

@oroulet
Copy link
Member

oroulet commented Feb 20, 2016

Can you fix the typo in line 451 in security_policies.py (uri -> policy_uri) then run again?
or fetch pull request #136 it has the fix

It will not fix your issue but at least we will get a good error message

@oroulet
Copy link
Member

oroulet commented Feb 20, 2016

@alkor In this log I see that in UserTokenPolicy the PolicyId is set to UserName_Policy_1. Is this a normal PolicyId? Can it be the reason of the crash here? any suggestion t fix this?
Then SecurityPolicyUri for UserTokenPolicy is http://opcfoundation.org/UA/SecurityPolicy#None. Maybe that means that password should not be encrypted?

@oroulet
Copy link
Member

oroulet commented Feb 20, 2016

@alkor Am I right to understand that name og UserTokenPolicy does not mean anything? The important thing is what is written in the SecurityPolicyUri? and in that case we are missing support for the simplest one: no encryption?

@alkor
Copy link
Contributor

alkor commented Feb 20, 2016

Oh, yes, I see the problem. I'll fix this. Thank you for fixing my typo (uri -> policy_uri).

@oroulet
Copy link
Member

oroulet commented Feb 20, 2016

This should now be fixed in master. Can you test and report?

@mertz3hack
Copy link
Author

This is what I tried running to connect
I re-downloaded master before attempting

import sys
sys.path.insert(0, "..")
from opcua import Client
if name == "main":
client = Client("opc.tcp://admin:password@192.168.12.27:4880/Arburg")
try:
client.connect()
finally:
client.disconnect()

And the results

Sending plain-text password
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\python\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\python\lib\threading.py", line 862, in run
self._target(_self._args, *_self._kwargs)
File "..\opcua\client\ua_client.py", line 92, in _run
self._receive()
File "..\opcua\client\ua_client.py", line 99, in _receive
msg = self._connection.receive_from_socket(self._socket)
File "..\opcua\ua\uaprotocol_hand.py", line 642, in receive_from_socket
header = Header.from_string(socket)
File "..\opcua\ua\uaprotocol_hand.py", line 121, in from_string
hdr.MessageType, hdr.ChunkType, hdr.packet_size = struct.unpack("<3scI", data.read
File "..\opcua\common\utils.py", line 101, in read
chunk = self.socket.recv(size)
OSError: [WinError 10038] An operation was attempted on something that is not a socket

@oroulet
Copy link
Member

oroulet commented Feb 22, 2016

Set logging to debug and run wireshark again. Then copy paste stdout here. And please try to keep some formating when pasting.
And add a sleep after connect to make sure we do not close connection too early

@oroulet
Copy link
Member

oroulet commented Feb 22, 2016

please update master. I just added some more debug to client. Now it prints everything it sends and receives from server, so you do not need to use wireshark.
so set logging to debug, run your example and paste output here

@mertz3hack
Copy link
Author

@oroulet is there an instant messenger on here we can use?

It is connecting to the server and the object node and root are fetching but the disconnect is throwing the error (Update: it does not appear to be the disconnect that is throwing the error)

wait
go
Sending plain-text password
annndddd
done
Objects node is: Node(TwoByteNodeId(i=84))
Children of root are: [Node(TwoByteNodeId(i=87)), Node(TwoByteNodeId(i=86)), Node(TwoByteNodeId(i=85))]
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\python\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\python\lib\threading.py", line 862, in run
self._target(_self._args, *_self._kwargs)
File "..\opcua\client\ua_client.py", line 93, in _run
self._receive()
File "..\opcua\client\ua_client.py", line 100, in _receive
msg = self._connection.receive_from_socket(self._socket)
File "..\opcua\ua\uaprotocol_hand.py", line 642, in receive_from_socket
header = Header.from_string(socket)
File "..\opcua\ua\uaprotocol_hand.py", line 121, in from_string
hdr.MessageType, hdr.ChunkType, hdr.packet_size = struct.unpack("<3scI", data.read(8))
File "..\opcua\common\utils.py", line 101, in read
chunk = self.socket.recv(size)
OSError: [WinError 10038] An operation was attempted on something that is not a socket

When ran with debugging on I do not get the error
debug txt.txt

@mertz3hack
Copy link
Author

I am able to successfully connect too and specify a node to get it's value.
I am still getting an error that I am not sure about yet.

minimal-client.txt
minimal error.txt
minimal debug.txt

@oroulet
Copy link
Member

oroulet commented Feb 23, 2016

the error is not visible in the minima debug.txt file. Should I understand that i only happens sometime? and only at end of connection?
Anyway it is probably some windows specific things at closing. Can you open a bug request for it? and close this one?
Thanks

@mertz3hack
Copy link
Author

I will close this issue with successful connection and will see if I can find anything more about his other error I am getting before creating an Issue for it.

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

No branches or pull requests

4 participants