get subject public key and use it to encrypt dvsni parameter r as y

This commit is contained in:
Seth Schoen 2012-07-03 18:03:30 -07:00
parent 0fa6fb49c4
commit 6df1976070

View file

@ -3,7 +3,8 @@
import web, redis, time
import CSR
from Crypto.Hash import SHA256, HMAC
from Crypto import Random
from Crypto.PublicKey import RSA
from Crypto import Random
from chocolate_protocol_pb2 import chocolatemessage
from google.protobuf.message import DecodeError
@ -102,6 +103,10 @@ class session(object):
"""Has there already been a signing request made in this session?"""
return sessions.hget(self.id, "state") is not None
def pubkey(self):
"""Return the PEM-formatted subject public key from the CSR."""
return CSR.pubkey(sessions.hget(self.id, "csr"))
def cert(self):
"""Return the issued certificate."""
return sessions.hget(self.id, "cert")
@ -276,8 +281,12 @@ class session(object):
chall.type = int(c["type"])
chall.name = c["name"]
chall.succeeded = (c["satisfied"] == "True") # TODO: this contradicts comment in protocol about meaning of "succeeded"
chall.data.append(c["dvsni:r"])
# Calculate y
dvsni_r = c["dvsni:r"]
y = RSA.importKey(self.pubkey()).encrypt(dvsni_r, None)[0]
# In dvsni, we send nonce, y, ext
chall.data.append(c["dvsni:nonce"])
chall.data.append(y)
chall.data.append(c["dvsni:ext"])
def POST(self):