Commit f9f4e5f3 authored by Julien Muchembled's avatar Julien Muchembled

Allow to join the network without email/token

parent 761f50c6
...@@ -30,6 +30,9 @@ def main(): ...@@ -30,6 +30,9 @@ def main():
help="Email address where your token is sent. Use -r option if you" help="Email address where your token is sent. Use -r option if you"
" want to show an email in your certificate.") " want to show an email in your certificate.")
_('--token', help="The token you received.") _('--token', help="The token you received.")
_('--anonymous', action='store_true',
help="Request an anonymous certificate. No email is required but the"
" registry may deliver a longer prefix.")
config = parser.parse_args() config = parser.parse_args()
if config.dir: if config.dir:
os.chdir(config.dir) os.chdir(config.dir)
...@@ -39,7 +42,7 @@ def main(): ...@@ -39,7 +42,7 @@ def main():
dh_path = 'dh2048.pem' dh_path = 'dh2048.pem'
# Establish connection with server # Establish connection with server
s = xmlrpclib.ServerProxy(config.registry) s = xmlrpclib.ServerProxy(config.registry, allow_none=True)
# Get CA # Get CA
create(ca_path, s.getCa()) create(ca_path, s.getCa())
...@@ -74,7 +77,10 @@ def main(): ...@@ -74,7 +77,10 @@ def main():
cert_fd = token_advice = None cert_fd = token_advice = None
try: try:
if not config.token: if config.anonymous:
if not (config.token is config.email is None):
parser.error("--anonymous conflicts with --email/--token")
elif not config.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)
......
...@@ -72,8 +72,11 @@ class main(object): ...@@ -72,8 +72,11 @@ class main(object):
_('--private', _('--private',
help="re6stnet IP of the node on which runs the registry." help="re6stnet IP of the node on which runs the registry."
" Required for normal operation.") " Required for normal operation.")
_('--prefix-length', default=16, _('--prefix-length', default=16, type=int,
help="Default length of allocated prefixes.") help="Default length of allocated prefixes.")
_('--anonymous-prefix-length', type=int,
help="Length of allocated anonymous prefixes."
" If 0 or unset, registration by email is required")
_('-l', '--logfile', default='/var/log/re6stnet/registry.log', _('-l', '--logfile', default='/var/log/re6stnet/registry.log',
help="Path to logging file.") help="Path to logging file.")
_('-v', '--verbose', default=1, type=int, _('-v', '--verbose', default=1, type=int,
...@@ -199,11 +202,19 @@ class main(object): ...@@ -199,11 +202,19 @@ class main(object):
try: try:
req = crypto.load_certificate_request(crypto.FILETYPE_PEM, cert_req) req = crypto.load_certificate_request(crypto.FILETYPE_PEM, cert_req)
with self.db: with self.db:
try: if token is None:
token, email, prefix_len, _ = self.db.execute("SELECT * FROM token WHERE token = ?", (token,)).next() prefix_len = self.config.anonymous_prefix_length
except StopIteration: if not prefix_len:
return return
self.db.execute("DELETE FROM token WHERE token = ?", (token,)) email = None
else:
try:
token, email, prefix_len, _ = self.db.execute(
"SELECT * FROM token WHERE token = ?",
(token,)).next()
except StopIteration:
return
self.db.execute("DELETE FROM token WHERE token = ?", (token,))
# Get a new prefix # Get a new prefix
prefix = self._getPrefix(prefix_len) prefix = self._getPrefix(prefix_len)
......
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