<reponame>philratcliffe/useful-scripts<filename>pgp/get_pgp_info.py
import pprint
import requests
import sys
from urlparse import urlparse

SERVERS = ["hkps://hkps.pool.sks-keyservers.net"]

# Example: python get_pgp_info.py <EMAIL> get

def get_info_from_keyserver(search_term, op_value="index"):

    for key_server in SERVERS:
        parse_result = urlparse(key_server)
        url = "https://{}/{}".format(parse_result.netloc, 'pks/lookup')
        payload = {'op':op_value, 'search':search_term, 'options':'mr',\
                'fingerprint':'on'}

        # Note: the CA verification cert is now included in this file.
        response = requests.get(url, params=payload, verify=__file__)

        if (search_term in response.text):
            break
    return response.text


if __name__ == '__main__':

    arg_list = []
    arg_count = len(sys.argv)

    if (arg_count < 2) or (arg_count > 3):
        sys.exit("\n\nUsage: {} search_term [op_value]\n\n".format(sys.argv[0]))

    arg_list.append(sys.argv[1])
    if arg_count > 2:
        arg_list.append(sys.argv[2])

    html_result = get_info_from_keyserver(*arg_list)
    pprint.pprint(html_result)


SKS_SERVERS_CA_CERT = """
-----BEGIN CERTIFICATE-----
<KEY>
-----END CERTIFICATE-----
"""


import pprint
import requests
import sys
from urlparse import urlparse

SERVERS = ["hkps://hkps.pool.sks-keyservers.net"]

# Example: python get_pgp_info.py <EMAIL> get

def get_info_from_keyserver(search_term, op_value="index"):

    for key_server in SERVERS:
        parse_result = urlparse(key_server)
        url = "https://{}/{}".format(parse_result.netloc, 'pks/lookup')
        payload = {'op':op_value, 'search':search_term, 'options':'mr',\
                'fingerprint':'on'}

        # Note: the CA verification cert is now included in this file.
        response = requests.get(url, params=payload, verify=__file__)

        if (search_term in response.text):
            break
    return response.text


if __name__ == '__main__':

    arg_list = []
    arg_count = len(sys.argv)

    if (arg_count < 2) or (arg_count > 3):
        sys.exit("\n\nUsage: {} search_term [op_value]\n\n".format(sys.argv[0]))

    arg_list.append(sys.argv[1])
    if arg_count > 2:
        arg_list.append(sys.argv[2])

    html_result = get_info_from_keyserver(*arg_list)
    pprint.pprint(html_result)


SKS_SERVERS_CA_CERT = """
-----BEGIN CERTIFICATE-----
<KEY>
-----END CERTIFICATE-----
"""
# Example: python get_pgp_info.py <EMAIL> get # Note: the CA verification cert is now included in this file. -----BEGIN CERTIFICATE----- <KEY> -----END CERTIFICATE-----