/******************************************************************************* * 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.test.eidas.specific.modules.authmodule_eIDASv2; import java.io.IOException; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchProviderException; import java.util.List; import org.apache.commons.lang3.StringUtils; 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.w3._2000._09.xmldsig.KeyValueType; import org.w3c.dom.Element; import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.Constants; import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.exception.SZRCommunicationException; import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.exception.eIDASAuthenticationException; import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.szr.SZRClient; import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.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; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/SpringTest-context_basic_test.xml") public class SZRClientTest { private static final Logger log = LoggerFactory.getLogger(SZRClientTest.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 eIDASeID = "IS/AT/1234sdgsdfg56789ABCDEF"; //Dummy public RSA Key private static final String PUBKEY_EXPONENT = "AQAB"; private static final String PUBKEY_MODULUS = "AJZyj/+sdCMDRq9RkvbFcgSTVn/OfS8EUE81ddwP8MNuJ1kd1SWBUJPaQX2JLJHrL54mkOhrkhH2M/zcuOTu8nW9TOEgXGjrRB/0HpiYKpV+VDJViyyc/GacNLxN4Anw4pima6gHYaJIw9hQkL/nuO2hyh8PGJd7rxeFXJmbLy+X"; private static final String DUMMY_TARGET = EAAFConstants.URN_PREFIX_CDID + "ZP"; @Test public void dummyTest() { } /* * getIdentityLink without RAW mode does not contain a valid signature */ //@Test // public void getIdentityLink() throws SZRException_Exception, EAAFParserException, NoSuchProviderException, IOException, InvalidKeyException, eIDASAuthenticationException { // log.debug("Starting connecting SZR Gateway"); // IdentityLinkType result = szrClient.getIdentityLink( // getPersonInfo(), // dummyCodeForKeys(), // basicConfig.getBasicMOAIDConfigurationBoolean( // Constants.CONIG_PROPS_EIDAS_SZRCLIENT_DEBUG_INSERTERNB, // true) // ); // // Element idlFromSZR = (Element)result.getAssertion(); // IIdentityLink identityLink = new SimpleIdentityLinkAssertionParser(idlFromSZR).parseIdentityLink(); // if (identityLink == null) // throw new SZRCommunicationException("ernb.00", new Object[] {"bPK is null or empty"}); // // } @Test public void getIdentityLinkRawMode() throws SZRException_Exception, EAAFParserException, NoSuchProviderException, IOException, InvalidKeyException, eIDASAuthenticationException { log.debug("Starting connecting SZR Gateway"); IdentityLinkType result = szrClient.getIdentityLinkInRawMode( getPersonInfo()); Element idlFromSZR = (Element)result.getAssertion(); 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"}); } // @Test public void getbPKTest() throws SZRException_Exception, eIDASAuthenticationException { 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 eIDASAuthenticationException { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] hash = md.digest(uniqueId.getBytes("UTF-8")); String hashBase64 = new String(Base64Utils.encode(hash), "UTF-8").replaceAll("\r\n", ""); return hashBase64; } catch (Exception ex) { throw new eIDASAuthenticationException("internal.03", new Object[]{}, ex); } } private PersonInfoType getPersonInfo() throws eIDASAuthenticationException { PersonInfoType personInfo = new PersonInfoType(); PersonNameType personName = new PersonNameType(); PhysicalPersonType naturalPerson = new PhysicalPersonType(); TravelDocumentType eDocument = new TravelDocumentType(); naturalPerson.setName(personName ); personInfo.setPerson(naturalPerson ); personInfo.setTravelDocument(eDocument ); //parse some eID attributes Trible eIdentifier = eIDASResponseUtils.parseEidasPersonalIdentifier((String)eIDASeID); String uniqueId = createHashFromUniqueId(eIdentifier.getThird()); String citizenCountry = eIdentifier.getFirst(); //person information personName.setFamilyName((String)familyName); personName.setGivenName((String)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)); //TODO: that should be removed // eDocument.setIssueDate(basicConfig.getBasicConfiguration( // Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_ISSUING_DATE)); // eDocument.setIssuingAuthority(basicConfig.getBasicConfiguration( // Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_ISSUING_AUTHORITY)); return personInfo; } private List dummyCodeForKeys() throws IOException, NoSuchProviderException, InvalidKeyException { // if (basicConfig.getBasicMOAIDConfigurationBoolean( // Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_KEYS_USEDUMMY, // false)) { // List keyvalueList = new ArrayList(); // try { // // set key values // RSAKeyValueType rsa = new RSAKeyValueType(); // rsa.setExponent(PUBKEY_EXPONENT); // rsa.setModulus(PUBKEY_MODULUS); // // KeyValueType key = new KeyValueType(); // key.setRSAKeyValue(rsa); // keyvalueList.add(key); // // return keyvalueList; // } catch (Exception e) { // log.error("TestCode has an internal ERROR", e); // throw e; // // } // // } return null; } }