示例#1
0
def main():
    # start the app
    app = QtGui.QApplication(sys.argv)

    # initialize and check for gpg and a secret key
    gpg = GnuPG()

    # initialize the module which handles the daily headlines feature.
    headlines = Headlines()

    system = platform.system()
    if system == 'Darwin':
        if not gpg.is_gpg_available():
            common.alert(
                'GPG doesn\'t seem to be installed. Install <a href="https://gpgtools.org/">GPGTools</a>, generate a key, and run AutoCanary again.'
            )
            sys.exit(0)

        seckeys = gpg.seckeys_list()
        if len(seckeys) == 0:
            common.alert(
                'You need an encryption key to use AutoCanary. Run the GPG Keychain program, generate a key, and run AutoCanary again.'
            )
            sys.exit(0)

    elif system == 'Linux':
        seckeys = gpg.seckeys_list()
        if len(seckeys) == 0:
            common.alert(
                'You need an encryption key to use AutoCanary. Generate a key, and run AutoCanary again.'
            )
            sys.exit(0)

    elif system == 'Windows':
        if not gpg.is_gpg_available():
            common.alert(
                'GPG doesn\'t seem to be installed. Install <a href="http://gpg4win.org/">Gpg4win</a>, generate a key, and run AutoCanary again.'
            )
            sys.exit(0)

        seckeys = gpg.seckeys_list()
        if len(seckeys) == 0:
            common.alert(
                'You need an encryption key to use AutoCanary. Run the Kleopatra program, generate a new personal OpenPGP key pair, and run AutoCanary again.'
            )
            sys.exit(0)

    # start the gui
    gui = AutoCanaryGui(app, gpg, headlines)
    sys.exit(app.exec_())
示例#2
0
    def save_to_file_clicked(self):
        d = QtGui.QFileDialog(caption='Save to File')
        d.setAcceptMode(QtGui.QFileDialog.AcceptSave)
        d.setDefaultSuffix('asc')
        d.setNameFilter('*.asc')
        if d.exec_():
            filename = d.selectedFiles()[0]

            # save output to file
            try:
                open(filename, 'w').write(self.signed_message)
                common.alert('Digitally signed cannary message saved to:\n{0}'.format(filename))
                self.accept()
            except:
                common.alert('Failed saving file:\n{0}'.format(filename))
示例#3
0
    def fetch_headlines(self):
        # --- feed.entries is empty list on fail.
        feed = feedparser.parse(config['feed_url'])

        # --- available keys: summary_detail published_parsed links title
        # comments summary guidislink title_detail link published id
        entry_data = map(lambda x: (x.title, ), feed.entries)
        headlines = map(
            lambda x: "{}{}".format(config['headline_bullet'], x[0]),
            entry_data)
        if len(headlines) == 0:
            self.have_headlines = False
            common.alert("Couldn't fetch headlines.")
        else:
            self.have_headlines = True
            self.store_headlines(headlines)
示例#4
0
    def save_to_file_clicked(self):
        d = QtGui.QFileDialog(caption='Save to File')
        d.setAcceptMode(QtGui.QFileDialog.AcceptSave)
        d.setDefaultSuffix('asc')
        d.setNameFilter('*.asc')
        if d.exec_():
            # this is a QString (character string).
            filename = d.selectedFiles()[0]

            filename_encoded = u'{}'.format(filename)

            # save output to file; don't forget to encode.
            try:
                open(filename_encoded, 'w').write(self.signed_message.encode('utf-8'))
                common.alert(u'Digitally signed canary message saved to:\n{0}'.format(filename_encoded))
                self.accept()
            except:
                common.alert(u'Failed saving file:\n{0}'.format(filename_encoded))
示例#5
0
    def copy_to_clipboard_clicked(self):
        if platform.system() == 'Windows':
            # Qt's QClipboard isn't working in Windows
            import ctypes
            GMEM_DDESHARE = 0x2000
            ctypes.windll.user32.OpenClipboard(None)
            ctypes.windll.user32.EmptyClipboard()
            hcd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(self.signed_message))+1)
            pch_data = ctypes.windll.kernel32.GlobalLock(hcd)
            ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pch_data), bytes(self.signed_message))
            ctypes.windll.kernel32.GlobalUnlock(hcd)
            ctypes.windll.user32.SetClipboardData(1, hcd)
            ctypes.windll.user32.CloseClipboard()
        else:
            clipboard = self.app.clipboard()
            clipboard.setText(self.signed_message)

        common.alert('Digitally signed cannary message copied to clipboard')
        self.accept()
示例#6
0
    def sign(self):
        frequency = self.frequency.currentText()
        year = self.year.currentText()
        year_period = self.get_year_period()
        status = str(self.status.currentText())
        text = str(self.textbox.toPlainText())

        if self.headlines.enabled and self.headlines.have_headlines:
            text = '\n\n'.join([text, self.headlines.headlines_str, ''])

        # add headers
        period_date = year_period
        if frequency == 'Quarterly':
            if year_period == 'Q1':
                period_date = 'January 1 to March 31'
            elif year_period == 'Q2':
                period_date = 'April 1 to June 30'
            elif year_period == 'Q3':
                period_date = 'July 1 to September 30'
            elif year_period == 'Q4':
                period_date = 'October 1 to December 31'
        elif frequency == 'Semiannually':
            if year_period == 'Q12':
                period_date = 'January 1 to June 30'
            elif year_period == 'Q34':
                period_date = 'July 1 to December 31'

        # the QString objects which represent the widget state are unicode
        # strings, hence the u'...'
        message = u'Status: {}\nPeriod: {}, {}\n\n{}'.format(
            status, period_date, year, text)

        # sign the file
        key_i = self.key_selection.currentIndex()
        fp = self.gpg.seckeys_list()[key_i]['fp']
        signed_message = self.gpg.sign(message, fp)

        if signed_message:
            # display signed message
            dialog = OutputDialog(self.app, signed_message)
            dialog.exec_()
        else:
            common.alert('Failed to sign message.')
示例#7
0
    def sign(self):
        frequency = self.frequency.currentText()
        year = self.year.currentText()
        year_period = self.get_year_period()
        status = str(self.status.currentText())
        text = self.textbox.toPlainText()

        # add headers
        period_date = year_period
        if frequency == 'Quarterly':
            if year_period == 'Q1':
                period_date = 'January 1 to March 31'
            elif year_period == 'Q2':
                period_date = 'April 1 to June 30'
            elif year_period == 'Q3':
                period_date = 'July 1 to September 30'
            elif year_period == 'Q4':
                period_date = 'October 1 to December 31'
        elif frequency == 'Semiannually':
            if year_period == 'Q12':
                period_date = 'January 1 to June 30'
            elif year_period == 'Q34':
                period_date = 'July 1 to December 31'

        # the QString objects which represent the widget state are unicode
        # strings, hence the u'...'
        message = u'Status: {}\nPeriod: {}, {}\n\n{}'.format(status, period_date, year, text)

        # sign the file
        key_i = self.key_selection.currentIndex()
        fp = self.gpg.seckeys_list()[key_i]['fp']
        signed_message = self.gpg.sign(message, fp)

        if signed_message:
            # display signed message
            dialog = OutputDialog(self.app, signed_message)
            dialog.exec_()
        else:
            common.alert('Failed to sign message.')
示例#8
0
    def save_to_file_clicked(self):
        d = QtGui.QFileDialog(caption='Save to File')
        d.setAcceptMode(QtGui.QFileDialog.AcceptSave)
        d.setDefaultSuffix('asc')
        d.setNameFilter('*.asc')
        if d.exec_():
            # this is a QString (character string).
            filename = d.selectedFiles()[0]

            filename_encoded = u'{}'.format(filename)

            # save output to file; don't forget to encode.
            try:
                open(filename_encoded,
                     'w').write(self.signed_message.encode('utf-8'))
                common.alert(
                    u'Digitally signed canary message saved to:\n{0}'.format(
                        filename_encoded))
                self.accept()
            except:
                common.alert(
                    u'Failed saving file:\n{0}'.format(filename_encoded))
示例#9
0
    def sign(self):
        frequency = self.frequency.currentText()
        year = self.year.currentText()
        year_period = self.get_year_period()
        status = str(self.status.currentText())
        text = self.textbox.toPlainText()

        # add headers
        period_date = year_period
        if frequency == 'Quarterly':
            if year_period == 'Q1':
                period_date = 'January 1 to March 31'
            elif year_period == 'Q2':
                period_date = 'April 1 to June 30'
            elif year_period == 'Q3':
                period_date = 'July 1 to September 30'
            elif year_period == 'Q4':
                period_date = 'October 1 to December 31'
        elif frequency == 'Semiannually':
            if year_period == 'Q12':
                period_date = 'January 1 to June 30'
            elif year_period == 'Q34':
                period_date = 'July 1 to December 31'
        message = 'Status: {}\nPeriod: {}, {}\n\n{}'.format(
            status, period_date, year, text)

        # sign the file
        key_i = self.key_selection.currentIndex()
        fp = self.gpg.seckeys_list()[key_i]['fp']
        signed_message = self.gpg.sign(message, fp)

        if signed_message:
            # display signed message
            dialog = OutputDialog(self.app, signed_message)
            dialog.exec_()
        else:
            common.alert('Failed to sign message.')
示例#10
0
def main():
    # start the app
    app = QtGui.QApplication(sys.argv)

    # initialize and check for gpg and a secret key
    gpg = GnuPG()

    system = platform.system()
    if system == 'Darwin':
        if not gpg.is_gpg_available():
            common.alert('GPG doesn\'t seem to be installed. Install <a href="https://gpgtools.org/">GPGTools</a>, generate a key, and run AutoCanary again.')
            sys.exit(0)

        seckeys = gpg.seckeys_list()
        if len(seckeys) == 0:
            common.alert('You need an encryption key to use AutoCanary. Run the GPG Keychain program, generate a key, and run AutoCanary again.')
            sys.exit(0)

    elif system == 'Linux':
        seckeys = gpg.seckeys_list()
        if len(seckeys) == 0:
            common.alert('You need an encryption key to use AutoCanary. Generate a key, and run AutoCanary again.')
            sys.exit(0)

    elif system == 'Windows':
        if not gpg.is_gpg_available():
            common.alert('GPG doesn\'t seem to be installed. Install <a href="http://gpg4win.org/">Gpg4win</a>, generate a key, and run AutoCanary again.')
            sys.exit(0)

        seckeys = gpg.seckeys_list()
        if len(seckeys) == 0:
            common.alert('You need an encryption key to use AutoCanary. Run the Kleopatra program, generate a new personal OpenPGP key pair, and run AutoCanary again.')
            sys.exit(0)

    # start the gui
    gui = AutoCanaryGui(app, gpg)
    sys.exit(app.exec_())
示例#11
0
import RPi.GPIO as gpio

# installable via pip
from filelock import Timeout, FileLock

# common source
from common import alert, path, max_buffer_size

gpio.setmode(gpio.BOARD)
gpio.setup(11, gpio.IN)
filename = os.path.join(path, 'data', 'buffer.dat')

with FileLock(filename + '.lock', timeout=2):
    
    # try to read old dataset, if it doesn't exist
    # initialize an empty buffer
    try:
        with open(filename, 'rt') as f:
            data = f.readlines()
    except:
        data = []
        
    wateralarm = 1-gpio.input(11)

    if wateralarm:
        alert('DANGER: WATERALARM ACTIVE!')

    with open(filename, 'wt') as f:
        f.writelines(data[-(max_buffer_size-1):])
        f.write("""{{"time": "{}", "value": {}}}\n""".format(datetime.now().isoformat(), wateralarm))
示例#12
0
 def other_org(self):
     common.alert('This has not been implemented yet. For now, choose one of the SecureDrop instances from the official list.')
示例#13
0
#!/usr/bin/python
"""
this script installs an interrupt to trigger actions asap
"""

from datetime import datetime
import os
import time
import RPi.GPIO as gpio

# installable via pip
from common import alert, path

gpio.setmode(gpio.BOARD)
gpio.setup(11, gpio.IN)

while True:
    try:
        channel = gpio.wait_for_edge(11, gpio.RISING)
        if channel is not None:
            alert("DANGER: WATERALARM TRIGGERED")

            with open(os.path.join(path, 'data', 'incidents.dat'), 'a') as f:
                f.write("""{{"time": "{}", "value": {}}}\n""".format(
                    datetime.now(), 1))

        else:
            print("fatal error")
    except Exception as e:
        print(e)
示例#14
0
 def login(self):
     common.alert('Login is not yet implemented.')
示例#15
0
 def create_account(self):
     common.alert('Create account is not yet implemented.')