Beispiel #1
0
    def test_build_pie_asymmetric_key(self):
        """
        Test that a core asymmetric key object can be converted into a Pie
        asymmetric object.
        """
        format_type = misc.KeyFormatType(enums.KeyFormatType.PKCS_1)
        algorithm = attributes.CryptographicAlgorithm(
            enums.CryptographicAlgorithm.RSA)
        length = attributes.CryptographicLength(2048)
        key_material = cobjects.KeyMaterial(self.public_bytes)
        key_value = cobjects.KeyValue(key_material)
        key_block = cobjects.KeyBlock(
            key_format_type=format_type,
            key_compression_type=None,
            key_value=key_value,
            cryptographic_algorithm=algorithm,
            cryptographic_length=length,
            key_wrapping_data=None)
        core_key = secrets.PublicKey(key_block)
        pie_key = self.factory._build_pie_key(core_key, pobjects.PublicKey)

        self.assertIsInstance(pie_key, pobjects.PublicKey)
        self._test_pie_key(
            pie_key, algorithm.value, length.value, self.public_bytes,
            format_type.value)
Beispiel #2
0
def get_sample_public_key(pkcs1=False):
    if pkcs1:
        public_key = kss.get_public_key_der_pkcs1(keys.get_public_key_pem())
        key_format_type = misc.KeyFormatType(enums.KeyFormatType.PKCS_1)
    else:
        public_key = keys.get_public_key_der()
        key_format_type = misc.KeyFormatType(enums.KeyFormatType.X_509)

    key_material = objects.KeyMaterial(public_key)
    key_value = objects.KeyValue(key_material)
    key_block = objects.KeyBlock(
        key_format_type=key_format_type,
        key_compression_type=None,
        key_value=key_value,
        cryptographic_algorithm=attr.CryptographicAlgorithm(
            enums.CryptographicAlgorithm.RSA),
        cryptographic_length=attr.CryptographicLength(2048),
        key_wrapping_data=None)
    return secrets.PublicKey(key_block)