summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/at/gv/util/demo/Clienttests.java392
1 files changed, 392 insertions, 0 deletions
diff --git a/src/test/java/at/gv/util/demo/Clienttests.java b/src/test/java/at/gv/util/demo/Clienttests.java
new file mode 100644
index 0000000..e984263
--- /dev/null
+++ b/src/test/java/at/gv/util/demo/Clienttests.java
@@ -0,0 +1,392 @@
+package at.gv.util.demo;
+
+import iaik.security.ecc.interfaces.ECDSAParams;
+import iaik.security.ecc.interfaces.ECDSAPublicKey;
+import iaik.security.ecc.math.ecgroup.AffineCoordinate;
+import iaik.security.ecc.math.ecgroup.ECPoint;
+import iaik.security.ecc.provider.ECCProvider;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.PublicKey;
+import java.security.interfaces.DSAParams;
+import java.security.interfaces.DSAPublicKey;
+import java.security.interfaces.ECPublicKey;
+import java.security.interfaces.RSAPublicKey;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerException;
+
+import org.apache.cxf.common.util.Base64Utility;
+import org.w3c.dom.Element;
+
+import at.gv.util.BpkUtil;
+import at.gv.util.DOMUtils;
+import at.gv.util.client.szr.SZRClient;
+import at.gv.util.client.ur_V5.URClient;
+import at.gv.util.client.ur_V5.URClient.URSearchResult;
+import at.gv.util.client.ur_V5.URClientException;
+import at.gv.util.config.EgovUtilPropertiesConfiguration;
+import at.gv.util.data.BPK;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.szr.SZRException;
+import at.gv.util.xsd.szr.GetIdentityLink;
+import at.gv.util.xsd.szr.IdentityLinkType;
+import at.gv.util.xsd.szr.PersonInfoType;
+import at.gv.util.xsd.szr.TravelDocumentType;
+import at.gv.util.xsd.szr.ecdsa.DomainParamsType;
+import at.gv.util.xsd.szr.ecdsa.ECDSAKeyValueType;
+import at.gv.util.xsd.szr.ecdsa.ECPointType;
+import at.gv.util.xsd.szr.ecdsa.NamedCurveType;
+import at.gv.util.xsd.szr.ecdsa.PrimeFieldElemType;
+import at.gv.util.xsd.szr.persondata.IdentificationType;
+import at.gv.util.xsd.szr.persondata.PersonNameType;
+import at.gv.util.xsd.szr.persondata.PhysicalPersonType;
+import at.gv.util.xsd.szr.xmldsig.DSAKeyValueType;
+import at.gv.util.xsd.szr.xmldsig.KeyValueType;
+import at.gv.util.xsd.szr.xmldsig.RSAKeyValueType;
+
+public class Clienttests {
+
+ public static String XFN_NAME = "Firmenbuchnummer";
+ public static String XFN_VALUE = "urn:publicid:gv.at:baseid+XFN";
+ public static String XFN_URT = "FBN";
+
+ public static String XZVR_NAME = "ZVR-Zahl";
+ public static String XZVR_VALUE = "urn:publicid:gv.at:baseid+XZVR";
+ public static String XZVR_URT = "ZVR";
+
+ public static String XERSB_NAME = "ERsB Ordnungsnummer";
+ public static String XERSB_VALUE = "urn:publicid:gv.at:baseid+XERSB";
+ public static String XERSB_URT = "ERJ";
+
+ public static List<String> UR_TYPES = Arrays.asList(XFN_URT, XZVR_URT, XERSB_URT);
+
+ public static HashSet<String> ERSB_KEYS = new HashSet<String>();
+
+ public static final String SSPIN_PREFIX = "urn:publicid:gv.at:cdid+";
+
+ private final static byte[] DEFAULT_PUBL_KEY = new byte[] {48, -127, -97, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -127, -115, 0, 48, -127, -119, 2, -127, -127, 0, -106, 114, -113, -1, -84, 116, 35, 3, 70, -81, 81, -110, -10, -59, 114, 4, -109, 86, 127, -50, 125, 47, 4, 80, 79, 53, 117, -36, 15, -16, -61, 110, 39, 89, 29, -43, 37, -127, 80, -109, -38, 65, 125, -119, 44, -111, -21, 47, -98, 38, -112, -24, 107, -110, 17, -10, 51, -4, -36, -72, -28, -18, -14, 117, -67, 76, -31, 32, 92, 104, -21, 68, 31, -12, 30, -104, -104, 42, -107, 126, 84, 50, 85, -117, 44, -100, -4, 102, -100, 52, -68, 77, -32, 9, -16, -30, -104, -90, 107, -88, 7, 97, -94, 72, -61, -40, 80, -112, -65, -25, -72, -19, -95, -54, 31, 15, 24, -105, 123, -81, 23, -123, 92, -103, -101, 47, 47, -105, 2, 3, 1, 0, 1};
+ public static final String DOCUMENT_TYPE = "ELEKTR_DOKUMENT";
+ public static final String ERnB_ISSUEDATE = "2014-01-01";
+ public static final String ERnB_ISSUINGAUTHORITY = "SZR-Gateway";
+
+ @SuppressWarnings("unused")
+ public static void main(String[] args) throws IOException {
+
+ String propertiesFileLocation = System.getProperty("mis.configuration");
+
+ if (propertiesFileLocation == null) {
+ System.out.println("No system properties found. Cannot load default configuration.");
+ throw new IOException("Cannot load default configuration. Please specify first mis.configuration location in system properties.");
+
+ }
+
+ File propertiesFile = new File(propertiesFileLocation);
+ FileInputStream fis = new FileInputStream(propertiesFile);
+ String configDir = propertiesFile.getParentFile().getAbsolutePath();
+ Properties props = new Properties();
+ props.load(fis);
+
+ EgovUtilPropertiesConfiguration egovUtilConfiguration = new EgovUtilPropertiesConfiguration(props, configDir);
+
+ ERSB_KEYS.add("136");
+ ERSB_KEYS.add("137");
+ ERSB_KEYS.add("138");
+ ERSB_KEYS.add("139");
+ ERSB_KEYS.add("140");
+
+ try {
+ SZRClient szrClient = new SZRClient(egovUtilConfiguration);
+ URClient urClient = new URClient(egovUtilConfiguration, UR_TYPES, ERSB_KEYS, false, false);
+
+
+ PersonInfoType personInfo = new PersonInfoType();
+ PhysicalPersonType person = new PhysicalPersonType();
+ personInfo.setPerson(person);
+ PersonNameType personName = new PersonNameType();
+ person.setName(personName );
+
+ IdentificationType id = new IdentificationType();
+
+// id.setType(SSPIN_PREFIX + "ZP");
+// id.setValue("U/wThc0XOTZp9Tvsxrh8DhGTXsU=");
+// person.setIdentification(id);
+
+ personName.setFamilyName("Karning");
+ personName.setGivenName("Bernhard");
+ person.setDateOfBirth("1976-01-15");
+
+
+
+ String baseID = szrClient.getStammzahl(personInfo );
+
+ BPK zpBpk = BpkUtil.createBPK(baseID, "ZP");
+
+ String encryptedbPK = szrClient.transformBPK(personInfo, zpBpk.getBpk(), SSPIN_PREFIX + "ZP", SSPIN_PREFIX + "WT-UR", "BBA-STA");
+
+
+// GetIdentityLink idlReq = createGetIdentityLink();
+//
+// String baseIDResp = szrClient.getStammzahl(personInfo);
+//
+// IdentityLinkType idlResp = szrClient.getIdentityLink(
+// idlReq.getPersonInfo(),
+// idlReq.getKeyValue(),
+// false);
+// Element idl = (Element)idlResp.getAssertion();
+// System.out.println(DOMUtils.serializeNode(idl));
+
+
+ List<URSearchResult> urResult = urClient.searchByBpk(encryptedbPK);
+
+ System.out.println("Finish");
+
+
+
+ } catch (EgovUtilException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ } catch (SZRException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ } catch (URClientException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private static GetIdentityLink createGetIdentityLink(){
+
+ // set parameter
+ GetIdentityLink getIdentityLink = new GetIdentityLink();
+
+ // generate PersonData
+ PersonNameType personName = new PersonNameType();
+ personName.setFamilyName("Janez Vzorec");
+ personName.setGivenName("Janez Vzorec");
+
+ PhysicalPersonType physicalPerson = new PhysicalPersonType();
+ SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
+
+ String birthday = "1998-12-06";
+ if (birthday != null)
+ physicalPerson.setDateOfBirth(birthday);
+
+ physicalPerson.setName(personName);
+
+ PersonInfoType personInfo = new PersonInfoType();
+ personInfo.setPerson(physicalPerson);
+
+
+ // add Traveldocument
+
+ TravelDocumentType trvlDoc = new TravelDocumentType();
+
+ // parse STORK-eID to his components
+ //ERnB allows only eIDs with a maximum length of 54 signs
+ trvlDoc.setDocumentNumber("33333333");
+ trvlDoc.setIssuingCountry("SI");
+ trvlDoc.setDocumentType(DOCUMENT_TYPE);
+
+ //set default values from SZR because certificate for mandator natural person is not
+ //available in case of authentication with electronic mandates.
+ trvlDoc.setIssueDate(ERnB_ISSUEDATE);
+ trvlDoc.setIssuingAuthority(ERnB_ISSUINGAUTHORITY);
+
+ JAXBElement<TravelDocumentType> jaxbtrvlDoc = personInfo.getTravelDocument();
+
+ if (jaxbtrvlDoc == null)
+ jaxbtrvlDoc = new JAXBElement<TravelDocumentType>(new QName("urn:SZRServices", "TravelDocument"), TravelDocumentType.class, trvlDoc);
+ else
+ jaxbtrvlDoc.setValue(trvlDoc);
+
+ //personInfo.setTravelDocument(jaxbtrvlDoc);
+
+ // Personendaten setzen
+ getIdentityLink.setPersonInfo(personInfo);
+
+ // add Keys
+
+ PublicKey pb;
+ List<KeyValueType> keyvalueList = getIdentityLink.getKeyValue();
+ if (keyvalueList == null)
+ keyvalueList = new ArrayList<KeyValueType>();
+
+
+ try {
+ pb = new iaik.security.rsa.RSAPublicKey(DEFAULT_PUBL_KEY);
+ List<KeyValueType> keys = getKeyValueTypes(pb);
+ keyvalueList.addAll(keys);
+
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+
+ }
+
+ // set Insert ERnP flag
+ getIdentityLink.setInsertERnP(false);
+
+// Constants.DATA_LOGGER.debug("Person wird im SZR und ERnP gesucht bzw. gegebenenfalls im ERnP eingetragen: "
+// + natPerson.getFamilyName() + " " + natPerson.getGivenName() + " " + natPerson.getBirthday()
+// + " eID=" + natPerson.geteID() , tid);
+
+ return getIdentityLink;
+
+ }
+
+ /**
+ * Returns the according key value types from the given public key
+ * @param pb
+ * @return
+ * @throws SZRGWException
+ */
+ private static List<KeyValueType> getKeyValueTypes(PublicKey pb) {
+ List<KeyValueType> keys = new ArrayList<KeyValueType>();
+
+ ECCProvider.addAsProvider();
+
+ //System.out.println(pb);
+
+ if (pb instanceof RSAPublicKey) {
+ //System.out.println("Is a RSAPublicKey");
+ //Extract key data
+ RSAPublicKey rsapb = (RSAPublicKey)pb;
+
+ BigInteger modulus = rsapb.getModulus();
+ BigInteger exponent = rsapb.getPublicExponent();
+
+ //System.out.println("Modulus: " + modulus);
+ //System.out.println("PublicExponent: " + exponent);
+
+ // set key values
+ RSAKeyValueType rsa = new RSAKeyValueType();
+ ;
+ rsa.setExponent(Base64Utility.encode(exponent.toByteArray()));
+ rsa.setModulus(Base64Utility.encode(modulus.toByteArray()));
+
+
+ KeyValueType key = new KeyValueType();
+ key.setRSAKeyValue(rsa);
+ keys.add(key);
+
+ }
+
+ if (pb instanceof DSAPublicKey) {
+ //System.out.println("Is a DSAPublicKey");
+ // extract key data
+ DSAPublicKey dsapb = (DSAPublicKey) pb;
+ BigInteger y = dsapb.getY();
+ DSAParams param = dsapb.getParams();
+ BigInteger g = param.getG();
+ BigInteger p = param.getP();
+ BigInteger q = param.getQ();
+
+// System.out.println("Y: " + y);
+// System.out.println("G: " + g);
+// System.out.println("P: " + p);
+// System.out.println("Q: " + q);
+//
+ //set key values
+ DSAKeyValueType dsa = new DSAKeyValueType();
+ if (y != null)
+ dsa.setY(y.toString());
+ if (g != null)
+ dsa.setG(g.toString());
+ if (p != null)
+ dsa.setP(p.toString());
+ if (q != null)
+ dsa.setQ(q.toString());
+
+ KeyValueType key = new KeyValueType();
+ key.setDSAKeyValue(dsa);
+ keys.add(key);
+
+ }
+
+ if (pb instanceof ECDSAPublicKey) {
+
+ //Extract key data
+ ECDSAPublicKey ecdsapb= (ECDSAPublicKey)pb;
+ ECDSAParams params = ecdsapb.getParameter();
+ //EllipticCurve curve = params.getG().getCurve();
+ String oid = params.getOID();
+ //String name = ObjectID.getRegisteredName(oid);
+ ECPoint w = ecdsapb.getW();
+ AffineCoordinate coordinate = (AffineCoordinate) w.getCoordinates().toAffine();
+ String x = coordinate.getX().toBigInt().toString();
+ String y = coordinate.getY().toBigInt().toString();
+
+ ECDSAKeyValueType ecdsa = new ECDSAKeyValueType();
+ DomainParamsType paramstype = new DomainParamsType();
+ NamedCurveType namedCurve = new NamedCurveType();
+ namedCurve.setURN("urn:oid:" + oid);
+ paramstype.setNamedCurve(namedCurve);
+ ecdsa.setDomainParameters(paramstype);
+
+ ECPointType ecpointtype = new ECPointType();
+ PrimeFieldElemType xElem = new PrimeFieldElemType();
+ xElem.setValue(x);
+ PrimeFieldElemType yElem = new PrimeFieldElemType();
+ yElem.setValue(y);
+ ecpointtype.setX(xElem);
+ ecpointtype.setY(yElem);
+ ecdsa.setPublicKey(ecpointtype);
+
+ KeyValueType key = new KeyValueType();
+ key.setECDSAKeyValue(ecdsa);
+ keys.add(key);
+
+ //throw new SZRGWException("Certificate enthält einen ECDSAPublicKey. Dieser wird momentan noch nicht unterstützt.");
+ }
+
+ if (pb instanceof ECPublicKey) {
+ //System.out.println("Is a ECPublicKey");
+
+
+// throw new SZRGWException("Certificate enthält einen ECPublicKey. Dieser wird momentan noch nicht unterstützt.");
+
+
+
+// ECPublicKey ecpb = (ECPublicKey) pb;
+//
+// System.out.println(ecpb.toString());
+//
+// ECParameterSpec params = ecpb.getParams();
+// EllipticCurve curve = params.getCurve();
+//
+// ECDSAKeyValueType ecdsa = new ECDSAKeyValueType();
+// DomainParamsType domainparams = new DomainParamsType();
+// NamedCurveType curvetype = new NamedCurveType();
+// curvetype.setURN("P-192");
+// domainparams.setNamedCurve(curvetype);
+// ecdsa.setDomainParameters(domainparams);
+// ECPointType publicKey = new ECPointType();
+// PrimeFieldElemType x = new PrimeFieldElemType();
+// x.setValue("12345x");
+// publicKey.setX(x);
+// PrimeFieldElemType y = new PrimeFieldElemType();
+// y.setValue("12345y");
+// publicKey.setY(y);
+// ecdsa.setPublicKey(publicKey);
+// keys[0].setECDSAKeyValue(ecdsa);
+
+
+ }
+
+ return keys;
+ }
+
+}