diff --git a/README.md b/README.md index ebd5cc0..474bdb2 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ pip install python-yubikey ## Register for an API key ``` -import yubikey +from yubikey import Yubikey yubi = Yubikey() yubi.register('') diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..d59be43 --- /dev/null +++ b/tests.py @@ -0,0 +1,5 @@ +from yubikey import Yubikey + + +yubi = Yubikey(123) +yubi.verify('asdadadasdasdadadadadasdasdadsasdadadsadadad') \ No newline at end of file diff --git a/yubikey.py b/yubikey.py index 0f4c24b..7efa2f9 100644 --- a/yubikey.py +++ b/yubikey.py @@ -38,6 +38,7 @@ class YubicoWS(object): self.api_ws = self._api_ws % choice(self._servers) def register_api_key(self, email, otp): + "Registers an API Key with the servers" data = { 'email': email, 'otp': str.lower(otp) @@ -50,6 +51,7 @@ class YubicoWS(object): return ws_response def verify(self, yubikey_id, otp, key=None): + "Verifies the provided OTP with the server" endpoint = 'verify' url = self.api_ws + endpoint @@ -86,9 +88,11 @@ class YubicoWS(object): return ws_response def sign_otp(self, data, key): + "Signs the OTP with the provided key" return data def parse_ws_response(self, text): + "Parses the API key=value response into a dict" data = {} for line in text.strip().split('\n'): key, value = line.split('=', 1) @@ -96,6 +100,7 @@ class YubicoWS(object): return data def generate_nonce(self): + "Generates a random string" chars = string.ascii_lowercase + string.digits return ''.join(choice(chars) for x in range(40)) @@ -115,6 +120,7 @@ class Yubikey(object): self.key = key def register(self, email, otp): + "Registers this yubikey" result = False if not self.id: credentials = self.ws.register_api_key(email, otp) @@ -126,6 +132,7 @@ class Yubikey(object): return result def verify(self, otp): + "Verify an OTP to check if its valid" result = False if self.id: self.get_prefix(otp) @@ -137,6 +144,7 @@ class Yubikey(object): return result def get_prefix(self, otp): + "Get prefix from an OTP if present" if len(otp) > 32: self.prefix = str.lower(otp[:-32]) diff --git a/yubikey.pyc b/yubikey.pyc new file mode 100644 index 0000000..ce6b2dc Binary files /dev/null and b/yubikey.pyc differ