Skip to main content

A Library to get Keys from a keyserver specified

Project description

# hkp4py

A Library to get GPG/PGP keys from a Keyserver.
This library uses the requests module to get the keys.

## Tested Python Versions

### Python 2.7

* 2.7.15

### Python 3

* 3.7

## Intstall via [AUR](https://aur.archlinux.org/packages/python-hkp4py-git/)

## Install via [PyPI](https://pypi.org/project/hkp4py/)

```bash
pip install hkp4py

pip3 install hkp4py
```

## KeyServer

This object represents a keyserver using the hkp protocol.

### Initialize

Initialize the KeyServer object.

```python
from hkp4py import KeyServer


server = KeyServer("hkps://pgp.ext.selfnet.de")
```

### Add

Add keys to a keyserver.

```python
key = "a long key"
server.add(key)
```

### Search

Find keys with the keyserver object.

```python
keys = server.search('@gnupg.org') # search by string
keys = server.search('0x{}'.format('6F4B4E15768C8C4E'), exact=True) #search by fingerprint
```

### Key Object

```python
for key in keys:
# Key Basic Information
print("Key Algorithm:\t{}".format(key.algo))
print("Key fpr:\t{}".format(key.keyid))
print("Key Length:\t{}".format(key.key_length))
print("Disabled?\t{}".format('yes' if key.disabled else 'no'))
print("Expired?\t{}".format('yes' if key.expired else 'no'))
print("Revoked?\t{}".format('yes' if key.revoked else 'no'))
print("From Host:\t{}".format(key.host))
print("From Port:\t{}".format(key.port))
print("Date Created:\t{}".format(key.creation_date))
print("Date Expired:\t{}".format(key.expiration_date))
print(key.key)
```

#### Identity Object

```python
for identity in key.identities:
print("Identity:\t{}".format(identity.uid))
print("\tDisabled?\t{}".format('yes' if identity.disabled else 'no'))
print("\tExpired?\t{}".format('yes' if identity.expired else 'no'))
print("\tRevoked?\t{}".format('yes' if identity.revoked else 'no'))
print("\tDate Created:\t{}".format(identity.creation_date))
print("\tDate Expired:\t{}".format(identity.expiration_date))
```

## More Advanced options

To set a different User-Agent and proxies for veiling purposes.
The KeyServer has the following additional options for the connection.

```python
server = KeyServer("hkps://pgp.ext.selfnet.de",
proxies={"http": "socks5h://localhost:5050", "https":
"socks5h://localhost:5050"},
headers={"User-Agent": "Testing"})
```

## Import key with gpgme python bindings

```python
from __future__ import absolute_import, unicode_literals

import gpg

result = gpg.Context().key_import(key.key.encode("utf-8"))
```


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hkp4py-0.2.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hkp4py-0.2.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file hkp4py-0.2.1.0.tar.gz.

File metadata

  • Download URL: hkp4py-0.2.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for hkp4py-0.2.1.0.tar.gz
Algorithm Hash digest
SHA256 d608872e79af8b64af7a2d4c0385359724983c5f5e257c647890e0a6acb3b2fa
MD5 9ec6c1c30a45b05e7be038e394b67fd4
BLAKE2b-256 03271b29c6189829bd7bf768e6ce54696d780de676b9c9048c136d936304bdef

See more details on using hashes here.

File details

Details for the file hkp4py-0.2.1.0-py3-none-any.whl.

File metadata

  • Download URL: hkp4py-0.2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for hkp4py-0.2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b85fe8aaa4d71dffe246bcd6536f8e45cb1d46e3175f94430235dbb645dd8e7
MD5 f46cec062195b582818bc1eb46640fa8
BLAKE2b-256 ec92de0805d5797e3627e0544fc3c2c1b0dfe962deaa2874666964c24264167d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page