From 102d5729d8d95cec65354f67a22d8c8e7ab5e40b Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 29 Aug 2008 12:59:10 +0000 Subject: added missing resource git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@2 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/stal/dummy/DummySTAL.java | 161 +++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java (limited to 'bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java') diff --git a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java new file mode 100644 index 00000000..2ea0bae0 --- /dev/null +++ b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java @@ -0,0 +1,161 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* 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. +*/ +package at.gv.egiz.stal.dummy; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.Signature; +import java.security.cert.CertificateEncodingException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Locale; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; +import at.gv.egiz.stal.InfoboxReadResponse; +import at.gv.egiz.stal.STAL; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.SignResponse; + +public class DummySTAL implements STAL { + + static Log log = LogFactory.getLog(DummySTAL.class); + + protected X509Certificate cert = null; + protected PrivateKey privateKey = null; + + public DummySTAL() { + try { + KeyStore ks = KeyStore.getInstance("pkcs12"); + ks.load(getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/stal/dummy/keystore/Cert.p12"), "1622".toCharArray()); + for (Enumeration aliases = ks.aliases(); aliases + .hasMoreElements();) { + String alias = aliases.nextElement(); + log.debug("Found alias " + alias + " in keystore"); + if (ks.isKeyEntry(alias)) { + log.debug("Found key entry for alias: " + alias); + privateKey = (PrivateKey) ks.getKey(alias, "1622".toCharArray()); + cert = (X509Certificate) ks.getCertificate(alias); + System.out.println(cert); + } + } + } catch (Exception e) { + log.error(e); + } + + } + + @Override + public List handleRequest(List requestList) { + + List responses = new ArrayList(); + for (STALRequest request : requestList) { + + log.debug("Got STALRequest " + request + "."); + + if (request instanceof InfoboxReadRequest) { + + String infoboxIdentifier = ((InfoboxReadRequest) request) + .getInfoboxIdentifier(); + InputStream stream = getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/stal/dummy/infoboxes4/" + infoboxIdentifier + ".bin"); + + STALResponse response; + if (stream != null) { + + log.debug("Infobox " + infoboxIdentifier + " found."); + + byte[] infobox; + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int b; + while ((b = stream.read()) != -1) { + buffer.write(b); + } + infobox = buffer.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + InfoboxReadResponse infoboxReadResponse = new InfoboxReadResponse(); + infoboxReadResponse.setInfoboxValue(infobox); + response = infoboxReadResponse; + + } else if ((infoboxIdentifier.equals("SecureSignatureKeypair")) ||(infoboxIdentifier.equals("CertifiedKeypair"))) { + try { + InfoboxReadResponse infoboxReadResponse = new InfoboxReadResponse(); + infoboxReadResponse.setInfoboxValue(cert.getEncoded()); + response = infoboxReadResponse; + } catch (CertificateEncodingException e) { + log.error(e); + response = new ErrorResponse(); + } + } else { + + log.debug("Infobox " + infoboxIdentifier + " not found."); + + response = new ErrorResponse(); + } + responses.add(response); + + } else if (request instanceof SignRequest) { + try { + + SignRequest signReq = (SignRequest) request; + Signature s = Signature.getInstance("SHA1withRSA"); + s.initSign(privateKey); + s.update(signReq.getSignedInfo()); + byte[] sigVal = s.sign(); + SignResponse resp = new SignResponse(); + resp.setSignatureValue(sigVal); + responses.add(resp); + } catch (Exception e) { + log.error(e); + responses.add(new ErrorResponse()); + } + + } else { + + log.debug("Request not implemented."); + + responses.add(new ErrorResponse()); + } + + } + + return responses; + } + + @Override + public void setLocale(Locale locale) { + // TODO Auto-generated method stub + + } + + +} -- cgit v1.2.3 From 2df9621154ad057f6cace73efe49c9ef42515fde Mon Sep 17 00:00:00 2001 From: mcentner Date: Tue, 9 Dec 2008 08:14:43 +0000 Subject: Refactored STAL interface. Additional infobox functionality. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@236 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java') diff --git a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java index 2ea0bae0..dd8b8c8f 100644 --- a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java +++ b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java @@ -71,7 +71,7 @@ public class DummySTAL implements STAL { } @Override - public List handleRequest(List requestList) { + public List handleRequest(List requestList) { List responses = new ArrayList(); for (STALRequest request : requestList) { -- cgit v1.2.3 From 1e2e6966def8aae45ff1b368c3582b6363c4294d Mon Sep 17 00:00:00 2001 From: mcentner Date: Tue, 9 Dec 2008 11:29:23 +0000 Subject: Updated tests. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@242 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java') diff --git a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java index dd8b8c8f..77dd7e4f 100644 --- a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java +++ b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java @@ -50,9 +50,10 @@ public class DummySTAL implements STAL { public DummySTAL() { try { - KeyStore ks = KeyStore.getInstance("pkcs12"); - ks.load(getClass().getClassLoader().getResourceAsStream( - "at/gv/egiz/stal/dummy/keystore/Cert.p12"), "1622".toCharArray()); + KeyStore ks = KeyStore.getInstance("pkcs12"); + InputStream ksStream = getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/bku/slcommands/impl/Cert.p12"); + ks.load(ksStream, "1622".toCharArray()); for (Enumeration aliases = ks.aliases(); aliases .hasMoreElements();) { String alias = aliases.nextElement(); -- cgit v1.2.3 From a8690cc956924e1d83b0c45d21995ee2e10fbba2 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 4 Mar 2009 16:44:34 +0000 Subject: 1.1-rc3 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@311 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/stal/dummy/DummySTAL.java | 280 ++++++++++----------- 1 file changed, 136 insertions(+), 144 deletions(-) (limited to 'bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java') diff --git a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java index 77dd7e4f..8adeadee 100644 --- a/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java +++ b/bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java @@ -14,149 +14,141 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.stal.dummy; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.PrivateKey; -import java.security.Signature; -import java.security.cert.CertificateEncodingException; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.Locale; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.InfoboxReadRequest; -import at.gv.egiz.stal.InfoboxReadResponse; -import at.gv.egiz.stal.STAL; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.SignRequest; -import at.gv.egiz.stal.SignResponse; - -public class DummySTAL implements STAL { - - static Log log = LogFactory.getLog(DummySTAL.class); - - protected X509Certificate cert = null; - protected PrivateKey privateKey = null; - - public DummySTAL() { - try { +package at.gv.egiz.stal.dummy; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.Signature; +import java.security.cert.CertificateEncodingException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Locale; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; +import at.gv.egiz.stal.InfoboxReadResponse; +import at.gv.egiz.stal.STAL; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.SignResponse; + +public class DummySTAL implements STAL { + + static Log log = LogFactory.getLog(DummySTAL.class); + + protected X509Certificate cert = null; + protected PrivateKey privateKey = null; + + public DummySTAL() { + try { KeyStore ks = KeyStore.getInstance("pkcs12"); InputStream ksStream = getClass().getClassLoader().getResourceAsStream( - "at/gv/egiz/bku/slcommands/impl/Cert.p12"); - ks.load(ksStream, "1622".toCharArray()); - for (Enumeration aliases = ks.aliases(); aliases - .hasMoreElements();) { - String alias = aliases.nextElement(); - log.debug("Found alias " + alias + " in keystore"); - if (ks.isKeyEntry(alias)) { - log.debug("Found key entry for alias: " + alias); - privateKey = (PrivateKey) ks.getKey(alias, "1622".toCharArray()); - cert = (X509Certificate) ks.getCertificate(alias); - System.out.println(cert); - } - } - } catch (Exception e) { - log.error(e); - } - - } - - @Override - public List handleRequest(List requestList) { - - List responses = new ArrayList(); - for (STALRequest request : requestList) { - - log.debug("Got STALRequest " + request + "."); - - if (request instanceof InfoboxReadRequest) { - - String infoboxIdentifier = ((InfoboxReadRequest) request) - .getInfoboxIdentifier(); - InputStream stream = getClass().getClassLoader().getResourceAsStream( - "at/gv/egiz/stal/dummy/infoboxes4/" + infoboxIdentifier + ".bin"); - - STALResponse response; - if (stream != null) { - - log.debug("Infobox " + infoboxIdentifier + " found."); - - byte[] infobox; - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int b; - while ((b = stream.read()) != -1) { - buffer.write(b); - } - infobox = buffer.toByteArray(); - } catch (IOException e) { - throw new RuntimeException(e); - } - - InfoboxReadResponse infoboxReadResponse = new InfoboxReadResponse(); - infoboxReadResponse.setInfoboxValue(infobox); - response = infoboxReadResponse; - - } else if ((infoboxIdentifier.equals("SecureSignatureKeypair")) ||(infoboxIdentifier.equals("CertifiedKeypair"))) { - try { - InfoboxReadResponse infoboxReadResponse = new InfoboxReadResponse(); - infoboxReadResponse.setInfoboxValue(cert.getEncoded()); - response = infoboxReadResponse; - } catch (CertificateEncodingException e) { - log.error(e); - response = new ErrorResponse(); - } - } else { - - log.debug("Infobox " + infoboxIdentifier + " not found."); - - response = new ErrorResponse(); - } - responses.add(response); - - } else if (request instanceof SignRequest) { - try { - - SignRequest signReq = (SignRequest) request; - Signature s = Signature.getInstance("SHA1withRSA"); - s.initSign(privateKey); - s.update(signReq.getSignedInfo()); - byte[] sigVal = s.sign(); - SignResponse resp = new SignResponse(); - resp.setSignatureValue(sigVal); - responses.add(resp); - } catch (Exception e) { - log.error(e); - responses.add(new ErrorResponse()); - } - - } else { - - log.debug("Request not implemented."); - - responses.add(new ErrorResponse()); - } - - } - - return responses; - } - - @Override - public void setLocale(Locale locale) { - // TODO Auto-generated method stub - - } - - -} + "at/gv/egiz/bku/slcommands/impl/Cert.p12"); + ks.load(ksStream, "1622".toCharArray()); + for (Enumeration aliases = ks.aliases(); aliases + .hasMoreElements();) { + String alias = aliases.nextElement(); + log.debug("Found alias " + alias + " in keystore"); + if (ks.isKeyEntry(alias)) { + log.debug("Found key entry for alias: " + alias); + privateKey = (PrivateKey) ks.getKey(alias, "1622".toCharArray()); + cert = (X509Certificate) ks.getCertificate(alias); + System.out.println(cert); + } + } + } catch (Exception e) { + log.error(e); + } + + } + + @Override + public List handleRequest(List requestList) { + + List responses = new ArrayList(); + for (STALRequest request : requestList) { + + log.debug("Got STALRequest " + request + "."); + + if (request instanceof InfoboxReadRequest) { + + String infoboxIdentifier = ((InfoboxReadRequest) request) + .getInfoboxIdentifier(); + InputStream stream = getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/stal/dummy/infoboxes4/" + infoboxIdentifier + ".bin"); + + STALResponse response; + if (stream != null) { + + log.debug("Infobox " + infoboxIdentifier + " found."); + + byte[] infobox; + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int b; + while ((b = stream.read()) != -1) { + buffer.write(b); + } + infobox = buffer.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + InfoboxReadResponse infoboxReadResponse = new InfoboxReadResponse(); + infoboxReadResponse.setInfoboxValue(infobox); + response = infoboxReadResponse; + + } else if ((infoboxIdentifier.equals("SecureSignatureKeypair")) ||(infoboxIdentifier.equals("CertifiedKeypair"))) { + try { + InfoboxReadResponse infoboxReadResponse = new InfoboxReadResponse(); + infoboxReadResponse.setInfoboxValue(cert.getEncoded()); + response = infoboxReadResponse; + } catch (CertificateEncodingException e) { + log.error(e); + response = new ErrorResponse(); + } + } else { + + log.debug("Infobox " + infoboxIdentifier + " not found."); + + response = new ErrorResponse(); + } + responses.add(response); + + } else if (request instanceof SignRequest) { + try { + + SignRequest signReq = (SignRequest) request; + Signature s = Signature.getInstance("SHA1withRSA"); + s.initSign(privateKey); + s.update(signReq.getSignedInfo()); + byte[] sigVal = s.sign(); + SignResponse resp = new SignResponse(); + resp.setSignatureValue(sigVal); + responses.add(resp); + } catch (Exception e) { + log.error(e); + responses.add(new ErrorResponse()); + } + + } else { + + log.debug("Request not implemented."); + + responses.add(new ErrorResponse()); + } + + } + + return responses; + } +} -- cgit v1.2.3