Program: 48145
Project: 48145
Buggy source:
/** 
 * Test for the VerifySignature Step of the Generic Cryptography protocol. After we connected to the ESIGN application of the eGK, we use DIDList to get a List of DIDs that support the compute signature function. We then authenticate with PIN.home and let the card sign our message. Afterwards we call VerifySignature for that signature which should return OK.
 * @throws Exception when something in this test went unexpectedly wrong
 */
@Test public void testVerifySignature() throws Exception {
  CardApplicationPath cardApplicationPath=new CardApplicationPath();
  CardApplicationPathType cardApplicationPathType=new CardApplicationPathType();
  cardApplicationPathType.setCardApplication(cardApplication);
  cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
  CardApplicationPathResponse cardApplicationPathResponse=instance.cardApplicationPath(cardApplicationPath);
  WSHelper.checkResult(cardApplicationPathResponse);
  CardApplicationConnect parameters=new CardApplicationConnect();
  CardAppPathResultSet cardAppPathResultSet=cardApplicationPathResponse.getCardAppPathResultSet();
  parameters.setCardApplicationPath(cardAppPathResultSet.getCardApplicationPathResult().get(0));
  CardApplicationConnectResponse result=instance.cardApplicationConnect(parameters);
  WSHelper.checkResult(result);
  assertEquals(ECardConstants.Major.OK,result.getResult().getResultMajor());
  DIDList didList=new DIDList();
  didList.setConnectionHandle(result.getConnectionHandle());
  DIDQualifierType didQualifier=new DIDQualifierType();
  didQualifier.setApplicationIdentifier(cardApplication);
  didQualifier.setObjectIdentifier(ECardConstants.Protocol.GENERIC_CRYPTO);
  didQualifier.setApplicationFunction("String_Node_Str");
  didList.setFilter(didQualifier);
  DIDListResponse didListResponse=instance.didList(didList);
  assertTrue(didListResponse.getDIDNameList().getDIDName().size() > 0);
  WSHelper.checkResult(didListResponse);
  DIDAuthenticate didAthenticate=new DIDAuthenticate();
  didAthenticate.setDIDName("String_Node_Str");
  PinCompareDIDAuthenticateInputType didAuthenticationData=new PinCompareDIDAuthenticateInputType();
  didAthenticate.setAuthenticationProtocolData(didAuthenticationData);
  didAthenticate.setConnectionHandle(result.getConnectionHandle());
  didAthenticate.getConnectionHandle().setCardApplication(cardApplication_ROOT);
  didAuthenticationData.setProtocol(ECardConstants.Protocol.PIN_COMPARE);
  didAthenticate.setAuthenticationProtocolData(didAuthenticationData);
  DIDAuthenticateResponse didAuthenticateResult=instance.didAuthenticate(didAthenticate);
  WSHelper.checkResult(didAuthenticateResult);
  assertEquals(didAuthenticateResult.getAuthenticationProtocolData().getProtocol(),ECardConstants.Protocol.PIN_COMPARE);
  assertEquals(didAuthenticateResult.getAuthenticationProtocolData().getAny().size(),0);
  assertEquals(ECardConstants.Major.OK,didAuthenticateResult.getResult().getResultMajor());
  for (int numOfDIDs=0; numOfDIDs < didListResponse.getDIDNameList().getDIDName().size(); numOfDIDs++) {
    String didName=didListResponse.getDIDNameList().getDIDName().get(numOfDIDs);
    DIDGet didGet=new DIDGet();
    didGet.setDIDName(didName);
    didGet.setDIDScope(DIDScopeType.LOCAL);
    didGet.setConnectionHandle(result.getConnectionHandle());
    didGet.getConnectionHandle().setCardApplication(cardApplication);
    DIDGetResponse didGetResponse=instance.didGet(didGet);
    Sign sign=new Sign();
    byte[] message=new byte[]{0x01,0x02,0x03};
    org.openecard.common.sal.anytype.CryptoMarkerType cryptoMarker=new org.openecard.common.sal.anytype.CryptoMarkerType((CryptoMarkerType)didGetResponse.getDIDStructure().getDIDMarker());
    String algorithmIdentifier=cryptoMarker.getAlgorithmInfo().getAlgorithmIdentifier().getAlgorithm();
    if (algorithmIdentifier.equals(GenericCryptoObjectIdentifier.id_RSASSA_PSS)) {
      MessageDigest messageDigest=MessageDigest.getInstance("String_Node_Str");
      message=messageDigest.digest(message);
    }
 else     if (algorithmIdentifier.equals(GenericCryptoObjectIdentifier.pkcs_1)) {
    }
 else {
      logger.warn("String_Node_Str",algorithmIdentifier);
      continue;
    }
    sign.setMessage(message);
    sign.setConnectionHandle(result.getConnectionHandle());
    sign.getConnectionHandle().setCardApplication(cardApplication);
    sign.setDIDName(didName);
    sign.setDIDScope(DIDScopeType.LOCAL);
    SignResponse signResponse=instance.sign(sign);
    assertEquals(ECardConstants.Major.OK,signResponse.getResult().getResultMajor());
    WSHelper.checkResult(signResponse);
    byte[] signature=signResponse.getSignature();
    VerifySignature verifySignature=new VerifySignature();
    verifySignature.setConnectionHandle(sign.getConnectionHandle());
    verifySignature.setDIDName(didName);
    verifySignature.setDIDScope(DIDScopeType.LOCAL);
    verifySignature.setMessage(message);
    verifySignature.setSignature(signature);
    VerifySignatureResponse verifySignatureResponse=instance.verifySignature(verifySignature);
    WSHelper.checkResult(verifySignatureResponse);
  }
}

Fixed version (ground truth):
/** 
 * Test for the VerifySignature Step of the Generic Cryptography protocol. After we connected to the ESIGN application of the eGK, we use DIDList to get a List of DIDs that support the compute signature function. We then authenticate with PIN.home and let the card sign our message. Afterwards we call VerifySignature for that signature which should return OK.
 * @throws Exception when something in this test went unexpectedly wrong
 */
@Test public void testVerifySignature() throws Exception {
  CardApplicationPath cardApplicationPath=new CardApplicationPath();
  CardApplicationPathType cardApplicationPathType=new CardApplicationPathType();
  cardApplicationPathType.setCardApplication(cardApplication);
  cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
  CardApplicationPathResponse cardApplicationPathResponse=instance.cardApplicationPath(cardApplicationPath);
  WSHelper.checkResult(cardApplicationPathResponse);
  CardApplicationConnect parameters=new CardApplicationConnect();
  CardAppPathResultSet cardAppPathResultSet=cardApplicationPathResponse.getCardAppPathResultSet();
  parameters.setCardApplicationPath(cardAppPathResultSet.getCardApplicationPathResult().get(0));
  CardApplicationConnectResponse result=instance.cardApplicationConnect(parameters);
  WSHelper.checkResult(result);
  assertEquals(ECardConstants.Major.OK,result.getResult().getResultMajor());
  DIDList didList=new DIDList();
  didList.setConnectionHandle(result.getConnectionHandle());
  DIDQualifierType didQualifier=new DIDQualifierType();
  didQualifier.setApplicationIdentifier(cardApplication);
  didQualifier.setObjectIdentifier(ECardConstants.Protocol.GENERIC_CRYPTO);
  didQualifier.setApplicationFunction("String_Node_Str");
  didList.setFilter(didQualifier);
  DIDListResponse didListResponse=instance.didList(didList);
  assertTrue(didListResponse.getDIDNameList().getDIDName().size() > 0);
  WSHelper.checkResult(didListResponse);
  DIDAuthenticate didAthenticate=new DIDAuthenticate();
  didAthenticate.setDIDName("String_Node_Str");
  PinCompareDIDAuthenticateInputType didAuthenticationData=new PinCompareDIDAuthenticateInputType();
  didAthenticate.setAuthenticationProtocolData(didAuthenticationData);
  didAthenticate.setConnectionHandle(result.getConnectionHandle());
  didAthenticate.getConnectionHandle().setCardApplication(cardApplication_ROOT);
  didAuthenticationData.setProtocol(ECardConstants.Protocol.PIN_COMPARE);
  didAthenticate.setAuthenticationProtocolData(didAuthenticationData);
  DIDAuthenticateResponse didAuthenticateResult=instance.didAuthenticate(didAthenticate);
  WSHelper.checkResult(didAuthenticateResult);
  assertEquals(didAuthenticateResult.getAuthenticationProtocolData().getProtocol(),ECardConstants.Protocol.PIN_COMPARE);
  assertEquals(didAuthenticateResult.getAuthenticationProtocolData().getAny().size(),0);
  assertEquals(ECardConstants.Major.OK,didAuthenticateResult.getResult().getResultMajor());
  for (int numOfDIDs=0; numOfDIDs < didListResponse.getDIDNameList().getDIDName().size(); numOfDIDs++) {
    String didName=didListResponse.getDIDNameList().getDIDName().get(numOfDIDs);
    DIDGet didGet=new DIDGet();
    didGet.setDIDName(didName);
    didGet.setDIDScope(DIDScopeType.LOCAL);
    didGet.setConnectionHandle(result.getConnectionHandle());
    didGet.getConnectionHandle().setCardApplication(cardApplication);
    DIDGetResponse didGetResponse=instance.didGet(didGet);
    Sign sign=new Sign();
    byte[] message=new byte[]{0x01,0x02,0x03};
    org.openecard.crypto.common.sal.CryptoMarkerType cryptoMarker=new org.openecard.crypto.common.sal.CryptoMarkerType((CryptoMarkerType)didGetResponse.getDIDStructure().getDIDMarker());
    String algorithmIdentifier=cryptoMarker.getAlgorithmInfo().getAlgorithmIdentifier().getAlgorithm();
    if (algorithmIdentifier.equals(GenericCryptoObjectIdentifier.id_RSASSA_PSS)) {
      MessageDigest messageDigest=MessageDigest.getInstance("String_Node_Str");
      message=messageDigest.digest(message);
    }
 else     if (algorithmIdentifier.equals(GenericCryptoObjectIdentifier.pkcs_1)) {
    }
 else {
      logger.warn("String_Node_Str",algorithmIdentifier);
      continue;
    }
    sign.setMessage(message);
    sign.setConnectionHandle(result.getConnectionHandle());
    sign.getConnectionHandle().setCardApplication(cardApplication);
    sign.setDIDName(didName);
    sign.setDIDScope(DIDScopeType.LOCAL);
    SignResponse signResponse=instance.sign(sign);
    assertEquals(ECardConstants.Major.OK,signResponse.getResult().getResultMajor());
    WSHelper.checkResult(signResponse);
    byte[] signature=signResponse.getSignature();
    VerifySignature verifySignature=new VerifySignature();
    verifySignature.setConnectionHandle(sign.getConnectionHandle());
    verifySignature.setDIDName(didName);
    verifySignature.setDIDScope(DIDScopeType.LOCAL);
    verifySignature.setMessage(message);
    verifySignature.setSignature(signature);
    VerifySignatureResponse verifySignatureResponse=instance.verifySignature(verifySignature);
    WSHelper.checkResult(verifySignatureResponse);
  }
}