Exemple #1
0
	cfg[sect] = dict()
	for (name, value) in _cfg.items(sect):
		cfg[sect][name] = value

if cfg.has_key('database') and cfg['database'].has_key('enabled') and cfg['database']['enabled'] == 'yes' and cfg['database'].has_key('name') and cfg['database'].has_key('host') and cfg['database'].has_key('username') and cfg['database'].has_key('password'):
	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:
Exemple #2
0
    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])
Exemple #3
0
        msg = MIMEMultipart("alternative")
        msg["From"] = cfg['mailregister']['register_email']
        msg["To"] = from_addr
        msg["Subject"] = "S/MIME certificate registration succeeded"

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

        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()