mirror of
https://github.com/certbot/certbot.git
synced 2026-06-06 07:12:54 -04:00
use M2Crypto for getting public key length
This commit is contained in:
parent
a6f244ec76
commit
42999f7bb9
1 changed files with 4 additions and 8 deletions
|
|
@ -3,6 +3,7 @@
|
|||
# use OpenSSL to provide CSR-related operations
|
||||
|
||||
import subprocess, tempfile, re, pkcs10
|
||||
import M2Crypto
|
||||
# we can use tempfile.NamedTemporaryFile() to get tempfiles
|
||||
# to pass to OpenSSL subprocesses.
|
||||
|
||||
|
|
@ -15,14 +16,9 @@ def parse(csr):
|
|||
|
||||
def modulusbits(key):
|
||||
"""How many bits are in the modulus of this key?"""
|
||||
out, err = subprocess.Popen(["openssl", "rsa", "-pubin", "-text", "-noout"],shell=False,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate(key)
|
||||
if out and not err:
|
||||
try:
|
||||
size = re.search("(Public-Key|Modulus):? \(([0-9]+) bit\)", out).groups()[-1]
|
||||
except:
|
||||
return None
|
||||
return int(size)
|
||||
return None
|
||||
bio = M2Crypto.BIO.MemoryBuffer(key)
|
||||
pubkey = M2Crypto.RSA.load_pub_key_bio(bio)
|
||||
return len(pubkey)
|
||||
|
||||
def goodkey(key):
|
||||
"""Does this public key comply with our CA policy?"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue