Class RsaTestResources


  • public final class RsaTestResources
    extends java.lang.Object
    Lists the RSA key sizes exercised by the test suite and locates the pre-generated test material (key pairs, self-signed certificate and signature) of a key size.

    The key sizes are read from the com.microej.crypto.test.rsa.keysizes property, a comma separated list of sizes in bits, shared by the key pair generation, cipher, signature and certificate tests. Each listed size must have its material in the test resources, named after the size (rsa_<size>.crt, rsa_<size>_priv.der, ...). The key pair generation tests can restrict the list further with their own property, see getKeyPairGeneratorKeySizes().

    • Field Detail

      • KEY_SIZES_PROPERTY

        public static final java.lang.String KEY_SIZES_PROPERTY
        Property listing the key sizes exercised by the test suite.
        See Also:
        Constant Field Values
      • KEY_PAIR_GENERATOR_KEY_SIZES_PROPERTY

        public static final java.lang.String KEY_PAIR_GENERATOR_KEY_SIZES_PROPERTY
        Optional property restricting KEY_SIZES_PROPERTY for the key pair generation tests.
        See Also:
        Constant Field Values
      • DEFAULT_KEY_SIZES

        public static final java.lang.String DEFAULT_KEY_SIZES
        Default key sizes: every size the test resources hold material for, hence every size KEY_SIZES_PROPERTY may list. A VEE Port whose backend lacks one of them restricts the list through the property.
        See Also:
        Constant Field Values
    • Method Detail

      • getKeySizes

        public static int[] getKeySizes()
        Gets the key sizes exercised by the test suite.
        Returns:
        the configured key sizes, or the default ones when the property is not set
        Throws:
        java.lang.IllegalStateException - if the property is set to an empty list
      • getKeyPairGeneratorKeySizes

        public static int[] getKeyPairGeneratorKeySizes()
        Gets the key sizes generated by the key pair generation tests: KEY_PAIR_GENERATOR_KEY_SIZES_PROPERTY when set, otherwise getKeySizes().
        Returns:
        the key sizes to generate
        Throws:
        java.lang.IllegalStateException - if the property lists a size that is not in getKeySizes()
      • certificatePath

        public static java.lang.String certificatePath​(int keySize)
        Gets the resource path of the DER self-signed certificate of the given key size.
        Parameters:
        keySize - the key size in bits
        Returns:
        the certificate resource path
      • privateKeyPath

        public static java.lang.String privateKeyPath​(int keySize)
        Gets the resource path of the PKCS#8 DER private key that signed the certificate of the given key size.
        Parameters:
        keySize - the key size in bits
        Returns:
        the private key resource path
      • protectedPrivateKeyPath

        public static java.lang.String protectedPrivateKeyPath​(int keySize)
        Gets the resource path of the private key of privateKeyPath(int), encrypted as PKCS#8 DER with the password changeit.
        Parameters:
        keySize - the key size in bits
        Returns:
        the encrypted private key resource path
      • publicKeyPath

        public static java.lang.String publicKeyPath​(int keySize)
        Gets the resource path of the X.509 DER public key matching privateKeyPath(int).
        Parameters:
        keySize - the key size in bits
        Returns:
        the public key resource path
      • alternatePublicKeyPath

        public static java.lang.String alternatePublicKeyPath​(int keySize)
        Gets the resource path of an X.509 DER public key of the given key size that is unrelated to the certificate.
        Parameters:
        keySize - the key size in bits
        Returns:
        the alternate public key resource path
      • signaturePath

        public static java.lang.String signaturePath​(int keySize)
        Gets the resource path of the SHA256withRSA signature of the data4096.bin resource, computed with privateKeyPath(int).

        RSA PKCS#1 v1.5 signing is deterministic, so this file is also the expected output of signing that resource with that key, and can be compared byte for byte.

        Parameters:
        keySize - the key size in bits
        Returns:
        the signature resource path