diff options
Diffstat (limited to 'bkucommon')
6 files changed, 161 insertions, 165 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java index 7b682136..aaeacd98 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.binding; +import at.gv.egiz.bku.conf.Configurator; import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; @@ -82,7 +83,7 @@ public class DataUrl { public static void setConfiguration(Properties props) { configuration = props; if (configuration != null) { - String className = configuration.getProperty(DataUrlConnection.DATAURLCONNECTION_CONFIG_P); + String className = configuration.getProperty(Configurator.DATAURLCONNECTION_CONFIG_P); if (className != null) { try { log.info("set DataURLConnection class: " + className); diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java index 21407cc3..f954a017 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java @@ -34,12 +34,6 @@ import at.gv.egiz.bku.slcommands.SLResult; */ public interface DataUrlConnection { - public final static String USERAGENT_CONFIG_P = "UserAgent"; - public static final String USERAGENT_DEFAULT = "citizen-card-environment/1.2 MOCCA/UNKNOWN"; - public static final String USERAGENT_BASE = "citizen-card-environment/1.2 MOCCA/"; - - public static final String DATAURLCONNECTION_CONFIG_P = "DataURLConnectionImplClass"; - public static final String FORMPARAM_RESPONSETYPE = "ResponseType"; public static final String DEFAULT_RESPONSETYPE = "HTTP-Security-Layer-RESPONSE"; public static final String FORMPARAM_XMLRESPONSE = "XMLResponse"; diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java index d9a9454e..4c235456 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java @@ -43,6 +43,7 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.binding.multipart.InputStreamPartSource; import at.gv.egiz.bku.binding.multipart.SLResultPart; +import at.gv.egiz.bku.conf.Configurator; import at.gv.egiz.bku.slcommands.SLResult; import at.gv.egiz.bku.slcommands.SLResult.SLResultType; import at.gv.egiz.bku.slexceptions.SLRuntimeException; @@ -225,12 +226,12 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI { boundary = "--" + IdFactory.getInstance().createId().toString(); requestHttpHeaders = new HashMap<String, String>(); if ((config != null) - && (config.getProperty(USERAGENT_CONFIG_P) != null)) { + && (config.getProperty(Configurator.USERAGENT_CONFIG_P) != null)) { requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, config - .getProperty(USERAGENT_CONFIG_P)); + .getProperty(Configurator.USERAGENT_CONFIG_P)); } else { requestHttpHeaders - .put(HttpUtil.HTTP_HEADER_USER_AGENT, USERAGENT_DEFAULT); + .put(HttpUtil.HTTP_HEADER_USER_AGENT, Configurator.USERAGENT_DEFAULT); } requestHttpHeaders.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java index ef9dd199..cfccb7f1 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java @@ -1,6 +1,7 @@ package at.gv.egiz.bku.binding; +import at.gv.egiz.bku.conf.Configurator; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -38,7 +39,7 @@ import at.gv.egiz.bku.utils.binding.Protocol; */ public class LegacyDataUrlConnectionImpl implements DataUrlConnectionSPI { - private final static Log log = LogFactory.getLog(DataUrlConnectionImpl.class); + private final static Log log = LogFactory.getLog(LegacyDataUrlConnectionImpl.class); public final static Protocol[] SUPPORTED_PROTOCOLS = { Protocol.HTTP, Protocol.HTTPS }; @@ -212,13 +213,13 @@ public class LegacyDataUrlConnectionImpl implements DataUrlConnectionSPI { this.url = url; requestHttpHeaders = new HashMap<String, String>(); if ((config != null) - && (config.getProperty(USERAGENT_CONFIG_P) != null)) { - log.debug("setting User-Agent header: " + config.getProperty(USERAGENT_CONFIG_P)); + && (config.getProperty(Configurator.USERAGENT_CONFIG_P) != null)) { + log.debug("setting User-Agent header: " + config.getProperty(Configurator.USERAGENT_CONFIG_P)); requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, config - .getProperty(USERAGENT_CONFIG_P)); + .getProperty(Configurator.USERAGENT_CONFIG_P)); } else { requestHttpHeaders - .put(HttpUtil.HTTP_HEADER_USER_AGENT, USERAGENT_DEFAULT); + .put(HttpUtil.HTTP_HEADER_USER_AGENT, Configurator.USERAGENT_DEFAULT); } requestHttpHeaders.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java b/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java index a6c70d2c..6213ffcf 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java @@ -49,6 +49,13 @@ public abstract class Configurator { private Log log = LogFactory.getLog(Configurator.class);
+ public final static String USERAGENT_CONFIG_P = "UserAgent";
+ public static final String DATAURLCONNECTION_CONFIG_P = "DataURLConnectionImplClass";
+
+ public static final String USERAGENT_DEFAULT = "citizen-card-environment/1.2 MOCCA/UNKNOWN";
+ public static final String USERAGENT_BASE = "citizen-card-environment/1.2 MOCCA/";
+
+
protected Properties properties;
protected CertValidator certValidator;
@@ -203,22 +210,22 @@ public abstract class Configurator { }
public void configureVersion() {
- if (properties.getProperty(DataUrlConnection.USERAGENT_CONFIG_P) == null) {
+ if (properties.getProperty(USERAGENT_CONFIG_P) == null) {
Properties p = new Properties();
try {
InputStream is = getManifest();
if (is != null) {
p.load(getManifest());
String version = p.getProperty("Implementation-Build");
- properties.setProperty(DataUrlConnection.USERAGENT_CONFIG_P,
- DataUrlConnection.USERAGENT_BASE + version);
+ properties.setProperty(USERAGENT_CONFIG_P,
+ USERAGENT_BASE + version);
log.debug("Setting user agent to: "
+ properties
- .getProperty(DataUrlConnection.USERAGENT_CONFIG_P));
+ .getProperty(USERAGENT_CONFIG_P));
} else {
log.warn("Cannot read manifest");
- properties.setProperty(DataUrlConnection.USERAGENT_CONFIG_P,
- DataUrlConnection.USERAGENT_DEFAULT);
+ properties.setProperty(USERAGENT_CONFIG_P,
+ USERAGENT_DEFAULT);
}
} catch (IOException e) {
log.error(e);
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; + } +} |