Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Improve otp decoding #15

Merged
merged 3 commits into from

1 participant

@Kami
Owner

Should fix #14.

added some commits
@Kami Not working on 1.6.2-dev 7fc5f9f
@Kami If there are multiple interpretations for a given OTP, first try to f…
…ind the one

which matches the input OTP. If the one is found, use the input OTP, otherwise
use last of the available interpretations.

Reported by Klas Lindfors, part of #14.
d02510a
@Kami Kami referenced this pull request
Closed

OTP Translation error #14

@Kami Kami merged commit 680f278 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2013
  1. Not working on 1.6.2-dev

    authored
Commits on Mar 30, 2013
  1. If there are multiple interpretations for a given OTP, first try to f…

    authored
    …ind the one
    
    which matches the input OTP. If the one is found, use the input OTP, otherwise
    use last of the available interpretations.
    
    Reported by Klas Lindfors, part of #14.
This page is out of date. Refresh to see the latest.
View
8 CHANGES.md
@@ -1,3 +1,11 @@
+in development:
+
+* If there are multiple interpretations for a given OTP, first try to find the one
+ which matches the input OTP. If the one is found, use the input OTP, otherwise
+ use random interpretation. - https://github.com/Kami/python-yubico-client/issues/14
+
+ Reported by Klas Lindfors
+
1.6.1 - 2013-03-19:
* Only run `logging.basicConfig` when running tests so logging config isn't initialised
View
2  setup.py
@@ -41,7 +41,7 @@ class TestCommand(Command):
def initialize_options(self):
FORMAT = '%(asctime)-15s [%(levelname)s] %(message)s'
logging.basicConfig(format=FORMAT)
-
+
THIS_DIR = os.path.abspath(os.path.split(__file__)[0])
sys.path.insert(0, THIS_DIR)
for test_path in TEST_PATHS:
View
13 tests/test_yubico.py
@@ -20,6 +20,19 @@ def test_otp_class(self):
self.assertEqual(otp2.otp,
'ccccccccljdeluiucdgffccchkugjcfditgbglbflvjc')
+ def test_translation_multiple_interpretations(self):
+ otp_str1 = 'vvbtbtndhtlfguefgluvbdcetnitidgkvfkbicevgcin'
+ otp1 = OTP(otp_str1)
+ self.assertEqual(otp1.otp, otp_str1)
+
+ def test_translation_single_interpretation(self):
+ otp_str1 = 'cccfgvgitchndibrrtuhdrgeufrdkrjfgutfjbnhhglv'
+ otp_str2 = 'cccagvgitchndibrrtuhdrgeufrdkrjfgutfjbnhhglv'
+ otp1 = OTP(otp_str1)
+ otp2 = OTP(otp_str2)
+ self.assertEqual(otp1.otp, otp_str1)
+ self.assertEqual(otp2.otp, otp_str2)
+
class TestYubicoVerifySingle(unittest.TestCase):
def setUp(self):
View
2  yubico/__init__.py
@@ -1 +1 @@
-__version__ = (1, 6, 1)
+__version__ = (1, 6, 2, 'dev')
View
15 yubico/otp.py
@@ -20,11 +20,20 @@ def get_otp_modehex_interpretation(self, otp):
# if the OTP uses all 16 characters in its alphabet
# there is only one possible interpretation of that otp
try:
- otp_translated = modhex.translate(unicode(otp)).pop()
+ interpretations = modhex.translate(unicode(otp))
except Exception:
- otp_translated = otp
+ return otp
- return otp_translated
+ if len(interpretations) == 0:
+ return otp
+ elif len(interpretations) > 1:
+ # If there are multiple interpretations first try to use the same
+ # translation as the input OTP. If the one is not found, use the
+ # random interpretation.
+ if unicode(otp) in interpretations:
+ return otp
+
+ return interpretations.pop()
def __repr__(self):
return '%s, %s, %s' % (self.otp, self.device_id, self.timestamp)
Something went wrong with that request. Please try again.