diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2009-03-04 16:44:34 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2009-03-04 16:44:34 +0000 |
commit | a8690cc956924e1d83b0c45d21995ee2e10fbba2 (patch) | |
tree | 1764672c1dd6ae6a8028960c9ab2a8782c2dd43a /bkucommon/src/test/java | |
parent | 4387153c6f65b55d576e1890c5b582237227369e (diff) | |
download | mocca-a8690cc956924e1d83b0c45d21995ee2e10fbba2.tar.gz mocca-a8690cc956924e1d83b0c45d21995ee2e10fbba2.tar.bz2 mocca-a8690cc956924e1d83b0c45d21995ee2e10fbba2.zip |
1.1-rc3
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@311 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/test/java')
-rw-r--r-- | bkucommon/src/test/java/at/gv/egiz/stal/dummy/DummySTAL.java | 280 |
1 files changed, 136 insertions, 144 deletions
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<String> 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<STALResponse> handleRequest(List<? extends STALRequest> requestList) {
-
- List<STALResponse> responses = new ArrayList<STALResponse>();
- 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<String> 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<STALResponse> handleRequest(List<? extends STALRequest> requestList) { + + List<STALResponse> responses = new ArrayList<STALResponse>(); + 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; + } +} |