Beispiel #1
0
 def retrieve(cls, username):
     resp = CONN.get('/certificate/' + username)
     if not resp.status_code == 200:
         print(resp.text)
         return None
     try:
         r = resp.json()
         assert (r['valid'] == 'Valid' and r['username'] == username)
         cert_pem = bytes(r['certificate'], 'utf-8')
         #load cert and check is valid signature from cert auth
         # get exceptions and returns right!
         cert = Certificate(
             False,
             x509.load_pem_x509_certificate(cert_pem, default_backend()))
         if not cert.is_valid():
             return None
         return cert
     except KeyError:
         gui.msgbox(
             "Did not receive a valid certificate for the requested user!",
             'Certificate Retrieval Error')
         return None
Beispiel #2
0
def client_totals():
    hl = "-" * 54
    report = [
        "Client Totals",
        " {:^30} {:^10} {:^10}".format("Client", "Cost", "Sales"), hl
    ]

    total_cost, total_sales, total_qty = 0, 0, 0
    for row in CONN.query(CLIENT_TOTALS).merge('name', normalise_alias,
                                               'first_name', 'last_name',
                                               'company'):
        total_cost += replace_value(row['total_cost'], 0)
        total_sales += replace_value(row['total_sales'], 0)
        total_qty += replace_value(row['total_qty'], 0)

        report.append("|{:<30}|{:>10}|{:>10}|".format(row['name'],
                                                      row['total_cost'],
                                                      row['total_sales']))
    report.append(hl)
    report.append(" {:<30} {:>10} {:>10}".format("Total", total_cost,
                                                 total_sales))
    print('\n'.join(report))
Beispiel #3
0
 def is_revoked(self):
     cert = self.certificate
     username = cert.subject.get_attributes_for_oid(
         NameOID.COMMON_NAME)[0].value
     resp = CONN.get('/revocation_list/' + username)
     if not resp.status_code == 200:
         return False
     rev = x509.load_pem_x509_crl(
         bytes(resp.json()['revocation_list'], 'utf-8'), default_backend())
     if not rev.is_signature_valid(CA_KEY):
         gui.msgbox(
             "Signature check failed for the revocation list of user " +
             username +
             "! Make sure you have the right CA (root) certificate. Otherwise there might be a Man in the middle attack!",
             'FAILED SIGNATURE CHECK')
         return False
     for r in rev:
         if r.serial_number == cert.serial_number:
             gui.msgbox(
                 "The user's certificate has been revoked. Try to retrieve a new certificate from the server.",
                 'REVOKED CERTIFICATE')
             return True
     return False
Beispiel #4
0
 def send(self, buffer):
     CONN.post(self.resource + self.steps[self.step],
               data={'data': base64.b64encode(buffer)})
     self.step += 1
Beispiel #5
0
import easygui as gui
from connection import CONN
from Configuration.user import USER
from main_handler import menu




if __name__ == '__main__':

    while 1:
        #handle all the options in menu!
        if menu():
            break

    if USER.logout():
        print("Logged out.")
    else:
        print("Closing client without successful logout!")
    CONN.close()
Beispiel #6
0
def drop(table="lastrow"):
    # solved
    CURSOR.execute(f"DROP TABLE {table}")
    CONN.commit()
Beispiel #7
0
def update(row):
    # solved
    _set = settostr(zip(games_title, row))
    request = f"UPDATE lastrow SET {_set} WHERE rowid = 1"
    CURSOR.execute(request)
    CONN.commit()
Beispiel #8
0
def retrieve_file_list():
    resp = CONN.get(list_location)
    if not resp.status_code == 200:
        print(resp.json())
        return None
    owner = resp.json()['owner']
    shared = resp.json()['shared']
    owner_list = []
    shared_list = []
    no_access_list = []
    files = {}
    if owner:
        for key, value in owner.items():
            own, enc_name = File.parse_file_url(value)
            f = File.get_name(own, enc_name)
            if not f:
                continue
            if not f.name:
                files.update({
                    'Lost access due to private key change. Select to delete: ' + f.encrypted_name:
                    f
                })
                no_access_list += [
                    'Lost access due to private key change. Select to delete: '
                    + f.encrypted_name
                ]
            else:
                files.update({'Your file: ' + f.name: f})
                owner_list += ['Your file: ' + f.name]
    if shared:
        for key, value in shared.items():
            own, enc_name = File.parse_file_url(value)
            f = File.get_name(own, enc_name)
            if not f:
                continue
            if not f.name:
                files.update({
                    "Lost access due to private key change. Select to delete: {}/{}".format(
                        own, f.encrypted_name):
                    f
                })
                no_access_list += [
                    "Lost access due to private key change. Select to delete: {}/{}"
                    .format(own, f.encrypted_name)
                ]
            else:
                files.update({"Shared with you: {}/{}".format(own, f.name): f})
                shared_list += ["Shared with you: {}/{}".format(own, f.name)]
    if not len(owner_list) > 0 and not len(shared_list) > 0 and not len(
            no_access_list) > 0:
        gui.msgbox("No Files available!")
        return
    choice = gui.choicebox("Which File do you want to access?", 'Access files',
                           owner_list + shared_list + no_access_list)
    if choice:
        if choice == 'Add more choices':
            return
        f = files[choice]
        if choice.startswith("Lost access"):
            f.delete()
        else:
            f.options()
Beispiel #9
0
 def delete(self, notification):
     data = {"data": notification}
     CONN.delete('/notification/' + self.username, data=data)
     self.list.remove(notification)
Beispiel #10
0
def create(table):
    # solved
    request = f"CREATE TABLE {table} {table_header(table)}"
    CURSOR.execute(request)
    CONN.commit()