Change-Id: If4904c0eeac396eee7082d19784e440991131297
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
# See the License for the specific language governing permissions and
# limitations under the License.
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO add package version filling commit id with 0's; e.g.: '5.0.0.post11+00000000.dirty-1'
date_version = '2019-01-28'
# TODO add package version filling commit id with 0's; e.g.: '5.0.0.post11+00000000.dirty-1'
date_version = '2019-01-28'
encrypted_msg = b64decode(value)
cipher = AES.new(secret_key)
decrypted_msg = cipher.decrypt(encrypted_msg)
encrypted_msg = b64decode(value)
cipher = AES.new(secret_key)
decrypted_msg = cipher.decrypt(encrypted_msg)
- unpadded_private_msg = decrypted_msg.decode().rstrip('\0')
+ try:
+ unpadded_private_msg = decrypted_msg.decode().rstrip('\0')
+ except UnicodeDecodeError:
+ raise DbException("Cannot decrypt information. Are you using same COMMONKEY in all OSM components?",
+ http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
return unpadded_private_msg
return unpadded_private_msg
import unittest
from osm_common.dbbase import DbBase, DbException, deep_update
from os import urandom
import unittest
from osm_common.dbbase import DbBase, DbException, deep_update
from os import urandom
+from http import HTTPStatus
def exception_message(message):
def exception_message(message):
for j in range(i+1, len(encrypted)):
self.assertNotEqual(encrypted[i], encrypted[j],
"encryption with different salt must contain different result")
for j in range(i+1, len(encrypted)):
self.assertNotEqual(encrypted[i], encrypted[j],
"encryption with different salt must contain different result")
+ # decrypt with a different master key
+ try:
+ decrypted = self.db_bases[-1].decrypt(encrypted[0], schema_version='1.1', salt=None)
+ self.assertNotEqual(encrypted[0], decrypted, "Decryption with different KEY must generate different result")
+ except DbException as e:
+ self.assertEqual(e.http_code, HTTPStatus.INTERNAL_SERVER_ERROR,
+ "Decryption with different KEY does not provide expected http_code")
class TestDeepUpdate(unittest.TestCase):
class TestDeepUpdate(unittest.TestCase):