Commit 6581f2c5 authored by oroulet's avatar oroulet

fix suspect line in encoding and fix (small) errors it was hiding

parent 02b764c9
...@@ -412,7 +412,7 @@ class Client(object): ...@@ -412,7 +412,7 @@ class Client(object):
challenge += self.security_policy.server_certificate challenge += self.security_policy.server_certificate
if self._server_nonce is not None: if self._server_nonce is not None:
challenge += self._server_nonce challenge += self._server_nonce
params.ClientSignature.Algorithm = b"http://www.w3.org/2000/09/xmldsig#rsa-sha1" params.ClientSignature.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
params.ClientSignature.Signature = self.security_policy.asymmetric_cryptography.signature(challenge) params.ClientSignature.Signature = self.security_policy.asymmetric_cryptography.signature(challenge)
params.LocaleIds.append("en") params.LocaleIds.append("en")
if not username and not certificate: if not username and not certificate:
...@@ -435,7 +435,7 @@ class Client(object): ...@@ -435,7 +435,7 @@ class Client(object):
# the last serverNonce to the serverCertificate # the last serverNonce to the serverCertificate
sig = uacrypto.sign_sha1(self.user_private_key, challenge) sig = uacrypto.sign_sha1(self.user_private_key, challenge)
params.UserTokenSignature = ua.SignatureData() params.UserTokenSignature = ua.SignatureData()
params.UserTokenSignature.Algorithm = b"http://www.w3.org/2000/09/xmldsig#rsa-sha1" params.UserTokenSignature.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
params.UserTokenSignature.Signature = sig params.UserTokenSignature.Signature = sig
def _add_user_auth(self, params, username, password): def _add_user_auth(self, params, username, password):
......
...@@ -85,7 +85,7 @@ class EventGenerator(object): ...@@ -85,7 +85,7 @@ class EventGenerator(object):
""" """
Trigger the event. This will send a notification to all subscribed clients Trigger the event. This will send a notification to all subscribed clients
""" """
self.event.EventId = ua.Variant(uuid.uuid4().hex, ua.VariantType.ByteString) self.event.EventId = ua.Variant(uuid.uuid4().hex.encode('utf-8'), ua.VariantType.ByteString)
if time: if time:
self.event.Time = time self.event.Time = time
else: else:
......
...@@ -48,17 +48,20 @@ class _DateTime(object): ...@@ -48,17 +48,20 @@ class _DateTime(object):
class _String(object): class _String(object):
@staticmethod @staticmethod
def pack(string): def pack(string):
if string is None: if string is not None:
return Primitives.Int32.pack(-1) if sys.version_info.major > 2:
if isinstance(string, unicode): string = string.encode('utf-8')
string = string.encode('utf-8') else:
length = len(string) # we do not want this test to happen with python3
return Primitives.Int32.pack(length) + string if isinstance(string, unicode):
string = string.encode('utf-8')
return _Bytes.pack(string)
@staticmethod @staticmethod
def unpack(data): def unpack(data):
b = _Bytes.unpack(data) b = _Bytes.unpack(data)
if sys.version_info.major < 3: if sys.version_info.major < 3:
# return unicode(b)
return b return b
else: else:
if b is None: if b is None:
...@@ -69,7 +72,12 @@ class _String(object): ...@@ -69,7 +72,12 @@ class _String(object):
class _Bytes(object): class _Bytes(object):
@staticmethod @staticmethod
def pack(data): def pack(data):
return _String.pack(data) if data is None:
return Primitives.Int32.pack(-1)
length = len(data)
if not isinstance(data, bytes):
print("BYTES EXPECTED", type(Primitives.Int32.pack(length)), type(data), data)
return Primitives.Int32.pack(length) + data
@staticmethod @staticmethod
def unpack(data): def unpack(data):
...@@ -142,7 +150,7 @@ class _Primitive1(object): ...@@ -142,7 +150,7 @@ class _Primitive1(object):
return None return None
if length == 0: if length == 0:
return () return ()
return struct.unpack(self._fmt.format(length), data.read(self.size*length)) return struct.unpack(self._fmt.format(length), data.read(self.size * length))
class Primitives1(object): class Primitives1(object):
...@@ -258,7 +266,7 @@ def to_binary(uatype, val): ...@@ -258,7 +266,7 @@ def to_binary(uatype, val):
Pack a python object to binary given a string defining its type Pack a python object to binary given a string defining its type
""" """
if uatype.startswith("ListOf"): if uatype.startswith("ListOf"):
#if isinstance(val, (list, tuple)): #if isinstance(val, (list, tuple)):
return list_to_binary(uatype[6:], val) return list_to_binary(uatype[6:], val)
elif isinstance(uatype, (str, unicode)) and hasattr(ua.VariantType, uatype): elif isinstance(uatype, (str, unicode)) and hasattr(ua.VariantType, uatype):
vtype = getattr(ua.VariantType, uatype) vtype = getattr(ua.VariantType, uatype)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment