relevent query to how to fetch public key from public key server

ぃ、小莉子 提交于 2019-12-06 11:47:43

问题


import urllib

response = urllib.urlopen('http://pool.sks-keyservers.net/')
print 'RESPONSE:', response
print 'URL     :', response.geturl()

headers = response.info()
print 'DATE    :', headers['date']
print 'HEADERS :'
print '---------'
print headers

data = response.read()
print 'LENGTH  :', len(data)
print 'DATA    :'
print '---------'
print data

This code enable me to see some webpage information and contents. what actually i had query that how to fetch the public key from any public key server using python function.


回答1:


This spec should help you along, and stop you asking the same question repeatedly :). Basically you need to perform an HTTP GET request to the key server. Most key servers work on TCP port 11371 so you need to ensure that your firewall will let you through.

For example, this URL will give you God's public key:

http://pool.sks-keyservers.net:11371/pks/lookup?op=get&search=0x1278A1862492D908&options=mr

The response is the key.

In python:

import urllib
f = urllib.urlopen('http://pool.sks-keyservers.net:11371/pks/lookup?op=get&search=0x1278A1862492D908&options=mr')
data = f.read()
print data

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.1.0

mQGiBD/dywoRBADkaddBEedMhFHGH3wKORuOIDFufSDERmlm2ktj3ma+GhfwvnuvvpAj+QYl
ANh1K86Mm5k0dGOlhZwIr1zB3cIoNqt7TJ62v8w6mc0BA8UWzWJp0i6dHPa/qeeFFC53B8U1
h3FlPrmQGcVeV+hjOPFU7ANDSDm3tduad7NRxAst7QCg/8o++2BaAlTnbMB+Xfo23uEEc6UE
AK0vD4EUPLfU5snfow1zUPXQUDalOcUP6RIhbi6yxKRFAIWI+7QgNPZf/Q2CFIRWsXKmW/ly
IDSJgs5ruB+Yj8gmBZlrn5KMmW3EcEoHAhOP+ONZAIOb2LsaAjHjHOuefhlIr1T3gng+kLoD
3Yfy2WTugBizeNybAd2nfZyOJhfWA/4xTfg+Hbcb9n+8sEqgiuyQJEID38Q3FDmwSzRfBMbO
JFrf8t/VHPjB7ZSdshl9GM86TXYnWjspzAjjQB8fxLgIim2mC0T46aRNdE0l2ozxRmS95nr7
YuHVA73vcI5tRn6qa9yLXew1YeN3YWxR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

Usage example:

>>> from hkp import KeyServer
>>> serv = KeyServer('http://pool.sks-keyservers.net')
>>> serv.search('Dmitry Gladkov')
[Key 28DFA7EC RSA (Encrypt or Sign), Key 473C57D9 RSA (Encrypt or Sign)]
>>> serv.search('Dmitry Gladkov')[0].identities
[Identity Dmitry Gladkov (dgl) <dmitry.gladkov@gmail.com>]


来源:https://stackoverflow.com/questions/1304130/relevent-query-to-how-to-fetch-public-key-from-public-key-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!