Skip to content

Commit

Permalink
Merge branch 'stable/0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Aug 17, 2023
2 parents 42f3581 + f742a3c commit 4e2570c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/zinolib/ritz.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

import logging
import socket
import hashlib
import enum
import ipaddress
from datetime import datetime, timedelta
Expand All @@ -89,7 +88,7 @@
import codecs
import select

from .utils import windows_codepage_cp1252
from .utils import windows_codepage_cp1252, generate_authtoken


codecs.register_error("windows_codepage_cp1252", windows_codepage_cp1252)
Expand Down Expand Up @@ -489,13 +488,12 @@ def authenticate(self, user, password):
ritz_session.connect()
ritz_session.authenticate("username","password")
"""
# Authenticate user
if not self.connStatus:
raise NotConnectedError("Not connected to device")

# Combine Password and authChallenge from Ritz to make authToken
genToken = "%s %s" % (self.authChallenge, password)
authToken = hashlib.sha1(genToken.encode("UTF-8")).hexdigest()
authToken = generate_authtoken(self.authChallenge, password)

# Authenticate user
cmd = "user %s %s -" % (user, authToken)
# try:
try:
Expand Down
17 changes: 17 additions & 0 deletions src/zinolib/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import hashlib


__all__ = [
"windows_codepage_cp1252",
"generate_authtoken",
]


def windows_codepage_cp1252(error):
"""Windows Codepage 1252 decoder fallback
Expand Down Expand Up @@ -39,3 +48,11 @@ def windows_codepage_cp1252(error):
result.append(chr(0x00 + byte))

return "".join(result), error.end


def generate_authtoken(challenge, password):
"Combine Password and authChallenge from Ritz to make authToken"

raw_token = "%s %s" % (challenge, password)
token = hashlib.sha1(raw_token.encode("UTF-8")).hexdigest()
return token
14 changes: 14 additions & 0 deletions tests/test_zinolib_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import hashlib
import unittest

from zinolib.utils import generate_authtoken


class GenerateAuthtokenTest(unittest.TestCase):

def test_generate_authtoken(self):
challenge = "ababp"
password = "fillifjonka"
expected = "84f9c302c392488f3f04f69f4c87994e10511892"
result = generate_authtoken(challenge, password)
self.assertEqual(expected, result)

0 comments on commit 4e2570c

Please sign in to comment.