RpIdHashValidator { public void validate(byte[] rpIdHash, CoreServerProperty serverProperty) { AssertUtil.notNull(serverProperty, "serverProperty must not be null"); String rpId = serverProperty.getRpId(); AssertUtil.notNull(rpId, "rpId must not be null"); MessageDigest messageDigest = MessageDigestUtil.createSHA256(); byte[] relyingPartyRpIdBytes = rpId.getBytes(StandardCharsets.UTF_8); byte[] relyingPartyRpIdHash = messageDigest.digest(relyingPartyRpIdBytes); if (!Arrays.equals(rpIdHash, relyingPartyRpIdHash)) { throw new BadRpIdException("rpIdHash doesn't match the hash of preconfigured rpId."); } }  void validate(byte[] rpIdHash, CoreServerProperty serverProperty);  }
@Test void verifyRpIdHash_test() { String rpIdA = "example.com"; String rpIdB = "example.com"; byte[] rpIdBytesA = rpIdA.getBytes(StandardCharsets.UTF_8); byte[] rpIdHashA = MessageDigestUtil.createSHA256().digest(rpIdBytesA); ServerProperty serverProperty = new ServerProperty(origin, rpIdB, null, null); target.validate(rpIdHashA, serverProperty); }
@Test void verifyRpIdHash_test_with_different_rpIds() { String rpIdA = "sub.example.com"; String rpIdB = "example.com"; byte[] rpIdBytesA = rpIdA.getBytes(StandardCharsets.UTF_8); byte[] rpIdHashA = MessageDigestUtil.createSHA256().digest(rpIdBytesA); ServerProperty serverProperty = new ServerProperty(origin, rpIdB, null, null); assertThrows(BadRpIdException.class, () -> target.validate(rpIdHashA, serverProperty) ); }
@Test void verifyRpIdHash_test_with_relyingParty_null() { String rpIdA = "example.com"; String rpIdB = "example.com"; byte[] rpIdBytesA = rpIdA.getBytes(StandardCharsets.UTF_8); byte[] rpIdHashA = MessageDigestUtil.createSHA256().digest(rpIdBytesA); assertThrows(IllegalArgumentException.class, () -> target.validate(rpIdHashA, null) ); }
@Test void verifyRpIdHash_test_with_relyingParty_rpId_null() { String rpIdA = "example.com"; String rpIdB = "example.com"; byte[] rpIdBytesA = rpIdA.getBytes(StandardCharsets.UTF_8); byte[] rpIdHashA = MessageDigestUtil.createSHA256().digest(rpIdBytesA); ServerProperty serverProperty = new ServerProperty(origin, null, null, null); assertThrows(IllegalArgumentException.class, () -> target.validate(rpIdHashA, serverProperty) ); }