@@ -40,17 +40,23 @@ import traceback
4040import urllib2
4141
4242try :
43- import gpgme
44- except ImportError :
43+ import gpg
4544 gpgme = None
45+ except ImportError :
46+ gpg = None
47+ # Still support gpgme for now. Remove this once we only support 17.10+.
48+ try :
49+ import gpgme
50+ except ImportError :
51+ gpgme = None
4652
4753from contextlib import closing , contextmanager
4854from posixpath import curdir , sep , pardir , join , abspath , commonprefix
4955
5056INFO = u"Dropbox is the easiest way to share and store your files online. Want to learn more? Head to"
5157LINK = u"https://www.dropbox.com/"
5258WARNING = u"In order to use Dropbox, you must download the proprietary daemon."
53- GPG_WARNING = u"Note: python-gpgme is not installed, we will not be able to verify binary signatures."
59+ GPG_WARNING = u"Note: python-gpg (python- gpgme for Ubuntu 17.04 and lower) is not installed, we will not be able to verify binary signatures."
5460ERROR_CONNECTING = u"Trouble connecting to Dropbox servers. Maybe your internet connection is down, or you need to set your http_proxy environment variable."
5561ERROR_SIGNATURE = u"Downloaded binary does not match Dropbox signature, aborting install."
5662
@@ -67,7 +73,7 @@ DESKTOP_FILE = u"@DESKTOP_FILE_DIR@/caja-dropbox.desktop"
6773enc = locale .getpreferredencoding ()
6874
6975# Available from https://linux.dropbox.com/fedora/rpm-public-key.asc
70- DROPBOX_PUBLIC_KEY = """
76+ DROPBOX_PUBLIC_KEY = b """
7177-----BEGIN PGP PUBLIC KEY BLOCK-----
7278Version: SKS 1.1.0
7379
@@ -179,7 +185,7 @@ def unicode_abspath(path):
179185 return os .path .abspath (path .encode (sys .getfilesystemencoding ())).decode (sys .getfilesystemencoding ())
180186
181187@contextmanager
182- def gpgme_context (keys ):
188+ def gpg_context (keys ):
183189 gpg_conf_contents = ''
184190 _gpghome = tempfile .mkdtemp (prefix = 'tmp.gpghome' )
185191
@@ -188,12 +194,20 @@ def gpgme_context(keys):
188194 fp = open (os .path .join (_gpghome , 'gpg.conf' ), 'wb' )
189195 fp .write (gpg_conf_contents )
190196 fp .close ()
191- ctx = gpgme .Context ()
197+ if gpg :
198+ ctx = gpg .Context ()
199+ else :
200+ ctx = gpgme .Context ()
192201
193202 loaded = []
194203 for key_file in keys :
195- result = ctx .import_ (key_file )
196- key = ctx .get_key (result .imports [0 ][0 ])
204+ if gpg :
205+ ctx .op_import (key_file .read ())
206+ result = ctx .op_import_result ()
207+ key = ctx .get_key (result .imports [0 ].fpr )
208+ else :
209+ result = ctx .import_ (key_file )
210+ key = ctx .get_key (result .imports [0 ][0 ])
197211 loaded .append (key )
198212
199213 ctx .signers = loaded
@@ -207,10 +221,16 @@ class SignatureVerifyError(Exception):
207221 pass
208222
209223def verify_signature (key_file , sig_file , plain_file ):
210- with gpgme_context ([key_file ]) as ctx :
224+ with gpg_context ([key_file ]) as ctx :
225+ if gpg :
226+ ctx .op_verify (sig_file .read (), plain_file .read (), None )
227+ result = ctx .op_verify_result ()
228+ return result .signatures [0 ].status == 0
229+ # gpgme exists
211230 sigs = ctx .verify (sig_file , plain_file , None )
212231 return sigs [0 ].status == None
213232
233+
214234def download_file_chunk (url , buf ):
215235 opener = urllib2 .build_opener ()
216236 opener .addheaders = [('User-Agent' , "DropboxLinuxDownloader/@PACKAGE_VERSION@" )]
@@ -252,7 +272,7 @@ class DownloadState(object):
252272 signature .seek (0 )
253273 self .local_file .seek (0 )
254274
255- if gpgme :
275+ if gpg or gpgme :
256276 if not verify_signature (StringIO .StringIO (DROPBOX_PUBLIC_KEY ), signature , self .local_file ):
257277 raise SignatureVerifyError ()
258278
@@ -454,7 +474,7 @@ if GUI_AVAILABLE:
454474 self .progress .set_property ('width-request' , 300 )
455475
456476 self .label = gtk .Label ()
457- GPG_WARNING_MSG = (u"\n \n " + GPG_WARNING ) if not gpgme else u""
477+ GPG_WARNING_MSG = (u"\n \n " + GPG_WARNING ) if not gpg and not gpgme else u""
458478 self .label .set_markup ('%s <span foreground="#000099" underline="single" weight="bold">%s</span>\n \n %s%s' % (INFO , LINK , WARNING , GPG_WARNING_MSG ))
459479 self .label .set_line_wrap (True )
460480 self .label .set_property ('width-request' , 300 )
@@ -543,7 +563,7 @@ else:
543563 write (save )
544564 flush ()
545565 console_print (u"%s %s\n " % (INFO , LINK ))
546- GPG_WARNING_MSG = (u"\n %s" % GPG_WARNING ) if not gpgme else u""
566+ GPG_WARNING_MSG = (u"\n %s" % GPG_WARNING ) if not gpg and not gpgme else u""
547567
548568 if not yes_no_question ("%s%s" % (WARNING , GPG_WARNING_MSG )):
549569 return
0 commit comments