Package list python-castellan / fc5099d
Merge tag '0.19.0' into debian/rocky castellan 0.19.0 release meta:version: 0.19.0 meta:diff-start: - meta:series: rocky meta:release-type: release meta:pypi: no meta:first: no meta:release:Author: Ben Nemec <bnemec@redhat.com> meta:release:Commit: Ben Nemec <bnemec@redhat.com> meta:release:Change-Id: Ida50e4359bfee903c25cef8ae4ba672c0a0e5d7d meta:release:Code-Review+1: Ade Lee <alee@redhat.com> meta:release:Code-Review+1: ChangBo Guo(gcb) <glongwave@gmail.com> meta:release:Code-Review+1: Dave McCowan <dmccowan@cisco.com> meta:release:Code-Review+2: Doug Hellmann <doug@doughellmann.com> meta:release:Code-Review+1: Matthew Thode <mthode@mthode.org> meta:release:Code-Review+2: Sean McGinnis <sean.mcginnis@gmail.com> meta:release:Workflow+1: Sean McGinnis <sean.mcginnis@gmail.com> Thomas Goirand 2 years ago
5 changed file(s) with 71 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
11 host=review.openstack.org
22 port=29418
33 project=openstack/castellan.git
4 defaultbranch=stable/rocky
5858 - castellan-functional-devstack
5959 - openstack-tox-lower-constraints
6060 - barbican-simple-crypto-devstack-tempest-castellan-from-git
61 templates:
62 - openstack-python-jobs
63 - openstack-python35-jobs
64 - release-notes-jobs-python3
65 - publish-openstack-docs-pti
66 - check-requirements
67 - periodic-stable-jobs
1414 """
1515
1616 import binascii
17 from cryptography.hazmat.backends import default_backend
18 from cryptography.hazmat.primitives.asymmetric import rsa
19 from cryptography.hazmat.primitives.serialization import Encoding
20 from cryptography.hazmat.primitives.serialization import NoEncryption
21 from cryptography.hazmat.primitives.serialization import PrivateFormat
22 from cryptography.hazmat.primitives.serialization import PublicFormat
23
1724 import os
1825 import time
1926 import uuid
94101 def create_key_pair(self, context, algorithm, length,
95102 expiration=None, name=None):
96103 """Creates an asymmetric key pair."""
97 raise NotImplementedError(
98 "VaultKeyManager does not support asymmetric keys")
104
105 # Confirm context is provided, if not raise forbidden
106 if not context:
107 msg = _("User is not authorized to use key manager.")
108 raise exception.Forbidden(msg)
109
110 if algorithm.lower() != 'rsa':
111 raise NotImplementedError(
112 "VaultKeyManager only implements rsa keys"
113 )
114
115 priv_key = rsa.generate_private_key(
116 public_exponent=65537,
117 key_size=length,
118 backend=default_backend()
119 )
120
121 private_key = pri_key.PrivateKey(
122 'RSA',
123 length,
124 priv_key.private_bytes(
125 Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()
126 )
127 )
128
129 private_key_id = uuid.uuid4().hex
130 private_id = self._store_key_value(
131 private_key_id,
132 private_key
133 )
134
135 # pub_key = priv_key.public_key()
136 public_key = pub_key.PublicKey(
137 'RSA',
138 length,
139 priv_key.public_key().public_bytes(
140 Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
141 )
142 )
143
144 public_key_id = uuid.uuid4().hex
145 public_id = self._store_key_value(
146 public_key_id,
147 public_key
148 )
149
150 return private_id, public_id
99151
100152 def _store_key_value(self, key_id, value):
101153
5555 def tearDown(self):
5656 super(VaultKeyManagerTestCase, self).tearDown()
5757
58 def test_create_key_pair(self):
59 self.assertRaises(NotImplementedError,
60 self.key_mgr.create_key_pair, None, None, None)
61
6258 def test_create_null_context(self):
6359 self.assertRaises(exception.Forbidden,
6460 self.key_mgr.create_key, None, 'AES', 256)
6561
6662 def test_create_key_pair_null_context(self):
67 self.assertRaises(NotImplementedError,
63 self.assertRaises(exception.Forbidden,
6864 self.key_mgr.create_key_pair, None, 'RSA', 2048)
65
66 def test_create_key_pair_bad_algorithm(self):
67 self.assertRaises(
68 NotImplementedError,
69 self.key_mgr.create_key_pair,
70 self.ctxt, 'DSA', 2048
71 )
6972
7073 def test_delete_null_context(self):
7174 key_uuid = self._get_valid_object_uuid(
1010 VIRTUAL_ENV={envdir}
1111 OS_TEST_PATH=./castellan/tests/unit
1212 deps =
13 -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt}
13 -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/rocky}
1414 -r{toxinidir}/requirements.txt
1515 -r{toxinidir}/test-requirements.txt
1616 commands = python setup.py testr --slowest --testr-args='{posargs}'