Giter Site home page Giter Site logo

abdullahselek / authenticatorpy Goto Github PK

View Code? Open in Web Editor NEW
41.0 41.0 7.0 79 KB

A Python library that provide unique keys for 2FA with given secret.

Home Page: https://authenticatorpy.abdullahselek.com

License: MIT License

Python 100.00%
pure-python pypi pypi-packages python2-7 python3 two-factor-authentication

authenticatorpy's Introduction

Senior Machine Learning Engineer with more than 10 years of experience in software and machine learning engineering with designing, developing, and implementing complex machine learning pipelines, automation and systems. Possessing a strong computer science background and expertise in various programming languages and frameworks. Committed to staying up-to-date with the latest advancements in the field and am always seeking out new and innovative ways to solve complex problems as well as leading development teams and technical discussions. I am passionate about mentoring and training junior team members on machine learning techniques and best practices. Using Github for publishing and contributing to open source projects at the same time working on open source identity verification projects using Machine Learning and Deep Learning techniques. One of the open source projects that I have contributed to was used in Mars 2020 Helicopter Mission.

authenticatorpy's People

Contributors

abdullahselek avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

authenticatorpy's Issues

Input validation?

There doesn't seem to be any input sanitation/validation which causes a bunch of errors. A first step would be to check isinstance to verify that the secret given is a string. If it is a string, it should be stripped of all non-ascii characters and then padded correctly.

Original Examples

# No `secret` provided, defaults to `None`
>>> Authenticator().one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'NoneType' object has no attribute 'replace'

# No padding (only ascii strings that are multiples of 8 length work)
# The next 8 calls all have the same `binascii.Error` (removed for brevity)
>>> Authenticator('a').one_time_password()
>>> Authenticator('ab').one_time_password()
>>> Authenticator('abc').one_time_password()
>>> Authenticator('abcd').one_time_password()
>>> Authenticator('abcde').one_time_password()
>>> Authenticator('abcd e').one_time_password()
>>> Authenticator('abcd ef').one_time_password()
>>> Authenticator('abcd efg').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 71, in one_time_password
  File "<input>", line 43, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 205, in b32decode
    raise binascii.Error('Incorrect padding')
binascii.Error: Incorrect padding

# Ascii string with a length of 8
>>> Authenticator('abcd efgh').one_time_password()
455904

>>> Authenticator('abcd efgh ijkl').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 71, in one_time_password
  File "<input>", line 43, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 205, in b32decode
    raise binascii.Error('Incorrect padding')
binascii.Error: Incorrect padding

# Ascii string with a length of 16
>>> Authenticator('abcd efgh ijkl mnop').one_time_password()
823746

# Unicode secret
>>> Authenticator('ĀƯŤĤËŊŦĩÇÁƮŏƦ').one_time_password()
Traceback (most recent call last):
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 37, in _bytes_from_decode_data
    return s.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-12: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 71, in one_time_password
  File "<input>", line 43, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 203, in b32decode
    s = _bytes_from_decode_data(s)
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 39, in _bytes_from_decode_data
    raise ValueError('string argument should contain only ASCII characters')
ValueError: string argument should contain only ASCII characters

# Other types of whitespace aren't being removed
>>> Authenticator('\t\t\t\t \t\t\t\t').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 71, in one_time_password
  File "<input>", line 43, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found

>>> Authenticator('\r\r\r\r \r\r\r\r').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 71, in one_time_password
  File "<input>", line 43, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.3/lib/python3.6/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found

# Non-string secret
>>> Authenticator(lambda: None).one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'function' object has no attribute 'replace'

>>> Authenticator(123456).one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'int' object has no attribute 'replace'

>>> Authenticator(123456.789).one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'float' object has no attribute 'replace'

>>> Authenticator([]).one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'list' object has no attribute 'replace'

>>> Authenticator(set()).one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'set' object has no attribute 'replace'

>>> Authenticator(tuple()).one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 69, in one_time_password
  File "<input>", line 32, in remove_spaces
AttributeError: 'tuple' object has no attribute 'replace'

EDIT:

Looks like 5b79e81 addressed some of the concerns raised above but there are a couple more to consider.

Any ASCII input that has a zero, one, eight or nine breaks your code (all valid ascii characters).

>>> Authenticator('abcd efg0').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 97, in one_time_password
  File "<input>", line 69, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.4/lib/python3.6/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found
>>> Authenticator('abcd efg1').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 97, in one_time_password
  File "<input>", line 69, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.4/lib/python3.6/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found
>>> Authenticator('abcd efg8').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 97, in one_time_password
  File "<input>", line 69, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.4/lib/python3.6/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found
>>> Authenticator('abcd efg9').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 97, in one_time_password
  File "<input>", line 69, in decode_with_base32
  File "/home/lettuce/.pyenv/versions/3.6.4/lib/python3.6/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found

You wouldn't have to write an error message and restrict the length of secrets to being a multiple of eight if you just padded any string that wasn't that long enough. Also, the message itself is worded slightly wrong since you can have secrets that are don't have a length of eight as long as the length is a multiple of eight.

>>> Authenticator('abcd abcd abcd abcd').one_time_password()
60803
>>> Authenticator('abcd abcd abcd').one_time_password()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 24, in __init__
  File "<input>", line 37, in __check_secret
ValueError: You must set a string length of 8!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.