Skip to content

Commit

Permalink
Merge 530fa2b into 5bf80d1
Browse files Browse the repository at this point in the history
  • Loading branch information
chtavares committed Mar 6, 2019
2 parents 5bf80d1 + 530fa2b commit 54c98f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ def test_can_get_private_key_path_from_environment(self):
observed = self.config.get_private_key_path()
self.assertEqual(observed, 'some-path')

def test_get_private_key_path_raises_error_if_not_set(self):
with self.assertRaises(ValueError):
self.config.get_private_key_path()

def test_set_command_does_not_override_previous_settings(self):
self.config.set('foo', 'bar')
self.config.set('bar', 'foo')
Expand Down
6 changes: 5 additions & 1 deletion uhu/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import configparser
import os
import logging

from .utils import get_global_config_file, get_credentials, PRIVATE_KEY_FN

Expand Down Expand Up @@ -37,7 +38,10 @@ def get_private_key_path(self):
pub_fn = self.get('private_key_path', AUTH_SECTION)
private_key = env_fn or pub_fn
if not private_key:
raise ValueError('Could not find any private key.')
logging.debug(
'The private key path is not set.'
'Update package won\'t be signed.')
return
return private_key

def set_credentials(self, access_id, access_secret):
Expand Down
5 changes: 4 additions & 1 deletion uhu/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def dump_package_archive(package, output=None, force=False):
signature = sign_dict(metadata, config.get_private_key_path())
metadata = json.dumps(metadata, sort_keys=True)
with zipfile.ZipFile(output, mode='w') as archive:
archive.writestr('signature', signature)
if signature is None:
archive.writestr('signature', "")
else:
archive.writestr('signature', signature)
archive.writestr('metadata', metadata)
for obj in package.objects.all():
sha256sum = obj['sha256sum']
Expand Down
4 changes: 3 additions & 1 deletion uhu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def sign_dict(dict_, private_key):
try:
with open(private_key) as fp:
key = RSA.importKey(fp.read())
except (FileNotFoundError, ValueError, IndexError, TypeError):
except TypeError:
return
except (FileNotFoundError, ValueError, IndexError):
raise ValueError('Invalid private key file.')

signer = PKCS1_v1_5.new(key)
Expand Down

0 comments on commit 54c98f0

Please sign in to comment.