-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdkpriv
More file actions
executable file
·31 lines (27 loc) · 937 Bytes
/
dkpriv
File metadata and controls
executable file
·31 lines (27 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python3
#
# SPDX-License-Identifier: 0BSD
# Part of badkeys: https://badkeys.info/
#
# Sometimes, people accidentally publish private keys in DKIM records,
# script to extract them.
import argparse
import base64
import pathlib
from cryptography.hazmat.primitives import serialization
ap = argparse.ArgumentParser()
ap.add_argument("input", nargs="+")
args = ap.parse_args()
for fn in args.input:
raw = pathlib.Path(fn).read_text()
raw = raw.replace(" ", "").replace('"', "")
for el in raw.split(";"):
if el.startswith("p="):
bkey = el[2:]
break
der = base64.b64decode(bkey.encode())
pkey = serialization.load_der_private_key(der, password=None)
pem = pkey.private_bytes(serialization.Encoding.PEM,
serialization.PrivateFormat.TraditionalOpenSSL,
serialization.NoEncryption()).decode()
print(pem, end="")