public PolyInfoResponse validatePolymorphInfoRestService(PolyInfoRequest request, String clientIp) {
        PolyInfoResponse response = new PolyInfoResponse();
        EidSession session = initSession(request, clientIp, response);
        if (session == null) return response;

        PcaSecurityInfos cardAccess = mapper.read(request.getEfCardAccess(), PcaSecurityInfos.class);

        // 1. Validate the EFCardAccess file.
        // In EF.cardaccess moet bij polymorphic info versie 1 staan.
        // (ASN1 parsing: pcaVersion=1, flag randomizedPIP aan, flag compressedEncoding aan)
        CardValidations.validatePolymorhpicInfo(cardAccess.getPolymorphicInfo());

        // 2. The CARs received match with the CVCA under which eID-Server terminal
        // certificates reside. (see RDW specifications)
        Certificate at = cvCertificateService.getBySubject(session.getAtReference());
        Certificate dvca = cvCertificateService.getIssuer(at);

        if (!dvca.getIssuer().equals(new String(request.getCar(), StandardCharsets.UTF_8))) {
            // TODO: Send link CVCA
            logger.error("Could not find chain with CVCA {}", request.getCar());
            throw new ClientException("Could not find CVCA");
        }

        // 3. Select an appropriate TA certificate chain for the polymorphic
        // authentication the user has consented to,
        // --> DVCA cert + CVCA Public Key + Terminal Certificate
        response.setDvCert(CvCertificate.getAsSequence(dvca.getRaw()));

        // 4. Generates a random ephemeral key K in participation of the coming CA
        // protocol.
        EcPrivateKey ephemeralKey = securityFactory.generateKey(cardAccess.getCaEcParameters().getDomainParameters());
        response.setEphemeralKey(KeyUtils.getEncodedPublicPoint(ephemeralKey.toPublicKeySpec()));

        // set session data that is used in later steps
        session.setIdpicc(new ByteArray(request.getIdpicc()));
        session.setEphemeralKey(ephemeralKey);
        session.setKeyReference(cardAccess.getCaKeyId());
        session.setTaVersion(cardAccess.getTaVersion());
        session.setPaceVersion(cardAccess.getPaceVersion());

        // Result OK
        sessionRepo.save(session);
        return response;
    }
@Test
    public void validatePolymorphInfoRestServiceTest() {
        EidSession session = new EidSession();
        Certificate certificate = new Certificate();
        certificate.setSubject("Subject");
        certificate.setIssuer("SSSSSSSSSSSSSSSS");
        certificate.setRaw(Base64.decode("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"));
        PolyInfoRequest request = new PolyInfoRequest();
        request.setHeader(createRequestHeader());
        request.setCar("SSSSSSSSSSSSSSSS".getBytes());
        request.setEfCardAccess(Base64.decode("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"));

        when(securityFactory.generateKey(Mockito.eq(ephemeralKey.toDomainParameters()))).thenReturn(ephemeralKey);
        doReturn(session).when(rdwService).initSession(any(AppRequest.class), eq(localhost), any(AppResponse.class));
        when(cvCertificateServiceMock.getBySubject(isNull())).thenReturn(certificate);
        when(cvCertificateServiceMock.getIssuer(any(Certificate.class))).thenReturn(certificate);

        PolyInfoResponse result = rdwService.validatePolymorphInfoRestService(request, localhost);

        assertEquals("OK", result.getStatus());
        verify(cvCertificateServiceMock, times(1)).getBySubject(isNull());
        verify(cvCertificateServiceMock, times(1)).getIssuer(any(Certificate.class));
    }