Merge
This commit is contained in:
commit
59b49d1f0e
@ -111,6 +111,7 @@ $(eval $(call SetupArchive,BUILD_LOCALEDATA_JAR, \
|
||||
# This value should exclude types destined for jars other than rt.jar and resources.jar.
|
||||
# When building a Profile this value augments the profile specific exclusions
|
||||
RT_JAR_EXCLUDES += \
|
||||
com/oracle/security/ucrypto \
|
||||
com/sun/codemodel \
|
||||
com/sun/crypto/provider \
|
||||
com/sun/istack/internal/tools \
|
||||
@ -476,7 +477,6 @@ TOOLS_JAR_INCLUDES := \
|
||||
com/sun/tools/doclint \
|
||||
com/sun/tools/example/debug/expr \
|
||||
com/sun/tools/example/debug/tty \
|
||||
com/sun/tools/extcheck \
|
||||
com/sun/tools/hat \
|
||||
com/sun/tools/internal/jxc \
|
||||
com/sun/tools/internal/jxc/ap \
|
||||
|
@ -169,27 +169,25 @@ endif
|
||||
##########################################################################################
|
||||
|
||||
ifeq ($(OPENJDK_TARGET_OS), solaris)
|
||||
ifndef OPENJDK
|
||||
|
||||
UCRYPTO_JAR_DST := $(JDK_OUTPUTDIR)/lib/ext/ucrypto.jar
|
||||
UCRYPTO_JAR_UNSIGNED := $(JDK_OUTPUTDIR)/jce/unsigned/ucrypto.jar
|
||||
UCRYPTO_JAR_DST := $(JDK_OUTPUTDIR)/lib/ext/ucrypto.jar
|
||||
UCRYPTO_JAR_UNSIGNED := $(JDK_OUTPUTDIR)/jce/unsigned/ucrypto.jar
|
||||
|
||||
$(eval $(call SetupArchive,BUILD_UCRYPTO_JAR, , \
|
||||
SRCS := $(JDK_OUTPUTDIR)/modules/jdk.crypto.ucrypto, \
|
||||
SUFFIXES := .class, \
|
||||
INCLUDES := com/oracle/security/ucrypto, \
|
||||
JAR := $(UCRYPTO_JAR_UNSIGNED), \
|
||||
MANIFEST := $(JCE_MANIFEST), \
|
||||
SKIP_METAINF := true))
|
||||
$(eval $(call SetupArchive,BUILD_UCRYPTO_JAR, , \
|
||||
SRCS := $(JDK_OUTPUTDIR)/modules/jdk.crypto.ucrypto, \
|
||||
SUFFIXES := .class, \
|
||||
INCLUDES := com/oracle/security/ucrypto, \
|
||||
JAR := $(UCRYPTO_JAR_UNSIGNED), \
|
||||
MANIFEST := $(JCE_MANIFEST), \
|
||||
SKIP_METAINF := true))
|
||||
|
||||
$(UCRYPTO_JAR_UNSIGNED): $(JCE_MANIFEST)
|
||||
$(UCRYPTO_JAR_UNSIGNED): $(JCE_MANIFEST)
|
||||
|
||||
$(UCRYPTO_JAR_DST): $(UCRYPTO_JAR_UNSIGNED)
|
||||
$(UCRYPTO_JAR_DST): $(UCRYPTO_JAR_UNSIGNED)
|
||||
$(install-file)
|
||||
|
||||
TARGETS += $(UCRYPTO_JAR_UNSIGNED) $(UCRYPTO_JAR_DST)
|
||||
TARGETS += $(UCRYPTO_JAR_UNSIGNED) $(UCRYPTO_JAR_DST)
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
all: $(TARGETS)
|
||||
|
@ -94,7 +94,6 @@ endef
|
||||
ifeq ($(PROFILE), )
|
||||
NOT_JRE_BIN_FILES := \
|
||||
appletviewer$(EXE_SUFFIX) \
|
||||
extcheck$(EXE_SUFFIX) \
|
||||
idlj$(EXE_SUFFIX) \
|
||||
jar$(EXE_SUFFIX) \
|
||||
jarsigner$(EXE_SUFFIX) \
|
||||
@ -326,7 +325,6 @@ ifneq ($(OPENJDK_TARGET_OS), windows)
|
||||
JDK_MAN_PAGES = \
|
||||
$(JRE_MAN_PAGES) \
|
||||
appletviewer.1 \
|
||||
extcheck.1 \
|
||||
idlj.1 \
|
||||
jar.1 \
|
||||
jarsigner.1 \
|
||||
|
@ -170,10 +170,7 @@ POLICY_SRC_LIST :=
|
||||
|
||||
ifeq ($(OPENJDK_TARGET_OS), windows)
|
||||
POLICY_SRC_LIST += $(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/conf/security/java.policy
|
||||
endif
|
||||
ifndef OPENJDK
|
||||
# if $(OPENJDK_TARGET_OS) is windows or solaris
|
||||
ifneq ($(findstring $(OPENJDK_TARGET_OS), windows solaris), )
|
||||
ifndef OPENJDK
|
||||
POLICY_SRC_LIST += $(JDK_TOPDIR)/src/closed/java.base/$(OPENJDK_TARGET_OS)/conf/security/java.policy
|
||||
endif
|
||||
endif
|
||||
|
@ -1,12 +1,12 @@
|
||||
#! /bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
@ -23,25 +23,27 @@
|
||||
# questions.
|
||||
#
|
||||
|
||||
if [ "x$TESTJAVA" = x ]; then
|
||||
TESTJAVA=$1; shift
|
||||
TESTCLASSES=.
|
||||
TESTSRC=.
|
||||
fi
|
||||
export TESTJAVA
|
||||
include CopyCommon.gmk
|
||||
|
||||
case "`uname`" in Windows*|CYGWIN* ) PS=';';; *) PS=':';; esac
|
||||
################################################################################
|
||||
|
||||
${TESTJAVA}/bin/javac -d ${TESTCLASSES} -classpath ${TESTJAVA}/lib/tools.jar${PS}${TESTCLASSES} ${TESTSRC}/TestExtcheckArgs.java
|
||||
rc=$?
|
||||
if [ $rc != 0 ]; then
|
||||
echo Compilation failure with exit status $rc
|
||||
exit $rc
|
||||
fi
|
||||
ifeq ($(OPENJDK_TARGET_OS), solaris)
|
||||
|
||||
UCRYPTO_CFG_SRC := $(JDK_TOPDIR)/src/jdk.crypto.ucrypto/solaris/conf/security/ucrypto-solaris.cfg
|
||||
UCRYPTO_CFG_DST := $(JDK_OUTPUTDIR)/lib/security/ucrypto-solaris.cfg
|
||||
|
||||
$(UCRYPTO_CFG_DST): $(UCRYPTO_CFG_SRC)
|
||||
$(call install-file)
|
||||
|
||||
SECURITY_UCRYPTO_CONF_FILES += $(UCRYPTO_CFG_DST)
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
||||
jdk.crypto.ucrypto: $(SECURITY_UCRYPTO_CONF_FILES)
|
||||
|
||||
all: jdk.crypto.ucrypto
|
||||
|
||||
.PHONY: all jdk.crypto.ucrypto
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} -classpath ${TESTJAVA}/lib/tools.jar${PS}${TESTCLASSES} TestExtcheckArgs
|
||||
rc=$?
|
||||
if [ $rc != 0 ]; then
|
||||
echo Execution failure with exit status $rc
|
||||
exit $rc
|
||||
fi
|
@ -25,9 +25,6 @@
|
||||
|
||||
include LauncherCommon.gmk
|
||||
|
||||
$(eval $(call SetupLauncher,extcheck, \
|
||||
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.extcheck.Main"$(COMMA) }'))
|
||||
|
||||
$(eval $(call SetupLauncher,jar, \
|
||||
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jar.Main"$(COMMA) }'))
|
||||
|
||||
|
@ -169,6 +169,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA, \
|
||||
-framework Foundation \
|
||||
-framework Security -framework SystemConfiguration, \
|
||||
LDFLAGS_SUFFIX_windows := -export:winFileHandleOpen -export:handleLseek \
|
||||
-export:getLastErrorString \
|
||||
jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \
|
||||
shell32.lib delayimp.lib -DELAYLOAD:shell32.dll \
|
||||
advapi32.lib, \
|
||||
|
62
jdk/make/lib/Lib-jdk.crypto.ucrypto.gmk
Normal file
62
jdk/make/lib/Lib-jdk.crypto.ucrypto.gmk
Normal file
@ -0,0 +1,62 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code 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
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
include $(SPEC)
|
||||
include $(JDK_TOPDIR)/make/lib/LibCommon.gmk
|
||||
|
||||
################################################################################
|
||||
|
||||
ifeq ($(OPENJDK_TARGET_OS), solaris)
|
||||
|
||||
LIBJ2UCRYPTO_SRC := $(JDK_TOPDIR)/src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto
|
||||
|
||||
$(eval $(call SetupNativeCompilation,BUILD_LIBJ2UCRYPTO, \
|
||||
LIBRARY := j2ucrypto, \
|
||||
OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
|
||||
SRC := $(LIBJ2UCRYPTO_SRC), \
|
||||
LANG := C, \
|
||||
OPTIMIZATION := LOW, \
|
||||
CFLAGS := $(CFLAGS_JDKLIB) \
|
||||
$(addprefix -I, $(LIBJ2UCRYPTO_SRC)), \
|
||||
MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libj2ucrypto/mapfile-vers, \
|
||||
LDFLAGS := $(LDFLAGS_JDKLIB), \
|
||||
LDFLAGS_SUFFIX := $(LIBDL), \
|
||||
LDFLAGS_SUFFIX_solaris := -lc, \
|
||||
OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libj2ucrypto, \
|
||||
DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))
|
||||
|
||||
$(BUILD_LIBJ2UCRYPTO): $(BUILD_LIBJAVA)
|
||||
|
||||
SECURITY_UCRYPTO_LIBRARIES += $(BUILD_LIBJ2UCRYPTO)
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
||||
jdk.crypto.ucrypto: $(SECURITY_UCRYPTO_LIBRARIES)
|
||||
|
||||
all: jdk.crypto.ucrypto
|
||||
|
||||
.PHONY: all jdk.crypto.ucrypto
|
@ -129,13 +129,11 @@ SUNWprivate_1.1 {
|
||||
Java_java_lang_ClassLoader_defineClass1;
|
||||
Java_java_lang_ClassLoader_defineClass2;
|
||||
Java_java_lang_ClassLoader_findLoadedClass0;
|
||||
Java_java_lang_ClassLoader_resolveClass0;
|
||||
Java_java_lang_ClassLoader_00024NativeLibrary_find;
|
||||
Java_java_lang_ClassLoader_00024NativeLibrary_load;
|
||||
Java_java_lang_ClassLoader_00024NativeLibrary_unload;
|
||||
Java_java_lang_ClassLoader_00024NativeLibrary_findBuiltinLib;
|
||||
Java_java_lang_ClassLoader_registerNatives;
|
||||
Java_java_lang_Compiler_registerNatives;
|
||||
Java_java_lang_Double_longBitsToDouble;
|
||||
Java_java_lang_Double_doubleToRawLongBits;
|
||||
Java_java_lang_reflect_Proxy_defineClass0;
|
||||
@ -196,8 +194,6 @@ SUNWprivate_1.1 {
|
||||
Java_java_lang_Runtime_gc;
|
||||
Java_java_lang_Runtime_runFinalization0;
|
||||
Java_java_lang_Runtime_totalMemory;
|
||||
Java_java_lang_Runtime_traceInstructions;
|
||||
Java_java_lang_Runtime_traceMethodCalls;
|
||||
Java_java_lang_Runtime_availableProcessors;
|
||||
Java_java_lang_SecurityManager_classDepth;
|
||||
Java_java_lang_SecurityManager_classLoaderDepth0;
|
||||
@ -280,6 +276,8 @@ SUNWprivate_1.1 {
|
||||
|
||||
# ZipFile.c needs this one
|
||||
throwFileNotFoundException;
|
||||
# zip_util.c needs this one
|
||||
getLastErrorString;
|
||||
|
||||
# Outcalls from libjvm done using dlsym().
|
||||
|
||||
|
@ -110,6 +110,8 @@ SUNWprivate_1.1 {
|
||||
NET_Bind;
|
||||
NET_MapSocketOption;
|
||||
NET_Wait;
|
||||
NET_EnableFastTcpLoopback;
|
||||
NET_ThrowNew;
|
||||
ipv6_available;
|
||||
initInetAddressIDs;
|
||||
|
||||
|
@ -1,91 +0,0 @@
|
||||
'\" t
|
||||
.\" Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
.\"
|
||||
.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
.\"
|
||||
.\" This code is free software; you can redistribute it and/or modify it
|
||||
.\" under the terms of the GNU General Public License version 2 only, as
|
||||
.\" published by the Free Software Foundation.
|
||||
.\"
|
||||
.\" This code 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
|
||||
.\" version 2 for more details (a copy is included in the LICENSE file that
|
||||
.\" accompanied this code).
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License version
|
||||
.\" 2 along with this work; if not, write to the Free Software Foundation,
|
||||
.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
.\"
|
||||
.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
.\" or visit www.oracle.com if you need additional information or have any
|
||||
.\" questions.
|
||||
.\"
|
||||
.\" Arch: generic
|
||||
.\" Software: JDK 8
|
||||
.\" Date: 21 November 2013
|
||||
.\" SectDesc: Basic Tools
|
||||
.\" Title: extcheck.1
|
||||
.\"
|
||||
.if n .pl 99999
|
||||
.TH extcheck 1 "21 November 2013" "JDK 8" "Basic Tools"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * Define some portability stuff
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.\" http://bugs.debian.org/507673
|
||||
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * set default formatting
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" disable hyphenation
|
||||
.nh
|
||||
.\" disable justification (adjust text to left margin only)
|
||||
.ad l
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * MAIN CONTENT STARTS HERE *
|
||||
.\" -----------------------------------------------------------------
|
||||
|
||||
.SH NAME
|
||||
extcheck \- Detects version conflicts between a target Java Archive (JAR) file and currently installed extension JAR files\&.
|
||||
.SH SYNOPSIS
|
||||
.sp
|
||||
.nf
|
||||
|
||||
\fBextcheck\fR [\fIoptions\fR] \fItargetfile\&.jar\fR
|
||||
.fi
|
||||
.sp
|
||||
.TP
|
||||
\fIoptions\fR
|
||||
The command-line options\&. See Options\&.
|
||||
.TP
|
||||
\fItargetfile\&.jar\fR
|
||||
The target JAR file against which the currently installed extension JAR files are compared to detect version conflicts\&.
|
||||
.SH DESCRIPTION
|
||||
The \f3extcheck\fR command checks a specified JAR file for title and version conflicts with any extensions installed in the Java SE SDK\&. Before installing an extension, you can use this utility to see whether the same or a more recent version of the extension is already installed\&.
|
||||
.PP
|
||||
The \f3extcheck\fR command compares the Specification-title and Specification-version headers in the manifest of the \f3targetfile\&.jar\fR file against the corresponding headers in all JAR files currently installed in the extension directory\&. By default, the extension directory is \f3jre/lib/ext\fR on Oracle Solaris and \f3\ejre\elib\eext\fR on Windows\&. The \f3extcheck\fR command compares version numbers in the same way as the \f3java\&.lang\&.Package\&.isCompatibleWith\fR method\&.
|
||||
.PP
|
||||
If no conflict is detected, then the return code is 0\&.
|
||||
.PP
|
||||
If the manifest of any JAR file in the extensions directory has the same \f3Specification-title\fR and the same or a newer \f3Specification-version\fR number, then a non-zero error code is returned\&. A non-zero error code is also returned when \f3targetfile\&.jar\fR does not have the \f3Specification-title\fR or \f3Specification-version\fR attributes in its manifest file\&.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
-verbose
|
||||
.br
|
||||
Lists JAR files in the extension directory as they are checked\&. Additionally, manifest attributes of the target JAR file and any conflicting JAR files are also reported\&.
|
||||
.TP
|
||||
-J\fIoption\fR
|
||||
.br
|
||||
Passes \fIoption\fR to the Java Virtual Machine (JVM), where option is one of the options described on the reference page for the Java launcher\&. For example, \f3-J-Xms48m\fR sets the startup memory to 48 MB\&. See java(1)\&.
|
||||
.SH SEE\ ALSO
|
||||
.TP 0.2i
|
||||
\(bu
|
||||
jar(1)
|
||||
.RE
|
||||
.br
|
||||
'pl 8.5i
|
||||
'bp
|
@ -1,24 +0,0 @@
|
||||
." Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
."
|
||||
." This code is free software; you can redistribute it and/or modify it
|
||||
." under the terms of the GNU General Public License version 2 only, as
|
||||
." published by the Free Software Foundation.
|
||||
."
|
||||
." This code 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
|
||||
." version 2 for more details (a copy is included in the LICENSE file that
|
||||
." accompanied this code).
|
||||
."
|
||||
." You should have received a copy of the GNU General Public License version
|
||||
." 2 along with this work; if not, write to the Free Software Foundation,
|
||||
." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
."
|
||||
." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
." or visit www.oracle.com if you need additional information or have any
|
||||
." questions.
|
||||
."
|
||||
.TH extcheck 1 "07 May 2011"
|
||||
|
||||
.LP
|
@ -70,7 +70,6 @@
|
||||
#define JVM_O_O_APPEND O_APPEND
|
||||
#define JVM_O_EXCL O_EXCL
|
||||
#define JVM_O_CREAT O_CREAT
|
||||
#define JVM_O_DELETE 0x10000
|
||||
|
||||
/* Signals */
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -956,11 +956,11 @@ public abstract class ClassLoader {
|
||||
* @see #defineClass(String, byte[], int, int)
|
||||
*/
|
||||
protected final void resolveClass(Class<?> c) {
|
||||
resolveClass0(c);
|
||||
if (c == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
private native void resolveClass0(Class<?> c);
|
||||
|
||||
/**
|
||||
* Finds a class with the specified <a href="#name">binary name</a>,
|
||||
* loading it if necessary.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -47,40 +47,6 @@ package java.lang;
|
||||
public final class Compiler {
|
||||
private Compiler() {} // don't make instances
|
||||
|
||||
private static native void initialize();
|
||||
|
||||
private static native void registerNatives();
|
||||
|
||||
static {
|
||||
registerNatives();
|
||||
java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
boolean loaded = false;
|
||||
String jit = System.getProperty("java.compiler");
|
||||
if ((jit != null) && (!jit.equals("NONE")) &&
|
||||
(!jit.equals("")))
|
||||
{
|
||||
try {
|
||||
System.loadLibrary(jit);
|
||||
initialize();
|
||||
loaded = true;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Warning: JIT compiler \"" +
|
||||
jit + "\" not found. Will use interpreter.");
|
||||
}
|
||||
}
|
||||
String info = System.getProperty("java.vm.info");
|
||||
if (loaded) {
|
||||
System.setProperty("java.vm.info", info + ", " + jit);
|
||||
} else {
|
||||
System.setProperty("java.vm.info", info + ", nojit");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the specified class.
|
||||
*
|
||||
@ -93,7 +59,9 @@ public final class Compiler {
|
||||
* @throws NullPointerException
|
||||
* If {@code clazz} is {@code null}
|
||||
*/
|
||||
public static native boolean compileClass(Class<?> clazz);
|
||||
public static boolean compileClass(Class<?> clazz) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles all classes whose name matches the specified string.
|
||||
@ -107,7 +75,9 @@ public final class Compiler {
|
||||
* @throws NullPointerException
|
||||
* If {@code string} is {@code null}
|
||||
*/
|
||||
public static native boolean compileClasses(String string);
|
||||
public static boolean compileClasses(String string) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Examines the argument type and its fields and perform some documented
|
||||
@ -122,15 +92,17 @@ public final class Compiler {
|
||||
* @throws NullPointerException
|
||||
* If {@code any} is {@code null}
|
||||
*/
|
||||
public static native Object command(Object any);
|
||||
public static Object command(Object any) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the Compiler to resume operation.
|
||||
*/
|
||||
public static native void enable();
|
||||
public static void enable() { }
|
||||
|
||||
/**
|
||||
* Cause the Compiler to cease operation.
|
||||
*/
|
||||
public static native void disable();
|
||||
public static void disable() { }
|
||||
}
|
||||
|
@ -730,7 +730,7 @@ public class Runtime {
|
||||
* @param on <code>true</code> to enable instruction tracing;
|
||||
* <code>false</code> to disable this feature.
|
||||
*/
|
||||
public native void traceInstructions(boolean on);
|
||||
public void traceInstructions(boolean on) { }
|
||||
|
||||
/**
|
||||
* Enables/Disables tracing of method calls.
|
||||
@ -748,7 +748,7 @@ public class Runtime {
|
||||
* @param on <code>true</code> to enable instruction tracing;
|
||||
* <code>false</code> to disable this feature.
|
||||
*/
|
||||
public native void traceMethodCalls(boolean on);
|
||||
public void traceMethodCalls(boolean on) { }
|
||||
|
||||
/**
|
||||
* Loads the native library specified by the filename argument. The filename
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
package java.security;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
@ -447,24 +448,37 @@ public class ProtectionDomain {
|
||||
/**
|
||||
* Used for storing ProtectionDomains as keys in a Map.
|
||||
*/
|
||||
final class Key {}
|
||||
final static class Key {}
|
||||
|
||||
// A cache of ProtectionDomains and their Permissions
|
||||
private static class PDCache implements ProtectionDomainCache {
|
||||
// We must wrap the PermissionCollection in a WeakReference as there
|
||||
// are some PermissionCollections which contain strong references
|
||||
// back to a ProtectionDomain and otherwise would never be removed
|
||||
// from the WeakHashMap
|
||||
private final Map<Key, WeakReference<PermissionCollection>>
|
||||
map = new WeakHashMap<>();
|
||||
|
||||
@Override
|
||||
public synchronized void put(ProtectionDomain pd,
|
||||
PermissionCollection pc) {
|
||||
map.put(pd == null ? null : pd.key, new WeakReference<>(pc));
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PermissionCollection get(ProtectionDomain pd) {
|
||||
WeakReference<PermissionCollection> ref =
|
||||
map.get(pd == null ? null : pd.key);
|
||||
return ref == null ? null : ref.get();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
SharedSecrets.setJavaSecurityProtectionDomainAccess(
|
||||
new JavaSecurityProtectionDomainAccess() {
|
||||
@Override
|
||||
public ProtectionDomainCache getProtectionDomainCache() {
|
||||
return new ProtectionDomainCache() {
|
||||
private final Map<Key, PermissionCollection> map =
|
||||
Collections.synchronizedMap
|
||||
(new WeakHashMap<Key, PermissionCollection>());
|
||||
public void put(ProtectionDomain pd,
|
||||
PermissionCollection pc) {
|
||||
map.put((pd == null ? null : pd.key), pc);
|
||||
}
|
||||
public PermissionCollection get(ProtectionDomain pd) {
|
||||
return pd == null ? map.get(null) : map.get(pd.key);
|
||||
}
|
||||
};
|
||||
return new PDCache();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1046,7 +1046,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
try {
|
||||
URI uri = ParseUtil.toURI(url);
|
||||
if (uri != null) {
|
||||
cachedResponse = cacheHandler.get(uri, getRequestMethod(), requests.getHeaders(EXCLUDE_HEADERS));
|
||||
cachedResponse = cacheHandler.get(uri, getRequestMethod(), getUserSetHeaders().getHeaders());
|
||||
if ("https".equalsIgnoreCase(uri.getScheme())
|
||||
&& !(cachedResponse instanceof SecureCacheResponse)) {
|
||||
cachedResponse = null;
|
||||
|
@ -50,30 +50,8 @@ public class Net {
|
||||
// set to true if exclusive binding is on for Windows
|
||||
private static final boolean exclusiveBind;
|
||||
|
||||
static {
|
||||
int availLevel = isExclusiveBindAvailable();
|
||||
if (availLevel >= 0) {
|
||||
String exclBindProp =
|
||||
java.security.AccessController.doPrivileged(
|
||||
new PrivilegedAction<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty(
|
||||
"sun.net.useExclusiveBind");
|
||||
}
|
||||
});
|
||||
if (exclBindProp != null) {
|
||||
exclusiveBind = exclBindProp.length() == 0 ?
|
||||
true : Boolean.parseBoolean(exclBindProp);
|
||||
} else if (availLevel == 1) {
|
||||
exclusiveBind = true;
|
||||
} else {
|
||||
exclusiveBind = false;
|
||||
}
|
||||
} else {
|
||||
exclusiveBind = false;
|
||||
}
|
||||
}
|
||||
// set to true if the fast tcp loopback should be enabled on Windows
|
||||
private static final boolean fastLoopback;
|
||||
|
||||
// -- Miscellaneous utilities --
|
||||
|
||||
@ -391,6 +369,23 @@ public class Net {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFastTcpLoopbackRequested() {
|
||||
String loopbackProp = java.security.AccessController.doPrivileged(
|
||||
new PrivilegedAction<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty("jdk.net.useFastTcpLoopback");
|
||||
}
|
||||
});
|
||||
boolean enable;
|
||||
if ("".equals(loopbackProp)) {
|
||||
enable = true;
|
||||
} else {
|
||||
enable = Boolean.parseBoolean(loopbackProp);
|
||||
}
|
||||
return enable;
|
||||
}
|
||||
|
||||
// -- Socket operations --
|
||||
|
||||
private static native boolean isIPv6Available0();
|
||||
@ -413,15 +408,16 @@ public class Net {
|
||||
throws IOException {
|
||||
boolean preferIPv6 = isIPv6Available() &&
|
||||
(family != StandardProtocolFamily.INET);
|
||||
return IOUtil.newFD(socket0(preferIPv6, stream, false));
|
||||
return IOUtil.newFD(socket0(preferIPv6, stream, false, fastLoopback));
|
||||
}
|
||||
|
||||
static FileDescriptor serverSocket(boolean stream) {
|
||||
return IOUtil.newFD(socket0(isIPv6Available(), stream, true));
|
||||
return IOUtil.newFD(socket0(isIPv6Available(), stream, true, fastLoopback));
|
||||
}
|
||||
|
||||
// Due to oddities SO_REUSEADDR on windows reuse is ignored
|
||||
private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse);
|
||||
private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse,
|
||||
boolean fastLoopback);
|
||||
|
||||
public static void bind(FileDescriptor fd, InetAddress addr, int port)
|
||||
throws IOException
|
||||
@ -634,4 +630,30 @@ public class Net {
|
||||
POLLCONN = pollconnValue();
|
||||
}
|
||||
|
||||
static {
|
||||
int availLevel = isExclusiveBindAvailable();
|
||||
if (availLevel >= 0) {
|
||||
String exclBindProp =
|
||||
java.security.AccessController.doPrivileged(
|
||||
new PrivilegedAction<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty(
|
||||
"sun.net.useExclusiveBind");
|
||||
}
|
||||
});
|
||||
if (exclBindProp != null) {
|
||||
exclusiveBind = exclBindProp.length() == 0 ?
|
||||
true : Boolean.parseBoolean(exclBindProp);
|
||||
} else if (availLevel == 1) {
|
||||
exclusiveBind = true;
|
||||
} else {
|
||||
exclusiveBind = false;
|
||||
}
|
||||
} else {
|
||||
exclusiveBind = false;
|
||||
}
|
||||
|
||||
fastLoopback = isFastTcpLoopbackRequested();
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,18 @@ grant codeBase "file:${java.home}/lib/ext/nashorn.jar" {
|
||||
permission java.security.AllPermission;
|
||||
};
|
||||
|
||||
grant codeBase "file:${java.home}/lib/ext/ucrypto.jar" {
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.security.*";
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
|
||||
permission java.lang.RuntimePermission "loadLibrary.j2ucrypto";
|
||||
// need "com.oracle.security.ucrypto.debug" for debugging
|
||||
permission java.util.PropertyPermission "*", "read";
|
||||
permission java.security.SecurityPermission "putProviderProperty.OracleUcrypto";
|
||||
permission java.security.SecurityPermission "clearProviderProperties.OracleUcrypto";
|
||||
permission java.security.SecurityPermission "removeProviderProperty.OracleUcrypto";
|
||||
permission java.io.FilePermission "${java.home}/lib/security/ucrypto-solaris.cfg", "read";
|
||||
};
|
||||
|
||||
grant codeBase "file:${java.home}/lib/ext/sunec.jar" {
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.security.*";
|
||||
permission java.lang.RuntimePermission "loadLibrary.sunec";
|
||||
|
@ -111,18 +111,10 @@ JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
|
||||
JNIEXPORT jobject JNICALL
|
||||
JVM_InitProperties(JNIEnv *env, jobject p);
|
||||
|
||||
/*
|
||||
* java.io.File
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_OnExit(void (*func)(void));
|
||||
|
||||
/*
|
||||
* java.lang.Runtime
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_Exit(jint code);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_Halt(jint code);
|
||||
|
||||
@ -146,12 +138,6 @@ JVM_GC(void);
|
||||
JNIEXPORT jlong JNICALL
|
||||
JVM_MaxObjectInspectionAge(void);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_TraceInstructions(jboolean on);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_TraceMethodCalls(jboolean on);
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
JVM_TotalMemory(void);
|
||||
|
||||
@ -176,12 +162,6 @@ JVM_FindLibraryEntry(void *handle, const char *name);
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JVM_IsSupportedJNIVersion(jint version);
|
||||
|
||||
/*
|
||||
* java.lang.Float and java.lang.Double
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JVM_IsNaN(jdouble d);
|
||||
|
||||
/*
|
||||
* java.lang.Throwable
|
||||
*/
|
||||
@ -194,30 +174,6 @@ JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable);
|
||||
JNIEXPORT jobject JNICALL
|
||||
JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index);
|
||||
|
||||
/*
|
||||
* java.lang.Compiler
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_InitializeCompiler (JNIEnv *env, jclass compCls);
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JVM_IsSilentCompiler(JNIEnv *env, jclass compCls);
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls);
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname);
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_EnableCompiler(JNIEnv *env, jclass compCls);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_DisableCompiler(JNIEnv *env, jclass compCls);
|
||||
|
||||
/*
|
||||
* java.lang.Thread
|
||||
*/
|
||||
@ -304,24 +260,8 @@ JVM_GetSystemPackages(JNIEnv *env);
|
||||
* java.io.ObjectInputStream
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL
|
||||
JVM_AllocateNewObject(JNIEnv *env, jobject obj, jclass currClass,
|
||||
jclass initClass);
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass,
|
||||
jint length);
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
JVM_LatestUserDefinedLoader(JNIEnv *env);
|
||||
|
||||
/*
|
||||
* This function has been deprecated and should not be considered
|
||||
* part of the specified JVM interface.
|
||||
*/
|
||||
JNIEXPORT jclass JNICALL
|
||||
JVM_LoadClass0(JNIEnv *env, jobject obj, jclass currClass,
|
||||
jstring currClassName);
|
||||
|
||||
/*
|
||||
* java.lang.reflect.Array
|
||||
*/
|
||||
@ -373,11 +313,6 @@ JVM_GetCallerClass(JNIEnv *env, int depth);
|
||||
JNIEXPORT jclass JNICALL
|
||||
JVM_FindPrimitiveClass(JNIEnv *env, const char *utf);
|
||||
|
||||
/*
|
||||
* Link the class
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_ResolveClass(JNIEnv *env, jclass cls);
|
||||
|
||||
/*
|
||||
* Find a class from a boot class loader. Returns NULL if class not found.
|
||||
@ -1101,43 +1036,6 @@ typedef int (*canonicalize_fn_t)(JNIEnv *env, char *orig, char *out, int len);
|
||||
PART 3: I/O and Network Support
|
||||
************************************************************************/
|
||||
|
||||
/* Note that the JVM IO functions are expected to return JVM_IO_ERR
|
||||
* when there is any kind of error. The caller can then use the
|
||||
* platform specific support (e.g., errno) to get the detailed
|
||||
* error info. The JVM_GetLastErrorString procedure may also be used
|
||||
* to obtain a descriptive error string.
|
||||
*/
|
||||
#define JVM_IO_ERR (-1)
|
||||
|
||||
/* For interruptible IO. Returning JVM_IO_INTR indicates that an IO
|
||||
* operation has been disrupted by Thread.interrupt. There are a
|
||||
* number of technical difficulties related to interruptible IO that
|
||||
* need to be solved. For example, most existing programs do not handle
|
||||
* InterruptedIOExceptions specially, they simply treat those as any
|
||||
* IOExceptions, which typically indicate fatal errors.
|
||||
*
|
||||
* There are also two modes of operation for interruptible IO. In the
|
||||
* resumption mode, an interrupted IO operation is guaranteed not to
|
||||
* have any side-effects, and can be restarted. In the termination mode,
|
||||
* an interrupted IO operation corrupts the underlying IO stream, so
|
||||
* that the only reasonable operation on an interrupted stream is to
|
||||
* close that stream. The resumption mode seems to be impossible to
|
||||
* implement on Win32 and Solaris. Implementing the termination mode is
|
||||
* easier, but it's not clear that's the right semantics.
|
||||
*
|
||||
* Interruptible IO is not supported on Win32.It can be enabled/disabled
|
||||
* using a compile-time flag on Solaris. Third-party JVM ports do not
|
||||
* need to implement interruptible IO.
|
||||
*/
|
||||
#define JVM_IO_INTR (-2)
|
||||
|
||||
/* Write a string into the given buffer, in the platform's local encoding,
|
||||
* that describes the most recent system-level error to occur in this thread.
|
||||
* Return the length of the string or zero if no error occurred.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_GetLastErrorString(char *buf, int len);
|
||||
|
||||
/*
|
||||
* Convert a pathname into native format. This function does syntactic
|
||||
* cleanup, such as removing redundant separator characters. It modifies
|
||||
@ -1146,150 +1044,6 @@ JVM_GetLastErrorString(char *buf, int len);
|
||||
JNIEXPORT char * JNICALL
|
||||
JVM_NativePath(char *);
|
||||
|
||||
/*
|
||||
* JVM I/O error codes
|
||||
*/
|
||||
#define JVM_EEXIST -100
|
||||
|
||||
/*
|
||||
* Open a file descriptor. This function returns a negative error code
|
||||
* on error, and a non-negative integer that is the file descriptor on
|
||||
* success.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Open(const char *fname, jint flags, jint mode);
|
||||
|
||||
/*
|
||||
* Close a file descriptor. This function returns -1 on error, and 0
|
||||
* on success.
|
||||
*
|
||||
* fd the file descriptor to close.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Close(jint fd);
|
||||
|
||||
/*
|
||||
* Read data from a file decriptor into a char array.
|
||||
*
|
||||
* fd the file descriptor to read from.
|
||||
* buf the buffer where to put the read data.
|
||||
* nbytes the number of bytes to read.
|
||||
*
|
||||
* This function returns -1 on error, and 0 on success.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Read(jint fd, char *buf, jint nbytes);
|
||||
|
||||
/*
|
||||
* Write data from a char array to a file decriptor.
|
||||
*
|
||||
* fd the file descriptor to read from.
|
||||
* buf the buffer from which to fetch the data.
|
||||
* nbytes the number of bytes to write.
|
||||
*
|
||||
* This function returns -1 on error, and 0 on success.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Write(jint fd, char *buf, jint nbytes);
|
||||
|
||||
/*
|
||||
* Returns the number of bytes available for reading from a given file
|
||||
* descriptor
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Available(jint fd, jlong *pbytes);
|
||||
|
||||
/*
|
||||
* Move the file descriptor pointer from whence by offset.
|
||||
*
|
||||
* fd the file descriptor to move.
|
||||
* offset the number of bytes to move it by.
|
||||
* whence the start from where to move it.
|
||||
*
|
||||
* This function returns the resulting pointer location.
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
JVM_Lseek(jint fd, jlong offset, jint whence);
|
||||
|
||||
/*
|
||||
* Set the length of the file associated with the given descriptor to the given
|
||||
* length. If the new length is longer than the current length then the file
|
||||
* is extended; the contents of the extended portion are not defined. The
|
||||
* value of the file pointer is undefined after this procedure returns.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_SetLength(jint fd, jlong length);
|
||||
|
||||
/*
|
||||
* Synchronize the file descriptor's in memory state with that of the
|
||||
* physical device. Return of -1 is an error, 0 is OK.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Sync(jint fd);
|
||||
|
||||
/*
|
||||
* Networking library support
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_InitializeSocketLibrary(void);
|
||||
|
||||
struct sockaddr;
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Socket(jint domain, jint type, jint protocol);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_SocketClose(jint fd);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_SocketShutdown(jint fd, jint howto);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Recv(jint fd, char *buf, jint nBytes, jint flags);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Send(jint fd, char *buf, jint nBytes, jint flags);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Timeout(int fd, long timeout);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Listen(jint fd, jint count);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Connect(jint fd, struct sockaddr *him, jint len);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Bind(jint fd, struct sockaddr *him, jint len);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_Accept(jint fd, struct sockaddr *him, jint *len);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_RecvFrom(jint fd, char *buf, int nBytes,
|
||||
int flags, struct sockaddr *from, int *fromlen);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_SendTo(jint fd, char *buf, int len,
|
||||
int flags, struct sockaddr *to, int tolen);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_SocketAvailable(jint fd, jint *result);
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_GetSockName(jint fd, struct sockaddr *him, int *len);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen);
|
||||
|
||||
JNIEXPORT int JNICALL
|
||||
JVM_GetHostName(char* name, int namelen);
|
||||
|
||||
/*
|
||||
* The standard printing functions supported by the Java VM. (Should they
|
||||
* be renamed to JVM_* in the future?
|
||||
@ -1355,39 +1109,6 @@ JVM_GetTemporaryDirectory(JNIEnv *env);
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass);
|
||||
|
||||
/*
|
||||
* Java thread state support
|
||||
*/
|
||||
enum {
|
||||
JAVA_THREAD_STATE_NEW = 0,
|
||||
JAVA_THREAD_STATE_RUNNABLE = 1,
|
||||
JAVA_THREAD_STATE_BLOCKED = 2,
|
||||
JAVA_THREAD_STATE_WAITING = 3,
|
||||
JAVA_THREAD_STATE_TIMED_WAITING = 4,
|
||||
JAVA_THREAD_STATE_TERMINATED = 5,
|
||||
JAVA_THREAD_STATE_COUNT = 6
|
||||
};
|
||||
|
||||
/*
|
||||
* Returns an array of the threadStatus values representing the
|
||||
* given Java thread state. Returns NULL if the VM version is
|
||||
* incompatible with the JDK or doesn't support the given
|
||||
* Java thread state.
|
||||
*/
|
||||
JNIEXPORT jintArray JNICALL
|
||||
JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState);
|
||||
|
||||
/*
|
||||
* Returns an array of the substate names representing the
|
||||
* given Java thread state. Returns NULL if the VM version is
|
||||
* incompatible with the JDK or the VM doesn't support
|
||||
* the given Java thread state.
|
||||
* values must be the jintArray returned from JVM_GetThreadStateValues
|
||||
* and javaThreadState.
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values);
|
||||
|
||||
/* =========================================================================
|
||||
* The following defines a private JVM interface that the JDK can query
|
||||
* for the JVM version and capabilities. sun.misc.Version defines
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -224,18 +224,6 @@ Java_java_lang_ClassLoader_defineClass2(JNIEnv *env,
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_lang_ClassLoader_resolveClass0(JNIEnv *env, jobject this,
|
||||
jclass cls)
|
||||
{
|
||||
if (cls == NULL) {
|
||||
JNU_ThrowNullPointerException(env, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
JVM_ResolveClass(env, cls);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns NULL if class not found.
|
||||
*/
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni.h"
|
||||
#include "java_lang_Compiler.h"
|
||||
|
||||
static JNINativeMethod methods[] = {
|
||||
{"compileClass",
|
||||
"(Ljava/lang/Class;)Z",
|
||||
(void *)&JVM_CompileClass},
|
||||
{"compileClasses",
|
||||
"(Ljava/lang/String;)Z",
|
||||
(void *)&JVM_CompileClasses},
|
||||
{"command",
|
||||
"(Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
(void *)&JVM_CompilerCommand},
|
||||
{"enable",
|
||||
"()V",
|
||||
(void *)&JVM_EnableCompiler},
|
||||
{"disable",
|
||||
"()V",
|
||||
(void *)&JVM_DisableCompiler}
|
||||
};
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_lang_Compiler_registerNatives(JNIEnv *env, jclass compCls)
|
||||
{
|
||||
(*env)->RegisterNatives(env, compCls, methods,
|
||||
sizeof methods / sizeof methods[0]);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -65,18 +65,6 @@ Java_java_lang_Runtime_gc(JNIEnv *env, jobject this)
|
||||
JVM_GC();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_lang_Runtime_traceInstructions(JNIEnv *env, jobject this, jboolean on)
|
||||
{
|
||||
JVM_TraceInstructions(on);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_lang_Runtime_traceMethodCalls(JNIEnv *env, jobject this, jboolean on)
|
||||
{
|
||||
JVM_TraceMethodCalls(on);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_lang_Runtime_runFinalization0(JNIEnv *env, jobject this)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,7 +54,6 @@ void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
|
||||
jint len, jboolean append, jfieldID fid);
|
||||
void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
|
||||
void throwFileNotFoundException(JNIEnv *env, jstring path);
|
||||
size_t getLastErrorString(char *buf, size_t len);
|
||||
|
||||
/*
|
||||
* Macros for managing platform strings. The typical usage pattern is:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -157,7 +157,7 @@ JNU_ThrowByNameWithLastError(JNIEnv *env, const char *name,
|
||||
const char *defaultDetail)
|
||||
{
|
||||
char buf[256];
|
||||
int n = JVM_GetLastErrorString(buf, sizeof(buf));
|
||||
int n = getLastErrorString(buf, sizeof(buf));
|
||||
|
||||
if (n > 0) {
|
||||
jstring s = JNU_NewStringPlatform(env, buf);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -387,6 +387,7 @@ void* getProcessHandle();
|
||||
void buildJniFunctionName(const char *sym, const char *cname,
|
||||
char *jniEntryName);
|
||||
|
||||
extern size_t getLastErrorString(char *buf, size_t len);
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
@ -184,9 +184,13 @@ NET_MapSocketOption(jint cmd, int *level, int *optname);
|
||||
JNIEXPORT int JNICALL
|
||||
NET_MapSocketOptionV6(jint cmd, int *level, int *optname);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_EnableFastTcpLoopback(int fd);
|
||||
|
||||
int getScopeID (struct sockaddr *);
|
||||
|
||||
int cmpScopeID (unsigned int, struct sockaddr *);
|
||||
|
||||
unsigned short in_cksum(unsigned short *addr, int len);
|
||||
|
||||
#endif /* NET_UTILS_H */
|
||||
|
@ -93,24 +93,27 @@ Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
|
||||
jzfile *zip = 0;
|
||||
|
||||
if (mode & OPEN_READ) flag |= O_RDONLY;
|
||||
if (mode & OPEN_DELETE) flag |= JVM_O_DELETE;
|
||||
|
||||
if (path != 0) {
|
||||
zip = ZIP_Get_From_Cache(path, &msg, lastModified);
|
||||
if (zip == 0 && msg == 0) {
|
||||
ZFILE zfd = 0;
|
||||
#ifdef WIN32
|
||||
if (mode & OPEN_DELETE) flag |= O_TEMPORARY;
|
||||
zfd = winFileHandleOpen(env, name, flag);
|
||||
if (zfd == -1) {
|
||||
/* Exception already pending. */
|
||||
goto finally;
|
||||
}
|
||||
#else
|
||||
zfd = JVM_Open(path, flag, 0);
|
||||
zfd = open(path, flag, 0);
|
||||
if (zfd < 0) {
|
||||
throwFileNotFoundException(env, name);
|
||||
goto finally;
|
||||
}
|
||||
if (mode & OPEN_DELETE) {
|
||||
unlink(path);
|
||||
}
|
||||
#endif
|
||||
zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -123,7 +123,7 @@ ZFILE_Open(const char *fname, int flags) {
|
||||
flagsAndAttributes, /* flags and attributes */
|
||||
NULL);
|
||||
#else
|
||||
return JVM_Open(fname, flags, 0);
|
||||
return open(fname, flags, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ ZFILE_Close(ZFILE zfd) {
|
||||
#ifdef WIN32
|
||||
CloseHandle((HANDLE) zfd);
|
||||
#else
|
||||
JVM_Close(zfd);
|
||||
close(zfd);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -145,14 +145,6 @@ ZFILE_read(ZFILE zfd, char *buf, jint nbytes) {
|
||||
#ifdef WIN32
|
||||
return (int) IO_Read(zfd, buf, nbytes);
|
||||
#else
|
||||
/*
|
||||
* Calling JVM_Read will return JVM_IO_INTR when Thread.interrupt is called
|
||||
* only on Solaris. Continue reading jar file in this case is the best
|
||||
* thing to do since zip file reading is relatively fast and it is very onerous
|
||||
* for a interrupted thread to deal with this kind of hidden I/O. However, handling
|
||||
* JVM_IO_INTR is tricky and could cause undesired side effect. So we decided
|
||||
* to simply call "read" on Solaris/Linux. See details in bug 6304463.
|
||||
*/
|
||||
return read(zfd, buf, nbytes);
|
||||
#endif
|
||||
}
|
||||
@ -198,9 +190,8 @@ readFully(ZFILE zfd, void *buf, jlong len) {
|
||||
if (n > 0) {
|
||||
bp += n;
|
||||
len -= n;
|
||||
} else if (n == JVM_IO_ERR && errno == EINTR) {
|
||||
/* Retry after EINTR (interrupted by signal).
|
||||
We depend on the fact that JVM_IO_ERR == -1. */
|
||||
} else if (n == -1 && errno == EINTR) {
|
||||
/* Retry after EINTR (interrupted by signal). */
|
||||
continue;
|
||||
} else { /* EOF or IO error */
|
||||
return -1;
|
||||
@ -828,7 +819,7 @@ ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified,
|
||||
zip->lastModified = lastModified;
|
||||
|
||||
if (zfd == -1) {
|
||||
if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0)
|
||||
if (pmsg && getLastErrorString(errbuf, sizeof(errbuf)) > 0)
|
||||
*pmsg = strdup(errbuf);
|
||||
freeZip(zip);
|
||||
return NULL;
|
||||
@ -849,7 +840,7 @@ ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified,
|
||||
*pmsg = strdup("zip file is empty");
|
||||
}
|
||||
} else { /* error */
|
||||
if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0)
|
||||
if (pmsg && getLastErrorString(errbuf, sizeof(errbuf)) > 0)
|
||||
*pmsg = strdup(errbuf);
|
||||
}
|
||||
ZFILE_Close(zfd);
|
||||
|
@ -75,7 +75,6 @@
|
||||
#define JVM_O_O_APPEND O_APPEND
|
||||
#define JVM_O_EXCL O_EXCL
|
||||
#define JVM_O_CREAT O_CREAT
|
||||
#define JVM_O_DELETE 0x10000
|
||||
|
||||
/* Signals */
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -211,18 +211,3 @@ handleSetLength(FD fd, jlong length)
|
||||
RESTARTABLE(ftruncate64(fd, length), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t
|
||||
getLastErrorString(char *buf, size_t len)
|
||||
{
|
||||
if (errno == 0 || len < 1) return 0;
|
||||
|
||||
const char *err = strerror(errno);
|
||||
size_t n = strlen(err);
|
||||
if (n >= len)
|
||||
n = len - 1;
|
||||
|
||||
strncpy(buf, err, n);
|
||||
buf[n] = '\0';
|
||||
return n;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,6 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jni.h"
|
||||
@ -51,3 +52,17 @@ void buildJniFunctionName(const char *sym, const char *cname,
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
getLastErrorString(char *buf, size_t len)
|
||||
{
|
||||
if (errno == 0 || len < 1) return 0;
|
||||
|
||||
const char *err = strerror(errno);
|
||||
size_t n = strlen(err);
|
||||
if (n >= len)
|
||||
n = len - 1;
|
||||
|
||||
strncpy(buf, err, n);
|
||||
buf[n] = '\0';
|
||||
return n;
|
||||
}
|
||||
|
@ -790,6 +790,11 @@ void parseExclusiveBindProperty(JNIEnv *env) {
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_EnableFastTcpLoopback(int fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* In the case of an IPv4 Inetaddress this method will return an
|
||||
* IPv4 mapped address where IPv6 is available and v4MappedAddress is TRUE.
|
||||
* Otherwise it will return a sockaddr_in structure for an IPv4 InetAddress.
|
||||
|
@ -188,7 +188,7 @@ Java_sun_nio_ch_Net_canJoin6WithIPv4Group0(JNIEnv* env, jclass cl)
|
||||
|
||||
JNIEXPORT int JNICALL
|
||||
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
|
||||
jboolean stream, jboolean reuse)
|
||||
jboolean stream, jboolean reuse, jboolean ignored)
|
||||
{
|
||||
int fd;
|
||||
int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
|
||||
|
@ -97,7 +97,6 @@ JVM_GetHostByName(char* name);
|
||||
#define JVM_O_O_APPEND O_APPEND
|
||||
#define JVM_O_EXCL O_EXCL
|
||||
#define JVM_O_CREAT O_CREAT
|
||||
#define JVM_O_DELETE O_TEMPORARY
|
||||
|
||||
/* Signals */
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -576,77 +576,3 @@ handleLseek(FD fd, jlong offset, jint whence)
|
||||
}
|
||||
return long_to_jlong(pos.QuadPart);
|
||||
}
|
||||
|
||||
size_t
|
||||
getLastErrorString(char *utf8_jvmErrorMsg, size_t cbErrorMsg)
|
||||
{
|
||||
size_t n = 0;
|
||||
if (cbErrorMsg > 0) {
|
||||
BOOLEAN noError = FALSE;
|
||||
WCHAR *utf16_osErrorMsg = (WCHAR *)malloc(cbErrorMsg*sizeof(WCHAR));
|
||||
if (utf16_osErrorMsg == NULL) {
|
||||
// OOM accident
|
||||
strncpy(utf8_jvmErrorMsg, "Out of memory", cbErrorMsg);
|
||||
// truncate if too long
|
||||
utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0';
|
||||
n = strlen(utf8_jvmErrorMsg);
|
||||
} else {
|
||||
DWORD errval = GetLastError();
|
||||
if (errval != 0) {
|
||||
// WIN32 error
|
||||
n = (size_t)FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
errval,
|
||||
0,
|
||||
utf16_osErrorMsg,
|
||||
(DWORD)cbErrorMsg,
|
||||
NULL);
|
||||
if (n > 3) {
|
||||
// Drop final '.', CR, LF
|
||||
if (utf16_osErrorMsg[n - 1] == L'\n') --n;
|
||||
if (utf16_osErrorMsg[n - 1] == L'\r') --n;
|
||||
if (utf16_osErrorMsg[n - 1] == L'.') --n;
|
||||
utf16_osErrorMsg[n] = L'\0';
|
||||
}
|
||||
} else if (errno != 0) {
|
||||
// C runtime error that has no corresponding WIN32 error code
|
||||
const WCHAR *rtError = _wcserror(errno);
|
||||
if (rtError != NULL) {
|
||||
wcsncpy(utf16_osErrorMsg, rtError, cbErrorMsg);
|
||||
// truncate if too long
|
||||
utf16_osErrorMsg[cbErrorMsg - 1] = L'\0';
|
||||
n = wcslen(utf16_osErrorMsg);
|
||||
}
|
||||
} else
|
||||
noError = TRUE; //OS has no error to report
|
||||
|
||||
if (!noError) {
|
||||
if (n > 0) {
|
||||
n = WideCharToMultiByte(
|
||||
CP_UTF8,
|
||||
0,
|
||||
utf16_osErrorMsg,
|
||||
n,
|
||||
utf8_jvmErrorMsg,
|
||||
cbErrorMsg,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
// no way to die
|
||||
if (n > 0)
|
||||
utf8_jvmErrorMsg[min(cbErrorMsg - 1, n)] = '\0';
|
||||
}
|
||||
|
||||
if (n <= 0) {
|
||||
strncpy(utf8_jvmErrorMsg, "Secondary error while OS message extraction", cbErrorMsg);
|
||||
// truncate if too long
|
||||
utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0';
|
||||
n = strlen(utf8_jvmErrorMsg);
|
||||
}
|
||||
}
|
||||
free(utf16_osErrorMsg);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2014 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -73,3 +73,77 @@ void buildJniFunctionName(const char *sym, const char *cname,
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
size_t
|
||||
getLastErrorString(char *utf8_jvmErrorMsg, size_t cbErrorMsg)
|
||||
{
|
||||
size_t n = 0;
|
||||
if (cbErrorMsg > 0) {
|
||||
BOOLEAN noError = FALSE;
|
||||
WCHAR *utf16_osErrorMsg = (WCHAR *)malloc(cbErrorMsg*sizeof(WCHAR));
|
||||
if (utf16_osErrorMsg == NULL) {
|
||||
// OOM accident
|
||||
strncpy(utf8_jvmErrorMsg, "Out of memory", cbErrorMsg);
|
||||
// truncate if too long
|
||||
utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0';
|
||||
n = strlen(utf8_jvmErrorMsg);
|
||||
} else {
|
||||
DWORD errval = GetLastError();
|
||||
if (errval != 0) {
|
||||
// WIN32 error
|
||||
n = (size_t)FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
errval,
|
||||
0,
|
||||
utf16_osErrorMsg,
|
||||
(DWORD)cbErrorMsg,
|
||||
NULL);
|
||||
if (n > 3) {
|
||||
// Drop final '.', CR, LF
|
||||
if (utf16_osErrorMsg[n - 1] == L'\n') --n;
|
||||
if (utf16_osErrorMsg[n - 1] == L'\r') --n;
|
||||
if (utf16_osErrorMsg[n - 1] == L'.') --n;
|
||||
utf16_osErrorMsg[n] = L'\0';
|
||||
}
|
||||
} else if (errno != 0) {
|
||||
// C runtime error that has no corresponding WIN32 error code
|
||||
const WCHAR *rtError = _wcserror(errno);
|
||||
if (rtError != NULL) {
|
||||
wcsncpy(utf16_osErrorMsg, rtError, cbErrorMsg);
|
||||
// truncate if too long
|
||||
utf16_osErrorMsg[cbErrorMsg - 1] = L'\0';
|
||||
n = wcslen(utf16_osErrorMsg);
|
||||
}
|
||||
} else
|
||||
noError = TRUE; //OS has no error to report
|
||||
|
||||
if (!noError) {
|
||||
if (n > 0) {
|
||||
n = WideCharToMultiByte(
|
||||
CP_UTF8,
|
||||
0,
|
||||
utf16_osErrorMsg,
|
||||
n,
|
||||
utf8_jvmErrorMsg,
|
||||
cbErrorMsg,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
// no way to die
|
||||
if (n > 0)
|
||||
utf8_jvmErrorMsg[min(cbErrorMsg - 1, n)] = '\0';
|
||||
}
|
||||
|
||||
if (n <= 0) {
|
||||
strncpy(utf8_jvmErrorMsg, "Secondary error while OS message extraction", cbErrorMsg);
|
||||
// truncate if too long
|
||||
utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0';
|
||||
n = strlen(utf8_jvmErrorMsg);
|
||||
}
|
||||
}
|
||||
free(utf16_osErrorMsg);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
@ -29,6 +29,9 @@
|
||||
#include "net_util.h"
|
||||
#include "jni.h"
|
||||
|
||||
// Taken from mstcpip.h in Windows SDK 8.0 or newer.
|
||||
#define SIO_LOOPBACK_FAST_PATH _WSAIOW(IOC_VENDOR,16)
|
||||
|
||||
#ifndef IPTOS_TOS_MASK
|
||||
#define IPTOS_TOS_MASK 0x1e
|
||||
#endif
|
||||
@ -844,6 +847,25 @@ jint getDefaultIPv6Interface(JNIEnv *env, struct SOCKADDR_IN6 *target_addr)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables SIO_LOOPBACK_FAST_PATH
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_EnableFastTcpLoopback(int fd) {
|
||||
int enabled = 1;
|
||||
DWORD result_byte_count = -1;
|
||||
int result = WSAIoctl(fd,
|
||||
SIO_LOOPBACK_FAST_PATH,
|
||||
&enabled,
|
||||
sizeof(enabled),
|
||||
NULL,
|
||||
0,
|
||||
&result_byte_count,
|
||||
NULL,
|
||||
NULL);
|
||||
return result == SOCKET_ERROR ? WSAGetLastError() : 0;
|
||||
}
|
||||
|
||||
/* If address types is IPv6, then IPv6 must be available. Otherwise
|
||||
* no address can be generated. In the case of an IPv4 Inetaddress this
|
||||
* method will return an IPv4 mapped address where IPv6 is available and
|
||||
|
@ -127,7 +127,7 @@ Java_sun_nio_ch_Net_canJoin6WithIPv4Group0(JNIEnv* env, jclass cl)
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
|
||||
jboolean stream, jboolean reuse)
|
||||
jboolean stream, jboolean reuse, jboolean fastLoopback)
|
||||
{
|
||||
SOCKET s;
|
||||
int domain = (preferIPv6) ? AF_INET6 : AF_INET;
|
||||
@ -152,6 +152,20 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
|
||||
NET_ThrowNew(env, WSAGetLastError(), "socket");
|
||||
}
|
||||
|
||||
if (stream && fastLoopback) {
|
||||
static int loopback_available = 1;
|
||||
if (loopback_available) {
|
||||
int rv = NET_EnableFastTcpLoopback((jint)s);
|
||||
if (rv) {
|
||||
if (rv == WSAEOPNOTSUPP) {
|
||||
loopback_available = 0;
|
||||
} else {
|
||||
NET_ThrowNew(env, rv, "fastLoopback");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (jint)s;
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ import java.util.Set;
|
||||
public class FileHandler extends StreamHandler {
|
||||
private MeteredStream meter;
|
||||
private boolean append;
|
||||
private int limit; // zero => no limit.
|
||||
private long limit; // zero => no limit.
|
||||
private int count;
|
||||
private String pattern;
|
||||
private String lockFileName;
|
||||
@ -164,11 +164,11 @@ public class FileHandler extends StreamHandler {
|
||||
* (a) forwards all its output to a target stream
|
||||
* (b) keeps track of how many bytes have been written
|
||||
*/
|
||||
private class MeteredStream extends OutputStream {
|
||||
private static final class MeteredStream extends OutputStream {
|
||||
final OutputStream out;
|
||||
int written;
|
||||
long written;
|
||||
|
||||
MeteredStream(OutputStream out, int written) {
|
||||
MeteredStream(OutputStream out, long written) {
|
||||
this.out = out;
|
||||
this.written = written;
|
||||
}
|
||||
@ -203,9 +203,9 @@ public class FileHandler extends StreamHandler {
|
||||
}
|
||||
|
||||
private void open(File fname, boolean append) throws IOException {
|
||||
int len = 0;
|
||||
long len = 0;
|
||||
if (append) {
|
||||
len = (int)fname.length();
|
||||
len = fname.length();
|
||||
}
|
||||
FileOutputStream fout = new FileOutputStream(fname.toString(), append);
|
||||
BufferedOutputStream bout = new BufferedOutputStream(fout);
|
||||
@ -223,7 +223,7 @@ public class FileHandler extends StreamHandler {
|
||||
String cname = getClass().getName();
|
||||
|
||||
pattern = manager.getStringProperty(cname + ".pattern", "%h/java%u.log");
|
||||
limit = manager.getIntProperty(cname + ".limit", 0);
|
||||
limit = manager.getLongProperty(cname + ".limit", 0);
|
||||
if (limit < 0) {
|
||||
limit = 0;
|
||||
}
|
||||
@ -395,6 +395,39 @@ public class FileHandler extends StreamHandler {
|
||||
*/
|
||||
public FileHandler(String pattern, int limit, int count, boolean append)
|
||||
throws IOException, SecurityException {
|
||||
this(pattern, (long)limit, count, append);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a {@code FileHandler} to write to a set of files
|
||||
* with optional append. When (approximately) the given limit has
|
||||
* been written to one file, another file will be opened. The
|
||||
* output will cycle through a set of count files.
|
||||
* <p>
|
||||
* The {@code FileHandler} is configured based on {@code LogManager}
|
||||
* properties (or their default values) except that the given pattern
|
||||
* argument is used as the filename pattern, the file limit is
|
||||
* set to the limit argument, and the file count is set to the
|
||||
* given count argument, and the append mode is set to the given
|
||||
* {@code append} argument.
|
||||
* <p>
|
||||
* The count must be at least 1.
|
||||
*
|
||||
* @param pattern the pattern for naming the output file
|
||||
* @param limit the maximum number of bytes to write to any one file
|
||||
* @param count the number of files to use
|
||||
* @param append specifies append mode
|
||||
* @exception IOException if there are IO problems opening the files.
|
||||
* @exception SecurityException if a security manager exists and if
|
||||
* the caller does not have {@code LoggingPermission("control")}.
|
||||
* @exception IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
|
||||
* @exception IllegalArgumentException if pattern is an empty string
|
||||
*
|
||||
* @since 1.9
|
||||
*
|
||||
*/
|
||||
public FileHandler(String pattern, long limit, int count, boolean append)
|
||||
throws IOException {
|
||||
if (limit < 0 || count < 1 || pattern.length() < 1) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@ -690,7 +723,7 @@ public class FileHandler extends StreamHandler {
|
||||
}
|
||||
super.publish(record);
|
||||
flush();
|
||||
if (limit > 0 && meter.written >= limit) {
|
||||
if (limit > 0 && (meter.written >= limit || meter.written < 0)) {
|
||||
// We performed access checks in the "init" method to make sure
|
||||
// we are only initialized from trusted code. So we assume
|
||||
// it is OK to write the target files, even if we are
|
||||
|
@ -1387,6 +1387,21 @@ public class LogManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Package private method to get a long property.
|
||||
// If the property is not defined or cannot be parsed
|
||||
// we return the given default value.
|
||||
long getLongProperty(String name, long defaultValue) {
|
||||
String val = getProperty(name);
|
||||
if (val == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(val.trim());
|
||||
} catch (Exception ex) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Package private method to get a boolean property.
|
||||
// If the property is not defined or cannot be parsed
|
||||
// we return the given default value.
|
||||
|
@ -65,6 +65,11 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
|
||||
dcmd_arg_info_array);
|
||||
dcmdArgInfoCls = (*env)->FindClass(env,
|
||||
"sun/management/DiagnosticCommandArgumentInfo");
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
free(dcmd_arg_info_array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL);
|
||||
if (result == NULL) {
|
||||
free(dcmd_arg_info_array);
|
||||
@ -91,9 +96,16 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
|
||||
}
|
||||
free(dcmd_arg_info_array);
|
||||
arraysCls = (*env)->FindClass(env, "java/util/Arrays");
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
return NULL;
|
||||
}
|
||||
mid = (*env)->GetStaticMethodID(env, arraysCls,
|
||||
"asList", "([Ljava/lang/Object;)Ljava/util/List;");
|
||||
resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// Make sure we return NULL in case of OOM inside Java
|
||||
return NULL;
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@ -121,6 +133,10 @@ Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
|
||||
num_commands = (*env)->GetArrayLength(env, commands);
|
||||
dcmdInfoCls = (*env)->FindClass(env,
|
||||
"sun/management/DiagnosticCommandInfo");
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL);
|
||||
if (result == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
|
@ -55,11 +55,6 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class RowSetWarning extends SQLException {
|
||||
|
||||
/**
|
||||
* RowSetWarning object handle.
|
||||
*/
|
||||
private RowSetWarning rwarning;
|
||||
|
||||
/**
|
||||
* Constructs a <code>RowSetWarning</code> object
|
||||
* with the given value for the reason; SQLState defaults to null,
|
||||
@ -128,7 +123,15 @@ public class RowSetWarning extends SQLException {
|
||||
* @see #setNextWarning
|
||||
*/
|
||||
public RowSetWarning getNextWarning() {
|
||||
return rwarning;
|
||||
SQLException warning = getNextException();
|
||||
if ( warning == null || warning instanceof RowSetWarning) {
|
||||
return (RowSetWarning)warning;
|
||||
} else {
|
||||
// The chained value isn't a RowSetWarning.
|
||||
// This is a programming error by whoever added it to
|
||||
// the RowSetWarning chain. We throw a Java "Error".
|
||||
throw new Error("RowSetWarning chain holds value that is not a RowSetWarning: ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,7 +144,7 @@ public class RowSetWarning extends SQLException {
|
||||
* @see #getNextWarning
|
||||
*/
|
||||
public void setNextWarning(RowSetWarning warning) {
|
||||
rwarning = warning;
|
||||
setNextException(warning);
|
||||
}
|
||||
|
||||
static final long serialVersionUID = 6678332766434564774L;
|
||||
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.lang.ref.*;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.spec.*;
|
||||
import javax.crypto.*;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
/**
|
||||
* Internal class for context resource clean up.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
final class CipherContextRef extends PhantomReference<NativeCipher>
|
||||
implements Comparable<CipherContextRef> {
|
||||
|
||||
private static ReferenceQueue<NativeCipher> refQueue =
|
||||
new ReferenceQueue<NativeCipher>();
|
||||
|
||||
// Needed to keep these references from being GC'ed until when their
|
||||
// referents are GC'ed so we can do post-mortem processing
|
||||
private static Set<CipherContextRef> refList =
|
||||
new ConcurrentSkipListSet<CipherContextRef>();
|
||||
|
||||
final long id;
|
||||
final boolean encrypt;
|
||||
|
||||
private static void drainRefQueueBounded() {
|
||||
while (true) {
|
||||
CipherContextRef next = (CipherContextRef) refQueue.poll();
|
||||
if (next == null) break;
|
||||
next.dispose(true);
|
||||
}
|
||||
}
|
||||
|
||||
CipherContextRef(NativeCipher nc, long id, boolean encrypt) {
|
||||
super(nc, refQueue);
|
||||
this.id = id;
|
||||
this.encrypt = encrypt;
|
||||
refList.add(this);
|
||||
UcryptoProvider.debug("Resource: trace CipherCtxt " + this.id);
|
||||
drainRefQueueBounded();
|
||||
}
|
||||
|
||||
public int compareTo(CipherContextRef other) {
|
||||
if (this.id == other.id) {
|
||||
return 0;
|
||||
} else {
|
||||
return (this.id < other.id) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
void dispose(boolean doCancel) {
|
||||
refList.remove(this);
|
||||
try {
|
||||
if (doCancel) {
|
||||
UcryptoProvider.debug("Resource: cancel CipherCtxt " + id);
|
||||
int k = NativeCipher.nativeFinal(id, encrypt, null, 0);
|
||||
if (k < 0) {
|
||||
UcryptoProvider.debug
|
||||
("Resource: error cancelling CipherCtxt " + id +
|
||||
" " + new UcryptoException(-k).getMessage());
|
||||
}
|
||||
} else {
|
||||
UcryptoProvider.debug("Resource: untrace CipherCtxt " + id);
|
||||
}
|
||||
} finally {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.io.*;
|
||||
import static java.io.StreamTokenizer.*;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
import java.security.*;
|
||||
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.security.util.PropertyExpander;
|
||||
|
||||
import sun.security.pkcs11.wrapper.*;
|
||||
|
||||
/**
|
||||
* Configuration container and file parsing.
|
||||
*
|
||||
* Currently, there is only one supported entry "disabledServices"
|
||||
* for disabling crypto services. Its syntax is as follows:
|
||||
*
|
||||
* disabledServices = {
|
||||
* <ServiceType>.<Algorithm>
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* where <Service> can be "MessageDigest", "Cipher", etc. and <Algorithm>
|
||||
* reprepresents the value that's passed into the various getInstance() calls.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
final class Config {
|
||||
|
||||
// Reader and StringTokenizer used during parsing
|
||||
private Reader reader;
|
||||
|
||||
private StreamTokenizer st;
|
||||
|
||||
private Set<String> parsedKeywords;
|
||||
|
||||
// set of disabled crypto services, e.g. MessageDigest.SHA1, or
|
||||
// Cipher.AES/ECB/PKCS5Padding
|
||||
private Set<String> disabledServices;
|
||||
|
||||
Config(String filename) throws IOException {
|
||||
FileInputStream in = new FileInputStream(expand(filename));
|
||||
reader = new BufferedReader(new InputStreamReader(in));
|
||||
parsedKeywords = new HashSet<String>();
|
||||
st = new StreamTokenizer(reader);
|
||||
setupTokenizer();
|
||||
parse();
|
||||
}
|
||||
|
||||
String[] getDisabledServices() {
|
||||
if (disabledServices != null) {
|
||||
return disabledServices.toArray(new String[disabledServices.size()]);
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static String expand(final String s) throws IOException {
|
||||
try {
|
||||
return PropertyExpander.expand(s);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTokenizer() {
|
||||
st.resetSyntax();
|
||||
st.wordChars('a', 'z');
|
||||
st.wordChars('A', 'Z');
|
||||
st.wordChars('0', '9');
|
||||
st.wordChars(':', ':');
|
||||
st.wordChars('.', '.');
|
||||
st.wordChars('_', '_');
|
||||
st.wordChars('-', '-');
|
||||
st.wordChars('/', '/');
|
||||
st.wordChars('\\', '\\');
|
||||
st.wordChars('$', '$');
|
||||
st.wordChars('{', '{'); // need {} for property subst
|
||||
st.wordChars('}', '}');
|
||||
st.wordChars('*', '*');
|
||||
st.wordChars('+', '+');
|
||||
st.wordChars('~', '~');
|
||||
// XXX check ASCII table and add all other characters except special
|
||||
|
||||
// special: #="(),
|
||||
st.whitespaceChars(0, ' ');
|
||||
st.commentChar('#');
|
||||
st.eolIsSignificant(true);
|
||||
st.quoteChar('\"');
|
||||
}
|
||||
|
||||
private ConfigException excToken(String msg) {
|
||||
return new ConfigException(msg + " " + st);
|
||||
}
|
||||
|
||||
private ConfigException excLine(String msg) {
|
||||
return new ConfigException(msg + ", line " + st.lineno());
|
||||
}
|
||||
|
||||
private void parse() throws IOException {
|
||||
while (true) {
|
||||
int token = nextToken();
|
||||
if (token == TT_EOF) {
|
||||
break;
|
||||
}
|
||||
if (token == TT_EOL) {
|
||||
continue;
|
||||
}
|
||||
if (token != TT_WORD) {
|
||||
throw excToken("Unexpected token:");
|
||||
}
|
||||
String word = st.sval;
|
||||
if (word.equals("disabledServices")) {
|
||||
parseDisabledServices(word);
|
||||
} else {
|
||||
throw new ConfigException
|
||||
("Unknown keyword '" + word + "', line " + st.lineno());
|
||||
}
|
||||
parsedKeywords.add(word);
|
||||
}
|
||||
reader.close();
|
||||
reader = null;
|
||||
st = null;
|
||||
parsedKeywords = null;
|
||||
}
|
||||
|
||||
//
|
||||
// Parsing helper methods
|
||||
//
|
||||
private int nextToken() throws IOException {
|
||||
int token = st.nextToken();
|
||||
return token;
|
||||
}
|
||||
|
||||
private void parseEquals() throws IOException {
|
||||
int token = nextToken();
|
||||
if (token != '=') {
|
||||
throw excToken("Expected '=', read");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseOpenBraces() throws IOException {
|
||||
while (true) {
|
||||
int token = nextToken();
|
||||
if (token == TT_EOL) {
|
||||
continue;
|
||||
}
|
||||
if ((token == TT_WORD) && st.sval.equals("{")) {
|
||||
return;
|
||||
}
|
||||
throw excToken("Expected '{', read");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCloseBraces(int token) {
|
||||
return (token == TT_WORD) && st.sval.equals("}");
|
||||
}
|
||||
|
||||
private void checkDup(String keyword) throws IOException {
|
||||
if (parsedKeywords.contains(keyword)) {
|
||||
throw excLine(keyword + " must only be specified once");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseDisabledServices(String keyword) throws IOException {
|
||||
checkDup(keyword);
|
||||
disabledServices = new HashSet<String>();
|
||||
parseEquals();
|
||||
parseOpenBraces();
|
||||
while (true) {
|
||||
int token = nextToken();
|
||||
if (isCloseBraces(token)) {
|
||||
break;
|
||||
}
|
||||
if (token == TT_EOL) {
|
||||
continue;
|
||||
}
|
||||
if (token != TT_WORD) {
|
||||
throw excToken("Expected mechanism, read");
|
||||
}
|
||||
disabledServices.add(st.sval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigException extends IOException {
|
||||
private static final long serialVersionUID = 254492758127673194L;
|
||||
ConfigException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.security.AlgorithmParametersSpi;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.InvalidParameterSpecException;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
import sun.security.util.*;
|
||||
|
||||
/**
|
||||
* This class implements the parameter set used with GCM mode
|
||||
* which is defined in RFC5084 as follows:
|
||||
*
|
||||
* <pre>
|
||||
* GCMParameters ::= SEQUENCE {
|
||||
* aes-nonce OCTET STRING, -- recommended size is 12 octets
|
||||
* aes-ICVlen AES-GCM-ICVlen DEFAULT 12 }
|
||||
*
|
||||
* where
|
||||
* AES-GCM-ICVlen ::= INTEGER (12 | 13 | 14 | 15 | 16)
|
||||
* NOTE: however, NIST 800-38D also lists 4 (32bit) and 8 (64bit)
|
||||
* as possible AES-GCM-ICVlen values, so we allow all 6 values.
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public final class GCMParameters extends AlgorithmParametersSpi {
|
||||
|
||||
private byte[] iv; // i.e. aes-nonce
|
||||
private int tLen; // i.e. aes-ICVlen, in bytes
|
||||
|
||||
public GCMParameters() {}
|
||||
|
||||
private void setValues(byte[] iv, int tLen) throws IOException {
|
||||
if (iv == null) {
|
||||
throw new IOException("IV cannot be null");
|
||||
}
|
||||
if (tLen != 4 && tLen != 8 && (tLen < 12 || tLen > 16)) {
|
||||
throw new IOException("Unsupported tag length: " + tLen);
|
||||
}
|
||||
this.iv = iv;
|
||||
this.tLen = tLen;
|
||||
}
|
||||
|
||||
protected byte[] engineGetEncoded() throws IOException {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
DerOutputStream bytes = new DerOutputStream();
|
||||
|
||||
bytes.putOctetString(iv);
|
||||
bytes.putInteger(tLen);
|
||||
out.write(DerValue.tag_Sequence, bytes);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
protected byte[] engineGetEncoded(String format) throws IOException {
|
||||
// ignore format for now
|
||||
return engineGetEncoded();
|
||||
}
|
||||
|
||||
protected <T extends AlgorithmParameterSpec>
|
||||
T engineGetParameterSpec(Class<T> paramSpec)
|
||||
throws InvalidParameterSpecException {
|
||||
if (GCMParameterSpec.class.isAssignableFrom(paramSpec)) {
|
||||
return paramSpec.cast(new GCMParameterSpec(tLen*8, iv.clone()));
|
||||
} else {
|
||||
throw new InvalidParameterSpecException
|
||||
("Inappropriate parameter specification");
|
||||
}
|
||||
}
|
||||
|
||||
protected void engineInit(AlgorithmParameterSpec paramSpec)
|
||||
throws InvalidParameterSpecException {
|
||||
if (!(paramSpec instanceof GCMParameterSpec)) {
|
||||
throw new InvalidParameterSpecException
|
||||
("Inappropriate parameter specification");
|
||||
}
|
||||
GCMParameterSpec gcmSpec = (GCMParameterSpec) paramSpec;
|
||||
try {
|
||||
setValues(gcmSpec.getIV(), gcmSpec.getTLen()/8);
|
||||
} catch (IOException ioe) {
|
||||
throw new InvalidParameterSpecException(ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void engineInit(byte[] encoded) throws IOException {
|
||||
DerValue val = new DerValue(encoded);
|
||||
if (val.tag == DerValue.tag_Sequence) {
|
||||
val.data.reset();
|
||||
setValues(val.data.getOctetString(), val.data.getInteger());
|
||||
} else {
|
||||
throw new IOException("GCM parameter parsing error: SEQ tag expected");
|
||||
}
|
||||
}
|
||||
|
||||
protected void engineInit(byte[] encoded, String format)
|
||||
throws IOException {
|
||||
// ignore format for now
|
||||
engineInit(encoded);
|
||||
}
|
||||
|
||||
protected String engineToString() {
|
||||
return ("IV=" + Arrays.toString(iv) + ", tLen=" + tLen * 8);
|
||||
}
|
||||
}
|
@ -0,0 +1,588 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.lang.ref.*;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.spec.*;
|
||||
import javax.crypto.*;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
/**
|
||||
* Cipher wrapper class utilizing ucrypto APIs. This class currently supports
|
||||
* - AES/ECB/NOPADDING
|
||||
* - AES/CBC/NOPADDING
|
||||
* - AES/CTR/NOPADDING
|
||||
* - AES/CFB128/NOPADDING
|
||||
* (Support for GCM mode is inside the child class NativeGCMCipher)
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
class NativeCipher extends CipherSpi {
|
||||
|
||||
// public implementation classes
|
||||
public static final class AesEcbNoPadding extends NativeCipher {
|
||||
public AesEcbNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_ECB);
|
||||
}
|
||||
}
|
||||
public static final class AesCbcNoPadding extends NativeCipher {
|
||||
public AesCbcNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_CBC);
|
||||
}
|
||||
}
|
||||
public static final class AesCtrNoPadding extends NativeCipher {
|
||||
public AesCtrNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_CTR);
|
||||
}
|
||||
}
|
||||
public static final class AesCfb128NoPadding extends NativeCipher {
|
||||
public AesCfb128NoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_CFB128);
|
||||
}
|
||||
}
|
||||
|
||||
// public implementation classes with fixed key sizes
|
||||
public static final class Aes128EcbNoPadding extends NativeCipher {
|
||||
public Aes128EcbNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_ECB, 16);
|
||||
}
|
||||
}
|
||||
public static final class Aes128CbcNoPadding extends NativeCipher {
|
||||
public Aes128CbcNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_CBC, 16);
|
||||
}
|
||||
}
|
||||
public static final class Aes192EcbNoPadding extends NativeCipher {
|
||||
public Aes192EcbNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_ECB, 24);
|
||||
}
|
||||
}
|
||||
public static final class Aes192CbcNoPadding extends NativeCipher {
|
||||
public Aes192CbcNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_CBC, 24);
|
||||
}
|
||||
}
|
||||
public static final class Aes256EcbNoPadding extends NativeCipher {
|
||||
public Aes256EcbNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_ECB, 32);
|
||||
}
|
||||
}
|
||||
public static final class Aes256CbcNoPadding extends NativeCipher {
|
||||
public Aes256CbcNoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_CBC, 32);
|
||||
}
|
||||
}
|
||||
|
||||
// ok as constants since AES is all we support
|
||||
public static final int AES_BLOCK_SIZE = 16;
|
||||
public static final String AES_KEY_ALGO = "AES";
|
||||
|
||||
// fields set in constructor
|
||||
protected final UcryptoMech mech;
|
||||
protected String keyAlgo;
|
||||
protected int blockSize;
|
||||
protected int fixedKeySize;
|
||||
|
||||
//
|
||||
// fields (re)set in every init()
|
||||
//
|
||||
protected CipherContextRef pCtxt = null;
|
||||
protected byte[] keyValue = null;
|
||||
protected byte[] iv = null;
|
||||
protected boolean initialized = false;
|
||||
protected boolean encrypt = true;
|
||||
protected int bytesBuffered = 0;
|
||||
|
||||
// private utility methods for key re-construction
|
||||
private static final PublicKey constructPublicKey(byte[] encodedKey,
|
||||
String encodedKeyAlgorithm)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException {
|
||||
|
||||
PublicKey key = null;
|
||||
try {
|
||||
KeyFactory keyFactory =
|
||||
KeyFactory.getInstance(encodedKeyAlgorithm);
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
|
||||
key = keyFactory.generatePublic(keySpec);
|
||||
} catch (NoSuchAlgorithmException nsae) {
|
||||
throw new NoSuchAlgorithmException("No provider found for " +
|
||||
encodedKeyAlgorithm +
|
||||
" KeyFactory");
|
||||
} catch (InvalidKeySpecException ikse) {
|
||||
// Should never happen
|
||||
throw new InvalidKeyException("Cannot construct public key", ikse);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
private static final PrivateKey constructPrivateKey(byte[] encodedKey,
|
||||
String encodedKeyAlgorithm)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException {
|
||||
|
||||
PrivateKey key = null;
|
||||
try {
|
||||
KeyFactory keyFactory =
|
||||
KeyFactory.getInstance(encodedKeyAlgorithm);
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
|
||||
key = keyFactory.generatePrivate(keySpec);
|
||||
} catch (NoSuchAlgorithmException nsae) {
|
||||
throw new NoSuchAlgorithmException("No provider found for " +
|
||||
encodedKeyAlgorithm +
|
||||
" KeyFactory");
|
||||
} catch (InvalidKeySpecException ikse) {
|
||||
// Should never happen
|
||||
throw new InvalidKeyException("Cannot construct private key", ikse);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
private static final SecretKey constructSecretKey(byte[] encodedKey,
|
||||
String encodedKeyAlgorithm) {
|
||||
return new SecretKeySpec(encodedKey, encodedKeyAlgorithm);
|
||||
}
|
||||
|
||||
// package-private utility method for general key re-construction
|
||||
static final Key constructKey(int keyType, byte[] encodedKey,
|
||||
String encodedKeyAlgorithm)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException {
|
||||
Key result = null;
|
||||
switch (keyType) {
|
||||
case Cipher.SECRET_KEY:
|
||||
result = constructSecretKey(encodedKey,
|
||||
encodedKeyAlgorithm);
|
||||
break;
|
||||
case Cipher.PRIVATE_KEY:
|
||||
result = constructPrivateKey(encodedKey,
|
||||
encodedKeyAlgorithm);
|
||||
break;
|
||||
case Cipher.PUBLIC_KEY:
|
||||
result = constructPublicKey(encodedKey,
|
||||
encodedKeyAlgorithm);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeCipher(UcryptoMech mech, int fixedKeySize) throws NoSuchAlgorithmException {
|
||||
this.mech = mech;
|
||||
// defaults to AES - the only supported symmetric cipher algo
|
||||
this.blockSize = AES_BLOCK_SIZE;
|
||||
this.keyAlgo = AES_KEY_ALGO;
|
||||
this.fixedKeySize = fixedKeySize;
|
||||
}
|
||||
|
||||
NativeCipher(UcryptoMech mech) throws NoSuchAlgorithmException {
|
||||
this(mech, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
|
||||
// Disallow change of mode for now since currently it's explicitly
|
||||
// defined in transformation strings
|
||||
throw new NoSuchAlgorithmException("Unsupported mode " + mode);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected void engineSetPadding(String padding)
|
||||
throws NoSuchPaddingException {
|
||||
// Disallow change of padding for now since currently it's explicitly
|
||||
// defined in transformation strings
|
||||
throw new NoSuchPaddingException("Unsupported padding " + padding);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected int engineGetBlockSize() {
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineGetOutputSize(int inputLen) {
|
||||
return getOutputSizeByOperation(inputLen, true);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineGetIV() {
|
||||
return (iv != null? iv.clone() : null);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized AlgorithmParameters engineGetParameters() {
|
||||
AlgorithmParameters params = null;
|
||||
try {
|
||||
if (iv != null) {
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(iv.clone());
|
||||
params = AlgorithmParameters.getInstance(keyAlgo);
|
||||
params.init(ivSpec);
|
||||
}
|
||||
} catch (GeneralSecurityException e) {
|
||||
// NoSuchAlgorithmException, NoSuchProviderException
|
||||
// InvalidParameterSpecException
|
||||
throw new UcryptoException("Could not encode parameters", e);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineGetKeySize(Key key) throws InvalidKeyException {
|
||||
return checkKey(key) * 8;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key,
|
||||
SecureRandom random) throws InvalidKeyException {
|
||||
try {
|
||||
engineInit(opmode, key, (AlgorithmParameterSpec)null, random);
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
throw new InvalidKeyException("init() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key,
|
||||
AlgorithmParameterSpec params, SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
checkKey(key);
|
||||
if (opmode != Cipher.ENCRYPT_MODE &&
|
||||
opmode != Cipher.DECRYPT_MODE &&
|
||||
opmode != Cipher.WRAP_MODE &&
|
||||
opmode != Cipher.UNWRAP_MODE) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("Unsupported mode: " + opmode);
|
||||
}
|
||||
boolean doEncrypt =
|
||||
(opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE);
|
||||
|
||||
byte[] ivBytes = null;
|
||||
if (mech == UcryptoMech.CRYPTO_AES_ECB) {
|
||||
if (params != null) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("No Parameters for ECB mode");
|
||||
}
|
||||
} else {
|
||||
if (params != null) {
|
||||
if (!(params instanceof IvParameterSpec)) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("IvParameterSpec required");
|
||||
} else {
|
||||
ivBytes = ((IvParameterSpec) params).getIV();
|
||||
if (ivBytes.length != blockSize) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("Wrong IV length: must be " + blockSize +
|
||||
" bytes long");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (encrypt) {
|
||||
// generate IV if none supplied for encryption
|
||||
ivBytes = new byte[blockSize];
|
||||
new SecureRandom().nextBytes(ivBytes);
|
||||
} else {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("Parameters required for decryption");
|
||||
}
|
||||
}
|
||||
}
|
||||
init(doEncrypt, key.getEncoded().clone(), ivBytes);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key,
|
||||
AlgorithmParameters params, SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
AlgorithmParameterSpec spec = null;
|
||||
if (params != null) {
|
||||
try {
|
||||
spec = params.getParameterSpec(IvParameterSpec.class);
|
||||
} catch (InvalidParameterSpecException iaps) {
|
||||
throw new InvalidAlgorithmParameterException(iaps);
|
||||
}
|
||||
}
|
||||
engineInit(opmode, key, spec, random);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineUpdate(byte[] in, int ofs, int len) {
|
||||
byte[] out = new byte[getOutputSizeByOperation(len, false)];
|
||||
int n = update(in, ofs, len, out, 0);
|
||||
if (n == 0) {
|
||||
return null;
|
||||
} else if (out.length != n) {
|
||||
out = Arrays.copyOf(out, n);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineUpdate(byte[] in, int inOfs, int inLen,
|
||||
byte[] out, int outOfs) throws ShortBufferException {
|
||||
int min = getOutputSizeByOperation(inLen, false);
|
||||
if (out.length - outOfs < min) {
|
||||
throw new ShortBufferException("min " + min + "-byte buffer needed");
|
||||
}
|
||||
return update(in, inOfs, inLen, out, outOfs);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineUpdateAAD(byte[] src, int ofs, int len)
|
||||
throws IllegalStateException {
|
||||
throw new IllegalStateException("No AAD can be supplied");
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected void engineUpdateAAD(ByteBuffer src)
|
||||
throws IllegalStateException {
|
||||
throw new IllegalStateException("No AAD can be supplied");
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineDoFinal(byte[] in, int ofs, int len)
|
||||
throws IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] out = new byte[getOutputSizeByOperation(len, true)];
|
||||
try {
|
||||
// delegate to the other engineDoFinal(...) method
|
||||
int k = engineDoFinal(in, ofs, len, out, 0);
|
||||
if (out.length != k) {
|
||||
out = Arrays.copyOf(out, k);
|
||||
}
|
||||
return out;
|
||||
} catch (ShortBufferException e) {
|
||||
throw new UcryptoException("Internal Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineDoFinal(byte[] in, int inOfs, int inLen,
|
||||
byte[] out, int outOfs)
|
||||
throws ShortBufferException, IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
int k = 0;
|
||||
int min = getOutputSizeByOperation(inLen, true);
|
||||
if (out.length - outOfs < min) {
|
||||
throw new ShortBufferException("min " + min + "-byte buffer needed");
|
||||
}
|
||||
if (inLen > 0) {
|
||||
k = update(in, inOfs, inLen, out, outOfs);
|
||||
outOfs += k;
|
||||
}
|
||||
k += doFinal(out, outOfs);
|
||||
return k;
|
||||
}
|
||||
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineWrap(Key key)
|
||||
throws IllegalBlockSizeException, InvalidKeyException {
|
||||
byte[] result = null;
|
||||
try {
|
||||
byte[] encodedKey = key.getEncoded();
|
||||
if ((encodedKey == null) || (encodedKey.length == 0)) {
|
||||
throw new InvalidKeyException("Cannot get an encoding of " +
|
||||
"the key to be wrapped");
|
||||
}
|
||||
result = engineDoFinal(encodedKey, 0, encodedKey.length);
|
||||
} catch (BadPaddingException e) {
|
||||
// Should never happen for key wrapping
|
||||
throw new UcryptoException("Internal Error" , e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized Key engineUnwrap(byte[] wrappedKey,
|
||||
String wrappedKeyAlgorithm, int wrappedKeyType)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException {
|
||||
|
||||
byte[] encodedKey;
|
||||
Key result = null;
|
||||
try {
|
||||
encodedKey = engineDoFinal(wrappedKey, 0,
|
||||
wrappedKey.length);
|
||||
} catch (Exception e) {
|
||||
throw (InvalidKeyException)
|
||||
(new InvalidKeyException()).initCause(e);
|
||||
}
|
||||
|
||||
return constructKey(wrappedKeyType, encodedKey, wrappedKeyAlgorithm);
|
||||
}
|
||||
|
||||
final int checkKey(Key key) throws InvalidKeyException {
|
||||
if (key == null || key.getEncoded() == null) {
|
||||
throw new InvalidKeyException("Key cannot be null");
|
||||
} else {
|
||||
// check key algorithm and format
|
||||
if (!keyAlgo.equalsIgnoreCase(key.getAlgorithm())) {
|
||||
throw new InvalidKeyException("Key algorithm must be " +
|
||||
keyAlgo);
|
||||
}
|
||||
if (!"RAW".equalsIgnoreCase(key.getFormat())) {
|
||||
throw new InvalidKeyException("Key format must be RAW");
|
||||
}
|
||||
int keyLen = key.getEncoded().length;
|
||||
if (fixedKeySize == -1) {
|
||||
// all 3 AES key lengths are allowed
|
||||
if (keyLen != 16 && keyLen != 24 && keyLen != 32) {
|
||||
throw new InvalidKeyException("Key size is not valid");
|
||||
}
|
||||
} else {
|
||||
if (keyLen != fixedKeySize) {
|
||||
throw new InvalidKeyException("Only " + fixedKeySize +
|
||||
"-byte keys are accepted");
|
||||
}
|
||||
}
|
||||
// return the validated key length in bytes
|
||||
return keyLen;
|
||||
}
|
||||
}
|
||||
|
||||
protected void reset(boolean doCancel) {
|
||||
initialized = false;
|
||||
bytesBuffered = 0;
|
||||
if (pCtxt != null) {
|
||||
pCtxt.dispose(doCancel);
|
||||
pCtxt = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calls ucrypto_encrypt_init(...) or ucrypto_decrypt_init(...)
|
||||
* @return pointer to the context
|
||||
*/
|
||||
protected native static long nativeInit(int mech, boolean encrypt,
|
||||
byte[] key, byte[] iv,
|
||||
int tagLen, byte[] aad);
|
||||
|
||||
/**
|
||||
* calls ucrypto_encrypt_update(...) or ucrypto_decrypt_update(...)
|
||||
* @returns the length of output or if negative, an error status code
|
||||
*/
|
||||
private native static int nativeUpdate(long pContext, boolean encrypt,
|
||||
byte[] in, int inOfs, int inLen,
|
||||
byte[] out, int outOfs);
|
||||
|
||||
/**
|
||||
* calls ucrypto_encrypt_final(...) or ucrypto_decrypt_final(...)
|
||||
* @returns the length of output or if negative, an error status code
|
||||
*/
|
||||
native static int nativeFinal(long pContext, boolean encrypt,
|
||||
byte[] out, int outOfs);
|
||||
|
||||
protected void ensureInitialized() {
|
||||
if (!initialized) {
|
||||
init(encrypt, keyValue, iv);
|
||||
if (!initialized) {
|
||||
throw new UcryptoException("Cannot initialize Cipher");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int getOutputSizeByOperation(int inLen, boolean isDoFinal) {
|
||||
if (inLen <= 0) {
|
||||
inLen = 0;
|
||||
}
|
||||
if (!isDoFinal && (inLen == 0)) {
|
||||
return 0;
|
||||
}
|
||||
return inLen + bytesBuffered;
|
||||
}
|
||||
|
||||
// actual init() implementation - caller should clone key and iv if needed
|
||||
protected void init(boolean encrypt, byte[] keyVal, byte[] ivVal) {
|
||||
reset(true);
|
||||
this.encrypt = encrypt;
|
||||
this.keyValue = keyVal;
|
||||
this.iv = ivVal;
|
||||
long pCtxtVal = nativeInit(mech.value(), encrypt, keyValue, iv, 0, null);
|
||||
initialized = (pCtxtVal != 0L);
|
||||
if (initialized) {
|
||||
pCtxt = new CipherContextRef(this, pCtxtVal, encrypt);
|
||||
} else {
|
||||
throw new UcryptoException("Cannot initialize Cipher");
|
||||
}
|
||||
}
|
||||
|
||||
// Caller MUST check and ensure output buffer has enough capacity
|
||||
private int update(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) {
|
||||
ensureInitialized();
|
||||
if (inLen <= 0) { return 0; }
|
||||
|
||||
int k = nativeUpdate(pCtxt.id, encrypt, in, inOfs, inLen, out, outOfs);
|
||||
if (k < 0) {
|
||||
reset(false);
|
||||
// cannot throw ShortBufferException here since it's too late
|
||||
// native context is invalid upon any failure
|
||||
throw new UcryptoException(-k);
|
||||
}
|
||||
bytesBuffered += (inLen - k);
|
||||
return k;
|
||||
}
|
||||
|
||||
// Caller MUST check and ensure output buffer has enough capacity
|
||||
private int doFinal(byte[] out, int outOfs) throws IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
try {
|
||||
ensureInitialized();
|
||||
|
||||
int k = nativeFinal(pCtxt.id, encrypt, out, outOfs);
|
||||
if (k < 0) {
|
||||
String cause = UcryptoException.getErrorMessage(-k);
|
||||
if (cause.endsWith("_LEN_RANGE")) {
|
||||
throw new IllegalBlockSizeException(cause);
|
||||
} else if (cause.endsWith("_DATA_INVALID")) {
|
||||
throw new BadPaddingException(cause);
|
||||
} else {
|
||||
throw new UcryptoException(-k);
|
||||
}
|
||||
}
|
||||
return k;
|
||||
} finally {
|
||||
reset(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,464 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.lang.ref.*;
|
||||
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.Key;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.InvalidParameterSpecException;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherSpi;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.ShortBufferException;
|
||||
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
/**
|
||||
* Wrapper class which uses NativeCipher class and Java impls of padding scheme.
|
||||
* This class currently supports
|
||||
* - AES/ECB/PKCS5PADDING
|
||||
* - AES/CBC/PKCS5PADDING
|
||||
* - AES/CFB128/PKCS5PADDING
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public class NativeCipherWithJavaPadding extends CipherSpi {
|
||||
|
||||
private static interface Padding {
|
||||
// ENC: generate and return the necessary padding bytes
|
||||
int getPadLen(int dataLen);
|
||||
|
||||
// ENC: generate and return the necessary padding bytes
|
||||
byte[] getPaddingBytes(int dataLen);
|
||||
|
||||
// DEC: process the decrypted data and buffer up the potential padding
|
||||
// bytes
|
||||
byte[] bufferBytes(byte[] intermediateData);
|
||||
|
||||
// DEC: return the length of internally buffered pad bytes
|
||||
int getBufferedLength();
|
||||
|
||||
// DEC: unpad and place the output in 'out', starting from outOfs
|
||||
// and return the number of bytes unpadded into 'out'.
|
||||
int unpad(byte[] paddedData, byte[] out, int outOfs)
|
||||
throws BadPaddingException, IllegalBlockSizeException,
|
||||
ShortBufferException;
|
||||
|
||||
// DEC: Clears the padding object to the initial state
|
||||
void clear();
|
||||
}
|
||||
|
||||
private static class PKCS5Padding implements Padding {
|
||||
private final int blockSize;
|
||||
// buffer for storing the the potential padding bytes
|
||||
private ByteBuffer trailingBytes = null;
|
||||
|
||||
PKCS5Padding(int blockSize)
|
||||
throws NoSuchPaddingException {
|
||||
if (blockSize == 0) {
|
||||
throw new NoSuchPaddingException
|
||||
("PKCS#5 padding not supported with stream ciphers");
|
||||
}
|
||||
this.blockSize = blockSize;
|
||||
}
|
||||
|
||||
public int getPadLen(int dataLen) {
|
||||
return (blockSize - (dataLen & (blockSize - 1)));
|
||||
}
|
||||
|
||||
public byte[] getPaddingBytes(int dataLen) {
|
||||
byte padValue = (byte) getPadLen(dataLen);
|
||||
byte[] paddingBytes = new byte[padValue];
|
||||
Arrays.fill(paddingBytes, padValue);
|
||||
return paddingBytes;
|
||||
}
|
||||
|
||||
public byte[] bufferBytes(byte[] dataFromUpdate) {
|
||||
if (dataFromUpdate == null || dataFromUpdate.length == 0) {
|
||||
return null;
|
||||
}
|
||||
byte[] result = null;
|
||||
if (trailingBytes == null) {
|
||||
trailingBytes = ByteBuffer.wrap(new byte[blockSize]);
|
||||
}
|
||||
int tbSize = trailingBytes.position();
|
||||
if (dataFromUpdate.length > trailingBytes.remaining()) {
|
||||
int totalLen = dataFromUpdate.length + tbSize;
|
||||
int newTBSize = totalLen % blockSize;
|
||||
if (newTBSize == 0) {
|
||||
newTBSize = blockSize;
|
||||
}
|
||||
if (tbSize == 0) {
|
||||
result = Arrays.copyOf(dataFromUpdate, totalLen - newTBSize);
|
||||
} else {
|
||||
// combine 'trailingBytes' and 'dataFromUpdate'
|
||||
result = Arrays.copyOf(trailingBytes.array(),
|
||||
totalLen - newTBSize);
|
||||
if (result.length != tbSize) {
|
||||
System.arraycopy(dataFromUpdate, 0, result, tbSize,
|
||||
result.length - tbSize);
|
||||
}
|
||||
}
|
||||
// update 'trailingBytes' w/ remaining bytes in 'dataFromUpdate'
|
||||
trailingBytes.clear();
|
||||
trailingBytes.put(dataFromUpdate,
|
||||
dataFromUpdate.length - newTBSize, newTBSize);
|
||||
} else {
|
||||
trailingBytes.put(dataFromUpdate);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getBufferedLength() {
|
||||
if (trailingBytes != null) {
|
||||
return trailingBytes.position();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int unpad(byte[] lastData, byte[] out, int outOfs)
|
||||
throws BadPaddingException, IllegalBlockSizeException,
|
||||
ShortBufferException {
|
||||
int tbSize = (trailingBytes == null? 0:trailingBytes.position());
|
||||
int dataLen = tbSize + lastData.length;
|
||||
// check total length
|
||||
if ((dataLen < 1) || (dataLen % blockSize != 0)) {
|
||||
UcryptoProvider.debug("PKCS5Padding: unpad, buffered " + tbSize +
|
||||
" bytes, last block " + lastData.length + " bytes");
|
||||
|
||||
throw new IllegalBlockSizeException
|
||||
("Input length must be multiples of " + blockSize);
|
||||
}
|
||||
|
||||
// check padding bytes
|
||||
if (lastData.length == 0) {
|
||||
if (tbSize != 0) {
|
||||
// work on 'trailingBytes' directly
|
||||
lastData = Arrays.copyOf(trailingBytes.array(), tbSize);
|
||||
trailingBytes.clear();
|
||||
tbSize = 0;
|
||||
} else {
|
||||
throw new BadPaddingException("No pad bytes found!");
|
||||
}
|
||||
}
|
||||
byte padValue = lastData[lastData.length - 1];
|
||||
if (padValue < 1 || padValue > blockSize) {
|
||||
UcryptoProvider.debug("PKCS5Padding: unpad, lastData: " + Arrays.toString(lastData));
|
||||
UcryptoProvider.debug("PKCS5Padding: unpad, padValue=" + padValue);
|
||||
throw new BadPaddingException("Invalid pad value!");
|
||||
}
|
||||
|
||||
// sanity check padding bytes
|
||||
int padStartIndex = lastData.length - padValue;
|
||||
for (int i = padStartIndex; i < lastData.length; i++) {
|
||||
if (lastData[i] != padValue) {
|
||||
UcryptoProvider.debug("PKCS5Padding: unpad, lastData: " + Arrays.toString(lastData));
|
||||
UcryptoProvider.debug("PKCS5Padding: unpad, padValue=" + padValue);
|
||||
throw new BadPaddingException("Invalid padding bytes!");
|
||||
}
|
||||
}
|
||||
|
||||
int actualOutLen = dataLen - padValue;
|
||||
// check output buffer capacity
|
||||
if (out.length - outOfs < actualOutLen) {
|
||||
throw new ShortBufferException("Output buffer too small, need " + actualOutLen +
|
||||
", got " + (out.length - outOfs));
|
||||
}
|
||||
try {
|
||||
if (tbSize != 0) {
|
||||
trailingBytes.rewind();
|
||||
if (tbSize < actualOutLen) {
|
||||
trailingBytes.get(out, outOfs, tbSize);
|
||||
outOfs += tbSize;
|
||||
} else {
|
||||
// copy from trailingBytes and we are done
|
||||
trailingBytes.get(out, outOfs, actualOutLen);
|
||||
return actualOutLen;
|
||||
}
|
||||
}
|
||||
if (lastData.length > padValue) {
|
||||
System.arraycopy(lastData, 0, out, outOfs,
|
||||
lastData.length - padValue);
|
||||
}
|
||||
return actualOutLen;
|
||||
} finally {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (trailingBytes != null) trailingBytes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class AesEcbPKCS5 extends NativeCipherWithJavaPadding {
|
||||
public AesEcbPKCS5() throws NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
super(new NativeCipher.AesEcbNoPadding(), "PKCS5Padding");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class AesCbcPKCS5 extends NativeCipherWithJavaPadding {
|
||||
public AesCbcPKCS5() throws NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
super(new NativeCipher.AesCbcNoPadding(), "PKCS5Padding");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class AesCfb128PKCS5 extends NativeCipherWithJavaPadding {
|
||||
public AesCfb128PKCS5() throws NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
super(new NativeCipher.AesCfb128NoPadding(), "PKCS5Padding");
|
||||
}
|
||||
}
|
||||
|
||||
// fields (re)set in every init()
|
||||
private final NativeCipher nc;
|
||||
private final Padding padding;
|
||||
private final int blockSize;
|
||||
private int lastBlockLen = 0;
|
||||
|
||||
// Only ECB, CBC, CTR, and CFB128 modes w/ NOPADDING for now
|
||||
NativeCipherWithJavaPadding(NativeCipher nc, String paddingScheme)
|
||||
throws NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
this.nc = nc;
|
||||
this.blockSize = nc.engineGetBlockSize();
|
||||
if (paddingScheme.toUpperCase().equals("PKCS5PADDING")) {
|
||||
padding = new PKCS5Padding(blockSize);
|
||||
} else {
|
||||
throw new NoSuchAlgorithmException("Unsupported padding scheme: " + paddingScheme);
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
padding.clear();
|
||||
lastBlockLen = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void engineSetMode(String mode) throws NoSuchAlgorithmException {
|
||||
nc.engineSetMode(mode);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected void engineSetPadding(String padding)
|
||||
throws NoSuchPaddingException {
|
||||
// Disallow change of padding for now since currently it's explicitly
|
||||
// defined in transformation strings
|
||||
throw new NoSuchPaddingException("Unsupported padding " + padding);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected int engineGetBlockSize() {
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineGetOutputSize(int inputLen) {
|
||||
int result = nc.engineGetOutputSize(inputLen);
|
||||
if (nc.encrypt) {
|
||||
result += padding.getPadLen(result);
|
||||
} else {
|
||||
result += padding.getBufferedLength();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineGetIV() {
|
||||
return nc.engineGetIV();
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized AlgorithmParameters engineGetParameters() {
|
||||
return nc.engineGetParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineGetKeySize(Key key) throws InvalidKeyException {
|
||||
return nc.engineGetKeySize(key);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key, SecureRandom random)
|
||||
throws InvalidKeyException {
|
||||
reset();
|
||||
nc.engineInit(opmode, key, random);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key,
|
||||
AlgorithmParameterSpec params, SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
reset();
|
||||
nc.engineInit(opmode, key, params, random);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key, AlgorithmParameters params,
|
||||
SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
reset();
|
||||
nc.engineInit(opmode, key, params, random);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineUpdate(byte[] in, int inOfs, int inLen) {
|
||||
if (nc.encrypt) {
|
||||
lastBlockLen += inLen;
|
||||
lastBlockLen &= (blockSize - 1);
|
||||
return nc.engineUpdate(in, inOfs, inLen);
|
||||
} else {
|
||||
return padding.bufferBytes(nc.engineUpdate(in, inOfs, inLen));
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineUpdate(byte[] in, int inOfs, int inLen, byte[] out,
|
||||
int outOfs) throws ShortBufferException {
|
||||
if (nc.encrypt) {
|
||||
lastBlockLen += inLen;
|
||||
lastBlockLen &= (blockSize - 1);
|
||||
return nc.engineUpdate(in, inOfs, inLen, out, outOfs);
|
||||
} else {
|
||||
byte[] result = padding.bufferBytes(nc.engineUpdate(in, inOfs, inLen));
|
||||
if (result != null) {
|
||||
System.arraycopy(result, 0, out, outOfs, result.length);
|
||||
return result.length;
|
||||
} else return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineDoFinal(byte[] in, int inOfs, int inLen)
|
||||
throws IllegalBlockSizeException, BadPaddingException {
|
||||
int estimatedOutLen = engineGetOutputSize(inLen);
|
||||
byte[] out = new byte[estimatedOutLen];
|
||||
try {
|
||||
int actualOut = this.engineDoFinal(in, inOfs, inLen, out, 0);
|
||||
// truncate off extra bytes
|
||||
if (actualOut != out.length) {
|
||||
out = Arrays.copyOf(out, actualOut);
|
||||
}
|
||||
} catch (ShortBufferException sbe) {
|
||||
throw new UcryptoException("Internal Error");
|
||||
} finally {
|
||||
reset();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out,
|
||||
int outOfs)
|
||||
throws ShortBufferException, IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
int estimatedOutLen = engineGetOutputSize(inLen);
|
||||
|
||||
if (out.length - outOfs < estimatedOutLen) {
|
||||
throw new ShortBufferException();
|
||||
}
|
||||
try {
|
||||
if (nc.encrypt) {
|
||||
int k = nc.engineUpdate(in, inOfs, inLen, out, outOfs);
|
||||
lastBlockLen += inLen;
|
||||
lastBlockLen &= (blockSize - 1);
|
||||
byte[] padBytes = padding.getPaddingBytes(lastBlockLen);
|
||||
k += nc.engineDoFinal(padBytes, 0, padBytes.length, out, (outOfs + k));
|
||||
return k;
|
||||
} else {
|
||||
byte[] tempOut = nc.engineDoFinal(in, inOfs, inLen);
|
||||
int len = padding.unpad(tempOut, out, outOfs);
|
||||
return len;
|
||||
}
|
||||
} finally {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineWrap(Key key) throws IllegalBlockSizeException,
|
||||
InvalidKeyException {
|
||||
byte[] result = null;
|
||||
try {
|
||||
byte[] encodedKey = key.getEncoded();
|
||||
if ((encodedKey == null) || (encodedKey.length == 0)) {
|
||||
throw new InvalidKeyException("Cannot get an encoding of " +
|
||||
"the key to be wrapped");
|
||||
}
|
||||
result = engineDoFinal(encodedKey, 0, encodedKey.length);
|
||||
} catch (BadPaddingException e) {
|
||||
// Should never happen for key wrapping
|
||||
throw new UcryptoException("Internal Error", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm,
|
||||
int wrappedKeyType)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException {
|
||||
|
||||
byte[] encodedKey;
|
||||
try {
|
||||
encodedKey = engineDoFinal(wrappedKey, 0,
|
||||
wrappedKey.length);
|
||||
} catch (Exception e) {
|
||||
throw (InvalidKeyException)
|
||||
(new InvalidKeyException()).initCause(e);
|
||||
}
|
||||
|
||||
return NativeCipher.constructKey(wrappedKeyType, encodedKey,
|
||||
wrappedKeyAlgorithm);
|
||||
}
|
||||
}
|
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.lang.ref.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.security.*;
|
||||
|
||||
/**
|
||||
* MessageDigest implementation class. This class currently supports
|
||||
* MD5, SHA1, SHA256, SHA384, and SHA512
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public abstract class NativeDigest extends MessageDigestSpi
|
||||
implements Cloneable {
|
||||
|
||||
private static final int MECH_MD5 = 1;
|
||||
private static final int MECH_SHA1 = 2;
|
||||
private static final int MECH_SHA256 = 3;
|
||||
private static final int MECH_SHA224 = 4;
|
||||
private static final int MECH_SHA384 = 5;
|
||||
private static final int MECH_SHA512 = 6;
|
||||
|
||||
private final int digestLen;
|
||||
private final int mech;
|
||||
|
||||
// field for ensuring native memory is freed
|
||||
private DigestContextRef pCtxt = null;
|
||||
|
||||
private static class DigestContextRef extends PhantomReference<NativeDigest>
|
||||
implements Comparable<DigestContextRef> {
|
||||
|
||||
private static ReferenceQueue<NativeDigest> refQueue =
|
||||
new ReferenceQueue<NativeDigest>();
|
||||
|
||||
// Needed to keep these references from being GC'ed until when their
|
||||
// referents are GC'ed so we can do post-mortem processing
|
||||
private static Set<DigestContextRef> refList =
|
||||
new ConcurrentSkipListSet<DigestContextRef>();
|
||||
// Collections.synchronizedSortedSet(new TreeSet<DigestContextRef>());
|
||||
|
||||
private final long id;
|
||||
private final int mech;
|
||||
|
||||
private static void drainRefQueueBounded() {
|
||||
while (true) {
|
||||
DigestContextRef next = (DigestContextRef) refQueue.poll();
|
||||
if (next == null) break;
|
||||
next.dispose(true);
|
||||
}
|
||||
}
|
||||
|
||||
DigestContextRef(NativeDigest nc, long id, int mech) {
|
||||
super(nc, refQueue);
|
||||
this.id = id;
|
||||
this.mech = mech;
|
||||
refList.add(this);
|
||||
UcryptoProvider.debug("Resource: track Digest Ctxt " + this.id);
|
||||
drainRefQueueBounded();
|
||||
}
|
||||
|
||||
public int compareTo(DigestContextRef other) {
|
||||
if (this.id == other.id) {
|
||||
return 0;
|
||||
} else {
|
||||
return (this.id < other.id) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
void dispose(boolean needFree) {
|
||||
refList.remove(this);
|
||||
try {
|
||||
if (needFree) {
|
||||
UcryptoProvider.debug("Resource: free Digest Ctxt " + this.id);
|
||||
NativeDigest.nativeFree(mech, id);
|
||||
} else UcryptoProvider.debug("Resource: stop tracking Digest Ctxt " + this.id);
|
||||
} finally {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NativeDigest(int mech, int digestLen) {
|
||||
this.digestLen = digestLen;
|
||||
this.mech = mech;
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected int engineGetDigestLength() {
|
||||
return digestLen;
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected synchronized void engineReset() {
|
||||
if (pCtxt != null) {
|
||||
pCtxt.dispose(true);
|
||||
pCtxt = null;
|
||||
}
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected synchronized byte[] engineDigest() {
|
||||
byte[] digest = new byte[digestLen];
|
||||
try {
|
||||
int len = engineDigest(digest, 0, digestLen);
|
||||
if (len != digestLen) {
|
||||
throw new UcryptoException("Digest length mismatch");
|
||||
}
|
||||
return digest;
|
||||
} catch (DigestException de) {
|
||||
throw new UcryptoException("Internal error", de);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected synchronized int engineDigest(byte[] out, int ofs, int len)
|
||||
throws DigestException {
|
||||
if (len < digestLen) {
|
||||
throw new DigestException("Output buffer must be at least " +
|
||||
digestLen + " bytes long");
|
||||
}
|
||||
if ((ofs < 0) || (len < 0) || (ofs > out.length - len)) {
|
||||
throw new DigestException("Buffer too short to store digest");
|
||||
}
|
||||
|
||||
if (pCtxt == null) {
|
||||
pCtxt = new DigestContextRef(this, nativeInit(mech), mech);
|
||||
}
|
||||
try {
|
||||
int status = nativeDigest(mech, pCtxt.id, out, ofs, digestLen);
|
||||
if (status != 0) {
|
||||
throw new DigestException("Internal error: " + status);
|
||||
}
|
||||
} finally {
|
||||
pCtxt.dispose(false);
|
||||
pCtxt = null;
|
||||
}
|
||||
return digestLen;
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected synchronized void engineUpdate(byte in) {
|
||||
byte[] temp = { in };
|
||||
engineUpdate(temp, 0, 1);
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected synchronized void engineUpdate(byte[] in, int ofs, int len) {
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
if ((ofs < 0) || (len < 0) || (ofs > in.length - len)) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
if (pCtxt == null) {
|
||||
pCtxt = new DigestContextRef(this, nativeInit(mech), mech);
|
||||
}
|
||||
nativeUpdate(mech, pCtxt.id, in, ofs, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone this digest.
|
||||
*/
|
||||
public synchronized Object clone() throws CloneNotSupportedException {
|
||||
NativeDigest copy = (NativeDigest) super.clone();
|
||||
// re-work the fields that cannot be copied over
|
||||
if (pCtxt != null) {
|
||||
copy.pCtxt = new DigestContextRef(this, nativeClone(mech, pCtxt.id), mech);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
// return pointer to the context
|
||||
protected static native long nativeInit(int mech);
|
||||
// return status code; always 0
|
||||
protected static native int nativeUpdate(int mech, long pCtxt, byte[] in, int ofs, int inLen);
|
||||
// return status code; always 0
|
||||
protected static native int nativeDigest(int mech, long pCtxt, byte[] out, int ofs, int digestLen);
|
||||
// return pointer to the duplicated context
|
||||
protected static native long nativeClone(int mech, long pCtxt);
|
||||
// free the specified context
|
||||
private native static void nativeFree(int mech, long id);
|
||||
|
||||
|
||||
public static final class MD5 extends NativeDigest {
|
||||
public MD5() {
|
||||
super(MECH_MD5, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SHA1 extends NativeDigest {
|
||||
public SHA1() {
|
||||
super(MECH_SHA1, 20);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SHA256 extends NativeDigest {
|
||||
public SHA256() {
|
||||
super(MECH_SHA256, 32);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class SHA384 extends NativeDigest {
|
||||
public SHA384() {
|
||||
super(MECH_SHA384, 48);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class SHA512 extends NativeDigest {
|
||||
public SHA512() {
|
||||
super(MECH_SHA512, 64);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,422 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.security.*;
|
||||
import java.security.spec.*;
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
|
||||
/**
|
||||
* Cipher wrapper class utilizing ucrypto APIs. This class currently supports
|
||||
* - AES/GCM/NoPADDING
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
class NativeGCMCipher extends NativeCipher {
|
||||
|
||||
public static final class AesGcmNoPadding extends NativeGCMCipher {
|
||||
public AesGcmNoPadding() throws NoSuchAlgorithmException {
|
||||
super(-1);
|
||||
}
|
||||
}
|
||||
public static final class Aes128GcmNoPadding extends NativeGCMCipher {
|
||||
public Aes128GcmNoPadding() throws NoSuchAlgorithmException {
|
||||
super(16);
|
||||
}
|
||||
}
|
||||
public static final class Aes192GcmNoPadding extends NativeGCMCipher {
|
||||
public Aes192GcmNoPadding() throws NoSuchAlgorithmException {
|
||||
super(24);
|
||||
}
|
||||
}
|
||||
public static final class Aes256GcmNoPadding extends NativeGCMCipher {
|
||||
public Aes256GcmNoPadding() throws NoSuchAlgorithmException {
|
||||
super(32);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int DEFAULT_TAG_LEN = 128; // same as SunJCE provider
|
||||
|
||||
// buffer for storing AAD data; if null, meaning buffer content has been
|
||||
// supplied to native context
|
||||
private ByteArrayOutputStream aadBuffer = new ByteArrayOutputStream();
|
||||
|
||||
// buffer for storing input in decryption, not used for encryption
|
||||
private ByteArrayOutputStream ibuffer = null;
|
||||
|
||||
private int tagLen = DEFAULT_TAG_LEN;
|
||||
|
||||
/*
|
||||
* variables used for performing the GCM (key+iv) uniqueness check.
|
||||
* To use GCM mode safely, the cipher object must be re-initialized
|
||||
* with a different combination of key + iv values for each
|
||||
* ENCRYPTION operation. However, checking all past key + iv values
|
||||
* isn't feasible. Thus, we only do a per-instance check of the
|
||||
* key + iv values used in previous encryption.
|
||||
* For decryption operations, no checking is necessary.
|
||||
*/
|
||||
private boolean requireReinit = false;
|
||||
private byte[] lastEncKey = null;
|
||||
private byte[] lastEncIv = null;
|
||||
|
||||
NativeGCMCipher(int fixedKeySize) throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_AES_GCM, fixedKeySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void ensureInitialized() {
|
||||
if (!initialized) {
|
||||
if (aadBuffer != null && aadBuffer.size() > 0) {
|
||||
init(encrypt, keyValue, iv, tagLen, aadBuffer.toByteArray());
|
||||
aadBuffer = null;
|
||||
} else {
|
||||
init(encrypt, keyValue, iv, tagLen, null);
|
||||
}
|
||||
if (!initialized) {
|
||||
throw new UcryptoException("Cannot initialize Cipher");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getOutputSizeByOperation(int inLen, boolean isDoFinal) {
|
||||
if (inLen < 0) return 0;
|
||||
|
||||
if (!isDoFinal && (inLen == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = inLen + bytesBuffered;
|
||||
if (encrypt) {
|
||||
if (isDoFinal) {
|
||||
result += tagLen/8;
|
||||
}
|
||||
} else {
|
||||
if (ibuffer != null) {
|
||||
result += ibuffer.size();
|
||||
}
|
||||
if (isDoFinal) {
|
||||
result -= tagLen/8;
|
||||
}
|
||||
}
|
||||
if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset(boolean doCancel) {
|
||||
super.reset(doCancel);
|
||||
if (aadBuffer == null) {
|
||||
aadBuffer = new ByteArrayOutputStream();
|
||||
} else {
|
||||
aadBuffer.reset();
|
||||
}
|
||||
|
||||
if (ibuffer != null) {
|
||||
ibuffer.reset();
|
||||
}
|
||||
if (!encrypt) requireReinit = false;
|
||||
}
|
||||
|
||||
// actual init() implementation - caller should clone key and iv if needed
|
||||
protected void init(boolean encrypt, byte[] keyVal, byte[] ivVal, int tLen, byte[] aad) {
|
||||
reset(true);
|
||||
this.encrypt = encrypt;
|
||||
this.keyValue = keyVal;
|
||||
this.iv = ivVal;
|
||||
long pCtxtVal = NativeCipher.nativeInit(mech.value(), encrypt, keyValue, iv,
|
||||
tLen, aad);
|
||||
initialized = (pCtxtVal != 0L);
|
||||
if (initialized) {
|
||||
pCtxt = new CipherContextRef(this, pCtxtVal, encrypt);
|
||||
} else {
|
||||
throw new UcryptoException("Cannot initialize Cipher");
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized AlgorithmParameters engineGetParameters() {
|
||||
AlgorithmParameters params = null;
|
||||
try {
|
||||
if (iv != null) {
|
||||
GCMParameterSpec gcmSpec = new GCMParameterSpec(tagLen, iv.clone());
|
||||
params = AlgorithmParameters.getInstance("GCM");
|
||||
params.init(gcmSpec);
|
||||
}
|
||||
} catch (GeneralSecurityException e) {
|
||||
// NoSuchAlgorithmException, NoSuchProviderException
|
||||
// InvalidParameterSpecException
|
||||
throw new UcryptoException("Could not encode parameters", e);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key,
|
||||
AlgorithmParameterSpec params, SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
checkKey(key);
|
||||
if (opmode != Cipher.ENCRYPT_MODE &&
|
||||
opmode != Cipher.DECRYPT_MODE &&
|
||||
opmode != Cipher.WRAP_MODE &&
|
||||
opmode != Cipher.UNWRAP_MODE) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("Unsupported mode: " + opmode);
|
||||
}
|
||||
boolean doEncrypt = (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE);
|
||||
byte[] keyBytes = key.getEncoded().clone();
|
||||
byte[] ivBytes = null;
|
||||
if (params != null) {
|
||||
if (!(params instanceof GCMParameterSpec)) {
|
||||
throw new InvalidAlgorithmParameterException("GCMParameterSpec required");
|
||||
} else {
|
||||
tagLen = ((GCMParameterSpec) params).getTLen();
|
||||
ivBytes = ((GCMParameterSpec) params).getIV();
|
||||
}
|
||||
} else {
|
||||
if (doEncrypt) {
|
||||
tagLen = DEFAULT_TAG_LEN;
|
||||
|
||||
// generate IV if none supplied for encryption
|
||||
ivBytes = new byte[blockSize];
|
||||
new SecureRandom().nextBytes(ivBytes);
|
||||
} else {
|
||||
throw new InvalidAlgorithmParameterException("Parameters required for decryption");
|
||||
}
|
||||
}
|
||||
if (doEncrypt) {
|
||||
requireReinit = Arrays.equals(ivBytes, lastEncIv) &&
|
||||
Arrays.equals(keyBytes, lastEncKey);
|
||||
if (requireReinit) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("Cannot reuse iv for GCM encryption");
|
||||
}
|
||||
lastEncIv = ivBytes;
|
||||
lastEncKey = keyBytes;
|
||||
} else {
|
||||
requireReinit = false;
|
||||
ibuffer = new ByteArrayOutputStream();
|
||||
}
|
||||
init(doEncrypt, keyBytes, ivBytes, tagLen, null);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key, AlgorithmParameters params,
|
||||
SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
AlgorithmParameterSpec spec = null;
|
||||
if (params != null) {
|
||||
try {
|
||||
// mech must be UcryptoMech.CRYPTO_AES_GCM
|
||||
spec = params.getParameterSpec(GCMParameterSpec.class);
|
||||
} catch (InvalidParameterSpecException iaps) {
|
||||
throw new InvalidAlgorithmParameterException(iaps);
|
||||
}
|
||||
}
|
||||
engineInit(opmode, key, spec, random);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineUpdate(byte[] in, int inOfs, int inLen) {
|
||||
if (aadBuffer != null && aadBuffer.size() > 0) {
|
||||
// init again with AAD data
|
||||
init(encrypt, keyValue, iv, tagLen, aadBuffer.toByteArray());
|
||||
aadBuffer = null;
|
||||
}
|
||||
if (requireReinit) {
|
||||
throw new IllegalStateException
|
||||
("Must use either different key or iv for GCM encryption");
|
||||
}
|
||||
if (inLen > 0) {
|
||||
if (!encrypt) {
|
||||
ibuffer.write(in, inOfs, inLen);
|
||||
return null;
|
||||
}
|
||||
return super.engineUpdate(in, inOfs, inLen);
|
||||
} else return null;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineUpdate(byte[] in, int inOfs, int inLen, byte[] out,
|
||||
int outOfs) throws ShortBufferException {
|
||||
int len = getOutputSizeByOperation(inLen, false);
|
||||
if (out.length - outOfs < len) {
|
||||
throw new ShortBufferException("Output buffer must be "
|
||||
+ "(at least) " + len
|
||||
+ " bytes long");
|
||||
}
|
||||
if (aadBuffer != null && aadBuffer.size() > 0) {
|
||||
// init again with AAD data
|
||||
init(encrypt, keyValue, iv, tagLen, aadBuffer.toByteArray());
|
||||
aadBuffer = null;
|
||||
}
|
||||
if (requireReinit) {
|
||||
throw new IllegalStateException
|
||||
("Must use either different key or iv for GCM encryption");
|
||||
}
|
||||
if (inLen > 0) {
|
||||
if (!encrypt) {
|
||||
ibuffer.write(in, inOfs, inLen);
|
||||
return 0;
|
||||
} else {
|
||||
return super.engineUpdate(in, inOfs, inLen, out, outOfs);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineUpdateAAD(byte[] src, int srcOfs, int srcLen)
|
||||
throws IllegalStateException {
|
||||
|
||||
if ((src == null) || (srcOfs < 0) || (srcOfs + srcLen > src.length)) {
|
||||
throw new IllegalArgumentException("Invalid AAD");
|
||||
}
|
||||
if (keyValue == null) {
|
||||
throw new IllegalStateException("Need to initialize Cipher first");
|
||||
}
|
||||
if (requireReinit) {
|
||||
throw new IllegalStateException
|
||||
("Must use either different key or iv for GCM encryption");
|
||||
}
|
||||
if (aadBuffer != null) {
|
||||
aadBuffer.write(src, srcOfs, srcLen);
|
||||
} else {
|
||||
// update has already been called
|
||||
throw new IllegalStateException
|
||||
("Update has been called; no more AAD data");
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected void engineUpdateAAD(ByteBuffer src)
|
||||
throws IllegalStateException {
|
||||
if (src == null) {
|
||||
throw new IllegalArgumentException("Invalid AAD");
|
||||
}
|
||||
if (keyValue == null) {
|
||||
throw new IllegalStateException("Need to initialize Cipher first");
|
||||
}
|
||||
if (requireReinit) {
|
||||
throw new IllegalStateException
|
||||
("Must use either different key or iv for GCM encryption");
|
||||
}
|
||||
if (aadBuffer != null) {
|
||||
if (src.hasRemaining()) {
|
||||
byte[] srcBytes = new byte[src.remaining()];
|
||||
src.get(srcBytes);
|
||||
aadBuffer.write(srcBytes, 0, srcBytes.length);
|
||||
}
|
||||
} else {
|
||||
// update has already been called
|
||||
throw new IllegalStateException
|
||||
("Update has been called; no more AAD data");
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineDoFinal(byte[] in, int inOfs, int inLen)
|
||||
throws IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] out = new byte[getOutputSizeByOperation(inLen, true)];
|
||||
try {
|
||||
// delegate to the other engineDoFinal(...) method
|
||||
int k = engineDoFinal(in, inOfs, inLen, out, 0);
|
||||
if (out.length != k) {
|
||||
out = Arrays.copyOf(out, k);
|
||||
}
|
||||
return out;
|
||||
} catch (ShortBufferException e) {
|
||||
throw new UcryptoException("Internal Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineDoFinal(byte[] in, int inOfs, int inLen,
|
||||
byte[] out, int outOfs)
|
||||
throws ShortBufferException, IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
int len = getOutputSizeByOperation(inLen, true);
|
||||
if (out.length - outOfs < len) {
|
||||
throw new ShortBufferException("Output buffer must be "
|
||||
+ "(at least) " + len
|
||||
+ " bytes long");
|
||||
}
|
||||
if (aadBuffer != null && aadBuffer.size() > 0) {
|
||||
// init again with AAD data
|
||||
init(encrypt, keyValue, iv, tagLen, aadBuffer.toByteArray());
|
||||
aadBuffer = null;
|
||||
}
|
||||
if (requireReinit) {
|
||||
throw new IllegalStateException
|
||||
("Must use either different key or iv for GCM encryption");
|
||||
}
|
||||
if (!encrypt) {
|
||||
if (inLen > 0) {
|
||||
ibuffer.write(in, inOfs, inLen);
|
||||
}
|
||||
inLen = ibuffer.size();
|
||||
if (inLen < tagLen/8) {
|
||||
// Otherwise, Solaris lib will error out w/ CRYPTO_BUFFER_TOO_SMALL
|
||||
// when ucrypto_decrypt_final() is called
|
||||
throw new AEADBadTagException("Input too short - need tag");
|
||||
}
|
||||
// refresh 'in' to all buffered-up bytes
|
||||
in = ibuffer.toByteArray();
|
||||
inOfs = 0;
|
||||
ibuffer.reset();
|
||||
}
|
||||
try {
|
||||
return super.engineDoFinal(in, inOfs, inLen, out, outOfs);
|
||||
} catch (UcryptoException ue) {
|
||||
if (ue.getMessage().equals("CRYPTO_INVALID_MAC")) {
|
||||
throw new AEADBadTagException("Tag does not match");
|
||||
} else {
|
||||
// pass it up
|
||||
throw ue;
|
||||
}
|
||||
} finally {
|
||||
requireReinit = encrypt;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.lang.ref.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Key;
|
||||
import java.security.PublicKey;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.KeyFactorySpi;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.RSAPrivateCrtKeySpec;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
|
||||
/**
|
||||
* Wrapper class for native keys needed for using ucrypto APIs.
|
||||
* This class currently supports native RSA private/public keys.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
abstract class NativeKey implements Key {
|
||||
|
||||
private static final long serialVersionUID = 6812507588904302830L;
|
||||
|
||||
private final int numComponents;
|
||||
|
||||
NativeKey(int numComponents) {
|
||||
this.numComponents = numComponents;
|
||||
}
|
||||
|
||||
abstract long value();
|
||||
|
||||
int length() {
|
||||
return numComponents;
|
||||
}
|
||||
|
||||
public String getAlgorithm() { return "RSA"; }
|
||||
public String getFormat() { return "RAW"; }
|
||||
public byte[] getEncoded() {
|
||||
// not used; so not generated
|
||||
return null;
|
||||
}
|
||||
|
||||
private native static void nativeFree(long id, int numComponents);
|
||||
|
||||
static byte[] getMagnitude(BigInteger bi) {
|
||||
byte[] b = bi.toByteArray();
|
||||
if ((b.length > 1) && (b[0] == 0)) {
|
||||
int n = b.length - 1;
|
||||
byte[] newarray = new byte[n];
|
||||
System.arraycopy(b, 1, newarray, 0, n);
|
||||
b = newarray;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
static final class RSAPrivateCrt extends NativeKey implements RSAPrivateCrtKey {
|
||||
|
||||
private static final long serialVersionUID = 6812507588904302831L;
|
||||
|
||||
private final RSAPrivateCrtKeySpec keySpec;
|
||||
private final long keyId;
|
||||
|
||||
RSAPrivateCrt(KeySpec keySpec) throws InvalidKeySpecException {
|
||||
super(8);
|
||||
long pKey = 0L;
|
||||
if (keySpec instanceof RSAPrivateCrtKeySpec) {
|
||||
RSAPrivateCrtKeySpec ks = (RSAPrivateCrtKeySpec) keySpec;
|
||||
BigInteger mod = ks.getModulus();
|
||||
BigInteger publicExp = ks.getPublicExponent();
|
||||
BigInteger privateExp = ks.getPrivateExponent();
|
||||
BigInteger primeP = ks.getPrimeP();
|
||||
BigInteger primeQ = ks.getPrimeQ();
|
||||
BigInteger primeExpP = ks.getPrimeExponentP();
|
||||
BigInteger primeExpQ = ks.getPrimeExponentQ();
|
||||
BigInteger crtCoeff = ks.getCrtCoefficient();
|
||||
pKey = nativeInit(NativeKey.getMagnitude(mod),
|
||||
NativeKey.getMagnitude(publicExp),
|
||||
NativeKey.getMagnitude(privateExp),
|
||||
NativeKey.getMagnitude(primeP),
|
||||
NativeKey.getMagnitude(primeQ),
|
||||
NativeKey.getMagnitude(primeExpP),
|
||||
NativeKey.getMagnitude(primeExpQ),
|
||||
NativeKey.getMagnitude(crtCoeff));
|
||||
} else {
|
||||
throw new InvalidKeySpecException("Only supports RSAPrivateCrtKeySpec");
|
||||
}
|
||||
if (pKey == 0L) {
|
||||
throw new UcryptoException("Error constructing RSA PrivateKey");
|
||||
}
|
||||
// track native resource clean up
|
||||
new KeyRef(this, pKey);
|
||||
this.keySpec = (RSAPrivateCrtKeySpec) keySpec;
|
||||
this.keyId = pKey;
|
||||
}
|
||||
|
||||
long value() { return keyId; }
|
||||
public BigInteger getModulus() { return keySpec.getModulus(); };
|
||||
public BigInteger getPublicExponent() { return keySpec.getPublicExponent(); };
|
||||
public BigInteger getPrivateExponent() { return keySpec.getPrivateExponent(); };
|
||||
public BigInteger getPrimeP() { return keySpec.getPrimeP(); };
|
||||
public BigInteger getPrimeQ() { return keySpec.getPrimeQ(); };
|
||||
public BigInteger getPrimeExponentP() { return keySpec.getPrimeExponentP(); };
|
||||
public BigInteger getPrimeExponentQ() { return keySpec.getPrimeExponentQ(); };
|
||||
public BigInteger getCrtCoefficient() { return keySpec.getCrtCoefficient(); };
|
||||
|
||||
private native static long nativeInit(byte[] mod, byte[] pubExp, byte[] privExp,
|
||||
byte[] p, byte[] q,
|
||||
byte[] expP, byte[] expQ, byte[] crtCoeff);
|
||||
}
|
||||
|
||||
static final class RSAPublic extends NativeKey implements RSAPublicKey {
|
||||
|
||||
private static final long serialVersionUID = 6812507588904302832L;
|
||||
|
||||
private final RSAPublicKeySpec keySpec;
|
||||
private final long keyId;
|
||||
|
||||
RSAPublic(KeySpec keySpec) throws InvalidKeySpecException {
|
||||
super(2);
|
||||
long pKey = 0L;
|
||||
if (keySpec instanceof RSAPublicKeySpec) {
|
||||
RSAPublicKeySpec ks = (RSAPublicKeySpec) keySpec;
|
||||
BigInteger mod = ks.getModulus();
|
||||
BigInteger publicExp = ks.getPublicExponent();
|
||||
pKey = nativeInit(NativeKey.getMagnitude(mod),
|
||||
NativeKey.getMagnitude(publicExp));
|
||||
} else {
|
||||
throw new InvalidKeySpecException("Only supports RSAPublicKeySpec");
|
||||
}
|
||||
if (pKey == 0L) {
|
||||
throw new UcryptoException("Error constructing RSA PublicKey");
|
||||
}
|
||||
// track native resource clean up
|
||||
new KeyRef(this, pKey);
|
||||
this.keySpec = (RSAPublicKeySpec) keySpec;
|
||||
this.keyId = pKey;
|
||||
}
|
||||
|
||||
long value() { return keyId; }
|
||||
public BigInteger getModulus() { return keySpec.getModulus(); };
|
||||
public BigInteger getPublicExponent() { return keySpec.getPublicExponent(); };
|
||||
|
||||
private native static long nativeInit(byte[] mod, byte[] pubExp);
|
||||
}
|
||||
|
||||
// internal class for native resource cleanup
|
||||
private static class KeyRef extends PhantomReference<NativeKey>
|
||||
implements Comparable<KeyRef> {
|
||||
|
||||
private static ReferenceQueue<NativeKey> refQueue =
|
||||
new ReferenceQueue<NativeKey>();
|
||||
|
||||
// Needed to keep these references from being GC'ed until when their
|
||||
// referents are GC'ed so we can do post-mortem processing
|
||||
private static Set<KeyRef> refList =
|
||||
new ConcurrentSkipListSet<KeyRef>();
|
||||
|
||||
private final long id;
|
||||
private final int length;
|
||||
|
||||
private static void drainRefQueueBounded() {
|
||||
while (true) {
|
||||
KeyRef next = (KeyRef) refQueue.poll();
|
||||
if (next == null) break;
|
||||
next.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
KeyRef(NativeKey nk, long id) {
|
||||
super(nk, refQueue);
|
||||
this.id = id;
|
||||
this.length = nk.length();
|
||||
refList.add(this);
|
||||
UcryptoProvider.debug("Resource: track NativeKey " + this.id);
|
||||
drainRefQueueBounded();
|
||||
}
|
||||
|
||||
public int compareTo(KeyRef other) {
|
||||
if (this.id == other.id) {
|
||||
return 0;
|
||||
} else {
|
||||
return (this.id < other.id) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
refList.remove(this);
|
||||
UcryptoProvider.debug("Resource: free NativeKey " + this.id);
|
||||
try {
|
||||
NativeKey.nativeFree(id, length);
|
||||
} finally {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,448 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.Key;
|
||||
import java.security.PublicKey;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.RSAPrivateCrtKeySpec;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
import java.security.interfaces.RSAKey;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.InvalidParameterSpecException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherSpi;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.ShortBufferException;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec;
|
||||
import sun.security.util.KeyUtil;
|
||||
|
||||
/**
|
||||
* Asymmetric Cipher wrapper class utilizing ucrypto APIs. This class
|
||||
* currently supports
|
||||
* - RSA/ECB/NOPADDING
|
||||
* - RSA/ECB/PKCS1PADDING
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public class NativeRSACipher extends CipherSpi {
|
||||
// fields set in constructor
|
||||
private final UcryptoMech mech;
|
||||
private final int padLen;
|
||||
private final NativeRSAKeyFactory keyFactory;
|
||||
private AlgorithmParameterSpec spec;
|
||||
private SecureRandom random;
|
||||
|
||||
// Keep a cache of RSA keys and their RSA NativeKey for reuse.
|
||||
// When the RSA key is gc'ed, we let NativeKey phatom references cleanup
|
||||
// the native allocation
|
||||
private static final Map<Key, NativeKey> keyList =
|
||||
Collections.synchronizedMap(new WeakHashMap<Key, NativeKey>());
|
||||
|
||||
//
|
||||
// fields (re)set in every init()
|
||||
//
|
||||
private NativeKey key = null;
|
||||
private int outputSize = 0; // e.g. modulus size in bytes
|
||||
private boolean encrypt = true;
|
||||
private byte[] buffer;
|
||||
private int bufOfs = 0;
|
||||
|
||||
// public implementation classes
|
||||
public static final class NoPadding extends NativeRSACipher {
|
||||
public NoPadding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_RSA_X_509, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PKCS1Padding extends NativeRSACipher {
|
||||
public PKCS1Padding() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_RSA_PKCS, 11);
|
||||
}
|
||||
}
|
||||
|
||||
NativeRSACipher(UcryptoMech mech, int padLen)
|
||||
throws NoSuchAlgorithmException {
|
||||
this.mech = mech;
|
||||
this.padLen = padLen;
|
||||
this.keyFactory = new NativeRSAKeyFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
|
||||
// Disallow change of mode for now since currently it's explicitly
|
||||
// defined in transformation strings
|
||||
throw new NoSuchAlgorithmException("Unsupported mode " + mode);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected void engineSetPadding(String padding)
|
||||
throws NoSuchPaddingException {
|
||||
// Disallow change of padding for now since currently it's explicitly
|
||||
// defined in transformation strings
|
||||
throw new NoSuchPaddingException("Unsupported padding " + padding);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected int engineGetBlockSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineGetOutputSize(int inputLen) {
|
||||
return outputSize;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected byte[] engineGetIV() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected AlgorithmParameters engineGetParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineGetKeySize(Key key) throws InvalidKeyException {
|
||||
if (!(key instanceof RSAKey)) {
|
||||
throw new InvalidKeyException("RSAKey required");
|
||||
}
|
||||
int n = ((RSAKey)key).getModulus().bitLength();
|
||||
// strip off the leading extra 0x00 byte prefix
|
||||
int realByteSize = (n + 7) >> 3;
|
||||
return realByteSize * 8;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key, SecureRandom random)
|
||||
throws InvalidKeyException {
|
||||
try {
|
||||
engineInit(opmode, key, (AlgorithmParameterSpec)null, random);
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
throw new InvalidKeyException("init() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key newKey,
|
||||
AlgorithmParameterSpec params, SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
if (newKey == null) {
|
||||
throw new InvalidKeyException("Key cannot be null");
|
||||
}
|
||||
if (opmode != Cipher.ENCRYPT_MODE &&
|
||||
opmode != Cipher.DECRYPT_MODE &&
|
||||
opmode != Cipher.WRAP_MODE &&
|
||||
opmode != Cipher.UNWRAP_MODE) {
|
||||
throw new InvalidAlgorithmParameterException
|
||||
("Unsupported mode: " + opmode);
|
||||
}
|
||||
if (params != null) {
|
||||
if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
|
||||
throw new InvalidAlgorithmParameterException(
|
||||
"No Parameters can be specified");
|
||||
}
|
||||
spec = params;
|
||||
this.random = random; // for TLS RSA premaster secret
|
||||
}
|
||||
boolean doEncrypt = (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE);
|
||||
|
||||
// Make sure the proper opmode uses the proper key
|
||||
if (doEncrypt && (!(newKey instanceof RSAPublicKey))) {
|
||||
throw new InvalidKeyException("RSAPublicKey required for encryption");
|
||||
} else if (!doEncrypt && (!(newKey instanceof RSAPrivateCrtKey))) {
|
||||
throw new InvalidKeyException("RSAPrivateCrtKey required for decryption");
|
||||
}
|
||||
|
||||
NativeKey nativeKey = null;
|
||||
// Check keyList cache for a nativeKey
|
||||
nativeKey = keyList.get(newKey);
|
||||
if (nativeKey == null) {
|
||||
// With no existing nativeKey for this newKey, create one
|
||||
if (doEncrypt) {
|
||||
RSAPublicKey publicKey = (RSAPublicKey) newKey;
|
||||
try {
|
||||
nativeKey = (NativeKey) keyFactory.engineGeneratePublic
|
||||
(new RSAPublicKeySpec(publicKey.getModulus(), publicKey.getPublicExponent()));
|
||||
} catch (InvalidKeySpecException ikse) {
|
||||
throw new InvalidKeyException(ikse);
|
||||
}
|
||||
} else {
|
||||
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) newKey;
|
||||
try {
|
||||
nativeKey = (NativeKey) keyFactory.engineGeneratePrivate
|
||||
(new RSAPrivateCrtKeySpec(privateKey.getModulus(),
|
||||
privateKey.getPublicExponent(),
|
||||
privateKey.getPrivateExponent(),
|
||||
privateKey.getPrimeP(),
|
||||
privateKey.getPrimeQ(),
|
||||
privateKey.getPrimeExponentP(),
|
||||
privateKey.getPrimeExponentQ(),
|
||||
privateKey.getCrtCoefficient()));
|
||||
} catch (InvalidKeySpecException ikse) {
|
||||
throw new InvalidKeyException(ikse);
|
||||
}
|
||||
}
|
||||
|
||||
// Add nativeKey to keyList cache and associate it with newKey
|
||||
keyList.put(newKey, nativeKey);
|
||||
}
|
||||
|
||||
init(doEncrypt, nativeKey);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized void engineInit(int opmode, Key key, AlgorithmParameters params,
|
||||
SecureRandom random)
|
||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
if (params != null) {
|
||||
throw new InvalidAlgorithmParameterException("No Parameters can be specified");
|
||||
}
|
||||
engineInit(opmode, key, (AlgorithmParameterSpec) null, random);
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineUpdate(byte[] in, int inOfs, int inLen) {
|
||||
if (inLen > 0) {
|
||||
update(in, inOfs, inLen);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineUpdate(byte[] in, int inOfs, int inLen, byte[] out,
|
||||
int outOfs) throws ShortBufferException {
|
||||
if (out.length - outOfs < outputSize) {
|
||||
throw new ShortBufferException("Output buffer too small");
|
||||
}
|
||||
if (inLen > 0) {
|
||||
update(in, inOfs, inLen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineDoFinal(byte[] in, int inOfs, int inLen)
|
||||
throws IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] out = new byte[outputSize];
|
||||
try {
|
||||
// delegate to the other engineDoFinal(...) method
|
||||
int actualLen = engineDoFinal(in, inOfs, inLen, out, 0);
|
||||
if (actualLen != outputSize) {
|
||||
return Arrays.copyOf(out, actualLen);
|
||||
} else {
|
||||
return out;
|
||||
}
|
||||
} catch (ShortBufferException e) {
|
||||
throw new UcryptoException("Internal Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out,
|
||||
int outOfs)
|
||||
throws ShortBufferException, IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
if (inLen != 0) {
|
||||
update(in, inOfs, inLen);
|
||||
}
|
||||
return doFinal(out, outOfs, out.length - outOfs);
|
||||
}
|
||||
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized byte[] engineWrap(Key key) throws IllegalBlockSizeException,
|
||||
InvalidKeyException {
|
||||
try {
|
||||
byte[] encodedKey = key.getEncoded();
|
||||
if ((encodedKey == null) || (encodedKey.length == 0)) {
|
||||
throw new InvalidKeyException("Cannot get an encoding of " +
|
||||
"the key to be wrapped");
|
||||
}
|
||||
if (encodedKey.length > buffer.length) {
|
||||
throw new InvalidKeyException("Key is too long for wrapping");
|
||||
}
|
||||
return engineDoFinal(encodedKey, 0, encodedKey.length);
|
||||
} catch (BadPaddingException e) {
|
||||
// Should never happen for key wrapping
|
||||
throw new UcryptoException("Internal Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// see JCE spec
|
||||
@Override
|
||||
protected synchronized Key engineUnwrap(byte[] wrappedKey,
|
||||
String wrappedKeyAlgorithm, int wrappedKeyType)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException {
|
||||
|
||||
if (wrappedKey.length > buffer.length) {
|
||||
throw new InvalidKeyException("Key is too long for unwrapping");
|
||||
}
|
||||
|
||||
boolean isTlsRsaPremasterSecret =
|
||||
wrappedKeyAlgorithm.equals("TlsRsaPremasterSecret");
|
||||
Exception failover = null;
|
||||
|
||||
byte[] encodedKey = null;
|
||||
try {
|
||||
encodedKey = engineDoFinal(wrappedKey, 0, wrappedKey.length);
|
||||
} catch (BadPaddingException bpe) {
|
||||
if (isTlsRsaPremasterSecret) {
|
||||
failover = bpe;
|
||||
} else {
|
||||
throw new InvalidKeyException("Unwrapping failed", bpe);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new InvalidKeyException("Unwrapping failed", e);
|
||||
}
|
||||
|
||||
if (isTlsRsaPremasterSecret) {
|
||||
if (!(spec instanceof TlsRsaPremasterSecretParameterSpec)) {
|
||||
throw new IllegalStateException(
|
||||
"No TlsRsaPremasterSecretParameterSpec specified");
|
||||
}
|
||||
|
||||
// polish the TLS premaster secret
|
||||
encodedKey = KeyUtil.checkTlsPreMasterSecretKey(
|
||||
((TlsRsaPremasterSecretParameterSpec)spec).getClientVersion(),
|
||||
((TlsRsaPremasterSecretParameterSpec)spec).getServerVersion(),
|
||||
random, encodedKey, (failover != null));
|
||||
}
|
||||
|
||||
return NativeCipher.constructKey(wrappedKeyType,
|
||||
encodedKey, wrappedKeyAlgorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* calls ucrypto_encrypt(...) or ucrypto_decrypt(...)
|
||||
* @returns the length of output or an negative error status code
|
||||
*/
|
||||
private native static int nativeAtomic(int mech, boolean encrypt,
|
||||
long keyValue, int keyLength,
|
||||
byte[] in, int inLen,
|
||||
byte[] out, int ouOfs, int outLen);
|
||||
|
||||
// do actual initialization
|
||||
private void init(boolean encrypt, NativeKey key) {
|
||||
this.encrypt = encrypt;
|
||||
this.key = key;
|
||||
try {
|
||||
this.outputSize = engineGetKeySize(key)/8;
|
||||
} catch (InvalidKeyException ike) {
|
||||
throw new UcryptoException("Internal Error", ike);
|
||||
}
|
||||
this.buffer = new byte[outputSize];
|
||||
this.bufOfs = 0;
|
||||
}
|
||||
|
||||
// store the specified input into the internal buffer
|
||||
private void update(byte[] in, int inOfs, int inLen) {
|
||||
if ((inLen <= 0) || (in == null)) {
|
||||
return;
|
||||
}
|
||||
// buffer bytes internally until doFinal is called
|
||||
if ((bufOfs + inLen + (encrypt? padLen:0)) > buffer.length) {
|
||||
// lead to IllegalBlockSizeException when doFinal() is called
|
||||
bufOfs = buffer.length + 1;
|
||||
return;
|
||||
}
|
||||
System.arraycopy(in, inOfs, buffer, bufOfs, inLen);
|
||||
bufOfs += inLen;
|
||||
}
|
||||
|
||||
// return the actual non-negative output length
|
||||
private int doFinal(byte[] out, int outOfs, int outLen)
|
||||
throws ShortBufferException, IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
if (bufOfs > buffer.length) {
|
||||
throw new IllegalBlockSizeException(
|
||||
"Data must not be longer than " +
|
||||
(buffer.length - (encrypt ? padLen : 0)) + " bytes");
|
||||
}
|
||||
if (outLen < outputSize) {
|
||||
throw new ShortBufferException();
|
||||
}
|
||||
try {
|
||||
long keyValue = key.value();
|
||||
int k = nativeAtomic(mech.value(), encrypt, keyValue,
|
||||
key.length(), buffer, bufOfs,
|
||||
out, outOfs, outLen);
|
||||
if (k < 0) {
|
||||
if ( k == -16 || k == -64) {
|
||||
// -16: CRYPTO_ENCRYPTED_DATA_INVALID
|
||||
// -64: CKR_ENCRYPTED_DATA_INVALID, see bug 17459266
|
||||
UcryptoException ue = new UcryptoException(16);
|
||||
BadPaddingException bpe =
|
||||
new BadPaddingException("Invalid encryption data");
|
||||
bpe.initCause(ue);
|
||||
throw bpe;
|
||||
}
|
||||
throw new UcryptoException(-k);
|
||||
}
|
||||
|
||||
return k;
|
||||
} finally {
|
||||
bufOfs = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.lang.ref.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Key;
|
||||
import java.security.PublicKey;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.KeyFactorySpi;
|
||||
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.RSAPrivateCrtKeySpec;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
|
||||
/**
|
||||
* Ucrypto-private KeyFactory class for generating native keys
|
||||
* needed for using ucrypto APIs. Given that it's not used
|
||||
* externally, it only needs to support RSAPrivateCrtKeySpec
|
||||
* and RSAPublicKeySpec objects.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public final class NativeRSAKeyFactory extends KeyFactorySpi {
|
||||
|
||||
@Override
|
||||
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
|
||||
throws InvalidKeySpecException {
|
||||
return new NativeKey.RSAPrivateCrt(keySpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicKey engineGeneratePublic(KeySpec keySpec)
|
||||
throws InvalidKeySpecException {
|
||||
return new NativeKey.RSAPublic(keySpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T extends KeySpec> T
|
||||
engineGetKeySpec(Key key, Class<T> keySpec)
|
||||
throws InvalidKeySpecException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key engineTranslateKey(Key key) throws InvalidKeyException {
|
||||
// no need to support this
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -0,0 +1,445 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.lang.ref.*;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import java.security.SignatureSpi;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.SignatureException;
|
||||
import java.security.Key;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.interfaces.*;
|
||||
import java.security.spec.RSAPrivateCrtKeySpec;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import sun.security.rsa.RSAPadding;
|
||||
|
||||
/**
|
||||
* Signature implementation class. This class currently supports the
|
||||
* following algorithms:
|
||||
*
|
||||
* . RSA:
|
||||
* . MD5withRSA
|
||||
* . SHA1withRSA
|
||||
* . SHA256withRSA
|
||||
* . SHA384withRSA
|
||||
* . SHA512withRSA
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
class NativeRSASignature extends SignatureSpi {
|
||||
|
||||
private static final int PKCS1PADDING_LEN = 11;
|
||||
|
||||
// fields set in constructor
|
||||
private final UcryptoMech mech;
|
||||
private final int encodedLen;
|
||||
|
||||
// field for ensuring native memory is freed
|
||||
private SignatureContextRef pCtxt = null;
|
||||
|
||||
//
|
||||
// fields (re)set in every init()
|
||||
//
|
||||
private boolean initialized = false;
|
||||
private boolean sign = true;
|
||||
private int sigLength;
|
||||
private NativeKey key;
|
||||
private NativeRSAKeyFactory keyFactory; // may need a more generic type later
|
||||
|
||||
// public implementation classes
|
||||
public static final class MD5 extends NativeRSASignature {
|
||||
public MD5() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_MD5_RSA_PKCS, 34);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SHA1 extends NativeRSASignature {
|
||||
public SHA1() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_SHA1_RSA_PKCS, 35);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SHA256 extends NativeRSASignature {
|
||||
public SHA256() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_SHA256_RSA_PKCS, 51);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SHA384 extends NativeRSASignature {
|
||||
public SHA384() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_SHA384_RSA_PKCS, 67);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SHA512 extends NativeRSASignature {
|
||||
public SHA512() throws NoSuchAlgorithmException {
|
||||
super(UcryptoMech.CRYPTO_SHA512_RSA_PKCS, 83);
|
||||
}
|
||||
}
|
||||
|
||||
// internal class for native resource cleanup
|
||||
private static class SignatureContextRef extends PhantomReference<NativeRSASignature>
|
||||
implements Comparable<SignatureContextRef> {
|
||||
|
||||
private static ReferenceQueue<NativeRSASignature> refQueue =
|
||||
new ReferenceQueue<NativeRSASignature>();
|
||||
|
||||
// Needed to keep these references from being GC'ed until when their
|
||||
// referents are GC'ed so we can do post-mortem processing
|
||||
private static Set<SignatureContextRef> refList =
|
||||
new ConcurrentSkipListSet<SignatureContextRef>();
|
||||
// Collections.synchronizedSortedSet(new TreeSet<SignatureContextRef>());
|
||||
|
||||
private final long id;
|
||||
private final boolean sign;
|
||||
|
||||
private static void drainRefQueueBounded() {
|
||||
while (true) {
|
||||
SignatureContextRef next = (SignatureContextRef) refQueue.poll();
|
||||
if (next == null) break;
|
||||
next.dispose(true);
|
||||
}
|
||||
}
|
||||
|
||||
SignatureContextRef(NativeRSASignature ns, long id, boolean sign) {
|
||||
super(ns, refQueue);
|
||||
this.id = id;
|
||||
this.sign = sign;
|
||||
refList.add(this);
|
||||
UcryptoProvider.debug("Resource: track Signature Ctxt " + this.id);
|
||||
drainRefQueueBounded();
|
||||
}
|
||||
|
||||
public int compareTo(SignatureContextRef other) {
|
||||
if (this.id == other.id) {
|
||||
return 0;
|
||||
} else {
|
||||
return (this.id < other.id) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
void dispose(boolean doCancel) {
|
||||
refList.remove(this);
|
||||
try {
|
||||
if (doCancel) {
|
||||
UcryptoProvider.debug("Resource: free Signature Ctxt " + this.id);
|
||||
NativeRSASignature.nativeFinal(id, sign, null, 0, 0);
|
||||
} else {
|
||||
UcryptoProvider.debug("Resource: stop tracking Signature Ctxt " + this.id);
|
||||
}
|
||||
} finally {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NativeRSASignature(UcryptoMech mech, int encodedLen)
|
||||
throws NoSuchAlgorithmException {
|
||||
this.mech = mech;
|
||||
this.encodedLen = encodedLen;
|
||||
this.keyFactory = new NativeRSAKeyFactory();
|
||||
}
|
||||
|
||||
// deprecated but abstract
|
||||
@SuppressWarnings("deprecation")
|
||||
protected Object engineGetParameter(String param) throws InvalidParameterException {
|
||||
throw new UnsupportedOperationException("getParameter() not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void engineInitSign(PrivateKey privateKey)
|
||||
throws InvalidKeyException {
|
||||
if (privateKey == null) {
|
||||
throw new InvalidKeyException("Key must not be null");
|
||||
}
|
||||
NativeKey newKey = key;
|
||||
int newSigLength = sigLength;
|
||||
// Need to check RSA key length whenever a new private key is set
|
||||
if (privateKey != key) {
|
||||
if (privateKey instanceof RSAPrivateCrtKey) {
|
||||
RSAPrivateCrtKey rsaPrivKey = (RSAPrivateCrtKey) privateKey;
|
||||
BigInteger mod = rsaPrivKey.getModulus();
|
||||
newSigLength = checkRSAKeyLength(mod);
|
||||
try {
|
||||
newKey = (NativeKey) keyFactory.engineGeneratePrivate
|
||||
(new RSAPrivateCrtKeySpec(mod,
|
||||
rsaPrivKey.getPublicExponent(),
|
||||
rsaPrivKey.getPrivateExponent(),
|
||||
rsaPrivKey.getPrimeP(),
|
||||
rsaPrivKey.getPrimeQ(),
|
||||
rsaPrivKey.getPrimeExponentP(),
|
||||
rsaPrivKey.getPrimeExponentQ(),
|
||||
rsaPrivKey.getCrtCoefficient()));
|
||||
} catch (InvalidKeySpecException ikse) {
|
||||
throw new InvalidKeyException(ikse);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidKeyException("RSAPrivateCrtKey required");
|
||||
}
|
||||
}
|
||||
init(true, newKey, newSigLength);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected synchronized void engineInitVerify(PublicKey publicKey)
|
||||
throws InvalidKeyException {
|
||||
if (publicKey == null) {
|
||||
throw new InvalidKeyException("Key must not be null");
|
||||
}
|
||||
NativeKey newKey = key;
|
||||
int newSigLength = sigLength;
|
||||
// Need to check RSA key length whenever a new public key is set
|
||||
if (publicKey != key) {
|
||||
if (publicKey instanceof RSAPublicKey) {
|
||||
BigInteger mod = ((RSAPublicKey) publicKey).getModulus();
|
||||
newSigLength = checkRSAKeyLength(mod);
|
||||
try {
|
||||
newKey = (NativeKey) keyFactory.engineGeneratePublic
|
||||
(new RSAPublicKeySpec(mod, ((RSAPublicKey) publicKey).getPublicExponent()));
|
||||
} catch (InvalidKeySpecException ikse) {
|
||||
throw new InvalidKeyException(ikse);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidKeyException("RSAPublicKey required");
|
||||
}
|
||||
}
|
||||
init(false, newKey, newSigLength);
|
||||
}
|
||||
|
||||
// deprecated but abstract
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
|
||||
throw new UnsupportedOperationException("setParameter() not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized byte[] engineSign() throws SignatureException {
|
||||
byte[] sig = new byte[sigLength];
|
||||
int rv = doFinal(sig, 0, sigLength);
|
||||
if (rv < 0) {
|
||||
throw new SignatureException(new UcryptoException(-rv));
|
||||
}
|
||||
return sig;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized int engineSign(byte[] outbuf, int offset, int len)
|
||||
throws SignatureException {
|
||||
if (outbuf == null || (offset < 0) || (outbuf.length < (offset + sigLength))
|
||||
|| (len < sigLength)) {
|
||||
throw new SignatureException("Invalid output buffer");
|
||||
}
|
||||
int rv = doFinal(outbuf, offset, sigLength);
|
||||
if (rv < 0) {
|
||||
throw new SignatureException(new UcryptoException(-rv));
|
||||
}
|
||||
return sigLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void engineUpdate(byte b) throws SignatureException {
|
||||
byte[] in = { b };
|
||||
int rv = update(in, 0, 1);
|
||||
if (rv < 0) {
|
||||
throw new SignatureException(new UcryptoException(-rv));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void engineUpdate(byte[] in, int inOfs, int inLen)
|
||||
throws SignatureException {
|
||||
if (in == null || inOfs < 0 || inLen == 0) return;
|
||||
|
||||
int rv = update(in, inOfs, inLen);
|
||||
if (rv < 0) {
|
||||
throw new SignatureException(new UcryptoException(-rv));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void engineUpdate(ByteBuffer in) {
|
||||
if (in == null || in.remaining() == 0) return;
|
||||
|
||||
if (in instanceof DirectBuffer == false) {
|
||||
// cannot do better than default impl
|
||||
super.engineUpdate(in);
|
||||
return;
|
||||
}
|
||||
long inAddr = ((DirectBuffer)in).address();
|
||||
int inOfs = in.position();
|
||||
int inLen = in.remaining();
|
||||
|
||||
int rv = update((inAddr + inOfs), inLen);
|
||||
if (rv < 0) {
|
||||
throw new UcryptoException(-rv);
|
||||
}
|
||||
in.position(inOfs + inLen);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized boolean engineVerify(byte[] sigBytes) throws SignatureException {
|
||||
return engineVerify(sigBytes, 0, sigBytes.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized boolean engineVerify(byte[] sigBytes, int sigOfs, int sigLen)
|
||||
throws SignatureException {
|
||||
if (sigBytes == null || (sigOfs < 0) || (sigBytes.length < (sigOfs + this.sigLength))
|
||||
|| (sigLen < this.sigLength)) {
|
||||
throw new SignatureException("Invalid signature buffer");
|
||||
}
|
||||
|
||||
int rv = doFinal(sigBytes, sigOfs, sigLen);
|
||||
if (rv == 0) {
|
||||
return true;
|
||||
} else {
|
||||
UcryptoProvider.debug("Signature: " + mech + " verification error " +
|
||||
new UcryptoException(-rv).getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void reset(boolean doCancel) {
|
||||
initialized = false;
|
||||
if (pCtxt != null) {
|
||||
pCtxt.dispose(doCancel);
|
||||
pCtxt = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calls ucrypto_sign_init(...) or ucrypto_verify_init(...)
|
||||
* @return pointer to the context
|
||||
*/
|
||||
private native static long nativeInit(int mech, boolean sign,
|
||||
long keyValue, int keyLength);
|
||||
|
||||
/**
|
||||
* calls ucrypto_sign_update(...) or ucrypto_verify_update(...)
|
||||
* @returns an error status code (0 means SUCCESS)
|
||||
*/
|
||||
private native static int nativeUpdate(long pContext, boolean sign,
|
||||
byte[] in, int inOfs, int inLen);
|
||||
/**
|
||||
* calls ucrypto_sign_update(...) or ucrypto_verify_update(...)
|
||||
* @returns an error status code (0 means SUCCESS)
|
||||
*/
|
||||
private native static int nativeUpdate(long pContext, boolean sign,
|
||||
long pIn, int inLen);
|
||||
|
||||
/**
|
||||
* calls ucrypto_sign_final(...) or ucrypto_verify_final(...)
|
||||
* @returns the length of signature bytes or verification status.
|
||||
* If negative, it indicates an error status code
|
||||
*/
|
||||
private native static int nativeFinal(long pContext, boolean sign,
|
||||
byte[] sig, int sigOfs, int sigLen);
|
||||
|
||||
// actual init() implementation - caller should clone key if needed
|
||||
private void init(boolean sign, NativeKey key, int sigLength) {
|
||||
reset(true);
|
||||
this.sign = sign;
|
||||
this.sigLength = sigLength;
|
||||
this.key = key;
|
||||
long pCtxtVal = nativeInit(mech.value(), sign, key.value(),
|
||||
key.length());
|
||||
initialized = (pCtxtVal != 0L);
|
||||
if (initialized) {
|
||||
pCtxt = new SignatureContextRef(this, pCtxtVal, sign);
|
||||
} else {
|
||||
throw new UcryptoException("Cannot initialize Signature");
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureInitialized() {
|
||||
if (!initialized) {
|
||||
init(sign, key, sigLength);
|
||||
if (!initialized) {
|
||||
throw new UcryptoException("Cannot initialize Signature");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns 0 (success) or negative (ucrypto error occurred)
|
||||
private int update(byte[] in, int inOfs, int inLen) {
|
||||
if (inOfs < 0 || inOfs + inLen > in.length) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
ensureInitialized();
|
||||
int k = nativeUpdate(pCtxt.id, sign, in, inOfs, inLen);
|
||||
if (k < 0) {
|
||||
reset(false);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
// returns 0 (success) or negative (ucrypto error occurred)
|
||||
private int update(long pIn, int inLen) {
|
||||
ensureInitialized();
|
||||
int k = nativeUpdate(pCtxt.id, sign, pIn, inLen);
|
||||
if (k < 0) {
|
||||
reset(false);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
// returns 0 (success) or negative (ucrypto error occurred)
|
||||
private int doFinal(byte[] sigBytes, int sigOfs, int sigLen) {
|
||||
try {
|
||||
ensureInitialized();
|
||||
int k = nativeFinal(pCtxt.id, sign, sigBytes, sigOfs, sigLen);
|
||||
return k;
|
||||
} finally {
|
||||
reset(false);
|
||||
}
|
||||
}
|
||||
|
||||
// check and return RSA key size in number of bytes
|
||||
private int checkRSAKeyLength(BigInteger mod) throws InvalidKeyException {
|
||||
int keySize = (mod.bitLength() + 7) >> 3;
|
||||
int maxDataSize = keySize - PKCS1PADDING_LEN;
|
||||
if (maxDataSize < encodedLen) {
|
||||
throw new InvalidKeyException
|
||||
("Key is too short for this signature algorithm");
|
||||
}
|
||||
return keySize;
|
||||
}
|
||||
}
|
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.util.*;
|
||||
import java.security.ProviderException;
|
||||
|
||||
/**
|
||||
* The exception class used by SunUcrypto provider. An exception
|
||||
* object of this class indicates that a function call to the underlying
|
||||
* native calls returned a value not equal to CRYPTO_SUCCESS.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public final class UcryptoException extends ProviderException {
|
||||
|
||||
private static final long serialVersionUID = -933864511110035746L;
|
||||
|
||||
// NOTE: check /usr/include/sys/crypto/common.h for updates
|
||||
private static final String ERROR_MSG[] = {
|
||||
"CRYPTO_SUCCESS",
|
||||
"CRYPTO_CANCEL",
|
||||
"CRYPTO_HOST_MEMORY",
|
||||
"CRYPTO_GENERAL_ERROR",
|
||||
"CRYPTO_FAILED",
|
||||
"CRYPTO_ARGUMENTS_BAD",
|
||||
"CRYPTO_ATTRIBUTE_READ_ONLY",
|
||||
"CRYPTO_ATTRIBUTE_SENSITIVE",
|
||||
"CRYPTO_ATTRIBUTE_TYPE_INVALID",
|
||||
"CRYPTO_ATTRIBUTE_VALUE_INVALID",
|
||||
"CRYPTO_CANCELED",
|
||||
"CRYPTO_DATA_INVALID",
|
||||
"CRYPTO_DATA_LEN_RANGE",
|
||||
"CRYPTO_DEVICE_ERROR",
|
||||
"CRYPTO_DEVICE_MEMORY",
|
||||
"CRYPTO_DEVICE_REMOVED",
|
||||
"CRYPTO_ENCRYPTED_DATA_INVALID",
|
||||
"CRYPTO_ENCRYPTED_DATA_LEN_RANGE",
|
||||
"CRYPTO_KEY_HANDLE_INVALID",
|
||||
"CRYPTO_KEY_SIZE_RANGE",
|
||||
"CRYPTO_KEY_TYPE_INCONSISTENT",
|
||||
"CRYPTO_KEY_NOT_NEEDED",
|
||||
"CRYPTO_KEY_CHANGED",
|
||||
"CRYPTO_KEY_NEEDED",
|
||||
"CRYPTO_KEY_INDIGESTIBLE",
|
||||
"CRYPTO_KEY_FUNCTION_NOT_PERMITTED",
|
||||
"CRYPTO_KEY_NOT_WRAPPABLE",
|
||||
"CRYPTO_KEY_UNEXTRACTABLE",
|
||||
"CRYPTO_MECHANISM_INVALID",
|
||||
"CRYPTO_MECHANISM_PARAM_INVALID",
|
||||
"CRYPTO_OBJECT_HANDLE_INVALID",
|
||||
"CRYPTO_OPERATION_IS_ACTIVE",
|
||||
"CRYPTO_OPERATION_NOT_INITIALIZED",
|
||||
"CRYPTO_PIN_INCORRECT",
|
||||
"CRYPTO_PIN_INVALID",
|
||||
"CRYPTO_PIN_LEN_RANGE",
|
||||
"CRYPTO_PIN_EXPIRED",
|
||||
"CRYPTO_PIN_LOCKED",
|
||||
"CRYPTO_SESSION_CLOSED",
|
||||
"CRYPTO_SESSION_COUNT",
|
||||
"CRYPTO_SESSION_HANDLE_INVALID",
|
||||
"CRYPTO_SESSION_READ_ONLY",
|
||||
"CRYPTO_SESSION_EXISTS",
|
||||
"CRYPTO_SESSION_READ_ONLY_EXISTS",
|
||||
"CRYPTO_SESSION_READ_WRITE_SO_EXISTS",
|
||||
"CRYPTO_SIGNATURE_INVALID",
|
||||
"CRYPTO_SIGNATURE_LEN_RANGE",
|
||||
"CRYPTO_TEMPLATE_INCOMPLETE",
|
||||
"CRYPTO_TEMPLATE_INCONSISTENT",
|
||||
"CRYPTO_UNWRAPPING_KEY_HANDLE_INVALID",
|
||||
"CRYPTO_UNWRAPPING_KEY_SIZE_RANGE",
|
||||
"CRYPTO_UNWRAPPING_KEY_TYPE_INCONSISTENT",
|
||||
"CRYPTO_USER_ALREADY_LOGGED_IN",
|
||||
"CRYPTO_USER_NOT_LOGGED_IN",
|
||||
"CRYPTO_USER_PIN_NOT_INITIALIZED",
|
||||
"CRYPTO_USER_TYPE_INVALID",
|
||||
"CRYPTO_USER_ANOTHER_ALREADY_LOGGED_IN",
|
||||
"CRYPTO_USER_TOO_MANY_TYPES",
|
||||
"CRYPTO_WRAPPED_KEY_INVALID",
|
||||
"CRYPTO_WRAPPED_KEY_LEN_RANGE",
|
||||
"CRYPTO_WRAPPING_KEY_HANDLE_INVALID",
|
||||
"CRYPTO_WRAPPING_KEY_SIZE_RANGE",
|
||||
"CRYPTO_WRAPPING_KEY_TYPE_INCONSISTENT",
|
||||
"CRYPTO_RANDOM_SEED_NOT_SUPPORTED",
|
||||
"CRYPTO_RANDOM_NO_RNG",
|
||||
"CRYPTO_DOMAIN_PARAMS_INVALID",
|
||||
"CRYPTO_BUFFER_TOO_SMALL",
|
||||
"CRYPTO_INFORMATION_SENSITIVE",
|
||||
"CRYPTO_NOT_SUPPORTED",
|
||||
"CRYPTO_QUEUED",
|
||||
"CRYPTO_BUFFER_TOO_BIG",
|
||||
"CRYPTO_INVALID_CONTEXT",
|
||||
"CRYPTO_INVALID_MAC",
|
||||
"CRYPTO_MECH_NOT_SUPPORTED",
|
||||
"CRYPTO_INCONSISTENT_ATTRIBUTE",
|
||||
"CRYPTO_NO_PERMISSION",
|
||||
"CRYPTO_INVALID_PROVIDER_ID",
|
||||
"CRYPTO_VERSION_MISMATCH",
|
||||
"CRYPTO_BUSY",
|
||||
"CRYPTO_UNKNOWN_PROVIDER",
|
||||
"CRYPTO_MODVERIFICATION_FAILED",
|
||||
"CRYPTO_OLD_CTX_TEMPLATE",
|
||||
"CRYPTO_WEAK_KEY",
|
||||
"CRYPTO_FIPS140_ERROR"
|
||||
};
|
||||
|
||||
/**
|
||||
* The error code if this exception is triggered by a Ucrypto error.
|
||||
*/
|
||||
private final int errorCode;
|
||||
|
||||
/**
|
||||
* This method gets the corresponding text error message from a
|
||||
* predefined mapping. If mapping is not found, then it returns the error
|
||||
* code as a hex-string.
|
||||
*
|
||||
* @return The message or the error code; e.g. "CRYPTO_DATA_INVALID" or
|
||||
* "0x88".
|
||||
*/
|
||||
static String getErrorMessage(int errorCode) {
|
||||
String message;
|
||||
if (errorCode < ERROR_MSG.length) {
|
||||
message = ERROR_MSG[errorCode];
|
||||
} else {
|
||||
message = "0x" + Integer.toHexString(errorCode);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor taking the error code as defined for the CRYPTO_* constants
|
||||
*/
|
||||
public UcryptoException(int rv) {
|
||||
super(getErrorMessage(rv));
|
||||
this.errorCode = rv;
|
||||
}
|
||||
|
||||
public UcryptoException(String message) {
|
||||
super(message);
|
||||
errorCode = -1;
|
||||
}
|
||||
|
||||
public UcryptoException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
errorCode = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Ucrypto error code.
|
||||
*
|
||||
* @return The error code.
|
||||
*/
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Enum for representing the ucrypto mechanisms.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
// Check /usr/include/libsoftcrypto.h for updates
|
||||
public enum UcryptoMech {
|
||||
CRYPTO_AES_ECB(1, new String[]
|
||||
{ "Cipher.AES/ECB/NoPadding;com.oracle.security.ucrypto.NativeCipher$AesEcbNoPadding",
|
||||
"Cipher.AES/ECB/PKCS5Padding;com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesEcbPKCS5",
|
||||
"Cipher.AES_128/ECB/NoPadding;com.oracle.security.ucrypto.NativeCipher$Aes128EcbNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.1;AES_128/ECB/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.1;AES_128/ECB/NoPadding",
|
||||
"Cipher.AES_192/ECB/NoPadding;com.oracle.security.ucrypto.NativeCipher$Aes192EcbNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.21;AES_192/ECB/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.21;AES_192/ECB/NoPadding",
|
||||
"Cipher.AES_256/ECB/NoPadding;com.oracle.security.ucrypto.NativeCipher$Aes256EcbNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.41;AES_256/ECB/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.41;AES_256/ECB/NoPadding"
|
||||
}),
|
||||
CRYPTO_AES_CBC(2, new String[]
|
||||
{ "Cipher.AES/CBC/NoPadding;com.oracle.security.ucrypto.NativeCipher$AesCbcNoPadding",
|
||||
"Cipher.AES/CBC/PKCS5Padding;com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesCbcPKCS5",
|
||||
"Cipher.AES_128/CBC/NoPadding;com.oracle.security.ucrypto.NativeCipher$Aes128CbcNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.2;AES_128/CBC/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.2;AES_128/CBC/NoPadding",
|
||||
"Cipher.AES_192/CBC/NoPadding;com.oracle.security.ucrypto.NativeCipher$Aes192CbcNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.22;AES_192/CBC/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.22;AES_192/CBC/NoPadding",
|
||||
"Cipher.AES_256/CBC/NoPadding;com.oracle.security.ucrypto.NativeCipher$Aes256CbcNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.42;AES_256/CBC/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.42;AES_256/CBC/NoPadding"
|
||||
}),
|
||||
CRYPTO_AES_CBC_PAD(3, null), // No support from Solaris yet
|
||||
CRYPTO_AES_CTR(4, new String[]
|
||||
{ "Cipher.AES/CTR/NoPadding;com.oracle.security.ucrypto.NativeCipher$AesCtrNoPadding" }),
|
||||
CRYPTO_AES_CCM(5, null), // Cannot support due to lack of Java API which corresponds to CK_AES_CCM_PARAMS
|
||||
CRYPTO_AES_GCM(6, new String[]
|
||||
{ "Cipher.AES/GCM/NoPadding;com.oracle.security.ucrypto.NativeGCMCipher$AesGcmNoPadding",
|
||||
"Cipher.AES_128/GCM/NoPadding;com.oracle.security.ucrypto.NativeGCMCipher$Aes128GcmNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.6;AES_128/GCM/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.6;AES_128/GCM/NoPadding",
|
||||
"Cipher.AES_192/GCM/NoPadding;com.oracle.security.ucrypto.NativeGCMCipher$Aes192GcmNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.26;AES_192/GCM/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.26;AES_192/GCM/NoPadding",
|
||||
"Cipher.AES_256/GCM/NoPadding;com.oracle.security.ucrypto.NativeGCMCipher$Aes256GcmNoPadding",
|
||||
"Alg.Alias.Cipher.2.16.840.1.101.3.4.1.46;AES_256/GCM/NoPadding",
|
||||
"Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.46;AES_256/GCM/NoPadding",
|
||||
}),
|
||||
CRYPTO_AES_GMAC(7, null), // No support from Solaris yet
|
||||
CRYPTO_AES_CFB128(8, new String[]
|
||||
{ "Cipher.AES/CFB128/NoPadding;com.oracle.security.ucrypto.NativeCipher$AesCfb128NoPadding",
|
||||
"Cipher.AES/CFB128/PKCS5Padding;com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesCfb128PKCS5" }),
|
||||
CRYPTO_RSA_PKCS(31, new String[]
|
||||
{ "Cipher.RSA/ECB/PKCS1Padding;com.oracle.security.ucrypto.NativeRSACipher$PKCS1Padding" }),
|
||||
CRYPTO_RSA_X_509(32, new String[]
|
||||
{ "Cipher.RSA/ECB/NoPadding;com.oracle.security.ucrypto.NativeRSACipher$NoPadding" }),
|
||||
CRYPTO_MD5_RSA_PKCS(33, new String[]
|
||||
{ "Signature.MD5withRSA;com.oracle.security.ucrypto.NativeRSASignature$MD5",
|
||||
"Alg.Alias.Signature.1.2.840.113549.1.1.4;MD5withRSA",
|
||||
"Alg.Alias.Signature.OID.1.2.840.113549.1.1.4;MD5withRSA" }),
|
||||
CRYPTO_SHA1_RSA_PKCS(34, new String[]
|
||||
{ "Signature.SHA1withRSA;com.oracle.security.ucrypto.NativeRSASignature$SHA1",
|
||||
"Alg.Alias.Signature.1.2.840.113549.1.1.5;SHA1withRSA",
|
||||
"Alg.Alias.Signature.OID.1.2.840.113549.1.1.5;SHA1withRSA",
|
||||
"Alg.Alias.Signature.1.3.14.3.2.29;SHA1withRSA" }),
|
||||
CRYPTO_SHA256_RSA_PKCS(35, new String[]
|
||||
{ "Signature.SHA256withRSA;com.oracle.security.ucrypto.NativeRSASignature$SHA256",
|
||||
"Alg.Alias.Signature.1.2.840.113549.1.1.11;SHA256withRSA",
|
||||
"Alg.Alias.Signature.OID.1.2.840.113549.1.1.11;SHA256withRSA" }),
|
||||
CRYPTO_SHA384_RSA_PKCS(36, new String[]
|
||||
{ "Signature.SHA384withRSA;com.oracle.security.ucrypto.NativeRSASignature$SHA384",
|
||||
"Alg.Alias.Signature.1.2.840.113549.1.1.12;SHA384withRSA",
|
||||
"Alg.Alias.Signature.OID.1.2.840.113549.1.1.12;SHA384withRSA" }),
|
||||
CRYPTO_SHA512_RSA_PKCS(37, new String[]
|
||||
{ "Signature.SHA512withRSA;com.oracle.security.ucrypto.NativeRSASignature$SHA512",
|
||||
"Alg.Alias.Signature.1.2.840.113549.1.1.13;SHA512withRSA",
|
||||
"Alg.Alias.Signature.OID.1.2.840.113549.1.1.13;SHA512withRSA" });
|
||||
|
||||
private int mech;
|
||||
private String[] jceProps;
|
||||
|
||||
UcryptoMech(int mech, String[] jceProps) {
|
||||
this.mech = mech;
|
||||
this.jceProps = jceProps;
|
||||
}
|
||||
|
||||
public int value() { return mech; }
|
||||
public String[] jceProperties() { return jceProps; }
|
||||
}
|
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.oracle.security.ucrypto;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
import java.security.*;
|
||||
import sun.security.action.PutAllAction;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
* OracleUcrypto provider main class.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
public final class UcryptoProvider extends Provider {
|
||||
|
||||
private static final long serialVersionUID = 351251234302833L;
|
||||
|
||||
private static boolean DEBUG;
|
||||
private static HashMap<String, String> provProp;
|
||||
|
||||
static {
|
||||
try {
|
||||
DEBUG = Boolean.parseBoolean(AccessController.doPrivileged
|
||||
(new GetPropertyAction("com.oracle.security.ucrypto.debug")));
|
||||
|
||||
// cannot use LoadLibraryAction because that would make the native
|
||||
// library available to the bootclassloader, but we run in the
|
||||
// extension classloader.
|
||||
provProp = AccessController.doPrivileged
|
||||
(new PrivilegedAction<HashMap<String, String>>() {
|
||||
public HashMap<String, String> run() {
|
||||
try {
|
||||
System.loadLibrary("j2ucrypto");
|
||||
String osname = System.getProperty("os.name");
|
||||
if (osname.startsWith("SunOS")) {
|
||||
return new HashMap<String, String>();
|
||||
} else return null;
|
||||
} catch (Error err) {
|
||||
return null;
|
||||
} catch (SecurityException se) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (provProp != null) {
|
||||
boolean[] result = loadLibraries();
|
||||
if (result.length == 2) {
|
||||
if (result[0]) { // successfully loaded libmd
|
||||
provProp.put("MessageDigest.MD5",
|
||||
"com.oracle.security.ucrypto.NativeDigest$MD5");
|
||||
provProp.put("MessageDigest.SHA",
|
||||
"com.oracle.security.ucrypto.NativeDigest$SHA1");
|
||||
provProp.put("Alg.Alias.MessageDigest.SHA-1", "SHA");
|
||||
provProp.put("Alg.Alias.MessageDigest.SHA1", "SHA");
|
||||
provProp.put("MessageDigest.SHA-256",
|
||||
"com.oracle.security.ucrypto.NativeDigest$SHA256");
|
||||
provProp.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.1", "SHA-256");
|
||||
provProp.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.1", "SHA-256");
|
||||
|
||||
provProp.put("MessageDigest.SHA-384",
|
||||
"com.oracle.security.ucrypto.NativeDigest$SHA384");
|
||||
provProp.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.2", "SHA-384");
|
||||
provProp.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.2", "SHA-384");
|
||||
|
||||
provProp.put("MessageDigest.SHA-512",
|
||||
"com.oracle.security.ucrypto.NativeDigest$SHA512");
|
||||
provProp.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.3", "SHA-512");
|
||||
provProp.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.3", "SHA-512");
|
||||
|
||||
}
|
||||
if (result[1]) { // successfully loaded libsoftcrypto
|
||||
String supportedMechs = getMechList();
|
||||
debug("Prov: supported mechs = " + supportedMechs);
|
||||
for (UcryptoMech m : UcryptoMech.values()) {
|
||||
if (supportedMechs.indexOf(m.name() + ",") != -1) {
|
||||
String[] jceProps = m.jceProperties();
|
||||
// skip unsupported UcryptoMech
|
||||
if (jceProps == null) continue;
|
||||
for (int p = 0; p < jceProps.length; p++) {
|
||||
StringTokenizer st =
|
||||
new StringTokenizer(jceProps[p], ";");
|
||||
if (st.countTokens() != 2) {
|
||||
throw new RuntimeException("Wrong format: " + jceProps[p]);
|
||||
}
|
||||
provProp.put(st.nextToken(), st.nextToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
// NOTE: GCM support is only available since jdk 7
|
||||
provProp.put("AlgorithmParameters.GCM",
|
||||
"com.oracle.security.ucrypto.GCMParameters");
|
||||
}
|
||||
} else {
|
||||
debug("Prov: unexpected ucrypto library loading error, got " + result.length);
|
||||
}
|
||||
}
|
||||
} catch (AccessControlException ace) {
|
||||
// disable Ucrypto provider
|
||||
DEBUG = false;
|
||||
provProp = null;
|
||||
}
|
||||
}
|
||||
|
||||
static Provider provider = null;
|
||||
private static native boolean[] loadLibraries();
|
||||
private static native String getMechList();
|
||||
|
||||
static void debug(String msg) {
|
||||
if (DEBUG) {
|
||||
System.out.println("UCrypto/" + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public UcryptoProvider() {
|
||||
super("OracleUcrypto", 1.9d, "Provider using Oracle Ucrypto API");
|
||||
if (provProp != null) {
|
||||
AccessController.doPrivileged(new PutAllAction(this, provProp));
|
||||
}
|
||||
if (provider == null) provider = this;
|
||||
}
|
||||
|
||||
public UcryptoProvider(String configName) {
|
||||
super("OracleUcrypto", 1.9d, "Provider using Oracle Ucrypto API");
|
||||
try {
|
||||
if (provProp != null) {
|
||||
HashMap<String, String> customProvProp =
|
||||
new HashMap<String, String>(provProp);
|
||||
Config c = new Config(configName);
|
||||
String[] disabledServices = c.getDisabledServices();
|
||||
for (int i = 0; i < disabledServices.length; i++) {
|
||||
if (customProvProp.remove(disabledServices[i]) != null) {
|
||||
debug("Prov: remove config-disabled service " + disabledServices[i]);
|
||||
} else {
|
||||
debug("Prov: ignore unsupported config-disabled service " +
|
||||
disabledServices[i]);
|
||||
}
|
||||
}
|
||||
AccessController.doPrivileged(new PutAllAction(this, customProvProp));
|
||||
}
|
||||
} catch (IOException ioe) { // thrown by Config
|
||||
throw new UcryptoException("Error parsing Config", ioe);
|
||||
}
|
||||
if (provider == null) provider = this;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return this == obj;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#
|
||||
# Configuration file for the OracleUcrypto provider
|
||||
#
|
||||
disabledServices = {
|
||||
# disabled due to Solaris bug 7121679
|
||||
Cipher.AES/CFB128/PKCS5Padding
|
||||
Cipher.AES/CFB128/NoPadding
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,24 +23,28 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMNetMaskV6.java */
|
||||
#ifndef _Included_com_oracle_security_ucrypto_NativeCrypto
|
||||
#define _Included_com_oracle_security_ucrypto_NativeCrypto
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
#undef com_oracle_security_ucrypto_NativeDigest_MECH_MD5
|
||||
#define com_oracle_security_ucrypto_NativeDigest_MECH_MD5 1L
|
||||
#undef com_oracle_security_ucrypto_NativeDigest_MECH_SHA1
|
||||
#define com_oracle_security_ucrypto_NativeDigest_MECH_SHA1 2L
|
||||
#undef com_oracle_security_ucrypto_NativeDigest_MECH_SHA256
|
||||
#define com_oracle_security_ucrypto_NativeDigest_MECH_SHA256 3L
|
||||
#undef com_oracle_security_ucrypto_NativeDigest_MECH_SHA224
|
||||
#define com_oracle_security_ucrypto_NativeDigest_MECH_SHA224 4L
|
||||
#undef com_oracle_security_ucrypto_NativeDigest_MECH_SHA384
|
||||
#define com_oracle_security_ucrypto_NativeDigest_MECH_SHA384 5L
|
||||
#undef com_oracle_security_ucrypto_NativeDigest_MECH_SHA512
|
||||
#define com_oracle_security_ucrypto_NativeDigest_MECH_SHA512 6L
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
#define DEBUG 0
|
||||
|
||||
class JDMNetMaskV6 extends JDMNetMask {
|
||||
private static final long serialVersionUID = 4505256777680576645L;
|
||||
|
||||
public JDMNetMaskV6(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public JDMNetMaskV6(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
protected PrincipalImpl createAssociatedPrincipal()
|
||||
throws UnknownHostException {
|
||||
return new NetMaskImpl(address.toString(), Integer.parseInt(mask));
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <link.h>
|
||||
#include "nativeFunc.h"
|
||||
|
||||
/* standard md5/md/softcrypto method names (ordering is from mapfile) */
|
||||
static const char MD5_INIT[] = "MD5Init";
|
||||
static const char MD5_UPDATE[] = "MD5Update";
|
||||
static const char MD5_FINAL[] = "MD5Final";
|
||||
static const char SHA1_INIT[] = "SHA1Init";
|
||||
static const char SHA1_UPDATE[] = "SHA1Update";
|
||||
static const char SHA1_FINAL[] = "SHA1Final";
|
||||
static const char SHA2_INIT[] = "SHA2Init";
|
||||
static const char SHA2_UPDATE[] = "SHA2Update";
|
||||
static const char SHA2_FINAL[] = "SHA2Final";
|
||||
static const char UCRYPTO_VERSION[] = "ucrypto_version";
|
||||
static const char UCRYPTO_GET_MECHLIST[] = "ucrypto_get_mechlist";
|
||||
static const char UCRYPTO_ENCRYPT_INIT[] = "ucrypto_encrypt_init";
|
||||
static const char UCRYPTO_ENCRYPT_UPDATE[] = "ucrypto_encrypt_update";
|
||||
static const char UCRYPTO_ENCRYPT_FINAL[] = "ucrypto_encrypt_final";
|
||||
static const char UCRYPTO_ENCRYPT[] = "ucrypto_encrypt";
|
||||
static const char UCRYPTO_DECRYPT_INIT[] = "ucrypto_decrypt_init";
|
||||
static const char UCRYPTO_DECRYPT_UPDATE[] = "ucrypto_decrypt_update";
|
||||
static const char UCRYPTO_DECRYPT_FINAL[] = "ucrypto_decrypt_final";
|
||||
static const char UCRYPTO_DECRYPT[] = "ucrypto_decrypt";
|
||||
static const char UCRYPTO_SIGN_INIT[] = "ucrypto_sign_init";
|
||||
static const char UCRYPTO_SIGN_UPDATE[] = "ucrypto_sign_update";
|
||||
static const char UCRYPTO_SIGN_FINAL[] = "ucrypto_sign_final";
|
||||
static const char UCRYPTO_VERIFY_INIT[] = "ucrypto_verify_init";
|
||||
static const char UCRYPTO_VERIFY_UPDATE[] = "ucrypto_verify_update";
|
||||
static const char UCRYPTO_VERIFY_FINAL[] = "ucrypto_verify_final";
|
||||
|
||||
/**
|
||||
* Initialize native T4 crypto function pointers
|
||||
*/
|
||||
jboolean* loadNative() {
|
||||
|
||||
jboolean* buf;
|
||||
void *lib;
|
||||
|
||||
buf = malloc(2 * sizeof(jboolean));
|
||||
buf[0] = buf[1] = JNI_FALSE;
|
||||
ftab = (T4CRYPTO_FUNCTION_TABLE_PTR) calloc(1, sizeof(T4CRYPTO_FUNCTION_TABLE));
|
||||
if (ftab == NULL) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lib = dlopen("libmd.so", RTLD_NOW);
|
||||
if (lib != NULL) {
|
||||
ftab->md5Init = (MD5INIT_FN_PTR) dlsym(lib, MD5_INIT);
|
||||
ftab->md5Update = (MD5UPDATE_FN_PTR) dlsym(lib, MD5_UPDATE);
|
||||
ftab->md5Final = (MD5FINAL_FN_PTR) dlsym(lib, MD5_FINAL);
|
||||
ftab->sha1Init = (SHA1INIT_FN_PTR) dlsym(lib, SHA1_INIT);
|
||||
ftab->sha1Update = (SHA1UPDATE_FN_PTR) dlsym(lib, SHA1_UPDATE);
|
||||
ftab->sha1Final = (SHA1FINAL_FN_PTR) dlsym(lib, SHA1_FINAL);
|
||||
ftab->sha2Init = (SHA2INIT_FN_PTR) dlsym(lib, SHA2_INIT);
|
||||
ftab->sha2Update = (SHA2UPDATE_FN_PTR) dlsym(lib, SHA2_UPDATE);
|
||||
ftab->sha2Final = (SHA2FINAL_FN_PTR) dlsym(lib, SHA2_FINAL);
|
||||
if (ftab->md5Init != NULL && ftab->md5Update != NULL &&
|
||||
ftab->md5Final != NULL && ftab->sha1Init != NULL &&
|
||||
ftab->sha1Update != NULL && ftab->sha1Final != NULL &&
|
||||
ftab->sha2Init != NULL && ftab->sha2Update != NULL &&
|
||||
ftab->sha2Final != NULL) {
|
||||
buf[0] = JNI_TRUE;
|
||||
} else {
|
||||
dlclose(lib);
|
||||
}
|
||||
}
|
||||
|
||||
lib = dlopen("libsoftcrypto.so", RTLD_NOW);
|
||||
if (lib != NULL) {
|
||||
// These APIs aren't available for v0 lib on Solaris 10
|
||||
ftab->ucryptoVersion = (UCRYPTO_VERSION_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_VERSION);
|
||||
ftab->ucryptoGetMechList = (UCRYPTO_GET_MECHLIST_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_GET_MECHLIST);
|
||||
//??
|
||||
ftab->ucryptoSignInit = (UCRYPTO_SIGN_INIT_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_SIGN_INIT);
|
||||
ftab->ucryptoSignUpdate = (UCRYPTO_SIGN_UPDATE_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_SIGN_UPDATE);
|
||||
ftab->ucryptoSignFinal = (UCRYPTO_SIGN_FINAL_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_SIGN_FINAL);
|
||||
ftab->ucryptoVerifyInit = (UCRYPTO_VERIFY_INIT_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_VERIFY_INIT);
|
||||
ftab->ucryptoVerifyUpdate = (UCRYPTO_VERIFY_UPDATE_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_VERIFY_UPDATE);
|
||||
ftab->ucryptoVerifyFinal = (UCRYPTO_VERIFY_FINAL_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_VERIFY_FINAL);
|
||||
|
||||
// These should be avilable for all libsoftcrypto libs
|
||||
ftab->ucryptoEncryptInit = (UCRYPTO_ENCRYPT_INIT_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_ENCRYPT_INIT);
|
||||
ftab->ucryptoEncryptUpdate = (UCRYPTO_ENCRYPT_UPDATE_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_ENCRYPT_UPDATE);
|
||||
ftab->ucryptoEncryptFinal = (UCRYPTO_ENCRYPT_FINAL_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_ENCRYPT_FINAL);
|
||||
ftab->ucryptoEncrypt = (UCRYPTO_ENCRYPT_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_ENCRYPT);
|
||||
|
||||
ftab->ucryptoDecryptInit = (UCRYPTO_DECRYPT_INIT_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_DECRYPT_INIT);
|
||||
ftab->ucryptoDecryptUpdate = (UCRYPTO_DECRYPT_UPDATE_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_DECRYPT_UPDATE);
|
||||
ftab->ucryptoDecryptFinal = (UCRYPTO_DECRYPT_FINAL_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_DECRYPT_FINAL);
|
||||
ftab->ucryptoDecrypt = (UCRYPTO_DECRYPT_FN_PTR)
|
||||
dlsym(lib, UCRYPTO_DECRYPT);
|
||||
|
||||
if (ftab->ucryptoEncryptInit != NULL &&
|
||||
ftab->ucryptoEncryptUpdate != NULL &&
|
||||
ftab->ucryptoEncryptFinal != NULL &&
|
||||
ftab->ucryptoEncrypt != NULL &&
|
||||
ftab->ucryptoDecryptInit != NULL &&
|
||||
ftab->ucryptoDecryptUpdate != NULL &&
|
||||
ftab->ucryptoDecryptFinal != NULL &&
|
||||
ftab->ucryptoDecrypt != NULL) {
|
||||
buf[1] = JNI_TRUE;
|
||||
} else {
|
||||
dlclose(lib);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef SPARCT4_NATIVE_FUNC_H
|
||||
#define SPARCT4_NATIVE_FUNC_H
|
||||
#include <md5.h>
|
||||
#include <sha1.h>
|
||||
#include <sha2.h>
|
||||
#include <libsoftcrypto.h>
|
||||
|
||||
jboolean* loadNative();
|
||||
|
||||
/* function pointer definitions */
|
||||
|
||||
typedef void (*MD5INIT_FN_PTR)(MD5_CTX *context);
|
||||
|
||||
typedef void (*MD5UPDATE_FN_PTR)
|
||||
(MD5_CTX *context, unsigned char *input,
|
||||
unsigned int inlen);
|
||||
|
||||
typedef void (*MD5FINAL_FN_PTR)
|
||||
(unsigned char *output, MD5_CTX *context);
|
||||
|
||||
typedef void (*SHA1INIT_FN_PTR)(SHA1_CTX *context);
|
||||
|
||||
typedef void (*SHA1UPDATE_FN_PTR)
|
||||
(SHA1_CTX *context, unsigned char *input,
|
||||
unsigned int inlen);
|
||||
|
||||
typedef void (*SHA1FINAL_FN_PTR)
|
||||
(unsigned char *output, SHA1_CTX *context);
|
||||
|
||||
typedef void (*SHA2INIT_FN_PTR)(uint64_t mech, SHA2_CTX *context);
|
||||
|
||||
typedef void (*SHA2UPDATE_FN_PTR)
|
||||
(SHA2_CTX *context, unsigned char *input,
|
||||
unsigned int inlen);
|
||||
|
||||
typedef void (*SHA2FINAL_FN_PTR)
|
||||
(unsigned char *output, SHA2_CTX *context);
|
||||
|
||||
typedef int (*UCRYPTO_VERSION_FN_PTR)();
|
||||
|
||||
typedef int (*UCRYPTO_GET_MECHLIST_FN_PTR)(char *str);
|
||||
|
||||
typedef int (*UCRYPTO_ENCRYPT_INIT_FN_PTR)
|
||||
(crypto_ctx_t *context, ucrypto_mech_t mech_type,
|
||||
uchar_t *key_str, size_t key_len,
|
||||
void *iv, size_t iv_len);
|
||||
|
||||
typedef int (*UCRYPTO_ENCRYPT_UPDATE_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *in,
|
||||
size_t in_len, uchar_t *out, size_t *out_len);
|
||||
|
||||
typedef int (*UCRYPTO_ENCRYPT_FINAL_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *out,
|
||||
size_t *out_len);
|
||||
|
||||
typedef int (*UCRYPTO_ENCRYPT_FN_PTR)
|
||||
(ucrypto_mech_t mech_type, uchar_t *key_str,
|
||||
size_t key_len, void *iv, size_t iv_len, uchar_t *in,
|
||||
size_t in_len, uchar_t *out, size_t *out_len);
|
||||
|
||||
typedef int (*UCRYPTO_DECRYPT_INIT_FN_PTR)
|
||||
(crypto_ctx_t *context,
|
||||
ucrypto_mech_t mech_type, uchar_t *key_str, size_t key_len,
|
||||
void *iv, size_t iv_len);
|
||||
|
||||
typedef int (*UCRYPTO_DECRYPT_UPDATE_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *in,
|
||||
size_t in_len, uchar_t *out, size_t *out_len);
|
||||
|
||||
typedef int (*UCRYPTO_DECRYPT_FINAL_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *out,
|
||||
size_t *out_len);
|
||||
|
||||
typedef int (*UCRYPTO_DECRYPT_FN_PTR)
|
||||
(ucrypto_mech_t mech_type, uchar_t *key_str,
|
||||
size_t key_len, void *iv, size_t iv_len, uchar_t *in,
|
||||
size_t in_len, uchar_t *out, size_t *out_len);
|
||||
|
||||
typedef int (*UCRYPTO_SIGN_INIT_FN_PTR)
|
||||
(crypto_ctx_t *context, ucrypto_mech_t mech_type,
|
||||
uchar_t *key_str, size_t key_len,
|
||||
void *iv, size_t iv_len);
|
||||
|
||||
typedef int (*UCRYPTO_SIGN_UPDATE_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *data_str, size_t data_len);
|
||||
|
||||
typedef int (*UCRYPTO_SIGN_FINAL_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *sig_str, size_t *sig_len);
|
||||
|
||||
typedef int (*UCRYPTO_VERIFY_INIT_FN_PTR)
|
||||
(crypto_ctx_t *context, ucrypto_mech_t mech_type,
|
||||
uchar_t *key_str, size_t key_len,
|
||||
void *iv, size_t iv_len);
|
||||
|
||||
typedef int (*UCRYPTO_VERIFY_UPDATE_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *data_str, size_t data_len);
|
||||
|
||||
typedef int (*UCRYPTO_VERIFY_FINAL_FN_PTR)
|
||||
(crypto_ctx_t *context, uchar_t *sig_str, size_t *sig_len);
|
||||
|
||||
|
||||
|
||||
/* dynamically resolved functions from libmd, and libsoftcrypto
|
||||
libraries */
|
||||
typedef struct T4CRYPTO_FUNCTION_TABLE {
|
||||
MD5INIT_FN_PTR md5Init;
|
||||
MD5UPDATE_FN_PTR md5Update;
|
||||
MD5FINAL_FN_PTR md5Final;
|
||||
SHA1INIT_FN_PTR sha1Init;
|
||||
SHA1UPDATE_FN_PTR sha1Update;
|
||||
SHA1FINAL_FN_PTR sha1Final;
|
||||
SHA2INIT_FN_PTR sha2Init;
|
||||
SHA2UPDATE_FN_PTR sha2Update;
|
||||
SHA2FINAL_FN_PTR sha2Final;
|
||||
UCRYPTO_VERSION_FN_PTR ucryptoVersion;
|
||||
UCRYPTO_GET_MECHLIST_FN_PTR ucryptoGetMechList;
|
||||
UCRYPTO_ENCRYPT_INIT_FN_PTR ucryptoEncryptInit;
|
||||
UCRYPTO_ENCRYPT_UPDATE_FN_PTR ucryptoEncryptUpdate;
|
||||
UCRYPTO_ENCRYPT_FINAL_FN_PTR ucryptoEncryptFinal;
|
||||
UCRYPTO_ENCRYPT_FN_PTR ucryptoEncrypt;
|
||||
UCRYPTO_DECRYPT_INIT_FN_PTR ucryptoDecryptInit;
|
||||
UCRYPTO_DECRYPT_UPDATE_FN_PTR ucryptoDecryptUpdate;
|
||||
UCRYPTO_DECRYPT_FINAL_FN_PTR ucryptoDecryptFinal;
|
||||
UCRYPTO_DECRYPT_FN_PTR ucryptoDecrypt;
|
||||
UCRYPTO_SIGN_INIT_FN_PTR ucryptoSignInit;
|
||||
UCRYPTO_SIGN_UPDATE_FN_PTR ucryptoSignUpdate;
|
||||
UCRYPTO_SIGN_FINAL_FN_PTR ucryptoSignFinal;
|
||||
UCRYPTO_VERIFY_INIT_FN_PTR ucryptoVerifyInit;
|
||||
UCRYPTO_VERIFY_UPDATE_FN_PTR ucryptoVerifyUpdate;
|
||||
UCRYPTO_VERIFY_FINAL_FN_PTR ucryptoVerifyFinal;
|
||||
} T4CRYPTO_FUNCTION_TABLE;
|
||||
|
||||
typedef T4CRYPTO_FUNCTION_TABLE *T4CRYPTO_FUNCTION_TABLE_PTR;
|
||||
|
||||
/* global function table */
|
||||
T4CRYPTO_FUNCTION_TABLE_PTR ftab;
|
||||
|
||||
#endif
|
@ -0,0 +1,637 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_CRYPTO_COMMON_H
|
||||
#define _SYS_CRYPTO_COMMON_H
|
||||
|
||||
/*
|
||||
* Header file for the common data structures of the cryptographic framework
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/stream.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/condvar.h>
|
||||
|
||||
/* Convenience defines/macros */
|
||||
|
||||
#define CRYPTO_ARG_INPLACE(input, output) \
|
||||
if ((output) == NULL) \
|
||||
(output) = (input);
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
#include <sys/kmem.h>
|
||||
#define CRYPTO_KMFLAG(x) crypto_kmflag((x))
|
||||
#define CRYPTO_ALLOC(sz, kmflag) kmem_alloc((sz), (kmflag))
|
||||
#define CRYPTO_ZALLOC(sz, kmflag) kmem_zalloc((sz), (kmflag))
|
||||
#define CRYPTO_FREE(ptr, sz) kmem_free((ptr), (sz))
|
||||
#define CRYPTO_ZFREE(ptr, sz) if (ptr != NULL) { \
|
||||
bzero((ptr), (sz)), \
|
||||
kmem_free((ptr), (sz)); \
|
||||
}
|
||||
|
||||
#else /* _KERNEL */
|
||||
|
||||
#include <malloc.h>
|
||||
#define CRYPTO_KMFLAG(x) (0)
|
||||
#define CRYPTO_ALLOC(sz, kmflag) malloc((sz))
|
||||
#define CRYPTO_ZALLOC(sz, kmflag) calloc(1, (sz))
|
||||
#define CRYPTO_FREE(ptr, sz) free((ptr))
|
||||
#define CRYPTO_ZFREE(ptr, sz) if (ptr != NULL) { \
|
||||
bzero((ptr), (sz)), \
|
||||
free((ptr)); \
|
||||
}
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
/* Cryptographic Mechanisms */
|
||||
|
||||
#define CRYPTO_MAX_MECH_NAME 32
|
||||
typedef char crypto_mech_name_t[CRYPTO_MAX_MECH_NAME];
|
||||
|
||||
typedef uint64_t crypto_mech_type_t;
|
||||
|
||||
typedef struct crypto_mechanism {
|
||||
crypto_mech_type_t cm_type; /* mechanism type */
|
||||
caddr_t cm_param; /* mech. parameter */
|
||||
size_t cm_param_len; /* mech. parameter len */
|
||||
} crypto_mechanism_t;
|
||||
|
||||
#ifdef _SYSCALL32
|
||||
|
||||
typedef struct crypto_mechanism32 {
|
||||
crypto_mech_type_t cm_type; /* mechanism type */
|
||||
caddr32_t cm_param; /* mech. parameter */
|
||||
size32_t cm_param_len; /* mech. parameter len */
|
||||
} crypto_mechanism32_t;
|
||||
|
||||
#endif /* _SYSCALL32 */
|
||||
|
||||
#ifdef _KERNEL
|
||||
/* CK_AES_CTR_PARAMS provides parameters to the CKM_AES_CTR mechanism */
|
||||
typedef struct CK_AES_CTR_PARAMS {
|
||||
ulong_t ulCounterBits;
|
||||
uint8_t cb[16];
|
||||
} CK_AES_CTR_PARAMS;
|
||||
#endif
|
||||
|
||||
/* CK_AES_CCM_PARAMS provides parameters to the CKM_AES_CCM mechanism */
|
||||
typedef struct CK_AES_CCM_PARAMS {
|
||||
ulong_t ulMACSize;
|
||||
ulong_t ulNonceSize;
|
||||
ulong_t ulAuthDataSize;
|
||||
ulong_t ulDataSize; /* used for plaintext or ciphertext */
|
||||
uchar_t *nonce;
|
||||
uchar_t *authData;
|
||||
} CK_AES_CCM_PARAMS;
|
||||
|
||||
/* CK_AES_GCM_PARAMS provides parameters to the CKM_AES_GCM mechanism */
|
||||
typedef struct CK_AES_GCM_PARAMS {
|
||||
uchar_t *pIv;
|
||||
ulong_t ulIvLen;
|
||||
ulong_t ulIvBits;
|
||||
uchar_t *pAAD;
|
||||
ulong_t ulAADLen;
|
||||
ulong_t ulTagBits;
|
||||
} CK_AES_GCM_PARAMS;
|
||||
|
||||
/* CK_AES_GMAC_PARAMS provides parameters to the CKM_AES_GMAC mechanism */
|
||||
typedef struct CK_AES_GMAC_PARAMS {
|
||||
uchar_t *pIv;
|
||||
uchar_t *pAAD;
|
||||
ulong_t ulAADLen;
|
||||
} CK_AES_GMAC_PARAMS;
|
||||
|
||||
#ifdef _KERNEL
|
||||
/*
|
||||
* CK_ECDH1_DERIVE_PARAMS provides the parameters to the
|
||||
* CKM_ECDH1_KEY_DERIVE mechanism
|
||||
*/
|
||||
typedef struct CK_ECDH1_DERIVE_PARAMS {
|
||||
ulong_t kdf;
|
||||
ulong_t ulSharedDataLen;
|
||||
uchar_t *pSharedData;
|
||||
ulong_t ulPublicDataLen;
|
||||
uchar_t *pPublicData;
|
||||
} CK_ECDH1_DERIVE_PARAMS;
|
||||
#endif
|
||||
|
||||
#ifdef _KERNEL
|
||||
#ifdef _SYSCALL32
|
||||
|
||||
/* needed for 32-bit applications running on 64-bit kernels */
|
||||
typedef struct CK_AES_CTR_PARAMS32 {
|
||||
uint32_t ulCounterBits;
|
||||
uint8_t cb[16];
|
||||
} CK_AES_CTR_PARAMS32;
|
||||
|
||||
/* needed for 32-bit applications running on 64-bit kernels */
|
||||
typedef struct CK_AES_CCM_PARAMS32 {
|
||||
uint32_t ulMACSize;
|
||||
uint32_t ulNonceSize;
|
||||
uint32_t ulAuthDataSize;
|
||||
uint32_t ulDataSize;
|
||||
caddr32_t nonce;
|
||||
caddr32_t authData;
|
||||
} CK_AES_CCM_PARAMS32;
|
||||
|
||||
/* needed for 32-bit applications running on 64-bit kernels */
|
||||
typedef struct CK_AES_GCM_PARAMS32 {
|
||||
caddr32_t pIv;
|
||||
uint32_t ulIvLen;
|
||||
uint32_t ulIvBits;
|
||||
caddr32_t pAAD;
|
||||
uint32_t ulAADLen;
|
||||
uint32_t ulTagBits;
|
||||
} CK_AES_GCM_PARAMS32;
|
||||
|
||||
/* needed for 32-bit applications running on 64-bit kernels */
|
||||
typedef struct CK_AES_GMAC_PARAMS32 {
|
||||
caddr32_t pIv;
|
||||
caddr32_t pAAD;
|
||||
uint32_t ulAADLen;
|
||||
} CK_AES_GMAC_PARAMS32;
|
||||
|
||||
typedef struct CK_ECDH1_DERIVE_PARAMS32 {
|
||||
uint32_t kdf;
|
||||
uint32_t ulSharedDataLen;
|
||||
caddr32_t pSharedData;
|
||||
uint32_t ulPublicDataLen;
|
||||
caddr32_t pPublicData;
|
||||
} CK_ECDH1_DERIVE_PARAMS32;
|
||||
|
||||
#endif /* _SYSCALL32 */
|
||||
#endif /* _KERNEL */
|
||||
|
||||
/*
|
||||
* The measurement unit bit flag for a mechanism's minimum or maximum key size.
|
||||
* The unit are mechanism dependent. It can be in bits or in bytes.
|
||||
*/
|
||||
typedef uint32_t crypto_keysize_unit_t;
|
||||
|
||||
/*
|
||||
* The following bit flags are valid in cm_mech_flags field in
|
||||
* the crypto_mech_info_t structure of the SPI.
|
||||
*
|
||||
* Only the first two bit flags are valid in mi_keysize_unit
|
||||
* field in the crypto_mechanism_info_t structure of the API.
|
||||
*/
|
||||
#define CRYPTO_KEYSIZE_UNIT_IN_BITS 0x00000001
|
||||
#define CRYPTO_KEYSIZE_UNIT_IN_BYTES 0x00000002
|
||||
#define CRYPTO_CAN_SHARE_OPSTATE 0x00000004 /* supports sharing */
|
||||
|
||||
|
||||
/* Mechanisms supported out-of-the-box */
|
||||
#define SUN_CKM_MD4 "CKM_MD4"
|
||||
#define SUN_CKM_MD5 "CKM_MD5"
|
||||
#define SUN_CKM_MD5_HMAC "CKM_MD5_HMAC"
|
||||
#define SUN_CKM_MD5_HMAC_GENERAL "CKM_MD5_HMAC_GENERAL"
|
||||
#define SUN_CKM_SHA1 "CKM_SHA_1"
|
||||
#define SUN_CKM_SHA1_HMAC "CKM_SHA_1_HMAC"
|
||||
#define SUN_CKM_SHA1_HMAC_GENERAL "CKM_SHA_1_HMAC_GENERAL"
|
||||
#define SUN_CKM_SHA256 "CKM_SHA256"
|
||||
#define SUN_CKM_SHA256_HMAC "CKM_SHA256_HMAC"
|
||||
#define SUN_CKM_SHA256_HMAC_GENERAL "CKM_SHA256_HMAC_GENERAL"
|
||||
#define SUN_CKM_SHA384 "CKM_SHA384"
|
||||
#define SUN_CKM_SHA384_HMAC "CKM_SHA384_HMAC"
|
||||
#define SUN_CKM_SHA384_HMAC_GENERAL "CKM_SHA384_HMAC_GENERAL"
|
||||
#define SUN_CKM_SHA512 "CKM_SHA512"
|
||||
#define SUN_CKM_SHA512_HMAC "CKM_SHA512_HMAC"
|
||||
#define SUN_CKM_SHA512_HMAC_GENERAL "CKM_SHA512_HMAC_GENERAL"
|
||||
#define SUN_CKM_DES_CBC "CKM_DES_CBC"
|
||||
#define SUN_CKM_DES3_CBC "CKM_DES3_CBC"
|
||||
#define SUN_CKM_DES_ECB "CKM_DES_ECB"
|
||||
#define SUN_CKM_DES3_ECB "CKM_DES3_ECB"
|
||||
#define SUN_CKM_BLOWFISH_CBC "CKM_BLOWFISH_CBC"
|
||||
#define SUN_CKM_BLOWFISH_ECB "CKM_BLOWFISH_ECB"
|
||||
#define SUN_CKM_AES_CBC "CKM_AES_CBC"
|
||||
#define SUN_CKM_AES_ECB "CKM_AES_ECB"
|
||||
#define SUN_CKM_AES_CTR "CKM_AES_CTR"
|
||||
#define SUN_CKM_AES_CCM "CKM_AES_CCM"
|
||||
#define SUN_CKM_AES_GCM "CKM_AES_GCM"
|
||||
#define SUN_CKM_AES_GMAC "CKM_AES_GMAC"
|
||||
#define SUN_CKM_AES_CFB128 "CKM_AES_CFB128"
|
||||
#define SUN_CKM_RC4 "CKM_RC4"
|
||||
#define SUN_CKM_RSA_PKCS "CKM_RSA_PKCS"
|
||||
#define SUN_CKM_RSA_X_509 "CKM_RSA_X_509"
|
||||
#define SUN_CKM_MD5_RSA_PKCS "CKM_MD5_RSA_PKCS"
|
||||
#define SUN_CKM_SHA1_RSA_PKCS "CKM_SHA1_RSA_PKCS"
|
||||
#define SUN_CKM_SHA256_RSA_PKCS "CKM_SHA256_RSA_PKCS"
|
||||
#define SUN_CKM_SHA384_RSA_PKCS "CKM_SHA384_RSA_PKCS"
|
||||
#define SUN_CKM_SHA512_RSA_PKCS "CKM_SHA512_RSA_PKCS"
|
||||
#define SUN_CKM_EC_KEY_PAIR_GEN "CKM_EC_KEY_PAIR_GEN"
|
||||
#define SUN_CKM_ECDH1_DERIVE "CKM_ECDH1_DERIVE"
|
||||
#define SUN_CKM_ECDSA_SHA1 "CKM_ECDSA_SHA1"
|
||||
#define SUN_CKM_ECDSA "CKM_ECDSA"
|
||||
|
||||
/* Shared operation context format for CKM_RC4 */
|
||||
typedef struct {
|
||||
#if defined(__amd64)
|
||||
uint32_t i, j;
|
||||
uint32_t arr[256];
|
||||
uint32_t flag;
|
||||
#else
|
||||
uchar_t arr[256];
|
||||
uchar_t i, j;
|
||||
#endif /* __amd64 */
|
||||
uint64_t pad; /* For 64-bit alignment */
|
||||
} arcfour_state_t;
|
||||
|
||||
/* Data arguments of cryptographic operations */
|
||||
|
||||
typedef enum crypto_data_format {
|
||||
CRYPTO_DATA_RAW = 1,
|
||||
CRYPTO_DATA_UIO,
|
||||
CRYPTO_DATA_MBLK
|
||||
} crypto_data_format_t;
|
||||
|
||||
typedef struct crypto_data {
|
||||
crypto_data_format_t cd_format; /* Format identifier */
|
||||
off_t cd_offset; /* Offset from the beginning */
|
||||
size_t cd_length; /* # of bytes in use */
|
||||
caddr_t cd_miscdata; /* ancillary data */
|
||||
union {
|
||||
/* Raw format */
|
||||
iovec_t cdu_raw; /* Pointer and length */
|
||||
|
||||
/* uio scatter-gather format */
|
||||
uio_t *cdu_uio;
|
||||
|
||||
/* mblk scatter-gather format */
|
||||
mblk_t *cdu_mp; /* The mblk chain */
|
||||
|
||||
} cdu; /* Crypto Data Union */
|
||||
} crypto_data_t;
|
||||
|
||||
#define cd_raw cdu.cdu_raw
|
||||
#define cd_uio cdu.cdu_uio
|
||||
#define cd_mp cdu.cdu_mp
|
||||
|
||||
#define CRYPTO_SET_RAW_DATA(var, str, len) \
|
||||
(var).cd_format = CRYPTO_DATA_RAW; \
|
||||
(var).cd_offset = 0; \
|
||||
(var).cd_length = (len); \
|
||||
(var).cd_miscdata = NULL; \
|
||||
(var).cd_raw.iov_base = (caddr_t)(str); \
|
||||
(var).cd_raw.iov_len = (len);
|
||||
|
||||
#define CRYPTO_DATA_IS_USERSPACE(buf) \
|
||||
((buf->cd_format == CRYPTO_DATA_UIO && \
|
||||
buf->cd_uio->uio_segflg == UIO_USERSPACE))
|
||||
|
||||
typedef struct crypto_dual_data {
|
||||
crypto_data_t dd_data; /* The data */
|
||||
off_t dd_offset2; /* Used by dual operation */
|
||||
size_t dd_len2; /* # of bytes to take */
|
||||
} crypto_dual_data_t;
|
||||
|
||||
#define dd_format dd_data.cd_format
|
||||
#define dd_offset1 dd_data.cd_offset
|
||||
#define dd_len1 dd_data.cd_length
|
||||
#define dd_miscdata dd_data.cd_miscdata
|
||||
#define dd_raw dd_data.cd_raw
|
||||
#define dd_uio dd_data.cd_uio
|
||||
#define dd_mp dd_data.cd_mp
|
||||
|
||||
/* The keys, and their contents */
|
||||
|
||||
typedef enum {
|
||||
CRYPTO_KEY_RAW = 1, /* ck_data is a cleartext key */
|
||||
CRYPTO_KEY_REFERENCE, /* ck_obj_id is an opaque reference */
|
||||
CRYPTO_KEY_ATTR_LIST /* ck_attrs is a list of object attributes */
|
||||
} crypto_key_format_t;
|
||||
|
||||
typedef uint64_t crypto_attr_type_t;
|
||||
|
||||
/* Attribute types to use for passing a RSA public key or a private key. */
|
||||
#define SUN_CKA_MODULUS 0x00000120
|
||||
#define SUN_CKA_MODULUS_BITS 0x00000121
|
||||
#define SUN_CKA_PUBLIC_EXPONENT 0x00000122
|
||||
#define SUN_CKA_PRIVATE_EXPONENT 0x00000123
|
||||
#define SUN_CKA_PRIME_1 0x00000124
|
||||
#define SUN_CKA_PRIME_2 0x00000125
|
||||
#define SUN_CKA_EXPONENT_1 0x00000126
|
||||
#define SUN_CKA_EXPONENT_2 0x00000127
|
||||
#define SUN_CKA_COEFFICIENT 0x00000128
|
||||
#define SUN_CKA_PRIME 0x00000130
|
||||
#define SUN_CKA_SUBPRIME 0x00000131
|
||||
#define SUN_CKA_BASE 0x00000132
|
||||
|
||||
#define CKK_EC 0x00000003
|
||||
#define CKK_GENERIC_SECRET 0x00000010
|
||||
#define CKK_RC4 0x00000012
|
||||
#define CKK_AES 0x0000001F
|
||||
#define CKK_DES 0x00000013
|
||||
#define CKK_DES2 0x00000014
|
||||
#define CKK_DES3 0x00000015
|
||||
|
||||
#define CKO_PUBLIC_KEY 0x00000002
|
||||
#define CKO_PRIVATE_KEY 0x00000003
|
||||
#define CKA_CLASS 0x00000000
|
||||
#define CKA_VALUE 0x00000011
|
||||
#define CKA_KEY_TYPE 0x00000100
|
||||
#define CKA_VALUE_LEN 0x00000161
|
||||
#define CKA_EC_PARAMS 0x00000180
|
||||
#define CKA_EC_POINT 0x00000181
|
||||
|
||||
typedef uint32_t crypto_object_id_t;
|
||||
|
||||
typedef struct crypto_object_attribute {
|
||||
crypto_attr_type_t oa_type; /* attribute type */
|
||||
caddr_t oa_value; /* attribute value */
|
||||
ssize_t oa_value_len; /* length of attribute value */
|
||||
} crypto_object_attribute_t;
|
||||
|
||||
typedef struct crypto_key {
|
||||
crypto_key_format_t ck_format; /* format identifier */
|
||||
union {
|
||||
/* for CRYPTO_KEY_RAW ck_format */
|
||||
struct {
|
||||
uint_t cku_v_length; /* # of bits in ck_data */
|
||||
void *cku_v_data; /* ptr to key value */
|
||||
} cku_key_value;
|
||||
|
||||
/* for CRYPTO_KEY_REFERENCE ck_format */
|
||||
crypto_object_id_t cku_key_id; /* reference to object key */
|
||||
|
||||
/* for CRYPTO_KEY_ATTR_LIST ck_format */
|
||||
struct {
|
||||
uint_t cku_a_count; /* number of attributes */
|
||||
crypto_object_attribute_t *cku_a_oattr;
|
||||
} cku_key_attrs;
|
||||
} cku_data; /* Crypto Key union */
|
||||
} crypto_key_t;
|
||||
|
||||
#ifdef _SYSCALL32
|
||||
|
||||
typedef struct crypto_object_attribute32 {
|
||||
uint64_t oa_type; /* attribute type */
|
||||
caddr32_t oa_value; /* attribute value */
|
||||
ssize32_t oa_value_len; /* length of attribute value */
|
||||
} crypto_object_attribute32_t;
|
||||
|
||||
typedef struct crypto_key32 {
|
||||
crypto_key_format_t ck_format; /* format identifier */
|
||||
union {
|
||||
/* for CRYPTO_KEY_RAW ck_format */
|
||||
struct {
|
||||
uint32_t cku_v_length; /* # of bytes in ck_data */
|
||||
caddr32_t cku_v_data; /* ptr to key value */
|
||||
} cku_key_value;
|
||||
|
||||
/* for CRYPTO_KEY_REFERENCE ck_format */
|
||||
crypto_object_id_t cku_key_id; /* reference to object key */
|
||||
|
||||
/* for CRYPTO_KEY_ATTR_LIST ck_format */
|
||||
struct {
|
||||
uint32_t cku_a_count; /* number of attributes */
|
||||
caddr32_t cku_a_oattr;
|
||||
} cku_key_attrs;
|
||||
} cku_data; /* Crypto Key union */
|
||||
} crypto_key32_t;
|
||||
|
||||
#endif /* _SYSCALL32 */
|
||||
|
||||
#define ck_data cku_data.cku_key_value.cku_v_data
|
||||
#define ck_length cku_data.cku_key_value.cku_v_length
|
||||
#define ck_obj_id cku_data.cku_key_id
|
||||
#define ck_count cku_data.cku_key_attrs.cku_a_count
|
||||
#define ck_attrs cku_data.cku_key_attrs.cku_a_oattr
|
||||
|
||||
/*
|
||||
* Raw key lengths are expressed in number of bits.
|
||||
* The following macro returns the minimum number of
|
||||
* bytes that can contain the specified number of bits.
|
||||
* Round up without overflowing the integer type.
|
||||
*/
|
||||
#define CRYPTO_BITS2BYTES(n) ((n) == 0 ? 0 : (((n) - 1) >> 3) + 1)
|
||||
#define CRYPTO_BYTES2BITS(n) ((n) << 3)
|
||||
|
||||
/* Providers */
|
||||
|
||||
typedef enum {
|
||||
CRYPTO_HW_PROVIDER = 0,
|
||||
CRYPTO_SW_PROVIDER,
|
||||
CRYPTO_LOGICAL_PROVIDER
|
||||
} crypto_provider_type_t;
|
||||
|
||||
typedef uint32_t crypto_provider_id_t;
|
||||
#define KCF_PROVID_INVALID ((uint32_t)-1)
|
||||
|
||||
typedef struct crypto_provider_entry {
|
||||
crypto_provider_id_t pe_provider_id;
|
||||
uint_t pe_mechanism_count;
|
||||
} crypto_provider_entry_t;
|
||||
|
||||
typedef struct crypto_dev_list_entry {
|
||||
char le_dev_name[MAXNAMELEN];
|
||||
uint_t le_dev_instance;
|
||||
uint_t le_mechanism_count;
|
||||
} crypto_dev_list_entry_t;
|
||||
|
||||
/* User type for authentication ioctls and SPI entry points */
|
||||
|
||||
typedef enum crypto_user_type {
|
||||
CRYPTO_SO = 0,
|
||||
CRYPTO_USER
|
||||
} crypto_user_type_t;
|
||||
|
||||
/* Version for provider management ioctls and SPI entry points */
|
||||
|
||||
typedef struct crypto_version {
|
||||
uchar_t cv_major;
|
||||
uchar_t cv_minor;
|
||||
} crypto_version_t;
|
||||
|
||||
/* session data structure opaque to the consumer */
|
||||
typedef void *crypto_session_t;
|
||||
|
||||
/* provider data structure opaque to the consumer */
|
||||
typedef void *crypto_provider_t;
|
||||
|
||||
/* Limits used by both consumers and providers */
|
||||
#define CRYPTO_EXT_SIZE_LABEL 32
|
||||
#define CRYPTO_EXT_SIZE_MANUF 32
|
||||
#define CRYPTO_EXT_SIZE_MODEL 16
|
||||
#define CRYPTO_EXT_SIZE_SERIAL 16
|
||||
#define CRYPTO_EXT_SIZE_TIME 16
|
||||
|
||||
typedef struct crypto_provider_ext_info {
|
||||
uchar_t ei_label[CRYPTO_EXT_SIZE_LABEL];
|
||||
uchar_t ei_manufacturerID[CRYPTO_EXT_SIZE_MANUF];
|
||||
uchar_t ei_model[CRYPTO_EXT_SIZE_MODEL];
|
||||
uchar_t ei_serial_number[CRYPTO_EXT_SIZE_SERIAL];
|
||||
ulong_t ei_flags;
|
||||
ulong_t ei_max_session_count;
|
||||
ulong_t ei_max_pin_len;
|
||||
ulong_t ei_min_pin_len;
|
||||
ulong_t ei_total_public_memory;
|
||||
ulong_t ei_free_public_memory;
|
||||
ulong_t ei_total_private_memory;
|
||||
ulong_t ei_free_private_memory;
|
||||
crypto_version_t ei_hardware_version;
|
||||
crypto_version_t ei_firmware_version;
|
||||
uchar_t ei_time[CRYPTO_EXT_SIZE_TIME];
|
||||
int ei_hash_max_input_len;
|
||||
int ei_hmac_max_input_len;
|
||||
} crypto_provider_ext_info_t;
|
||||
|
||||
typedef uint_t crypto_session_id_t;
|
||||
|
||||
typedef enum cmd_type {
|
||||
COPY_FROM_DATA,
|
||||
COPY_TO_DATA,
|
||||
COMPARE_TO_DATA,
|
||||
MD5_DIGEST_DATA,
|
||||
SHA1_DIGEST_DATA,
|
||||
SHA2_DIGEST_DATA,
|
||||
GHASH_DATA
|
||||
} cmd_type_t;
|
||||
|
||||
#define CRYPTO_DO_UPDATE 0x01
|
||||
#define CRYPTO_DO_FINAL 0x02
|
||||
#define CRYPTO_DO_MD5 0x04
|
||||
#define CRYPTO_DO_SHA1 0x08
|
||||
#define CRYPTO_DO_SIGN 0x10
|
||||
#define CRYPTO_DO_VERIFY 0x20
|
||||
#define CRYPTO_DO_SHA2 0x40
|
||||
|
||||
#define PROVIDER_OWNS_KEY_SCHEDULE 0x00000001
|
||||
|
||||
/*
|
||||
* Common cryptographic status and error codes.
|
||||
*/
|
||||
#define CRYPTO_SUCCESS 0x00000000
|
||||
#define CRYPTO_CANCEL 0x00000001
|
||||
#define CRYPTO_HOST_MEMORY 0x00000002
|
||||
#define CRYPTO_GENERAL_ERROR 0x00000003
|
||||
#define CRYPTO_FAILED 0x00000004
|
||||
#define CRYPTO_ARGUMENTS_BAD 0x00000005
|
||||
#define CRYPTO_ATTRIBUTE_READ_ONLY 0x00000006
|
||||
#define CRYPTO_ATTRIBUTE_SENSITIVE 0x00000007
|
||||
#define CRYPTO_ATTRIBUTE_TYPE_INVALID 0x00000008
|
||||
#define CRYPTO_ATTRIBUTE_VALUE_INVALID 0x00000009
|
||||
#define CRYPTO_CANCELED 0x0000000A
|
||||
#define CRYPTO_DATA_INVALID 0x0000000B
|
||||
#define CRYPTO_DATA_LEN_RANGE 0x0000000C
|
||||
#define CRYPTO_DEVICE_ERROR 0x0000000D
|
||||
#define CRYPTO_DEVICE_MEMORY 0x0000000E
|
||||
#define CRYPTO_DEVICE_REMOVED 0x0000000F
|
||||
#define CRYPTO_ENCRYPTED_DATA_INVALID 0x00000010
|
||||
#define CRYPTO_ENCRYPTED_DATA_LEN_RANGE 0x00000011
|
||||
#define CRYPTO_KEY_HANDLE_INVALID 0x00000012
|
||||
#define CRYPTO_KEY_SIZE_RANGE 0x00000013
|
||||
#define CRYPTO_KEY_TYPE_INCONSISTENT 0x00000014
|
||||
#define CRYPTO_KEY_NOT_NEEDED 0x00000015
|
||||
#define CRYPTO_KEY_CHANGED 0x00000016
|
||||
#define CRYPTO_KEY_NEEDED 0x00000017
|
||||
#define CRYPTO_KEY_INDIGESTIBLE 0x00000018
|
||||
#define CRYPTO_KEY_FUNCTION_NOT_PERMITTED 0x00000019
|
||||
#define CRYPTO_KEY_NOT_WRAPPABLE 0x0000001A
|
||||
#define CRYPTO_KEY_UNEXTRACTABLE 0x0000001B
|
||||
#define CRYPTO_MECHANISM_INVALID 0x0000001C
|
||||
#define CRYPTO_MECHANISM_PARAM_INVALID 0x0000001D
|
||||
#define CRYPTO_OBJECT_HANDLE_INVALID 0x0000001E
|
||||
#define CRYPTO_OPERATION_IS_ACTIVE 0x0000001F
|
||||
#define CRYPTO_OPERATION_NOT_INITIALIZED 0x00000020
|
||||
#define CRYPTO_PIN_INCORRECT 0x00000021
|
||||
#define CRYPTO_PIN_INVALID 0x00000022
|
||||
#define CRYPTO_PIN_LEN_RANGE 0x00000023
|
||||
#define CRYPTO_PIN_EXPIRED 0x00000024
|
||||
#define CRYPTO_PIN_LOCKED 0x00000025
|
||||
#define CRYPTO_SESSION_CLOSED 0x00000026
|
||||
#define CRYPTO_SESSION_COUNT 0x00000027
|
||||
#define CRYPTO_SESSION_HANDLE_INVALID 0x00000028
|
||||
#define CRYPTO_SESSION_READ_ONLY 0x00000029
|
||||
#define CRYPTO_SESSION_EXISTS 0x0000002A
|
||||
#define CRYPTO_SESSION_READ_ONLY_EXISTS 0x0000002B
|
||||
#define CRYPTO_SESSION_READ_WRITE_SO_EXISTS 0x0000002C
|
||||
#define CRYPTO_SIGNATURE_INVALID 0x0000002D
|
||||
#define CRYPTO_SIGNATURE_LEN_RANGE 0x0000002E
|
||||
#define CRYPTO_TEMPLATE_INCOMPLETE 0x0000002F
|
||||
#define CRYPTO_TEMPLATE_INCONSISTENT 0x00000030
|
||||
#define CRYPTO_UNWRAPPING_KEY_HANDLE_INVALID 0x00000031
|
||||
#define CRYPTO_UNWRAPPING_KEY_SIZE_RANGE 0x00000032
|
||||
#define CRYPTO_UNWRAPPING_KEY_TYPE_INCONSISTENT 0x00000033
|
||||
#define CRYPTO_USER_ALREADY_LOGGED_IN 0x00000034
|
||||
#define CRYPTO_USER_NOT_LOGGED_IN 0x00000035
|
||||
#define CRYPTO_USER_PIN_NOT_INITIALIZED 0x00000036
|
||||
#define CRYPTO_USER_TYPE_INVALID 0x00000037
|
||||
#define CRYPTO_USER_ANOTHER_ALREADY_LOGGED_IN 0x00000038
|
||||
#define CRYPTO_USER_TOO_MANY_TYPES 0x00000039
|
||||
#define CRYPTO_WRAPPED_KEY_INVALID 0x0000003A
|
||||
#define CRYPTO_WRAPPED_KEY_LEN_RANGE 0x0000003B
|
||||
#define CRYPTO_WRAPPING_KEY_HANDLE_INVALID 0x0000003C
|
||||
#define CRYPTO_WRAPPING_KEY_SIZE_RANGE 0x0000003D
|
||||
#define CRYPTO_WRAPPING_KEY_TYPE_INCONSISTENT 0x0000003E
|
||||
#define CRYPTO_RANDOM_SEED_NOT_SUPPORTED 0x0000003F
|
||||
#define CRYPTO_RANDOM_NO_RNG 0x00000040
|
||||
#define CRYPTO_DOMAIN_PARAMS_INVALID 0x00000041
|
||||
#define CRYPTO_BUFFER_TOO_SMALL 0x00000042
|
||||
#define CRYPTO_INFORMATION_SENSITIVE 0x00000043
|
||||
#define CRYPTO_NOT_SUPPORTED 0x00000044
|
||||
|
||||
#define CRYPTO_QUEUED 0x00000045
|
||||
#define CRYPTO_BUFFER_TOO_BIG 0x00000046
|
||||
#define CRYPTO_INVALID_CONTEXT 0x00000047
|
||||
#define CRYPTO_INVALID_MAC 0x00000048
|
||||
#define CRYPTO_MECH_NOT_SUPPORTED 0x00000049
|
||||
#define CRYPTO_INCONSISTENT_ATTRIBUTE 0x0000004A
|
||||
#define CRYPTO_NO_PERMISSION 0x0000004B
|
||||
#define CRYPTO_INVALID_PROVIDER_ID 0x0000004C
|
||||
#define CRYPTO_VERSION_MISMATCH 0x0000004D
|
||||
#define CRYPTO_BUSY 0x0000004E
|
||||
#define CRYPTO_UNKNOWN_PROVIDER 0x0000004F
|
||||
#define CRYPTO_MODVERIFICATION_FAILED 0x00000050
|
||||
#define CRYPTO_OLD_CTX_TEMPLATE 0x00000051
|
||||
#define CRYPTO_WEAK_KEY 0x00000052
|
||||
#define CRYPTO_FIPS140_ERROR 0x00000053
|
||||
/*
|
||||
* Don't forget to update CRYPTO_LAST_ERROR and the error_number_table[]
|
||||
* in kernelUtil.c when new error code is added.
|
||||
*/
|
||||
#define CRYPTO_LAST_ERROR 0x00000053
|
||||
|
||||
/*
|
||||
* Special values that can be used to indicate that information is unavailable
|
||||
* or that there is not practical limit. These values can be used
|
||||
* by fields of the SPI crypto_provider_ext_info(9S) structure.
|
||||
* The value of CRYPTO_UNAVAILABLE_INFO should be the same as
|
||||
* CK_UNAVAILABLE_INFO in the PKCS#11 spec.
|
||||
*/
|
||||
#define CRYPTO_UNAVAILABLE_INFO ((ulong_t)(-1))
|
||||
#define CRYPTO_EFFECTIVELY_INFINITE 0x0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_CRYPTO_COMMON_H */
|
@ -0,0 +1,791 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_CRYPTO_SPI_H
|
||||
#define _SYS_CRYPTO_SPI_H
|
||||
|
||||
/*
|
||||
* CSPI: Cryptographic Service Provider Interface.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/crypto/common.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/dditypes.h>
|
||||
#include <sys/ddi.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#define CRYPTO_SPI_VERSION_1 1
|
||||
#define CRYPTO_SPI_VERSION_2 2
|
||||
#define CRYPTO_SPI_VERSION_3 3
|
||||
#define CRYPTO_SPI_VERSION_4 4
|
||||
#define CRYPTO_SPI_VERSION_5 5
|
||||
|
||||
#define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f)
|
||||
#define CRYPTO_PROVIDER_OFFSET(f) \
|
||||
offsetof(crypto_provider_management_ops_t, f)
|
||||
#define CRYPTO_OBJECT_OFFSET(f) offsetof(crypto_object_ops_t, f)
|
||||
#define CRYPTO_SESSION_OFFSET(f) offsetof(crypto_session_ops_t, f)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Provider-private handle. This handle is specified by a provider
|
||||
* when it registers by means of the pi_provider_handle field of
|
||||
* the crypto_provider_info structure, and passed to the provider
|
||||
* when its entry points are invoked.
|
||||
*/
|
||||
typedef void *crypto_provider_handle_t;
|
||||
|
||||
/*
|
||||
* Context templates can be used to by software providers to pre-process
|
||||
* keying material, such as key schedules. They are allocated by
|
||||
* a software provider create_ctx_template(9E) entry point, and passed
|
||||
* as argument to initialization and atomic provider entry points.
|
||||
*/
|
||||
typedef void *crypto_spi_ctx_template_t;
|
||||
|
||||
/*
|
||||
* Request handles are used by the kernel to identify an asynchronous
|
||||
* request being processed by a provider. It is passed by the kernel
|
||||
* to a hardware provider when submitting a request, and must be
|
||||
* specified by a provider when calling crypto_op_notification(9F)
|
||||
*/
|
||||
typedef void *crypto_req_handle_t;
|
||||
|
||||
/*
|
||||
* The context structure is passed from kcf to a provider in kernel and
|
||||
* internally in libsoftcrypto between ucrypto and the algorithm.
|
||||
* It contains the information needed to process a multi-part or
|
||||
* single part operation. The context structure is not used
|
||||
* by atomic operations.
|
||||
*
|
||||
* Parameters needed to perform a cryptographic operation, such
|
||||
* as keys, mechanisms, input and output buffers, are passed
|
||||
* as separate arguments to Provider routines.
|
||||
*/
|
||||
typedef struct crypto_ctx {
|
||||
crypto_provider_handle_t cc_provider;
|
||||
crypto_session_id_t cc_session;
|
||||
void *cc_provider_private; /* owned by provider */
|
||||
void *cc_framework_private; /* owned by framework */
|
||||
uint32_t cc_flags; /* flags */
|
||||
void *cc_opstate; /* state */
|
||||
} crypto_ctx_t;
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
/* Values for cc_flags field */
|
||||
#define CRYPTO_INIT_OPSTATE 0x00000001 /* allocate and init cc_opstate */
|
||||
#define CRYPTO_USE_OPSTATE 0x00000002 /* .. start using it as context */
|
||||
|
||||
/*
|
||||
* Extended provider information.
|
||||
*/
|
||||
|
||||
/*
|
||||
* valid values for ei_flags field of extended info structure
|
||||
* They match the RSA Security, Inc PKCS#11 tokenInfo flags.
|
||||
*/
|
||||
#define CRYPTO_EXTF_RNG 0x00000001
|
||||
#define CRYPTO_EXTF_WRITE_PROTECTED 0x00000002
|
||||
#define CRYPTO_EXTF_LOGIN_REQUIRED 0x00000004
|
||||
#define CRYPTO_EXTF_USER_PIN_INITIALIZED 0x00000008
|
||||
#define CRYPTO_EXTF_CLOCK_ON_TOKEN 0x00000040
|
||||
#define CRYPTO_EXTF_PROTECTED_AUTHENTICATION_PATH 0x00000100
|
||||
#define CRYPTO_EXTF_DUAL_CRYPTO_OPERATIONS 0x00000200
|
||||
#define CRYPTO_EXTF_TOKEN_INITIALIZED 0x00000400
|
||||
#define CRYPTO_EXTF_USER_PIN_COUNT_LOW 0x00010000
|
||||
#define CRYPTO_EXTF_USER_PIN_FINAL_TRY 0x00020000
|
||||
#define CRYPTO_EXTF_USER_PIN_LOCKED 0x00040000
|
||||
#define CRYPTO_EXTF_USER_PIN_TO_BE_CHANGED 0x00080000
|
||||
#define CRYPTO_EXTF_SO_PIN_COUNT_LOW 0x00100000
|
||||
#define CRYPTO_EXTF_SO_PIN_FINAL_TRY 0x00200000
|
||||
#define CRYPTO_EXTF_SO_PIN_LOCKED 0x00400000
|
||||
#define CRYPTO_EXTF_SO_PIN_TO_BE_CHANGED 0x00800000
|
||||
|
||||
/*
|
||||
* The crypto_control_ops structure contains pointers to control
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_control_ops {
|
||||
void (*provider_status)(crypto_provider_handle_t, uint_t *);
|
||||
} crypto_control_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_ctx_ops structure contains points to context and context
|
||||
* templates management operations for cryptographic providers. It is
|
||||
* passed through the crypto_ops(9S) structure when providers register
|
||||
* with the kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_ctx_ops {
|
||||
int (*create_ctx_template)(crypto_provider_handle_t,
|
||||
crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_spi_ctx_template_t *, size_t *, crypto_req_handle_t);
|
||||
int (*free_context)(crypto_ctx_t *);
|
||||
} crypto_ctx_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_digest_ops structure contains pointers to digest
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_digest_ops {
|
||||
int (*digest_init)(crypto_ctx_t *, crypto_mechanism_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*digest)(crypto_ctx_t *, crypto_data_t *, crypto_data_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*digest_update)(crypto_ctx_t *, crypto_data_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*digest_key)(crypto_ctx_t *, crypto_key_t *, crypto_req_handle_t);
|
||||
int (*digest_final)(crypto_ctx_t *, crypto_data_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*digest_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
} crypto_digest_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_cipher_ops structure contains pointers to encryption
|
||||
* and decryption operations for cryptographic providers. It is
|
||||
* passed through the crypto_ops(9S) structure when providers register
|
||||
* with the kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_cipher_ops {
|
||||
int (*encrypt_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
int (*encrypt)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*encrypt_update)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*encrypt_final)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*encrypt_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
|
||||
int (*decrypt_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
int (*decrypt)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*decrypt_update)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*decrypt_final)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*decrypt_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
} crypto_cipher_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_mac_ops structure contains pointers to MAC
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_mac_ops {
|
||||
int (*mac_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
int (*mac)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*mac_update)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*mac_final)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*mac_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*mac_verify_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
} crypto_mac_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_sign_ops structure contains pointers to signing
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_sign_ops {
|
||||
int (*sign_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*sign)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*sign_update)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*sign_final)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*sign_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*sign_recover_init)(crypto_ctx_t *, crypto_mechanism_t *,
|
||||
crypto_key_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*sign_recover)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*sign_recover_atomic)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
} crypto_sign_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_verify_ops structure contains pointers to verify
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_verify_ops {
|
||||
int (*verify_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*verify)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*verify_update)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*verify_final)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*verify_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*verify_recover_init)(crypto_ctx_t *, crypto_mechanism_t *,
|
||||
crypto_key_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
int (*verify_recover)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*verify_recover_atomic)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_req_handle_t);
|
||||
} crypto_verify_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_dual_ops structure contains pointers to dual
|
||||
* cipher and sign/verify operations for cryptographic providers.
|
||||
* It is passed through the crypto_ops(9S) structure when
|
||||
* providers register with the kernel using
|
||||
* crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_dual_ops {
|
||||
int (*digest_encrypt_update)(
|
||||
crypto_ctx_t *, crypto_ctx_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*decrypt_digest_update)(
|
||||
crypto_ctx_t *, crypto_ctx_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*sign_encrypt_update)(
|
||||
crypto_ctx_t *, crypto_ctx_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
int (*decrypt_verify_update)(
|
||||
crypto_ctx_t *, crypto_ctx_t *, crypto_data_t *,
|
||||
crypto_data_t *, crypto_req_handle_t);
|
||||
} crypto_dual_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_dual_cipher_mac_ops structure contains pointers to dual
|
||||
* cipher and MAC operations for cryptographic providers.
|
||||
* It is passed through the crypto_ops(9S) structure when
|
||||
* providers register with the kernel using
|
||||
* crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_dual_cipher_mac_ops {
|
||||
int (*encrypt_mac_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_mechanism_t *,
|
||||
crypto_key_t *, crypto_spi_ctx_template_t,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
int (*encrypt_mac)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_dual_data_t *, crypto_data_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*encrypt_mac_update)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_dual_data_t *, crypto_req_handle_t);
|
||||
int (*encrypt_mac_final)(crypto_ctx_t *,
|
||||
crypto_dual_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*encrypt_mac_atomic)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_mechanism_t *,
|
||||
crypto_key_t *, crypto_data_t *, crypto_dual_data_t *,
|
||||
crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
|
||||
int (*mac_decrypt_init)(crypto_ctx_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_mechanism_t *,
|
||||
crypto_key_t *, crypto_spi_ctx_template_t,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
int (*mac_decrypt)(crypto_ctx_t *,
|
||||
crypto_dual_data_t *, crypto_data_t *, crypto_data_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*mac_decrypt_update)(crypto_ctx_t *,
|
||||
crypto_dual_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*mac_decrypt_final)(crypto_ctx_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_req_handle_t);
|
||||
int (*mac_decrypt_atomic)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_dual_data_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
int (*mac_verify_decrypt_atomic)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_mechanism_t *, crypto_key_t *,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_dual_data_t *,
|
||||
crypto_data_t *, crypto_data_t *, crypto_spi_ctx_template_t,
|
||||
crypto_spi_ctx_template_t, crypto_req_handle_t);
|
||||
} crypto_dual_cipher_mac_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_random_number_ops structure contains pointers to random
|
||||
* number operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_random_number_ops {
|
||||
int (*seed_random)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
uchar_t *, size_t, uint_t, uint32_t, crypto_req_handle_t);
|
||||
int (*generate_random)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
uchar_t *, size_t, crypto_req_handle_t);
|
||||
} crypto_random_number_ops_t;
|
||||
|
||||
/*
|
||||
* Flag values for seed_random.
|
||||
*/
|
||||
#define CRYPTO_SEED_NOW 0x00000001
|
||||
|
||||
/*
|
||||
* The crypto_session_ops structure contains pointers to session
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_session_ops {
|
||||
int (*session_open)(crypto_provider_handle_t, crypto_session_id_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*session_close)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_req_handle_t);
|
||||
int (*session_login)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_user_type_t, char *, size_t, crypto_req_handle_t);
|
||||
int (*session_logout)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_req_handle_t);
|
||||
} crypto_session_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_object_ops structure contains pointers to object
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_object_ops {
|
||||
int (*object_create)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_object_attribute_t *, uint_t, crypto_object_id_t *,
|
||||
crypto_req_handle_t);
|
||||
int (*object_copy)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_object_id_t, crypto_object_attribute_t *, uint_t,
|
||||
crypto_object_id_t *, crypto_req_handle_t);
|
||||
int (*object_destroy)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_object_id_t, crypto_req_handle_t);
|
||||
int (*object_get_size)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_object_id_t, size_t *, crypto_req_handle_t);
|
||||
int (*object_get_attribute_value)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_object_id_t,
|
||||
crypto_object_attribute_t *, uint_t, crypto_req_handle_t);
|
||||
int (*object_set_attribute_value)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_object_id_t,
|
||||
crypto_object_attribute_t *, uint_t, crypto_req_handle_t);
|
||||
int (*object_find_init)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_object_attribute_t *, uint_t, void **,
|
||||
crypto_req_handle_t);
|
||||
int (*object_find)(crypto_provider_handle_t, void *,
|
||||
crypto_object_id_t *, uint_t, uint_t *, crypto_req_handle_t);
|
||||
int (*object_find_final)(crypto_provider_handle_t, void *,
|
||||
crypto_req_handle_t);
|
||||
} crypto_object_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_key_ops structure contains pointers to key
|
||||
* operations for cryptographic providers. It is passed through
|
||||
* the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_key_ops {
|
||||
int (*key_generate)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_object_attribute_t *, uint_t,
|
||||
crypto_object_id_t *, crypto_req_handle_t);
|
||||
int (*key_generate_pair)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_object_attribute_t *, uint_t,
|
||||
crypto_object_attribute_t *, uint_t, crypto_object_id_t *,
|
||||
crypto_object_id_t *, crypto_req_handle_t);
|
||||
int (*key_wrap)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_object_id_t *,
|
||||
uchar_t *, size_t *, crypto_req_handle_t);
|
||||
int (*key_unwrap)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, uchar_t *, size_t *,
|
||||
crypto_object_attribute_t *, uint_t,
|
||||
crypto_object_id_t *, crypto_req_handle_t);
|
||||
int (*key_derive)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_object_attribute_t *,
|
||||
uint_t, crypto_object_id_t *, crypto_req_handle_t);
|
||||
int (*key_check)(crypto_provider_handle_t, crypto_mechanism_t *,
|
||||
crypto_key_t *);
|
||||
} crypto_key_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_provider_management_ops structure contains pointers
|
||||
* to management operations for cryptographic providers. It is passed
|
||||
* through the crypto_ops(9S) structure when providers register with the
|
||||
* kernel using crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_provider_management_ops {
|
||||
int (*ext_info)(crypto_provider_handle_t,
|
||||
crypto_provider_ext_info_t *, crypto_req_handle_t);
|
||||
int (*init_token)(crypto_provider_handle_t, char *, size_t,
|
||||
char *, crypto_req_handle_t);
|
||||
int (*init_pin)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
char *, size_t, crypto_req_handle_t);
|
||||
int (*set_pin)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
char *, size_t, char *, size_t, crypto_req_handle_t);
|
||||
} crypto_provider_management_ops_t;
|
||||
|
||||
typedef struct crypto_mech_ops {
|
||||
int (*copyin_mechanism)(crypto_provider_handle_t,
|
||||
crypto_mechanism_t *, crypto_mechanism_t *, int *, int);
|
||||
int (*copyout_mechanism)(crypto_provider_handle_t,
|
||||
crypto_mechanism_t *, crypto_mechanism_t *, int *, int);
|
||||
int (*free_mechanism)(crypto_provider_handle_t, crypto_mechanism_t *);
|
||||
} crypto_mech_ops_t;
|
||||
|
||||
typedef struct crypto_nostore_key_ops {
|
||||
int (*nostore_key_generate)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_mechanism_t *,
|
||||
crypto_object_attribute_t *, uint_t, crypto_object_attribute_t *,
|
||||
uint_t, crypto_req_handle_t);
|
||||
int (*nostore_key_generate_pair)(crypto_provider_handle_t,
|
||||
crypto_session_id_t, crypto_mechanism_t *,
|
||||
crypto_object_attribute_t *, uint_t, crypto_object_attribute_t *,
|
||||
uint_t, crypto_object_attribute_t *, uint_t,
|
||||
crypto_object_attribute_t *, uint_t, crypto_req_handle_t);
|
||||
int (*nostore_key_derive)(crypto_provider_handle_t, crypto_session_id_t,
|
||||
crypto_mechanism_t *, crypto_key_t *, crypto_object_attribute_t *,
|
||||
uint_t, crypto_object_attribute_t *, uint_t, crypto_req_handle_t);
|
||||
} crypto_nostore_key_ops_t;
|
||||
|
||||
/*
|
||||
* crypto_fips140_ops provides a function for FIPS 140 Power-On Self Test for
|
||||
* those providers that are part of the Cryptographic Framework bounday. See
|
||||
* crypto_fips140_ops(9s) for details.
|
||||
*/
|
||||
typedef struct crypto_fips140_ops {
|
||||
void (*fips140_post)(int *);
|
||||
} crypto_fips140_ops_t;
|
||||
|
||||
/*
|
||||
* The crypto_ops(9S) structure contains the structures containing
|
||||
* the pointers to functions implemented by cryptographic providers.
|
||||
* It is specified as part of the crypto_provider_info(9S)
|
||||
* supplied by a provider when it registers with the kernel
|
||||
* by calling crypto_register_provider(9F).
|
||||
*/
|
||||
typedef struct crypto_ops_v1 {
|
||||
crypto_control_ops_t *co_control_ops;
|
||||
crypto_digest_ops_t *co_digest_ops;
|
||||
crypto_cipher_ops_t *co_cipher_ops;
|
||||
crypto_mac_ops_t *co_mac_ops;
|
||||
crypto_sign_ops_t *co_sign_ops;
|
||||
crypto_verify_ops_t *co_verify_ops;
|
||||
crypto_dual_ops_t *co_dual_ops;
|
||||
crypto_dual_cipher_mac_ops_t *co_dual_cipher_mac_ops;
|
||||
crypto_random_number_ops_t *co_random_ops;
|
||||
crypto_session_ops_t *co_session_ops;
|
||||
crypto_object_ops_t *co_object_ops;
|
||||
crypto_key_ops_t *co_key_ops;
|
||||
crypto_provider_management_ops_t *co_provider_ops;
|
||||
crypto_ctx_ops_t *co_ctx_ops;
|
||||
} crypto_ops_v1_t;
|
||||
|
||||
typedef struct crypto_ops_v2 {
|
||||
crypto_ops_v1_t v1_ops;
|
||||
crypto_mech_ops_t *co_mech_ops;
|
||||
} crypto_ops_v2_t;
|
||||
|
||||
typedef struct crypto_ops_v3 {
|
||||
crypto_ops_v2_t v2_ops;
|
||||
crypto_nostore_key_ops_t *co_nostore_key_ops;
|
||||
} crypto_ops_v3_t;
|
||||
|
||||
typedef struct crypto_ops_v4 {
|
||||
crypto_ops_v3_t v3_ops;
|
||||
crypto_fips140_ops_t *co_fips140_ops;
|
||||
} crypto_ops_v4_t;
|
||||
|
||||
typedef struct crypto_ops_v5 {
|
||||
crypto_ops_v4_t v4_ops;
|
||||
boolean_t co_uio_userspace_ok;
|
||||
} crypto_ops_v5_t;
|
||||
|
||||
typedef struct crypto_ops {
|
||||
union {
|
||||
crypto_ops_v5_t cou_v5;
|
||||
crypto_ops_v4_t cou_v4;
|
||||
crypto_ops_v3_t cou_v3;
|
||||
crypto_ops_v2_t cou_v2;
|
||||
crypto_ops_v1_t cou_v1;
|
||||
} cou;
|
||||
} crypto_ops_t;
|
||||
|
||||
#define co_control_ops cou.cou_v1.co_control_ops
|
||||
#define co_digest_ops cou.cou_v1.co_digest_ops
|
||||
#define co_cipher_ops cou.cou_v1.co_cipher_ops
|
||||
#define co_mac_ops cou.cou_v1.co_mac_ops
|
||||
#define co_sign_ops cou.cou_v1.co_sign_ops
|
||||
#define co_verify_ops cou.cou_v1.co_verify_ops
|
||||
#define co_dual_ops cou.cou_v1.co_dual_ops
|
||||
#define co_dual_cipher_mac_ops cou.cou_v1.co_dual_cipher_mac_ops
|
||||
#define co_random_ops cou.cou_v1.co_random_ops
|
||||
#define co_session_ops cou.cou_v1.co_session_ops
|
||||
#define co_object_ops cou.cou_v1.co_object_ops
|
||||
#define co_key_ops cou.cou_v1.co_key_ops
|
||||
#define co_provider_ops cou.cou_v1.co_provider_ops
|
||||
#define co_ctx_ops cou.cou_v1.co_ctx_ops
|
||||
#define co_mech_ops cou.cou_v2.co_mech_ops
|
||||
#define co_nostore_key_ops cou.cou_v3.co_nostore_key_ops
|
||||
#define co_fips140_ops cou.cou_v4.co_fips140_ops
|
||||
#define co_uio_userspace_ok cou.cou_v5.co_uio_userspace_ok
|
||||
|
||||
/*
|
||||
* Provider device specification passed during registration.
|
||||
*
|
||||
* Software providers set the pi_provider_type field of provider_info_t
|
||||
* to CRYPTO_SW_PROVIDER, and set the pd_sw field of
|
||||
* crypto_provider_dev_t to the address of their modlinkage.
|
||||
*
|
||||
* Hardware providers set the pi_provider_type field of provider_info_t
|
||||
* to CRYPTO_HW_PROVIDER, and set the pd_hw field of
|
||||
* crypto_provider_dev_t to the dev_info structure corresponding
|
||||
* to the device instance being registered.
|
||||
*
|
||||
* Logical providers set the pi_provider_type field of provider_info_t
|
||||
* to CRYPTO_LOGICAL_PROVIDER, and set the pd_hw field of
|
||||
* crypto_provider_dev_t to the dev_info structure corresponding
|
||||
* to the device instance being registered.
|
||||
*/
|
||||
|
||||
typedef union crypto_provider_dev {
|
||||
struct modlinkage *pd_sw; /* for CRYPTO_SW_PROVIDER */
|
||||
dev_info_t *pd_hw; /* for CRYPTO_HW_PROVIDER */
|
||||
} crypto_provider_dev_t;
|
||||
|
||||
/*
|
||||
* The mechanism info structure crypto_mech_info_t contains a function group
|
||||
* bit mask cm_func_group_mask. This field, of type crypto_func_group_t,
|
||||
* specifies the provider entry point that can be used a particular
|
||||
* mechanism. The function group mask is a combination of the following values.
|
||||
*/
|
||||
|
||||
typedef uint32_t crypto_func_group_t;
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#define CRYPTO_FG_ENCRYPT 0x00000001 /* encrypt_init() */
|
||||
#define CRYPTO_FG_DECRYPT 0x00000002 /* decrypt_init() */
|
||||
#define CRYPTO_FG_DIGEST 0x00000004 /* digest_init() */
|
||||
#define CRYPTO_FG_SIGN 0x00000008 /* sign_init() */
|
||||
#define CRYPTO_FG_SIGN_RECOVER 0x00000010 /* sign_recover_init() */
|
||||
#define CRYPTO_FG_VERIFY 0x00000020 /* verify_init() */
|
||||
#define CRYPTO_FG_VERIFY_RECOVER 0x00000040 /* verify_recover_init() */
|
||||
#define CRYPTO_FG_GENERATE 0x00000080 /* key_generate() */
|
||||
#define CRYPTO_FG_GENERATE_KEY_PAIR 0x00000100 /* key_generate_pair() */
|
||||
#define CRYPTO_FG_WRAP 0x00000200 /* key_wrap() */
|
||||
#define CRYPTO_FG_UNWRAP 0x00000400 /* key_unwrap() */
|
||||
#define CRYPTO_FG_DERIVE 0x00000800 /* key_derive() */
|
||||
#define CRYPTO_FG_MAC 0x00001000 /* mac_init() */
|
||||
#define CRYPTO_FG_ENCRYPT_MAC 0x00002000 /* encrypt_mac_init() */
|
||||
#define CRYPTO_FG_MAC_DECRYPT 0x00004000 /* decrypt_mac_init() */
|
||||
#define CRYPTO_FG_ENCRYPT_ATOMIC 0x00008000 /* encrypt_atomic() */
|
||||
#define CRYPTO_FG_DECRYPT_ATOMIC 0x00010000 /* decrypt_atomic() */
|
||||
#define CRYPTO_FG_MAC_ATOMIC 0x00020000 /* mac_atomic() */
|
||||
#define CRYPTO_FG_DIGEST_ATOMIC 0x00040000 /* digest_atomic() */
|
||||
#define CRYPTO_FG_SIGN_ATOMIC 0x00080000 /* sign_atomic() */
|
||||
#define CRYPTO_FG_SIGN_RECOVER_ATOMIC 0x00100000 /* sign_recover_atomic() */
|
||||
#define CRYPTO_FG_VERIFY_ATOMIC 0x00200000 /* verify_atomic() */
|
||||
#define CRYPTO_FG_VERIFY_RECOVER_ATOMIC 0x00400000 /* verify_recover_atomic() */
|
||||
#define CRYPTO_FG_ENCRYPT_MAC_ATOMIC 0x00800000 /* encrypt_mac_atomic() */
|
||||
#define CRYPTO_FG_MAC_DECRYPT_ATOMIC 0x01000000 /* mac_decrypt_atomic() */
|
||||
#define CRYPTO_FG_RESERVED 0x80000000
|
||||
|
||||
/*
|
||||
* Maximum length of the pi_provider_description field of the
|
||||
* crypto_provider_info structure.
|
||||
*/
|
||||
#define CRYPTO_PROVIDER_DESCR_MAX_LEN 64
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
/* Bit mask for all the simple operations */
|
||||
#define CRYPTO_FG_SIMPLEOP_MASK (CRYPTO_FG_ENCRYPT | CRYPTO_FG_DECRYPT | \
|
||||
CRYPTO_FG_DIGEST | CRYPTO_FG_SIGN | CRYPTO_FG_VERIFY | CRYPTO_FG_MAC | \
|
||||
CRYPTO_FG_ENCRYPT_ATOMIC | CRYPTO_FG_DECRYPT_ATOMIC | \
|
||||
CRYPTO_FG_MAC_ATOMIC | CRYPTO_FG_DIGEST_ATOMIC | CRYPTO_FG_SIGN_ATOMIC | \
|
||||
CRYPTO_FG_VERIFY_ATOMIC)
|
||||
|
||||
/* Bit mask for all the dual operations */
|
||||
#define CRYPTO_FG_MAC_CIPHER_MASK (CRYPTO_FG_ENCRYPT_MAC | \
|
||||
CRYPTO_FG_MAC_DECRYPT | CRYPTO_FG_ENCRYPT_MAC_ATOMIC | \
|
||||
CRYPTO_FG_MAC_DECRYPT_ATOMIC)
|
||||
|
||||
/* Add other combos to CRYPTO_FG_DUAL_MASK */
|
||||
#define CRYPTO_FG_DUAL_MASK CRYPTO_FG_MAC_CIPHER_MASK
|
||||
|
||||
/*
|
||||
* The crypto_mech_info structure specifies one of the mechanisms
|
||||
* supported by a cryptographic provider. The pi_mechanisms field of
|
||||
* the crypto_provider_info structure contains a pointer to an array
|
||||
* of crypto_mech_info's.
|
||||
*/
|
||||
typedef struct crypto_mech_info {
|
||||
crypto_mech_name_t cm_mech_name;
|
||||
crypto_mech_type_t cm_mech_number;
|
||||
crypto_func_group_t cm_func_group_mask;
|
||||
ssize_t cm_min_key_length;
|
||||
ssize_t cm_max_key_length;
|
||||
uint32_t cm_mech_flags;
|
||||
} crypto_mech_info_t;
|
||||
|
||||
/* Alias the old name to the new name for compatibility. */
|
||||
#define cm_keysize_unit cm_mech_flags
|
||||
|
||||
/*
|
||||
* crypto_kcf_provider_handle_t is a handle allocated by the kernel.
|
||||
* It is returned after the provider registers with
|
||||
* crypto_register_provider(), and must be specified by the provider
|
||||
* when calling crypto_unregister_provider(), and
|
||||
* crypto_provider_notification().
|
||||
*/
|
||||
typedef uint_t crypto_kcf_provider_handle_t;
|
||||
|
||||
/*
|
||||
* Provider information. Passed as argument to crypto_register_provider(9F).
|
||||
* Describes the provider and its capabilities. Multiple providers can
|
||||
* register for the same device instance. In this case, the same
|
||||
* pi_provider_dev must be specified with a different pi_provider_handle.
|
||||
*/
|
||||
typedef struct crypto_provider_info_v1 {
|
||||
uint_t pi_interface_version;
|
||||
char *pi_provider_description;
|
||||
crypto_provider_type_t pi_provider_type;
|
||||
crypto_provider_dev_t pi_provider_dev;
|
||||
crypto_provider_handle_t pi_provider_handle;
|
||||
crypto_ops_t *pi_ops_vector;
|
||||
uint_t pi_mech_list_count;
|
||||
crypto_mech_info_t *pi_mechanisms;
|
||||
uint_t pi_logical_provider_count;
|
||||
crypto_kcf_provider_handle_t *pi_logical_providers;
|
||||
} crypto_provider_info_v1_t;
|
||||
|
||||
typedef struct crypto_provider_info_v2 {
|
||||
crypto_provider_info_v1_t v1_info;
|
||||
uint_t pi_flags;
|
||||
} crypto_provider_info_v2_t;
|
||||
|
||||
typedef struct crypto_provider_info {
|
||||
union {
|
||||
crypto_provider_info_v2_t piu_v2;
|
||||
crypto_provider_info_v1_t piu_v1;
|
||||
} piu;
|
||||
} crypto_provider_info_t;
|
||||
|
||||
#define pi_interface_version piu.piu_v1.pi_interface_version
|
||||
#define pi_provider_description piu.piu_v1.pi_provider_description
|
||||
#define pi_provider_type piu.piu_v1.pi_provider_type
|
||||
#define pi_provider_dev piu.piu_v1.pi_provider_dev
|
||||
#define pi_provider_handle piu.piu_v1.pi_provider_handle
|
||||
#define pi_ops_vector piu.piu_v1.pi_ops_vector
|
||||
#define pi_mech_list_count piu.piu_v1.pi_mech_list_count
|
||||
#define pi_mechanisms piu.piu_v1.pi_mechanisms
|
||||
#define pi_logical_provider_count piu.piu_v1.pi_logical_provider_count
|
||||
#define pi_logical_providers piu.piu_v1.pi_logical_providers
|
||||
#define pi_flags piu.piu_v2.pi_flags
|
||||
|
||||
/* hidden providers can only be accessed via a logical provider */
|
||||
#define CRYPTO_HIDE_PROVIDER 0x00000001
|
||||
/*
|
||||
* provider can not do multi-part digest (updates) and has a limit
|
||||
* on maximum input data that it can digest. The provider sets
|
||||
* this value in crypto_provider_ext_info_t by implementing
|
||||
* the ext_info entry point in the co_provider_ops vector.
|
||||
*/
|
||||
#define CRYPTO_HASH_NO_UPDATE 0x00000002
|
||||
/*
|
||||
* provider can not do multi-part HMAC (updates) and has a limit
|
||||
* on maximum input data that it can hmac. The provider sets
|
||||
* this value in crypto_provider_ext_info_t by implementing
|
||||
* the ext_info entry point in the co_provider_ops vector.
|
||||
*/
|
||||
#define CRYPTO_HMAC_NO_UPDATE 0x00000008
|
||||
|
||||
/* provider can handle the request without returning a CRYPTO_QUEUED */
|
||||
#define CRYPTO_SYNCHRONOUS 0x00000004
|
||||
|
||||
#define CRYPTO_PIFLAGS_RESERVED2 0x40000000
|
||||
#define CRYPTO_PIFLAGS_RESERVED1 0x80000000
|
||||
|
||||
/*
|
||||
* Provider status passed by a provider to crypto_provider_notification(9F)
|
||||
* and returned by the provider_stauts(9E) entry point.
|
||||
*/
|
||||
#define CRYPTO_PROVIDER_READY 0
|
||||
#define CRYPTO_PROVIDER_BUSY 1
|
||||
#define CRYPTO_PROVIDER_FAILED 2
|
||||
|
||||
/*
|
||||
* Functions exported by Solaris to cryptographic providers. Providers
|
||||
* call these functions to register and unregister, notify the kernel
|
||||
* of state changes, and notify the kernel when a asynchronous request
|
||||
* completed.
|
||||
*/
|
||||
extern int crypto_register_provider(crypto_provider_info_t *,
|
||||
crypto_kcf_provider_handle_t *);
|
||||
extern int crypto_unregister_provider(crypto_kcf_provider_handle_t);
|
||||
extern void crypto_provider_notification(crypto_kcf_provider_handle_t, uint_t);
|
||||
extern void crypto_op_notification(crypto_req_handle_t, int);
|
||||
extern int crypto_kmflag(crypto_req_handle_t);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_CRYPTO_SPI_H */
|
@ -1,410 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.extcheck;
|
||||
|
||||
import java.util.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Vector;
|
||||
import java.io.*;
|
||||
import java.util.StringTokenizer;
|
||||
import java.net.URL;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Attributes.Name;
|
||||
import java.net.URLConnection;
|
||||
import java.security.Permission;
|
||||
import java.util.jar.*;
|
||||
import java.net.JarURLConnection;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
/**
|
||||
* ExtCheck reports on clashes between a specified (target)
|
||||
* jar file and jar files already installed in the extensions
|
||||
* directory.
|
||||
*
|
||||
* @author Benedict Gomes
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class ExtCheck {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
// The following strings hold the values of the version variables
|
||||
// for the target jar file
|
||||
private String targetSpecTitle;
|
||||
private String targetSpecVersion;
|
||||
private String targetSpecVendor;
|
||||
private String targetImplTitle;
|
||||
private String targetImplVersion;
|
||||
private String targetImplVendor;
|
||||
private String targetsealed;
|
||||
|
||||
/* Flag to indicate whether extra information should be dumped to stdout */
|
||||
private boolean verboseFlag;
|
||||
|
||||
/*
|
||||
* Create a new instance of the jar reporting tool for a particular
|
||||
* targetFile.
|
||||
* @param targetFile is the file to compare against.
|
||||
* @param verbose indicates whether to dump filenames and manifest
|
||||
* information (on conflict) to the standard output.
|
||||
*/
|
||||
static ExtCheck create(File targetFile, boolean verbose) {
|
||||
return new ExtCheck(targetFile, verbose);
|
||||
}
|
||||
|
||||
private ExtCheck(File targetFile, boolean verbose) {
|
||||
verboseFlag = verbose;
|
||||
investigateTarget(targetFile);
|
||||
}
|
||||
|
||||
|
||||
private void investigateTarget(File targetFile) {
|
||||
verboseMessage("Target file:" + targetFile);
|
||||
Manifest targetManifest = null;
|
||||
try {
|
||||
File canon = new File(targetFile.getCanonicalPath());
|
||||
URL url = ParseUtil.fileToEncodedURL(canon);
|
||||
if (url != null){
|
||||
JarLoader loader = new JarLoader(url);
|
||||
JarFile jarFile = loader.getJarFile();
|
||||
targetManifest = jarFile.getManifest();
|
||||
}
|
||||
} catch (MalformedURLException e){
|
||||
error("Malformed URL ");
|
||||
} catch (IOException e) {
|
||||
error("IO Exception ");
|
||||
}
|
||||
if (targetManifest == null)
|
||||
error("No manifest available in "+targetFile);
|
||||
Attributes attr = targetManifest.getMainAttributes();
|
||||
if (attr != null) {
|
||||
targetSpecTitle = attr.getValue(Name.SPECIFICATION_TITLE);
|
||||
targetSpecVersion = attr.getValue(Name.SPECIFICATION_VERSION);
|
||||
targetSpecVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
|
||||
targetImplTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
|
||||
targetImplVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
|
||||
targetImplVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
|
||||
targetsealed = attr.getValue(Name.SEALED);
|
||||
} else {
|
||||
error("No attributes available in the manifest");
|
||||
}
|
||||
if (targetSpecTitle == null)
|
||||
error("The target file does not have a specification title");
|
||||
if (targetSpecVersion == null)
|
||||
error("The target file does not have a specification version");
|
||||
verboseMessage("Specification title:" + targetSpecTitle);
|
||||
verboseMessage("Specification version:" + targetSpecVersion);
|
||||
if (targetSpecVendor != null)
|
||||
verboseMessage("Specification vendor:" + targetSpecVendor);
|
||||
if (targetImplVersion != null)
|
||||
verboseMessage("Implementation version:" + targetImplVersion);
|
||||
if (targetImplVendor != null)
|
||||
verboseMessage("Implementation vendor:" + targetImplVendor);
|
||||
verboseMessage("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that none of the jar files in the install directory
|
||||
* has the same specification-title and the same or a newer
|
||||
* specification-version.
|
||||
*
|
||||
* @return Return true if the target jar file is newer
|
||||
* than any installed jar file with the same specification-title,
|
||||
* otherwise return false
|
||||
*/
|
||||
boolean checkInstalledAgainstTarget(){
|
||||
String s = System.getProperty("java.ext.dirs");
|
||||
File [] dirs;
|
||||
if (s != null) {
|
||||
StringTokenizer st =
|
||||
new StringTokenizer(s, File.pathSeparator);
|
||||
int count = st.countTokens();
|
||||
dirs = new File[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
dirs[i] = new File(st.nextToken());
|
||||
}
|
||||
} else {
|
||||
dirs = new File[0];
|
||||
}
|
||||
|
||||
boolean result = true;
|
||||
for (int i = 0; i < dirs.length; i++) {
|
||||
String[] files = dirs[i].list();
|
||||
if (files != null) {
|
||||
for (int j = 0; j < files.length; j++) {
|
||||
try {
|
||||
File f = new File(dirs[i],files[j]);
|
||||
File canon = new File(f.getCanonicalPath());
|
||||
URL url = ParseUtil.fileToEncodedURL(canon);
|
||||
if (url != null){
|
||||
result = result && checkURLRecursively(1,url);
|
||||
}
|
||||
} catch (MalformedURLException e){
|
||||
error("Malformed URL");
|
||||
} catch (IOException e) {
|
||||
error("IO Exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
generalMessage("No conflicting installed jar found.");
|
||||
} else {
|
||||
generalMessage("Conflicting installed jar found. "
|
||||
+ " Use -verbose for more information.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively verify that a jar file, and any urls mentioned
|
||||
* in its class path, do not conflict with the target jar file.
|
||||
*
|
||||
* @param indent is the current nesting level
|
||||
* @param url is the path to the jar file being checked.
|
||||
* @return true if there is no newer URL, otherwise false
|
||||
*/
|
||||
private boolean checkURLRecursively(int indent, URL url)
|
||||
throws IOException
|
||||
{
|
||||
verboseMessage("Comparing with " + url);
|
||||
JarLoader jarloader = new JarLoader(url);
|
||||
JarFile j = jarloader.getJarFile();
|
||||
Manifest man = j.getManifest();
|
||||
if (man != null) {
|
||||
Attributes attr = man.getMainAttributes();
|
||||
if (attr != null){
|
||||
String title = attr.getValue(Name.SPECIFICATION_TITLE);
|
||||
String version = attr.getValue(Name.SPECIFICATION_VERSION);
|
||||
String vendor = attr.getValue(Name.SPECIFICATION_VENDOR);
|
||||
String implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
|
||||
String implVersion
|
||||
= attr.getValue(Name.IMPLEMENTATION_VERSION);
|
||||
String implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
|
||||
String sealed = attr.getValue(Name.SEALED);
|
||||
if (title != null){
|
||||
if (title.equals(targetSpecTitle)){
|
||||
if (version != null){
|
||||
if (version.equals(targetSpecVersion) ||
|
||||
isNotOlderThan(version,targetSpecVersion)){
|
||||
verboseMessage("");
|
||||
verboseMessage("CONFLICT DETECTED ");
|
||||
verboseMessage("Conflicting file:"+ url);
|
||||
verboseMessage("Installed Version:" +
|
||||
version);
|
||||
if (implTitle != null)
|
||||
verboseMessage("Implementation Title:"+
|
||||
implTitle);
|
||||
if (implVersion != null)
|
||||
verboseMessage("Implementation Version:"+
|
||||
implVersion);
|
||||
if (implVendor != null)
|
||||
verboseMessage("Implementation Vendor:"+
|
||||
implVendor);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean result = true;
|
||||
URL[] loaderList = jarloader.getClassPath();
|
||||
if (loaderList != null) {
|
||||
for(int i=0; i < loaderList.length; i++){
|
||||
if (url != null){
|
||||
boolean res = checkURLRecursively(indent+1,loaderList[i]);
|
||||
result = res && result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* See comment in method java.lang.Package.isCompatibleWith.
|
||||
* Return true if already is not older than target. i.e. the
|
||||
* target file may be superseded by a file already installed
|
||||
*/
|
||||
private boolean isNotOlderThan(String already,String target)
|
||||
throws NumberFormatException
|
||||
{
|
||||
if (already == null || already.length() < 1) {
|
||||
throw new NumberFormatException("Empty version string");
|
||||
}
|
||||
|
||||
// Until it matches scan and compare numbers
|
||||
StringTokenizer dtok = new StringTokenizer(target, ".", true);
|
||||
StringTokenizer stok = new StringTokenizer(already, ".", true);
|
||||
while (dtok.hasMoreTokens() || stok.hasMoreTokens()) {
|
||||
int dver;
|
||||
int sver;
|
||||
if (dtok.hasMoreTokens()) {
|
||||
dver = Integer.parseInt(dtok.nextToken());
|
||||
} else
|
||||
dver = 0;
|
||||
|
||||
if (stok.hasMoreTokens()) {
|
||||
sver = Integer.parseInt(stok.nextToken());
|
||||
} else
|
||||
sver = 0;
|
||||
|
||||
if (sver < dver)
|
||||
return false; // Known to be incompatible
|
||||
if (sver > dver)
|
||||
return true; // Known to be compatible
|
||||
|
||||
// Check for and absorb separators
|
||||
if (dtok.hasMoreTokens())
|
||||
dtok.nextToken();
|
||||
if (stok.hasMoreTokens())
|
||||
stok.nextToken();
|
||||
// Compare next component
|
||||
}
|
||||
// All components numerically equal
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints out message if the verboseFlag is set
|
||||
*/
|
||||
void verboseMessage(String message){
|
||||
if (verboseFlag) {
|
||||
System.err.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
void generalMessage(String message){
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws a RuntimeException with a message describing the error.
|
||||
*/
|
||||
static void error(String message) throws RuntimeException {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class used to represent a loader of resources and classes
|
||||
* from a base URL. Somewhat modified version of code in
|
||||
* sun.misc.URLClassPath.JarLoader
|
||||
*/
|
||||
private static class JarLoader {
|
||||
private final URL base;
|
||||
private JarFile jar;
|
||||
private URL csu;
|
||||
|
||||
/*
|
||||
* Creates a new Loader for the specified URL.
|
||||
*/
|
||||
JarLoader(URL url) {
|
||||
String urlName = url + "!/";
|
||||
URL tmpBaseURL = null;
|
||||
try {
|
||||
tmpBaseURL = new URL("jar","",urlName);
|
||||
jar = findJarFile(url);
|
||||
csu = url;
|
||||
} catch (MalformedURLException e) {
|
||||
ExtCheck.error("Malformed url "+urlName);
|
||||
} catch (IOException e) {
|
||||
ExtCheck.error("IO Exception occurred");
|
||||
}
|
||||
base = tmpBaseURL;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the base URL for this Loader.
|
||||
*/
|
||||
URL getBaseURL() {
|
||||
return base;
|
||||
}
|
||||
|
||||
JarFile getJarFile() {
|
||||
return jar;
|
||||
}
|
||||
|
||||
private JarFile findJarFile(URL url) throws IOException {
|
||||
// Optimize case where url refers to a local jar file
|
||||
if ("file".equals(url.getProtocol())) {
|
||||
String path = url.getFile().replace('/', File.separatorChar);
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException(path);
|
||||
}
|
||||
return new JarFile(path);
|
||||
}
|
||||
URLConnection uc = getBaseURL().openConnection();
|
||||
//uc.setRequestProperty(USER_AGENT_JAVA_VERSION, JAVA_VERSION);
|
||||
return ((JarURLConnection)uc).getJarFile();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the JAR file local class path, or null if none.
|
||||
*/
|
||||
URL[] getClassPath() throws IOException {
|
||||
Manifest man = jar.getManifest();
|
||||
if (man != null) {
|
||||
Attributes attr = man.getMainAttributes();
|
||||
if (attr != null) {
|
||||
String value = attr.getValue(Name.CLASS_PATH);
|
||||
if (value != null) {
|
||||
return parseClassPath(csu, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses value of the Class-Path manifest attribute and returns
|
||||
* an array of URLs relative to the specified base URL.
|
||||
*/
|
||||
private URL[] parseClassPath(URL base, String value)
|
||||
throws MalformedURLException
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(value);
|
||||
URL[] urls = new URL[st.countTokens()];
|
||||
int i = 0;
|
||||
while (st.hasMoreTokens()) {
|
||||
String path = st.nextToken();
|
||||
urls[i] = new URL(base, path);
|
||||
i++;
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.extcheck;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Main program of extcheck
|
||||
*/
|
||||
|
||||
public final class Main {
|
||||
public static final String INSUFFICIENT = "Insufficient number of arguments";
|
||||
public static final String MISSING = "Missing <jar file> argument";
|
||||
public static final String DOES_NOT_EXIST = "Jarfile does not exist: ";
|
||||
public static final String EXTRA = "Extra command line argument: ";
|
||||
|
||||
/**
|
||||
* Terminates with one of the following codes
|
||||
* 1 A newer (or same version) jar file is already installed
|
||||
* 0 No newer jar file was found
|
||||
* -1 An internal error occurred
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
realMain(args);
|
||||
} catch (Exception ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void realMain(String[] args) throws Exception {
|
||||
if (args.length < 1) {
|
||||
usage(INSUFFICIENT);
|
||||
}
|
||||
int argIndex = 0;
|
||||
boolean verboseFlag = false;
|
||||
if (args[argIndex].equals("-verbose")) {
|
||||
verboseFlag = true;
|
||||
argIndex++;
|
||||
if (argIndex >= args.length) {
|
||||
usage(MISSING);
|
||||
}
|
||||
}
|
||||
String jarName = args[argIndex];
|
||||
argIndex++;
|
||||
File jarFile = new File(jarName);
|
||||
if (!jarFile.exists()){
|
||||
usage(DOES_NOT_EXIST + jarName);
|
||||
}
|
||||
if (argIndex < args.length) {
|
||||
usage(EXTRA + args[argIndex]);
|
||||
}
|
||||
ExtCheck jt = ExtCheck.create(jarFile,verboseFlag);
|
||||
boolean result = jt.checkInstalledAgainstTarget();
|
||||
if (result) {
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage(String msg) throws Exception {
|
||||
throw new Exception(msg + "\nUsage: extcheck [-verbose] <jar file>");
|
||||
}
|
||||
}
|
||||
|
@ -1,757 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The <CODE>BerDecoder</CODE> class is used for decoding
|
||||
* BER-encoded data.
|
||||
*
|
||||
* A <CODE>BerDecoder</CODE> needs to be set up with the byte string containing
|
||||
* the encoding. It maintains a current position in the byte string.
|
||||
*
|
||||
* Methods allows to fetch integer, string, OID, etc., from the current
|
||||
* position. After a fetch the current position is moved forward.
|
||||
*
|
||||
* A fetch throws a <CODE>BerException</CODE> if the encoding is not of the
|
||||
* expected type.
|
||||
*
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
public class BerDecoder {
|
||||
|
||||
/**
|
||||
* Constructs a new decoder and attaches it to the specified byte string.
|
||||
*
|
||||
* @param b The byte string containing the encoded data.
|
||||
*/
|
||||
|
||||
public BerDecoder(byte b[]) {
|
||||
bytes = b ;
|
||||
reset() ;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
next = 0 ;
|
||||
stackTop = 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an integer.
|
||||
*
|
||||
* @return The decoded integer.
|
||||
*
|
||||
* @exception BerException Current position does not point to an integer.
|
||||
*/
|
||||
|
||||
public int fetchInteger() throws BerException {
|
||||
return fetchInteger(IntegerTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an integer with the specified tag.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @return The decoded integer.
|
||||
*
|
||||
* @exception BerException Current position does not point to an integer
|
||||
* or the tag is not the expected one.
|
||||
*/
|
||||
|
||||
public int fetchInteger(int tag) throws BerException {
|
||||
int result = 0 ;
|
||||
final int backup = next ;
|
||||
try {
|
||||
if (fetchTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
result = fetchIntegerValue() ;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an integer and return a long value.
|
||||
*
|
||||
* @return The decoded integer.
|
||||
*
|
||||
* @exception BerException Current position does not point to an integer.
|
||||
*/
|
||||
|
||||
public long fetchIntegerAsLong() throws BerException {
|
||||
return fetchIntegerAsLong(IntegerTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an integer with the specified tag and return a long value.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @return The decoded integer.
|
||||
*
|
||||
* @exception BerException Current position does not point to an integer
|
||||
* or the tag is not the expected one.
|
||||
*/
|
||||
|
||||
public long fetchIntegerAsLong(int tag) throws BerException {
|
||||
long result = 0 ;
|
||||
final int backup = next ;
|
||||
try {
|
||||
if (fetchTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
result = fetchIntegerValueAsLong() ;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an octet string.
|
||||
*
|
||||
* @return The decoded string.
|
||||
*
|
||||
* @exception BerException Current position does not point to an octet string.
|
||||
*/
|
||||
|
||||
public byte[] fetchOctetString() throws BerException {
|
||||
return fetchOctetString(OctetStringTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an octet string with a specified tag.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @return The decoded string.
|
||||
*
|
||||
* @exception BerException Current position does not point to an octet string
|
||||
* or the tag is not the expected one.
|
||||
*/
|
||||
|
||||
public byte[] fetchOctetString(int tag) throws BerException {
|
||||
byte[] result = null ;
|
||||
final int backup = next ;
|
||||
try {
|
||||
if (fetchTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
result = fetchStringValue() ;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an object identifier.
|
||||
*
|
||||
* @return The decoded object identifier as an array of long.
|
||||
*/
|
||||
|
||||
public long[] fetchOid() throws BerException {
|
||||
return fetchOid(OidTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an object identifier with a specified tag.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @return The decoded object identifier as an array of long.
|
||||
*
|
||||
* @exception BerException Current position does not point to an oid
|
||||
* or the tag is not the expected one.
|
||||
*/
|
||||
|
||||
public long[] fetchOid(int tag) throws BerException {
|
||||
long[] result = null ;
|
||||
final int backup = next ;
|
||||
try {
|
||||
if (fetchTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
result = fetchOidValue() ;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a <CODE>NULL</CODE> value.
|
||||
*
|
||||
* @exception BerException Current position does not point to <CODE>NULL</CODE> value.
|
||||
*/
|
||||
|
||||
public void fetchNull() throws BerException {
|
||||
fetchNull(NullTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a <CODE>NULL</CODE> value with a specified tag.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @exception BerException Current position does not point to
|
||||
* <CODE>NULL</CODE> value or the tag is not the expected one.
|
||||
*/
|
||||
|
||||
public void fetchNull(int tag) throws BerException {
|
||||
final int backup = next ;
|
||||
try {
|
||||
if (fetchTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
final int length = fetchLength();
|
||||
if (length != 0) throw new BerException();
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an <CODE>ANY</CODE> value. In fact, this method does not decode anything
|
||||
* it simply returns the next TLV as an array of bytes.
|
||||
*
|
||||
* @return The TLV as a byte array.
|
||||
*
|
||||
* @exception BerException The next TLV is really badly encoded...
|
||||
*/
|
||||
|
||||
public byte[] fetchAny() throws BerException {
|
||||
byte[] result = null ;
|
||||
final int backup = next ;
|
||||
try {
|
||||
final int tag = fetchTag() ;
|
||||
final int contentLength = fetchLength() ;
|
||||
if (contentLength < 0) throw new BerException() ;
|
||||
final int tlvLength = next + contentLength - backup ;
|
||||
if (contentLength > (bytes.length - next))
|
||||
throw new IndexOutOfBoundsException("Decoded length exceeds buffer");
|
||||
final byte[] data = new byte[tlvLength] ;
|
||||
java.lang.System.arraycopy(bytes,backup,data,0,tlvLength);
|
||||
// for (int i = 0 ; i < tlvLength ; i++) {
|
||||
// data[i] = bytes[backup + i] ;
|
||||
// }
|
||||
next = next + contentLength ;
|
||||
result = data;
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
// catch(Error e) {
|
||||
// debug("fetchAny: Error decoding BER: " + e);
|
||||
// throw e;
|
||||
// }
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an <CODE>ANY</CODE> value with a specific tag.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @return The TLV as a byte array.
|
||||
*
|
||||
* @exception BerException The next TLV is really badly encoded...
|
||||
*/
|
||||
|
||||
public byte[] fetchAny(int tag) throws BerException {
|
||||
if (getTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
return fetchAny() ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a sequence header.
|
||||
* The decoder computes the end position of the sequence and push it
|
||||
* on its stack.
|
||||
*
|
||||
* @exception BerException Current position does not point to a sequence header.
|
||||
*/
|
||||
|
||||
public void openSequence() throws BerException {
|
||||
openSequence(SequenceTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a sequence header with a specific tag.
|
||||
*
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @exception BerException Current position does not point to a sequence header
|
||||
* or the tag is not the expected one.
|
||||
*/
|
||||
|
||||
public void openSequence(int tag) throws BerException {
|
||||
final int backup = next ;
|
||||
try {
|
||||
if (fetchTag() != tag) {
|
||||
throw new BerException() ;
|
||||
}
|
||||
final int l = fetchLength() ;
|
||||
if (l < 0) throw new BerException();
|
||||
if (l > (bytes.length - next)) throw new BerException();
|
||||
stackBuf[stackTop++] = next + l ;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close a sequence.
|
||||
* The decode pull the stack and verifies that the current position
|
||||
* matches with the calculated end of the sequence. If not it throws
|
||||
* an exception.
|
||||
*
|
||||
* @exception BerException The sequence is not expected to finish here.
|
||||
*/
|
||||
|
||||
public void closeSequence() throws BerException {
|
||||
if (stackBuf[stackTop - 1] == next) {
|
||||
stackTop-- ;
|
||||
}
|
||||
else {
|
||||
throw new BerException() ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return <CODE>true</CODE> if the end of the current sequence is not reached.
|
||||
* When this method returns <CODE>false</CODE>, <CODE>closeSequence</CODE> can (and must) be
|
||||
* invoked.
|
||||
*
|
||||
* @return <CODE>true</CODE> if there is still some data in the sequence.
|
||||
*/
|
||||
|
||||
public boolean cannotCloseSequence() {
|
||||
return (next < stackBuf[stackTop - 1]) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the tag of the data at the current position.
|
||||
* Current position is unchanged.
|
||||
*
|
||||
* @return The next tag.
|
||||
*/
|
||||
|
||||
public int getTag() throws BerException {
|
||||
int result = 0 ;
|
||||
final int backup = next ;
|
||||
try {
|
||||
result = fetchTag() ;
|
||||
}
|
||||
finally {
|
||||
next = backup ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String toString() {
|
||||
final StringBuffer result = new StringBuffer(bytes.length * 2) ;
|
||||
for (int i = 0 ; i < bytes.length ; i++) {
|
||||
final int b = (bytes[i] > 0) ? bytes[i] : bytes[i] + 256 ;
|
||||
if (i == next) {
|
||||
result.append("(") ;
|
||||
}
|
||||
result.append(Character.forDigit(b / 16, 16)) ;
|
||||
result.append(Character.forDigit(b % 16, 16)) ;
|
||||
if (i == next) {
|
||||
result.append(")") ;
|
||||
}
|
||||
}
|
||||
if (bytes.length == next) {
|
||||
result.append("()") ;
|
||||
}
|
||||
|
||||
return new String(result) ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Some standard tags
|
||||
//
|
||||
public final static int BooleanTag = 1 ;
|
||||
public final static int IntegerTag = 2 ;
|
||||
public final static int OctetStringTag = 4 ;
|
||||
public final static int NullTag = 5 ;
|
||||
public final static int OidTag = 6 ;
|
||||
public final static int SequenceTag = 0x30 ;
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////// PRIVATE ///////////////////////////////
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a tag and move the current position forward.
|
||||
*
|
||||
* @return The tag
|
||||
*/
|
||||
|
||||
private final int fetchTag() throws BerException {
|
||||
int result = 0 ;
|
||||
final int backup = next ;
|
||||
|
||||
try {
|
||||
final byte b0 = bytes[next++] ;
|
||||
result = (b0 >= 0) ? b0 : b0 + 256 ;
|
||||
if ((result & 31) == 31) {
|
||||
while ((bytes[next] & 128) != 0) {
|
||||
result = result << 7 ;
|
||||
result = result | (bytes[next++] & 127);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a length and move the current position forward.
|
||||
*
|
||||
* @return The length
|
||||
*/
|
||||
|
||||
private final int fetchLength() throws BerException {
|
||||
int result = 0 ;
|
||||
final int backup = next ;
|
||||
|
||||
try {
|
||||
final byte b0 = bytes[next++] ;
|
||||
if (b0 >= 0) {
|
||||
result = b0 ;
|
||||
}
|
||||
else {
|
||||
for (int c = 128 + b0 ; c > 0 ; c--) {
|
||||
final byte bX = bytes[next++] ;
|
||||
result = result << 8 ;
|
||||
result = result | ((bX >= 0) ? bX : bX+256) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an integer value and move the current position forward.
|
||||
*
|
||||
* @return The integer
|
||||
*/
|
||||
|
||||
private int fetchIntegerValue() throws BerException {
|
||||
int result = 0 ;
|
||||
final int backup = next ;
|
||||
|
||||
try {
|
||||
final int length = fetchLength() ;
|
||||
if (length <= 0) throw new BerException() ;
|
||||
if (length > (bytes.length - next)) throw
|
||||
new IndexOutOfBoundsException("Decoded length exceeds buffer");
|
||||
final int end = next + length ;
|
||||
result = bytes[next++] ;
|
||||
while (next < end) {
|
||||
final byte b = bytes[next++] ;
|
||||
if (b < 0) {
|
||||
result = (result << 8) | (256 + b) ;
|
||||
}
|
||||
else {
|
||||
result = (result << 8) | b ;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
catch(ArithmeticException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an integer value and return a long value.
|
||||
* FIX ME: someday we could have only on fetchIntegerValue() which always
|
||||
* returns a long value.
|
||||
*
|
||||
* @return The integer
|
||||
*/
|
||||
|
||||
private final long fetchIntegerValueAsLong() throws BerException {
|
||||
long result = 0 ;
|
||||
final int backup = next ;
|
||||
|
||||
try {
|
||||
final int length = fetchLength() ;
|
||||
if (length <= 0) throw new BerException() ;
|
||||
if (length > (bytes.length - next)) throw
|
||||
new IndexOutOfBoundsException("Decoded length exceeds buffer");
|
||||
|
||||
final int end = next + length ;
|
||||
result = bytes[next++] ;
|
||||
while (next < end) {
|
||||
final byte b = bytes[next++] ;
|
||||
if (b < 0) {
|
||||
result = (result << 8) | (256 + b) ;
|
||||
}
|
||||
else {
|
||||
result = (result << 8) | b ;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
catch(ArithmeticException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a byte string and move the current position forward.
|
||||
*
|
||||
* @return The byte string
|
||||
*/
|
||||
|
||||
private byte[] fetchStringValue() throws BerException {
|
||||
byte[] result = null ;
|
||||
final int backup = next ;
|
||||
|
||||
try {
|
||||
final int length = fetchLength() ;
|
||||
if (length < 0) throw new BerException() ;
|
||||
if (length > (bytes.length - next))
|
||||
throw new IndexOutOfBoundsException("Decoded length exceeds buffer");
|
||||
final byte data[] = new byte[length] ;
|
||||
java.lang.System.arraycopy(bytes,next,data,0,length);
|
||||
next += length;
|
||||
// int i = 0 ;
|
||||
// while (i < length) {
|
||||
// result[i++] = bytes[next++] ;
|
||||
// }
|
||||
result = data;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
catch(ArithmeticException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
// catch(Error e) {
|
||||
// debug("fetchStringValue: Error decoding BER: " + e);
|
||||
// throw e;
|
||||
// }
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an oid and move the current position forward.
|
||||
*
|
||||
* @return The oid
|
||||
*/
|
||||
|
||||
private final long[] fetchOidValue() throws BerException {
|
||||
long[] result = null ;
|
||||
final int backup = next ;
|
||||
|
||||
try {
|
||||
final int length = fetchLength() ;
|
||||
if (length <= 0) throw new BerException() ;
|
||||
if (length > (bytes.length - next))
|
||||
throw new IndexOutOfBoundsException("Decoded length exceeds buffer");
|
||||
// Count how many bytes have their 8th bit to 0
|
||||
// -> this gives the number of components in the oid
|
||||
int subidCount = 2 ;
|
||||
for (int i = 1 ; i < length ; i++) {
|
||||
if ((bytes[next + i] & 0x80) == 0) {
|
||||
subidCount++ ;
|
||||
}
|
||||
}
|
||||
final int datalen = subidCount;
|
||||
final long[] data = new long[datalen];
|
||||
final byte b0 = bytes[next++] ;
|
||||
|
||||
// bugId 4641746
|
||||
// The 8th bit of the first byte should always be set to 0
|
||||
if (b0 < 0) throw new BerException();
|
||||
|
||||
// bugId 4641746
|
||||
// The first sub Id cannot be greater than 2
|
||||
final long lb0 = b0 / 40 ;
|
||||
if (lb0 > 2) throw new BerException();
|
||||
|
||||
final long lb1 = b0 % 40;
|
||||
data[0] = lb0 ;
|
||||
data[1] = lb1 ;
|
||||
int i = 2 ;
|
||||
while (i < datalen) {
|
||||
long subid = 0 ;
|
||||
byte b = bytes[next++] ;
|
||||
while ((b & 0x80) != 0) {
|
||||
subid = (subid << 7) | (b & 0x7f) ;
|
||||
// bugId 4654674
|
||||
if (subid < 0) throw new BerException();
|
||||
b = bytes[next++] ;
|
||||
}
|
||||
subid = (subid << 7) | b ;
|
||||
// bugId 4654674
|
||||
if (subid < 0) throw new BerException();
|
||||
data[i++] = subid ;
|
||||
}
|
||||
result = data;
|
||||
}
|
||||
catch(BerException e) {
|
||||
next = backup ;
|
||||
throw e ;
|
||||
}
|
||||
catch(IndexOutOfBoundsException e) {
|
||||
next = backup ;
|
||||
throw new BerException() ;
|
||||
}
|
||||
// catch(Error e) {
|
||||
// debug("fetchOidValue: Error decoding BER: " + e);
|
||||
// throw e;
|
||||
// }
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
// private static final void debug(String str) {
|
||||
// System.out.println(str);
|
||||
// }
|
||||
|
||||
//
|
||||
// This is the byte array containing the encoding.
|
||||
//
|
||||
private final byte bytes[];
|
||||
|
||||
//
|
||||
// This is the current location. It is the next byte
|
||||
// to be decoded. It's an index in bytes[].
|
||||
//
|
||||
private int next = 0 ;
|
||||
|
||||
//
|
||||
// This is the stack where end of sequences are kept.
|
||||
// A value is computed and pushed in it each time openSequence()
|
||||
// is invoked.
|
||||
// A value is pulled and checked each time closeSequence() is called.
|
||||
//
|
||||
private final int stackBuf[] = new int[200] ;
|
||||
private int stackTop = 0 ;
|
||||
|
||||
}
|
@ -1,477 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp;
|
||||
|
||||
|
||||
/**
|
||||
* The <CODE>BerEncoder</CODE> class is used for encoding data using BER.
|
||||
*
|
||||
* A <CODE>BerEncoder</CODE> needs to be set up with a byte buffer. The encoded
|
||||
* data are stored in this byte buffer.
|
||||
* <P>
|
||||
* NOTE : the buffer is filled from end to start. This means the caller
|
||||
* needs to encode its data in the reverse order.
|
||||
*
|
||||
*
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
public class BerEncoder {
|
||||
|
||||
/**
|
||||
* Constructs a new encoder and attaches it to the specified byte string.
|
||||
*
|
||||
* @param b The byte string containing the encoded data.
|
||||
*/
|
||||
|
||||
public BerEncoder(byte b[]) {
|
||||
bytes = b ;
|
||||
start = b.length ;
|
||||
stackTop = 0 ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trim the encoding data and returns the length of the encoding.
|
||||
*
|
||||
* The encoder does backward encoding : so the bytes buffer is
|
||||
* filled from end to start. The encoded data must be shift before
|
||||
* the buffer can be used. This is the purpose of the <CODE>trim</CODE> method.
|
||||
*
|
||||
* After a call to the <CODE>trim</CODE> method, the encoder is reinitialized and <CODE>putXXX</CODE>
|
||||
* overwrite any existing encoded data.
|
||||
*
|
||||
* @return The length of the encoded data.
|
||||
*/
|
||||
|
||||
public int trim() {
|
||||
final int result = bytes.length - start ;
|
||||
|
||||
// for (int i = start ; i < bytes.length ; i++) {
|
||||
// bytes[i-start] = bytes[i] ;
|
||||
// }
|
||||
if (result > 0)
|
||||
java.lang.System.arraycopy(bytes,start,bytes,0,result);
|
||||
|
||||
start = bytes.length ;
|
||||
stackTop = 0 ;
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an integer.
|
||||
*
|
||||
* @param v The integer to encode.
|
||||
*/
|
||||
|
||||
public void putInteger(int v) {
|
||||
putInteger(v, IntegerTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an integer with the specified tag.
|
||||
*
|
||||
* @param v The integer to encode.
|
||||
* @param tag The tag to encode.
|
||||
*/
|
||||
|
||||
public void putInteger(int v, int tag) {
|
||||
putIntegerValue(v) ;
|
||||
putTag(tag) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put an integer expressed as a long.
|
||||
*
|
||||
* @param v The long to encode.
|
||||
*/
|
||||
|
||||
public void putInteger(long v) {
|
||||
putInteger(v, IntegerTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an integer expressed as a long with the specified tag.
|
||||
*
|
||||
* @param v The long to encode
|
||||
* @param tag The tag to encode.
|
||||
*/
|
||||
|
||||
public void putInteger(long v, int tag) {
|
||||
putIntegerValue(v) ;
|
||||
putTag(tag) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put an octet string.
|
||||
*
|
||||
* @param s The bytes to encode
|
||||
*/
|
||||
|
||||
public void putOctetString(byte[] s) {
|
||||
putOctetString(s, OctetStringTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an octet string with a specified tag.
|
||||
*
|
||||
* @param s The bytes to encode
|
||||
* @param tag The tag to encode.
|
||||
*/
|
||||
|
||||
public void putOctetString(byte[] s, int tag) {
|
||||
putStringValue(s) ;
|
||||
putTag(tag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an object identifier.
|
||||
*
|
||||
* @param s The oid to encode.
|
||||
*/
|
||||
|
||||
public void putOid(long[] s) {
|
||||
putOid(s, OidTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an object identifier with a specified tag.
|
||||
*
|
||||
* @param s The integer to encode.
|
||||
* @param tag The tag to encode.
|
||||
*/
|
||||
|
||||
public void putOid(long[] s, int tag) {
|
||||
putOidValue(s) ;
|
||||
putTag(tag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a <CODE>NULL</CODE> value.
|
||||
*/
|
||||
|
||||
public void putNull() {
|
||||
putNull(NullTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a <CODE>NULL</CODE> value with a specified tag.
|
||||
*
|
||||
* @param tag The tag to encode.
|
||||
*/
|
||||
|
||||
public void putNull(int tag) {
|
||||
putLength(0) ;
|
||||
putTag(tag) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put an <CODE>ANY</CODE> value. In fact, this method does not encode anything.
|
||||
* It simply copies the specified bytes into the encoding.
|
||||
*
|
||||
* @param s The encoding of the <CODE>ANY</CODE> value.
|
||||
*/
|
||||
|
||||
public void putAny(byte[] s) {
|
||||
putAny(s, s.length) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an <CODE>ANY</CODE> value. Only the first <CODE>byteCount</CODE> are considered.
|
||||
*
|
||||
* @param s The encoding of the <CODE>ANY</CODE> value.
|
||||
* @param byteCount The number of bytes of the encoding.
|
||||
*/
|
||||
|
||||
public void putAny(byte[] s, int byteCount) {
|
||||
java.lang.System.arraycopy(s,0,bytes,start-byteCount,byteCount);
|
||||
start -= byteCount;
|
||||
// for (int i = byteCount - 1 ; i >= 0 ; i--) {
|
||||
// bytes[--start] = s[i] ;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open a sequence.
|
||||
* The encoder push the current position on its stack.
|
||||
*/
|
||||
|
||||
public void openSequence() {
|
||||
stackBuf[stackTop++] = start ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close a sequence.
|
||||
* The decode pull the stack to know the end of the current sequence.
|
||||
*/
|
||||
|
||||
public void closeSequence() {
|
||||
closeSequence(SequenceTag) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close a sequence with the specified tag.
|
||||
*/
|
||||
|
||||
public void closeSequence(int tag) {
|
||||
final int end = stackBuf[--stackTop] ;
|
||||
putLength(end - start) ;
|
||||
putTag(tag) ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Some standard tags
|
||||
//
|
||||
public final static int BooleanTag = 1 ;
|
||||
public final static int IntegerTag = 2 ;
|
||||
public final static int OctetStringTag = 4 ;
|
||||
public final static int NullTag = 5 ;
|
||||
public final static int OidTag = 6 ;
|
||||
public final static int SequenceTag = 0x30 ;
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////// PROTECTED ///////////////////////////////
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put a tag and move the current position backward.
|
||||
*
|
||||
* @param tag The tag to encode.
|
||||
*/
|
||||
|
||||
protected final void putTag(int tag) {
|
||||
if (tag < 256) {
|
||||
bytes[--start] = (byte)tag ;
|
||||
}
|
||||
else {
|
||||
while (tag != 0) {
|
||||
bytes[--start] = (byte)(tag & 127) ;
|
||||
tag = tag << 7 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a length and move the current position backward.
|
||||
*
|
||||
* @param length The length to encode.
|
||||
*/
|
||||
|
||||
protected final void putLength(final int length) {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
else if (length < 128) {
|
||||
bytes[--start] = (byte)length ;
|
||||
}
|
||||
else if (length < 256) {
|
||||
bytes[--start] = (byte)length ;
|
||||
bytes[--start] = (byte)0x81 ;
|
||||
}
|
||||
else if (length < 65536) {
|
||||
bytes[--start] = (byte)(length) ;
|
||||
bytes[--start] = (byte)(length >> 8) ;
|
||||
bytes[--start] = (byte)0x82 ;
|
||||
}
|
||||
else if (length < 16777126) {
|
||||
bytes[--start] = (byte)(length) ;
|
||||
bytes[--start] = (byte)(length >> 8) ;
|
||||
bytes[--start] = (byte)(length >> 16) ;
|
||||
bytes[--start] = (byte)0x83 ;
|
||||
}
|
||||
else {
|
||||
bytes[--start] = (byte)(length) ;
|
||||
bytes[--start] = (byte)(length >> 8) ;
|
||||
bytes[--start] = (byte)(length >> 16) ;
|
||||
bytes[--start] = (byte)(length >> 24) ;
|
||||
bytes[--start] = (byte)0x84 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an integer value and move the current position backward.
|
||||
*
|
||||
* @param v The integer to encode.
|
||||
*/
|
||||
|
||||
protected final void putIntegerValue(int v) {
|
||||
final int end = start ;
|
||||
int mask = 0x7f800000 ;
|
||||
int byteNeeded = 4 ;
|
||||
if (v < 0) {
|
||||
while (((mask & v) == mask) && (byteNeeded > 1)) {
|
||||
mask = mask >> 8 ;
|
||||
byteNeeded-- ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (((mask & v) == 0) && (byteNeeded > 1)) {
|
||||
mask = mask >> 8 ;
|
||||
byteNeeded-- ;
|
||||
}
|
||||
}
|
||||
for (int i = 0 ; i < byteNeeded ; i++) {
|
||||
bytes[--start] = (byte)v ;
|
||||
v = v >> 8 ;
|
||||
}
|
||||
putLength(end - start) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an integer value expressed as a long.
|
||||
*
|
||||
* @param v The integer to encode.
|
||||
*/
|
||||
|
||||
protected final void putIntegerValue(long v) {
|
||||
final int end = start ;
|
||||
long mask = 0x7f80000000000000L ;
|
||||
int byteNeeded = 8 ;
|
||||
if (v < 0) {
|
||||
while (((mask & v) == mask) && (byteNeeded > 1)) {
|
||||
mask = mask >> 8 ;
|
||||
byteNeeded-- ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (((mask & v) == 0) && (byteNeeded > 1)) {
|
||||
mask = mask >> 8 ;
|
||||
byteNeeded-- ;
|
||||
}
|
||||
}
|
||||
for (int i = 0 ; i < byteNeeded ; i++) {
|
||||
bytes[--start] = (byte)v ;
|
||||
v = v >> 8 ;
|
||||
}
|
||||
putLength(end - start) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a byte string and move the current position backward.
|
||||
*
|
||||
* @param s The byte string to encode.
|
||||
*/
|
||||
|
||||
protected final void putStringValue(byte[] s) {
|
||||
final int datalen = s.length;
|
||||
java.lang.System.arraycopy(s,0,bytes,start-datalen,datalen);
|
||||
start -= datalen;
|
||||
// for (int i = s.length - 1 ; i >= 0 ; i--) {
|
||||
// bytes[--start] = s[i] ;
|
||||
// }
|
||||
putLength(datalen) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put an oid and move the current position backward.
|
||||
*
|
||||
* @param s The oid to encode.
|
||||
*/
|
||||
|
||||
protected final void putOidValue(final long[] s) {
|
||||
final int end = start ;
|
||||
final int slength = s.length;
|
||||
|
||||
// bugId 4641746: 0, 1, and 2 are legal values.
|
||||
if ((slength < 2) || (s[0] > 2) || (s[1] >= 40)) {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
for (int i = slength - 1 ; i >= 2 ; i--) {
|
||||
long c = s[i] ;
|
||||
if (c < 0) {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
else if (c < 128) {
|
||||
bytes[--start] = (byte)c ;
|
||||
}
|
||||
else {
|
||||
bytes[--start] = (byte)(c & 127) ;
|
||||
c = c >> 7 ;
|
||||
while (c != 0) {
|
||||
bytes[--start] = (byte)(c | 128) ;
|
||||
c = c >> 7 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
bytes[--start] = (byte)(s[0] * 40 + s[1]) ;
|
||||
putLength(end - start) ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// This is the byte array containing the encoding.
|
||||
//
|
||||
protected final byte bytes[];
|
||||
|
||||
//
|
||||
// This is the index of the first byte of the encoding.
|
||||
// It is initialized to <CODE>bytes.length</CODE> and decrease each time
|
||||
// an value is put in the encoder.
|
||||
//
|
||||
protected int start = -1 ;
|
||||
|
||||
//
|
||||
// This is the stack where end of sequences are kept.
|
||||
// A value is computed and pushed in it each time the <CODE>openSequence</CODE> method
|
||||
// is invoked.
|
||||
// A value is pulled and checked each time the <CODE>closeSequence</CODE> method is called.
|
||||
//
|
||||
protected final int stackBuf[] = new int[200] ;
|
||||
protected int stackTop = 0 ;
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Exception thrown when a BER encoding/decoding error occurs.
|
||||
*
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
public class BerException extends Exception {
|
||||
private static final long serialVersionUID = 494709767137042951L;
|
||||
|
||||
public static final int BAD_VERSION=1;
|
||||
|
||||
private int errorType= 0;
|
||||
|
||||
public BerException() {
|
||||
errorType= 0;
|
||||
}
|
||||
|
||||
public BerException(int x) {
|
||||
errorType= x;
|
||||
}
|
||||
|
||||
public boolean isInvalidSnmpVersion() {
|
||||
if (errorType == BAD_VERSION)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,304 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.jmx.snmp;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Hashtable;
|
||||
|
||||
|
||||
/**
|
||||
* This class is an internal class which is used to represent RowStatus
|
||||
* codes as defined in RFC 2579.
|
||||
*
|
||||
* It defines an additional code, <i>unspecified</i>, which is
|
||||
* implementation specific, and is used to identify
|
||||
* unspecified actions (when for instance the RowStatus variable
|
||||
* is not present in the varbind list) or uninitialized values.
|
||||
*
|
||||
* mibgen does not generate objects of this class but any variable
|
||||
* using the RowStatus textual convention can be converted into an
|
||||
* object of this class thanks to the
|
||||
* <code>EnumRowStatus(Enumerated valueIndex)</code> constructor.
|
||||
*
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
**/
|
||||
|
||||
public class EnumRowStatus extends Enumerated implements Serializable {
|
||||
private static final long serialVersionUID = 8966519271130162420L;
|
||||
|
||||
/**
|
||||
* This value is SNMP Runtime implementation specific, and is used to identify
|
||||
* unspecified actions (when for instance the RowStatus variable
|
||||
* is not present in the varbind list) or uninitialized values.
|
||||
*/
|
||||
public final static int unspecified = 0;
|
||||
|
||||
/**
|
||||
* This value corresponds to the <i>active</i> RowStatus, as defined in
|
||||
* RFC 2579 from SMIv2:
|
||||
* <ul>
|
||||
* <i>active</i> indicates that the conceptual row is available for
|
||||
* use by the managed device;
|
||||
* </ul>
|
||||
*/
|
||||
public final static int active = 1;
|
||||
|
||||
/**
|
||||
* This value corresponds to the <i>notInService</i> RowStatus, as
|
||||
* defined in RFC 2579 from SMIv2:
|
||||
* <ul>
|
||||
* <i>notInService</i> indicates that the conceptual
|
||||
* row exists in the agent, but is unavailable for use by
|
||||
* the managed device; <i>notInService</i> has
|
||||
* no implication regarding the internal consistency of
|
||||
* the row, availability of resources, or consistency with
|
||||
* the current state of the managed device;
|
||||
* </ul>
|
||||
**/
|
||||
public final static int notInService = 2;
|
||||
|
||||
/**
|
||||
* This value corresponds to the <i>notReady</i> RowStatus, as defined
|
||||
* in RFC 2579 from SMIv2:
|
||||
* <ul>
|
||||
* <i>notReady</i> indicates that the conceptual row
|
||||
* exists in the agent, but is missing information
|
||||
* necessary in order to be available for use by the
|
||||
* managed device (i.e., one or more required columns in
|
||||
* the conceptual row have not been instantiated);
|
||||
* </ul>
|
||||
*/
|
||||
public final static int notReady = 3;
|
||||
|
||||
/**
|
||||
* This value corresponds to the <i>createAndGo</i> RowStatus,
|
||||
* as defined in RFC 2579 from SMIv2:
|
||||
* <ul>
|
||||
* <i>createAndGo</i> is supplied by a management
|
||||
* station wishing to create a new instance of a
|
||||
* conceptual row and to have its status automatically set
|
||||
* to active, making it available for use by the managed
|
||||
* device;
|
||||
* </ul>
|
||||
*/
|
||||
public final static int createAndGo = 4;
|
||||
|
||||
/**
|
||||
* This value corresponds to the <i>createAndWait</i> RowStatus,
|
||||
* as defined in RFC 2579 from SMIv2:
|
||||
* <ul>
|
||||
* <i>createAndWait</i> is supplied by a management
|
||||
* station wishing to create a new instance of a
|
||||
* conceptual row (but not make it available for use by
|
||||
* the managed device);
|
||||
* </ul>
|
||||
*/
|
||||
public final static int createAndWait = 5;
|
||||
|
||||
/**
|
||||
* This value corresponds to the <i>destroy</i> RowStatus, as defined in
|
||||
* RFC 2579 from SMIv2:
|
||||
* <ul>
|
||||
* <i>destroy</i> is supplied by a management station
|
||||
* wishing to delete all of the instances associated with
|
||||
* an existing conceptual row.
|
||||
* </ul>
|
||||
*/
|
||||
public final static int destroy = 6;
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from an <code>int</code>.
|
||||
* @param valueIndex should be either 0 (<i>unspecified</i>), or one of
|
||||
* the values defined in RFC 2579.
|
||||
* @exception IllegalArgumentException if the given
|
||||
* <code>valueIndex</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(int valueIndex)
|
||||
throws IllegalArgumentException {
|
||||
super(valueIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from an <code>Enumerated</code>.
|
||||
* @param valueIndex should be either 0 (<i>unspecified</i>), or one of
|
||||
* the values defined in RFC 2579.
|
||||
* @exception IllegalArgumentException if the given
|
||||
* <code>valueIndex</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(Enumerated valueIndex)
|
||||
throws IllegalArgumentException {
|
||||
this(valueIndex.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from a <code>long</code>.
|
||||
* @param valueIndex should be either 0 (<i>unspecified</i>), or one of
|
||||
* the values defined in RFC 2579.
|
||||
* @exception IllegalArgumentException if the given
|
||||
* <code>valueIndex</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(long valueIndex)
|
||||
throws IllegalArgumentException {
|
||||
this((int)valueIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from an <code>Integer</code>.
|
||||
* @param valueIndex should be either 0 (<i>unspecified</i>), or one of
|
||||
* the values defined in RFC 2579.
|
||||
* @exception IllegalArgumentException if the given
|
||||
* <code>valueIndex</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(Integer valueIndex)
|
||||
throws IllegalArgumentException {
|
||||
super(valueIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from a <code>Long</code>.
|
||||
* @param valueIndex should be either 0 (<i>unspecified</i>), or one of
|
||||
* the values defined in RFC 2579.
|
||||
* @exception IllegalArgumentException if the given
|
||||
* <code>valueIndex</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(Long valueIndex)
|
||||
throws IllegalArgumentException {
|
||||
this(valueIndex.longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> with <i>unspecified</i> value.
|
||||
**/
|
||||
public EnumRowStatus()
|
||||
throws IllegalArgumentException {
|
||||
this(unspecified);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from a <code>String</code>.
|
||||
* @param x should be either "unspecified", or one of
|
||||
* the values defined in RFC 2579 ("active", "notReady", etc...)
|
||||
* @exception IllegalArgumentException if the given String
|
||||
* <code>x</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(String x)
|
||||
throws IllegalArgumentException {
|
||||
super(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an <code>EnumRowStatus</code> from an <code>SnmpInt</code>.
|
||||
* @param valueIndex should be either 0 (<i>unspecified</i>), or one of
|
||||
* the values defined in RFC 2579.
|
||||
* @exception IllegalArgumentException if the given
|
||||
* <code>valueIndex</code> is not valid.
|
||||
**/
|
||||
public EnumRowStatus(SnmpInt valueIndex)
|
||||
throws IllegalArgumentException {
|
||||
this(valueIndex.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SnmpValue from this object.
|
||||
*
|
||||
* @exception IllegalArgumentException if this object holds an
|
||||
* <i>unspecified</i> value.
|
||||
* @return an SnmpInt containing this object value.
|
||||
**/
|
||||
public SnmpInt toSnmpValue()
|
||||
throws IllegalArgumentException {
|
||||
if (value == unspecified)
|
||||
throw new
|
||||
IllegalArgumentException("`unspecified' is not a valid SNMP value.");
|
||||
return new SnmpInt(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the given <code>value</code> is valid.
|
||||
*
|
||||
* Valid values are:
|
||||
* <ul><li><i>unspecified(0)</i></li>
|
||||
* <li><i>active(1)</i></li>
|
||||
* <li><i>notInService(2)</i></li>
|
||||
* <li><i>notReady(3)</i></li>
|
||||
* <li><i>createAndGo(4)</i></li>
|
||||
* <li><i>createAndWait(5)</i></li>
|
||||
* <li><i>destroy(6)</i></li>
|
||||
* </ul>
|
||||
*
|
||||
**/
|
||||
static public boolean isValidValue(int value) {
|
||||
if (value < 0) return false;
|
||||
if (value > 6) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Documented in Enumerated
|
||||
//
|
||||
@Override
|
||||
protected Hashtable<Integer, String> getIntTable() {
|
||||
return EnumRowStatus.getRSIntTable();
|
||||
}
|
||||
|
||||
// Documented in Enumerated
|
||||
//
|
||||
@Override
|
||||
protected Hashtable<String, Integer> getStringTable() {
|
||||
return EnumRowStatus.getRSStringTable();
|
||||
}
|
||||
|
||||
static Hashtable<Integer, String> getRSIntTable() {
|
||||
return intTable ;
|
||||
}
|
||||
|
||||
static Hashtable<String, Integer> getRSStringTable() {
|
||||
return stringTable ;
|
||||
}
|
||||
|
||||
// Initialize the mapping tables.
|
||||
//
|
||||
final static Hashtable<Integer, String> intTable = new Hashtable<>();
|
||||
final static Hashtable<String, Integer> stringTable = new Hashtable<>();
|
||||
static {
|
||||
intTable.put(0, "unspecified");
|
||||
intTable.put(3, "notReady");
|
||||
intTable.put(6, "destroy");
|
||||
intTable.put(2, "notInService");
|
||||
intTable.put(5, "createAndWait");
|
||||
intTable.put(1, "active");
|
||||
intTable.put(4, "createAndGo");
|
||||
stringTable.put("unspecified", 0);
|
||||
stringTable.put("notReady", 3);
|
||||
stringTable.put("destroy", 6);
|
||||
stringTable.put("notInService", 2);
|
||||
stringTable.put("createAndWait", 5);
|
||||
stringTable.put("active", 1);
|
||||
stringTable.put("createAndGo", 4);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,221 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.jmx.snmp;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Hashtable;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
/** This class is used for implementing enumerated values.
|
||||
*
|
||||
* An enumeration is represented by a class derived from Enumerated.
|
||||
* The derived class defines what are the permitted values in the enumeration.
|
||||
*
|
||||
* An enumerated value is represented by an instance of the derived class.
|
||||
* It can be represented :
|
||||
* - as an integer
|
||||
* - as a string
|
||||
*
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
*/
|
||||
@SuppressWarnings("serial") // JDK implementation class
|
||||
abstract public class Enumerated implements Serializable {
|
||||
|
||||
/**
|
||||
* Construct an enumerated with a default value.
|
||||
* The default value is the first available in getIntTable().
|
||||
* @exception IllegalArgumentException One of the arguments passed to the method is illegal or inappropriate.
|
||||
*/
|
||||
public Enumerated() throws IllegalArgumentException {
|
||||
Enumeration<Integer> e =getIntTable().keys();
|
||||
if (e.hasMoreElements()) {
|
||||
value = e.nextElement().intValue() ;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an enumerated from its integer form.
|
||||
*
|
||||
* @param valueIndex The integer form.
|
||||
* @exception IllegalArgumentException One of the arguments passed to
|
||||
* the method is illegal or inappropriate.
|
||||
*/
|
||||
public Enumerated(int valueIndex) throws IllegalArgumentException {
|
||||
if (getIntTable().get(valueIndex) == null) {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
value = valueIndex ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an enumerated from its Integer form.
|
||||
*
|
||||
* @param valueIndex The Integer form.
|
||||
* @exception IllegalArgumentException One of the arguments passed to
|
||||
* the method is illegal or inappropriate.
|
||||
*/
|
||||
public Enumerated(Integer valueIndex) throws IllegalArgumentException {
|
||||
if (getIntTable().get(valueIndex) == null) {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
value = valueIndex.intValue() ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct an enumerated from its string form.
|
||||
*
|
||||
* @param valueString The string form.
|
||||
* @exception IllegalArgumentException One of the arguments passed
|
||||
* to the method is illegal or inappropriate.
|
||||
*/
|
||||
public Enumerated(String valueString) throws IllegalArgumentException {
|
||||
Integer index = getStringTable().get(valueString) ;
|
||||
if (index == null) {
|
||||
throw new IllegalArgumentException() ;
|
||||
}
|
||||
else {
|
||||
value = index.intValue() ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the integer form of the enumerated.
|
||||
*
|
||||
* @return The integer form
|
||||
*/
|
||||
|
||||
public int intValue() {
|
||||
return value ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an Java enumeration of the permitted integers.
|
||||
*
|
||||
* @return An enumeration of Integer instances
|
||||
*/
|
||||
|
||||
public Enumeration<Integer> valueIndexes() {
|
||||
return getIntTable().keys() ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an Java enumeration of the permitted strings.
|
||||
*
|
||||
* @return An enumeration of String instances
|
||||
*/
|
||||
|
||||
public Enumeration<String> valueStrings() {
|
||||
return getStringTable().keys() ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares this enumerated to the specified enumerated.
|
||||
*
|
||||
* The result is true if and only if the argument is not null
|
||||
* and is of the same class.
|
||||
*
|
||||
* @param obj The object to compare with.
|
||||
*
|
||||
* @return True if this and obj are the same; false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
return ((obj != null) &&
|
||||
(getClass() == obj.getClass()) &&
|
||||
(value == ((Enumerated)obj).value)) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hash code for this enumerated.
|
||||
*
|
||||
* @return A hash code value for this object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
String hashString = getClass().getName() + String.valueOf(value) ;
|
||||
return hashString.hashCode() ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the string form of this enumerated.
|
||||
*
|
||||
* @return The string for for this object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getIntTable().get(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hashtable of the integer forms.
|
||||
* getIntTable().get(x) returns the string form associated
|
||||
* to the integer x.
|
||||
*
|
||||
* This method must be implemented by the derived class.
|
||||
*
|
||||
* @return An hashtable for read-only purpose
|
||||
*/
|
||||
|
||||
protected abstract Hashtable<Integer,String> getIntTable() ;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hashtable of the string forms.
|
||||
* getStringTable().get(s) returns the integer form associated
|
||||
* to the string s.
|
||||
*
|
||||
* This method must be implemented by the derived class.
|
||||
*
|
||||
* @return An hashtable for read-only purpose
|
||||
*/
|
||||
|
||||
protected abstract Hashtable<String,Integer> getStringTable() ;
|
||||
|
||||
|
||||
/**
|
||||
* This variable keeps the integer form of the enumerated.
|
||||
* The string form is retrieved using getIntTable().
|
||||
*/
|
||||
protected int value ;
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
WARNING : ASCII_CharStream.java must be PATCHED.
|
||||
|
||||
The following methods should be removed after javacc generation.
|
||||
The goal is to simplify 100%-pure testing (see bug 4127719).
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see #getEndColumn
|
||||
*/
|
||||
|
||||
public final int getColumn() {
|
||||
return bufcolumn[bufpos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see #getEndLine
|
||||
*/
|
||||
|
||||
public final int getLine() {
|
||||
return bufline[bufpos];
|
||||
}
|
@ -1,402 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JavaCC: Do not edit this line. ASCII_CharStream.java Version 0.7pre6 */
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
/**
|
||||
* An implementation of interface CharStream, where the stream is assumed to
|
||||
* contain only ASCII characters (without unicode processing).
|
||||
*/
|
||||
|
||||
final class ASCII_CharStream
|
||||
{
|
||||
public static final boolean staticFlag = false;
|
||||
int bufsize;
|
||||
int available;
|
||||
int tokenBegin;
|
||||
public int bufpos = -1;
|
||||
private int bufline[];
|
||||
private int bufcolumn[];
|
||||
|
||||
private int column = 0;
|
||||
private int line = 1;
|
||||
|
||||
private boolean prevCharIsCR = false;
|
||||
private boolean prevCharIsLF = false;
|
||||
|
||||
private java.io.Reader inputStream;
|
||||
|
||||
private char[] buffer;
|
||||
private int maxNextCharInd = 0;
|
||||
private int inBuf = 0;
|
||||
|
||||
private final void ExpandBuff(boolean wrapAround)
|
||||
{
|
||||
char[] newbuffer = new char[bufsize + 2048];
|
||||
int newbufline[] = new int[bufsize + 2048];
|
||||
int newbufcolumn[] = new int[bufsize + 2048];
|
||||
|
||||
try
|
||||
{
|
||||
if (wrapAround)
|
||||
{
|
||||
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
|
||||
System.arraycopy(buffer, 0, newbuffer,
|
||||
bufsize - tokenBegin, bufpos);
|
||||
buffer = newbuffer;
|
||||
|
||||
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
|
||||
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
|
||||
bufline = newbufline;
|
||||
|
||||
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
|
||||
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
|
||||
bufcolumn = newbufcolumn;
|
||||
|
||||
maxNextCharInd = (bufpos += (bufsize - tokenBegin));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
|
||||
buffer = newbuffer;
|
||||
|
||||
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
|
||||
bufline = newbufline;
|
||||
|
||||
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
|
||||
bufcolumn = newbufcolumn;
|
||||
|
||||
maxNextCharInd = (bufpos -= tokenBegin);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new Error(t.getMessage());
|
||||
}
|
||||
|
||||
|
||||
bufsize += 2048;
|
||||
available = bufsize;
|
||||
tokenBegin = 0;
|
||||
}
|
||||
|
||||
private final void FillBuff() throws java.io.IOException
|
||||
{
|
||||
if (maxNextCharInd == available)
|
||||
{
|
||||
if (available == bufsize)
|
||||
{
|
||||
if (tokenBegin > 2048)
|
||||
{
|
||||
bufpos = maxNextCharInd = 0;
|
||||
available = tokenBegin;
|
||||
}
|
||||
else if (tokenBegin < 0)
|
||||
bufpos = maxNextCharInd = 0;
|
||||
else
|
||||
ExpandBuff(false);
|
||||
}
|
||||
else if (available > tokenBegin)
|
||||
available = bufsize;
|
||||
else if ((tokenBegin - available) < 2048)
|
||||
ExpandBuff(true);
|
||||
else
|
||||
available = tokenBegin;
|
||||
}
|
||||
|
||||
int i;
|
||||
try {
|
||||
if ((i = inputStream.read(buffer, maxNextCharInd,
|
||||
available - maxNextCharInd)) == -1)
|
||||
{
|
||||
inputStream.close();
|
||||
throw new java.io.IOException();
|
||||
}
|
||||
else
|
||||
maxNextCharInd += i;
|
||||
return;
|
||||
}
|
||||
catch(java.io.IOException e) {
|
||||
--bufpos;
|
||||
backup(0);
|
||||
if (tokenBegin == -1)
|
||||
tokenBegin = bufpos;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public final char BeginToken() throws java.io.IOException
|
||||
{
|
||||
tokenBegin = -1;
|
||||
char c = readChar();
|
||||
tokenBegin = bufpos;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private final void UpdateLineColumn(char c)
|
||||
{
|
||||
column++;
|
||||
|
||||
if (prevCharIsLF)
|
||||
{
|
||||
prevCharIsLF = false;
|
||||
line += (column = 1);
|
||||
}
|
||||
else if (prevCharIsCR)
|
||||
{
|
||||
prevCharIsCR = false;
|
||||
if (c == '\n')
|
||||
{
|
||||
prevCharIsLF = true;
|
||||
}
|
||||
else
|
||||
line += (column = 1);
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\r' :
|
||||
prevCharIsCR = true;
|
||||
break;
|
||||
case '\n' :
|
||||
prevCharIsLF = true;
|
||||
break;
|
||||
case '\t' :
|
||||
column--;
|
||||
column += (8 - (column & 07));
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
bufline[bufpos] = line;
|
||||
bufcolumn[bufpos] = column;
|
||||
}
|
||||
|
||||
public final char readChar() throws java.io.IOException
|
||||
{
|
||||
if (inBuf > 0)
|
||||
{
|
||||
--inBuf;
|
||||
return (char)((char)0xff & buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos]);
|
||||
}
|
||||
|
||||
if (++bufpos >= maxNextCharInd)
|
||||
FillBuff();
|
||||
|
||||
char c = (char)((char)0xff & buffer[bufpos]);
|
||||
|
||||
UpdateLineColumn(c);
|
||||
return (c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see #getEndColumn
|
||||
*/
|
||||
@Deprecated
|
||||
public final int getColumn() {
|
||||
return bufcolumn[bufpos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see #getEndLine
|
||||
*/
|
||||
@Deprecated
|
||||
public final int getLine() {
|
||||
return bufline[bufpos];
|
||||
}
|
||||
|
||||
public final int getEndColumn() {
|
||||
return bufcolumn[bufpos];
|
||||
}
|
||||
|
||||
public final int getEndLine() {
|
||||
return bufline[bufpos];
|
||||
}
|
||||
|
||||
public final int getBeginColumn() {
|
||||
return bufcolumn[tokenBegin];
|
||||
}
|
||||
|
||||
public final int getBeginLine() {
|
||||
return bufline[tokenBegin];
|
||||
}
|
||||
|
||||
public final void backup(int amount) {
|
||||
|
||||
inBuf += amount;
|
||||
if ((bufpos -= amount) < 0)
|
||||
bufpos += bufsize;
|
||||
}
|
||||
|
||||
public ASCII_CharStream(java.io.Reader dstream, int startline,
|
||||
int startcolumn, int buffersize)
|
||||
{
|
||||
inputStream = dstream;
|
||||
line = startline;
|
||||
column = startcolumn - 1;
|
||||
|
||||
available = bufsize = buffersize;
|
||||
buffer = new char[buffersize];
|
||||
bufline = new int[buffersize];
|
||||
bufcolumn = new int[buffersize];
|
||||
}
|
||||
|
||||
public ASCII_CharStream(java.io.Reader dstream, int startline,
|
||||
int startcolumn)
|
||||
{
|
||||
this(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
public void ReInit(java.io.Reader dstream, int startline,
|
||||
int startcolumn, int buffersize)
|
||||
{
|
||||
inputStream = dstream;
|
||||
line = startline;
|
||||
column = startcolumn - 1;
|
||||
|
||||
if (buffer == null || buffersize != buffer.length)
|
||||
{
|
||||
available = bufsize = buffersize;
|
||||
buffer = new char[buffersize];
|
||||
bufline = new int[buffersize];
|
||||
bufcolumn = new int[buffersize];
|
||||
}
|
||||
prevCharIsLF = prevCharIsCR = false;
|
||||
tokenBegin = inBuf = maxNextCharInd = 0;
|
||||
bufpos = -1;
|
||||
}
|
||||
|
||||
public void ReInit(java.io.Reader dstream, int startline,
|
||||
int startcolumn)
|
||||
{
|
||||
ReInit(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
public ASCII_CharStream(java.io.InputStream dstream, int startline,
|
||||
int startcolumn, int buffersize)
|
||||
{
|
||||
this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
|
||||
}
|
||||
|
||||
public ASCII_CharStream(java.io.InputStream dstream, int startline,
|
||||
int startcolumn)
|
||||
{
|
||||
this(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
|
||||
public void ReInit(java.io.InputStream dstream, int startline,
|
||||
int startcolumn, int buffersize)
|
||||
{
|
||||
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
|
||||
}
|
||||
public void ReInit(java.io.InputStream dstream, int startline,
|
||||
int startcolumn)
|
||||
{
|
||||
ReInit(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
public final String GetImage()
|
||||
{
|
||||
if (bufpos >= tokenBegin)
|
||||
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
|
||||
else
|
||||
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
|
||||
new String(buffer, 0, bufpos + 1);
|
||||
}
|
||||
|
||||
public final char[] GetSuffix(int len)
|
||||
{
|
||||
char[] ret = new char[len];
|
||||
|
||||
if ((bufpos + 1) >= len)
|
||||
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
|
||||
else
|
||||
{
|
||||
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
|
||||
len - bufpos - 1);
|
||||
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
buffer = null;
|
||||
bufline = null;
|
||||
bufcolumn = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to adjust line and column numbers for the start of a token.
|
||||
*/
|
||||
public void adjustBeginLineColumn(int newLine, int newCol)
|
||||
{
|
||||
int start = tokenBegin;
|
||||
int len;
|
||||
|
||||
if (bufpos >= tokenBegin)
|
||||
{
|
||||
len = bufpos - tokenBegin + inBuf + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
|
||||
}
|
||||
|
||||
int i = 0, j = 0, k = 0;
|
||||
int nextColDiff = 0, columnDiff = 0;
|
||||
|
||||
while (i < len &&
|
||||
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
|
||||
{
|
||||
bufline[j] = newLine;
|
||||
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
|
||||
bufcolumn[j] = newCol + columnDiff;
|
||||
columnDiff = nextColDiff;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i < len)
|
||||
{
|
||||
bufline[j] = newLine++;
|
||||
bufcolumn[j] = newCol + columnDiff;
|
||||
|
||||
while (i++ < len)
|
||||
{
|
||||
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
|
||||
bufline[j] = newLine++;
|
||||
else
|
||||
bufline[j] = newLine;
|
||||
}
|
||||
}
|
||||
|
||||
line = bufline[j];
|
||||
column = bufcolumn[j];
|
||||
}
|
||||
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
|
||||
import java.security.acl.Permission;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.io.Serializable;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.security.acl.AclEntry;
|
||||
|
||||
|
||||
/**
|
||||
* Represent one entry in the Access Control List (ACL).
|
||||
* This ACL entry object contains a permission associated with a particular principal.
|
||||
* (A principal represents an entity such as an individual machine or a group).
|
||||
*
|
||||
* @see java.security.acl.AclEntry
|
||||
*/
|
||||
|
||||
class AclEntryImpl implements AclEntry, Serializable {
|
||||
private static final long serialVersionUID = -5047185131260073216L;
|
||||
|
||||
private AclEntryImpl (AclEntryImpl i) throws UnknownHostException {
|
||||
setPrincipal(i.getPrincipal());
|
||||
permList = new Vector<Permission>();
|
||||
commList = new Vector<String>();
|
||||
|
||||
for (Enumeration<String> en = i.communities(); en.hasMoreElements();){
|
||||
addCommunity(en.nextElement());
|
||||
}
|
||||
|
||||
for (Enumeration<Permission> en = i.permissions(); en.hasMoreElements();){
|
||||
addPermission(en.nextElement());
|
||||
}
|
||||
if (i.isNegative()) setNegativePermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contructs an empty ACL entry.
|
||||
*/
|
||||
public AclEntryImpl (){
|
||||
princ = null;
|
||||
permList = new Vector<Permission>();
|
||||
commList = new Vector<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an ACL entry with a specified principal.
|
||||
*
|
||||
* @param p the principal to be set for this entry.
|
||||
*/
|
||||
public AclEntryImpl (Principal p) throws UnknownHostException {
|
||||
princ = p;
|
||||
permList = new Vector<Permission>();
|
||||
commList = new Vector<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this ACL entry.
|
||||
*
|
||||
* @return a clone of this ACL entry.
|
||||
*/
|
||||
public Object clone() {
|
||||
AclEntryImpl i;
|
||||
try {
|
||||
i = new AclEntryImpl(this);
|
||||
}catch (UnknownHostException e) {
|
||||
i = null;
|
||||
}
|
||||
return (Object) i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a negative ACL entry (one denying the associated principal
|
||||
* the set of permissions in the entry), false otherwise.
|
||||
*
|
||||
* @return true if this is a negative ACL entry, false if it's not.
|
||||
*/
|
||||
public boolean isNegative(){
|
||||
return neg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified permission to this ACL entry. Note: An entry can
|
||||
* have multiple permissions.
|
||||
*
|
||||
* @param perm the permission to be associated with the principal in this
|
||||
* entry
|
||||
* @return true if the permission is removed, false if the permission was
|
||||
* not part of this entry's permission set.
|
||||
*
|
||||
*/
|
||||
public boolean addPermission(java.security.acl.Permission perm){
|
||||
if (permList.contains(perm)) return false;
|
||||
permList.addElement(perm);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified permission from this ACL entry.
|
||||
*
|
||||
* @param perm the permission to be removed from this entry.
|
||||
* @return true if the permission is removed, false if the permission
|
||||
* was not part of this entry's permission set.
|
||||
*/
|
||||
public boolean removePermission(java.security.acl.Permission perm){
|
||||
if (!permList.contains(perm)) return false;
|
||||
permList.removeElement(perm);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified permission is part of the permission set in
|
||||
* this entry.
|
||||
*
|
||||
* @param perm the permission to be checked for.
|
||||
* @return true if the permission is part of the permission set in this
|
||||
* entry, false otherwise.
|
||||
*/
|
||||
|
||||
public boolean checkPermission(java.security.acl.Permission perm){
|
||||
return (permList.contains(perm));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an enumeration of the permissions in this ACL entry.
|
||||
*
|
||||
* @return an enumeration of the permissions in this ACL entry.
|
||||
*/
|
||||
public Enumeration<Permission> permissions(){
|
||||
return permList.elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this ACL entry to be a negative one. That is, the associated principal
|
||||
* (e.g., a user or a group) will be denied the permission set specified in the
|
||||
* entry. Note: ACL entries are by default positive. An entry becomes a negative
|
||||
* entry only if this setNegativePermissions method is called on it.
|
||||
*
|
||||
* Not Implemented.
|
||||
*/
|
||||
public void setNegativePermissions(){
|
||||
neg = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the principal for which permissions are granted or denied by this ACL
|
||||
* entry. Returns null if there is no principal set for this entry yet.
|
||||
*
|
||||
* @return the principal associated with this entry.
|
||||
*/
|
||||
public Principal getPrincipal(){
|
||||
return princ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the principal for which permissions are granted or denied by
|
||||
* this ACL entry. If a principal was already set for this ACL entry,
|
||||
* false is returned, otherwise true is returned.
|
||||
*
|
||||
* @param p the principal to be set for this entry.
|
||||
* @return true if the principal is set, false if there was already a
|
||||
* principal set for this entry.
|
||||
*/
|
||||
public boolean setPrincipal(Principal p) {
|
||||
if (princ != null )
|
||||
return false;
|
||||
princ = p;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the contents of this ACL entry.
|
||||
*
|
||||
* @return a string representation of the contents.
|
||||
*/
|
||||
public String toString(){
|
||||
return "AclEntry:"+princ.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an enumeration of the communities in this ACL entry.
|
||||
*
|
||||
* @return an enumeration of the communities in this ACL entry.
|
||||
*/
|
||||
public Enumeration<String> communities(){
|
||||
return commList.elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified community to this ACL entry. Note: An entry can
|
||||
* have multiple communities.
|
||||
*
|
||||
* @param comm the community to be associated with the principal
|
||||
* in this entry.
|
||||
* @return true if the community was added, false if the community was
|
||||
* already part of this entry's community set.
|
||||
*/
|
||||
public boolean addCommunity(String comm){
|
||||
if (commList.contains(comm)) return false;
|
||||
commList.addElement(comm);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified community from this ACL entry.
|
||||
*
|
||||
* @param comm the community to be removed from this entry.
|
||||
* @return true if the community is removed, false if the community was
|
||||
* not part of this entry's community set.
|
||||
*/
|
||||
public boolean removeCommunity(String comm){
|
||||
if (!commList.contains(comm)) return false;
|
||||
commList.removeElement(comm);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified community is part of the community set in this
|
||||
* entry.
|
||||
*
|
||||
* @param comm the community to be checked for.
|
||||
* @return true if the community is part of the community set in this
|
||||
* entry, false otherwise.
|
||||
*/
|
||||
public boolean checkCommunity(String comm){
|
||||
return (commList.contains(comm));
|
||||
}
|
||||
|
||||
private Principal princ = null;
|
||||
private boolean neg = false;
|
||||
private Vector<Permission> permList = null;
|
||||
private Vector<String> commList = null;
|
||||
}
|
@ -1,295 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
|
||||
import java.security.Principal;
|
||||
import java.security.acl.Acl;
|
||||
import java.security.acl.AclEntry;
|
||||
import java.security.acl.NotOwnerException;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.acl.Permission;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
|
||||
/**
|
||||
* Represent an Access Control List (ACL) which is used to guard access to http adaptor.
|
||||
* <P>
|
||||
* It is a data structure with multiple ACL entries. Each ACL entry, of interface type
|
||||
* AclEntry, contains a set of permissions and a set of communities associated with a
|
||||
* particular principal. (A principal represents an entity such as a host or a group of host).
|
||||
* Additionally, each ACL entry is specified as being either positive or negative.
|
||||
* If positive, the permissions are to be granted to the associated principal.
|
||||
* If negative, the permissions are to be denied.
|
||||
*
|
||||
* @see java.security.acl.Acl
|
||||
*/
|
||||
|
||||
class AclImpl extends OwnerImpl implements Acl, Serializable {
|
||||
private static final long serialVersionUID = -2250957591085270029L;
|
||||
|
||||
private Vector<AclEntry> entryList = null;
|
||||
private String aclName = null;
|
||||
|
||||
/**
|
||||
* Constructs the ACL with a specified owner
|
||||
*
|
||||
* @param owner owner of the ACL.
|
||||
* @param name name of this ACL.
|
||||
*/
|
||||
public AclImpl (PrincipalImpl owner, String name) {
|
||||
super(owner);
|
||||
entryList = new Vector<>();
|
||||
aclName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this ACL.
|
||||
*
|
||||
* @param caller the principal invoking this method. It must be an owner
|
||||
* of this ACL.
|
||||
* @param name the name to be given to this ACL.
|
||||
*
|
||||
* @exception NotOwnerException if the caller principal is not an owner
|
||||
* of this ACL.
|
||||
* @see java.security.Principal
|
||||
*/
|
||||
@Override
|
||||
public void setName(Principal caller, String name)
|
||||
throws NotOwnerException {
|
||||
if (!isOwner(caller))
|
||||
throw new NotOwnerException();
|
||||
aclName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this ACL.
|
||||
*
|
||||
* @return the name of this ACL.
|
||||
*/
|
||||
@Override
|
||||
public String getName(){
|
||||
return aclName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an ACL entry to this ACL. An entry associates a principal (e.g., an individual or a group)
|
||||
* with a set of permissions. Each principal can have at most one positive ACL entry
|
||||
* (specifying permissions to be granted to the principal) and one negative ACL entry
|
||||
* (specifying permissions to be denied). If there is already an ACL entry
|
||||
* of the same type (negative or positive) already in the ACL, false is returned.
|
||||
*
|
||||
* @param caller the principal invoking this method. It must be an owner
|
||||
* of this ACL.
|
||||
* @param entry the ACL entry to be added to this ACL.
|
||||
* @return true on success, false if an entry of the same type (positive
|
||||
* or negative) for the same principal is already present in this ACL.
|
||||
* @exception NotOwnerException if the caller principal is not an owner of
|
||||
* this ACL.
|
||||
* @see java.security.Principal
|
||||
*/
|
||||
@Override
|
||||
public boolean addEntry(Principal caller, AclEntry entry)
|
||||
throws NotOwnerException {
|
||||
if (!isOwner(caller))
|
||||
throw new NotOwnerException();
|
||||
|
||||
if (entryList.contains(entry))
|
||||
return false;
|
||||
/*
|
||||
for (Enumeration e = entryList.elements();e.hasMoreElements();){
|
||||
AclEntry ent = (AclEntry) e.nextElement();
|
||||
if (ent.getPrincipal().equals(entry.getPrincipal()))
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
entryList.addElement(entry);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an ACL entry from this ACL.
|
||||
*
|
||||
* @param caller the principal invoking this method. It must be an owner
|
||||
* of this ACL.
|
||||
* @param entry the ACL entry to be removed from this ACL.
|
||||
* @return true on success, false if the entry is not part of this ACL.
|
||||
* @exception NotOwnerException if the caller principal is not an owner
|
||||
* of this Acl.
|
||||
* @see java.security.Principal
|
||||
* @see java.security.acl.AclEntry
|
||||
*/
|
||||
@Override
|
||||
public boolean removeEntry(Principal caller, AclEntry entry)
|
||||
throws NotOwnerException {
|
||||
if (!isOwner(caller))
|
||||
throw new NotOwnerException();
|
||||
|
||||
return (entryList.removeElement(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all ACL entries from this ACL.
|
||||
*
|
||||
* @param caller the principal invoking this method. It must be an owner
|
||||
* of this ACL.
|
||||
* @exception NotOwnerException if the caller principal is not an owner of
|
||||
* this Acl.
|
||||
* @see java.security.Principal
|
||||
*/
|
||||
public void removeAll(Principal caller)
|
||||
throws NotOwnerException {
|
||||
if (!isOwner(caller))
|
||||
throw new NotOwnerException();
|
||||
entryList.removeAllElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an enumeration for the set of allowed permissions for
|
||||
* the specified principal
|
||||
* (representing an entity such as an individual or a group).
|
||||
* This set of allowed permissions is calculated as follows:
|
||||
* <UL>
|
||||
* <LI>If there is no entry in this Access Control List for the specified
|
||||
* principal, an empty permission set is returned.</LI>
|
||||
* <LI>Otherwise, the principal's group permission sets are determined.
|
||||
* (A principal can belong to one or more groups, where a group is a group
|
||||
* of principals, represented by the Group interface.)</LI>
|
||||
* </UL>
|
||||
* @param user the principal whose permission set is to be returned.
|
||||
* @return the permission set specifying the permissions the principal
|
||||
* is allowed.
|
||||
* @see java.security.Principal
|
||||
*/
|
||||
@Override
|
||||
public Enumeration<Permission> getPermissions(Principal user){
|
||||
Vector<Permission> empty = new Vector<>();
|
||||
for (Enumeration<AclEntry> e = entryList.elements();e.hasMoreElements();){
|
||||
AclEntry ent = e.nextElement();
|
||||
if (ent.getPrincipal().equals(user))
|
||||
return ent.permissions();
|
||||
}
|
||||
return empty.elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an enumeration of the entries in this ACL. Each element in the
|
||||
* enumeration is of type AclEntry.
|
||||
*
|
||||
* @return an enumeration of the entries in this ACL.
|
||||
*/
|
||||
@Override
|
||||
public Enumeration<AclEntry> entries(){
|
||||
return entryList.elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified principal has the specified
|
||||
* permission.
|
||||
* If it does, true is returned, otherwise false is returned.
|
||||
* More specifically, this method checks whether the passed permission
|
||||
* is a member of the allowed permission set of the specified principal.
|
||||
* The allowed permission set is determined by the same algorithm as is
|
||||
* used by the getPermissions method.
|
||||
*
|
||||
* @param user the principal, assumed to be a valid authenticated Principal.
|
||||
* @param perm the permission to be checked for.
|
||||
* @return true if the principal has the specified permission,
|
||||
* false otherwise.
|
||||
* @see java.security.Principal
|
||||
* @see java.security.Permission
|
||||
*/
|
||||
@Override
|
||||
public boolean checkPermission(Principal user,
|
||||
java.security.acl.Permission perm) {
|
||||
for (Enumeration<AclEntry> e = entryList.elements();e.hasMoreElements();){
|
||||
AclEntry ent = e.nextElement();
|
||||
if (ent.getPrincipal().equals(user))
|
||||
if (ent.checkPermission(perm)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified principal has the specified
|
||||
* permission.
|
||||
* If it does, true is returned, otherwise false is returned.
|
||||
* More specifically, this method checks whether the passed permission
|
||||
* is a member of the allowed permission set of the specified principal.
|
||||
* The allowed permission set is determined by the same algorithm as is
|
||||
* used by the getPermissions method.
|
||||
*
|
||||
* @param user the principal, assumed to be a valid authenticated Principal.
|
||||
* @param community the community name associated with the principal.
|
||||
* @param perm the permission to be checked for.
|
||||
* @return true if the principal has the specified permission, false
|
||||
* otherwise.
|
||||
* @see java.security.Principal
|
||||
* @see java.security.Permission
|
||||
*/
|
||||
public boolean checkPermission(Principal user, String community,
|
||||
java.security.acl.Permission perm) {
|
||||
for (Enumeration<AclEntry> e = entryList.elements();e.hasMoreElements();){
|
||||
AclEntryImpl ent = (AclEntryImpl) e.nextElement();
|
||||
if (ent.getPrincipal().equals(user))
|
||||
if (ent.checkPermission(perm) && ent.checkCommunity(community)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified community string is defined.
|
||||
*
|
||||
* @param community the community name associated with the principal.
|
||||
*
|
||||
* @return true if the specified community string is defined, false
|
||||
* otherwise.
|
||||
* @see java.security.Principal
|
||||
* @see java.security.Permission
|
||||
*/
|
||||
public boolean checkCommunity(String community) {
|
||||
for (Enumeration<AclEntry> e = entryList.elements();e.hasMoreElements();){
|
||||
AclEntryImpl ent = (AclEntryImpl) e.nextElement();
|
||||
if (ent.checkCommunity(community)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the ACL contents.
|
||||
*
|
||||
* @return a string representation of the ACL contents.
|
||||
*/
|
||||
@Override
|
||||
public String toString(){
|
||||
return ("AclImpl: "+ getName());
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.io.Serializable;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
||||
import java.security.Principal;
|
||||
import java.security.acl.Group;
|
||||
|
||||
|
||||
/**
|
||||
* This class is used to represent a subnet mask (a group of hosts
|
||||
* matching the same
|
||||
* IP mask).
|
||||
*
|
||||
*/
|
||||
|
||||
class GroupImpl extends PrincipalImpl implements Group, Serializable {
|
||||
private static final long serialVersionUID = -7777387035032541168L;
|
||||
|
||||
/**
|
||||
* Constructs an empty group.
|
||||
* @exception UnknownHostException Not implemented
|
||||
*/
|
||||
public GroupImpl () throws UnknownHostException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a group using the specified subnet mask.
|
||||
*
|
||||
* @param mask The subnet mask to use to build the group.
|
||||
* @exception UnknownHostException if the subnet mask cann't be built.
|
||||
*/
|
||||
public GroupImpl (String mask) throws UnknownHostException {
|
||||
super(mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified member to the group.
|
||||
*
|
||||
* @param p the principal to add to this group.
|
||||
* @return true if the member was successfully added, false if the
|
||||
* principal was already a member.
|
||||
*/
|
||||
public boolean addMember(Principal p) {
|
||||
// we don't need to add members because the ip address is a
|
||||
// subnet mask
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this group to the specified object. Returns true if the object
|
||||
* passed in matches the group represented.
|
||||
*
|
||||
* @param p the object to compare with.
|
||||
* @return true if the object passed in matches the subnet mask,
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean equals (Object p) {
|
||||
if (p instanceof PrincipalImpl || p instanceof GroupImpl){
|
||||
if ((super.hashCode() & p.hashCode()) == p.hashCode()) return true;
|
||||
else return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the passed principal is a member of the group.
|
||||
*
|
||||
* @param p the principal whose membership is to be checked.
|
||||
* @return true if the principal is a member of this group, false otherwise.
|
||||
*/
|
||||
public boolean isMember(Principal p) {
|
||||
if ((p.hashCode() & super.hashCode()) == p.hashCode()) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an enumeration which contains the subnet mask.
|
||||
*
|
||||
* @return an enumeration which contains the subnet mask.
|
||||
*/
|
||||
public Enumeration<? extends Principal> members(){
|
||||
Vector<Principal> v = new Vector<Principal>(1);
|
||||
v.addElement(this);
|
||||
return v.elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified member from the group. (Not implemented)
|
||||
*
|
||||
* @param p the principal to remove from this group.
|
||||
* @return allways return true.
|
||||
*/
|
||||
public boolean removeMember(Principal p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a string representation of this group.
|
||||
*
|
||||
* @return a string representation of this group.
|
||||
*/
|
||||
public String toString() {
|
||||
return ("GroupImpl :"+super.getAddress().toString());
|
||||
}
|
||||
}
|
@ -1,182 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
|
||||
// java import
|
||||
//
|
||||
import java.io.Serializable;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Vector;
|
||||
import java.security.acl.NotOwnerException;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.SNMP_LOGGER;
|
||||
|
||||
/**
|
||||
* The class defines an abstract representation of a host.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial") // JDK implementation class
|
||||
abstract class Host extends SimpleNode implements Serializable {
|
||||
|
||||
public Host(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Host(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
protected abstract PrincipalImpl createAssociatedPrincipal()
|
||||
throws UnknownHostException;
|
||||
|
||||
protected abstract String getHname();
|
||||
|
||||
public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {
|
||||
// Create a principal
|
||||
//
|
||||
PrincipalImpl p=null;
|
||||
try {
|
||||
p = createAssociatedPrincipal();
|
||||
} catch(UnknownHostException e) {
|
||||
if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
|
||||
SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
|
||||
"buildAclEntries",
|
||||
"Cannot create ACL entry; got exception", e);
|
||||
}
|
||||
throw new IllegalArgumentException("Cannot create ACL entry for " + e.getMessage());
|
||||
}
|
||||
|
||||
// Create an AclEntry
|
||||
//
|
||||
AclEntryImpl entry= null;
|
||||
try {
|
||||
entry = new AclEntryImpl(p);
|
||||
// Add permission
|
||||
//
|
||||
registerPermission(entry);
|
||||
acl.addEntry(owner, entry);
|
||||
} catch(UnknownHostException e) {
|
||||
if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
|
||||
SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
|
||||
"buildAclEntries",
|
||||
"Cannot create ACL entry; got exception", e);
|
||||
}
|
||||
return;
|
||||
} catch(NotOwnerException a) {
|
||||
if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
|
||||
SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
|
||||
"buildAclEntries",
|
||||
"Cannot create ACL entry; got exception", a);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPermission(AclEntryImpl entry) {
|
||||
JDMHost host= (JDMHost) jjtGetParent();
|
||||
JDMManagers manager= (JDMManagers) host.jjtGetParent();
|
||||
JDMAclItem acl= (JDMAclItem) manager.jjtGetParent();
|
||||
JDMAccess access= acl.getAccess();
|
||||
access.putPermission(entry);
|
||||
JDMCommunities comm= acl.getCommunities();
|
||||
comm.buildCommunities(entry);
|
||||
}
|
||||
|
||||
public void buildTrapEntries(Hashtable<InetAddress, Vector<String>> dest) {
|
||||
|
||||
JDMHostTrap host= (JDMHostTrap) jjtGetParent();
|
||||
JDMTrapInterestedHost hosts= (JDMTrapInterestedHost) host.jjtGetParent();
|
||||
JDMTrapItem trap = (JDMTrapItem) hosts.jjtGetParent();
|
||||
JDMTrapCommunity community = trap.getCommunity();
|
||||
String comm = community.getCommunity();
|
||||
|
||||
InetAddress add = null;
|
||||
try {
|
||||
add = java.net.InetAddress.getByName(getHname());
|
||||
} catch(UnknownHostException e) {
|
||||
if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
|
||||
SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
|
||||
"buildTrapEntries",
|
||||
"Cannot create TRAP entry; got exception", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<String> list = null;
|
||||
if (dest.containsKey(add)){
|
||||
list = dest.get(add);
|
||||
if (!list.contains(comm)){
|
||||
list.addElement(comm);
|
||||
}
|
||||
} else {
|
||||
list = new Vector<String>();
|
||||
list.addElement(comm);
|
||||
dest.put(add,list);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildInformEntries(Hashtable<InetAddress, Vector<String>> dest) {
|
||||
|
||||
JDMHostInform host= (JDMHostInform) jjtGetParent();
|
||||
JDMInformInterestedHost hosts= (JDMInformInterestedHost) host.jjtGetParent();
|
||||
JDMInformItem inform = (JDMInformItem) hosts.jjtGetParent();
|
||||
JDMInformCommunity community = inform.getCommunity();
|
||||
String comm = community.getCommunity();
|
||||
|
||||
InetAddress add = null;
|
||||
try {
|
||||
add = java.net.InetAddress.getByName(getHname());
|
||||
} catch(UnknownHostException e) {
|
||||
if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
|
||||
SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
|
||||
"buildTrapEntries",
|
||||
"Cannot create INFORM entry; got exception", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<String> list = null;
|
||||
if (dest.containsKey(add)){
|
||||
list = dest.get(add);
|
||||
if (!list.contains(comm)){
|
||||
list.addElement(comm);
|
||||
}
|
||||
} else {
|
||||
list = new Vector<String>();
|
||||
list.addElement(comm);
|
||||
dest.put(add,list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMAccess.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
class JDMAccess extends SimpleNode {
|
||||
protected int access= -1;
|
||||
|
||||
JDMAccess(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMAccess(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMAccess(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMAccess(p, id);
|
||||
}
|
||||
|
||||
protected void putPermission(AclEntryImpl entry) {
|
||||
if (access == ParserConstants.RO) {
|
||||
// We have a read-only access.
|
||||
//
|
||||
entry.addPermission(com.sun.jmx.snmp.IPAcl.SnmpAcl.getREAD());
|
||||
}
|
||||
if (access == ParserConstants.RW) {
|
||||
// We have a read-write access.
|
||||
//
|
||||
entry.addPermission(com.sun.jmx.snmp.IPAcl.SnmpAcl.getREAD());
|
||||
entry.addPermission(com.sun.jmx.snmp.IPAcl.SnmpAcl.getWRITE());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMAclBlock.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
class JDMAclBlock extends SimpleNode {
|
||||
JDMAclBlock(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMAclBlock(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMAclBlock(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMAclBlock(p, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do no need to go through this part of the tree for
|
||||
* building TrapEntry.
|
||||
*/
|
||||
@Override
|
||||
public void buildTrapEntries(Hashtable<InetAddress, Vector<String>> dest) {}
|
||||
|
||||
/**
|
||||
* Do no need to go through this part of the tree for
|
||||
* building InformEntry.
|
||||
*/
|
||||
@Override
|
||||
public void buildInformEntries(Hashtable<InetAddress, Vector<String>> dest) {}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMAclItem.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMAclItem extends SimpleNode {
|
||||
protected JDMAccess access= null;
|
||||
protected JDMCommunities com= null;
|
||||
|
||||
JDMAclItem(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMAclItem(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMAclItem(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMAclItem(p, id);
|
||||
}
|
||||
|
||||
public JDMAccess getAccess() {
|
||||
return access;
|
||||
}
|
||||
|
||||
public JDMCommunities getCommunities() {
|
||||
return com;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMCommunities.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
class JDMCommunities extends SimpleNode {
|
||||
JDMCommunities(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMCommunities(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMCommunities(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMCommunities(p, id);
|
||||
}
|
||||
|
||||
public void buildCommunities(AclEntryImpl entry){
|
||||
for (int i =0 ; i < children.length ; i++)
|
||||
entry.addCommunity(((JDMCommunity)children[i]).getCommunity());
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMCommunity.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMCommunity extends SimpleNode {
|
||||
protected String communityString= "";
|
||||
|
||||
JDMCommunity(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMCommunity(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMCommunity(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMCommunity(p, id);
|
||||
}
|
||||
|
||||
public String getCommunity(){
|
||||
return communityString;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMEnterprise.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMEnterprise extends SimpleNode {
|
||||
protected String enterprise= "";
|
||||
|
||||
JDMEnterprise(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMEnterprise(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMEnterprise(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMEnterprise(p, id);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMHost.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
|
||||
class JDMHost extends SimpleNode {
|
||||
|
||||
JDMHost(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMHost(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMHost(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMHost(p, id);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMHostInform.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMHostInform extends SimpleNode {
|
||||
protected String name= "";
|
||||
|
||||
JDMHostInform(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMHostInform(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMHostInform(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMHostInform(p, id);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMHostName.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
class JDMHostName extends Host {
|
||||
private static final long serialVersionUID = -9120082068923591122L;
|
||||
|
||||
protected StringBuffer name = new StringBuffer();
|
||||
|
||||
JDMHostName(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMHostName(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMHostName(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMHostName(p, id);
|
||||
}
|
||||
|
||||
protected String getHname() {
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
protected PrincipalImpl createAssociatedPrincipal()
|
||||
throws UnknownHostException {
|
||||
return new PrincipalImpl(name.toString());
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMHostTrap.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMHostTrap extends SimpleNode {
|
||||
protected String name= "";
|
||||
|
||||
JDMHostTrap(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMHostTrap(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMHostTrap(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMHostTrap(p, id);
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMInformBlock.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
class JDMInformBlock extends SimpleNode {
|
||||
JDMInformBlock(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMInformBlock(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMInformBlock(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMInformBlock(p, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do no need to go through this part of the tree for
|
||||
* building AclEntry.
|
||||
*/
|
||||
@Override
|
||||
public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {}
|
||||
|
||||
/**
|
||||
* Do no need to go through this part of the tree for
|
||||
* building TrapEntry.
|
||||
*/
|
||||
@Override
|
||||
public void buildTrapEntries(Hashtable<InetAddress, Vector<String>> dest) {}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMInformCommunity.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMInformCommunity extends SimpleNode {
|
||||
protected String community= "";
|
||||
JDMInformCommunity(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMInformCommunity(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMInformCommunity(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMInformCommunity(p, id);
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMInformInterestedHost.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMInformInterestedHost extends SimpleNode {
|
||||
JDMInformInterestedHost(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMInformInterestedHost(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMInformInterestedHost(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMInformInterestedHost(p, id);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMInformItem.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMInformItem extends SimpleNode {
|
||||
protected JDMInformCommunity comm = null;
|
||||
JDMInformItem(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMInformItem(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMInformItem(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMInformItem(p, id);
|
||||
}
|
||||
|
||||
public JDMInformCommunity getCommunity(){
|
||||
return comm;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMIpAddress.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
import java.lang.StringBuffer;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
class JDMIpAddress extends Host {
|
||||
private static final long serialVersionUID = 849729919486384484L;
|
||||
|
||||
protected StringBuffer address= new StringBuffer();
|
||||
|
||||
JDMIpAddress(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMIpAddress(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMIpAddress(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMIpAddress(p, id);
|
||||
}
|
||||
|
||||
protected String getHname() {
|
||||
return address.toString();
|
||||
}
|
||||
|
||||
protected PrincipalImpl createAssociatedPrincipal()
|
||||
throws UnknownHostException {
|
||||
return new PrincipalImpl(address.toString());
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMIpMask.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
import java.lang.StringBuffer;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
class JDMIpMask extends Host {
|
||||
private static final long serialVersionUID = -8211312690652331386L;
|
||||
|
||||
protected StringBuffer address= new StringBuffer();
|
||||
|
||||
JDMIpMask(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMIpMask(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMIpMask(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMIpMask(p, id);
|
||||
}
|
||||
|
||||
protected String getHname() {
|
||||
return address.toString();
|
||||
}
|
||||
|
||||
protected PrincipalImpl createAssociatedPrincipal()
|
||||
throws UnknownHostException {
|
||||
return new GroupImpl(address.toString());
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMIpV6Address.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMIpV6Address extends JDMIpAddress {
|
||||
private static final long serialVersionUID = -5929917334606674243L;
|
||||
|
||||
public JDMIpV6Address(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public JDMIpV6Address(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMManagers.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMManagers extends SimpleNode {
|
||||
JDMManagers(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMManagers(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMManagers(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMManagers(p, id);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/* Generated By:JJTree: Do not edit this line. JDMNetMask.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
class JDMNetMask extends Host {
|
||||
private static final long serialVersionUID = -1979318280250821787L;
|
||||
|
||||
protected StringBuffer address= new StringBuffer();
|
||||
protected String mask = null;
|
||||
public JDMNetMask(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public JDMNetMask(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMNetMask(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMNetMask(p, id);
|
||||
}
|
||||
|
||||
protected String getHname() {
|
||||
return address.toString();
|
||||
}
|
||||
|
||||
protected PrincipalImpl createAssociatedPrincipal()
|
||||
throws UnknownHostException {
|
||||
return new NetMaskImpl(address.toString(), Integer.parseInt(mask));
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMSecurityDefs.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMSecurityDefs extends SimpleNode {
|
||||
JDMSecurityDefs(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMSecurityDefs(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMSecurityDefs(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMSecurityDefs(p, id);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMTrapBlock.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
class JDMTrapBlock extends SimpleNode {
|
||||
JDMTrapBlock(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMTrapBlock(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMTrapBlock(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMTrapBlock(p, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do no need to go through this part of the tree for
|
||||
* building AclEntry.
|
||||
*/
|
||||
@Override
|
||||
public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {}
|
||||
|
||||
/**
|
||||
* Do no need to go through this part of the tree for
|
||||
* building InformEntry.
|
||||
*/
|
||||
@Override
|
||||
public void buildInformEntries(Hashtable<InetAddress, Vector<String>> dest) {}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/* Generated By:JJTree: Do not edit this line. JDMTrapCommunity.java */
|
||||
|
||||
package com.sun.jmx.snmp.IPAcl;
|
||||
|
||||
class JDMTrapCommunity extends SimpleNode {
|
||||
protected String community= "";
|
||||
JDMTrapCommunity(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
JDMTrapCommunity(Parser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new JDMTrapCommunity(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(Parser p, int id) {
|
||||
return new JDMTrapCommunity(p, id);
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user