mirror of
https://github.com/adulau/crl-monitor.git
synced 2024-11-22 01:57:05 +00:00
Option to store certificate in keystore added
This commit is contained in:
parent
80049f8f30
commit
cdbccbc256
1 changed files with 26 additions and 0 deletions
|
@ -13,6 +13,15 @@ import base64
|
||||||
import argparse
|
import argparse
|
||||||
import redis
|
import redis
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
def bpath(ha=None, level=6):
|
||||||
|
if ha is None:
|
||||||
|
return False
|
||||||
|
fn = ""
|
||||||
|
for i in range(0, level*2, 2):
|
||||||
|
fn = fn + "/"+ ha[i:2+i]
|
||||||
|
return fn
|
||||||
|
|
||||||
argParser = argparse.ArgumentParser(description='Dump DN from X.509 certificates')
|
argParser = argparse.ArgumentParser(description='Dump DN from X.509 certificates')
|
||||||
argParser.add_argument('-c', action='store_true', default=True, help='Dump CSV')
|
argParser.add_argument('-c', action='store_true', default=True, help='Dump CSV')
|
||||||
|
@ -20,6 +29,8 @@ argParser.add_argument('-s', action='store_true', default=False, help='Store in
|
||||||
argParser.add_argument('-b', default='127.0.0.1', help='Redis host (default is 127.0.0.1)')
|
argParser.add_argument('-b', default='127.0.0.1', help='Redis host (default is 127.0.0.1)')
|
||||||
argParser.add_argument('-p', default=6379, help='Redis TCP port (default is 6379)')
|
argParser.add_argument('-p', default=6379, help='Redis TCP port (default is 6379)')
|
||||||
argParser.add_argument('-v', action='store_true', help='Verbose output')
|
argParser.add_argument('-v', action='store_true', help='Verbose output')
|
||||||
|
argParser.add_argument('-k', default=False, action='store_true', help='Add certificate to keystore')
|
||||||
|
argParser.add_argument('-d', default=None, help='Certificate directory')
|
||||||
argParser.add_argument('-r', default='-', help='Read from a file, default is stdin')
|
argParser.add_argument('-r', default='-', help='Read from a file, default is stdin')
|
||||||
args = argParser.parse_args()
|
args = argParser.parse_args()
|
||||||
|
|
||||||
|
@ -31,6 +42,11 @@ if args.s:
|
||||||
print "Unable to connect to the Redis server"
|
print "Unable to connect to the Redis server"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if args.k:
|
||||||
|
if args.d is None:
|
||||||
|
print "You need to set the certificate directory -d"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
for cert in fileinput.input(args.r):
|
for cert in fileinput.input(args.r):
|
||||||
try:
|
try:
|
||||||
fp = cert.split(",")[0]
|
fp = cert.split(",")[0]
|
||||||
|
@ -40,6 +56,16 @@ for cert in fileinput.input(args.r):
|
||||||
print "Padding error "+fileinput.lineno()
|
print "Padding error "+fileinput.lineno()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if args.k:
|
||||||
|
p = args.d + "/" + bpath(ha=fp)
|
||||||
|
if not os.path.exists(p):
|
||||||
|
os.makedirs(p)
|
||||||
|
fn = os.path.join(p,fp)
|
||||||
|
if not os.path.exists(fn):
|
||||||
|
f = open(fn, 'w+')
|
||||||
|
f.write(certb)
|
||||||
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
x509 = X509.load_cert_string(certb, X509.FORMAT_DER)
|
x509 = X509.load_cert_string(certb, X509.FORMAT_DER)
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in a new issue