Example #1
0
def get_sample_private_key(pkcs1=False):
    if pkcs1:
        private_key = kss.get_private_key_der_pkcs1(keys.get_private_key_pem())
        key_format_type = misc.KeyFormatType(enums.KeyFormatType.PKCS_1)
    else:
        private_key = keys.get_private_key_der()
        key_format_type = misc.KeyFormatType(enums.KeyFormatType.PKCS_8)
    key_material = objects.KeyMaterial(private_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.PrivateKey(key_block)
Example #2
0
    def test_convert_private_key_core_to_pie(self):
        """
        Test that a core private key can be converted into a Pie private key.
        """
        format_type = misc.KeyFormatType(enums.KeyFormatType.PKCS_8)
        algorithm = attributes.CryptographicAlgorithm(
            enums.CryptographicAlgorithm.RSA)
        length = attributes.CryptographicLength(2048)
        key_material = cobjects.KeyMaterial(self.private_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.PrivateKey(key_block)

        pie_key = self.factory.convert(core_key)
        self.assertIsInstance(pie_key, pobjects.PrivateKey)
        self._test_pie_key(pie_key, algorithm.value, length.value,
                           self.private_bytes, format_type.value)