Commit d66d14a4 authored by Julien Muchembled's avatar Julien Muchembled

Fix anomymous registration

This fixes a regression introduced with new protocol to registry (commit
e24eb3f5), which can't transport None value.
parent eb964f4b
......@@ -93,15 +93,18 @@ def main():
cert_fd = token_advice = None
try:
token = config.token
if config.anonymous:
if not (config.token is config.email is None):
if not (token is config.email is None):
parser.error("--anonymous conflicts with --email/--token")
elif not config.token:
token = ''
elif not token:
if not config.email:
config.email = raw_input('Please enter your email address: ')
s.requestToken(config.email)
token_advice = "Use --token to retry without asking a new token\n"
config.token = raw_input('Please enter your token: ')
while not token:
token = raw_input('Please enter your token: ')
try:
with open(key_path) as f:
......@@ -125,7 +128,7 @@ def main():
# to avoid using our token for nothing.
cert_fd = os.open(cert_path, os.O_CREAT | os.O_WRONLY, 0666)
print "Requesting certificate ..."
cert = s.requestCertificate(config.token, req)
cert = s.requestCertificate(token, req)
if not cert:
token_advice = None
sys.exit("Error: invalid or expired token")
......
......@@ -179,12 +179,7 @@ class RegistryServer(object):
req = crypto.load_certificate_request(crypto.FILETYPE_PEM, req)
with self.lock:
with self.db:
if token is None:
prefix_len = self.config.anonymous_prefix_length
if not prefix_len:
return
email = None
else:
if token:
try:
token, email, prefix_len, _ = self.db.execute(
"SELECT * FROM token WHERE token = ?",
......@@ -193,6 +188,11 @@ class RegistryServer(object):
return
self.db.execute("DELETE FROM token WHERE token = ?",
(token,))
else:
prefix_len = self.config.anonymous_prefix_length
if not prefix_len:
return
email = None
prefix = self._getPrefix(prefix_len)
self.db.execute("UPDATE cert SET email = ? WHERE prefix = ?",
(email, prefix))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment