Program: 48099
Project: 48099
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.IDATA_CARD_STATE_ENTRY);
    boolean nativePace=genericPACESupport(cardState.handleCopy());
    CardVerifiableCertificateChain certChain=new CardVerifiableCertificateChain(eac1Input.getCertificates());
    byte[] rawCertificateDescription=eac1Input.getCertificateDescription();
    CertificateDescription certDescription=CertificateDescription.getInstance(rawCertificateDescription);
    final DynamicContext dynCtx=DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    Promise<Object> promise=dynCtx.getPromise(TR03112Keys.ESERVICE_CERTIFICATE_DESC);
    promise.deliver(certDescription);
    Result activationChecksResult=performChecks(certDescription,dynCtx);
    if (!ECardConstants.Major.OK.equals(activationChecksResult.getResultMajor())) {
      response.setResult(activationChecksResult);
      return response;
    }
    CHAT requiredCHAT=new CHAT(eac1Input.getRequiredCHAT());
    CHAT optionalCHAT=new CHAT(eac1Input.getOptionalCHAT());
    AuthenticatedAuxiliaryData aad=new AuthenticatedAuxiliaryData(eac1Input.getAuthenticatedAuxiliaryData());
    byte pinID=PasswordID.valueOf(didAuthenticate.getDIDName()).getByte();
    String passwordType=PasswordID.parse(pinID).getString();
    PACEMarkerType paceMarker=getPaceMarker(cardState,passwordType);
    CardVerifiableCertificate taCert=certChain.getTerminalCertificates().get(0);
    CardVerifiableCertificateVerifier.verify(taCert,certDescription);
    CHATVerifier.verfiy(taCert.getCHAT(),requiredCHAT);
    optionalCHAT.restrictAccessRights(taCert.getCHAT());
    EACData eacData=new EACData();
    eacData.didRequest=didAuthenticate;
    eacData.certificate=certChain.getTerminalCertificates().get(0);
    eacData.certificateDescription=certDescription;
    eacData.rawCertificateDescription=rawCertificateDescription;
    eacData.transactionInfo=eac1Input.getTransactionInfo();
    eacData.requiredCHAT=requiredCHAT;
    eacData.optionalCHAT=optionalCHAT;
    eacData.selectedCHAT=requiredCHAT;
    eacData.aad=aad;
    eacData.pinID=pinID;
    eacData.passwordType=passwordType;
    InputAPDUInfoType input=new InputAPDUInfoType();
    input.setInputAPDU(new byte[]{(byte)0x00,(byte)0x22,(byte)0xC1,(byte)0xA4,(byte)0x0F,(byte)0x80,(byte)0x0A,(byte)0x04,(byte)0x00,(byte)0x7F,(byte)0x00,(byte)0x07,(byte)0x02,(byte)0x02,(byte)0x04,(byte)0x02,(byte)0x02,(byte)0x83,(byte)0x01,(byte)0x03});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x90,(byte)0x00});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x63,(byte)0xC2});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x63,(byte)0xC1});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x63,(byte)0xC0});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x62,(byte)0x83});
    Transmit transmit=new Transmit();
    transmit.setSlotHandle(slotHandle);
    transmit.getInputAPDUInfo().add(input);
    TransmitResponse pinCheckResponse=(TransmitResponse)dispatcher.deliver(transmit);
    byte[] output=pinCheckResponse.getOutputAPDU().get(0);
    ResponseAPDU outputApdu=new ResponseAPDU(output);
    byte[] status={(byte)outputApdu.getSW1(),(byte)outputApdu.getSW2()};
    UserConsentDescription uc=new UserConsentDescription(lang.translationForKey(TITLE));
    if (!Arrays.equals(status,new byte[]{(byte)0x63,(byte)0xC0})) {
      CVCStep cvcStep=new CVCStep(eacData);
      CHATStep chatStep=new CHATStep(eacData);
      PINStep pinStep=new PINStep(eacData,!nativePace,paceMarker);
      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,status);
      pinStep.setAction(pinAction);
    }
 else {
      StepAction errorAction=new ErrorStepAction("String_Node_Str");
      ErrorStep eStep=new ErrorStep(langPace.translationForKey("String_Node_Str"),langPace.translationForKey("String_Node_Str"));
      eStep.setAction(errorAction);
      uc.getSteps().add(eStep);
    }
    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;
    }
    TerminalAuthentication ta=new TerminalAuthentication(dispatcher,slotHandle);
    byte[] challenge=ta.getChallenge();
    DIDAuthenticationDataType data=eacData.paceResponse.getAuthenticationProtocolData();
    AuthDataMap paceOutputMap=new AuthDataMap(data);
    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.IDATA_SECURITY_INFOS,securityInfos);
    internalData.put(EACConstants.IDATA_AUTHENTICATED_AUXILIARY_DATA,aad);
    internalData.put(EACConstants.IDATA_CERTIFICATES,certChain);
    internalData.put(EACConstants.IDATA_CURRENT_CAR,currentCAR);
    internalData.put(EACConstants.IDATA_CHALLENGE,challenge);
    eac1Output.setCHAT(eacData.selectedCHAT.toByteArray());
    eac1Output.setCurrentCAR(currentCAR);
    eac1Output.setPreviousCAR(previousCAR);
    eac1Output.setEFCardAccess(efCardAccess);
    eac1Output.setIDPICC(idpicc);
    eac1Output.setChallenge(challenge);
    response.setResult(WSHelper.makeResultOK());
    response.setAuthenticationProtocolData(eac1Output.getAuthDataType());
  }
 catch (  CertificateException ex) {
    logger.error(ex.getMessage(),ex);
    String msg=ex.getMessage();
    response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.EAC.DOC_VALID_FAILED,msg));
  }
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.IDATA_CARD_STATE_ENTRY);
    boolean nativePace=genericPACESupport(cardState.handleCopy());
    CardVerifiableCertificateChain certChain=new CardVerifiableCertificateChain(eac1Input.getCertificates());
    byte[] rawCertificateDescription=eac1Input.getCertificateDescription();
    CertificateDescription certDescription=CertificateDescription.getInstance(rawCertificateDescription);
    final DynamicContext dynCtx=DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    Promise<Object> promise=dynCtx.getPromise(TR03112Keys.ESERVICE_CERTIFICATE_DESC);
    promise.deliver(certDescription);
    Result activationChecksResult=performChecks(certDescription,dynCtx);
    if (!ECardConstants.Major.OK.equals(activationChecksResult.getResultMajor())) {
      response.setResult(activationChecksResult);
      return response;
    }
    CHAT requiredCHAT=new CHAT(eac1Input.getRequiredCHAT());
    CHAT optionalCHAT=new CHAT(eac1Input.getOptionalCHAT());
    AuthenticatedAuxiliaryData aad=new AuthenticatedAuxiliaryData(eac1Input.getAuthenticatedAuxiliaryData());
    byte pinID=PasswordID.valueOf(didAuthenticate.getDIDName()).getByte();
    String passwordType=PasswordID.parse(pinID).getString();
    PACEMarkerType paceMarker=getPaceMarker(cardState,passwordType);
    CardVerifiableCertificate taCert=certChain.getTerminalCertificates().get(0);
    CardVerifiableCertificateVerifier.verify(taCert,certDescription);
    CHATVerifier.verfiy(taCert.getCHAT(),requiredCHAT);
    optionalCHAT.restrictAccessRights(taCert.getCHAT());
    EACData eacData=new EACData();
    eacData.didRequest=didAuthenticate;
    eacData.certificate=certChain.getTerminalCertificates().get(0);
    eacData.certificateDescription=certDescription;
    eacData.rawCertificateDescription=rawCertificateDescription;
    eacData.transactionInfo=eac1Input.getTransactionInfo();
    eacData.requiredCHAT=requiredCHAT;
    eacData.optionalCHAT=optionalCHAT;
    eacData.selectedCHAT=requiredCHAT;
    eacData.aad=aad;
    eacData.pinID=pinID;
    eacData.passwordType=passwordType;
    InputAPDUInfoType input=new InputAPDUInfoType();
    input.setInputAPDU(new byte[]{(byte)0x00,(byte)0x22,(byte)0xC1,(byte)0xA4,(byte)0x0F,(byte)0x80,(byte)0x0A,(byte)0x04,(byte)0x00,(byte)0x7F,(byte)0x00,(byte)0x07,(byte)0x02,(byte)0x02,(byte)0x04,(byte)0x02,(byte)0x02,(byte)0x83,(byte)0x01,(byte)0x03});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x90,(byte)0x00});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x63,(byte)0xC2});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x63,(byte)0xC1});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x63,(byte)0xC0});
    input.getAcceptableStatusCode().add(new byte[]{(byte)0x62,(byte)0x83});
    Transmit transmit=new Transmit();
    transmit.setSlotHandle(slotHandle);
    transmit.getInputAPDUInfo().add(input);
    TransmitResponse pinCheckResponse=(TransmitResponse)dispatcher.deliver(transmit);
    byte[] output=pinCheckResponse.getOutputAPDU().get(0);
    ResponseAPDU outputApdu=new ResponseAPDU(output);
    byte[] status={(byte)outputApdu.getSW1(),(byte)outputApdu.getSW2()};
    UserConsentDescription uc=new UserConsentDescription(lang.translationForKey(TITLE));
    if (!Arrays.equals(status,new byte[]{(byte)0x63,(byte)0xC0})) {
      CVCStep cvcStep=new CVCStep(eacData);
      CHATStep chatStep=new CHATStep(eacData);
      PINStep pinStep=new PINStep(eacData,!nativePace,paceMarker);
      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,status);
      pinStep.setAction(pinAction);
    }
 else {
      StepAction errorAction=new ErrorStepAction("String_Node_Str");
      ErrorStep eStep=new ErrorStep(langPace.translationForKey("String_Node_Str",pin),langPace.translationForKey("String_Node_Str",pin,pin,puk,pin));
      eStep.setAction(errorAction);
      uc.getSteps().add(eStep);
    }
    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;
    }
    TerminalAuthentication ta=new TerminalAuthentication(dispatcher,slotHandle);
    byte[] challenge=ta.getChallenge();
    DIDAuthenticationDataType data=eacData.paceResponse.getAuthenticationProtocolData();
    AuthDataMap paceOutputMap=new AuthDataMap(data);
    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.IDATA_SECURITY_INFOS,securityInfos);
    internalData.put(EACConstants.IDATA_AUTHENTICATED_AUXILIARY_DATA,aad);
    internalData.put(EACConstants.IDATA_CERTIFICATES,certChain);
    internalData.put(EACConstants.IDATA_CURRENT_CAR,currentCAR);
    internalData.put(EACConstants.IDATA_CHALLENGE,challenge);
    eac1Output.setCHAT(eacData.selectedCHAT.toByteArray());
    eac1Output.setCurrentCAR(currentCAR);
    eac1Output.setPreviousCAR(previousCAR);
    eac1Output.setEFCardAccess(efCardAccess);
    eac1Output.setIDPICC(idpicc);
    eac1Output.setChallenge(challenge);
    response.setResult(WSHelper.makeResultOK());
    response.setAuthenticationProtocolData(eac1Output.getAuthDataType());
  }
 catch (  CertificateException ex) {
    logger.error(ex.getMessage(),ex);
    String msg=ex.getMessage();
    response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.EAC.DOC_VALID_FAILED,msg));
  }
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;
}