diff options
Diffstat (limited to 'mocca-1.2.11/utils/src/main/java/at/gv/egiz')
41 files changed, 0 insertions, 4523 deletions
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugOutputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugOutputStream.java deleted file mode 100644 index 8516b76c..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugOutputStream.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -* 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.bku.utils; - -import java.io.ByteArrayOutputStream; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class DebugOutputStream extends FilterOutputStream { - - private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - public DebugOutputStream(OutputStream out) { - super(out); - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - buffer.write(b, off, len); - super.write(b, off, len); - } - - @Override - public void write(int b) throws IOException { - buffer.write(b); - super.write(b); - } - - public byte[] getBufferedBytes() { - return buffer.toByteArray(); - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugReader.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugReader.java deleted file mode 100644 index cafe4a72..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugReader.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -* 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.bku.utils; - -import java.io.FilterReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringWriter; - -public class DebugReader extends FilterReader { - - private StringWriter buffer = new StringWriter(); - - public DebugReader(Reader in) { - super(in); - } - - public DebugReader(Reader in, String start) { - super(in); - buffer.write(start); - } - - @Override - public int read() throws IOException { - int c = super.read(); - if (c != -1) - buffer.write(c); - return c; - } - - @Override - public int read(char[] cbuf, int off, int len) throws IOException { - int l = super.read(cbuf, off, len); - if (l != -1 ) { - buffer.write(cbuf, off, l); - } - return l; - } - - public String getCachedString() { - return buffer.toString(); - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugWriter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugWriter.java deleted file mode 100644 index 5566f927..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugWriter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -* 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.bku.utils; - -import java.io.FilterWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -public class DebugWriter extends FilterWriter { - - private Writer buffer = new StringWriter(); - - public DebugWriter(Writer out) { - super(out); - } - - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - buffer.write(cbuf, off, len); - super.write(cbuf, off, len); - } - - @Override - public void write(String str, int off, int len) throws IOException { - buffer.write(str, off, len); - super.write(str, off, len); - } - - @Override - public void write(int c) throws IOException { - buffer.write(c); - super.write(c); - } - - public String getBufferedString() { - return buffer.toString(); - } - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java deleted file mode 100644 index 88d49bad..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -* 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.bku.utils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-
-public class HexDump {
-
- public static String hexDump(InputStream is) throws IOException {
- StringWriter writer = new StringWriter();
- hexDump(is, writer);
- return writer.toString();
- }
-
- public static void hexDump(InputStream is, Writer writer) throws IOException {
- hexDump(is, writer, 16);
- }
-
- public static void hexDump(InputStream is, Writer writer, int chunkSize) throws IOException {
-
- byte[] chunk = new byte[chunkSize];
- long adr = 0;
- for (int l; (l = is.read(chunk)) != -1;) {
-
- writer.append(String.format("[%06x]", adr));
- for (int i = 0; i < l; i++) {
- if (i % 8 == 0) {
- writer.append(" ");
- } else {
- writer.append(":");
- }
- writer.append(Integer.toHexString((chunk[i] & 240) >> 4));
- writer.append(Integer.toHexString(chunk[i] & 15));
- }
-
- for (int i = 0; i < (chunkSize - l); i++) {
- writer.append(" ");
- }
-
- for (int i = 0; i < l; i++) {
- if (i % 8 == 0) {
- writer.append(" ");
- }
- if (chunk[i] > 31 && chunk[i] < 127) {
- writer.append((char) chunk[i]);
- } else {
- writer.append(".");
- }
- }
-
- writer.append("\n");
- adr += l;
-
- }
-
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/NullOutputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/NullOutputStream.java deleted file mode 100644 index edbd9c01..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/NullOutputStream.java +++ /dev/null @@ -1,10 +0,0 @@ -package at.gv.egiz.bku.utils;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class NullOutputStream extends OutputStream {
- @Override
- public void write(int b) throws IOException {
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/StreamUtil.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/StreamUtil.java deleted file mode 100644 index a774df2b..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/StreamUtil.java +++ /dev/null @@ -1,101 +0,0 @@ -/* -* 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.bku.utils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-
-public class StreamUtil {
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(InputStream is, OutputStream os)
- throws IOException {
- copyStream(is, os, 1024);
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(InputStream is, OutputStream os, int bufferSize)
- throws IOException {
- byte[] buffer = new byte[bufferSize];
- copyStream(is, os, buffer);
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(InputStream is, OutputStream os, byte[] buffer)
- throws IOException {
- for (int i = is.read(buffer); i > -1; i = is.read(buffer)) {
- os.write(buffer, 0, i);
- }
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(Reader is, Writer os)
- throws IOException {
- copyStream(is, os, 1024);
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(Reader is, Writer os, int bufferSize)
- throws IOException {
- char[] chars = new char[bufferSize];
- for (int i = is.read(chars); i > -1; i = is.read(chars)) {
- os.write(chars, 0, i);
- }
- }
-
-
- public static String asString(InputStream is, String charset)
- throws IOException {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- copyStream(is, os);
- return new String(os.toByteArray(), charset);
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingInputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingInputStream.java deleted file mode 100644 index 28ef6b88..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingInputStream.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - */ -package at.gv.egiz.bku.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.CharBuffer; - -/** - * @author mcentner - * - */ -public class URLEncodingInputStream extends InputStream { - - private char[] buffer = new char[1]; - - private CharBuffer charBuffer = CharBuffer.wrap(buffer); - - protected Readable in; - - /** - * @param in - */ - public URLEncodingInputStream(Readable in) { - this.in = in; - } - - /* (non-Javadoc) - * @see java.io.InputStream#read() - */ - @Override - public int read() throws IOException { - charBuffer.rewind(); - if (in.read(charBuffer) == -1) { - return -1; - } - if (buffer[0] == '+') { - return ' '; - } else if (buffer[0] == '%') { - charBuffer.rewind(); - if (in.read(charBuffer) == -1) { - throw new IOException("Invalid URL encoding."); - } - int c1 = Character.digit(buffer[0], 16); - charBuffer.rewind(); - if (in.read(charBuffer) == -1) { - throw new IOException("Invalid URL encoding."); - } - int c2 = Character.digit(buffer[0], 16); - if (c1 == -1 || c2 == -1) { - throw new IOException("Invalid URL encoding."); - } - return ((c1 << 4) | c2); - } else { - return buffer[0]; - } - } - - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingOutputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingOutputStream.java deleted file mode 100644 index df42df6d..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingOutputStream.java +++ /dev/null @@ -1,134 +0,0 @@ -/* -* 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.bku.utils; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.CharBuffer; -import java.util.BitSet; - -/** - * An URLEncoding <a - * href="http://tools.ietf.org/html/rfc3986#section-2.1">RFC3986, Section 2.1</a> - * OutputStream. - * - * @author mcentner - */ -public class URLEncodingOutputStream extends OutputStream { - - private static final int MAX_BUFFER_SIZE = 512; - - private static final BitSet UNRESERVED = new BitSet(256); - - static { - for (int i = '0'; i <= '9'; i++) { - UNRESERVED.set(i); - } - for (int i = 'a'; i <= 'z'; i++) { - UNRESERVED.set(i); - } - for (int i = 'A'; i <= 'Z'; i++) { - UNRESERVED.set(i); - } - UNRESERVED.set('-'); - UNRESERVED.set('_'); - UNRESERVED.set('.'); - UNRESERVED.set('*'); - UNRESERVED.set(' '); - } - - private static final char[] HEX = new char[] { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' - }; - - private char[] buf; - - protected Appendable out; - - /** - * Creates a new instance of this URLEncodingOutputStream that writes to the - * given Appendable. - * <p> - * Note: According to - * http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars the input - * for the {@link #write()} methods should be the UTF-8. - * </p> - * - * @param out - */ - public URLEncodingOutputStream(Appendable out) { - this.out = out; - } - - /* (non-Javadoc) - * @see java.io.OutputStream#write(int) - */ - @Override - public void write(int b) throws IOException { - b &= 0xFF; - if (UNRESERVED.get(b)) { - if (b == ' ') { - out.append('+'); - } else { - out.append((char) b); - } - } else { - out.append('%').append(HEX[b >>> 4]).append(HEX[b & 0xF]); - } - - } - - /* (non-Javadoc) - * @see java.io.OutputStream#write(byte[], int, int) - */ - @Override - public void write(byte[] b, int off, int len) throws IOException { - - // ensure a buffer at least double the size of end - start + 1 - // but max - int sz = Math.min(len + 1, MAX_BUFFER_SIZE); - if (buf == null || buf.length < sz) { - buf = new char[sz]; - } - - int bPos = 0; - for (int i = 0; i < len; i++) { - if (bPos + 3 > buf.length) { - // flush buffer - out.append(CharBuffer.wrap(buf, 0, bPos)); - bPos = 0; - } - int c = 0xFF & b[off + i]; - if (UNRESERVED.get(c)) { - if (c == ' ') { - buf[bPos++] = '+'; - } else { - buf[bPos++] = (char) c; - } - } else { - buf[bPos++] = '%'; - buf[bPos++] = HEX[c >>> 4]; - buf[bPos++] = HEX[c & 0xF]; - } - } - out.append(CharBuffer.wrap(buf, 0, bPos)); - - } - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingWriter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingWriter.java deleted file mode 100644 index 3ba90265..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingWriter.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.bku.utils; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.Charset; - -/** - * An URLEncoding <a - * href="http://tools.ietf.org/html/rfc3986#section-2.1">RFC3986, Section - * 2.1</a> Writer, that uses an UTF-8 encoding according to <a href - * ="http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars" - * >http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars</a> for - * writing non-ASCII characters. - * - * @author mcentner - */ -public class URLEncodingWriter extends Writer { - - protected OutputStreamWriter osw; - - public URLEncodingWriter(Appendable out) { - URLEncodingOutputStream urlEnc = new URLEncodingOutputStream(out); - osw = new OutputStreamWriter(urlEnc, Charset.forName("UTF-8")); - } - - @Override - public void close() throws IOException { - osw.close(); - } - - @Override - public void flush() throws IOException { - osw.flush(); - } - - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - osw.write(cbuf, off, len); - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/binding/Protocol.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/binding/Protocol.java deleted file mode 100644 index f0504697..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/binding/Protocol.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* 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.bku.utils.binding;
-
-public enum Protocol {
- HTTP("http"), HTTPS("https");
-
- private String name;
-
- Protocol(String s) {
- name = s;
- }
-
- public String toString() {
- return name;
- }
-
- public static Protocol fromString(String protocol) {
- if (HTTP.toString().equalsIgnoreCase(protocol)) {
- return HTTP;
- }
- if (HTTPS.toString().equalsIgnoreCase(protocol)) {
- return HTTPS;
- }
- return null;
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/FormDataURLSupplier.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/FormDataURLSupplier.java deleted file mode 100644 index 7272f1bb..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/FormDataURLSupplier.java +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-import java.io.InputStream;
-
-public interface FormDataURLSupplier {
- public static final String PROPERTY_KEY_NAME = "at.gv.egiz.bku.util.urldereferencer.FormDataURLSupplier";
-
- public InputStream getFormData(String aParameterName);
- public String getFormDataContentType(String aParameterName);
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/HTTPURLProtocolHandlerImpl.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/HTTPURLProtocolHandlerImpl.java deleted file mode 100644 index dfe7d5e6..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/HTTPURLProtocolHandlerImpl.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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.bku.utils.urldereferencer; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.InvalidParameterException; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class HTTPURLProtocolHandlerImpl implements URLProtocolHandler { - - private static Log log = LogFactory.getLog(HTTPURLProtocolHandlerImpl.class); - - public final static String HTTP = "http"; - public final static String HTTPS = "https"; - public final static String FORMDATA = "formdata"; - public final static String[] PROTOCOLS = { HTTP, HTTPS, FORMDATA }; - - private HostnameVerifier hostnameVerifier; - private SSLSocketFactory sslSocketFactory; - - public StreamData dereference(String aUrl, URLDereferencerContext aContext) - throws IOException { - String urlString = aUrl.toLowerCase().trim(); - if (urlString.startsWith(FORMDATA)) { - log.debug("Requested to dereference a formdata url"); - return dereferenceFormData(aUrl, aContext); - } - - URL url = new URL(aUrl); - if ((!HTTP.equalsIgnoreCase(url.getProtocol()) && (!HTTPS - .equalsIgnoreCase(url.getProtocol())))) { - throw new InvalidParameterException("Url " + aUrl + " not supported"); - } - return dereferenceHTTP(url); - } - - protected StreamData dereferenceHTTP(URL url) throws IOException { - log.debug("Dereferencing url: " + url); - HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); - if (httpConn instanceof HttpsURLConnection) { - log.trace("Detected ssl connection"); - HttpsURLConnection https = (HttpsURLConnection) httpConn; - if (sslSocketFactory != null) { - log.debug("Setting custom ssl socket factory for ssl connection"); - https.setSSLSocketFactory(sslSocketFactory); - } else { - log.trace("No custom socket factory set"); - } - if (hostnameVerifier != null) { - log.debug("Setting custom hostname verifier"); - https.setHostnameVerifier(hostnameVerifier); - } - } else { - log.trace("No secure connection with: "+url+ " class="+httpConn.getClass()); - } - log.trace("Successfully opened connection"); - return new StreamData(url.toString(), httpConn.getContentType(), httpConn - .getInputStream()); - } - - /** - * - * @param aUrl - * @param aContext - * @return - * @throws IOException if the data cannot be found or reading the stream failed. - */ - protected StreamData dereferenceFormData(String aUrl, - URLDereferencerContext aContext) throws IOException { - log.debug("Dereferencing formdata url: " + aUrl); - String[] parts = aUrl.split(":", 2); - FormDataURLSupplier supplier = (FormDataURLSupplier) aContext - .getProperty(FormDataURLSupplier.PROPERTY_KEY_NAME); - if (supplier == null) { - throw new NullPointerException( - "No FormdataUrlSupplier found in provided context"); - } - String contentType = supplier.getFormDataContentType(parts[1]); - InputStream is = supplier.getFormData(parts[1]); - if (is != null) { - return new StreamData(aUrl, contentType, is); - } - throw new IOException("Cannot dereference url: formdata not found"); - } - - @Override - public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { - this.hostnameVerifier = hostnameVerifier; - } - - @Override - public void setSSLSocketFactory(SSLSocketFactory socketFactory) { - this.sslSocketFactory = socketFactory; - } - -}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/SimpleFormDataContextImpl.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/SimpleFormDataContextImpl.java deleted file mode 100644 index e9da9c81..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/SimpleFormDataContextImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-public class SimpleFormDataContextImpl implements URLDereferencerContext {
- protected FormDataURLSupplier formdata;
-
- /**
- *
- * @param formdata must not be null
- */
- public SimpleFormDataContextImpl(FormDataURLSupplier formdata) {
- if (formdata == null) {
- throw new NullPointerException("FormdataURLSupplier must not be null");
- }
- this.formdata = formdata;
- }
-
- @Override
- public Object getProperty(Object key) {
- if (key.equals(FormDataURLSupplier.PROPERTY_KEY_NAME)) {
- return formdata;
- }
- return null;
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/StreamData.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/StreamData.java deleted file mode 100644 index 541c6878..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/StreamData.java +++ /dev/null @@ -1,61 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-import java.io.InputStream;
-
-/**
- * This class models the result when dereferencing an URL.
- *
- */
-public class StreamData {
-
- protected InputStream inputStream;
- protected String url;
- protected String contentType;
-
- /**
- *
- * @param url
- * @param contentType
- * @param stream must not be null
- */
- public StreamData(String url, String contentType, InputStream stream) {
- if (stream == null) {
- throw new NullPointerException("Parameter inputstream must not be null");
- }
- inputStream = stream;
- this.contentType = contentType;
- this.url = url;
- }
-
- public String getUrl() {
- return url;
- }
-
- /**
- *
- * @return the returned stream must be closed
- */
- public InputStream getStream() {
- return inputStream;
- }
-
- public String getContentType() {
- return contentType;
- }
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URIResolverAdapter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URIResolverAdapter.java deleted file mode 100644 index 2d11010e..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URIResolverAdapter.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Adapter to make the Urldereferencer work as URIResolver for
- * Stylesheettransforms.
- *
- * @author wbauer
- *
- */
-public class URIResolverAdapter implements URIResolver {
-
- private static Log log = LogFactory.getLog(URIResolverAdapter.class);
-
- private URLDereferencer urlDereferencer;
- private URLDereferencerContext ctx;
-
- /**
- *
- * @param deferecencer
- * must not be null
- * @param ctx may be null
- */
- public URIResolverAdapter(URLDereferencer deferecencer,
- URLDereferencerContext ctx) {
- if (deferecencer == null) {
- throw new NullPointerException("Urlderefencer must not be set to null");
- }
- this.urlDereferencer = deferecencer;
- this.ctx = ctx;
- }
-
- @Override
- public Source resolve(String href, String base) throws TransformerException {
- log.debug("Resolving href: "+href+" base: "+base);
- try {
- URI baseUri = null;
- URI hrefUri = new URI(href);
- if (base != null) {
- baseUri = new URI(base);
- }
- URI abs;
- if (baseUri != null) {
- abs = baseUri.resolve(hrefUri);
- } else {
- abs = hrefUri;
- }
- if (!abs.isAbsolute()) {
- throw new TransformerException("Only absolute URLs are supported");
- }
- return new StreamSource(urlDereferencer.dereference(abs.toString(), ctx)
- .getStream());
- } catch (URISyntaxException e) {
- throw new TransformerException("Cannot resolve URI: base:" + base
- + " href:" + href, e);
- } catch (IOException iox) {
- throw new TransformerException("Cannot resolve URI: base:" + base
- + " href:" + href, iox);
- }
- }
-
- public URLDereferencerContext getCtx() {
- return ctx;
- }
-
- public void setCtx(URLDereferencerContext ctx) {
- this.ctx = ctx;
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencer.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencer.java deleted file mode 100644 index 7361ec26..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencer.java +++ /dev/null @@ -1,108 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.HashMap;
-import java.util.Map;
- -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSocketFactory; -
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Class used to dereference (external URLs).
- *
- * @author wbauer
- *
- */
-public class URLDereferencer {
-
- private static Log log = LogFactory.getLog(URLDereferencer.class);
-
- private static URLDereferencer instance = new URLDereferencer();
-
- private Map<String, URLProtocolHandler> handlerMap = new HashMap<String, URLProtocolHandler>();
- - private HostnameVerifier hostnameVerifier; - private SSLSocketFactory sslSocketFactory; -
- private URLDereferencer() {
- registerHandlers();
- }
-
- /**
- *
- * @param aUrl
- * must not be null
- * @param aContext
- * @throws MalformedURLException
- * if the protocol is not supported - * @throws IOException if the url cannot be dereferenced (e.g. formdata not provided) - *
- */
- public StreamData dereference(String aUrl, URLDereferencerContext aContext)
- throws IOException {
- log.debug("Looking for handler for URL: " + aUrl);
- int i = aUrl.indexOf(":");
- if (i == -1) {
- throw new MalformedURLException("Invalid url: " + aUrl);
- }
- String protocol = aUrl.substring(0, i).toLowerCase().trim();
- URLProtocolHandler handler = handlerMap.get(protocol);
- if (handler == null) {
- throw new MalformedURLException("No handler for protocol: " + protocol
- + " found");
- } - handler.setHostnameVerifier(hostnameVerifier); - handler.setSSLSocketFactory(sslSocketFactory);
- return handler.dereference(aUrl, aContext);
- }
-
- /**
- * Registers a handler for a protocol.
- *
- * @param aProtocol
- * @param aHandler
- * may be set to null to disable this protocol
- */
- public void registerHandler(String aProtocol, URLProtocolHandler aHandler) {
- handlerMap.put(aProtocol.toLowerCase(), aHandler);
- }
-
- public static URLDereferencer getInstance() {
- return instance;
- }
-
- protected void registerHandlers() {
- URLProtocolHandler handler = new HTTPURLProtocolHandlerImpl();
- for (String proto : HTTPURLProtocolHandlerImpl.PROTOCOLS) {
- handlerMap.put(proto, handler);
- }
- } - - public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { - this.hostnameVerifier = hostnameVerifier; - } - - public void setSSLSocketFactory(SSLSocketFactory socketFactory) { - this.sslSocketFactory = socketFactory; - }
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencerContext.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencerContext.java deleted file mode 100644 index 6befd5b3..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencerContext.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-public interface URLDereferencerContext {
-
- /**
- *
- * @param key
- * @return may return null
- */
- public Object getProperty(Object key);
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLProtocolHandler.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLProtocolHandler.java deleted file mode 100644 index f886bd4e..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLProtocolHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -* 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.bku.utils.urldereferencer;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
- -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSocketFactory; -
-
-public interface URLProtocolHandler {
- /**
- *
- * @param aUrl
- * @param aContext
- * @return the streamdata of this url or null if the url cannot be resolved.
- * @throws IOException
- */
- public StreamData dereference(String aUrl, URLDereferencerContext aContext) throws IOException; - - public void setSSLSocketFactory(SSLSocketFactory socketFactory); - - public void setHostnameVerifier(HostnameVerifier hostnameVerifier);
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/dom/DOMUtils.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/dom/DOMUtils.java deleted file mode 100644 index 32c7c5e6..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/dom/DOMUtils.java +++ /dev/null @@ -1,115 +0,0 @@ -/* -* 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.dom;
-
-import iaik.utils.Base64OutputStream;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Text;
-import org.w3c.dom.bootstrap.DOMImplementationRegistry;
-import org.w3c.dom.ls.DOMImplementationLS;
-
-public final class DOMUtils {
-
- /**
- * DOM Implementation.
- */
- private static String DOM_LS_3_0 = "LS 3.0";
-
- private static DOMImplementationLS domImplLS;
-
- private DOMUtils() {
- }
-
- private static synchronized void ensureDOMImplementation() {
-
- if (domImplLS == null) {
-
- DOMImplementationRegistry registry;
- try {
- registry = DOMImplementationRegistry.newInstance();
- } catch (Exception e) {
- throw new RuntimeException("Failed to get DOMImplementationRegistry.");
- }
-
- domImplLS = (DOMImplementationLS) registry.getDOMImplementation(DOM_LS_3_0);
- if (domImplLS == null) {
- throw new RuntimeException("Failed to get DOMImplementation " + DOM_LS_3_0);
- }
-
- }
-
- }
-
- public static DOMImplementationLS getDOMImplementationLS() {
-
- if (domImplLS == null) {
- ensureDOMImplementation();
- }
-
- return domImplLS;
- }
-
- public static Document createDocument() {
-
- // This does not work with the Xerces-J version (2.6.2) included in Java 6
- //document = ((DOMImplementation) domImplLS).createDocument(null, null, null);
- // Therefore we have to employ the good old DocumentBuilderFactory
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db;
- try {
- db = dbf.newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- throw new RuntimeException(e);
- }
- return db.newDocument();
-
- }
-
- public static Text createBase64Text(byte[] bytes, Document doc) throws IOException {
-
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- Base64OutputStream base64OutputStream = new Base64OutputStream(outputStream);
- base64OutputStream.write(bytes);
- base64OutputStream.flush();
- return doc.createTextNode(outputStream.toString("ASCII"));
-
- }
-
- public static Text createBase64Text(InputStream bytes, Document doc) throws IOException {
-
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- Base64OutputStream base64OutputStream = new Base64OutputStream(outputStream, new byte[] {0xa});
-
- byte[] b = new byte[2^8];
- for(int l; (l = bytes.read(b)) != -1;) {
- base64OutputStream.write(b, 0, l);
- }
-
- base64OutputStream.flush();
- return doc.createTextNode(outputStream.toString("ASCII"));
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java deleted file mode 100644 index 31e5163a..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java +++ /dev/null @@ -1,416 +0,0 @@ -/* -* 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.idlink; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.security.PublicKey; -import java.security.cert.X509Certificate; -import java.util.List; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.PropertyException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMResult; - -import org.w3._2000._09.xmldsig_.KeyValueType; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import at.buergerkarte.namespaces.personenbindung._20020506_.CompressedIdentityLinkType; -import at.gv.e_government.reference.namespace.persondata._20020228_.AbstractPersonType; -import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType; -import at.gv.e_government.reference.namespace.persondata._20020228_.PersonNameType; -import at.gv.e_government.reference.namespace.persondata._20020228_.PhysicalPersonType; -import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType.Value; -import at.gv.e_government.reference.namespace.persondata._20020228_.PersonNameType.FamilyName; -import at.gv.egiz.idlink.ans1.CitizenPublicKey; -import at.gv.egiz.idlink.ans1.IdentityLink; -import at.gv.egiz.idlink.ans1.PersonData; -import at.gv.egiz.idlink.ans1.PhysicalPersonData; -import at.gv.egiz.marshal.MarshallerFactory; -import at.gv.egiz.marshal.NamespacePrefixMapperImpl; -import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; -import at.gv.egiz.xmldsig.KeyValueFactory; - -public class CompressedIdentityLinkFactory { - - /** - * The instance returned by {@link #getInstance()}. - */ - private static CompressedIdentityLinkFactory instance; - - /** - * The <code>JAXBContext</code>. - */ - private static JAXBContext jaxbContext; - - /** - * The <code>KeyValueFactory</code>. - */ - private static KeyValueFactory keyValueFactory; - - /** - * Get an instance of this <code>CompressedIdentityLinkFactory</code>. - * - * @return an instance of this <code>CompressedIdentityLinkFactory</code> - */ - public synchronized static CompressedIdentityLinkFactory getInstance() { - if (instance == null) { - instance = new CompressedIdentityLinkFactory(); - } - return instance; - } - - /** - * Private constructor. - */ - private CompressedIdentityLinkFactory() { - - keyValueFactory = new KeyValueFactory(); - - StringBuffer packageNames = new StringBuffer(); - packageNames.append(at.gv.e_government.reference.namespace.persondata._20020228_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(org.w3._2001._04.xmldsig_more_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(at.buergerkarte.namespaces.personenbindung._20020506_.ObjectFactory.class.getPackage().getName()); - - try { - jaxbContext = JAXBContext.newInstance(packageNames.toString()); - } catch (JAXBException e) { - // we should not get an JAXBException initializing the JAXBContext - throw new RuntimeException(e); - } - - } - - public IdentityLink createIdLink(CompressedIdentityLinkType compressedIdentityLinkType) { - - // IssuerTemplate - String issuerTemplate = compressedIdentityLinkType.getIssuerTemplate(); - - // AssertionId - String assertionID = compressedIdentityLinkType.getAssertionID(); - - // IssueInstant - String issueInstant = compressedIdentityLinkType.getIssueInstant(); - - AbstractPersonType personDataType = compressedIdentityLinkType.getPersonData(); - - String baseId = null; - - List<IdentificationType> identifications = personDataType.getIdentification(); - for (IdentificationType identificationType : identifications) { - String type = identificationType.getType(); - if ("urn:publicid:gv.at:baseid".equals(type)) { - baseId = identificationType.getValue().getValue(); - } - } - - String givenName = null; - String familyName = null; - String dateOfBirth = null; - - if (personDataType instanceof PhysicalPersonType) { - PhysicalPersonType physicalPersonType = (PhysicalPersonType) personDataType; - PersonNameType name = physicalPersonType.getName(); - List<String> givenNames = name.getGivenName(); - if (!givenNames.isEmpty()) { - givenName = givenNames.get(0); - } - List<FamilyName> familyNames = name.getFamilyName(); - if (!familyNames.isEmpty()) { - familyName = familyNames.get(0).getValue(); - } - dateOfBirth = physicalPersonType.getDateOfBirth(); - } - - PhysicalPersonData physicalPersonData = new PhysicalPersonData(baseId, givenName, familyName, dateOfBirth); - PersonData personData = new PersonData(physicalPersonData); - - int numKeys = compressedIdentityLinkType.getCitizenPublicKey().size(); - CitizenPublicKey[] citizenPublicKeys = new CitizenPublicKey[numKeys]; - for (int i = 0; i < numKeys;) { - citizenPublicKeys[i] = new CitizenPublicKey(++i); - } - - byte[] signatureValue = compressedIdentityLinkType.getSignatureValue(); - byte[] referenceDigest = compressedIdentityLinkType.getReferenceDigest(); - byte[] referenceManifestDigest = compressedIdentityLinkType.getReferenceManifestDigest(); - byte[] manifestReferenceDigest = compressedIdentityLinkType.getManifestReferenceDigest(); - - IdentityLink idLink = new IdentityLink(issuerTemplate, assertionID, issueInstant, personData, citizenPublicKeys, signatureValue); - idLink.setReferenceDigest(referenceDigest); - idLink.setReferenceManifestDigest(referenceManifestDigest); - idLink.setManifestReferenceDigest(manifestReferenceDigest); - - return idLink; - - } - - /** - * Creates a new <code>CompressedIdentityLink</code> element from the given - * ASN.1 representation of an <code>idLink</code>. - * - * @param idLink - * the ASN.1 representation of an <code>IdentityLink</code> - * @param certificates - * a list of {@link X509Certificate}s containing the corresponding - * public keys - * @param domainId TODO - * @return a new <code>CompressedIdentityLink</code> element - * - * @throws NullPointerException - * if <code>idLink</code> or <code>certificates</code> is - * <code>null</code> - * @throws IllegalArgumentException - * if <code>idLink</code> references certificates not in the range - * of the <code>certificates</code> list - */ - public JAXBElement<CompressedIdentityLinkType> createCompressedIdentityLink( - at.gv.egiz.idlink.ans1.IdentityLink idLink, - List<X509Certificate> certificates, String domainId) { - - at.gv.e_government.reference.namespace.persondata._20020228_.ObjectFactory prFactory = - new at.gv.e_government.reference.namespace.persondata._20020228_.ObjectFactory(); - - at.buergerkarte.namespaces.personenbindung._20020506_.ObjectFactory pbFactory = - new at.buergerkarte.namespaces.personenbindung._20020506_.ObjectFactory(); - - org.w3._2000._09.xmldsig_.ObjectFactory dsFactory = new org.w3._2000._09.xmldsig_.ObjectFactory(); - - // PersonData - PhysicalPersonData __physicalPersonData = idLink.getPersonData() - .getPhysicalPerson(); - - Value identificationTypeValue = prFactory.createIdentificationTypeValue(); - identificationTypeValue.setValue(__physicalPersonData.getBaseId()); - IdentificationType identificationType = prFactory - .createIdentificationType(); - identificationType.setValue(identificationTypeValue); - if (domainId != null) { - identificationType.setType(domainId); - } else { - identificationType.setType("urn:publicid:gv.at:baseid"); - } - - PersonNameType personNameType = prFactory.createPersonNameType(); - FamilyName personNameTypeFamilyName = prFactory - .createPersonNameTypeFamilyName(); - personNameTypeFamilyName.setValue(__physicalPersonData.getFamilyName()); - personNameType.getFamilyName().add(personNameTypeFamilyName); - personNameType.getGivenName().add(__physicalPersonData.getGivenName()); - - PhysicalPersonType physicalPersonType = prFactory - .createPhysicalPersonType(); - physicalPersonType.getIdentification().add(identificationType); - physicalPersonType.setName(personNameType); - physicalPersonType.setDateOfBirth(__physicalPersonData.getDateOfBirth()); - - // CompressedIdentityLink - CompressedIdentityLinkType compressedIdentityLinkType = pbFactory - .createCompressedIdentityLinkType(); - compressedIdentityLinkType.setIssuerTemplate(idLink.getIssuerTemplate()); - compressedIdentityLinkType.setAssertionID(idLink.getAssertionID()); - compressedIdentityLinkType.setIssueInstant(idLink.getIssueInstant()); - compressedIdentityLinkType.setPersonData(physicalPersonType); - - // CitizenPublicKey - CitizenPublicKey[] __citizenPublicKeys = idLink.getCitizenPublicKeys(); - for (CitizenPublicKey __citizenPublicKey : __citizenPublicKeys) { - - X509Certificate certificate = certificates.get(__citizenPublicKey.getOnToken()); - PublicKey publicKey = certificate.getPublicKey(); - - JAXBElement<?> keyValue; - try { - keyValue = keyValueFactory.createKeyValue(publicKey); - } catch (KeyTypeNotSupportedException e) { - // TODO: handle exception properly - throw new RuntimeException(e); - } - - KeyValueType keyValueType = dsFactory.createKeyValueType(); - keyValueType.getContent().add(keyValue); - - compressedIdentityLinkType.getCitizenPublicKey().add(keyValueType); - } - - compressedIdentityLinkType.setSignatureValue(idLink.getSignatureValue()); - compressedIdentityLinkType.setReferenceDigest(idLink.getReferenceDigest()); - compressedIdentityLinkType.setReferenceManifestDigest(idLink - .getReferenceManifestDigest()); - compressedIdentityLinkType.setManifestReferenceDigest(idLink - .getManifestReferenceDigest()); - JAXBElement<CompressedIdentityLinkType> compressedIdentityLink = pbFactory - .createCompressedIdentityLink(compressedIdentityLinkType); - - return compressedIdentityLink; - - } - - /** - * Marshall the given <code>compressedIdentityLink</code> into a DOM document - * with the given Nodes as <code>parent</code> and <code>nextSibling</code> - * nodes. - * - * @param compressedIdentityLink - * the <code>CompressedIdentityLink</code> element - * @param parent - * the parent node - * @param nextSibling - * the next sibling node (may be <code>null</code>) - * @param applyWorkarounds - * apply workarounds as spefiyed by - * {@link #applyWorkarounds(Element, int)} - * - * @throws JAXBException - * if an unexpected error occurs while marshalling - * @throws NullPointerException - * if <code>compressdIdentityLink</code> or <code>parent</code> is - * <code>null</code> - */ - public void marshallCompressedIdentityLink( - JAXBElement<CompressedIdentityLinkType> compressedIdentityLink, - Node parent, Node nextSibling, boolean applyWorkarounds) throws JAXBException { - - DOMResult result = new DOMResult(parent, nextSibling); - - - try { - Marshaller marshaller = MarshallerFactory.createMarshaller(jaxbContext); - - marshaller.marshal(compressedIdentityLink, result); - } catch (PropertyException e) { - throw new RuntimeException(e); - } - - if (applyWorkarounds) { - Element element = (Element) ((nextSibling != null) - ? nextSibling.getPreviousSibling() - : parent.getFirstChild()); - applyWorkarounds(element, 76); - } - - } - - @SuppressWarnings("unchecked") - public CompressedIdentityLinkType unmarshallCompressedIdentityLink(Source source) throws JAXBException { - - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - - return ((JAXBElement<CompressedIdentityLinkType>) unmarshaller.unmarshal(source)).getValue(); - - } - - /** - * Apply some workarounds to the given CompressedIdentityLink - * <code>element</code> to achieve compatibility with IdentityLink - * transformation stylesheets that have been designed for a (buggy) form of - * the CompressedIdentityLink as produced by a well-known citizen card - * environment implementation. - * - * <ol> - * <li>Replace the attribute node <code>URN</code> of the - * <code>NamedCurve</code> element of an <code>ECDSAKeyValue</code> element by - * a child text-node with the same content.</li> - * <li>Replace the attribute nodes <code>Value</code> of the <code>X</code> - * and <code>Y</code> elements of an <code>ECDSAKeyValue</code> element by a - * child text-node with the same content.</li> - * <li>Insert "\n" at <code>base64LineLength</code> into the Base64 - * content of the <code>Modulus</code> element of an <code>RSAKeyValue</code> - * element. - * </ol> - * - * @param element - * the <code>CompressedIdentityLink</code> element - * @param base64LineLength - * the line length of Base64 content - */ - public void applyWorkarounds(Element element, int base64LineLength) { - - Document document = element.getOwnerDocument(); - - NodeList nodeList = element.getElementsByTagNameNS( - "http://www.w3.org/2001/04/xmldsig-more#", "NamedCurve"); - for (int i = 0; i < nodeList.getLength(); i++) { - Node ecdsaNameCurve = nodeList.item(i); - Attr attrNode = ((Element) ecdsaNameCurve).getAttributeNodeNS(null, - "URN"); - ecdsaNameCurve - .appendChild(document.createTextNode(attrNode.getValue())); - ((Element) ecdsaNameCurve).removeAttributeNode(attrNode); - } - nodeList = document.getElementsByTagNameNS( - "http://www.w3.org/2001/04/xmldsig-more#", "X"); - for (int i = 0; i < nodeList.getLength(); i++) { - Node x = nodeList.item(i); - Attr attrNode = ((Element) x).getAttributeNodeNS(null, "Value"); - x.appendChild(document.createTextNode(attrNode.getValue())); - ((Element) x).removeAttributeNode(attrNode); - } - nodeList = document.getElementsByTagNameNS( - "http://www.w3.org/2001/04/xmldsig-more#", "Y"); - for (int i = 0; i < nodeList.getLength(); i++) { - Node y = nodeList.item(i); - Attr attrNode = ((Element) y).getAttributeNodeNS(null, "Value"); - y.appendChild(document.createTextNode(attrNode.getValue())); - ((Element) y).removeAttributeNode(attrNode); - } - - if (base64LineLength > 0) { - nodeList = document.getElementsByTagNameNS( - "http://www.w3.org/2000/09/xmldsig#", "Modulus"); - for (int i = 0; i < nodeList.getLength(); i++) { - Node modulus = nodeList.item(i); - String value = ((Element) modulus).getTextContent(); - BufferedReader reader = new BufferedReader(new InputStreamReader( - new ByteArrayInputStream(value.getBytes()))); - char[] buff = new char[base64LineLength]; - StringBuffer newValue = new StringBuffer(); - int found = 0; - try { - while ((found = reader.read(buff)) > 0) { - newValue.append(buff, 0, found); - if (found == base64LineLength) - newValue.append('\n'); - } - } catch (IOException e) { - // this should never happen, as we are reading from a ByteArrayInputStream - throw new RuntimeException(e); - } - ((Element) modulus).setTextContent(newValue.toString()); - } - - } - - - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java deleted file mode 100644 index 38597446..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java +++ /dev/null @@ -1,428 +0,0 @@ -/* -* 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.idlink; - -import iaik.xml.crypto.XmldsigMore; - -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringWriter; -import java.math.BigInteger; -import java.nio.charset.Charset; -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.TimeZone; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.PropertyException; -import javax.xml.crypto.MarshalException; -import javax.xml.crypto.dsig.CanonicalizationMethod; -import javax.xml.crypto.dsig.DigestMethod; -import javax.xml.crypto.dsig.Manifest; -import javax.xml.crypto.dsig.Reference; -import javax.xml.crypto.dsig.SignatureMethod; -import javax.xml.crypto.dsig.SignedInfo; -import javax.xml.crypto.dsig.Transform; -import javax.xml.crypto.dsig.XMLObject; -import javax.xml.crypto.dsig.XMLSignature; -import javax.xml.crypto.dsig.XMLSignatureException; -import javax.xml.crypto.dsig.XMLSignatureFactory; -import javax.xml.crypto.dsig.dom.DOMSignContext; -import javax.xml.crypto.dsig.keyinfo.KeyInfo; -import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory; -import javax.xml.crypto.dsig.keyinfo.X509Data; -import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; -import javax.xml.crypto.dsig.spec.TransformParameterSpec; -import javax.xml.crypto.dsig.spec.XPathFilterParameterSpec; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import oasis.names.tc.saml._1_0.assertion.AssertionType; -import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; -import oasis.names.tc.saml._1_0.assertion.AttributeType; -import oasis.names.tc.saml._1_0.assertion.SubjectConfirmationType; -import oasis.names.tc.saml._1_0.assertion.SubjectType; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import at.gv.e_government.reference.namespace.persondata._20020228_.AbstractPersonType; -import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType; -import at.gv.e_government.reference.namespace.persondata._20020228_.PersonNameType; -import at.gv.e_government.reference.namespace.persondata._20020228_.PhysicalPersonType; -import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType.Value; -import at.gv.e_government.reference.namespace.persondata._20020228_.PersonNameType.FamilyName; -import at.gv.egiz.marshal.MarshallerFactory; -import at.gv.egiz.marshal.NamespacePrefixMapperImpl; -import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; -import at.gv.egiz.xmldsig.KeyValueFactory; -import oasis.names.tc.saml._1_0.assertion.AnyType; - -public class IdentityLinkFactory { - - private static Log log = LogFactory.getLog(IdentityLinkFactory.class); - - /** - * The instance returned by {@link #getInstance()}. - */ - private static IdentityLinkFactory instance; - - /** - * The <code>JAXBContext</code>. - */ - private static JAXBContext jaxbContext; - - /** - * The <code>KeyValueFactory</code>. - */ - private static KeyValueFactory keyValueFactory; - - /** - * Get an instance of this <code>CompressedIdentityLinkFactory</code>. - * - * @return an instance of this <code>CompressedIdentityLinkFactory</code> - */ - public synchronized static IdentityLinkFactory getInstance() { - if (instance == null) { - instance = new IdentityLinkFactory(); - } - return instance; - } - - /** - * Private constructor. - */ - private IdentityLinkFactory() { - - keyValueFactory = new KeyValueFactory(); - - StringBuffer packageNames = new StringBuffer(); - packageNames.append(at.gv.e_government.reference.namespace.persondata._20020228_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(org.w3._2001._04.xmldsig_more_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(at.buergerkarte.namespaces.personenbindung._20020506_.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(oasis.names.tc.saml._1_0.assertion.ObjectFactory.class.getPackage().getName()); - - try { - jaxbContext = JAXBContext.newInstance(packageNames.toString()); - } catch (JAXBException e) { - // we should not get an JAXBException initializing the JAXBContext - throw new RuntimeException(e); - } - - } - - public JAXBElement<AssertionType> createAssertion(String assertionId, - Date issueInstant, String issuer, long majorVersion, long minorVersion, AttributeStatementType attributeStatement) { - - oasis.names.tc.saml._1_0.assertion.ObjectFactory asFactory = - new oasis.names.tc.saml._1_0.assertion.ObjectFactory(); - - AssertionType assertionType = asFactory.createAssertionType(); - - assertionType.setAssertionID(assertionId); - - GregorianCalendar gregorianCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - gregorianCalendar.setTime(issueInstant); - try { - DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); - assertionType.setIssueInstant(datatypeFactory.newXMLGregorianCalendar(gregorianCalendar)); - } catch (DatatypeConfigurationException e) { - throw new RuntimeException(e); - } - - assertionType.setIssuer(issuer); - - assertionType.setMajorVersion(BigInteger.valueOf(majorVersion)); - assertionType.setMinorVersion(BigInteger.valueOf(minorVersion)); - - assertionType.getStatementOrSubjectStatementOrAuthenticationStatement().add(attributeStatement); - - return asFactory.createAssertion(assertionType); - - } - - public AttributeStatementType createAttributeStatement(String idValue, String idType, - String givenName, String familyName, String dateOfBirth, - PublicKey[] publicKeys) throws KeyTypeNotSupportedException { - - oasis.names.tc.saml._1_0.assertion.ObjectFactory asFactory = - new oasis.names.tc.saml._1_0.assertion.ObjectFactory(); - - at.gv.e_government.reference.namespace.persondata._20020228_.ObjectFactory prFactory = - new at.gv.e_government.reference.namespace.persondata._20020228_.ObjectFactory(); - - AttributeStatementType attributeStatementType = asFactory.createAttributeStatementType(); - - // saml:Subject - SubjectConfirmationType subjectConfirmationType = asFactory.createSubjectConfirmationType(); - - subjectConfirmationType.getConfirmationMethod().add("urn:oasis:names:tc:SAML:1.0:cm:sender-vouches"); - - // pr:Person - Value identificationTypeValue = prFactory.createIdentificationTypeValue(); - identificationTypeValue.setValue(idValue); - IdentificationType identificationType = prFactory - .createIdentificationType(); - identificationType.setValue(identificationTypeValue); - identificationType.setType(idType); - - PersonNameType personNameType = prFactory.createPersonNameType(); - FamilyName personNameTypeFamilyName = prFactory - .createPersonNameTypeFamilyName(); - personNameTypeFamilyName.setValue(familyName); - personNameTypeFamilyName.setPrimary("undefined"); - personNameType.getFamilyName().add(personNameTypeFamilyName); - personNameType.getGivenName().add(givenName); - - PhysicalPersonType physicalPersonType = prFactory - .createPhysicalPersonType(); - physicalPersonType.getIdentification().add(identificationType); - physicalPersonType.setName(personNameType); - physicalPersonType.setDateOfBirth(dateOfBirth); - JAXBElement<AbstractPersonType> physicalPerson = prFactory.createPerson(physicalPersonType); - - AnyType personType = asFactory.createAnyType(); - personType.getContent().add(physicalPerson); - subjectConfirmationType.setSubjectConfirmationData(personType); - - JAXBElement<SubjectConfirmationType> subjectConfirmation = asFactory.createSubjectConfirmation(subjectConfirmationType); - - SubjectType subjectType = asFactory.createSubjectType(); - subjectType.getContent().add(subjectConfirmation); - - attributeStatementType.setSubject(subjectType); - - // saml:Attribute CitizenPublicKey - for (int i = 0; i < publicKeys.length; i++) { - - JAXBElement<?> createKeyValue = keyValueFactory.createKeyValue(publicKeys[i]); - AttributeType attributeType = asFactory.createAttributeType(); - attributeType.setAttributeName("CitizenPublicKey"); - attributeType.setAttributeNamespace("urn:publicid:gv.at:namespaces:identitylink:1.2"); - AnyType attributeValueType = asFactory.createAnyType(); - attributeValueType.getContent().add(createKeyValue); - attributeType.getAttributeValue().add(attributeValueType); - - attributeStatementType.getAttribute().add(attributeType); - - } - - return attributeStatementType; - } - - /** - * Marshall the given <code>compressedIdentityLink</code> into a DOM document - * with the given Nodes as <code>parent</code> and <code>nextSibling</code> - * nodes. - * - * @param identityLink - * the <code>CompressedIdentityLink</code> element - * @param parent - * the parent node - * @param nextSibling - * the next sibling node (may be <code>null</code>) - * @param applyWorkarounds - * apply workarounds as spefiyed by - * {@link #applyWorkarounds(Element, int)} - * - * @throws JAXBException - * if an unexpected error occurs while marshalling - * @throws NullPointerException - * if <code>compressdIdentityLink</code> or <code>parent</code> is - * <code>null</code> - */ - public void marshallIdentityLink( - JAXBElement<AssertionType> identityLink, - Node parent, Node nextSibling) throws JAXBException { - - DOMResult result = new DOMResult(parent, nextSibling); - - try { - Marshaller marshaller = MarshallerFactory.createMarshaller(jaxbContext, true); - - marshaller.marshal(identityLink, result); - } catch (PropertyException e) { - throw new RuntimeException(e); - } - - } - - public void signIdentityLink(Element assertion, X509Certificate certificate, - PrivateKey key) throws NoSuchAlgorithmException, - InvalidAlgorithmParameterException, XMLSignatureException, - MarshalException { - - XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance(); - - KeyInfoFactory keyInfoFactory = KeyInfoFactory.getInstance(); - - List<Reference> references = new ArrayList<Reference>(); - - // Reference #1 - - Map<String, String> prefixMap = new HashMap<String, String>(); - prefixMap.put("pr", "http://reference.e-government.gv.at/namespace/persondata/20020228#"); - List<Transform> transforms1 = new ArrayList<Transform>(); - transforms1.add(signatureFactory.newTransform(Transform.XPATH, - new XPathFilterParameterSpec( - "not(ancestor-or-self::pr:Identification)", prefixMap))); - transforms1.add(signatureFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)); - DigestMethod digestMethod1 = signatureFactory.newDigestMethod(DigestMethod.SHA1, null); - references.add(signatureFactory.newReference("", digestMethod1, transforms1, null, null)); - - // Reference (Manifest) - - DigestMethod digestMethod2 = signatureFactory.newDigestMethod(DigestMethod.SHA1, null); - references.add(signatureFactory.newReference("#manifest", digestMethod2, null, Manifest.TYPE, null)); - - CanonicalizationMethod canonicalizationMethod = signatureFactory - .newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, - (C14NMethodParameterSpec) null); - - SignatureMethod signatureMethod; - String algorithm = key.getAlgorithm(); - if ("RSA".equalsIgnoreCase(algorithm)) { - signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null); - } else if ("ECDSA".equalsIgnoreCase(algorithm) || "EC".equalsIgnoreCase(algorithm)) { - signatureMethod = signatureFactory.newSignatureMethod(XmldsigMore.SIGNATURE_ECDSA_SHA1, null); - } else if ("DSA".equalsIgnoreCase(algorithm)) { - signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.DSA_SHA1, null); - } else { - throw new NoSuchAlgorithmException("Algorithm '" + algorithm + "' not supported."); - } - - SignedInfo signedInfo = signatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod, references); - - - X509Data x509Data = keyInfoFactory.newX509Data(Collections.singletonList(certificate)); - KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(x509Data)); - - // Manifest - - Map<String, String> manifestPrefixMap = new HashMap<String, String>(); - manifestPrefixMap.put("dsig", XMLSignature.XMLNS); - List<Transform> manifestTransforms = Collections - .singletonList(signatureFactory.newTransform(Transform.XPATH, - new XPathFilterParameterSpec( - "not(ancestor-or-self::dsig:Signature)", manifestPrefixMap))); - Reference manifestReference = signatureFactory.newReference("", - signatureFactory.newDigestMethod(DigestMethod.SHA1, null), - manifestTransforms, null, null); - - Manifest manifest = signatureFactory.newManifest(Collections - .singletonList(manifestReference), "manifest"); - - XMLObject xmlObject = signatureFactory.newXMLObject(Collections - .singletonList(manifest), null, null, null); - - XMLSignature xmlSignature = signatureFactory.newXMLSignature(signedInfo, - keyInfo, Collections.singletonList(xmlObject), null, null); - - DOMSignContext signContext = new DOMSignContext(key, assertion); - - if (log.isTraceEnabled()) { - signContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE); - } - - xmlSignature.sign(signContext); - - if (log.isDebugEnabled()) { - - try { - - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - - StringWriter writer = new StringWriter(); - - transformer.transform(new DOMSource(assertion), new StreamResult(writer)); - - log.debug(writer.toString()); - - } catch (Exception e) { - log.debug(e); - } - - } - - if (log.isTraceEnabled()) { - - StringBuilder sb = new StringBuilder(); - - sb.append("Digest input data:\n\n"); - - try { - - Iterator<Reference> refs = references.iterator(); - for (int i = 0; refs.hasNext(); i++) { - Reference reference = (Reference) refs.next(); - sb.append("Reference " + i + "\n"); - - Reader reader = new InputStreamReader(reference - .getDigestInputStream(), Charset.forName("UTF-8")); - char c[] = new char[512]; - for (int l; (l = reader.read(c)) != -1;) { - sb.append(c, 0, l); - } - sb.append("\n"); - } - - sb.append("Manifest Reference\n"); - - Reader reader = new InputStreamReader(manifestReference - .getDigestInputStream(), Charset.forName("UTF-8")); - char c[] = new char[512]; - for (int l; (l = reader.read(c)) != -1;) { - sb.append(c, 0, l); - } - - } catch (Exception e) { - sb.append(e.getMessage()); - } - - log.trace(sb.toString()); - } - - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java deleted file mode 100644 index 8bee5fa4..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java +++ /dev/null @@ -1,188 +0,0 @@ -/* -* 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.idlink;
-
-import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Templates; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.stream.StreamSource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - -import at.gv.egiz.bku.utils.urldereferencer.StreamData; -import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; -
-public class IdentityLinkTransformer { - - protected static Log log = LogFactory.getLog(IdentityLinkTransformer.class);
-
- /**
- * The transformer factory.
- */
- private static SAXTransformerFactory factory;
-
- /**
- * The instance to be returned by {@link #getInstance()}.
- */
- private static IdentityLinkTransformer instance;
-
- /**
- * Returns an instance of this <code>IdentityLinkTransfomer</code>.
- *
- * @return an instance of this <code>IdentityLinkTransformer</code>
- */
- public static IdentityLinkTransformer getInstance() {
- if (instance == null) {
- instance = new IdentityLinkTransformer();
- factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
- }
- return instance;
- }
-
- /**
- * Sets the given <code>domainIdentifier</code> on the corresponding
- * node of the given <code>idLink</code>.
- * <p>This method may be used to cope with a flaw in the IssuerTemplate-Stylesheets
- * used to transform a <code>CompressedIdentitiyLink</code> into an
- * <code>IdentityLink</code>. Some IssuerTemplate-Stylesheets do not
- * consider the <code>pr:Type</code> element value of the
- * <code>CompressedIdentityLink</code> and render a <code>pr:Type</code>
- * element value of <code>urn:publicid:gv.at:baseid</code>
- * into the <code>IdentityLink</code> structure. This method allows to
- * set the <code>pr:Type</code> element value on the given <code>idLink</code>
- * after the transformation.
- * </p>
- *
- * @param idLink the <code>IdentityLink</code> element or one of it's ancestors.
- * Must not be <code>null</code>.
- *
- * @param domainIdentifier the value to be set for the <code>pr:Type</code> element
- *
- * @throws NullPointerException if <code>idLink</code> is <code>null</code>.
- */
- public static void setDomainIdentifier(Node idLink, String domainIdentifier) {
-
- Element element;
- if (idLink instanceof Element) {
- element = (Element) idLink;
- } else if (idLink instanceof Document) {
- element = ((Document) idLink).getDocumentElement();
- } else if (idLink != null) {
- Document document = idLink.getOwnerDocument();
- element = document.getDocumentElement();
- } else {
- throw new NullPointerException("Parameter 'idLink' must no be null.");
- }
-
- NodeList nodeList = element.getElementsByTagNameNS(
- "http://reference.e-government.gv.at/namespace/persondata/20020228#",
- "Type");
-
- for (int i = 0; i < nodeList.getLength(); i++) {
- if (nodeList.item(i) instanceof Element) {
- Element typeElement = (Element) nodeList.item(i);
- NodeList children = typeElement.getChildNodes();
- for (int j = 0; j < children.getLength(); j++) {
- if (children.item(j) instanceof Text) {
- ((Text) children.item(j)).setNodeValue(domainIdentifier);
- }
- }
- }
- }
-
- }
-
- /** - * Mapping of issuer template URIs to transformation templates. - */ - private Map<String, Templates> templates = new HashMap<String, Templates>();
-
- /**
- * Private constructor.
- */
- private IdentityLinkTransformer() {
- } - - /** - * Transforms an identity link <code>source</code> to <code>result</code> with - * the given issuer template from the <code>stylesheetURL</code>. - * - * @param stylesheetURL - * the URL of the issuer template to be used for transformation - * @param source - * the compressed identity link source - * @param result - * the transformed identity link result - * - * @throws MalformedURLException - * if the given <code>stylesheetURL</code> is not a valid - * <code>http</code> or <code>https</code> URL. - * @throws IOException - * if dereferencing the <code>stylesheetURL</code> fails. - * @throws TransformerConfigurationException - * if creating a transformation template from the dereferenced - * stylesheet fails. - * @throws TransformerException - * if transforming the identity link fails. - */
- public void transformIdLink(String stylesheetURL, Source source, Result result) throws IOException, TransformerException { - - Templates templ = templates.get(stylesheetURL); - - if (templ == null) { - - // TODO: implement stylesheet cache - URL url = new URL(stylesheetURL); - - if (!"http".equalsIgnoreCase(url.getProtocol()) && !"https".equalsIgnoreCase(url.getProtocol())) { - throw new MalformedURLException("Protocol " + url.getProtocol() + " not supported for IssuerTemplate URL."); - } - - URLDereferencer dereferencer = URLDereferencer.getInstance(); - StreamData data = dereferencer.dereference(url.toExternalForm(), null); - - log.trace("Trying to create issuer template."); - templ = factory.newTemplates(new StreamSource(data.getStream())); - log.trace("Successfully created issuer template"); - - templates.put(stylesheetURL, templ); - - } - - Transformer transformer = templ.newTransformer(); - - transformer.transform(source, result); - - }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/CitizenPublicKey.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/CitizenPublicKey.java deleted file mode 100644 index c32cf2b9..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/CitizenPublicKey.java +++ /dev/null @@ -1,92 +0,0 @@ -/* -* 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.idlink.ans1; - -import java.math.BigInteger; - -import iaik.asn1.*; - -/** - * This class implements the ASN.1 representation of the - * <code>CitizenPublicKey</code> of a compressed identity link. - * - * <pre>CitizenPublicKey ::= CHOICE { - onToken [0] INTEGER, - referenceURL [1] UTF8String, - x509Data [2] SubjectPublicKeyInfo -} -</pre> - * - * @author mivkovic@egiz.gv.at, mcentner@egiz.gv.at - */ -public class CitizenPublicKey implements ASN1Type { - - /** - * <code>onToken</code> - */ - private int onToken; // INTEGER - - /** - * Creates a new <code>CitizenPublicKey</code> with the given - * <code>onToken</code> value. - * - * @param onToken - */ - public CitizenPublicKey(int onToken) { - this.onToken = onToken; - } - - /** - * Creates a new <code>CitizenPublicKey</code> from the given ASN.1 representation. - * - * @param obj - * @throws CodingException - */ - public CitizenPublicKey(ASN1Object obj) throws CodingException { - decode(obj); - } - - @Override - public void decode(ASN1Object obj) throws CodingException { - try { - BigInteger Value = (BigInteger)(obj.getValue()); - onToken = Value.intValue(); - } catch (Exception ex) { - throw new CodingException(ex.toString()); - } - } - - @Override - public ASN1Object toASN1Object() { - INTEGER ot = new INTEGER(onToken); - return ot; - } - - /** - * Returns the DER encoding of this <code>CitizenPublicKey</code>. - * - * @return the DER encoding of this <code>CitizenPublicKey</code> - */ - public byte[] getEncoded() { - return DerCoder.encode(toASN1Object()); - } - - public int getOnToken() { - return onToken; - } - -}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/IdentityLink.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/IdentityLink.java deleted file mode 100644 index 37e4b240..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/IdentityLink.java +++ /dev/null @@ -1,315 +0,0 @@ -/* -* 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.idlink.ans1;
-
-import iaik.asn1.ASN1Object;
-import iaik.asn1.ASN1Type;
-import iaik.asn1.BIT_STRING;
-import iaik.asn1.CON_SPEC;
-import iaik.asn1.CodingException;
-import iaik.asn1.DerCoder;
-import iaik.asn1.INTEGER;
-import iaik.asn1.SEQUENCE;
-import iaik.asn1.UTF8String;
-
-/**
- * This class impelments an ASN.1 representation of the compressed <code>IdentiyLink</code>.
- * <pre>
-PersonenBindung ::= SEQUENCE {
- version INTEGER,
- issuerTemplate UTF8String,
- assertionID UTF8String,
- issueInstant UTF8String,
- personData PersonData,
- citizenPublicKey SEQUENCE SIZE (1..MAX) OF CitizenPublicKey,
- signatureValue BIT STRING,
- referenceDigest [0] BIT STRING OPTIONAL,
- referenceManifestDigest [1] BIT STRING OPTIONAL,
- manifestReferenceDigest [2] BIT STRING OPTIONAL
-}
-</pre>
- *
- * @author mivkovic@egiz.gv.at, mcentner@egiz.gv.at
- */
-public class IdentityLink implements ASN1Type {
-
- private int version = 1; // INTEGER
- private String issuerTemplate; // UTF8String
- private String assertionID; // UTF8String
- private String issueInstant; // UTF8String
- private PersonData personData; // PersonData
- private CitizenPublicKey[] citizenPublicKeys; // SEQUENCE SIZE (1..MAX) OF
- private byte[] signatureValue; // BIT STRING
- private byte[] referenceDigest; // BIT STRING OPTIONAL
- private byte[] referenceManifestDigest; // BIT STRING OPTIONAL
- private byte[] manifestReferenceDigest; // BIT STRING OPTIONAL
-
- /**
- * Creates a new <code>IdentityLink</code> with the given
- * <code>issuerTemplate</code>, <code>assertionID</code>,
- * <code>issueInstant</code>, <code>personData</code>,
- * <code>citizenPublicKeys</code> and <code>signatureValue</code>.
- *
- * @param issuerTemplate
- * @param assertionID
- * @param issueInstant
- * @param personData
- * @param citizenPublicKeys
- * @param signatureValue
- */
- public IdentityLink(String issuerTemplate, String assertionID,
- String issueInstant, PersonData personData,
- CitizenPublicKey[] citizenPublicKeys, byte[] signatureValue) {
- this.issuerTemplate = issuerTemplate;
- this.assertionID = assertionID;
- this.issueInstant = issueInstant;
- this.personData = personData;
- this.citizenPublicKeys = citizenPublicKeys;
- this.signatureValue = signatureValue;
- }
-
- /**
- * Create a new IdentityLink from an ASN1Object.
- *
- * @param identiyLink
- * @throws CodingException
- */
- public IdentityLink(ASN1Object identiyLink) throws CodingException {
- decode(identiyLink);
- }
-
- @Override
- public void decode(ASN1Object obj) throws CodingException {
- issuerTemplate = (String) ((ASN1Object) obj.getComponentAt(1)).getValue();
- assertionID = (String) ((ASN1Object) obj.getComponentAt(2)).getValue();
- issueInstant = (String) ((ASN1Object) obj.getComponentAt(3)).getValue();
-
- if (((CON_SPEC) obj.getComponentAt(4)).getAsnType().getTag() == 0)
- personData = new PersonData((ASN1Object) obj.getComponentAt(4).getValue());
- else {
- throw new CodingException("CorporateBodyData currently not supported.");
- }
-
- SEQUENCE publicKeySequence = (SEQUENCE) obj.getComponentAt(5);
- int anz = publicKeySequence.countComponents();
- citizenPublicKeys = new CitizenPublicKey[anz];
- for (int i = 0; i < citizenPublicKeys.length; i++) {
- CON_SPEC tmp = (CON_SPEC) publicKeySequence.getComponentAt(i);
- if (tmp.getAsnType().getTag() == 0) {
- citizenPublicKeys[i] = new CitizenPublicKey((ASN1Object) tmp.getValue());
- } else {
- throw new CodingException(
- "Currently only PublicKeys on token are supported.");
- }
- }
-
- signatureValue = (byte[]) ((ASN1Object) obj.getComponentAt(6)).getValue();
-
- for (int i = 7; i < obj.countComponents(); i++) {
- CON_SPEC tmp = (CON_SPEC) obj.getComponentAt(i);
- switch (tmp.getAsnType().getTag()) {
- case 0:
- referenceDigest = (byte[]) ((BIT_STRING) tmp.getValue()).getValue();
- break;
- case 1:
- referenceManifestDigest = (byte[]) ((BIT_STRING) tmp.getValue())
- .getValue();
- break;
- case 2:
- manifestReferenceDigest = (byte[]) ((BIT_STRING) tmp.getValue())
- .getValue();
- break;
- }
-
- }
-
- }
-
- @Override
- public ASN1Object toASN1Object() {
- SEQUENCE pb = new SEQUENCE();
- pb.addComponent(new INTEGER(version));
- pb.addComponent(new UTF8String(issuerTemplate));
- pb.addComponent(new UTF8String(assertionID));
- pb.addComponent(new UTF8String(issueInstant));
-
- pb.addComponent(new CON_SPEC(0, personData.toASN1Object()));
- SEQUENCE seq = new SEQUENCE();
- for (int i = 0; i < citizenPublicKeys.length; i++) {
- seq.addComponent(new CON_SPEC(0, citizenPublicKeys[i].toASN1Object()));
- }
- pb.addComponent(seq);
- pb.addComponent(new BIT_STRING(signatureValue));
- if (referenceDigest != null)
- pb.addComponent(new CON_SPEC(0, new BIT_STRING(referenceDigest)));
- if (referenceManifestDigest != null)
- pb.addComponent(new CON_SPEC(1, new BIT_STRING(referenceManifestDigest)));
- if (manifestReferenceDigest != null)
- pb.addComponent(new CON_SPEC(2, new BIT_STRING(manifestReferenceDigest)));
- return pb;
- }
-
- /**
- * Returns the DER encoding of this <code>IdentityLink</code>.
- *
- * @return the DER encoding of this <code>IdentityLink</code>
- */
- public byte[] toByteArray() {
- return DerCoder.encode(toASN1Object());
- }
-
- /**
- * @return the version
- */
- public int getVersion() {
- return version;
- }
-
- /**
- * @param version the version to set
- */
- public void setVersion(int version) {
- this.version = version;
- }
-
- /**
- * @return the issuerTemplate
- */
- public String getIssuerTemplate() {
- return issuerTemplate;
- }
-
- /**
- * @param issuerTemplate the issuerTemplate to set
- */
- public void setIssuerTemplate(String issuerTemplate) {
- this.issuerTemplate = issuerTemplate;
- }
-
- /**
- * @return the assertionID
- */
- public String getAssertionID() {
- return assertionID;
- }
-
- /**
- * @param assertionID the assertionID to set
- */
- public void setAssertionID(String assertionID) {
- this.assertionID = assertionID;
- }
-
- /**
- * @return the issueInstant
- */
- public String getIssueInstant() {
- return issueInstant;
- }
-
- /**
- * @param issueInstant the issueInstant to set
- */
- public void setIssueInstant(String issueInstant) {
- this.issueInstant = issueInstant;
- }
-
- /**
- * @return the personData
- */
- public PersonData getPersonData() {
- return personData;
- }
-
- /**
- * @param personData the personData to set
- */
- public void setPersonData(PersonData personData) {
- this.personData = personData;
- }
-
- /**
- * @return the citizenPublicKeys
- */
- public CitizenPublicKey[] getCitizenPublicKeys() {
- return citizenPublicKeys;
- }
-
- /**
- * @param citizenPublicKeys the citizenPublicKeys to set
- */
- public void setCitizenPublicKeys(CitizenPublicKey[] citizenPublicKeys) {
- this.citizenPublicKeys = citizenPublicKeys;
- }
-
- /**
- * @return the signatureValue
- */
- public byte[] getSignatureValue() {
- return signatureValue;
- }
-
- /**
- * @param signatureValue the signatureValue to set
- */
- public void setSignatureValue(byte[] signatureValue) {
- this.signatureValue = signatureValue;
- }
-
- /**
- * @return the referenceDigest
- */
- public byte[] getReferenceDigest() {
- return referenceDigest;
- }
-
- /**
- * @param referenceDigest the referenceDigest to set
- */
- public void setReferenceDigest(byte[] referenceDigest) {
- this.referenceDigest = referenceDigest;
- }
-
- /**
- * @return the referenceManifestDigest
- */
- public byte[] getReferenceManifestDigest() {
- return referenceManifestDigest;
- }
-
- /**
- * @param referenceManifestDigest the referenceManifestDigest to set
- */
- public void setReferenceManifestDigest(byte[] referenceManifestDigest) {
- this.referenceManifestDigest = referenceManifestDigest;
- }
-
- /**
- * @return the manifestReferenceDigest
- */
- public byte[] getManifestReferenceDigest() {
- return manifestReferenceDigest;
- }
-
- /**
- * @param manifestReferenceDigest the manifestReferenceDigest to set
- */
- public void setManifestReferenceDigest(byte[] manifestReferenceDigest) {
- this.manifestReferenceDigest = manifestReferenceDigest;
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/PersonData.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/PersonData.java deleted file mode 100644 index 2a537eb3..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/PersonData.java +++ /dev/null @@ -1,91 +0,0 @@ -/* -* 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.idlink.ans1; - -import iaik.asn1.*; - -/** - * This class represents the ASN.1 version of the <code>PersonData</code> - * of a compressed identity link. - * - * <pre> -PersonData ::= CHOICE { - physcialPerson [0] PhysicalPersonData, - corporateBody [1] CorporateBodyData -} </pre> - * - * @author mivkovic@egiz.gv.at, mcentner@egiz.gv.at - * - */ -public class PersonData implements ASN1Type { - - /** - * <code>physicalPerson</code> - */ - private PhysicalPersonData physicalPerson; // PhysicalPersonData - - /** - * Creates a new <code>PersonData</code> with the given - * <code>physicalPersonData</code>. - * - * @param physicalPersonData - */ - public PersonData(PhysicalPersonData physicalPersonData) { - physicalPerson = physicalPersonData; - } - - /** - * Creates a new <code>PersonData</code> from its ASN.1 representation. - * - * @param obj - * @throws CodingException - */ - public PersonData(ASN1Object obj) throws CodingException { - decode(obj); - } - - @Override - public void decode(ASN1Object obj) throws CodingException { - try { - physicalPerson = new PhysicalPersonData(obj); - } catch (Exception ex) { - throw new CodingException(ex.toString()); - } - } - - @Override - public ASN1Object toASN1Object() { - return physicalPerson.toASN1Object(); - } - - /** - * Returns the DER encoded representation of this <code>PersonData</code>. - * - * @return the DER encoded representation of this <code>PersonData</code> - */ - public byte[] getEncoded() { - return DerCoder.encode(toASN1Object()); - } - - /** - * @return the physicalPerson - */ - public PhysicalPersonData getPhysicalPerson() { - return physicalPerson; - } - -}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/PhysicalPersonData.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/PhysicalPersonData.java deleted file mode 100644 index a6aea97e..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/idlink/ans1/PhysicalPersonData.java +++ /dev/null @@ -1,143 +0,0 @@ -/* -* 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.idlink.ans1; - -import iaik.asn1.*; - -/** - * This class represents the ASN.1 version of the <code>PhysicalPersonData</code> - * of an compressed identity link. - * - * <pre>PhysicalPersonData ::= SEQUENCE { - baseId UTF8String, - givenName UTF8String, - familyName UTF8String, - dateOfBirth UTF8String -}</pre> - * - * @author mivkovic@egiz.gv.at, mcentner@eigz.gv.at - */ -public class PhysicalPersonData implements ASN1Type { - - /** - * <code>baseId</code> - */ - private String baseId; // UTF8String - - /** - * <code>givenName</code> - */ - private String givenName; // UTF8String - - /** - * <code>familyName</code> - */ - private String familyName; // UTF8String - - /** - * <code>dataOfBirth</code> - */ - private String dateOfBirth; // UTF8String - - /** - * Creates a new <code>PhysicalPersonData</code> with the - * given <code>baseId</code>, <code>givenName</code>, <code>familyName</code> - * and <code>dataOfBirth</code>. - * - * @param baseId - * @param givenName - * @param familyName - * @param dateOfBirth - */ - public PhysicalPersonData(String baseId, String givenName, String familyName, String dateOfBirth) { - this.baseId = baseId; - this.givenName = givenName; - this.familyName = familyName; - this.dateOfBirth = dateOfBirth; - } - - /** - * Creates a new <code>PhysicalPersonData</code> from its ASN.1 representation. - * - * @param obj - * - * @throws CodingException - */ - public PhysicalPersonData(ASN1Object obj) throws CodingException { - decode(obj); - } - - @Override - public void decode(ASN1Object obj) throws CodingException { - try { - baseId = (String) ((ASN1Object) obj.getComponentAt(0)).getValue(); - givenName = (String) ((ASN1Object) obj.getComponentAt(1)).getValue(); - familyName = (String) ((ASN1Object) obj.getComponentAt(2)).getValue(); - dateOfBirth = (String) ((ASN1Object) obj.getComponentAt(3)).getValue(); - } catch (Exception ex) { - throw new CodingException(ex.toString()); - } - } - - @Override - public ASN1Object toASN1Object() { - SEQUENCE ppd = new SEQUENCE(); - ppd.addComponent(new UTF8String(baseId)); - ppd.addComponent(new UTF8String(givenName)); - ppd.addComponent(new UTF8String(familyName)); - ppd.addComponent(new UTF8String(dateOfBirth)); - return ppd; - } - - /** - * Returns the DER encoding of this <code>PhysicalPersonData</code>. - * - * @return the DER encoding of this <code>PhysicalPersonData</code> - */ - public byte[] toByteArray() { - return DerCoder.encode(toASN1Object()); - } - - /** - * @return the baseId - */ - public String getBaseId() { - return baseId; - } - - /** - * @return the givenName - */ - public String getGivenName() { - return givenName; - } - - /** - * @return the familyName - */ - public String getFamilyName() { - return familyName; - } - - /** - * @return the dateOfBirth - */ - public String getDateOfBirth() { - return dateOfBirth; - } - -}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/marshal/MarshallerFactory.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/marshal/MarshallerFactory.java deleted file mode 100644 index 3ac0a86e..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/marshal/MarshallerFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.marshal; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.PropertyException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> - */ -public class MarshallerFactory { - - private static final Log log = LogFactory.getLog(MarshallerFactory.class); - - public static Marshaller createMarshaller(JAXBContext ctx, boolean formattedOutput, boolean fragment) throws JAXBException { - Marshaller m = ctx.createMarshaller(); - try { - if (formattedOutput) { - log.trace("setting marshaller property FORMATTED_OUTPUT"); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - } - if (fragment) { - log.trace("setting marshaller property FRAGMENT"); - m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - } - log.trace("setting marshaller property NamespacePrefixMapper"); - m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl()); - } catch (PropertyException ex) { - log.info("failed to set marshaller property: " + ex.getMessage()); - } - return m; - } - - public static Marshaller createMarshaller(JAXBContext ctx, boolean formattedOutput) throws JAXBException { - return createMarshaller(ctx, formattedOutput, false); - } - - public static Marshaller createMarshaller(JAXBContext ctx) throws JAXBException { - return createMarshaller(ctx, false, false); - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java deleted file mode 100644 index e0698977..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.marshal; - -//import com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper; -import java.util.HashMap; -import java.util.Map; - -import com.sun.xml.bind.marshaller.NamespacePrefixMapper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> - */ -public class NamespacePrefixMapperImpl extends NamespacePrefixMapper { - - private static final Log log = LogFactory.getLog(NamespacePrefixMapperImpl.class); - - protected static final Map<String, String> prefixMap = new HashMap<String, String>(); - - static { - prefixMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi"); - prefixMap.put("http://www.w3.org/2000/09/xmldsig#", "dsig"); - prefixMap.put("http://www.buergerkarte.at/namespaces/securitylayer/1.2#", "sl"); - prefixMap.put("http://www.buergerkarte.at/cardchannel", "cc"); - prefixMap.put("http://www.w3.org/2001/04/xmldsig-more#", "ecdsa"); - prefixMap.put("http://reference.e-government.gv.at/namespace/persondata/20020228#", "pr"); - prefixMap.put("urn:oasis:names:tc:SAML:1.0:assertion", "saml"); - prefixMap.put("http://uri.etsi.org/01903/v1.1.1#", "xades"); - prefixMap.put("http://www.buergerkarte.at/namespaces/securitylayer/20020225#", "sl10"); - prefixMap.put("http://www.buergerkarte.at/namespaces/securitylayer/20020831#", "sl11"); - } - - - @Override - public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) { - - if (log.isTraceEnabled()) { - log.trace("prefix for namespace " + namespaceUri + " requested"); - } - - String prefix = prefixMap.get(namespaceUri); - - return (prefix != null) ? prefix : suggestion; - } - - /** - * Returns a list of namespace URIs that should be declared - * at the root element. - * <p> - * By default, the JAXB RI produces namespace declarations only when - * they are necessary, only at where they are used. Because of this - * lack of look-ahead, sometimes the marshaller produces a lot of - * namespace declarations that look redundant to human eyes. For example, - */ - @Override - public String[] getPreDeclaredNamespaceUris() { - return new String[]{ "http://www.buergerkarte.at/namespaces/securitylayer/1.2#" }; - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/org/apache/tomcat/util/http/AcceptLanguage.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/org/apache/tomcat/util/http/AcceptLanguage.java deleted file mode 100644 index 231966ac..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/org/apache/tomcat/util/http/AcceptLanguage.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.org.apache.tomcat.util.http; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Locale; -import java.util.StringTokenizer; -import java.util.Vector; - -/** - * Util to process the "Accept-Language" header. Used by facade to implement - * getLocale() and by StaticInterceptor. - * - * Not optimized - it's very slow. - * - * @author James Duncan Davidson [duncan@eng.sun.com] - * @author James Todd [gonzo@eng.sun.com] - * @author Jason Hunter [jch@eng.sun.com] - * @author Harish Prabandham - * @author costin@eng.sun.com - */ -public class AcceptLanguage { - - public static Locale getLocale(String acceptLanguage) { - if( acceptLanguage == null ) return Locale.getDefault(); - - Hashtable<String,Vector<String>> languages = - new Hashtable<String,Vector<String>>(); - Vector<Double> quality = new Vector<Double>(); - processAcceptLanguage(acceptLanguage, languages, quality); - - if (languages.size() == 0) return Locale.getDefault(); - - Vector<Locale> l = new Vector<Locale>(); - extractLocales( languages,quality, l); - - return (Locale)l.elementAt(0); - } - - public static Enumeration getLocales(String acceptLanguage) { - // Short circuit with an empty enumeration if null header - if (acceptLanguage == null) { - Vector<Locale> v = new Vector<Locale>(); - v.addElement(Locale.getDefault()); - return v.elements(); - } - - Hashtable<String,Vector<String>> languages = - new Hashtable<String,Vector<String>>(); - Vector<Double> quality=new Vector<Double>(); - processAcceptLanguage(acceptLanguage, languages , quality); - - if (languages.size() == 0) { - Vector<Locale> v = new Vector<Locale>(); - v.addElement(Locale.getDefault()); - return v.elements(); - } - Vector<Locale> l = new Vector<Locale>(); - extractLocales( languages, quality , l); - return l.elements(); - } - - private static void processAcceptLanguage( String acceptLanguage, - Hashtable<String,Vector<String>> languages, Vector<Double> q) - { - StringTokenizer languageTokenizer = - new StringTokenizer(acceptLanguage, ","); - - while (languageTokenizer.hasMoreTokens()) { - String language = languageTokenizer.nextToken().trim(); - int qValueIndex = language.indexOf(';'); - int qIndex = language.indexOf('q'); - int equalIndex = language.indexOf('='); - Double qValue = new Double(1); - - if (qValueIndex > -1 && - qValueIndex < qIndex && - qIndex < equalIndex) { - String qValueStr = language.substring(qValueIndex + 1); - language = language.substring(0, qValueIndex); - qValueStr = qValueStr.trim().toLowerCase(); - qValueIndex = qValueStr.indexOf('='); - qValue = new Double(0); - if (qValueStr.startsWith("q") && - qValueIndex > -1) { - qValueStr = qValueStr.substring(qValueIndex + 1); - try { - qValue = new Double(qValueStr.trim()); - } catch (NumberFormatException nfe) { - } - } - } - - // XXX - // may need to handle "*" at some point in time - - if (! language.equals("*")) { - String key = qValue.toString(); - Vector<String> v; - if (languages.containsKey(key)) { - v = languages.get(key) ; - } else { - v= new Vector<String>(); - q.addElement(qValue); - } - v.addElement(language); - languages.put(key, v); - } - } - } - - private static void extractLocales(Hashtable languages, Vector q, - Vector<Locale> l) - { - // XXX We will need to order by q value Vector in the Future ? - Enumeration e = q.elements(); - while (e.hasMoreElements()) { - Vector v = - (Vector)languages.get(((Double)e.nextElement()).toString()); - Enumeration le = v.elements(); - while (le.hasMoreElements()) { - String language = (String)le.nextElement(); - String country = ""; - int countryIndex = language.indexOf("-"); - if (countryIndex > -1) { - country = language.substring(countryIndex + 1).trim(); - language = language.substring(0, countryIndex).trim(); - } - l.addElement(new Locale(language, country)); - } - } - } - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/NamespaceContextCallback.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/NamespaceContextCallback.java deleted file mode 100644 index 08c075ac..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/NamespaceContextCallback.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding; - -import javax.xml.namespace.NamespaceContext; - -/** - * - * @author clemens - */ -public interface NamespaceContextCallback { - - /** - * preserves the current namespace context from the XMLEventFilter - * @param filter - */ - void preserveNamespaceContext(RedirectEventFilter filter); - - /** - * @return the namespace context if preserveNamespaceContext() was called on this object before, null otherwise - */ - NamespaceContext getNamespaceContext(); -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectCallback.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectCallback.java deleted file mode 100644 index 80fb56dc..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectCallback.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding; - -import java.io.ByteArrayOutputStream; -import javax.xml.stream.XMLStreamException; - -/** - * - * The beforeUnmarshal(Unmarshaller um, Object parent) methods don't allow to pass the RedirectEventFilter, - * so we implement a callback interface common to all generated classes - * @author clemens - */ -public interface RedirectCallback { - - void enableRedirect(RedirectEventFilter filter) throws XMLStreamException; - - void disableRedirect(RedirectEventFilter filter) throws XMLStreamException; - - /** - * @return the redirected stream or null if enableRedirect() was not called before - */ - ByteArrayOutputStream getRedirectedStream(); -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java deleted file mode 100644 index 5fe84aae..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * 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. - */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding; - -import java.io.OutputStream; -import java.util.Set; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.EventFilter; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.XMLEvent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/* - * TODO: don't set redirect stream from caller (caller does not know whether redirection will be triggered) - * rather create on trigger and pass to caller - */ -public class RedirectEventFilter implements EventFilter { - - public static final String DEFAULT_ENCODING = "UTF-8"; - private static Log log = LogFactory.getLog(RedirectEventFilter.class); - protected XMLEventWriter redirectWriter = null; - protected Set<QName> redirectTriggers = null; - private int depth = -1; - protected NamespaceContext currentNamespaceContext = null; - - /** - * Event redirection is disabled, set a redirect stream to enable. - */ - public RedirectEventFilter() { - redirectWriter = null; - // redirectTriggers = null; - } - - /** - * - * @param redirectStream - * if null, no events are redirected - * @param redirectTriggers - * if null, all events are redirected - */ - public RedirectEventFilter(OutputStream redirectStream, String encoding) - throws XMLStreamException { // , List<QName> redirectTriggers - if (redirectStream != null) { - XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - if (encoding == null) { - encoding = DEFAULT_ENCODING; - } - this.redirectWriter = outputFactory.createXMLEventWriter(redirectStream, - encoding); - } - // this.redirectTriggers = redirectTriggers; - } - - /** - * All startElement events occuring in the redirectTriggers list will trigger - * redirection of the entire (sub-)fragment. - * - * @param event - * @return false if an event is redirected - */ - @Override - public boolean accept(XMLEvent event) { - int eventType = event.getEventType(); - - if (eventType == XMLStreamConstants.START_ELEMENT) { - //hopefully, this is a copy - currentNamespaceContext = event.asStartElement().getNamespaceContext(); - } - if (redirectWriter == null) { - return true; - } - if (eventType == XMLStreamConstants.START_ELEMENT) { - if (depth >= 0 || triggersRedirect(event.asStartElement().getName())) { - depth++; - } - } else if (eventType == XMLStreamConstants.END_ELEMENT) { - if (depth >= 0 && --depth < 0) { - // redirect the end element of the trigger, - // but do not redirect the end element of the calling type - if (redirectTriggers != null) { - redirectEvent(event); - return false; - } - } - } - if (depth >= 0) { //|| (depth == 0 && redirectTriggers == null)) { - redirectEvent(event); - return false; - } - return true; // depth < 0; - -// switch (event.getEventType()) { -// case XMLStreamConstants.START_ELEMENT: -// StartElement startElt = event.asStartElement(); -// if (depth >= 0 || triggersRedirect(startElt.getName())) { -// depth++; -// } -// // namespace context changes only on start elements -// // (first event might not be startElement, but we don't need CDATA's -// // namespace context) -// currentNamespaceContext = startElt.getNamespaceContext(); -// break; -// case XMLStreamConstants.END_ELEMENT: -// // if depth switches from positive to negative, this is the closing tag of -// // the trigger (redirect as well!) -// if (depth >= 0 && --depth < 0) { -// redirectEvent(event); -// return false; -// } -// break; -// } -// if (depth >= 0) { -// redirectEvent(event); -// return false; -// } -// return true; // depth < 0; - } - - /** - * @param startElt - * @return true if the set of triggers contains startElement - * (or no triggers are registered, i.e. everything is redirected) - */ - private boolean triggersRedirect(QName startElement) { - if (redirectTriggers != null) { - return redirectTriggers.contains(startElement); - } - return true; - } - - private void redirectEvent(XMLEvent event) { - try { - redirectWriter.add(event); - } catch (XMLStreamException ex) { - ex.printStackTrace(); - } - } - - /** - * Enable/disable redirection of <em>all</em> events from now on. - * The redirected events will be UTF-8 encoded and written to the stream. - * - * @param redirectstream - * if null, redirection is disabled - */ - public void setRedirectStream(OutputStream redirectStream) throws XMLStreamException { - setRedirectStream(redirectStream, DEFAULT_ENCODING, null); - } - - /** - * Enable/disable redirection of <em>all</em> events from now on. - * - * @param redirectStream if null, redirection is disabled - * @param encoding The encoding for the redirect stream - * @throws javax.xml.stream.XMLStreamException - */ - public void setRedirectStream(OutputStream redirectStream, String encoding) throws XMLStreamException { - setRedirectStream(redirectStream, encoding, null); - } - - /** - * Enable/disable redirection of all (child) elements contained in redirect triggers. - * The redirected events will be UTF-8 encoded and written to the stream. - * - * @param redirectstream - * if null, redirection is disabled - * @param redirectTriggers elements that trigger the redirection - */ - public void setRedirectStream(OutputStream redirectStream, Set<QName> redirectTriggers) throws XMLStreamException { - setRedirectStream(redirectStream, DEFAULT_ENCODING, redirectTriggers); - } - - /** - * Enable/disable redirection of all (child) elements contained in redirect triggers. - * - * TODO: don't set redirect stream from caller (caller does not know whether redirection will be triggered) - * rather create on trigger and pass to caller - * @param redirectstream - * if null, redirection is disabled - * @param encoding The encoding for the redirect stream - * @param redirectTriggers elements that trigger the redirection - */ - public void setRedirectStream(OutputStream redirectStream, String encoding, Set<QName> redirectTriggers) throws XMLStreamException { - if (redirectStream != null) { - XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - if (encoding == null) { - encoding = DEFAULT_ENCODING; - } - redirectWriter = outputFactory.createXMLEventWriter(redirectStream, - encoding); - if (redirectTriggers == null) { - // start redirecting - depth = 0; - } - this.redirectTriggers = redirectTriggers; - } else { - redirectWriter = null; - this.redirectTriggers = null; - } - } - - /** - * Enable/disable redirection of fragments (defined by elements in - * redirectTriggers) - * - * @param redirectStream - * if null, redirection is disabled - * @param redirectTriggers - * All startElement events occuring in this list will trigger - * redirection of the entire fragment. If null, all events are - * redirected - */ - // public void setRedirectStream(OutputStream redirectStream, List<QName> - // redirectTriggers) throws XMLStreamException { - // if (redirectStream != null) { - // XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - // redirectWriter = outputFactory.createXMLEventWriter(redirectStream); - // } else { - // redirectWriter = null; - // } - // this.redirectTriggers = (redirectStream == null) ? null : redirectTriggers; - // } - /** - * flushes the internal EventWriter - * - * @throws javax.xml.stream.XMLStreamException - */ - public void flushRedirectStream() throws XMLStreamException { - redirectWriter.flush(); - } - - /** - * the namespaceContext of the last startelement event read - * - * @return - */ - public NamespaceContext getCurrentNamespaceContext() { - return currentNamespaceContext; - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectUnmarshallerListener.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectUnmarshallerListener.java deleted file mode 100644 index 08c12146..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/RedirectUnmarshallerListener.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding; - -import javax.xml.bind.Unmarshaller; -import javax.xml.stream.XMLStreamException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Enables event redirection before marshalling a target of type RedirectCallback. - * It is up to the target class to implement the redirection (default implementation in RedirectCallback). - * Disables event redirection after marshalling (when the closing tag occurs). - * @author clemens - */ -public class RedirectUnmarshallerListener extends Unmarshaller.Listener { - - private static Log log = LogFactory.getLog(RedirectUnmarshallerListener.class); - protected RedirectEventFilter eventFilter; - - public RedirectUnmarshallerListener(RedirectEventFilter eventFilter) { - this.eventFilter = eventFilter; - } - - @Override - public void beforeUnmarshal(Object target, Object parent) { - if (target instanceof RedirectCallback) { - try { - ((RedirectCallback) target).enableRedirect(eventFilter); - } catch (XMLStreamException ex) { - log.error("failed to enable event redirection for " + target.getClass().getName() + ": " + ex.getMessage(), ex); - } - } - if (target instanceof NamespaceContextCallback) { - ((NamespaceContextCallback) target).preserveNamespaceContext(eventFilter); - } - } - - @Override - public void afterUnmarshal(Object target, Object parent) { - if (target instanceof RedirectCallback) { - try { - ((RedirectCallback) target).disableRedirect(eventFilter); - } catch (XMLStreamException ex) { - log.error("failed to disable event redirection for " + target.getClass().getName() + ": " + ex.getMessage(), ex); - } - } - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/SignatureLocationType.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/SignatureLocationType.java deleted file mode 100644 index 494e6972..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/SignatureLocationType.java +++ /dev/null @@ -1,50 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding.impl; - -import at.gv.egiz.slbinding.*; -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.namespace.NamespaceContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class SignatureLocationType extends at.buergerkarte.namespaces.securitylayer._1.SignatureLocationType implements NamespaceContextCallback { - - @XmlTransient - private static Log log = LogFactory.getLog(SignatureLocationType.class); - @XmlTransient - protected NamespaceContext namespaceContext; - - @Override - public NamespaceContext getNamespaceContext() { - return namespaceContext; - } - - @Override - public void preserveNamespaceContext(RedirectEventFilter filter) { - log.debug("preserving namespace context for SignatureLocationType"); - namespaceContext = filter.getCurrentNamespaceContext(); - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java deleted file mode 100644 index b1de9406..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java +++ /dev/null @@ -1,79 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding.impl; - -import at.gv.egiz.slbinding.*; -import java.io.ByteArrayOutputStream; -import java.io.UnsupportedEncodingException; -import java.util.HashSet; -import java.util.Set; -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class TransformsInfoType extends at.buergerkarte.namespaces.securitylayer._1.TransformsInfoType implements RedirectCallback { - - @XmlTransient - private static Log log = LogFactory.getLog(TransformsInfoType.class); - @XmlTransient - private static final Set<QName> redirectTriggers = initRedirectTriggers(); - @XmlTransient - protected ByteArrayOutputStream redirectOS = null; - - private static Set<QName> initRedirectTriggers() { - HashSet<QName> dsigTransforms = new HashSet<QName>(); - dsigTransforms.add(new QName("http://www.w3.org/2000/09/xmldsig#", "Transforms")); - return dsigTransforms; - } - - @Override - public void enableRedirect(RedirectEventFilter filter) throws XMLStreamException { - log.debug("enabling event redirection for TransformsInfoType"); - redirectOS = new ByteArrayOutputStream(); - filter.setRedirectStream(redirectOS, redirectTriggers); - } - - @Override - public void disableRedirect(RedirectEventFilter filter) throws XMLStreamException { - log.debug("disabling event redirection for TransformsInfoType"); - filter.flushRedirectStream(); - filter.setRedirectStream(null); - if (log.isDebugEnabled()) { - try { - log.debug("redirected events (UTF-8): " + redirectOS.toString("UTF-8")); - } catch (UnsupportedEncodingException ex) { - log.debug("failed to log redirected events", ex); - } - } - } - - @Override - public ByteArrayOutputStream getRedirectedStream() { - return redirectOS; - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java deleted file mode 100644 index fd52e378..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding.impl; - -import at.gv.egiz.slbinding.RedirectCallback; -import at.gv.egiz.slbinding.RedirectEventFilter; -import java.io.ByteArrayOutputStream; -import java.io.UnsupportedEncodingException; - -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.stream.XMLStreamException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class XMLContentType extends at.buergerkarte.namespaces.securitylayer._1.XMLContentType implements RedirectCallback { - - @XmlTransient - private static Log log = LogFactory.getLog(XMLContentType.class); - @XmlTransient - protected ByteArrayOutputStream redirectOS = null; - - @Override - public void enableRedirect(RedirectEventFilter filter) throws XMLStreamException { - log.debug("enabling event redirection for XMLContentType"); - redirectOS = new ByteArrayOutputStream(); - filter.setRedirectStream(redirectOS); - } - - @Override - public void disableRedirect(RedirectEventFilter filter) throws XMLStreamException { - log.debug("disabling event redirection for XMLContentType"); - filter.flushRedirectStream(); - filter.setRedirectStream(null); - if (log.isDebugEnabled()) { - try { - log.debug("redirected events (UTF-8): " + redirectOS.toString("UTF-8")); - } catch (UnsupportedEncodingException ex) { - log.debug("failed to log redirected events", ex); - } - } - } - - @Override - public ByteArrayOutputStream getRedirectedStream() { - return redirectOS; - } -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/validation/ReportingValidationEventHandler.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/validation/ReportingValidationEventHandler.java deleted file mode 100644 index 6543c333..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/validation/ReportingValidationEventHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.validation; - -import javax.xml.bind.ValidationEvent; -import javax.xml.bind.ValidationEventHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> - */ -public class ReportingValidationEventHandler implements ValidationEventHandler { - - protected static final Log log = LogFactory.getLog(ReportingValidationEventHandler.class); - - protected ValidationEvent errorEvent; - - /** - * - * @param event - * @return false, terminate the current unmarshal, validate, or marshal operation after handling this warning/error - * (except for WARNING validation events) - */ - @Override - public boolean handleEvent(ValidationEvent event) { - switch (event.getSeverity()) { - case ValidationEvent.WARNING: - log.info(event.getMessage()); - return true; - case ValidationEvent.ERROR: - log.warn(event.getMessage()); - errorEvent = event; - return false; - case ValidationEvent.FATAL_ERROR: - log.error(event.getMessage()); - errorEvent = event; - return false; - default: - log.debug(event.getMessage()); - return false; - } - } - - public ValidationEvent getErrorEvent() { - return errorEvent; - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xades/QualifyingPropertiesException.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xades/QualifyingPropertiesException.java deleted file mode 100644 index e892a13b..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xades/QualifyingPropertiesException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* 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.xades;
-
-public class QualifyingPropertiesException extends Exception {
-
- public QualifyingPropertiesException() {
- // TODO Auto-generated constructor stub
- }
-
- public QualifyingPropertiesException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- public QualifyingPropertiesException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- public QualifyingPropertiesException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xades/QualifyingPropertiesFactory.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xades/QualifyingPropertiesFactory.java deleted file mode 100644 index 6f694b91..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xades/QualifyingPropertiesFactory.java +++ /dev/null @@ -1,230 +0,0 @@ -/* -* 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.xades; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateEncodingException; -import java.security.cert.X509Certificate; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.TimeZone; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.PropertyException; -import javax.xml.crypto.dsig.DigestMethod; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - -import org.etsi.uri._01903.v1_1.CertIDListType; -import org.etsi.uri._01903.v1_1.CertIDType; -import org.etsi.uri._01903.v1_1.DataObjectFormatType; -import org.etsi.uri._01903.v1_1.DigestAlgAndValueType; -import org.etsi.uri._01903.v1_1.QualifyingPropertiesType; -import org.etsi.uri._01903.v1_1.SignaturePolicyIdentifierType; -import org.etsi.uri._01903.v1_1.SignedDataObjectPropertiesType; -import org.etsi.uri._01903.v1_1.SignedPropertiesType; -import org.etsi.uri._01903.v1_1.SignedSignaturePropertiesType; -import org.w3._2000._09.xmldsig_.DigestMethodType; -import org.w3._2000._09.xmldsig_.X509IssuerSerialType; -import org.w3c.dom.Node; - -import at.gv.egiz.marshal.MarshallerFactory; - -public class QualifyingPropertiesFactory { - - public static String NS_URI_V1_1_1 = "http://uri.etsi.org/01903/v1.1.1#"; - - public static String SIGNED_PROPERTIES_REFERENCE_TYPE_V1_1_1 = NS_URI_V1_1_1 + "SignedProperties"; - - private static QualifyingPropertiesFactory instance; - - /** - * The <code>JAXBContext</code>. - */ - private static JAXBContext jaxbContext; - - public static synchronized QualifyingPropertiesFactory getInstance() { - if (instance == null) { - instance = new QualifyingPropertiesFactory(); - } - return instance; - } - - private DatatypeFactory datatypeFactory; - - private org.etsi.uri._01903.v1_1.ObjectFactory qpFactory; - - private org.w3._2000._09.xmldsig_.ObjectFactory dsFactory; - - public QualifyingPropertiesFactory() { - - try { - datatypeFactory = DatatypeFactory.newInstance(); - } catch (DatatypeConfigurationException e) { - throw new RuntimeException(e); - } - - qpFactory = new org.etsi.uri._01903.v1_1.ObjectFactory(); - - dsFactory = new org.w3._2000._09.xmldsig_.ObjectFactory(); - - StringBuffer packageNames = new StringBuffer(); - - packageNames.append(org.etsi.uri._01903.v1_1.ObjectFactory.class.getPackage().getName()); - packageNames.append(":"); - packageNames.append(org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName()); - - try { - jaxbContext = JAXBContext.newInstance(packageNames.toString()); - } catch (JAXBException e) { - // we should not get an JAXBException initializing the JAXBContext - throw new RuntimeException(e); - } - - } - - public DigestAlgAndValueType createDigestAlgAndValueType(X509Certificate certificate, DigestMethod dm) throws QualifyingPropertiesException { - - DigestMethodType digestMethodType = dsFactory.createDigestMethodType(); - digestMethodType.setAlgorithm(dm.getAlgorithm()); - - byte[] digest; - try { - MessageDigest messageDigest = MessageDigest.getInstance(dm.getAlgorithm()); - digest = messageDigest.digest(certificate.getEncoded()); - } catch (CertificateEncodingException e) { - throw new QualifyingPropertiesException(e); - } catch (NoSuchAlgorithmException e) { - throw new QualifyingPropertiesException(e); - } - - DigestAlgAndValueType digestAlgAndValueType = qpFactory.createDigestAlgAndValueType(); - digestAlgAndValueType.setDigestMethod(digestMethodType); - digestAlgAndValueType.setDigestValue(digest); - - return digestAlgAndValueType; - - } - - public X509IssuerSerialType createX509IssuerSerialType(X509Certificate certificate) { - - String name = certificate.getIssuerX500Principal().getName("RFC2253"); - BigInteger serialNumber = certificate.getSerialNumber(); - - X509IssuerSerialType issuerSerialType = dsFactory.createX509IssuerSerialType(); - issuerSerialType.setX509IssuerName(name); - issuerSerialType.setX509SerialNumber(serialNumber); - - return issuerSerialType; - - } - - public DataObjectFormatType createDataObjectFormatType(String objectReference, String mimeType, String description) { - - DataObjectFormatType dataObjectFormatType = qpFactory.createDataObjectFormatType(); - dataObjectFormatType.setObjectReference(objectReference); - - if (mimeType != null) { - dataObjectFormatType.setMimeType(mimeType); - } - if (description != null) { - dataObjectFormatType.setDescription(description); - } - - return dataObjectFormatType; - } - - public JAXBElement<QualifyingPropertiesType> createQualifyingProperties111( - String target, Date signingTime, List<X509Certificate> certificates, - String idValue, List<DataObjectFormatType> dataObjectFormats, - DigestMethod digestMethod) throws QualifyingPropertiesException { - - GregorianCalendar gregorianCalendar = new GregorianCalendar(); - gregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); - gregorianCalendar.setTime(signingTime); - - SignedSignaturePropertiesType signedSignaturePropertiesType = qpFactory.createSignedSignaturePropertiesType(); - - // SigningTime - XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar); - xmlGregorianCalendar.setFractionalSecond(null); - signedSignaturePropertiesType.setSigningTime(xmlGregorianCalendar); - - // SigningCertificate - CertIDListType certIDListType = qpFactory.createCertIDListType(); - List<CertIDType> certIDs = certIDListType.getCert(); - - for (X509Certificate certificate : certificates) { - - CertIDType certIDType = qpFactory.createCertIDType(); - certIDType.setCertDigest(createDigestAlgAndValueType(certificate, digestMethod)); - certIDType.setIssuerSerial(createX509IssuerSerialType(certificate)); - - certIDs.add(certIDType); - - } - signedSignaturePropertiesType.setSigningCertificate(certIDListType); - - // SignaturePolicy - SignaturePolicyIdentifierType signaturePolicyIdentifierType = qpFactory.createSignaturePolicyIdentifierType(); - signaturePolicyIdentifierType.setSignaturePolicyImplied(new SignaturePolicyIdentifierType.SignaturePolicyImplied()); - signedSignaturePropertiesType.setSignaturePolicyIdentifier(signaturePolicyIdentifierType); - - // SignedProperties - SignedPropertiesType signedPropertiesType = qpFactory.createSignedPropertiesType(); - signedPropertiesType.setSignedSignatureProperties(signedSignaturePropertiesType); - - // DataObjectFormat - if (dataObjectFormats != null && !dataObjectFormats.isEmpty()) { - SignedDataObjectPropertiesType signedDataObjectPropertiesType = qpFactory.createSignedDataObjectPropertiesType(); - List<DataObjectFormatType> dataObjectFormatTypes = signedDataObjectPropertiesType.getDataObjectFormat(); - dataObjectFormatTypes.addAll(dataObjectFormats); - signedPropertiesType.setSignedDataObjectProperties(signedDataObjectPropertiesType); - } - - signedPropertiesType.setId(idValue); - - // QualifyingProperties - QualifyingPropertiesType qualifyingPropertiesType = qpFactory.createQualifyingPropertiesType(); - qualifyingPropertiesType.setSignedProperties(signedPropertiesType); - - qualifyingPropertiesType.setTarget(target); - - return qpFactory.createQualifyingProperties(qualifyingPropertiesType); - - } - - public void marshallQualifyingProperties(JAXBElement<QualifyingPropertiesType> qualifyingProperties, Node parent) throws JAXBException { - - try { - Marshaller marshaller = MarshallerFactory.createMarshaller(jaxbContext, true); - - marshaller.marshal(qualifyingProperties, parent); - } catch (PropertyException e) { - throw new RuntimeException(e); - } - - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xmldsig/KeyTypeNotSupportedException.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xmldsig/KeyTypeNotSupportedException.java deleted file mode 100644 index 3afa6d51..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xmldsig/KeyTypeNotSupportedException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* -* 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.xmldsig;
-
-/**
- * @author mcentner
- *
- */
-public class KeyTypeNotSupportedException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- *
- */
- public KeyTypeNotSupportedException() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- */
- public KeyTypeNotSupportedException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param cause
- */
- public KeyTypeNotSupportedException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
- */
- public KeyTypeNotSupportedException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xmldsig/KeyValueFactory.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xmldsig/KeyValueFactory.java deleted file mode 100644 index c1772312..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/xmldsig/KeyValueFactory.java +++ /dev/null @@ -1,279 +0,0 @@ -/* -* 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.xmldsig;
-
-import iaik.security.ecc.interfaces.ECDSAParams;
-import iaik.security.ecc.interfaces.ECDSAPublicKey;
-import iaik.security.ecc.math.ecgroup.Coordinate;
-import iaik.security.ecc.math.ecgroup.ECPoint;
-import iaik.security.ecc.math.ecgroup.EllipticCurve;
-import iaik.security.ecc.math.field.BinaryField;
-import iaik.security.ecc.math.field.Field;
-import iaik.security.ecc.math.field.FieldElement;
-import iaik.security.ecc.math.field.PrimeField;
-
-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.RSAPublicKey;
-
-import javax.xml.bind.JAXBElement;
-
-import org.w3._2000._09.xmldsig_.DSAKeyValueType;
-import org.w3._2000._09.xmldsig_.RSAKeyValueType;
-import org.w3._2001._04.xmldsig_more_.BasePointParamsType;
-import org.w3._2001._04.xmldsig_more_.CharTwoFieldElemType;
-import org.w3._2001._04.xmldsig_more_.CurveParamsType;
-import org.w3._2001._04.xmldsig_more_.DomainParamsType;
-import org.w3._2001._04.xmldsig_more_.ECDSAKeyValueType;
-import org.w3._2001._04.xmldsig_more_.ECPointType;
-import org.w3._2001._04.xmldsig_more_.ExplicitParamsType;
-import org.w3._2001._04.xmldsig_more_.FieldElemType;
-import org.w3._2001._04.xmldsig_more_.FieldParamsType;
-import org.w3._2001._04.xmldsig_more_.PnBFieldParamsType;
-import org.w3._2001._04.xmldsig_more_.PrimeFieldElemType;
-import org.w3._2001._04.xmldsig_more_.PrimeFieldParamsType;
-import org.w3._2001._04.xmldsig_more_.TnBFieldParamsType;
-import org.w3._2001._04.xmldsig_more_.DomainParamsType.NamedCurve;
-
-public class KeyValueFactory {
-
- private static byte[] bigInteger2byteArray(BigInteger bigPositiveInt) {
- if (bigPositiveInt == null)
- throw new NullPointerException("Argument 'bigPositiveInt' must not be null");
- if (bigPositiveInt.signum() != 1)
- throw new IllegalArgumentException("Argument 'bigPositiveInt' must not be negative");
-
- byte[] byteRepresentation = bigPositiveInt.toByteArray();
- if (byteRepresentation[0] == 0) {
- byte[] oldByteRepresentation = byteRepresentation;
- byteRepresentation = new byte[oldByteRepresentation.length - 1];
- System.arraycopy(oldByteRepresentation, 1, byteRepresentation, 0, oldByteRepresentation.length - 1);
- }
- return byteRepresentation;
- }
-
- org.w3._2001._04.xmldsig_more_.ObjectFactory ecFactory = new org.w3._2001._04.xmldsig_more_.ObjectFactory();
-
- org.w3._2000._09.xmldsig_.ObjectFactory dsFactory = new org.w3._2000._09.xmldsig_.ObjectFactory();
-
- public JAXBElement<?> createKeyValue(PublicKey publicKey) throws KeyTypeNotSupportedException {
-
- if (publicKey instanceof RSAPublicKey) {
- RSAKeyValueType keyValueType = createRSAKeyValueType((RSAPublicKey) publicKey);
- return dsFactory.createRSAKeyValue(keyValueType);
- } else if (publicKey instanceof DSAPublicKey) {
- DSAKeyValueType keyValueType = createKeyValueType((DSAPublicKey) publicKey);
- return dsFactory.createDSAKeyValue(keyValueType);
- } else if (publicKey instanceof ECDSAPublicKey) {
- ECDSAKeyValueType keyValueType = createKeyValueType((ECDSAPublicKey) publicKey);
- return ecFactory.createECDSAKeyValue(keyValueType);
- } else if ("EC".equals(publicKey.getAlgorithm())) {
- byte[] encoded = publicKey.getEncoded();
- try {
- iaik.security.ecc.ecdsa.ECPublicKey key = new iaik.security.ecc.ecdsa.ECPublicKey(encoded);
- ECDSAKeyValueType keyValueType = createKeyValueType(key);
- return ecFactory.createECDSAKeyValue(keyValueType);
- } catch (InvalidKeyException e) {
- throw new KeyTypeNotSupportedException("Public key of type "
- + publicKey.getAlgorithm() + " (" + publicKey.getClass()
- + ") not supported.");
- }
- } else {
- throw new KeyTypeNotSupportedException("Public key of type "
- + publicKey.getAlgorithm() + " (" + publicKey.getClass()
- + ") not supported.");
- }
-
- }
-
- public RSAKeyValueType createRSAKeyValueType(RSAPublicKey publicKey) {
-
- RSAKeyValueType keyValueType = dsFactory.createRSAKeyValueType();
- keyValueType.setExponent(bigInteger2byteArray(publicKey.getPublicExponent()));
- keyValueType.setModulus(bigInteger2byteArray(publicKey.getModulus()));
-
- return keyValueType;
- }
-
- public DSAKeyValueType createKeyValueType(DSAPublicKey publicKey) {
-
- DSAKeyValueType keyValueType = dsFactory.createDSAKeyValueType();
-
- if (publicKey.getParams() != null) {
- // P, Q, G
- DSAParams params = publicKey.getParams();
- if (params.getP() != null && params.getQ() != null) {
- keyValueType.setP(bigInteger2byteArray(params.getP()));
- keyValueType.setQ(bigInteger2byteArray(params.getQ()));
- }
- if (params.getG() != null) {
- keyValueType.setG(bigInteger2byteArray(params.getG()));
- }
- }
- //
- keyValueType.setY(bigInteger2byteArray(publicKey.getY()));
-
- return keyValueType;
- }
-
- public ECDSAKeyValueType createKeyValueType(ECDSAPublicKey publicKey) throws KeyTypeNotSupportedException {
-
- ECDSAKeyValueType keyValueType = ecFactory.createECDSAKeyValueType();
-
- ECDSAParams params = publicKey.getParameter();
- if (params != null) {
- keyValueType.setDomainParameters(createDomainParamsType(params));
- }
-
- if (!publicKey.getW().isInfinity()) {
- keyValueType.setPublicKey(createPointType(publicKey.getW()));
- }
-
- return keyValueType;
- }
-
- public ECPointType createPointType(ECPoint point) throws KeyTypeNotSupportedException {
- ECPointType pointType = ecFactory.createECPointType();
- Coordinate affine = point.getCoordinates().toAffine();
- pointType.setX(createFieldElemType(affine.getX()));
- pointType.setY(createFieldElemType(affine.getY()));
- return pointType;
- }
-
- public FieldElemType createFieldElemType(FieldElement fieldElement) throws KeyTypeNotSupportedException {
- int fieldId = fieldElement.getField().getFieldId();
- if (fieldId == PrimeField.PRIME_FIELD_ID) {
- PrimeFieldElemType fieldElemType = ecFactory.createPrimeFieldElemType();
- fieldElemType.setValue(fieldElement.toBigInt());
- return fieldElemType;
- } else if (fieldId == BinaryField.BINARY_FIELD_ID) {
- CharTwoFieldElemType fieldElemType = ecFactory.createCharTwoFieldElemType();
- fieldElemType.setValue(fieldElement.toByteArray());
- return fieldElemType;
- } else {
- throw new KeyTypeNotSupportedException("Field element of type " + fieldId + " not supported.");
- }
- }
-
- public FieldParamsType createFieldParamsType(Field field) throws KeyTypeNotSupportedException {
-
- if (field.getFieldId() == PrimeField.PRIME_FIELD_ID) {
- // PrimeFieldParamsType
- PrimeFieldParamsType primeFieldParamsType = ecFactory.createPrimeFieldParamsType();
- primeFieldParamsType.setP(field.getSize());
- return primeFieldParamsType;
- } else if (field.getFieldId() == BinaryField.BINARY_FIELD_ID && field instanceof BinaryField) {
- // CharTwoFieldParamsType
-
- BinaryField binaryField = (BinaryField) field;
- int[] irreduciblePolynomial = binaryField.getIrreduciblePolynomial();
-
- // The irreducible polynomial as a BinaryFieldValue
- FieldElement irreducible = binaryField.newElement(irreduciblePolynomial);
-
- int order = binaryField.getOrder();
- int[] coeffPositions = new int[3];
-
- // Get coefficients of irreducible polynomial
- int coeffCount = 2;
- for (int i = 1; i < order -1; i++) {
- if (irreducible.testBit(i)) {
- coeffPositions[coeffCount - 2] = i;
- coeffCount++;
- if (coeffCount == 5)
- break;
- }
- }
- // detect if trinomial or pentanomial base is present...
- switch (coeffCount) {
- case 3:
- // trinomial base
- TnBFieldParamsType tnBFieldParamsType = ecFactory.createTnBFieldParamsType();
- tnBFieldParamsType.setM(BigInteger.valueOf(binaryField.getOrder()));
- tnBFieldParamsType.setK(BigInteger.valueOf(coeffPositions[0]));
- return tnBFieldParamsType;
-
- case 5:
- // pentanomial base
- PnBFieldParamsType pnBFieldParamsType = ecFactory.createPnBFieldParamsType();
- pnBFieldParamsType.setM(BigInteger.valueOf(binaryField.getOrder()));
- pnBFieldParamsType.setK1(BigInteger.valueOf(coeffPositions[0]));
- pnBFieldParamsType.setK2(BigInteger.valueOf(coeffPositions[1]));
- pnBFieldParamsType.setK3(BigInteger.valueOf(coeffPositions[2]));
- return pnBFieldParamsType;
-
- default:
- throw new KeyTypeNotSupportedException("Only trinomial and pentanomial base is supported.");
- }
-
- } else {
- throw new KeyTypeNotSupportedException("Field element of type " + field.getFieldId() + " not supported.");
- }
-
- }
-
- public DomainParamsType createDomainParamsType(ECDSAParams params) throws KeyTypeNotSupportedException {
-
- DomainParamsType domainParamsType = ecFactory.createDomainParamsType();
- EllipticCurve curve = params.getG().getCurve();
-
- String oid = params.getOID();
- if (oid != null) {
- // NamedCurve
- NamedCurve namedCurve = ecFactory.createDomainParamsTypeNamedCurve();
- namedCurve.setURN("urn:oid:" + oid);
- domainParamsType.setNamedCurve(namedCurve);
- } else {
- // Explicit parameters
- ExplicitParamsType explicitParamsType = ecFactory.createExplicitParamsType();
- explicitParamsType.setFieldParams(createFieldParamsType(curve.getField()));
-
- CurveParamsType curveParamsType = ecFactory.createCurveParamsType();
-
- // curve coefficients
- curveParamsType.setA(createFieldElemType(curve.getA()));
- curveParamsType.setB(createFieldElemType(curve.getB()));
-
- // seed
- if (params.getS() != null) {
- curveParamsType.setSeed(bigInteger2byteArray(params.getS()));
- }
- explicitParamsType.setCurveParams(curveParamsType);
-
-
- // BasePoint parameters
- BasePointParamsType basePointParamsType = ecFactory.createBasePointParamsType();
- if (!params.getG().isInfinity()) {
- basePointParamsType.setBasePoint(createPointType(params.getG()));
- }
- basePointParamsType.setOrder(params.getR());
- if(params.getK() != null) {
- basePointParamsType.setCofactor(params.getK());
- }
- explicitParamsType.setBasePointParams(basePointParamsType);
-
- domainParamsType.setExplicitParams(explicitParamsType);
- }
-
- return domainParamsType;
-
- }
-
-}
|