def test_get_public_key(self): test_public_key = rsa.generate_private_key( public_exponent=65537, key_size=2048, backend=default_backend()).public_key() key_info = dogtag_key.KeyInfo() key_info.public_key = test_public_key.public_bytes( serialization.Encoding.DER, serialization.PublicFormat.PKCS1) self.keyclient_mock.get_key_info.return_value = key_info secret_metadata = { dogtag_import.DogtagKRAPlugin.ALG: sstore.KeyAlgorithm.RSA, dogtag_import.DogtagKRAPlugin.BIT_LENGTH: 2048, dogtag_import.DogtagKRAPlugin.KEY_ID: 'key1', dogtag_import.DogtagKRAPlugin.CONVERT_TO_PEM: 'true' } result = self.plugin.get_secret(sstore.SecretType.PUBLIC, secret_metadata) self.assertEqual( test_public_key.public_bytes( serialization.Encoding.PEM, serialization.PublicFormat.PKCS1), result.secret )
def test_get_public_key(self): test_public_key = RSA.generate(2048).publickey() key_info = dogtag_key.KeyInfo() key_info.public_key = test_public_key.exportKey('DER') self.keyclient_mock.get_key_info.return_value = key_info secret_metadata = { dogtag_import.DogtagKRAPlugin.ALG: sstore.KeyAlgorithm.RSA, dogtag_import.DogtagKRAPlugin.BIT_LENGTH: 2048, dogtag_import.DogtagKRAPlugin.KEY_ID: 'key1', dogtag_import.DogtagKRAPlugin.CONVERT_TO_PEM: 'true' } result = self.plugin.get_secret(sstore.SecretType.PUBLIC, secret_metadata) self.assertEqual( test_public_key.exportKey('PEM').encode('utf-8'), result.secret)