From 2882e14d19cfa58ea382083434210aaf0cfea3e3 Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 13 Mar 2009 07:49:49 +0000 Subject: Fixed Bug#405 and added according test case Fixed Bug#402 Added Feature#403 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@320 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/binding/DataUrlConnectionImpl.java | 16 ++++-- .../gv/egiz/bku/binding/HTTPBindingProcessor.java | 4 +- .../main/java/at/gv/egiz/bku/binding/HttpUtil.java | 3 +- .../java/at/gv/egiz/bku/conf/Configurator.java | 59 +++++++++++++++++----- .../slcommands/impl/xsect/LocRefDereferencer.java | 1 - 5 files changed, 63 insertions(+), 20 deletions(-) (limited to 'bkucommon/src/main/java/at/gv/egiz') 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 4c235456..c8bddbbd 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 @@ -225,10 +225,17 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI { this.url = url; boundary = "--" + IdFactory.getInstance().createId().toString(); requestHttpHeaders = new HashMap(); - if ((config != null) - && (config.getProperty(Configurator.USERAGENT_CONFIG_P) != null)) { - requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, config - .getProperty(Configurator.USERAGENT_CONFIG_P)); + + if (config != null) { + String sigLayout=""; + String version = config.getProperty(Configurator.SIGNATURE_LAYOUT); + if ((version != null) && (!"".equals(version.trim()))) { + requestHttpHeaders.put(Configurator.SIGNATURE_LAYOUT, version); + } else { + log.debug("Do not set siglayout header"); + } + String userAgent = config.getProperty(Configurator.USERAGENT_CONFIG_P, Configurator.USERAGENT_DEFAULT); + requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, userAgent); } else { requestHttpHeaders .put(HttpUtil.HTTP_HEADER_USER_AGENT, Configurator.USERAGENT_DEFAULT); @@ -251,6 +258,7 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI { DataUrlConnectionSPI uc = new DataUrlConnectionImpl(); uc.setConfiguration(config); uc.setSSLSocketFactory(sslSocketFactory); + uc.setHostnameVerifier(hostnameVerifier); return uc; } diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java index 43f42331..d0b2dac1 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java @@ -672,10 +672,10 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements } else { FormParameterStore fps = new FormParameterStore(); fps.init(fp); - if (!fps.isEmpty()) { + //if (!fps.isEmpty()) { log.debug("Setting form parameter: " + fps.getFormParameterName()); formParameterMap.put(fps.getFormParameterName(), fps); - } + //} } } if (slCommand == null) { diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HttpUtil.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HttpUtil.java index b11a4d85..5ea7b25e 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HttpUtil.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HttpUtil.java @@ -29,7 +29,8 @@ public class HttpUtil { public final static String CHAR_SET = "charset"; public final static String DEFAULT_CHARSET = "ISO-8859-1"; public final static String HTTP_HEADER_CONTENT_TYPE = "Content-Type"; - public static final String HTTP_HEADER_USER_AGENT = "User-Agent"; + public static final String HTTP_HEADER_USER_AGENT = "User-Agent"; + public static final String HTTP_HEADER_SERVER = "Server"; public final static String HTTP_HEADER_REFERER = "Referer"; public final static String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; public final static String MULTIPART_FOTMDATA = "multipart/form-data"; 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 6213ffcf..8a94e88d 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 @@ -9,6 +9,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.net.URL; import java.security.GeneralSecurityException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; @@ -26,6 +27,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -39,7 +42,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.binding.DataUrl; -import at.gv.egiz.bku.binding.DataUrlConnection; import at.gv.egiz.bku.slcommands.impl.xsect.DataObject; import at.gv.egiz.bku.slcommands.impl.xsect.STALProvider; import at.gv.egiz.bku.slexceptions.SLRuntimeException; @@ -55,10 +57,12 @@ public abstract class Configurator { 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 SIGNATURE_LAYOUT = "SignatureLayout"; protected Properties properties; protected CertValidator certValidator; + protected String signaturLayoutVersion; protected Configurator() { } @@ -161,7 +165,7 @@ public abstract class Configurator { log.debug("Registering security providers"); Security.insertProviderAt(new IAIK(), 1); Security.insertProviderAt(new ECCProvider(false), 2); - + // registering STALProvider as delegation provider for XSECT STALProvider stalProvider = new STALProvider(); Set services = stalProvider.getServices(); @@ -171,8 +175,10 @@ public abstract class Configurator { XSecProvider.setDelegationProvider(algorithm, stalProvider.getName()); sb.append("\n" + algorithm); } - log.debug("Registered STALProvider as XSecProvider delegation provider for the following services : " + sb.toString()); - + log + .debug("Registered STALProvider as XSecProvider delegation provider for the following services : " + + sb.toString()); + Security.addProvider(stalProvider); XSecProvider.addAsProvider(false); sb = new StringBuilder(); @@ -193,6 +199,31 @@ public abstract class Configurator { } } + public void configureSingatureLayoutVersion() { + if (properties.get(SIGNATURE_LAYOUT) == null) { + try { + String classContainer = Configurator.class.getProtectionDomain() + .getCodeSource().getLocation().toString(); + URL manifestUrl = new URL("jar:" + classContainer + + "!/META-INF/MANIFEST.MF"); + Manifest manifest = new Manifest(manifestUrl.openStream()); + Attributes att = manifest.getMainAttributes(); + String layout = null; + if (att != null) { + layout = att.getValue(SIGNATURE_LAYOUT); + } + if (layout != null) { + log.info("Setting signature layout to: " + layout); + properties.put(SIGNATURE_LAYOUT, layout); + } else { + log.warn("No signature layout version defined"); + } + } catch (Exception ex) { + log.warn("Cannot read manifest", ex); + } + } + } + public void configureNetwork() { String proxy = getProperty("HTTPProxyHost"); String portString = getProperty("HTTPProxyPort"); @@ -217,15 +248,15 @@ public abstract class Configurator { if (is != null) { p.load(getManifest()); String version = p.getProperty("Implementation-Build"); - properties.setProperty(USERAGENT_CONFIG_P, - USERAGENT_BASE + version); + if (version == null) { + version="UNKNOWN"; + } + properties.setProperty(USERAGENT_CONFIG_P, USERAGENT_BASE + version); log.debug("Setting user agent to: " - + properties - .getProperty(USERAGENT_CONFIG_P)); + + properties.getProperty(USERAGENT_CONFIG_P)); } else { log.warn("Cannot read manifest"); - properties.setProperty(USERAGENT_CONFIG_P, - USERAGENT_DEFAULT); + properties.setProperty(USERAGENT_CONFIG_P, USERAGENT_DEFAULT); } } catch (IOException e) { log.error(e); @@ -240,6 +271,7 @@ public abstract class Configurator { configViewer(); configureSSL(); configureVersion(); + configureSingatureLayoutVersion(); configureNetwork(); } @@ -280,11 +312,14 @@ public abstract class Configurator { sslCtx.init(km, new TrustManager[] { pkixTM }, null); } DataUrl.setSSLSocketFactory(sslCtx.getSocketFactory()); - URLDereferencer.getInstance().setSSLSocketFactory(sslCtx.getSocketFactory()); + URLDereferencer.getInstance().setSSLSocketFactory( + sslCtx.getSocketFactory()); } catch (Exception e) { log.error("Cannot configure SSL", e); } - if ((disableAll != null && Boolean.parseBoolean(disableAll)) || (disableHostnameVerification != null && Boolean.parseBoolean(disableHostnameVerification))) { + if ((disableAll != null && Boolean.parseBoolean(disableAll)) + || (disableHostnameVerification != null && Boolean + .parseBoolean(disableHostnameVerification))) { log.warn("---------------------------------"); log.warn(" Disabling Hostname Verification "); log.warn("---------------------------------"); diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java index a6399c9b..f5394157 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java @@ -105,7 +105,6 @@ public class LocRefDereferencer implements URIDereferencer { throw new URIReferenceException("Failed to dereference URI '" + locRef + "'. " + e.getMessage(), e); } - return new OctetStreamData(streamData.getStream(), locRef, streamData .getContentType()); } -- cgit v1.2.3