/* * Copyright 2018 A-SIT Plus GmbH * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ, * A-SIT Plus GmbH, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "License"); * You may not use this work except in compliance with the License. * You may obtain a copy of the License at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test; import java.io.IOException; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchProviderException; import org.apache.commons.lang3.StringUtils; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Base64Utils; import org.w3c.dom.Element; import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.SzrCommunicationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenticationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.szr.SzrClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils; import at.gv.e_government.reference.namespace.persondata._20020228.PersonNameType; import at.gv.e_government.reference.namespace.persondata._20020228.PhysicalPersonType; import at.gv.egiz.eaaf.core.api.data.EaafConstants; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink; import at.gv.egiz.eaaf.core.exceptions.EaafParserException; import at.gv.egiz.eaaf.core.impl.data.Trible; import at.gv.egiz.eaaf.core.impl.idp.auth.data.SimpleIdentityLinkAssertionParser; import szrservices.IdentityLinkType; import szrservices.PersonInfoType; import szrservices.SZRException_Exception; import szrservices.TravelDocumentType; @Ignore @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/SpringTest-context_basic_test.xml") public class SzrClientTestProduction { private static final Logger log = LoggerFactory.getLogger(SzrClientTestProduction.class); @Autowired SzrClient szrClient; @Autowired IConfiguration basicConfig; private static final String givenName = "Franz"; private static final String familyName = "Mustermann"; // private static final String dateOfBirth = "1989-05-05"; private static final String dateOfBirth = "1989-05-04"; private static final String eIDASeID = "IS/AT/1234sdgsdfg56789ABCDEF"; private static final String DUMMY_TARGET = EaafConstants.URN_PREFIX_CDID + "ZP"; @Test public void dummyTest() { } @Test public void getIdentityLinkRawMode() throws SZRException_Exception, EaafParserException, NoSuchProviderException, IOException, InvalidKeyException, EidasSAuthenticationException { log.debug("Starting connecting SZR Gateway"); final IdentityLinkType result = szrClient.getIdentityLinkInRawMode( getPersonInfo()); final Element idlFromSzr = (Element) result.getAssertion(); final IIdentityLink identityLink = new SimpleIdentityLinkAssertionParser(idlFromSzr).parseIdentityLink(); if (identityLink == null) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO IDL object" }); } System.out.println(identityLink.getSerializedSamlAssertion()); if (StringUtils.isEmpty(identityLink.getFamilyName())) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO FamilyName from IDL" }); } if (StringUtils.isEmpty(identityLink.getGivenName())) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO GivenName from IDL" }); } if (StringUtils.isEmpty(identityLink.getDateOfBirth())) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO DateOfBirthName from IDL" }); } if (StringUtils.isEmpty(identityLink.getIdentificationType())) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO baseIdType from IDL" }); } if (StringUtils.isEmpty(identityLink.getIdentificationValue())) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO baseId from IDL" }); } if (StringUtils.isEmpty(identityLink.getSerializedSamlAssertion())) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO serialized IDL" }); } if (identityLink.getSamlAssertion() == null) { throw new SzrCommunicationException("ernb.00", new Object[] { "NO raw IDL" }); } } @Ignore @Test public void getBpkTest() throws SZRException_Exception, EidasSAuthenticationException { final String bPK = szrClient.getBpk(getPersonInfo(), DUMMY_TARGET, basicConfig.getBasicConfiguration( Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_VKZ, "no VKZ defined")); if (StringUtils.isEmpty(bPK)) { throw new SzrCommunicationException("ernb.01", new Object[] { "bPK is null or empty" }); } } private String createHashFromUniqueId(String uniqueId) throws EidasSAuthenticationException { try { final MessageDigest md = MessageDigest.getInstance("SHA-256"); final byte[] hash = md.digest(uniqueId.getBytes("UTF-8")); final String hashBase64 = new String(Base64Utils.encode(hash), "UTF-8").replaceAll("\r\n", ""); return hashBase64; } catch (final Exception ex) { throw new EidasSAuthenticationException("internal.03", new Object[] {}, ex); } } private PersonInfoType getPersonInfo() throws EidasSAuthenticationException { final PersonInfoType personInfo = new PersonInfoType(); final PersonNameType personName = new PersonNameType(); final PhysicalPersonType naturalPerson = new PhysicalPersonType(); final TravelDocumentType eDocument = new TravelDocumentType(); naturalPerson.setName(personName); personInfo.setPerson(naturalPerson); personInfo.setTravelDocument(eDocument); // parse some eID attributes final Trible eIdentifier = EidasResponseUtils.parseEidasPersonalIdentifier(eIDASeID); final String uniqueId = createHashFromUniqueId(eIdentifier.getThird()); final String citizenCountry = eIdentifier.getFirst(); // person information personName.setFamilyName(familyName); personName.setGivenName(givenName); naturalPerson.setDateOfBirth(dateOfBirth); eDocument.setIssuingCountry(citizenCountry); eDocument.setDocumentNumber(uniqueId); // eID document information eDocument.setDocumentType(basicConfig.getBasicConfiguration( Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_EDOCUMENTTYPE, Constants.SZR_CONSTANTS_DEFAULT_DOCUMENT_TYPE)); return personInfo; } }