[Nym3-commit] r177 - trunk/nym3/Client
laurent at conuropsis.org
laurent at conuropsis.org
Fri Apr 8 17:20:28 CEST 2005
Author: laurent
Date: 2005-04-08 17:20:25 +0200 (Fri, 08 Apr 2005)
New Revision: 177
Modified:
trunk/nym3/Client/Keyring.py
trunk/nym3/Client/Main.py
Log:
Keyring stuff might start working now.
Modified: trunk/nym3/Client/Keyring.py
===================================================================
--- trunk/nym3/Client/Keyring.py 2005-04-06 06:25:13 UTC (rev 176)
+++ trunk/nym3/Client/Keyring.py 2005-04-08 15:20:25 UTC (rev 177)
@@ -25,26 +25,33 @@
import pickle
import random
+import nym3.Mail as Mail
from mixminion.Crypto import sha1, ctr_crypt, AES_KEY_LEN
+SALT_LEN = 8
+
class NewKeyring(Exception): pass
-
class Keyring:
"""Class that holds a user keyring.
Keys are stored in a file and are accessed via an abstract
handle (a string)."""
# TODO : this would need locking. Somewhere.
- def __init__(self, keyfile):
+ def __init__(self, keyfile, create = False):
self.keyfile = keyfile
+ self.status = 'encrypted'
try:
f = open(keyfile, 'r')
self.datastring = f.read()
f.close()
except IOError:
- raise NewKeyring()
- self.status = 'encrypted'
+ if create:
+ f = open(keyfile, "w")
+ f.close()
+ self.data = {}
+ self.status = "clear"
+ else: raise NewKeyring()
def decrypt(self, passphrase):
"""Decrypt the keyring"""
@@ -64,7 +71,7 @@
def _get_unused_handle(self):
handle = "42"
while self.data.has_key(handle):
- handle = Mail.genmid(8)
+ handle = Mail.genMid(8)
return handle
def store(self, key):
@@ -83,7 +90,7 @@
salt = ""
for i in range(0, SALT_LEN):
salt = salt + chr(random.randint(0, 255))
- key = sha1(salt + passphrase + salt)
+ key = sha1(salt + passphrase + salt)[:AES_KEY_LEN]
clear = pickle.dumps(self.data)
encrypted = ctr_crypt(clear, key)
digest = sha1(clear + salt)
Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py 2005-04-06 06:25:13 UTC (rev 176)
+++ trunk/nym3/Client/Main.py 2005-04-08 15:20:25 UTC (rev 177)
@@ -69,7 +69,7 @@
new[3] = new[3] & ~termios.ECHO # lflags
try:
termios.tcsetattr(fd, termios.TCSADRAIN, new)
- passwd = prompt(s)
+ passwd = self.prompt(s)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
return passwd
@@ -125,8 +125,10 @@
# the policy which we don't let the user change at this point for the sake
# of simplicity. So, let's store all of that in the account and prepare the
# message for the server.
+ pubring = None
+ secring = None
try:
- pubring = Keyring.Keyring(config.pubring_path)
+ pubring = Keyring.Keyring(config.pubring_path, create = True)
except: pass
try:
secring = Keyring.Keyring(config.secring_path)
@@ -140,7 +142,15 @@
if passphrase1 == passphrase2: break
# TODO : warn for an empty passphrase.
ui.display("Passphrases do not match.")
+ secring = Keyring.Keyring(config.secring_path, create = True)
+ idtag = secring.store(_cr.pk_encode_private_key(idKey))
+ enctag = secring.store(_cr.pk_encode_private_key(encKey))
+ pubring.update_key(idtag, _cr.pk_encode_public_key(idKey))
+ pubring.update_key(enctag, _cr.pk_encode_public_key(encKey))
+ secring.save(passphrase1)
+ pubring.save("nym3")
+
def main(args):
if len(args) < 2:
More information about the Nym3-commit
mailing list