Skip to content

Commit 02885fd

Browse files
committed
Change PNG generation to using the qrcode library instead of a web service.
1 parent 3514b89 commit 02885fd

5 files changed

Lines changed: 14 additions & 31 deletions

File tree

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PyAuth
88
.. image:: https://img.shields.io/pypi/pyversions/PyAuth.png
99
:target: https://pypi.python.org/pypi/PyAuth/
1010
:alt: Latest Version
11-
11+
1212
.. image:: https://img.shields.io/github/release/tknarr/PyAuth.png
1313
:target: https://github.com/tknarr/PyAuth/releases/latest
1414
:alt: Latest Version
@@ -53,8 +53,8 @@ Prerequisites
5353
`wxWidgets <http://www.wxwidgets.org/>`_
5454
* `pyotp 2.0.1 <https://pypi.python.org/pypi/pyotp>`_ or higher
5555
* `cryptography 1.3 <https://pypi.python.org/pypi/cryptography>`_ or higher
56-
* `pycrypto 2.6.1 <https://pypi/python.org/pypi/pycrypto>`_ or higher, strictly for
57-
decrypting older databases
56+
* `qrcode 5.3 <https://pypi.python.org/pypi/qrcode>`_ or higher
57+
* `Pillow 3.4 <https://pypi.python.org/pypi/Pillow>`_ or higher
5858

5959
wxPython isn't automatically pulled in by ``pip`` because the version at PyPI is
6060
still 2.9. Your distribution probably includes a pre-packaged version, or you can
@@ -103,7 +103,7 @@ Command line:
103103
* ``-n`` forces the program to display in a normal window without using the
104104
notification icon. This overrides ``-s`` and ``-m`` and any remembered settings
105105
for the notification icon.
106-
106+
107107
* ``--icons`` selects a set of icons with the named background (default white).
108108

109109
* ``--logfile`` allows you to set a log file for errors and messages logged by

pyauth/AuthEntryPanel.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import wx
2222
from AuthenticationStore import AuthenticationEntry
2323
from Logging import GetLogger
24-
from qrcode import QrCodeImage, QrCodeFrame
24+
from QrCode import QrCodeImage, QrCodeFrame
2525

2626

2727
class AuthEntryPanel( wx.Panel ):
@@ -389,10 +389,6 @@ def GetCodeString( self, selected ):
389389
def GetProvisioningUri( self ):
390390
return self.entry.GetKeyUri( )
391391

392-
def GetQrCodeUrl( self ):
393-
qr = QrCodeImage( self.entry )
394-
return qr.GetUrl( )
395-
396392
def GetQrCodeImage( self ):
397393
qr = QrCodeImage( self.entry )
398394
return qr.GetImage( )

pyauth/Encryption.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
## along with this program. If not, see http://www.gnu.org/licenses/
2727

2828
import os
29-
import string
3029
import base64
3130
from cryptography.hazmat.primitives import hashes
3231
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

pyauth/qrcode.py renamed to pyauth/QrCode.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
## along with this program. If not, see http://www.gnu.org/licenses/
1919

2020
import wx
21-
import requests
22-
import urllib
21+
import qrcode
2322
from io import BytesIO
24-
from AuthenticationStore import AuthenticationEntry
25-
from Logging import GetLogger
2623

2724

2825
class QrCodeImage:
@@ -31,21 +28,12 @@ class QrCodeImage:
3128
def __init__( self, entry ):
3229
self.provisioning_uri = entry.GetKeyUri( )
3330

34-
def GetUrl( self ):
35-
return "https://www.google.com/chart?chs=240x240&chld=M|0&cht=qr&chl=" + urllib.quote( self.provisioning_uri )
36-
3731
def GetImage( self ):
38-
url = self.GetUrl( )
39-
GetLogger( ).debug( "Requesting QR code image from %s", url )
40-
resp = requests.get( url )
41-
GetLogger( ).debug( "HTTP status: %d", resp.status_code )
42-
if resp.status_code == requests.codes.ok:
43-
input_strm = BytesIO( resp.content )
44-
image = wx.ImageFromStream( input_strm, wx.BITMAP_TYPE_PNG )
45-
else:
46-
GetLogger( ).error( "HTTP error %d", resp.status_code )
47-
GetLogger( ).error( "Error response body:\n%s", resp.text )
48-
image = None
32+
img = qrcode.make( self.provisioning_uri )
33+
strm = BytesIO( )
34+
img.save( strm, "PNG" )
35+
strm.seek( 0 )
36+
image = wx.ImageFromStream( strm, wx.BITMAP_TYPE_PNG )
4937
return image
5038

5139

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@
8181

8282
install_requires = [
8383
# 'wxPython>=3.0',
84-
'requests>=2.10',
8584
'pyotp>=2.0.1',
86-
'pycrypto>=2.6.1',
87-
'cryptography>=1.3'
85+
'cryptography>=1.3',
86+
'qrcode>=5.3',
87+
'Pillow>=3.4'
8888
],
8989

9090
package_data = {

0 commit comments

Comments
 (0)