- Update dknewkey.py to use argparse. Add --ktype option to specify

different key type options in anticipation of the DCRUP WG output.
This commit is contained in:
Scott Kitterman
2017-06-22 18:08:01 -04:00
parent e06014404c
commit ddc1cbd61f
2 changed files with 20 additions and 7 deletions
+2
View File
@@ -6,6 +6,8 @@ UNRELEASED Version 0.7.0
- Add command line option to dkimsign.py to select signing algorithm - Add command line option to dkimsign.py to select signing algorithm
- For dknewkey.py make default to include h=sha256 in the DNS record to - For dknewkey.py make default to include h=sha256 in the DNS record to
exclude usage with sha1. Can be overriden. exclude usage with sha1. Can be overriden.
- Update dknewkey.py to use argparse. Add --ktype option to specify
different key type options in anticipation of the DCRUP WG output.
2017-05-30 Version 0.6.2 2017-05-30 Version 0.6.2
- Fixed problem with header folding that caused the first line to be - Fixed problem with header folding that caused the first line to be
+18 -7
View File
@@ -32,6 +32,7 @@ import os
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import argparse
# how strong are our keys? # how strong are our keys?
BITS_REQUIRED = 2048 BITS_REQUIRED = 2048
@@ -51,7 +52,7 @@ def GenKeys(private_key_file):
str(BITS_REQUIRED)]) str(BITS_REQUIRED)])
def ExtractDnsPublicKey(private_key_file, dns_file): def ExtractDnsPublicKey(private_key_file, dns_file, key_type='rsa'):
""" Given a key, extract the bit we should place in DNS. """ Given a key, extract the bit we should place in DNS.
""" """
print >> sys.stderr, 'extracting ' + private_key_file print >> sys.stderr, 'extracting ' + private_key_file
@@ -66,18 +67,28 @@ def ExtractDnsPublicKey(private_key_file, dns_file):
dns_fp = open(dns_file, "w+") dns_fp = open(dns_file, "w+")
print >> sys.stderr, 'writing ' + dns_file print >> sys.stderr, 'writing ' + dns_file
if HTAG: if HTAG:
print >> dns_fp, "k=rsa; h={0}; p={1}".format(HTAG,output) print >> dns_fp, "k={0} h={1}; p={2}".format(key_type,HTAG,output)
else: else:
print >> dns_fp, "k=rsa; p=%s" % output print >> dns_fp, "k={0}; p={1}".format(key_type, output)
dns_fp.close() dns_fp.close()
def main(argv): def main(argv):
if len(argv) != 2: parser = argparse.ArgumentParser(
print >> sys.stderr, '%s: <keyname>' % argv[0] description='Produce DKIM keys.',)
sys.exit(1) parser.add_argument('key_name', action="store")
parser.add_argument('--ktype', choices=['rsa',],
default='rsa',
help='DKIM key type: Default is rsa')
args=parser.parse_args()
if sys.version_info[0] >= 3:
args.key_name = bytes(args.key_name, encoding='UTF-8')
args.ktype = bytes(args.ktype, encoding='UTF-8')
# Make sys.stdin and stdout binary streams.
sys.stdin = sys.stdin.detach()
sys.stdout = sys.stdout.detach()
key_name = argv[1] key_name = args.key_name
private_key_file = key_name + '.key' private_key_file = key_name + '.key'
dns_file = key_name + '.dns' dns_file = key_name + '.dns'