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(): ...@@ -93,15 +93,18 @@ def main():
cert_fd = token_advice = None cert_fd = token_advice = None
try: try:
token = config.token
if config.anonymous: 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") parser.error("--anonymous conflicts with --email/--token")
elif not config.token: token = ''
elif not token:
if not config.email: if not config.email:
config.email = raw_input('Please enter your email address: ') config.email = raw_input('Please enter your email address: ')
s.requestToken(config.email) s.requestToken(config.email)
token_advice = "Use --token to retry without asking a new token\n" 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: try:
with open(key_path) as f: with open(key_path) as f:
...@@ -125,7 +128,7 @@ def main(): ...@@ -125,7 +128,7 @@ def main():
# to avoid using our token for nothing. # to avoid using our token for nothing.
cert_fd = os.open(cert_path, os.O_CREAT | os.O_WRONLY, 0666) cert_fd = os.open(cert_path, os.O_CREAT | os.O_WRONLY, 0666)
print "Requesting certificate ..." print "Requesting certificate ..."
cert = s.requestCertificate(config.token, req) cert = s.requestCertificate(token, req)
if not cert: if not cert:
token_advice = None token_advice = None
sys.exit("Error: invalid or expired token") sys.exit("Error: invalid or expired token")
......
...@@ -179,12 +179,7 @@ class RegistryServer(object): ...@@ -179,12 +179,7 @@ class RegistryServer(object):
req = crypto.load_certificate_request(crypto.FILETYPE_PEM, req) req = crypto.load_certificate_request(crypto.FILETYPE_PEM, req)
with self.lock: with self.lock:
with self.db: with self.db:
if token is None: if token:
prefix_len = self.config.anonymous_prefix_length
if not prefix_len:
return
email = None
else:
try: try:
token, email, prefix_len, _ = self.db.execute( token, email, prefix_len, _ = self.db.execute(
"SELECT * FROM token WHERE token = ?", "SELECT * FROM token WHERE token = ?",
...@@ -193,6 +188,11 @@ class RegistryServer(object): ...@@ -193,6 +188,11 @@ class RegistryServer(object):
return return
self.db.execute("DELETE FROM token WHERE token = ?", self.db.execute("DELETE FROM token WHERE token = ?",
(token,)) (token,))
else:
prefix_len = self.config.anonymous_prefix_length
if not prefix_len:
return
email = None
prefix = self._getPrefix(prefix_len) prefix = self._getPrefix(prefix_len)
self.db.execute("UPDATE cert SET email = ? WHERE prefix = ?", self.db.execute("UPDATE cert SET email = ? WHERE prefix = ?",
(email, 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