summaryrefslogtreecommitdiff
path: root/__init__.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-01-24 12:03:45 -0200
committerdrebs <drebs@leap.se>2013-01-24 12:03:45 -0200
commit71df5a4431bce607550eec4425f4fdfbdbfa2af7 (patch)
treef71347068d0a9296c857a5027728130e7ed14ca8 /__init__.py
parent3bf11c9109a457ddbeb47524e34a5c1fd97bd27c (diff)
parent2f761fea9e72554806b012c64d00fcae80e1d254 (diff)
Merge branch 'feature/soledad-api' into develop
Conflicts: src/leap/soledad/util.py
Diffstat (limited to '__init__.py')
-rw-r--r--__init__.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/__init__.py b/__init__.py
index 1473da38..cbd4bb0d 100644
--- a/__init__.py
+++ b/__init__.py
@@ -10,12 +10,13 @@ from leap.soledad.backends import sqlcipher
from leap.soledad.util import GPGWrapper
import util
+
class Soledad(object):
# paths
- PREFIX = os.environ['HOME'] + '/.config/leap/soledad'
- SECRET_PATH = PREFIX + '/secret.gpg'
- GNUPG_HOME = PREFIX + '/gnupg'
+ PREFIX = os.environ['HOME'] + '/.config/leap/soledad'
+ SECRET_PATH = PREFIX + '/secret.gpg'
+ GNUPG_HOME = PREFIX + '/gnupg'
LOCAL_DB_PATH = PREFIX + '/soledad.u1db'
# other configs
@@ -52,7 +53,8 @@ class Soledad(object):
def _has_secret(self):
"""
- Verify if secret for symmetric encryption exists on local encrypted file.
+ Verify if secret for symmetric encryption exists on local encrypted
+ file.
"""
# TODO: verify if file is a GPG-encrypted file and if we have the
# corresponding private key for decryption.
@@ -66,16 +68,20 @@ class Soledad(object):
"""
try:
with open(self.SECRET_PATH) as f:
- self._secret = str(self._gpg.decrypt(f.read()))
+ self._secret = str(self._gpg.decrypt(f.read()))
except IOError as e:
- raise IOError('Failed to open secret file %s.' % self.SECRET_PATH)
+ raise IOError('Failed to open secret file %s.' % self.SECRET_PATH)
def _gen_secret(self):
"""
- Generate a secret for symmetric encryption and store in a local encrypted file.
+ Generate a secret for symmetric encryption and store in a local
+ encrypted file.
"""
- self._secret = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(self.SECRET_LENGTH))
- ciphertext = self._gpg.encrypt(self._secret, self._fingerprint, self._fingerprint)
+ self._secret = ''.join(random.choice(string.ascii_uppercase +
+ string.digits) for x in
+ range(self.SECRET_LENGTH))
+ ciphertext = self._gpg.encrypt(self._secret, self._fingerprint,
+ self._fingerprint)
f = open(self.SECRET_PATH, 'w')
f.write(str(ciphertext))
f.close()
@@ -100,11 +106,11 @@ class Soledad(object):
Generate an OpenPGP keypair for this user.
"""
params = self._gpg.gen_key_input(
- key_type='RSA',
- key_length=4096,
- name_real=self._user_email,
- name_email=self._user_email,
- name_comment='Generated by LEAP Soledad.')
+ key_type='RSA',
+ key_length=4096,
+ name_real=self._user_email,
+ name_email=self._user_email,
+ name_comment='Generated by LEAP Soledad.')
self._gpg.gen_key(params)
def _load_openpgp_keypair(self):
@@ -129,7 +135,8 @@ class Soledad(object):
Encrypt data.
"""
return str(self._gpg.encrypt(data, self._fingerprint, sign=sign,
- passphrase=passphrase, symmetric=symmetric))
+ passphrase=passphrase,
+ symmetric=symmetric))
def encrypt_symmetric(self, doc_id, data, sign=None):
"""
@@ -208,4 +215,3 @@ class Soledad(object):
return self._db.sync(url, creds=None, autocreate=True, soledad=self)
__all__ = ['util']
-