~raoul-snyman/openlp/bug-1608194

« back to all changes in this revision

Viewing changes to openlp/core/lib/projector/pjlink1.py

Bugfix 1593882 and 1593883 - projector authorization

- Fix exception when authenticated connection requested and pin is None
- Fix pjlink authentication (use python hash instead of qt hash)
- Fix md5_hash functions
- Fix qmd5hash functions
- Added tests for bugfixes
Tested with test server and Eiki XL200 projector

--------------------------------
lp:~alisonken1/openlp/bug-1593883-projector-authentication (revision 2684)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1629/
[SUCCESS] https...

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from PyQt5.QtCore import pyqtSignal, pyqtSlot
50
50
from PyQt5.QtNetwork import QAbstractSocket, QTcpSocket
51
51
 
52
 
from openlp.core.common import translate, qmd5_hash
 
52
from openlp.core.common import translate, md5_hash
53
53
from openlp.core.lib.projector.constants import *
54
54
 
55
55
# Shortcuts
297
297
        Processes the initial connection and authentication (if needed).
298
298
        Starts poll timer if connection is established.
299
299
 
 
300
        NOTE: Qt md5 hash function doesn't work with projector authentication. Use the python md5 hash function.
 
301
 
300
302
        :param data: Optional data if called from another routine
301
303
        """
302
304
        log.debug('({ip}) check_login(data="{data}")'.format(ip=self.ip, data=data))
344
346
            return
345
347
        elif data_check[1] == '0' and self.pin is not None:
346
348
            # Pin set and no authentication needed
 
349
            log.warning('({ip}) Regular connection but PIN set'.format(ip=self.name))
347
350
            self.disconnect_from_host()
348
351
            self.change_status(E_AUTHENTICATION)
349
 
            log.debug('({ip}) emitting projectorNoAuthentication() signal'.format(ip=self.name))
 
352
            log.debug('({ip}) Emitting projectorNoAuthentication() signal'.format(ip=self.name))
350
353
            self.projectorNoAuthentication.emit(self.name)
351
354
            return
352
355
        elif data_check[1] == '1':
353
356
            # Authenticated login with salt
354
 
            log.debug('({ip}) Setting hash with salt="{data}"'.format(ip=self.ip, data=data_check[2]))
355
 
            log.debug('({ip}) pin="{data}"'.format(ip=self.ip, data=self.pin))
356
 
            salt = qmd5_hash(salt=data_check[2].encode('ascii'), data=self.pin.encode('ascii'))
 
357
            if self.pin is None:
 
358
                log.warning('({ip}) Authenticated connection but no pin set'.format(ip=self.name))
 
359
                self.disconnect_from_host()
 
360
                self.change_status(E_AUTHENTICATION)
 
361
                log.debug('({ip}) Emitting projectorAuthentication() signal'.format(ip=self.name))
 
362
                self.projectorAuthentication.emit(self.name)
 
363
                return
 
364
            else:
 
365
                log.debug('({ip}) Setting hash with salt="{data}"'.format(ip=self.ip, data=data_check[2]))
 
366
                log.debug('({ip}) pin="{data}"'.format(ip=self.ip, data=self.pin))
 
367
                salt = md5_hash(salt=data_check[2].encode('ascii'), data=self.pin.encode('ascii'))
357
368
        else:
358
369
            salt = None
359
370
        # We're connected at this point, so go ahead and do regular I/O