Permalink
Browse files

Tab to spaces, no functional changes.

  • Loading branch information...
1 parent b38e555 commit 8c8f40287986f9cc76beb728c737ce39133fec66 @Kami committed Nov 18, 2011
Showing with 368 additions and 368 deletions.
  1. +14 −14 demo/example.py
  2. +22 −22 setup.py
  3. +48 −48 yubico/httplib_ssl.py
  4. +22 −22 yubico/otp.py
  5. +241 −241 yubico/yubico.py
  6. +21 −21 yubico/yubico_exceptions.py
View
@@ -8,28 +8,28 @@
token = raw_input('Enter OTP token: ')
if not secret_key:
- secret_key = None
-
+ secret_key = None
+
if use_https == 'n':
- https = False
+ https = False
else:
- https = True
+ https = True
client = yubico.Yubico(client_id, secret_key, https)
try:
- status = client.verify(token)
+ status = client.verify(token)
except yubico_exceptions.InvalidClientIdError, e:
- print 'Client with id %s does not exist' % (e.client_id)
- sys.exit(1)
+ print 'Client with id %s does not exist' % (e.client_id)
+ sys.exit(1)
except yubico_exceptions.SignatureVerificationError:
- print 'Signature verification failed'
- sys.exit(1)
+ print 'Signature verification failed'
+ sys.exit(1)
except yubico_exceptions.StatusCodeError, e:
- print 'Negative status code was returned: %s' % (e.status_code)
- sys.exit(1)
-
+ print 'Negative status code was returned: %s' % (e.status_code)
+ sys.exit(1)
+
if status:
- print 'Success, the provided OTP is valid'
+ print 'Success, the provided OTP is valid'
else:
- print 'No response from the servers or received other negative status code'
+ print 'No response from the servers or received other negative status code'
View
@@ -21,25 +21,25 @@
fp.close()
setup(name = 'yubico',
- version = '.' . join(map(str, version)),
- description = 'Python Yubico Client',
- author = 'Tomaž Muraus',
- author_email = 'kami@k5-storitve.net',
- license = 'BSD',
- url = 'http://github.com/Kami/python-yubico-client/',
- download_url = 'http://github.com/Kami/python-yubico-client/downloads/',
- packages = ['yubico'],
- provides = ['yubico'],
-
- classifiers = [
- 'Development Status :: 4 - Beta',
- 'Environment :: Console',
- 'Intended Audience :: Developers',
- 'Intended Audience :: System Administrators',
- 'License :: OSI Approved :: BSD License',
- 'Operating System :: OS Independent',
- 'Programming Language :: Python',
- 'Topic :: Security',
- 'Topic :: Software Development :: Libraries :: Python Modules',
- ],
-)
+ version = '.' . join(map(str, version)),
+ description = 'Python Yubico Client',
+ author = 'Tomaž Muraus',
+ author_email = 'kami@k5-storitve.net',
+ license = 'BSD',
+ url = 'http://github.com/Kami/python-yubico-client/',
+ download_url = 'http://github.com/Kami/python-yubico-client/downloads/',
+ packages = ['yubico'],
+ provides = ['yubico'],
+
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ 'Intended Audience :: System Administrators',
+ 'License :: OSI Approved :: BSD License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Security',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ ]
+)
View
@@ -10,54 +10,54 @@
CA_CERTS = ''
class VerifiedHTTPSConnection(httplib.HTTPSConnection):
- def connect(self):
- sock = socket.create_connection((self.host, self.port),
- self.timeout)
- if self._tunnel_host:
- self.sock = sock
- self._tunnel()
-
- self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, \
- cert_reqs = ssl.CERT_REQUIRED, ca_certs = CA_CERTS, \
- ssl_version = ssl.PROTOCOL_TLSv1)
-
- cert = self.sock.getpeercert()
- if not self._verify_hostname(self.host, cert):
- raise ssl.SSLError('Failed to verify hostname')
-
- def _verify_hostname(self, hostname, cert):
- common_name = self._get_commonName(cert)
- alt_names = self._get_subjectAltName(cert)
-
- if (hostname == common_name) or hostname in alt_names:
- return True
-
- return False
-
- def _get_subjectAltName(self, cert):
- if not cert.has_key('subjectAltName'):
- return None
-
- alt_names = []
- for value in cert['subjectAltName']:
- if value[0].lower() == 'dns':
- alt_names.append(value[0])
-
- return alt_names
-
- def _get_commonName(self, cert):
- if not cert.has_key('subject'):
- return None
-
- for value in cert['subject']:
- if value[0][0].lower() == 'commonname':
- return value[0][1]
- return None
+ def connect(self):
+ sock = socket.create_connection((self.host, self.port),
+ self.timeout)
+ if self._tunnel_host:
+ self.sock = sock
+ self._tunnel()
+
+ self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, \
+ cert_reqs = ssl.CERT_REQUIRED, ca_certs = CA_CERTS, \
+ ssl_version = ssl.PROTOCOL_TLSv1)
+
+ cert = self.sock.getpeercert()
+ if not self._verify_hostname(self.host, cert):
+ raise ssl.SSLError('Failed to verify hostname')
+
+ def _verify_hostname(self, hostname, cert):
+ common_name = self._get_commonName(cert)
+ alt_names = self._get_subjectAltName(cert)
+
+ if (hostname == common_name) or hostname in alt_names:
+ return True
+
+ return False
+
+ def _get_subjectAltName(self, cert):
+ if not cert.has_key('subjectAltName'):
+ return None
+
+ alt_names = []
+ for value in cert['subjectAltName']:
+ if value[0].lower() == 'dns':
+ alt_names.append(value[0])
+
+ return alt_names
+
+ def _get_commonName(self, cert):
+ if not cert.has_key('subject'):
+ return None
+
+ for value in cert['subject']:
+ if value[0][0].lower() == 'commonname':
+ return value[0][1]
+ return None
class VerifiedHTTPSHandler(urllib2.HTTPSHandler):
- def __init__(self, connection_class = VerifiedHTTPSConnection):
- self.specialized_conn_class = connection_class
- urllib2.HTTPSHandler.__init__(self)
+ def __init__(self, connection_class = VerifiedHTTPSConnection):
+ self.specialized_conn_class = connection_class
+ urllib2.HTTPSHandler.__init__(self)
- def https_open(self, req):
- return self.do_open(self.specialized_conn_class, req)
+ def https_open(self, req):
+ return self.do_open(self.specialized_conn_class, req)
View
@@ -5,25 +5,25 @@
import modhex
class OTP():
- def __init__(self, otp, translate_otp = True):
- self.otp = self.get_otp_modehex_interpretation(otp) \
- if translate_otp else otp
-
- self.device_id = self.otp[:12]
- self.session_counter = None
- self.timestamp = None
- self.session_user = None
-
- def get_otp_modehex_interpretation(self, otp):
- # We only use the first interpretation, because
- # 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()
- except Exception:
- otp_translated = otp
-
- return otp_translated
-
- def __repr__(self):
- return '%s, %s, %s' % (self.otp, self.device_id, self.timestamp)
+ def __init__(self, otp, translate_otp = True):
+ self.otp = self.get_otp_modehex_interpretation(otp) \
+ if translate_otp else otp
+
+ self.device_id = self.otp[:12]
+ self.session_counter = None
+ self.timestamp = None
+ self.session_user = None
+
+ def get_otp_modehex_interpretation(self, otp):
+ # We only use the first interpretation, because
+ # 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()
+ except Exception:
+ otp_translated = otp
+
+ return otp_translated
+
+ def __repr__(self):
+ return '%s, %s, %s' % (self.otp, self.device_id, self.timestamp)
Oops, something went wrong.

0 comments on commit 8c8f402

Please sign in to comment.