Program: 48174
Project: 48174
Buggy source:
@Override public DIDAuthenticateResponse perform(DIDAuthenticate request,Map<String,Object> internalData){
  DIDAuthenticate didAuthenticate=request;
  DIDAuthenticateResponse response=new DIDAuthenticateResponse();
  byte[] slotHandle=didAuthenticate.getConnectionHandle().getSlotHandle();
  try {
    EAC1InputType eac1Input=new EAC1InputType(didAuthenticate.getAuthenticationProtocolData());
    EAC1OutputType eac1Output=eac1Input.getOutputType();
    CardStateEntry cardState=(CardStateEntry)internalData.get(EACConstants.INTERNAL_DATA_CARD_STATE_ENTRY);
    boolean nativePace=genericPACESupport(cardState.handleCopy());
    CardVerifiableCertificateChain certChain=new CardVerifiableCertificateChain(eac1Input.getCertificates());
    byte[] rawCertificateDescription=eac1Input.getCertificateDescription();
    CertificateDescription certDescription=CertificateDescription.getInstance(rawCertificateDescription);
    CHAT requiredCHAT=new CHAT(eac1Input.getRequiredCHAT());
    CHAT optionalCHAT=new CHAT(eac1Input.getOptionalCHAT());
    byte pinID=PasswordID.valueOf(didAuthenticate.getDIDName()).getByte();
    String passwordType=PasswordID.parse(pinID).getString();
    CardVerifiableCertificate taCert=certChain.getTerminalCertificates().get(0);
    CardVerifiableCertificateVerifier.verify(taCert,certDescription);
    CHATVerifier.verfiy(taCert.getCHAT(),optionalCHAT);
    CHATVerifier.verfiy(taCert.getCHAT(),requiredCHAT);
    CHATVerifier.verfiy(taCert.getCHAT(),optionalCHAT);
    EACData eacData=new EACData();
    eacData.didRequest=didAuthenticate;
    eacData.certificate=certChain.getTerminalCertificates().get(0);
    eacData.certificateDescription=certDescription;
    eacData.rawCertificateDescription=rawCertificateDescription;
    eacData.requiredCHAT=requiredCHAT;
    eacData.optionalCHAT=optionalCHAT;
    eacData.selectedCHAT=requiredCHAT;
    eacData.pinID=pinID;
    eacData.passwordType=passwordType;
    UserConsentDescription uc=new UserConsentDescription(lang.translationForKey(TITLE));
    CVCStep cvcStep=new CVCStep(eacData);
    CHATStep chatStep=new CHATStep(eacData);
    PINStep pinStep=new PINStep(eacData,!nativePace);
    uc.getSteps().add(cvcStep);
    uc.getSteps().add(chatStep);
    uc.getSteps().add(pinStep);
    StepAction chatAction=new CHATStepAction(eacData,chatStep);
    chatStep.setAction(chatAction);
    StepAction pinAction=new PINStepAction(eacData,!nativePace,slotHandle,dispatcher,pinStep);
    pinStep.setAction(pinAction);
    UserConsentNavigator navigator=gui.obtainNavigator(uc);
    ExecutionEngine exec=new ExecutionEngine(navigator);
    ResultStatus guiResult=exec.process();
    if (guiResult == ResultStatus.CANCEL) {
      String msg="String_Node_Str";
      Result r=WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER,msg);
      response.setResult(r);
      return response;
    }
    DIDAuthenticationDataType data=eacData.paceResponse.getAuthenticationProtocolData();
    AuthDataMap paceOutputMap=new AuthDataMap(data);
    int retryCounter=Integer.valueOf(paceOutputMap.getContentAsString(PACEOutputType.RETRY_COUNTER));
    byte[] efCardAccess=paceOutputMap.getContentAsBytes(PACEOutputType.EF_CARD_ACCESS);
    byte[] currentCAR=paceOutputMap.getContentAsBytes(PACEOutputType.CURRENT_CAR);
    byte[] previousCAR=paceOutputMap.getContentAsBytes(PACEOutputType.PREVIOUS_CAR);
    byte[] idpicc=paceOutputMap.getContentAsBytes(PACEOutputType.ID_PICC);
    SecurityInfos securityInfos=SecurityInfos.getInstance(efCardAccess);
    internalData.put(EACConstants.INTERNAL_DATA_SECURITY_INFOS,securityInfos);
    internalData.put(EACConstants.INTERNAL_DATA_AUTHENTICATED_AUXILIARY_DATA,eac1Input.getAuthenticatedAuxiliaryData());
    internalData.put(EACConstants.INTERNAL_DATA_CERTIFICATES,certChain);
    internalData.put(EACConstants.INTERNAL_DATA_CURRENT_CAR,currentCAR);
    eac1Output.setEFCardAccess(efCardAccess);
    eac1Output.setRetryCounter(retryCounter);
    eac1Output.setIDPICC(idpicc);
    eac1Output.setCHAT(eacData.selectedCHAT.toByteArray());
    eac1Output.setCAR(currentCAR);
    response.setResult(WSHelper.makeResultOK());
    response.setAuthenticationProtocolData(eac1Output.getAuthDataType());
  }
 catch (  WSHelper.WSException e) {
    logger.error(e.getMessage(),e);
    response.setResult(e.getResult());
  }
catch (  Exception e) {
    logger.error(e.getMessage(),e);
    response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
  }
  return response;
}

Fixed version (ground truth):
@Override public DIDAuthenticateResponse perform(DIDAuthenticate request,Map<String,Object> internalData){
  DIDAuthenticate didAuthenticate=request;
  DIDAuthenticateResponse response=new DIDAuthenticateResponse();
  byte[] slotHandle=didAuthenticate.getConnectionHandle().getSlotHandle();
  try {
    EAC1InputType eac1Input=new EAC1InputType(didAuthenticate.getAuthenticationProtocolData());
    EAC1OutputType eac1Output=eac1Input.getOutputType();
    CardStateEntry cardState=(CardStateEntry)internalData.get(EACConstants.INTERNAL_DATA_CARD_STATE_ENTRY);
    boolean nativePace=genericPACESupport(cardState.handleCopy());
    CardVerifiableCertificateChain certChain=new CardVerifiableCertificateChain(eac1Input.getCertificates());
    byte[] rawCertificateDescription=eac1Input.getCertificateDescription();
    CertificateDescription certDescription=CertificateDescription.getInstance(rawCertificateDescription);
    CHAT requiredCHAT=new CHAT(eac1Input.getRequiredCHAT());
    CHAT optionalCHAT=new CHAT(eac1Input.getOptionalCHAT());
    byte pinID=PasswordID.valueOf(didAuthenticate.getDIDName()).getByte();
    String passwordType=PasswordID.parse(pinID).getString();
    CardVerifiableCertificate taCert=certChain.getTerminalCertificates().get(0);
    CardVerifiableCertificateVerifier.verify(taCert,certDescription);
    CHATVerifier.verfiy(taCert.getCHAT(),optionalCHAT);
    CHATVerifier.verfiy(taCert.getCHAT(),requiredCHAT);
    CHATVerifier.verfiy(taCert.getCHAT(),optionalCHAT);
    EACData eacData=new EACData();
    eacData.didRequest=didAuthenticate;
    eacData.certificate=certChain.getTerminalCertificates().get(0);
    eacData.certificateDescription=certDescription;
    eacData.rawCertificateDescription=rawCertificateDescription;
    eacData.requiredCHAT=requiredCHAT;
    eacData.optionalCHAT=optionalCHAT;
    eacData.selectedCHAT=requiredCHAT;
    eacData.pinID=pinID;
    eacData.passwordType=passwordType;
    UserConsentDescription uc=new UserConsentDescription(lang.translationForKey(TITLE));
    CVCStep cvcStep=new CVCStep(eacData);
    CHATStep chatStep=new CHATStep(eacData);
    PINStep pinStep=new PINStep(eacData,!nativePace);
    uc.getSteps().add(cvcStep);
    uc.getSteps().add(chatStep);
    uc.getSteps().add(pinStep);
    StepAction chatAction=new CHATStepAction(eacData,chatStep);
    chatStep.setAction(chatAction);
    StepAction pinAction=new PINStepAction(eacData,!nativePace,slotHandle,dispatcher,pinStep);
    pinStep.setAction(pinAction);
    UserConsentNavigator navigator=gui.obtainNavigator(uc);
    ExecutionEngine exec=new ExecutionEngine(navigator);
    ResultStatus guiResult=exec.process();
    if (guiResult == ResultStatus.CANCEL) {
      String protocol=didAuthenticate.getAuthenticationProtocolData().getProtocol();
      cardState.removeProtocol(protocol);
      String msg="String_Node_Str";
      Result r=WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER,msg);
      response.setResult(r);
      return response;
    }
    DIDAuthenticationDataType data=eacData.paceResponse.getAuthenticationProtocolData();
    AuthDataMap paceOutputMap=new AuthDataMap(data);
    int retryCounter=Integer.valueOf(paceOutputMap.getContentAsString(PACEOutputType.RETRY_COUNTER));
    byte[] efCardAccess=paceOutputMap.getContentAsBytes(PACEOutputType.EF_CARD_ACCESS);
    byte[] currentCAR=paceOutputMap.getContentAsBytes(PACEOutputType.CURRENT_CAR);
    byte[] previousCAR=paceOutputMap.getContentAsBytes(PACEOutputType.PREVIOUS_CAR);
    byte[] idpicc=paceOutputMap.getContentAsBytes(PACEOutputType.ID_PICC);
    SecurityInfos securityInfos=SecurityInfos.getInstance(efCardAccess);
    internalData.put(EACConstants.INTERNAL_DATA_SECURITY_INFOS,securityInfos);
    internalData.put(EACConstants.INTERNAL_DATA_AUTHENTICATED_AUXILIARY_DATA,eac1Input.getAuthenticatedAuxiliaryData());
    internalData.put(EACConstants.INTERNAL_DATA_CERTIFICATES,certChain);
    internalData.put(EACConstants.INTERNAL_DATA_CURRENT_CAR,currentCAR);
    eac1Output.setEFCardAccess(efCardAccess);
    eac1Output.setRetryCounter(retryCounter);
    eac1Output.setIDPICC(idpicc);
    eac1Output.setCHAT(eacData.selectedCHAT.toByteArray());
    eac1Output.setCAR(currentCAR);
    response.setResult(WSHelper.makeResultOK());
    response.setAuthenticationProtocolData(eac1Output.getAuthDataType());
  }
 catch (  WSHelper.WSException e) {
    logger.error(e.getMessage(),e);
    response.setResult(e.getResult());
  }
catch (  Exception e) {
    logger.error(e.getMessage(),e);
    response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
  }
  return response;
}