|
@@ -135,7 +135,6 @@ class CryptoEngine(object):
|
|
else:
|
|
else:
|
|
CryptoEngine._instance = CryptoEngine()
|
|
CryptoEngine._instance = CryptoEngine()
|
|
return CryptoEngine._instance
|
|
return CryptoEngine._instance
|
|
- # get = classmethod(get)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
"""Initialise the Cryptographic Engine
|
|
"""Initialise the Cryptographic Engine
|
|
@@ -218,13 +217,12 @@ class CryptoEngine(object):
|
|
"""
|
|
"""
|
|
return self._callback
|
|
return self._callback
|
|
|
|
|
|
- def get_user_password():
|
|
|
|
|
|
+ def get_user_password(self):
|
|
"get the password from the user"
|
|
"get the password from the user"
|
|
if self._callback is None:
|
|
if self._callback is None:
|
|
raise CryptoNoCallbackException("No call back class has been "
|
|
raise CryptoNoCallbackException("No call back class has been "
|
|
"specified")
|
|
"specified")
|
|
|
|
|
|
-
|
|
|
|
def changepassword(self):
|
|
def changepassword(self):
|
|
"""
|
|
"""
|
|
Creates a new key. The key itself is actually stored in
|
|
Creates a new key. The key itself is actually stored in
|
|
@@ -241,25 +239,23 @@ class CryptoEngine(object):
|
|
random = OSRNG.new()
|
|
random = OSRNG.new()
|
|
key = str(random.read(32)).encode('base64')
|
|
key = str(random.read(32)).encode('base64')
|
|
else:
|
|
else:
|
|
- password = self._callback.getsecret("Please enter your current \
|
|
|
|
-password")
|
|
|
|
|
|
+ password = self._callback.getsecret(("Please enter your current "
|
|
|
|
+ "password"))
|
|
cipher = self._getcipher_real(password, self._algo)
|
|
cipher = self._getcipher_real(password, self._algo)
|
|
plainkey = cipher.decrypt(str(self._keycrypted).decode('base64'))
|
|
plainkey = cipher.decrypt(str(self._keycrypted).decode('base64'))
|
|
key = self._retrievedata(plainkey)
|
|
key = self._retrievedata(plainkey)
|
|
|
|
|
|
- newpassword1 = self._callback.getsecret("Please enter your new \
|
|
|
|
|
|
+ newpassword1 = self._callback.getnewsecret("Please enter your new \
|
|
password")
|
|
password")
|
|
- newpassword2 = self._callback.getsecret("Please enter your new \
|
|
|
|
|
|
+ newpassword2 = self._callback.getnewsecret("Please enter your new \
|
|
password again")
|
|
password again")
|
|
while newpassword1 != newpassword2:
|
|
while newpassword1 != newpassword2:
|
|
print "Passwords do not match!"
|
|
print "Passwords do not match!"
|
|
- newpassword1 = self._callback.getsecret("Please enter your new \
|
|
|
|
|
|
+ newpassword1 = self._callback.getnewsecret("Please enter your new \
|
|
password")
|
|
password")
|
|
- newpassword2 = self._callback.getsecret("Please enter your new \
|
|
|
|
|
|
+ newpassword2 = self._callback.getnewsecret("Please enter your new \
|
|
password again")
|
|
password again")
|
|
|
|
|
|
- # if (newpassword1 != newpassword2):
|
|
|
|
- # raise CryptoPasswordMismatchException("Passwords do not match")
|
|
|
|
newcipher = self._getcipher_real(newpassword1, self._algo)
|
|
newcipher = self._getcipher_real(newpassword1, self._algo)
|
|
self._keycrypted = str(newcipher.encrypt(
|
|
self._keycrypted = str(newcipher.encrypt(
|
|
self._preparedata(key,
|
|
self._preparedata(key,
|
|
@@ -269,13 +265,14 @@ password again")
|
|
# them
|
|
# them
|
|
zerome(newpassword1)
|
|
zerome(newpassword1)
|
|
zerome(newpassword2)
|
|
zerome(newpassword2)
|
|
|
|
+ del(newpassword1)
|
|
|
|
+ del(newpassword2)
|
|
# we also want to create the cipher if there isn't one already
|
|
# we also want to create the cipher if there isn't one already
|
|
# so this CryptoEngine can be used from now on
|
|
# so this CryptoEngine can be used from now on
|
|
if self._cipher is None:
|
|
if self._cipher is None:
|
|
self._cipher = self._getcipher_real(str(key).decode('base64'),
|
|
self._cipher = self._getcipher_real(str(key).decode('base64'),
|
|
self._algo)
|
|
self._algo)
|
|
CryptoEngine._timeoutcount = time.time()
|
|
CryptoEngine._timeoutcount = time.time()
|
|
-
|
|
|
|
return self._keycrypted
|
|
return self._keycrypted
|
|
|
|
|
|
def alive(self):
|
|
def alive(self):
|
|
@@ -309,7 +306,6 @@ password again")
|
|
|
|
|
|
max_tries = 5
|
|
max_tries = 5
|
|
tries = 0
|
|
tries = 0
|
|
-
|
|
|
|
key = None
|
|
key = None
|
|
|
|
|
|
while tries < max_tries:
|
|
while tries < max_tries:
|