
libjava/ChangeLog: 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * sources.am, Makfile.in: Regenerate. 2008-10-17 Matthias Klose <doko@ubuntu.com> * configure.ac: Fix bashisms. * configure: Regenerate. 2008-10-15 Matthias Klose <doko@ubuntu.com> * configure.ac: Disable build of gjdoc, if configured without --with-antlr-jar or if no antlr.jar found. * configure: Regenerate. 2008-10-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure.ac, * classpath/m4/ac_prog_antlr.m4, * classpath/m4/ac_prog_java.m4, * classpath/tools/Makefile.am: Ported --regen-gjdoc-parser patch and cantlr support from GNU Classpath. 2008-10-06 Andrew Haley <aph@redhat.com> * java/lang/Thread.java (Thread): Always create the ThreadLocalMap when creating a thread. (getThreadLocals) Don't lazily create the ThreadLocalMap. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/java/lang/ThreadLocalMap.java, * java/lang/ThreadLocalMap$Entry.h, * java/lang/ThreadLocalMap.h, * lib/java/lang/ThreadLocalMap.class, * lib/java/lang/ThreadLocalMap$Entry.class: Add the new files for the ThreadLocal patch. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/ChangeLog, * classpath/java/lang/InheritableThreadLocal.java, * classpath/java/lang/Thread.java, * classpath/java/lang/ThreadLocal.java: Merge Daniel Frampton's ThreadLocal patch. * gcj/javaprims.h: Updated. * java/lang/Thread.h: Regenerated. * java/lang/Thread.java: Replace WeakIdentityHashMap with ThreadLocalMap. (getThreadLocals()): Likewise. * java/lang/ThreadLocal.h: Regenerated. * java/lang/ThreadLocal.java: (computeNextHash()): New method. (ThreadLocal()): Initialise fastHash. (internalGet()): Updated to match Classpath's get(). (internalSet(Object)): Likewise for set(Object). (internalRemove()): Likewise for remove(). 2008-09-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure, * classpath/configure.ac: Resynchronise with Classpath's configure. * classpath/examples/Makefile.in: Add equivalent support for building as in tools/Makefile.in. * classpath/java/nio/Buffer.java, * classpath/java/nio/ByteBuffer.java, * classpath/java/nio/ByteBufferImpl.java, * classpath/java/nio/CharBuffer.java, * classpath/java/nio/CharBufferImpl.java, * classpath/java/nio/CharSequenceBuffer.java, * classpath/java/nio/CharViewBufferImpl.java, * classpath/java/nio/DirectByteBufferImpl.java, * classpath/java/nio/DoubleBuffer.java, * classpath/java/nio/DoubleBufferImpl.java, * classpath/java/nio/DoubleViewBufferImpl.java, * classpath/java/nio/FloatBuffer.java, * classpath/java/nio/FloatBufferImpl.java, * classpath/java/nio/FloatViewBufferImpl.java, * classpath/java/nio/IntBuffer.java, * classpath/java/nio/IntBufferImpl.java, * classpath/java/nio/IntViewBufferImpl.java, * classpath/java/nio/LongBuffer.java, * classpath/java/nio/LongBufferImpl.java, * classpath/java/nio/LongViewBufferImpl.java, * classpath/java/nio/MappedByteBuffer.java, * classpath/java/nio/MappedByteBufferImpl.java, * classpath/java/nio/ShortBuffer.java, * classpath/java/nio/ShortBufferImpl.java, * classpath/java/nio/ShortViewBufferImpl.java: Replace use of gnu.classpath.Pointer with gnu.gcj.RawData, and fix some formatting issues. * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.txt: Regenerated (later version of antlr). * java/nio/Buffer.h: Regenerated. * java/nio/Buffer.java: Ported changes from Classpath. * java/nio/ByteBuffer.h, * java/nio/CharBuffer.h: Regenerated. * java/nio/DirectByteBufferImpl.java: Ported changes from Classpath. * java/nio/DoubleBuffer.h, * java/nio/FloatBuffer.h, * java/nio/IntBuffer.h, * java/nio/LongBuffer.h, * java/nio/MappedByteBuffer.h, * java/nio/MappedByteBufferImpl.h: Regenerated. * java/nio/MappedByteBufferImpl.java: Ported changes from Classpath. * java/nio/ShortBuffer.h: Regenerated. 2008-09-24 Matthias Klose <doko@ubuntu.com> * configure.ac: Search for antlr.jar, if not configured. * configure: Regenerate. 2008-09-24 Matthias Klose <doko@ubuntu.com> * Makefile.am: Build a gjdoc binary, if enabled. * configure.ac: Add options --disable-gjdoc, --with-antlr-jar=file. * Makefile.in, */Makefile.in, configure: Regenerate. 2008-09-22 Andrew Haley <aph@redhat.com> * java/lang/String.java (toString(char[], int, int)): New method. 2008-09-14 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080914). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --disable-gjdoc to classpath. * sources.am: Regenerated. * HACKING: Mention to build gjdoc in maintainer builds. * gnu/classpath/Configuration.java: Update classpath version. * gcj/javaprims.h: Update. 2008-09-08 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.am: Replace natStringBuffer.cc and natStringBuilder.cc with natAbstractStringBuffer.cc. * Makefile.in: Regenerated. * java/lang/AbstractStringBuffer.java: (append(int)): Made native. (regionMatches(int,String)): Likewise. * java/lang/StringBuffer.h: Regenerated. * java/lang/StringBuffer.java: Remerged with GNU Classpath. * java/lang/StringBuilder.h: Regenerated. * java/lang/StringBuilder.java: Remerged with GNU Classpath. * java/lang/natAbstractStringBuffer.cc: Provide common native methods for StringBuffer and StringBuilder. * java/lang/natStringBuffer.cc, * java/lang/natStringBuilder.cc: Removed. 2008-09-04 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in, * classpath/configure: Regenerated. * gnu/gcj/util/natDebug.cc, * gnu/gcj/xlib/natColormap.cc, * gnu/gcj/xlib/natDisplay.cc, * gnu/gcj/xlib/natDrawable.cc, * gnu/gcj/xlib/natFont.cc, * gnu/gcj/xlib/natWMSizeHints.cc, * gnu/gcj/xlib/natWindow.cc, * gnu/gcj/xlib/natXImage.cc: Add :: prefix to namespaces. * java/io/CharArrayWriter.h, * java/lang/StringBuffer.h: Regenerated using patched gjavah. * java/lang/natStringBuffer.cc: Fix naming of append(jint). * java/sql/Timestamp.h: Regenerated using patched gjavah. * jni.cc: Rename p to functions to match change in GNU Classpath. * scripts/makemake.tcl: Switch gnu.java.math to BC compilation. * sources.am: Regenerated. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated location of Configuration.java. * classpath/lib/gnu/java/locale/LocaleData.class: Regenerated. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated with new Java files. * classpath/configure: Regenerated. * classpath/tools/Makefile.am: Add missing use of GJDOC_EX so --disable-gjdoc works. * classpath/tools/Makefile.in: Regenerated. 2008-08-15 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080811). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --with-fastjar to classpath, substitute new dummy value in classpath/gnu/classpath/Configuration.java.in, pass --disable-gjdoc to classpath. * scripts/makemake.tcl: * sources.am: Regenerated. * java/lang/AbstractStringBuffer.java, gnu/java/lang/VMCPStringBuilder.java: New, copied from classpath, use System instead of VMSystem. * java/lang/StringBuffer.java: Merge from classpath. * java/lang/ClassLoader.java: Merge from classpath. * gcj/javaprims.h: Update class definitions, remove _Jv_jobjectRefType, jobjectRefType definitions. libjava/classpath/ChangeLog.gcj: 2008-10-21 Matthias Klose <doko@ubuntu.com> * classpath/tools/gnu/classpath/tools/gjdoc/expr/Java*: Move from ... * classpath/tools/generated/gnu/classpath/tools/gjdoc/expr/ ... here. * Update .class files. 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Always generate parser in the srcdir. 2008-10-21 Matthias Klose <doko@ubuntu.com> * doc/Makefile.am (MAINTAINERCLEANFILES): Add gjdoc.1. * doc/Makefile.in: Regenerate. 2008-10-20 Matthias Klose <doko@ubuntu.com> * configure.ac: Don't check for working java, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_java.m4: Revert previous change. * m4/ac_prog_javac.m4: Apply it here. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac.m4: Don't check for working javac, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. * Makefile.in, */Makefile.in: Regenerate. 2008-09-30 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for cantlr binary as well. 2008-09-29 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for antlr binary as well. 2008-09-28 Matthias Klose <doko@ubuntu.com> * PR libgcj/37636. Revert: 2008-02-20 Matthias Klose <doko@ubuntu.com> * tools/Makefile.am ($(TOOLS_ZIP)): Revert part of previous change, Do copy resource files in JAVA_MAINTAINER_MODE only. * tools/Makefile.in: Regenerate. 2008-09-14 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac_works.m4, m4/ac_prog_javac.m4, m4/acinclude.m4: Revert local changes. * m4/ac_prog_antlr.m4: Check for an runantlr binary. * tools/Makefile.am, lib/Makefile.am: Revert local changes (JCOMPILER). * tools/Makefile.am: Remove USE_JAVAC_FLAGS, pass ANTLR_JAR in GLIBJ_CLASSPATH. 2008-09-14 Matthias Klose <doko@ubuntu.com> Revert: Daniel Frampton <zyridium at zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-08-15 Matthias Klose <doko@ubuntu.com> * m4/acinclude.m4 (CLASSPATH_JAVAC_MEM_CHECK): Remove unknown args for javac. libjava/classpath/ChangeLog: 2008-10-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr.m4: Remove redundant checks. * tools/Makefile.am: Use gjdoc_gendir when calling antlr. 2008-10-15 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Remove superfluous AC_PROG_JAVA call. 2008-10-06 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr: Check for cantlr as well. * tools/Makefile.am: Only build GJDoc parser when both CREATE_GJDOC and CREATE_GJDOC_PARSER are on. 2008-10-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Add regen-gjdoc-parser option, and separate antlr tests. * m4/ac_prog_antlr.m4: Turn single test into AC_LIB_ANTLR and AC_PROG_ANTLR. * m4/ac_prog_java.m4: Quote tests. * tools/Makefile.am: Support CREATE_GJDOC_PARSER option. 2008-09-14 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am: Check lib directly as well as glibj.zip for boot classes. * m4/acinclude.m4: Only require the class files to be built to allow the tools and examples to be built, not the installation of glibj.zip. * tools/Makefile.am: Check lib directly as well as glibj.zip for boot classes. 2008-09-13 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am, * lib/Makefile.am: Add GCJ rules. * m4/ac_prog_javac.m4: Check whether JAVAC is gcj. * m4/ac_prog_javac_works.m4: Add GCJ rules. * m4/acinclude.m4: Don't bother checking for -J if using GCJ. * tools/Makefile.am: Add GCJ rules. 2007-08-23 Daniel Frampton <zyridium@zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-02-07 Ian Rogers <ian.rogers@manchester.ac.uk> * java/util/zip/ZipEntry.java: Use byte fields instead of integer fields, store the time as well as the DOS time and don't retain a global Calendar instance. (setDOSTime(int)): Set KNOWN_DOSTIME instead of KNOWN_TIME, and unset KNOWN_TIME. (getDOSTime()): Compute DOS time from UNIX time only when needed. (clone()): Provide cloning via the ZipEntry constructor where possible. (setTime(long)): Don't compute DOS time at this point. (getCalendar()): Removed. 2008-09-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/getopt/Parser.java: (setHeader(String)): Make synchronized. (setFooter(String)): Likewise. * tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java, (reset()): Make synchronized. (name(Class)): Likewise. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * gnu/java/nio/charset/ByteDecodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. * gnu/java/nio/charset/ByteEncodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * java/text/DecimalFormat.java: (scanFix): Use 'i + 1' when looking at following character. (scanNegativePattern): Dito. 2008-09-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/javah/ClassWrapper.java: (makeVtable()): Populate methodNameMap. (printMethods(CniPrintStream)): Always use pre-populated methodNameMap for bridge targets. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XImage.java (XImageProducer): remove @Override annotation to allow compilation on javac < 1.6 and ecj < 3.4. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XGraphicsDevice.java (getDisplay): fix to support new Escher API. * gnu/java/awt/peer/x/XImage.java (getSource): method implemented. * gnu/java/awt/peer/x/XImage.java (XImageProducer): implement ImageProducer for getSource. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/BacktrackStack.java, * gnu/java/util/regex/CharIndexed.java, * gnu/java/util/regex/CharIndexedCharArray.java, * gnu/java/util/regex/CharIndexedCharSequence.java, * gnu/java/util/regex/CharIndexedInputStream.java, * gnu/java/util/regex/CharIndexedString.java, * gnu/java/util/regex/CharIndexedStringBuffer.java, * gnu/java/util/regex/RE.java, * gnu/java/util/regex/REException.java, * gnu/java/util/regex/REFilterInputStream.java, * gnu/java/util/regex/REMatch.java, * gnu/java/util/regex/REMatchEnumeration.java, * gnu/java/util/regex/RESyntax.java, * gnu/java/util/regex/REToken.java, * gnu/java/util/regex/RETokenAny.java, * gnu/java/util/regex/RETokenBackRef.java, * gnu/java/util/regex/RETokenChar.java, * gnu/java/util/regex/RETokenEnd.java, * gnu/java/util/regex/RETokenEndOfPreviousMatch.java, * gnu/java/util/regex/RETokenEndSub.java, * gnu/java/util/regex/RETokenIndependent.java, * gnu/java/util/regex/RETokenLookAhead.java, * gnu/java/util/regex/RETokenLookBehind.java, * gnu/java/util/regex/RETokenNamedProperty.java, * gnu/java/util/regex/RETokenOneOf.java, * gnu/java/util/regex/RETokenPOSIX.java, * gnu/java/util/regex/RETokenRange.java, * gnu/java/util/regex/RETokenRepeated.java, * gnu/java/util/regex/RETokenStart.java, * gnu/java/util/regex/RETokenWordBoundary.java, * gnu/java/util/regex/UncheckedRE.java: Fix indentation. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/RETokenStart.java: (getMaximumLength()): Add Override annotation. (matchThis(CharIndexed, REMatch)): Likewise. (returnsFixedLengthMatches()): Renamed from returnsFixedLengthmatches and added Override annotation. (findFixedLengthMatches(CharIndexed,REMatch,int)): Add Override annotation. (dump(CPStringBuilder)): Likewise. * gnu/javax/print/ipp/IppRequest.java: (RequestWriter.writeOperationAttributes(AttributeSet)): Throw exception, don't just create and drop it. * javax/management/MBeanServerPermission.java: (MBeanServerPermissionCollection.add(Permission)): Compare against individual Strings not the entire array, and store the result of replace. * javax/swing/text/html/StyleSheet.java: (setBaseFontSize(size)): Store result of trim(). 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/tools/FileObject.java: (openReader(boolean)): Document new parameter. 2008-03-27 Michael Franz <mvfranz@gmail.com> PR classpath/35690: * javax/tools/FileObject.java: (toUri()): Fix case from toURI. (openReader(boolean)): Add missing boolean argument. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/35487: * gnu/javax/management/Server.java: (beans): Change to ConcurrentHashMap. (defaultDomain): Make final. (outer): Likewise. (LazyListenersHolder): Added to wrap listeners, also now a ConcurrentHashMap, providing lazy initialisation safely. (sequenceNumber): Documented. (getBean(ObjectName)): Remove redundant cast. (addNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Remove map initialisation and use holder. (getObjectInstance(ObjectName)): Remove redundant cast. (registerMBean(Object,ObjectName)): Add bean atomically. (removeNotificationListener(ObjectName,NotificationListener)): Simplified. (removeNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Likewise. (notify(ObjectName,String)): Documented. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Server.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Translator.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/DefaultLoaderRepository.java, * javax/management/JMX.java, * javax/management/MBeanAttributeInfo.java, * javax/management/MBeanConstructorInfo.java, * javax/management/MBeanOperationInfo.java, * javax/management/MBeanServerDelegate.java: Fix warnings due to generics. 2008-08-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/MBeanPermission.java, * javax/management/MBeanServerDelegate.java, * javax/management/MBeanServerFactory.java, * javax/management/MBeanServerInvocationHandler.java, * javax/management/MBeanServerPermission.java: Fix warnings due to use of non-generic collections. 2008-08-25 Mario Torre <neugens@aicas.com> * gnu/javax/rmi/CORBA/RmiUtilities.java (readValue): check if sender is null to avoid NPE. 2008-08-22 Mario Torre <neugens@aicas.com> * gnu/CORBA/OrbFunctional.java (set_parameters): Fix NullPointerException checking when param is null. 2008-08-23 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (reset()): Reset append position so we don't try and append to the end of the old input. 2008-08-22 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: Also allow versions of GJDoc from 0.8* on, as CVS is 0.8.0-pre. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: (CLASSPATH_WITH_GJDOC): Ensure version 0.7.9 is being used. 2008-08-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Add taglets subdirectory to list of excluded paths when GJDoc is not compiled. 2008-08-19 David P Grove <groved@us.ibm.com> * scripts/check_jni_methods.sh.in: Fix build issue on AIX by splitting generation of method list. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * native/jni/gstreamer-peer/gst_native_pipeline.c: (get_free_space(int)): Use #else not #elif when there is no condition. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/31895: * java/text/DecimalFormat.java: (setCurrency(Currency)): Update prefixes and suffixes when currency changes. * java/text/DecimalFormatSymbols.java: (DecimalFormatSymbols(Locale)): Set locale earlier so it can be used by setCurrency(Currency). (setCurrency(Currency)): Set the symbol correctly using the locale of the instance. * java/util/Currency.java: Throw error instead of just printing a message. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/activation/ActivationDataFlavor.java: Suppress warnings from public API. (mimeType): Made final. (representationClass): Added generic type and made final. (normalizeMimeTypeParameter(String,String)): Use CPStringBuilder. * javax/activation/CommandInfo.java: (verb): Made final. (className): Made final. * javax/activation/DataHandler.java: (dataSource): Made final. * javax/activation/FileDataSource.java: (file): Made final. * javax/activation/MailcapCommandMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeType.java: (toString()): Use CPStringBuilder. (getBaseType()): Likewise. * javax/activation/MimeTypeParameterList.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeTypeParseException.java: (MimeTypeParseException(String,String)): Use CPStringBuilder. * javax/activation/MimetypesFileTypeMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/URLDataSource.java: (url): Made final. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/activation/viewers/ImageViewer.java, * gnu/javax/activation/viewers/TextEditor.java, * gnu/javax/activation/viewers/TextViewer.java, * javax/activation/ActivationDataFlavor.java, * javax/activation/CommandInfo.java, * javax/activation/CommandMap.java, * javax/activation/CommandObject.java, * javax/activation/DataContentHandler.java, * javax/activation/DataContentHandlerFactory.java, * javax/activation/DataHandler.java, * javax/activation/DataHandlerDataSource.java, * javax/activation/DataSource.java, * javax/activation/DataSourceDataContentHandler.java, * javax/activation/FileDataSource.java, * javax/activation/FileTypeMap.java, * javax/activation/MailcapCommandMap.java, * javax/activation/MimeType.java, * javax/activation/MimeTypeParameterList.java, * javax/activation/MimeTypeParseException.java, * javax/activation/MimetypesFileTypeMap.java, * javax/activation/ObjectDataContentHandler.java, * javax/activation/URLDataSource.java, * javax/activation/UnsupportedDataTypeException.java, * javax/activation/package.html, * resource/META-INF/mailcap.default, * resource/META-INF/mimetypes.default: Import GNU JAF CVS as of 17/08/2008. 2006-04-25 Archit Shah <ashah@redhat.com> * javax/activation/MimeTypeParameterList.java: Insert ';' separator before parameter list. 2005-06-29 Xavier Poinsard <xpoinsard@openpricer.com> * javax/activation/ObjectDataContentHandler.java: Fixed typo. 2005-05-28 Chris Burdess <dog@bluezoo.org> * javax/activation/CommandMap.java, * javax/activation/MailcapCommandMap.java: Updated to JAF 1.1. 2004-06-09 Chris Burdess <dog@bluezoo.org> * javax/activation/MailcapCommandMap.java: Fixed bug whereby x-java prefix was not attempted. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * AUTHORS: Added Laszlo. 2008-04-20 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/30436: * java/util/Scanner.java: Fix package to be java.util and correct indentation. 2007-07-25 Laszlo Andras Hernadi <e0327023@student.tuwien.ac.at> PR classpath/30436: * java/util/Scanner.java: Initial implementation. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (toMatchResult()): Implemented. 2008-08-13 Joshua Sumali <jsumali@redhat.com> * doc/Makefile.am (gjdoc.pod): Generate gjdoc pod from cp-tools.texinfo instead of invoke.texi. Remove invoke.texi from EXTRA_DIST. * doc/invoke.texi: Removed and merged into ... * doc/cp-tools.texinfo: Here 2008-08-12 Robert Schuster <robertschuster@fsfe.org> * native/jni/java-net/local.c (local_bind): Removed fprintf call, fixed access outside of array bounds. From-SVN: r141271
1319 lines
38 KiB
Java
1319 lines
38 KiB
Java
/* X509CertSelector.java -- selects X.509 certificates by criteria.
|
|
Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
|
|
|
|
This file is part of GNU Classpath.
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
02110-1301 USA.
|
|
|
|
Linking this library statically or dynamically with other modules is
|
|
making a combined work based on this library. Thus, the terms and
|
|
conditions of the GNU General Public License cover the whole
|
|
combination.
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
permission to link this library with independent modules to produce an
|
|
executable, regardless of the license terms of these independent
|
|
modules, and to copy and distribute the resulting executable under
|
|
terms of your choice, provided that you also meet, for each linked
|
|
independent module, the terms and conditions of the license of that
|
|
module. An independent module is a module which is not derived from
|
|
or based on this library. If you modify this library, you may extend
|
|
this exception to your version of the library, but you are not
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
exception statement from your version. */
|
|
|
|
|
|
package java.security.cert;
|
|
|
|
import gnu.classpath.SystemProperties;
|
|
import gnu.java.lang.CPStringBuilder;
|
|
import gnu.java.security.OID;
|
|
import gnu.java.security.x509.GnuPKIExtension;
|
|
import gnu.java.security.x509.ext.CertificatePolicies;
|
|
import gnu.java.security.x509.ext.Extension;
|
|
import gnu.java.security.x509.ext.GeneralName;
|
|
import gnu.java.security.x509.ext.GeneralSubtree;
|
|
import gnu.java.security.x509.ext.NameConstraints;
|
|
import gnu.java.security.x509.ext.GeneralName.Kind;
|
|
|
|
import java.io.IOException;
|
|
import java.math.BigInteger;
|
|
import java.net.InetAddress;
|
|
import java.security.KeyFactory;
|
|
import java.security.PublicKey;
|
|
import java.security.spec.X509EncodedKeySpec;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
import javax.security.auth.x500.X500Principal;
|
|
|
|
/**
|
|
* A concrete implementation of {@link CertSelector} for X.509 certificates,
|
|
* which allows a number of criteria to be set when accepting certificates,
|
|
* from validity dates, to issuer and subject distinguished names, to some
|
|
* of the various X.509 extensions.
|
|
*
|
|
* <p>Use of this class requires extensive knowledge of the Internet
|
|
* Engineering Task Force's Public Key Infrastructure (X.509). The primary
|
|
* document describing this standard is <a
|
|
* href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509
|
|
* Public Key Infrastructure Certificate and Certificate Revocation List
|
|
* (CRL) Profile</a>.
|
|
*
|
|
* <p>Note that this class is not thread-safe. If multiple threads will
|
|
* use or modify this class then they need to synchronize on the object.
|
|
*
|
|
* @author Casey Marshall (csm@gnu.org)
|
|
* @since 1.4
|
|
*/
|
|
public class X509CertSelector implements CertSelector, Cloneable
|
|
{
|
|
|
|
// Constants and fields.
|
|
// -------------------------------------------------------------------------
|
|
|
|
private static final String AUTH_KEY_ID = "2.5.29.35";
|
|
private static final String SUBJECT_KEY_ID = "2.5.29.14";
|
|
private static final String NAME_CONSTRAINTS_ID = "2.5.29.30";
|
|
|
|
private static boolean checkOid(int[] oid)
|
|
{
|
|
return (oid != null && oid.length > 2 &&
|
|
(oid[0] >= 0 && oid[0] <= 2) && (oid[1] >= 0 && oid[1] <= 39));
|
|
}
|
|
|
|
private static GeneralName makeName(int id, String name) throws IOException
|
|
{
|
|
byte[] nameBytes = null;
|
|
GeneralName.Kind kind = GeneralName.Kind.forTag(id);
|
|
switch (Kind.forTag(id))
|
|
{
|
|
case dNSName:
|
|
case rfc822Name:
|
|
case uniformResourceIdentifier:
|
|
nameBytes = name.getBytes("ASCII");
|
|
break;
|
|
|
|
case iPAddress:
|
|
InetAddress addr = InetAddress.getByName(name);
|
|
nameBytes = addr.getAddress();
|
|
break;
|
|
|
|
case registeredId:
|
|
OID oid = new OID(name);
|
|
nameBytes = oid.getDER();
|
|
break;
|
|
|
|
case directoryName:
|
|
X500Principal xname = new X500Principal(name);
|
|
nameBytes = xname.getEncoded();
|
|
break;
|
|
|
|
case ediPartyName:
|
|
case x400Address:
|
|
case otherName:
|
|
throw new IOException("cannot decode string representation of "
|
|
+ kind);
|
|
}
|
|
return new GeneralName(kind, nameBytes);
|
|
}
|
|
|
|
private int basicConstraints;
|
|
private X509Certificate cert;
|
|
private BigInteger serialNo;
|
|
private X500Principal issuer;
|
|
private X500Principal subject;
|
|
private byte[] subjectKeyId;
|
|
private byte[] authKeyId;
|
|
private boolean[] keyUsage;
|
|
private Date certValid;
|
|
private OID sigId;
|
|
private PublicKey subjectKey;
|
|
private X509EncodedKeySpec subjectKeySpec;
|
|
private Set<String> keyPurposeSet;
|
|
private List<GeneralName> altNames;
|
|
private boolean matchAllNames;
|
|
private byte[] nameConstraints;
|
|
private Set<OID> policy;
|
|
private List<GeneralName> pathToNames;
|
|
|
|
/**
|
|
* Creates a new X.509 certificate selector. The new selector will be
|
|
* empty, and will accept any certificate (provided that it is an
|
|
* {@link X509Certificate}).
|
|
*/
|
|
public X509CertSelector()
|
|
{
|
|
basicConstraints = -1;
|
|
}
|
|
|
|
/**
|
|
* Add a name to match in the NameConstraints extension. The argument is
|
|
* the DER-encoded bytes of a GeneralName structure.
|
|
*
|
|
* See the method {@link #addSubjectAlternativeName(int, byte[])} for the
|
|
* format of the GeneralName structure.
|
|
*
|
|
* @param id The name identifier. Must be between 0 and 8.
|
|
* @param name The DER-encoded bytes of the name to match.
|
|
* @throws IOException If the name DER is malformed.
|
|
*/
|
|
public void addPathToName(int id, byte[] name) throws IOException
|
|
{
|
|
GeneralName generalName = new GeneralName(GeneralName.Kind.forTag(id), name);
|
|
if (pathToNames == null)
|
|
pathToNames = new LinkedList<GeneralName>();
|
|
pathToNames.add(generalName);
|
|
}
|
|
|
|
/**
|
|
* Add a name to match in the NameConstraints extension. This method will
|
|
* only recognize certain types of name that have convenient string
|
|
* encodings. For robustness, you should use the {@link
|
|
* #addPathToName(int, byte[])} method whenever possible.
|
|
*
|
|
* @param id The name identifier. Must be between 0 and 8.
|
|
* @param name The name.
|
|
* @throws IOException If the name cannot be decoded.
|
|
*/
|
|
public void addPathToName(int id, String name) throws IOException
|
|
{
|
|
GeneralName generalName = makeName(id, name);
|
|
if (pathToNames == null)
|
|
pathToNames = new LinkedList<GeneralName>();
|
|
pathToNames.add(generalName);
|
|
}
|
|
|
|
/**
|
|
* Add a name, as DER-encoded bytes, to the subject alternative names
|
|
* criterion.
|
|
*
|
|
* The name is a GeneralName structure, which has the ASN.1 format:
|
|
*
|
|
* <pre>
|
|
GeneralName ::= CHOICE {
|
|
otherName [0] OtherName,
|
|
rfc822Name [1] IA5String,
|
|
dNSName [2] IA5String,
|
|
x400Address [3] ORAddress,
|
|
directoryName [4] Name,
|
|
ediPartyName [5] EDIPartyName,
|
|
uniformResourceIdentifier [6] IA5String,
|
|
iPAddress [7] OCTET STRING,
|
|
registeredID [8] OBJECT IDENTIFIER }
|
|
</pre>
|
|
*
|
|
* @param id The type of name this is.
|
|
* @param name The DER-encoded name.
|
|
* @throws IOException If the name is not a valid DER sequence.
|
|
*/
|
|
public void addSubjectAlternativeName(int id, byte[] name)
|
|
throws IOException
|
|
{
|
|
GeneralName generalName = new GeneralName(GeneralName.Kind.forTag(id), name);
|
|
if (altNames == null)
|
|
altNames = new LinkedList<GeneralName>();
|
|
altNames.add(generalName);
|
|
}
|
|
|
|
/**
|
|
* Add a name to the subject alternative names criterion. This method will
|
|
* only recognize certain types of name that have convenient string
|
|
* encodings. For robustness, you should use the {@link
|
|
* #addSubjectAlternativeName(int, byte[])} method whenever possible.
|
|
*
|
|
* This method can only decode certain name kinds of names as strings.
|
|
*
|
|
* @param id The type of name this is. Must be in the range [0,8].
|
|
* @param name The name.
|
|
* @throws IOException If the id is out of range, or if the name
|
|
* is null.
|
|
*/
|
|
public void addSubjectAlternativeName(int id, String name)
|
|
throws IOException
|
|
{
|
|
GeneralName generalName = makeName(id, name);
|
|
if (altNames == null)
|
|
altNames = new LinkedList<GeneralName>();
|
|
altNames.add(generalName);
|
|
}
|
|
|
|
public Object clone()
|
|
{
|
|
try
|
|
{
|
|
return super.clone();
|
|
}
|
|
catch (CloneNotSupportedException shouldNotHappen)
|
|
{
|
|
throw new Error(shouldNotHappen);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the authority key identifier criterion, or <code>null</code> if
|
|
* this value was not set. Note that the byte array is cloned to prevent
|
|
* modification.
|
|
*
|
|
* @return The authority key identifier.
|
|
*/
|
|
public byte[] getAuthorityKeyIdentifier()
|
|
{
|
|
if (authKeyId != null)
|
|
return (byte[]) authKeyId.clone();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the basic constraints criterion, or -1 if this value is not set.
|
|
*
|
|
* @return The basic constraints.
|
|
*/
|
|
public int getBasicConstraints()
|
|
{
|
|
return basicConstraints;
|
|
}
|
|
|
|
/**
|
|
* Returns the certificate criterion, or <code>null</code> if this value
|
|
* was not set.
|
|
*
|
|
* @return The certificate.
|
|
*/
|
|
public X509Certificate getCertificate()
|
|
{
|
|
return cert;
|
|
}
|
|
|
|
/**
|
|
* Returns the date at which certificates must be valid, or <code>null</code>
|
|
* if this criterion was not set.
|
|
*
|
|
* @return The target certificate valitity date.
|
|
*/
|
|
public Date getCertificateValid()
|
|
{
|
|
if (certValid != null)
|
|
return (Date) certValid.clone();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the set of extended key purpose IDs, as an unmodifiable set
|
|
* of OID strings. Returns <code>null</code> if this criterion is not
|
|
* set.
|
|
*
|
|
* @return The set of key purpose OIDs (strings).
|
|
*/
|
|
public Set<String> getExtendedKeyUsage()
|
|
{
|
|
if (keyPurposeSet != null)
|
|
return Collections.unmodifiableSet(keyPurposeSet);
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the issuer criterion as a sequence of DER bytes, or
|
|
* <code>null</code> if this value was not set.
|
|
*
|
|
* @return The issuer.
|
|
*/
|
|
public byte[] getIssuerAsBytes() throws IOException
|
|
{
|
|
if (issuer != null)
|
|
return issuer.getEncoded();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the issuer criterion as a string, or <code>null</code> if this
|
|
* value was not set.
|
|
*
|
|
* @return The issuer.
|
|
*/
|
|
public String getIssuerAsString()
|
|
{
|
|
if (issuer != null)
|
|
return issuer.getName();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the public key usage criterion, or <code>null</code> if this
|
|
* value is not set. Note that the array is cloned to prevent modification.
|
|
*
|
|
* @return The public key usage.
|
|
*/
|
|
public boolean[] getKeyUsage()
|
|
{
|
|
if (keyUsage != null)
|
|
return (boolean[]) keyUsage.clone();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns whether or not all specified alternative names must match.
|
|
* If false, a certificate is considered a match if <em>one</em> of the
|
|
* specified alternative names matches.
|
|
*
|
|
* @return true if all names must match.
|
|
*/
|
|
public boolean getMatchAllSubjectAltNames()
|
|
{
|
|
return matchAllNames;
|
|
}
|
|
|
|
/**
|
|
* Returns the name constraints criterion, or <code>null</code> if this
|
|
* value is not set. Note that the byte array is cloned to prevent
|
|
* modification.
|
|
*
|
|
* @return The name constraints.
|
|
*/
|
|
public byte[] getNameConstraints()
|
|
{
|
|
if (nameConstraints != null)
|
|
return (byte[]) nameConstraints.clone();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
public Collection<List<?>> getPathToNames()
|
|
{
|
|
if (pathToNames != null)
|
|
{
|
|
List<List<?>> names = new ArrayList<List<?>>(pathToNames.size());
|
|
for (GeneralName name : pathToNames)
|
|
{
|
|
List<Object> n = new ArrayList<Object>(2);
|
|
n.add(name.kind().tag());
|
|
n.add(name.name());
|
|
names.add(n);
|
|
}
|
|
|
|
return names;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the certificate policy extension that will be matched by this
|
|
* selector, or null if the certificate policy will not be matched.
|
|
*
|
|
* @return The policy to be matched, or null.
|
|
*/
|
|
public Set<String> getPolicy()
|
|
{
|
|
Set<OID> p = this.policy;
|
|
if (p != null)
|
|
{
|
|
Set<String> strings = new HashSet<String>(p.size());
|
|
for (OID o : p)
|
|
{
|
|
strings.add(o.toString());
|
|
}
|
|
return strings;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* This method, and its related X.509 certificate extension — the
|
|
* private key usage period — is not supported under the Internet
|
|
* PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this
|
|
* method is not supported either.
|
|
*
|
|
* <p>Do not use this method. It is not deprecated, as it is not deprecated
|
|
* in the Java standard, but it is basically a no-operation and simply
|
|
* returns <code>null</code>.
|
|
*
|
|
* @return Null.
|
|
*/
|
|
public Date getPrivateKeyValid()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the serial number criterion, or <code>null</code> if this
|
|
* value was not set.
|
|
*
|
|
* @return The serial number.
|
|
*/
|
|
public BigInteger getSerialNumber()
|
|
{
|
|
return serialNo;
|
|
}
|
|
|
|
/**
|
|
* Get the subject alternative names criterion. The collection returned
|
|
* is a collection of pairs: the first element is an {@link Integer}
|
|
* containing the name type, and the second is a byte array containing
|
|
* the DER-encoded name bytes.
|
|
*
|
|
* @return The subject alternative names criterion. Returns null if this
|
|
* criterion is not set.
|
|
*/
|
|
public Collection<List<?>> getSubjectAlternativeNames()
|
|
{
|
|
if (altNames != null)
|
|
{
|
|
List<List<?>> names = new ArrayList<List<?>>(altNames.size());
|
|
for (GeneralName name : altNames)
|
|
{
|
|
List<Object> n = new ArrayList<Object>(2);
|
|
n.add(name.kind().tag());
|
|
n.add(name.name());
|
|
names.add(n);
|
|
}
|
|
return names;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the subject criterion as a sequence of DER bytes, or
|
|
* <code>null</code> if this value is not set.
|
|
*
|
|
* @return The subject.
|
|
*/
|
|
public byte[] getSubjectAsBytes() throws IOException
|
|
{
|
|
if (subject != null)
|
|
return subject.getEncoded();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the subject criterion as a string, of <code>null</code> if
|
|
* this value was not set.
|
|
*
|
|
* @return The subject.
|
|
*/
|
|
public String getSubjectAsString()
|
|
{
|
|
if (subject != null)
|
|
return subject.getName();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the subject key identifier criterion, or <code>null</code> if
|
|
* this value was not set. Note that the byte array is cloned to prevent
|
|
* modification.
|
|
*
|
|
* @return The subject key identifier.
|
|
*/
|
|
public byte[] getSubjectKeyIdentifier()
|
|
{
|
|
if (subjectKeyId != null)
|
|
return (byte[]) subjectKeyId.clone();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the subject public key criterion, or <code>null</code> if this
|
|
* value is not set.
|
|
*
|
|
* @return The subject public key.
|
|
*/
|
|
public PublicKey getSubjectPublicKey()
|
|
{
|
|
return subjectKey;
|
|
}
|
|
|
|
/**
|
|
* Returns the public key algorithm ID that matching certificates must have,
|
|
* or <code>null</code> if this criterion was not set.
|
|
*
|
|
* @return The public key algorithm ID.
|
|
*/
|
|
public String getSubjectPublicKeyAlgID()
|
|
{
|
|
return String.valueOf(sigId);
|
|
}
|
|
|
|
/**
|
|
* Match a certificate. This method will check the given certificate
|
|
* against all the enabled criteria of this selector, and will return
|
|
* <code>true</code> if the given certificate matches.
|
|
*
|
|
* @param certificate The certificate to check.
|
|
* @return true if the certificate matches all criteria.
|
|
*/
|
|
public boolean match(Certificate certificate)
|
|
{
|
|
if (!(certificate instanceof X509Certificate))
|
|
return false;
|
|
X509Certificate cert = (X509Certificate) certificate;
|
|
if (this.cert != null)
|
|
{
|
|
try
|
|
{
|
|
byte[] e1 = this.cert.getEncoded();
|
|
byte[] e2 = cert.getEncoded();
|
|
if (!Arrays.equals(e1, e2))
|
|
return false;
|
|
}
|
|
catch (CertificateEncodingException cee)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
if (serialNo != null)
|
|
{
|
|
if (!serialNo.equals(cert.getSerialNumber()))
|
|
return false;
|
|
}
|
|
if (certValid != null)
|
|
{
|
|
try
|
|
{
|
|
cert.checkValidity(certValid);
|
|
}
|
|
catch (CertificateException ce)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
if (issuer != null)
|
|
{
|
|
if (!issuer.equals(cert.getIssuerX500Principal()))
|
|
return false;
|
|
}
|
|
if (subject != null)
|
|
{
|
|
if (!subject.equals(cert.getSubjectX500Principal()))
|
|
return false;
|
|
}
|
|
if (sigId != null)
|
|
{
|
|
if (!sigId.toString().equals(cert.getSigAlgOID()))
|
|
return false;
|
|
}
|
|
if (subjectKeyId != null)
|
|
{
|
|
byte[] b = cert.getExtensionValue(SUBJECT_KEY_ID);
|
|
if (!Arrays.equals(b, subjectKeyId))
|
|
return false;
|
|
}
|
|
if (authKeyId != null)
|
|
{
|
|
byte[] b = cert.getExtensionValue(AUTH_KEY_ID);
|
|
if (!Arrays.equals(b, authKeyId))
|
|
return false;
|
|
}
|
|
if (keyUsage != null)
|
|
{
|
|
boolean[] b = cert.getKeyUsage();
|
|
if (!Arrays.equals(b, keyUsage))
|
|
return false;
|
|
}
|
|
if (basicConstraints >= 0)
|
|
{
|
|
if (cert.getBasicConstraints() != basicConstraints)
|
|
return false;
|
|
}
|
|
if (keyPurposeSet != null)
|
|
{
|
|
List kp = null;
|
|
try
|
|
{
|
|
kp = cert.getExtendedKeyUsage();
|
|
}
|
|
catch (CertificateParsingException cpe)
|
|
{
|
|
return false;
|
|
}
|
|
if (kp == null)
|
|
return false;
|
|
for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); )
|
|
{
|
|
if (!kp.contains(it.next()))
|
|
return false;
|
|
}
|
|
}
|
|
if (altNames != null)
|
|
{
|
|
Collection<List<?>> an = null;
|
|
try
|
|
{
|
|
an = cert.getSubjectAlternativeNames();
|
|
}
|
|
catch (CertificateParsingException cpe)
|
|
{
|
|
return false;
|
|
}
|
|
if (an == null)
|
|
return false;
|
|
int match = 0;
|
|
for (GeneralName name : altNames)
|
|
{
|
|
for (List<?> list : an)
|
|
{
|
|
try
|
|
{
|
|
Integer id = (Integer) list.get(0);
|
|
Object val = list.get(1);
|
|
GeneralName n = null;
|
|
if (val instanceof String)
|
|
n = makeName(id, (String) val);
|
|
else if (val instanceof byte[])
|
|
{
|
|
n = new GeneralName(GeneralName.Kind.forTag(id),
|
|
(byte[]) val);
|
|
}
|
|
else
|
|
continue;
|
|
if (name.equals(n))
|
|
match++;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
if (match == 0 || (matchAllNames && match < altNames.size()))
|
|
return false;
|
|
}
|
|
}
|
|
if (nameConstraints != null)
|
|
{
|
|
byte[] nc = cert.getExtensionValue(NAME_CONSTRAINTS_ID);
|
|
if (!Arrays.equals(nameConstraints, nc))
|
|
return false;
|
|
}
|
|
|
|
if (policy != null)
|
|
{
|
|
CertificatePolicies policies = null;
|
|
if (cert instanceof GnuPKIExtension)
|
|
{
|
|
policies = (CertificatePolicies)
|
|
((GnuPKIExtension) cert).getExtension(CertificatePolicies.ID).getValue();
|
|
}
|
|
else
|
|
{
|
|
byte[] policiesDer =
|
|
cert.getExtensionValue(CertificatePolicies.ID.toString());
|
|
try
|
|
{
|
|
policies = new CertificatePolicies(policiesDer);
|
|
}
|
|
catch (IOException ioe)
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
|
|
if (policies == null)
|
|
return false;
|
|
if (!policies.getPolicies().containsAll(policy))
|
|
return false;
|
|
}
|
|
|
|
if (pathToNames != null)
|
|
{
|
|
NameConstraints nc = null;
|
|
if (cert instanceof GnuPKIExtension)
|
|
{
|
|
Extension e =
|
|
((GnuPKIExtension) cert).getExtension(NameConstraints.ID);
|
|
if (e != null)
|
|
nc = (NameConstraints) e.getValue();
|
|
}
|
|
else
|
|
{
|
|
byte[] b = cert.getExtensionValue(NameConstraints.ID.toString());
|
|
if (b != null)
|
|
{
|
|
try
|
|
{
|
|
nc = new NameConstraints(b);
|
|
}
|
|
catch (IOException ioe)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
if (nc == null)
|
|
return false;
|
|
|
|
int match = 0;
|
|
for (GeneralName name : pathToNames)
|
|
{
|
|
for (GeneralSubtree subtree : nc.permittedSubtrees())
|
|
{
|
|
if (name.equals(subtree.base()))
|
|
match++;
|
|
}
|
|
}
|
|
if (match == 0 || (matchAllNames && match < pathToNames.size()))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Sets the authority key identifier criterion, or <code>null</code> to clear
|
|
* this criterion. Note that the byte array is cloned to prevent modification.
|
|
*
|
|
* @param authKeyId The authority key identifier.
|
|
*/
|
|
public void setAuthorityKeyIdentifier(byte[] authKeyId)
|
|
{
|
|
this.authKeyId = authKeyId != null ? (byte[]) authKeyId.clone() : null;
|
|
}
|
|
|
|
/**
|
|
* Sets the basic constraints criterion. Specify -1 to clear this parameter.
|
|
*
|
|
* @param basicConstraints The new basic constraints value.
|
|
*/
|
|
public void setBasicConstraints(int basicConstraints)
|
|
{
|
|
if (basicConstraints < -1)
|
|
basicConstraints = -1;
|
|
this.basicConstraints = basicConstraints;
|
|
}
|
|
|
|
/**
|
|
* Sets the certificate criterion. If set, only certificates that are
|
|
* equal to the certificate passed here will be accepted.
|
|
*
|
|
* @param cert The certificate.
|
|
*/
|
|
public void setCertificate(X509Certificate cert)
|
|
{
|
|
this.cert = cert;
|
|
}
|
|
|
|
/**
|
|
* Sets the date at which certificates must be valid. Specify
|
|
* <code>null</code> to clear this criterion.
|
|
*
|
|
* @param certValid The certificate validity date.
|
|
*/
|
|
public void setCertificateValid(Date certValid)
|
|
{
|
|
this.certValid = certValid != null ? (Date) certValid.clone() : null;
|
|
}
|
|
|
|
/**
|
|
* Sets the extended key usage criterion, as a set of OID strings. Specify
|
|
* <code>null</code> to clear this value.
|
|
*
|
|
* @param keyPurposeSet The set of key purpose OIDs.
|
|
* @throws IOException If any element of the set is not a valid OID string.
|
|
*/
|
|
public void setExtendedKeyUsage(Set<String> keyPurposeSet) throws IOException
|
|
{
|
|
if (keyPurposeSet == null)
|
|
{
|
|
this.keyPurposeSet = null;
|
|
return;
|
|
}
|
|
Set<String> s = new HashSet<String>();
|
|
for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); )
|
|
{
|
|
Object o = it.next();
|
|
if (!(o instanceof String))
|
|
throw new IOException("not a string: " + o);
|
|
try
|
|
{
|
|
OID oid = new OID((String) o);
|
|
int[] comp = oid.getIDs();
|
|
if (!checkOid(comp))
|
|
throw new IOException("malformed OID: " + o);
|
|
}
|
|
catch (IllegalArgumentException iae)
|
|
{
|
|
IOException ioe = new IOException("malformed OID: " + o);
|
|
ioe.initCause(iae);
|
|
throw ioe;
|
|
}
|
|
}
|
|
this.keyPurposeSet = s;
|
|
}
|
|
|
|
/**
|
|
* Sets the issuer, specified as the DER encoding of the issuer's
|
|
* distinguished name. Only certificates issued by this issuer will
|
|
* be accepted.
|
|
*
|
|
* @param name The DER encoding of the issuer's distinguished name.
|
|
* @throws IOException If the given name is incorrectly formatted.
|
|
*/
|
|
public void setIssuer(byte[] name) throws IOException
|
|
{
|
|
if (name != null)
|
|
{
|
|
try
|
|
{
|
|
issuer = new X500Principal(name);
|
|
}
|
|
catch (IllegalArgumentException iae)
|
|
{
|
|
throw new IOException(iae.getMessage());
|
|
}
|
|
}
|
|
else
|
|
issuer = null;
|
|
}
|
|
|
|
/**
|
|
* Sets the issuer, specified as a string representation of the issuer's
|
|
* distinguished name. Only certificates issued by this issuer will
|
|
* be accepted.
|
|
*
|
|
* @param name The string representation of the issuer's distinguished name.
|
|
* @throws IOException If the given name is incorrectly formatted.
|
|
*/
|
|
public void setIssuer(String name) throws IOException
|
|
{
|
|
if (name != null)
|
|
{
|
|
try
|
|
{
|
|
issuer = new X500Principal(name);
|
|
}
|
|
catch (IllegalArgumentException iae)
|
|
{
|
|
throw new IOException(iae.getMessage());
|
|
}
|
|
}
|
|
else
|
|
issuer = null;
|
|
}
|
|
|
|
/**
|
|
* Sets the public key usage criterion. Specify <code>null</code> to clear
|
|
* this value.
|
|
*
|
|
* @param keyUsage The public key usage.
|
|
*/
|
|
public void setKeyUsage(boolean[] keyUsage)
|
|
{
|
|
this.keyUsage = keyUsage != null ? (boolean[]) keyUsage.clone() : null;
|
|
}
|
|
|
|
/**
|
|
* Sets whether or not all subject alternative names must be matched.
|
|
* If false, then a certificate will be considered a match if one
|
|
* alternative name matches.
|
|
*
|
|
* @param matchAllNames Whether or not all alternative names must be
|
|
* matched.
|
|
*/
|
|
public void setMatchAllSubjectAltNames(boolean matchAllNames)
|
|
{
|
|
this.matchAllNames = matchAllNames;
|
|
}
|
|
|
|
/**
|
|
* Sets the name constraints criterion; specify <code>null</code> to
|
|
* clear this criterion. Note that if non-null, the argument will be
|
|
* cloned to prevent modification.
|
|
*
|
|
* @param nameConstraints The new name constraints.
|
|
* @throws IOException If the argument is not a valid DER-encoded
|
|
* name constraints.
|
|
*/
|
|
public void setNameConstraints(byte[] nameConstraints)
|
|
throws IOException
|
|
{
|
|
// Check if the input is well-formed...
|
|
new NameConstraints(nameConstraints);
|
|
|
|
// But we just compare raw byte arrays.
|
|
this.nameConstraints = nameConstraints != null
|
|
? (byte[]) nameConstraints.clone() : null;
|
|
}
|
|
|
|
/**
|
|
* Sets the pathToNames criterion. The argument is a collection of
|
|
* pairs, the first element of which is an {@link Integer} giving
|
|
* the ID of the name, and the second element is either a {@link String}
|
|
* or a byte array.
|
|
*
|
|
* See {@link #addPathToName(int, byte[])} and {@link #addPathToName(int, String)}
|
|
* for how these arguments are handled.
|
|
*
|
|
* @param names The names.
|
|
* @throws IOException If any argument is malformed.
|
|
*/
|
|
public void setPathToNames(Collection<List<?>> names) throws IOException
|
|
{
|
|
if (names == null || names.size() == 0)
|
|
{
|
|
pathToNames = null;
|
|
}
|
|
else
|
|
{
|
|
pathToNames = new ArrayList<GeneralName>(names.size());
|
|
for (List<?> name : names)
|
|
{
|
|
Integer id = (Integer) name.get(0);
|
|
Object name2 = name.get(1);
|
|
if (name2 instanceof String)
|
|
addPathToName(id, (String) name2);
|
|
else if (name2 instanceof byte[])
|
|
addPathToName(id, (byte[]) name2);
|
|
else
|
|
throw new IOException("invalid name type: "
|
|
+ name2.getClass().getName());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets the certificate policy to match, or null if this criterion should
|
|
* not be checked. Each element if the set must be a dotted-decimal form
|
|
* of certificate policy object identifier.
|
|
*
|
|
* @param policy The policy to match.
|
|
* @throws IOException If some element of the policy is not a valid
|
|
* policy extenison OID.
|
|
*/
|
|
public void setPolicy(Set<String> policy) throws IOException
|
|
{
|
|
if (policy != null)
|
|
{
|
|
HashSet<OID> p = new HashSet<OID>(policy.size());
|
|
for (String s : policy)
|
|
{
|
|
try
|
|
{
|
|
OID oid = new OID(s);
|
|
int[] i = oid.getIDs();
|
|
if (!checkOid(i))
|
|
throw new IOException("invalid OID");
|
|
p.add(oid);
|
|
}
|
|
catch (IOException ioe)
|
|
{
|
|
throw ioe;
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
IOException ioe = new IOException("invalid OID");
|
|
ioe.initCause(x);
|
|
throw ioe;
|
|
}
|
|
}
|
|
this.policy = p;
|
|
}
|
|
else
|
|
this.policy = null;
|
|
}
|
|
|
|
/**
|
|
* This method, and its related X.509 certificate extension — the
|
|
* private key usage period — is not supported under the Internet
|
|
* PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this
|
|
* method is not supported either.
|
|
*
|
|
* <p>Do not use this method. It is not deprecated, as it is not deprecated
|
|
* in the Java standard, but it is basically a no-operation.
|
|
*
|
|
* @param UNUSED Is silently ignored.
|
|
*/
|
|
public void setPrivateKeyValid(Date UNUSED)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Sets the serial number of the desired certificate. Only certificates that
|
|
* contain this serial number are accepted.
|
|
*
|
|
* @param serialNo The serial number.
|
|
*/
|
|
public void setSerialNumber(BigInteger serialNo)
|
|
{
|
|
this.serialNo = serialNo;
|
|
}
|
|
|
|
/**
|
|
* Sets the subject, specified as the DER encoding of the subject's
|
|
* distinguished name. Only certificates with the given subject will
|
|
* be accepted.
|
|
*
|
|
* @param name The DER encoding of the subject's distinguished name.
|
|
* @throws IOException If the given name is incorrectly formatted.
|
|
*/
|
|
public void setSubject(byte[] name) throws IOException
|
|
{
|
|
if (name != null)
|
|
{
|
|
try
|
|
{
|
|
subject = new X500Principal(name);
|
|
}
|
|
catch (IllegalArgumentException iae)
|
|
{
|
|
throw new IOException(iae.getMessage());
|
|
}
|
|
}
|
|
else
|
|
subject = null;
|
|
}
|
|
|
|
/**
|
|
* Sets the subject, specified as a string representation of the
|
|
* subject's distinguished name. Only certificates with the given
|
|
* subject will be accepted.
|
|
*
|
|
* @param name The string representation of the subject's distinguished name.
|
|
* @throws IOException If the given name is incorrectly formatted.
|
|
*/
|
|
public void setSubject(String name) throws IOException
|
|
{
|
|
if (name != null)
|
|
{
|
|
try
|
|
{
|
|
subject = new X500Principal(name);
|
|
}
|
|
catch (IllegalArgumentException iae)
|
|
{
|
|
throw new IOException(iae.getMessage());
|
|
}
|
|
}
|
|
else
|
|
subject = null;
|
|
}
|
|
|
|
/**
|
|
* Sets the subject alternative names critertion. Each element of the
|
|
* argument must be a {@link java.util.List} that contains exactly two
|
|
* elements: the first an {@link Integer}, representing the type of
|
|
* name, and the second either a {@link String} or a byte array,
|
|
* representing the name itself.
|
|
*
|
|
* @param altNames The alternative names.
|
|
* @throws IOException If any element of the argument is invalid.
|
|
*/
|
|
public void setSubjectAlternativeNames(Collection<List<?>> altNames)
|
|
throws IOException
|
|
{
|
|
if (altNames == null || altNames.isEmpty())
|
|
{
|
|
this.altNames = null;
|
|
return;
|
|
}
|
|
List<GeneralName> l = new ArrayList<GeneralName>(altNames.size());
|
|
for (List<?> list : altNames)
|
|
{
|
|
Integer id = (Integer) list.get(0);
|
|
Object value = list.get(1);
|
|
GeneralName name = null;
|
|
if (value instanceof String)
|
|
name = makeName(id, (String) value);
|
|
else if (value instanceof byte[])
|
|
name = new GeneralName(GeneralName.Kind.forTag(id), (byte[]) value);
|
|
else
|
|
throw new IOException("invalid name type: " + value.getClass().getName());
|
|
l.add(name);
|
|
}
|
|
this.altNames = l;
|
|
}
|
|
|
|
/**
|
|
* Sets the subject key identifier criterion, or <code>null</code> to clear
|
|
* this criterion. Note that the byte array is cloned to prevent modification.
|
|
*
|
|
* @param subjectKeyId The subject key identifier.
|
|
*/
|
|
public void setSubjectKeyIdentifier(byte[] subjectKeyId)
|
|
{
|
|
this.subjectKeyId = subjectKeyId != null ? (byte[]) subjectKeyId.clone() :
|
|
null;
|
|
}
|
|
|
|
/**
|
|
* Sets the subject public key criterion as a DER-encoded key. Specify
|
|
* <code>null</code> to clear this value.
|
|
*
|
|
* @param key The DER-encoded key bytes.
|
|
* @throws IOException If the argument is not a valid DER-encoded key.
|
|
*/
|
|
public void setSubjectPublicKey(byte[] key) throws IOException
|
|
{
|
|
if (key == null)
|
|
{
|
|
subjectKey = null;
|
|
subjectKeySpec = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
subjectKeySpec = new X509EncodedKeySpec(key);
|
|
KeyFactory enc = KeyFactory.getInstance("X.509");
|
|
subjectKey = enc.generatePublic(subjectKeySpec);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
subjectKey = null;
|
|
subjectKeySpec = null;
|
|
IOException ioe = new IOException(x.getMessage());
|
|
ioe.initCause(x);
|
|
throw ioe;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets the subject public key criterion as an opaque representation.
|
|
* Specify <code>null</code> to clear this criterion.
|
|
*
|
|
* @param key The public key.
|
|
*/
|
|
public void setSubjectPublicKey(PublicKey key)
|
|
{
|
|
this.subjectKey = key;
|
|
if (key == null)
|
|
{
|
|
subjectKeySpec = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
KeyFactory enc = KeyFactory.getInstance("X.509");
|
|
subjectKeySpec = (X509EncodedKeySpec)
|
|
enc.getKeySpec(key, X509EncodedKeySpec.class);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
subjectKey = null;
|
|
subjectKeySpec = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets the public key algorithm ID that matching certificates must have.
|
|
* Specify <code>null</code> to clear this criterion.
|
|
*
|
|
* @param sigId The public key ID.
|
|
* @throws IOException If the specified ID is not a valid object identifier.
|
|
*/
|
|
public void setSubjectPublicKeyAlgID(String sigId) throws IOException
|
|
{
|
|
if (sigId != null)
|
|
{
|
|
try
|
|
{
|
|
OID oid = new OID(sigId);
|
|
int[] comp = oid.getIDs();
|
|
if (!checkOid(comp))
|
|
throw new IOException("malformed OID: " + sigId);
|
|
this.sigId = oid;
|
|
}
|
|
catch (IllegalArgumentException iae)
|
|
{
|
|
IOException ioe = new IOException("malformed OID: " + sigId);
|
|
ioe.initCause(iae);
|
|
throw ioe;
|
|
}
|
|
}
|
|
else
|
|
this.sigId = null;
|
|
}
|
|
|
|
public String toString()
|
|
{
|
|
CPStringBuilder str = new CPStringBuilder(X509CertSelector.class.getName());
|
|
String nl = SystemProperties.getProperty("line.separator");
|
|
String eol = ";" + nl;
|
|
str.append(" {").append(nl);
|
|
if (cert != null)
|
|
str.append(" certificate = ").append(cert).append(eol);
|
|
if (basicConstraints >= 0)
|
|
str.append(" basic constraints = ").append(basicConstraints).append(eol);
|
|
if (serialNo != null)
|
|
str.append(" serial number = ").append(serialNo).append(eol);
|
|
if (certValid != null)
|
|
str.append(" valid date = ").append(certValid).append(eol);
|
|
if (issuer != null)
|
|
str.append(" issuer = ").append(issuer).append(eol);
|
|
if (subject != null)
|
|
str.append(" subject = ").append(subject).append(eol);
|
|
if (sigId != null)
|
|
str.append(" signature OID = ").append(sigId).append(eol);
|
|
if (subjectKey != null)
|
|
str.append(" subject public key = ").append(subjectKey).append(eol);
|
|
if (subjectKeyId != null)
|
|
{
|
|
str.append(" subject key ID = ");
|
|
for (int i = 0; i < subjectKeyId.length; i++)
|
|
{
|
|
str.append(Character.forDigit((subjectKeyId[i] & 0xF0) >>> 8, 16));
|
|
str.append(Character.forDigit((subjectKeyId[i] & 0x0F), 16));
|
|
if (i < subjectKeyId.length - 1)
|
|
str.append(':');
|
|
}
|
|
str.append(eol);
|
|
}
|
|
if (authKeyId != null)
|
|
{
|
|
str.append(" authority key ID = ");
|
|
for (int i = 0; i < authKeyId.length; i++)
|
|
{
|
|
str.append(Character.forDigit((authKeyId[i] & 0xF0) >>> 8, 16));
|
|
str.append(Character.forDigit((authKeyId[i] & 0x0F), 16));
|
|
if (i < authKeyId.length - 1)
|
|
str.append(':');
|
|
}
|
|
str.append(eol);
|
|
}
|
|
if (keyUsage != null)
|
|
{
|
|
str.append(" key usage = ");
|
|
for (int i = 0; i < keyUsage.length; i++)
|
|
str.append(keyUsage[i] ? '1' : '0');
|
|
str.append(eol);
|
|
}
|
|
if (keyPurposeSet != null)
|
|
str.append(" key purpose = ").append(keyPurposeSet).append(eol);
|
|
if (altNames != null)
|
|
str.append(" alternative names = ").append(altNames).append(eol);
|
|
if (nameConstraints != null)
|
|
str.append(" name constraints = <blob of data>").append(eol);
|
|
if (policy != null)
|
|
str.append(" policy = ").append(policy).append(eol);
|
|
if (pathToNames != null)
|
|
str.append(" pathToNames = ").append(pathToNames).append(eol);
|
|
str.append("}").append(nl);
|
|
return str.toString();
|
|
}
|
|
}
|