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():
help="Email address where your token is sent. Use -r option if you"
" want to show an email in your certificate.")
_('--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()
if config.dir:
os.chdir(config.dir)
......@@ -39,7 +42,7 @@ def main():
dh_path = 'dh2048.pem'
# Establish connection with server
s = xmlrpclib.ServerProxy(config.registry)
s = xmlrpclib.ServerProxy(config.registry, allow_none=True)
# Get CA
create(ca_path, s.getCa())
......@@ -74,7 +77,10 @@ def main():
cert_fd = token_advice = None
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:
config.email = raw_input('Please enter your email address: ')
s.requestToken(config.email)
......
......@@ -72,8 +72,11 @@ class main(object):
_('--private',
help="re6stnet IP of the node on which runs the registry."
" Required for normal operation.")
_('--prefix-length', default=16,
_('--prefix-length', default=16, type=int,
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',
help="Path to logging file.")
_('-v', '--verbose', default=1, type=int,
......@@ -199,11 +202,19 @@ class main(object):
try:
req = crypto.load_certificate_request(crypto.FILETYPE_PEM, cert_req)
with self.db:
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,))
if token is None:
prefix_len = self.config.anonymous_prefix_length
if not prefix_len:
return
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
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