mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
20 hours ago 2863452733f1815ce5557ff01cfe148b49e182b0
opendj-server-legacy/src/test/java/org/opends/server/crypto/RsaSveKeyTransportTestCase.java
@@ -120,19 +120,18 @@
  @Test
  public void testAnotherPrivateKeyCannotUnwrap() throws Exception
  {
    KeyPair other;
    do
    {
      other = rsaKeyPair(2048);
    }
    while (modulus(other).compareTo(modulus(keyPair)) <= 0);
    final KeyPair otherKeyPair = other;
    final KeyPair secondKeyPair = rsaKeyPair(2048);
    final int modulusOrder = modulus(keyPair).compareTo(modulus(secondKeyPair));
    assertThat(modulusOrder).as("the two RSA moduli must differ").isNotZero();
    final KeyPair wrappingKeyPair = modulusOrder < 0 ? keyPair : secondKeyPair;
    final KeyPair wrongKeyPair = modulusOrder < 0 ? secondKeyPair : keyPair;
    final SecretKey key = new SecretKeySpec(bytes(16, 0x3C), "AES");
    inProviders(BC_FIPS, () ->
    {
      final byte[] wrapped = RsaSveKeyTransport.wrap(keyPair.getPublic(), key, KEY_ID, random);
      assertThatThrownBy(() -> RsaSveKeyTransport.unwrap(otherKeyPair, wrapped, "AES", KEY_ID))
          .isInstanceOf(GeneralSecurityException.class);
      final byte[] wrapped = RsaSveKeyTransport.wrap(wrappingKeyPair.getPublic(), key, KEY_ID, random);
      assertThatThrownBy(() -> RsaSveKeyTransport.unwrap(wrongKeyPair, wrapped, "AES", KEY_ID))
          .isInstanceOf(InvalidKeyException.class)
          .hasMessage(RsaSveKeyTransport.NAME + " cannot unwrap the key");
      return null;
    });
  }