Commit 03f01032 authored by Alain Takoudjou's avatar Alain Takoudjou

disallow anonymous and email options

parent 43d4c9a0
...@@ -36,13 +36,7 @@ def main(): ...@@ -36,13 +36,7 @@ def main():
" which actually encodes your allocated prefix in the network." " which actually encodes your allocated prefix in the network."
" You can repeat this option to add any field you want to its" " You can repeat this option to add any field you want to its"
" subject.") " subject.")
_('--email',
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.") _('--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)
...@@ -103,15 +97,7 @@ def main(): ...@@ -103,15 +97,7 @@ def main():
cert_fd = token_advice = None cert_fd = token_advice = None
try: try:
token = config.token if not token:
if config.anonymous:
if not (token is config.email is None):
parser.error("--anonymous conflicts with --email/--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" token_advice = "Use --token to retry without asking a new token\n"
while not token: while not token:
token = raw_input('Please enter your token: ') token = raw_input('Please enter your token: ')
......
...@@ -290,38 +290,9 @@ class RegistryServer(object): ...@@ -290,38 +290,9 @@ class RegistryServer(object):
@rpc @rpc
def requestToken(self, email): def requestToken(self, email):
with self.lock: logging.info("This re6st version doesn't allow client to request token. Email is %s" %
while True: email)
# Generating token return
token = ''.join(random.sample(string.ascii_lowercase, 8))
args = token, email, self.config.prefix_length, int(time.time())
# Updating database
try:
self.db.execute("INSERT INTO token VALUES (?,?,?,?)", args)
break
except sqlite3.IntegrityError:
pass
self.timeout = 1
# Creating and sending email
msg = MIMEText('Hello, your token to join re6st network is: %s\n'
% token)
msg['Subject'] = '[re6stnet] Token Request'
if self.email:
msg['From'] = self.email
msg['To'] = email
if os.path.isabs(self.config.mailhost) or \
os.path.isfile(self.config.mailhost):
with self.lock:
m = mailbox.mbox(self.config.mailhost)
try:
m.add(msg)
finally:
m.close()
else:
s = smtplib.SMTP(self.config.mailhost)
s.sendmail(self.email, email, msg.as_string())
s.quit()
@rpc @rpc
def requestAddToken(self, token, email): def requestAddToken(self, token, email):
...@@ -381,20 +352,17 @@ class RegistryServer(object): ...@@ -381,20 +352,17 @@ 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: 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 = ?", (token,)).next()
(token,)).next() except StopIteration:
except StopIteration: return
return if not token:
self.db.execute("DELETE FROM token WHERE token = ?", logging.info("Empty token is not allowed for this re6st version.")
(token,)) return
else: self.db.execute("DELETE FROM token WHERE token = ?",
prefix_len = self.config.anonymous_prefix_length (token,))
if not prefix_len:
return
email = None
prefix = self.newPrefix(prefix_len) prefix = self.newPrefix(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