Example #1
0
	connection = MySQLdb.connect(host = cfg['database']['host'], user = cfg['database']['username'], passwd = cfg['database']['password'], db = cfg['database']['name'], port = 3306)
	cursor = connection.cursor()

	# import keys
	cursor.execute("SELECT publickey, id, email FROM gpgmw_keys WHERE status = 0 AND confirm = '' LIMIT 100")
	result_set = cursor.fetchall()

	for row in result_set:
		# delete any other public keys associated with this confirmed email address
		cursor.execute("DELETE FROM gpgmw_keys WHERE email = %s AND id != %s", (row[2], row[1],))
		GnuPG.delete_key(cfg['gpg']['keyhome'], row[2])
		appendLog('Deleted key for <' + row[2] + '> via import request')

		if row[0].strip(): # we have this so that user can submit blank key to remove any encryption
			if GnuPG.confirm_key(row[0], row[2]):
				GnuPG.add_key(cfg['gpg']['keyhome'], row[0]) # import the key to gpg
				cursor.execute("UPDATE gpgmw_keys SET status = 1 WHERE id = %s", (row[1],)) # mark key as accepted
				appendLog('Imported key from <' + row[2] + '>')
				if cfg['cron'].has_key('send_email') and cfg['cron']['send_email'] == 'yes':
					send_msg( "PGP key registration successful", "registrationSuccess.md", row[2] )
			else:
				cursor.execute("DELETE FROM gpgmw_keys WHERE id = %s", (row[1],)) # delete key
				appendLog('Import confirmation failed for <' + row[2] + '>')
				if cfg['cron'].has_key('send_email') and cfg['cron']['send_email'] == 'yes':
					send_msg( "PGP key registration failed", "registrationError.md", row[2] )
		else:
			# delete key so we don't continue processing it
			cursor.execute("DELETE FROM gpgmw_keys WHERE id = %s", (row[1],))
			if cfg['cron'].has_key('send_email') and cfg['cron']['send_email'] == 'yes':
				send_msg( "PGP key deleted", "keyDeleted.md", row[2])
Example #2
0
    result_set = cursor.fetchall()

    for row in result_set:
        # delete any other public keys associated with this confirmed email address
        cursor.execute("DELETE FROM gpgmw_keys WHERE email = %s AND id != %s",
                       (
                           row[2],
                           row[1],
                       ))
        GnuPG.delete_key(cfg['gpg']['keyhome'], row[2])
        appendLog('Deleted key for <' + row[2] + '> via import request')

        if row[0].strip(
        ):  # we have this so that user can submit blank key to remove any encryption
            if GnuPG.confirm_key(row[0], row[2]):
                GnuPG.add_key(cfg['gpg']['keyhome'],
                              row[0])  # import the key to gpg
                cursor.execute(
                    "UPDATE gpgmw_keys SET status = 1 WHERE id = %s",
                    (row[1], ))  # mark key as accepted
                appendLog('Imported key from <' + row[2] + '>')
                if cfg['cron'].has_key(
                        'send_email') and cfg['cron']['send_email'] == 'yes':
                    send_msg("PGP key registration successful",
                             "registrationSuccess.md", row[2])
            else:
                cursor.execute("DELETE FROM gpgmw_keys WHERE id = %s",
                               (row[1], ))  # delete key
                appendLog('Import confirmation failed for <' + row[2] + '>')
                if cfg['cron'].has_key(
                        'send_email') and cfg['cron']['send_email'] == 'yes':
                    send_msg("PGP key registration failed",
Example #3
0
        send_msg(msg, cfg['mailregister']['register_email'], [from_addr])

        log("S/MIME Registration succeeded")
    elif sign_type == 'pgp':
        # send POST to gpg-mailgate webpanel
        sig = sign_part

        GnuPG.delete_key(cfg['gpg']['keyhome'], from_addr)
        log('Deleted key for <%s> via import request' % from_addr)

        if from_addr.strip(
        ):  # we have this so that user can submit blank key to remove any encryption
            if not GnuPG.confirm_key(sig, from_addr):
                log("Can not verify sig for email <%s>" % from_addr)
            try:
                GnuPG.add_key(cfg['gpg']['keyhome'],
                              sig)  # import the key to gpg
                log("PGP registration success")
            except:
                log("Could not hand registration over to GPGMW. Error: %s" %
                    r.status_code)
                error_msg = file(cfg['mailregister']['mail_templates'] +
                                 "/gpgmwFailed.md").read()
                error_msg = error_msg.replace("[:FROMADDRESS:]", from_addr)

                msg = MIMEMultipart("alternative")
                msg["From"] = cfg['mailregister']['register_email']
                msg["To"] = from_addr
                msg["Subject"] = "PGP key registration failed"

                msg.attach(MIMEText(error_msg, 'plain'))
                msg.attach(MIMEText(markdown.markdown(error_msg), 'html'))