Require private key to have a matching certificate
Showing
-
mentioned in commit slapcache@2db8bcf1
-
mentioned in commit tomo/slapos.core@41cbe596
... | ... | @@ -9,7 +9,23 @@ class Error(Exception): pass |
FILETYPE_PEM = 1 | ||
class X509(object): | ||
pass | ||
def dump_publickey(type, pkey): | ||
assert type == FILETYPE_PEM, type | ||
pkey.seek(0, 0) | ||
r = pkey.read() | ||
if not r.startswith('-----BEGIN PUBLIC KEY-----'): | ||
Please
register
or
sign in
to reply
|
||
p = Popen(("openssl", "rsa", "-in", pkey.name, "-pubout"), | ||
stdout=PIPE, stderr=PIPE) | ||
r, err = p.communicate() | ||
if p.poll(): | ||
raise Error(err) | ||
return r | ||
def load_privatekey(type, buffer): | ||
assert type == FILETYPE_PEM, type | ||
r = _tmpfile() | ||
r.write(buffer.encode()) | ||
r.flush() | ||
... | ... | @@ -17,13 +33,16 @@ def load_privatekey(type, buffer): |
def load_certificate(type, buffer): | ||
# extract public key since we only use it to verify signatures | ||
assert type == FILETYPE_PEM, type | ||
r = _tmpfile() | ||
p = Popen(("openssl", "x509", "-pubkey", "-noout"), | ||
stdin=PIPE, stdout=r, stderr=PIPE) | ||
err = p.communicate(buffer.encode())[1] | ||
if p.poll(): | ||
raise Error(err) | ||
return r | ||
cert = X509() | ||
cert.get_pubkey = lambda: r | ||
return cert | ||
def sign(pkey, data, digest): | ||
p = Popen(("openssl", digest, "-sign", pkey.name), | ||
... | ... | @@ -37,8 +56,8 @@ def verify(cert, signature, data, digest): |
with _tmpfile() as f: | ||
f.write(signature) | ||
f.flush() | ||
p = Popen(("openssl", digest, "-verify", cert.name, "-signature", f.name), | ||
stdin=PIPE, stdout=PIPE, stderr=STDOUT) | ||
p = Popen(("openssl", digest, "-verify", cert.get_pubkey().name, | ||
"-signature", f.name), stdin=PIPE, stdout=PIPE, stderr=STDOUT) | ||
err = p.communicate(data)[0] | ||
if p.poll(): | ||
raise Error(err) |
mentioned in commit slapcache@2db8bcf1
·mentioned in commit slapcache@2db8bcf1
mentioned in commit tomo/slapos.core@41cbe596
·mentioned in commit tomo/slapos.core@41cbe596