提交 4086c86f 编写于 作者: H herrick

7016724: Remove sun.jkernel.* classes in JDK 7

Summary: Remove sun.jkernel.* classes in JDK 7
Reviewed-by: ohair, alanb, mchung
上级 84fa8907
......@@ -771,12 +771,7 @@ module client {
/**************************************************************************/
module jkernel {
include sun.jkernel.*;
}
module deploy {
include jkernel;
// For now, all plugin and JNLP
include com.sun.java.browser.**,
......
......@@ -74,8 +74,7 @@ SUBDIRS_desktop = audio $(RENDER_SUBDIR) image \
$(HEADLESS_SUBDIR) $(DGA_SUBDIR) \
jawt font jpeg cmm applet beans
SUBDIRS_management = management
SUBDIRS_misc = jkernel $(ORG_SUBDIR) \
rmi $(JDBC_SUBDIR) tracing
SUBDIRS_misc = $(ORG_SUBDIR) rmi $(JDBC_SUBDIR) tracing
SUBDIRS_tools = native2ascii serialver tools jconsole
include $(BUILDDIR)/common/Subdirs.gmk
......
#
# Copyright (c) 2008, 2009, 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.
#
FILES_cpp = \
stdafx.cpp \
kernel.cpp \
DownloadDialog.cpp \
DownloadHelper.cpp \
DownloadHelper.cpp
FILES_rc = kernel.rc
# FILES_export definitions for Win32
FILES_export = \
sun/jkernel/DownloadManager.java \
sun/jkernel/Mutex.java \
sun/jkernel/Bundle.java \
sun/jkernel/BackgroundDownloader.java \
#
# Copyright (c) 2008, 2009, 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.
#
FILES_java = \
$(TARGDIR)sun/jkernel/BackgroundDownloader.java \
$(TARGDIR)sun/jkernel/Bundle.java \
$(TARGDIR)sun/jkernel/ByteArrayToFromHexDigits.java \
$(TARGDIR)sun/jkernel/BundleCheck.java \
$(TARGDIR)sun/jkernel/DownloadManager.java \
$(TARGDIR)sun/jkernel/Mutex.java \
$(TARGDIR)sun/jkernel/StandaloneByteArrayAccess.java \
$(TARGDIR)sun/jkernel/StandaloneMessageDigest.java \
$(TARGDIR)sun/jkernel/StandaloneSHA.java \
FILES_export = \
sun/jkernel/DownloadManager.java \
sun/jkernel/Mutex.java \
sun/jkernel/Bundle.java \
sun/jkernel/BackgroundDownloader.java
#
# Copyright (c) 2008, 2010, 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.
#
BUILDDIR = ../..
MODULE = jkernel
PACKAGE = sun.jkernel
LIBRARY = jkernel
PRODUCT = sun
include $(BUILDDIR)/common/Defs.gmk
#
# Use highest optimization level
#
_OPT = $(CC_HIGHEST_OPT)
#
# Java source files
#
include FILES_java.gmk
AUTO_FILES_JAVA_DIRS = sun/jkernel
LOCALE_SUFFIXES = $(JDK_LOCALES)
#
# Native source files
#
ifeq ($(ARCH_DATA_MODEL), 32)
ifeq ($(PLATFORM), windows)
# If this is the VS Express compiler it will lack vc/atlmfc/
ATL_MFC_DIR :=$(call DirExists,$(COMPILER_PATH)/../atlmfc,,)
ifneq ($(ATL_MFC_DIR),)
include FILES_c_windows.gmk
vpath %.cpp $(PLATFORM_SRC)/native/sun/jkernel
VERSIONINFO_RESOURCE = $(PLATFORM_SRC)/native/sun/jkernel/kernel.rc
LDLIBS += urlmon.lib wininet.lib shlwapi.lib version.lib comctl32.lib gdi32.lib -def:$(PLATFORM_SRC)/native/sun/jkernel/kernel.def
include $(BUILDDIR)/common/Library.gmk
endif
endif
endif
#
# Resources
#
include $(TOPDIR)/make/common/internal/Resources.gmk
#
# Rules
#
include $(BUILDDIR)/common/Classes.gmk
# If extra compression is going to be available in the deploy build enable
# its use here by defining the JRE-relative pathname of the shared library
ifeq ($(PLATFORM), windows)
ifdef EXTRA_COMP_INSTALL_PATH
CPPFLAGS += -DEXTRA_COMP_INSTALL_PATH=$(EXTRA_COMP_INSTALL_PATH)
endif
endif
......@@ -1856,13 +1856,6 @@ public class ICC_Profile implements Serializable {
File.separatorChar + "lib" + File.separatorChar + "cmm";
String fullPath = dir + File.separatorChar + fileName;
File f = new File(fullPath);
if (!f.isFile()) {
//make sure file was installed in the kernel mode
BootClassLoaderHook hook = BootClassLoaderHook.getHook();
if (hook != null) {
hook.prefetchFile("lib/cmm/"+fileName);
}
}
return (f.isFile() && isChildOf(f, dir)) ? f : null;
}
......
......@@ -110,19 +110,7 @@ class ZipEntry implements ZipConstants, Cloneable {
* @see #getTime()
*/
public void setTime(long time) {
// Same value as defined in sun.jkernel.DownloadManager.KERNEL_STATIC_MODTIME
// to avoid direct reference to DownoadManager class. Need to revisit
// if this is needed any more (see comment in the DownloadManager class)
final int KERNEL_STATIC_MODTIME = 10000000;
BootClassLoaderHook hook = BootClassLoaderHook.getHook();
if (hook != null && hook.isCurrentThreadPrefetching()) {
// fix for bug 6625963: we bypass time calculations while Kernel is
// downloading bundles, since they aren't necessary and would cause
// the Kernel core to depend upon the (very large) time zone data
this.time = KERNEL_STATIC_MODTIME;
} else {
this.time = javaToDosTime(time);
}
this.time = javaToDosTime(time);
}
/**
......
/*
* Copyright (c) 2008, 2009, 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 sun.jkernel;
import java.io.*;
/**
* Invoked by DownloadManager to begin (in a new JRE) the process of downloading
* all remaining JRE components in the background. A mutex is used to ensure
* that only one BackgroundDownloader can be active at a time.
*
*/
public class BackgroundDownloader {
public static final String BACKGROUND_DOWNLOAD_PROPERTY = "kernel.background.download";
// relative to the bundle directory
public static final String PID_PATH = "tmp" + File.separator + "background.pid";
// Time to wait before beginning to download components. Gives the JRE
// which spawned this one a chance to get its downloads going.
private static final int WAIT_TIME = 10000;
private static Mutex backgroundMutex;
static synchronized Mutex getBackgroundMutex() {
if (backgroundMutex == null)
backgroundMutex = Mutex.create(DownloadManager.MUTEX_PREFIX + "background");
return backgroundMutex;
}
private static void doBackgroundDownloads() {
if (DownloadManager.isJREComplete())
return;
if (getBackgroundMutex().acquire(0)) { // give up and exit immediately if we can't acquire mutex
try {
writePid();
Thread.sleep(WAIT_TIME);
DownloadManager.doBackgroundDownloads(false);
DownloadManager.performCompletionIfNeeded();
}
catch (InterruptedException e) {
}
finally {
getBackgroundMutex().release();
}
}
else {
System.err.println("Unable to acquire background download mutex.");
System.exit(1);
}
}
/**
* Writes the current process ID to a file, so that the uninstaller can
* find and kill this process if needed.
*/
private static void writePid() {
try {
File pid = new File(DownloadManager.getBundlePath(), PID_PATH);
pid.getParentFile().mkdirs();
PrintStream out = new PrintStream(new FileOutputStream(pid));
pid.deleteOnExit();
out.println(DownloadManager.getCurrentProcessId());
out.close();
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* Reads from an InputStream until exhausted, writing all data to the
* specified OutputStream.
*/
private static void send(InputStream in, OutputStream out)
throws IOException {
int c;
byte[] buffer = new byte[2048];
while ((c = in.read(buffer)) > 0)
out.write(buffer, 0, c);
}
/*
* Returns the value of the BACKGROUND_DOWNLOAD_PROPERTY.
* Checks if system property has been set first
* then checks if registry key to disable background download
* has been set.
*/
public static boolean getBackgroundDownloadProperty(){
/*
* Check registry key value
*/
boolean bgDownloadEnabled = getBackgroundDownloadKey();
/*
* Check system property - it should override the registry
* key value.
*/
if (System.getProperty(BACKGROUND_DOWNLOAD_PROPERTY) != null){
bgDownloadEnabled = Boolean.valueOf(
System.getProperty(BACKGROUND_DOWNLOAD_PROPERTY));
}
return bgDownloadEnabled;
}
// This method is to retrieve the value of registry key
// that disables background download.
static native boolean getBackgroundDownloadKey();
static void startBackgroundDownloads() {
if (!getBackgroundDownloadProperty()){
// If getBackgroundDownloadProperty() returns false
// we're doing the downloads from this VM; we don't want to
// spawn another one
return;
}
// if System.err isn't initialized yet, it means the charsets aren't
// available yet and we're going to run into trouble down below. Wait
// until it's ready.
while (System.err == null) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
return;
}
}
try {
String args = "-D" + BACKGROUND_DOWNLOAD_PROPERTY + "=false -Xmx256m";
String backgroundDownloadURL = DownloadManager.getBaseDownloadURL();
// only set KERNEL_DOWNLOAD_URL_PROPERTY if we override
// the default download url
if (backgroundDownloadURL != null &&
backgroundDownloadURL.equals(
DownloadManager.DEFAULT_DOWNLOAD_URL) == false) {
args += " -D" + DownloadManager.KERNEL_DOWNLOAD_URL_PROPERTY +
"=" + backgroundDownloadURL;
};
args += " sun.jkernel.BackgroundDownloader";
final Process jvm = Runtime.getRuntime().exec("\"" + new File(System.getProperty("java.home"), "bin" +
File.separator + "java.exe") + "\" " + args);
Thread outputReader = new Thread("kernelOutputReader") {
public void run() {
try {
InputStream in = jvm.getInputStream();
send(in, new PrintStream(new ByteArrayOutputStream()));
}
catch (IOException e) {
e.printStackTrace();
}
}
};
outputReader.setDaemon(true);
outputReader.start();
Thread errorReader = new Thread("kernelErrorReader") {
public void run() {
try {
InputStream in = jvm.getErrorStream();
send(in, new PrintStream(new ByteArrayOutputStream()));
}
catch (IOException e) {
e.printStackTrace();
}
}
};
errorReader.setDaemon(true);
errorReader.start();
}
catch (Exception e) {
e.printStackTrace();
// TODO: error handling
}
}
public static void main(String[] arg) {
doBackgroundDownloads();
}
}
此差异已折叠。
/*
* Copyright (c) 2008, 2009, 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.
*/
/*
*
* The Java Kernel Bundle security check.
*
* This class is responsible for detail of creating, storing, dispensing, and
* updating bundle security checks and security checks for all the files
* extracted from a bundle. Security checks are cryptographic
* hashcodes that make it impractical to counterfeit a file. The security
* check algorithm is defined by peer class StandaloneMessageDigest. The
* cryptographic
* hashcodes are held in instances of this class as byte arrays and externally
* as hexidecimal string values for Bundle name Property keys. The properties
* are a resource in the Java Kernel core JRE rt.jar and accessed after a
* real or simulated bundle download by peer classes DownloadManager and
* Bundle. Build-time deployment class SplitJRE uses this class to create file
* security checks directly and via a special execution of DownloadManager.
* The main method of this class can be used to create a
* new set of security codes and updated properties for a given JRE path
* and set of bundle names (CWD assume to contain bundle files as <name>.zip).
*
* This is a Sun internal class defined by the Sun implementation and
* intended for JRE/JDK release deployment.
*
* @see sun.jkernel.DownloadManager
* @see sun.jkernel.Bundle
* @see sun.jkernel.StandaloneSHA
* @see sun.jkernel.ByteArrayToFromHexDigits
* See also deploy/src/kernel/share/classes/sun/kernel/SplitJRE.java
*/
package sun.jkernel;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class BundleCheck {
/* File buffer size */
private static final int DIGEST_STREAM_BUFFER_SIZE = 2048;
/* The bundle filename suffix */
private static final String BUNDLE_SUFFIX = ".zip";
/* Mutable static state. */
/* Properties (Bundle name/check hex String pairs) for a set of Bundles.
Guarded by this class' object. */
private static volatile Properties properties;
/* Mutable instance state. */
/**
* The bytes of the check value. Guarded by the bundle Mutex (in
* sun.jkernel.DownloadManager) or the fact that sun.kernel.SplitJRE
* and/or DownloadManager with "-download all" runs a single thread.
*/
private byte[] checkBytes;
/* Prevent instantiation by default constructor */
private BundleCheck(){}
/**
* Store the bundle check values as properties to the path specified.
* Only invoked by SplitJRE.
*/
public static void storeProperties(String fullPath) {
try {
File f = new File(fullPath);
f.getParentFile().mkdirs();
OutputStream out = new FileOutputStream(f);
properties.store(out, null);
out.close();
} catch (Exception e) {
throw new RuntimeException(
"BundleCheck: storing properties threw: " + e);
}
}
/**
* Fetch the check value properties as a DownloadManager resource.
*/
private static void loadProperties() {
properties = new Properties();
try {
InputStream in = new BufferedInputStream(
DownloadManager.class.getResourceAsStream(
DownloadManager.CHECK_VALUES_FILE));
if (in == null)
throw new RuntimeException("BundleCheck: unable to locate " +
DownloadManager.CHECK_VALUES_FILE + " as resource");
properties.load(in);
in.close();
} catch (Exception e) {
throw new RuntimeException("BundleCheck: loadProperties threw " +
e);
}
}
/* Get the check value Properties object */
private synchronized static Properties getProperties() {
if (properties == null) {
// If this fails it means addProperty has been used inappropriately
loadProperties();
}
return properties;
}
/* Reset the properties with an empty Properties object */
public static void resetProperties() {
properties = null;
}
/* The BundleCheck expressed as a String */
public String toString() {
return ByteArrayToFromHexDigits.bytesToHexString(checkBytes);
}
/* Add the given BundleCheck as a property to bundleCheckvalueProperties */
private void addProperty(String name) {
// When first called by SplitJRE just start with empty object
// rather than allowing a load to happen, as it does at install time.
if (properties == null) {
properties = new Properties();
}
getProperties().put(name, toString());
}
/* private ctor for creating/initializing a BundleCheck */
private BundleCheck(byte[] checkBytes) {
this.checkBytes = checkBytes;
}
/* private ctor for creating a BundleCheck with a given name and known
Property value. */
private BundleCheck(String name) {
String hexString = getProperties().getProperty(name);
if (hexString == null) {
throw new RuntimeException(
"BundleCheck: no check property for bundle: " + name);
}
this.checkBytes = ByteArrayToFromHexDigits.hexStringToBytes(hexString);
}
/* Make a BundleCheck from the contents of the given file or a Bundle
name. Save the new object's value as a property if saveProperty is
true. Behavior is only defined for name or file being null, but not
both, and for saveProperty to be true only when both name and file
are not null.
Any IO or other exception implies an unexpected and fatal internal
error and results in a RuntimeException. */
private static BundleCheck getInstance(String name,
File file, boolean saveProperty) {
if (file == null ) {
return new BundleCheck(name);
} else {
StandaloneMessageDigest checkDigest = null;
try {
FileInputStream checkFileStream = new FileInputStream(file);
checkDigest = StandaloneMessageDigest.getInstance("SHA-1");
// Compute a check code across all of the file bytes.
// NOTE that every time a bundle is created, even from
// the "same bits", it may be different wrt to the security
// code because of slight variations build to build. For
// example, the JVM build normally contains an
// auto-incrementing build number, built archives might have
// timestamps, etc.
int readCount;
byte[] messageStreamBuff =
new byte[DIGEST_STREAM_BUFFER_SIZE];
do {
readCount = checkFileStream.read(messageStreamBuff);
if (readCount > 0) {
checkDigest.update(messageStreamBuff,0,readCount);
}
} while (readCount != -1);
checkFileStream.close();
} catch (Exception e) {
throw new RuntimeException(
"BundleCheck.addProperty() caught: " + e);
}
BundleCheck bc = new BundleCheck(checkDigest.digest());
if (saveProperty) {
bc.addProperty(name);
}
return bc;
}
}
/* Create a BundleCheck from the given file */
public static BundleCheck getInstance(File file) {
return getInstance(null, file, false);
}
/* Create a BundleCheck from the given bundle name */
static BundleCheck getInstance(String name) {
return getInstance(name, null, false);
}
/* Create a BundleCheck from the given bundle name and file and
use it to make and save a security check Property value. */
public static void addProperty(String name, File file) {
getInstance(name, file, true);
}
/* Create a bundlecheck from the given bundle name and file and
add a Property value for it. */
static void add(String name, File file) {
getInstance(name, file, true).addProperty(name);
}
/* Compare two BundkCheck instances for equal check values */
boolean equals(BundleCheck b) {
if ((checkBytes == null) || (b.checkBytes == null)) {
return false;
}
if (checkBytes.length != b.checkBytes.length) {
return false;
}
for (int i = 0; i < checkBytes.length; i++) {
if (checkBytes[i] != b.checkBytes[i]) {
if (DownloadManager.debug) {
System.out.println(
"BundleCheck.equals mismatch between this: " +
toString() + " and param: " + b.toString());
}
return false;
}
}
return true;
}
/* After SplitJRE is used to restructure the JRE into a "core JRE" and
a set of Java Kernel "bundles", if extra compression is available
the bundles are extracted and rearchived with zero compression by
deploy build make steps. The newly compressed bundle names are then
passed to this main with the path of the kernel core JRE to have new
bundle security check values computed and the corresponding properties
updated in rt.jar. If extra compression isn't available then this main is
never used and the default jar/zip bundle compression and security
codes created by SplitJRE are left in place and ready to use. */
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Usage: java BundleCheck <jre path> " +
"<bundle 1 name> ... <bundle N name>");
return;
}
// Make a security check code for each bundle file
for (int arg = 1; arg < args.length; arg++) {
BundleCheck.addProperty(args[arg],
new File(args[arg] + BUNDLE_SUFFIX));
}
// Store the new check code properties below the current directory
BundleCheck.storeProperties(DownloadManager.CHECK_VALUES_DIR);
// Now swap the new properties file into the core rt.jar
try {
int status = Runtime.getRuntime().exec(
"jar uf " + args[0] + "\\lib\\rt.jar " +
DownloadManager.CHECK_VALUES_DIR).waitFor();
if (status != 0) {
System.err.println(
"BundleCheck: exec of jar uf gave nonzero status");
return;
}
} catch (Exception e) {
System.err.println("BundleCheck: exec of jar uf threw: " + e);
return;
}
} // main
}
/*
* Copyright (c) 2008, 2009, 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 sun.jkernel;
/**
* TODO: The JRE and deploy build code (SplitJRE) can be made a bit smarter
* then cryto hashcode byte arrays can be used directly, eliminating the need
* for this class altogether. So just leave this alone until it can be removed.
* TODO: Change "Digits" to "String" for uniformity and more intuitive names.
* A lightweight class to provide convert between hex digits and
* <code>byte[]</code>.
*<p>
* TODO: Try to get this built without the -source 1.3 -target -1.3 options,
* which prevent use of java.text.Format, assuming this wouldn't bloat the
* JK rt.jar. Also, there still might be equivalent code hiding in the JDK
* already, but preliminary searches havn't found it.
*/
public final class ByteArrayToFromHexDigits {
private static final char [] chars = new char[]
{'0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F'};
private static final boolean debug = false;
/**
* Converts the <code>byte[] b</code> into a <code>String</code> of
* hex digits representing the integer values of all the bytes.
*
* @param b byte array to be converted
* @return String representing <code>b</code> in hexadecimal
* @throws IllegalArgumentException if <code>b</code> is null or zero length
*/
public static String bytesToHexString(byte[] b) {
if (debug ) {
System.out.print("I: ");
for(int i=0;i<b.length;i++) {
System.out.format("%02X",b[i]);
}
System.out.println();
}
if ((b == null) || (b.length == 0)) {
throw new IllegalArgumentException("argument null or zero length");
}
StringBuffer buff = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++ ) {
buff.insert(i*2,chars[(b[i] >> 4) & 0xf]);
buff.insert(i*2+1,chars[b[i] & 0xf]);
}
if (debug ) {
System.out.println("O: " + buff.toString());
}
return buff.toString();
}
// Convert one hex character to a 4 bit byte value
private static byte hexCharToByte(char c) throws IllegalArgumentException {
if ((c < '0') ||
( ((c < 'A') && (c > 'F')) && ((c < 'a') && (c > 'f'))) ) {
throw new IllegalArgumentException("not a hex digit");
}
if (c > '9') {
if (c > 'F') {
return (byte) ((c - 'a' + 10) & 0xf);
} else {
return (byte) ((c - 'A' + 10) & 0xf);
}
} else {
return (byte) ((c - '0') & 0xf);
}
}
/**
* Converts the <code>String d</code> assumed to contain a sequence
* of hexadecimal digit characters into a <code>byte[]</code>.
*
* @param d String to be converted
* @return byte array representing the hex string
* @throws IllegalArgumentException if <code>d</code> is odd length,
* contains a character outside the ranges of 0-9, a-f, and A-F,
* or is zero length or null
*/
public static byte[] hexStringToBytes(String d) throws IllegalArgumentException {
if (d == null) {
throw new IllegalArgumentException(
"parameter cannot be null");
}
if (d.length() == 0) {
throw new IllegalArgumentException(
"parameter cannot be zero length");
}
if ((d.length() & 1) != 0) {
throw new IllegalArgumentException(
"odd length string");
}
byte[] b = new byte[d.length() / 2];
// TODO Might be code in the JK initial bundle to do this better (i.e.
// method that tests for a hex char?)
for (int i=0;i<d.length();i+=2) {
b[i/2] = (byte) (( (byte) (hexCharToByte(d.charAt(i))) << 4) +
(byte) hexCharToByte(d.charAt(i+1)));
}
return b;
}
}
/*
* Copyright (c) 2008, 2009, 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 sun.jkernel;
import java.io.FilterOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import sun.jkernel.StandaloneMessageDigest;
/*
* This class provides the main functionality of <code>FilterOutputStream</code>,
* and accumulates a check value as bytes are written to
* it. The check value is available by method <code>getCheckValue</code>.
*<p>
* Operations on the public <code>out</code> field of this class should be
* avoided to prevent an invalid check code being generated.
*
* TODO: The javadoc HTML hasn't been generated and eyeballed for yet.
* TODO: There is a javadoc trick to cause the parent class javadoc to be
* automagically used: try to take advantage of this.
* TODO: Add javadoc links instead of <code>API</code> where it would be useful.
* TODO: Go visit the Docs style guide again and get the periods right and
* consistent for all sun.* classes.
* @author Pete Soper
* @see java.lang.FilterOutputStream
* @see getCheckValue
*/
public class DigestOutputStream extends FilterOutputStream {
private static final String DEFAULT_ALGORITHM = "SHA-1";
private final boolean debug = false;
private StandaloneMessageDigest smd = null;
private void initDigest(String algorithm) throws NoSuchAlgorithmException {
smd = StandaloneMessageDigest.getInstance(algorithm);
}
// The underlying stream.
protected volatile OutputStream out;
/**
* Creates a <code>DigestOutputStream</code> with stream <code>s</code>
* to be checked with using <code>algorithm</code>.
* <p>
* If <code>algorithm</code> is not supported then
* <code>NoSuchAlgorithm</code> is thrown.
* <p>
* See {linkplain sun.security.provider.StandaloneMessageDigest} for an
* implementation-specific list of supported algorithms.
*
* @throws NoSuchAlgorithm if <code>algorithm</code> is not supported
* @see sun.security.provider.StandaloneMessageDigest
*/
/**
* Creates an output stream filter built on top of
* underlying output stream <code>out</code> for checking with
* algorithm <code>algorithm</code>.
* <p>
* If <code>algorithm</code> is not supported then
* <code>NoSuchAlgorithm</code> is thrown.
* <p>
* See {linkplain sun.security.provider.StandaloneMessageDigest} for an
* implementation-specific list of supported algorithms.
*
* @param out the underlying output stream to be assigned to
* the field <tt>this.out</tt> for later use, or
* <code>null</code> if this instance is to be
* created without an underlying stream.
* @param algorithm the check algorithm to use.
* @throws NoSuchAlgorithm if <code>algorithm</code> is not supported
* @see sun.security.provider.StandaloneMessageDigest
* @see DigestInputStream(InputStream, String)
*/
public DigestOutputStream(OutputStream out, String algorithm) throws NoSuchAlgorithmException {
super(out);
initDigest(algorithm);
this.out = out;
}
/**
* Creates an output stream filter built on top of
* underlying output stream <code>out</code> for the default checking
* algorithm.
* <p>
* This implemention provides "SHA-1" as the default checking algorithm.
*
* @param out the underlying output stream to be assigned to
* the field <tt>this.out</tt> for later use, or
* <code>null</code> if this instance is to be
* created without an underlying stream.
* @see DigestInputStream(InputStream)
*/
public DigestOutputStream(OutputStream out) {
super(out);
try {
initDigest(DEFAULT_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
// Impossible to get here, but stranger things have happened...
throw new RuntimeException("DigestOutputStream() unknown algorithm");
}
// superstition from a test failure this.out = out;
}
/**
* Writes a byte specified by <code>v</code> to this stream
* and updates the check information.
*
*
* @param v the byte to be written.
* @throws IOException if an I/O error occurs.
*/
public void write(int v) throws IOException {
super.write(v);
// TODO Could create this array once
byte[] b = new byte[] {(byte) (v & 0xff)};
smd.update(b,0,1);
}
/**
* Writes the bytes in array <code>data</code>
* to this stream and updates the check information.
*
* @param data the data.
* @throws IOException if an I/O error occurs.
* @throws NullPointerException if <code>data</code> is <code>null</code>
*/
public void write(byte[] data) throws IOException {
write(data,0,data.length);
}
/**
* Writes a sub array as a sequence of bytes to this output stream and
* updates the check information.
* @param data the data to be written
* @param ofs the start offset in the data
* @param len the number of bytes that are written
* @throws IOException If an I/O error has occurred.
* @throws NullPointerException if <code>data</code> is <code>null</code>
* @throws IndexOutOfBoundsException If <code>ofs</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - ofs</code>
*/
public void write(byte[] data, int ofs, int len) throws IOException {
if (debug) {
System.out.print("DigestOutputStream.write: ");
for (int i=ofs; i<(len - ofs); i++) {
System.out.format("%02X",data[i]);
}
System.out.println();
}
if (data == null) {
throw new NullPointerException("null array in DigestOutputStream.write");
} else if (ofs < 0 || len < 0 || len > data.length - ofs) {
throw new IndexOutOfBoundsException();
}
//super.write(data,ofs,len);
// WATCH OUT: FilterOutputStream does a byte at a time write(byte)
// TODO: Will this work all the time, or is there another caveat
// to publish
out.write(data,ofs,len);
if (debug) {
System.out.println("DigestOutputStream.write before");
}
smd.update(data,ofs,len);
if (debug) {
System.out.println("DigestOutputStream.write after");
}
}
/**
* Closes this file output stream and releases any system resources
* associated with this stream and makes the check value for the stream
* available via <code>getCheckValue</code>. This file output stream may
* no longer be used for writing bytes.
*
* @throws IOException if an I/O error occurs.
* @see getCheckValue
*/
public void close() throws IOException {
super.close();
}
/**
* Return the check value computed for the stream and reset the state of
* check value generation.
*
* @return the check value bytes
*/
public byte[] getCheckValue() {
byte[] b = smd.digest();
if (debug) {
System.out.print("DigestOutputStream.getCheckValue: ");
for (int i=0; i<b.length; i++) {
System.out.format("%02X",b[i]);
}
System.out.println();
}
smd.reset();
return b;
}
/**
* Flushes this output stream.
*
* @throws IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#flush()
*/
public void flush() throws IOException {
super.flush();
}
/**
* Compares two digests for equality. Does a simple byte compare.
*
* @param digesta one of the digests to compare.
*
* @param digestb the other digest to compare.
*
* @return true if the digests are equal, false otherwise.
*/
// public static boolean isEqual(byte digesta[], byte digestb[]) {
// return StandaloneMessageDigest.isEqual(digesta, digestb);
// }
}
/*
* Copyright (c) 2008, 2009, 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 sun.jkernel;
/**
* Thrown to indicate that Java Kernel is unable to install a required bundle
* and the JRE is therefore not adhering to specifications.
*/
public class KernelError extends VirtualMachineError {
/**
* Constructs a <code>KernelError</code> with no detail message.
*/
public KernelError() {
super();
}
/**
* Constructs a <code>KernelError</code> with the specified
* detail message.
*
* @param s the detail message.
*/
public KernelError(String s) {
super(s);
}
}
/*
* Copyright (c) 2008, 2009, 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 sun.jkernel;
/**
* A mutex which works even between different processes. Currently implemented
* only on Win32.
*
*@author Ethan Nicholas
*/
public class Mutex {
static {
try {
System.loadLibrary("jkernel");
}
catch (Exception e) {
throw new Error(e);
}
}
private String uniqueId;
private long handle;
public static Mutex create(String uniqueId) {
return new Mutex(uniqueId);
}
private Mutex(String uniqueId) {
this.uniqueId = uniqueId;
this.handle = createNativeMutex(uniqueId);
}
private static native long createNativeMutex(String uniqueId);
public native void acquire();
public native boolean acquire(int timeout);
public native void release();
public native void destroyNativeMutex();
public void dispose() {
destroyNativeMutex();
handle = 0;
}
public void finalize() {
dispose();
}
public String toString() {
return "Mutex[" + uniqueId + "]";
}
}
/*
* Copyright (c) 2008, 2009, 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.
*/
/*
* This is a pure subset of package-private class
* sun.security.provider.ByteArrayAccess. The subset consists of only the simple
* shift and boolean operations needed for the one current client of this
* class (sun.jkernel.StandaloneSHA) and omits optimization code and comments
* not relevant to the subset. No semantic changes have been made.
* A few long lines were broken to conform to JDK coding style.
* Pete Soper, August, 2007.
*/
package sun.jkernel;
/**
* Methods for converting between byte[] and int[]/long[].
*
* @since 1.6
* @version 1.1, 05/26/06
* @author Andreas Sterbenz
*/
final class StandaloneByteArrayAccess {
private StandaloneByteArrayAccess() {
// empty
}
/**
* byte[] to int[] conversion, little endian byte order.
*/
static void b2iLittle(byte[] in, int inOfs, int[] out, int outOfs,
int len) {
len += inOfs;
while (inOfs < len) {
out[outOfs++] = ((in[inOfs ] & 0xff) )
| ((in[inOfs + 1] & 0xff) << 8)
| ((in[inOfs + 2] & 0xff) << 16)
| ((in[inOfs + 3] ) << 24);
inOfs += 4;
}
}
/**
* int[] to byte[] conversion, little endian byte order.
*/
static void i2bLittle(int[] in, int inOfs, byte[] out, int outOfs,
int len) {
len += outOfs;
while (outOfs < len) {
int i = in[inOfs++];
out[outOfs++] = (byte)(i );
out[outOfs++] = (byte)(i >> 8);
out[outOfs++] = (byte)(i >> 16);
out[outOfs++] = (byte)(i >> 24);
}
}
/**
* byte[] to int[] conversion, big endian byte order.
*/
static void b2iBig(byte[] in, int inOfs, int[] out, int outOfs, int len) {
len += inOfs;
while (inOfs < len) {
out[outOfs++] = ((in[inOfs + 3] & 0xff) )
| ((in[inOfs + 2] & 0xff) << 8)
| ((in[inOfs + 1] & 0xff) << 16)
| ((in[inOfs ] ) << 24);
inOfs += 4;
}
}
/**
* int[] to byte[] conversion, big endian byte order.
*/
static void i2bBig(int[] in, int inOfs, byte[] out, int outOfs, int len) {
len += outOfs;
while (outOfs < len) {
int i = in[inOfs++];
out[outOfs++] = (byte)(i >> 24);
out[outOfs++] = (byte)(i >> 16);
out[outOfs++] = (byte)(i >> 8);
out[outOfs++] = (byte)(i );
}
}
// Store one 32-bit value into out[outOfs..outOfs+3] in big endian order.
static void i2bBig4(int val, byte[] out, int outOfs) {
out[outOfs ] = (byte)(val >> 24);
out[outOfs + 1] = (byte)(val >> 16);
out[outOfs + 2] = (byte)(val >> 8);
out[outOfs + 3] = (byte)(val );
}
/**
* byte[] to long[] conversion, big endian byte order.
*/
static void b2lBig(byte[] in, int inOfs, long[] out, int outOfs, int len) {
len += inOfs;
while (inOfs < len) {
int i1 = ((in[inOfs + 3] & 0xff) )
| ((in[inOfs + 2] & 0xff) << 8)
| ((in[inOfs + 1] & 0xff) << 16)
| ((in[inOfs ] ) << 24);
inOfs += 4;
int i2 = ((in[inOfs + 3] & 0xff) )
| ((in[inOfs + 2] & 0xff) << 8)
| ((in[inOfs + 1] & 0xff) << 16)
| ((in[inOfs ] ) << 24);
out[outOfs++] = ((long)i1 << 32) | (i2 & 0xffffffffL);
inOfs += 4;
}
}
/**
* long[] to byte[] conversion
*/
static void l2bBig(long[] in, int inOfs, byte[] out, int outOfs, int len) {
len += outOfs;
while (outOfs < len) {
long i = in[inOfs++];
out[outOfs++] = (byte)(i >> 56);
out[outOfs++] = (byte)(i >> 48);
out[outOfs++] = (byte)(i >> 40);
out[outOfs++] = (byte)(i >> 32);
out[outOfs++] = (byte)(i >> 24);
out[outOfs++] = (byte)(i >> 16);
out[outOfs++] = (byte)(i >> 8);
out[outOfs++] = (byte)(i );
}
}
}
/*
* Copyright (c) 2008, 2009, 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.
*/
/*
* This is a combination and adaptation of subsets of
* <code>java.security.MessageDigest</code> and
* <code>sun.security.provider.DigestBase</code> to provide a class offering
* most of the same public methods of <code>MessageDigest</code> while not
* depending on the Java Security Framework.
* <p>
* One algorithm is currently supported: "SHA-1".
* <p>
* NOTE If <code>java.security.MessageDigest</code>,
* <code>sun.security.provider.DigestBase</code> or
* <code>sun.security.provider.SHA</code> are modified, review of those
* modifications should be done to determine any possible implications for this
* class and <code>StandaloneSHA</code>.
*/
package sun.jkernel;
import java.security.DigestException;
import java.security.ProviderException;
import java.security.NoSuchAlgorithmException;
/**
* (Adapted from the <code>sun.security.provider.DigestBase</code> doc).
* This is a simple subset of the Common base message digest implementation
* for the Sun provider.
* It implements most of the JCA methods as suitable for a Java message
* digest
* implementation of an algorithm based on a compression function (as all
* commonly used algorithms are). The individual digest subclasses only need to
* implement the following methods:
*
* . abstract void implCompress(byte[] b, int ofs);
* . abstract void implDigest(byte[] out, int ofs);
* . abstract void implReset();
* <p>
* No support for a clone() method is provided.
* <p>
* See the inline documentation for details.
*
* @since 1.5
* @version 1.3, 08/08/07
* @author Andreas Sterbenz (MessageDigest)
* @author Pete Soper (this derived class)
*/
public abstract class StandaloneMessageDigest {
public static final boolean debug = false;
/*
* (Copied/adapted from <code>java.security.MessageDigest</code>
*
* This is a subset/simplification <code>java.security.MessageDigest</code>
* that supports a fixed set of hashcode mechanisms (currently just
* SHA-1) while preserving the following MessageDigest methods:
*
* public MessageDigest getInstance(String algorithm)
* public final int getDigestLength()
* public void reset()
* public byte[] digest()
* public void update(byte[] input, int offset, int len)
* public final String getAlgorithm()
* <p>
* NOTE that the clone() method is not provided.
*/
/**
* Prevent direct instantiation except via the factory method.
*/
private StandaloneMessageDigest() {
// Keep javac happy.
digestLength = 0;
blockSize = 0;
algorithm = null;
buffer = null;
}
private String algorithm;
// The state of this digest
private static final int INITIAL = 0;
private static final int IN_PROGRESS = 1;
private int state = INITIAL;
/**
* Returns a StandaloneMessageDigest object that implements the specified
* digest algorithm.
*
* <p> This method returns a new StandaloneMessageDigest for a single
* algorithm provider.
*
* @param algorithm the name of the algorithm requested.
*
* @return a standalone Message Digest object that implements the specified algorithm.
*
* @exception NoSuchAlgorithmException if algorithm not supported
*
*/
public static StandaloneMessageDigest getInstance(String algorithm)
throws NoSuchAlgorithmException {
if (! algorithm.equals("SHA-1")) {
throw new NoSuchAlgorithmException(algorithm + " not found");
} else {
return new StandaloneSHA();
}
}
/**
* Updates the digest using the specified array of bytes, starting
* at the specified offset.
*
* @param input the array of bytes.
*
* @param offset the offset to start from in the array of bytes.
*
* @param len the number of bytes to use, starting at
* <code>offset</code>.
*/
public void update(byte[] input, int offset, int len) {
if (debug) {
System.out.println("StandaloneMessageDigest.update");
(new Exception()).printStackTrace();
}
if (input == null) {
throw new IllegalArgumentException("No input buffer given");
}
if (input.length - offset < len) {
throw new IllegalArgumentException("Input buffer too short");
}
// No need to check for negative offset: engineUpdate does this
engineUpdate(input, offset, len);
state = IN_PROGRESS;
}
/**
* Completes the hash computation by performing final operations
* such as padding. The digest is reset after this call is made.
*
* @return the array of bytes for the resulting hash value.
*/
public byte[] digest() {
if (debug) {
System.out.println("StandaloneMessageDigest.digest");
}
/* Resetting is the responsibility of implementors. */
byte[] result = engineDigest();
state = INITIAL;
return result;
}
/**
* Compares two digests for equality. Does a simple byte compare.
*
* @param digesta one of the digests to compare.
*
* @param digestb the other digest to compare.
*
* @return true if the digests are equal, false otherwise.
*/
public static boolean isEqual(byte digesta[], byte digestb[]) {
if (digesta.length != digestb.length)
return false;
for (int i = 0; i < digesta.length; i++) {
if (digesta[i] != digestb[i]) {
return false;
}
}
return true;
}
/**
* Resets the digest for further use.
*/
public void reset() {
if (debug) {
System.out.println("StandaloneMessageDigest.reset");
}
engineReset();
state = INITIAL;
}
/**
* Returns a string that identifies the algorithm, independent of
* implementation details. The name should be a standard
* Java Security name (such as "SHA", "MD5", and so on).
* See Appendix A in the <a href=
* "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
* Java Cryptography Architecture API Specification &amp; Reference </a>
* for information about standard algorithm names.
*
* @return the name of the algorithm
*/
public final String getAlgorithm() {
return this.algorithm;
}
/**
* Returns the length of the digest in bytes.
*
* @return the digest length in bytes.
*
* @since 1.2
*/
public final int getDigestLength() {
return engineGetDigestLength();
}
//* End of copied/adapted <code>java.security.MessageDigest</code>
// Start of copied/adapted <code>sun.security.provider.DigestBase</code>
// one element byte array, temporary storage for update(byte)
private byte[] oneByte;
// length of the message digest in bytes
private final int digestLength;
// size of the input to the compression function in bytes
private final int blockSize;
// buffer to store partial blocks, blockSize bytes large
// Subclasses should not access this array directly except possibly in their
// implDigest() method. See MD5.java as an example.
final byte[] buffer;
// offset into buffer
private int bufOfs;
// number of bytes processed so far. subclasses should not modify
// this value.
// also used as a flag to indicate reset status
// -1: need to call engineReset() before next call to update()
// 0: is already reset
long bytesProcessed;
/**
* Main constructor.
*/
StandaloneMessageDigest(String algorithm, int digestLength, int blockSize) {
// super();
this.algorithm = algorithm;
this.digestLength = digestLength;
this.blockSize = blockSize;
buffer = new byte[blockSize];
}
// return digest length. See JCA doc.
protected final int engineGetDigestLength() {
return digestLength;
}
// single byte update. See JCA doc.
protected final void engineUpdate(byte b) {
if (oneByte == null) {
oneByte = new byte[1];
}
oneByte[0] = b;
engineUpdate(oneByte, 0, 1);
}
// array update. See JCA doc.
protected final void engineUpdate(byte[] b, int ofs, int len) {
if (len == 0) {
return;
}
if ((ofs < 0) || (len < 0) || (ofs > b.length - len)) {
throw new ArrayIndexOutOfBoundsException();
}
if (bytesProcessed < 0) {
engineReset();
}
bytesProcessed += len;
// if buffer is not empty, we need to fill it before proceeding
if (bufOfs != 0) {
int n = Math.min(len, blockSize - bufOfs);
System.arraycopy(b, ofs, buffer, bufOfs, n);
bufOfs += n;
ofs += n;
len -= n;
if (bufOfs >= blockSize) {
// compress completed block now
implCompress(buffer, 0);
bufOfs = 0;
}
}
// compress complete blocks
while (len >= blockSize) {
implCompress(b, ofs);
len -= blockSize;
ofs += blockSize;
}
// copy remainder to buffer
if (len > 0) {
System.arraycopy(b, ofs, buffer, 0, len);
bufOfs = len;
}
}
// reset this object. See JCA doc.
protected final void engineReset() {
if (bytesProcessed == 0) {
// already reset, ignore
return;
}
implReset();
bufOfs = 0;
bytesProcessed = 0;
}
// return the digest. See JCA doc.
protected final byte[] engineDigest() throws ProviderException {
byte[] b = new byte[digestLength];
try {
engineDigest(b, 0, b.length);
} catch (DigestException e) {
throw (ProviderException)
new ProviderException("Internal error").initCause(e);
}
return b;
}
// return the digest in the specified array. See JCA doc.
protected final int engineDigest(byte[] out, int ofs, int len)
throws DigestException {
if (len < digestLength) {
throw new DigestException("Length must be at least "
+ digestLength + " for " + algorithm + "digests");
}
if ((ofs < 0) || (len < 0) || (ofs > out.length - len)) {
throw new DigestException("Buffer too short to store digest");
}
if (bytesProcessed < 0) {
engineReset();
}
implDigest(out, ofs);
bytesProcessed = -1;
return digestLength;
}
/**
* Core compression function. Processes blockSize bytes at a time
* and updates the state of this object.
*/
abstract void implCompress(byte[] b, int ofs);
/**
* Return the digest. Subclasses do not need to reset() themselves,
* StandaloneMessageDigest calls implReset() when necessary.
*/
abstract void implDigest(byte[] out, int ofs);
/**
* Reset subclass specific state to their initial values. StandaloneMessageDigest
* calls this method when necessary.
*/
abstract void implReset();
// padding used for the MD5, and SHA-* message digests
static final byte[] padding;
static {
// we need 128 byte padding for SHA-384/512
// and an additional 8 bytes for the high 8 bytes of the 16
// byte bit counter in SHA-384/512
padding = new byte[136];
padding[0] = (byte)0x80;
}
}
/*
* Copyright (c) 2008, 2009, 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 sun.jkernel;
import static sun.jkernel.StandaloneByteArrayAccess.*;
/**
* This is a slightly modified subset of the
* <code>sun.security.provider.SHA</code> class that
* is not dependent on the regular Java Security framework classes. It
* implements the Secure Hash Algorithm (SHA-1) developed by
* the National Institute of Standards and Technology along with the
* National Security Agency. This is the updated version of SHA
* fip-180 as superseded by fip-180-1.
* <p>
* The <code>sun.security.provider.SHA.clonde()</code> method is not
* implemented and other, formerly public methods, are package private.
*
*/
final class StandaloneSHA extends StandaloneMessageDigest {
static final boolean debug = false;
// Buffer of int's and count of characters accumulated
// 64 bytes are included in each hash block so the low order
// bits of count are used to know how to pack the bytes into ints
// and to know when to compute the block and start the next one.
private final int[] W;
// state of this
private final int[] state;
/**
* Creates a new StandaloneSHA object.
*/
StandaloneSHA() {
super("SHA-1", 20, 64);
state = new int[5];
W = new int[80];
implReset();
}
/**
* Resets the buffers and hash value to start a new hash.
*/
void implReset() {
if (debug) {
System.out.print("StandaloneSHA.implR: " );
}
state[0] = 0x67452301;
state[1] = 0xefcdab89;
state[2] = 0x98badcfe;
state[3] = 0x10325476;
state[4] = 0xc3d2e1f0;
}
/**
* Computes the final hash and copies the 20 bytes to the output array.
*/
void implDigest(byte[] out, int ofs) {
if (debug) {
System.out.print("StandaloneSHA.implD: " );
}
long bitsProcessed = bytesProcessed << 3;
int index = (int)bytesProcessed & 0x3f;
int padLen = (index < 56) ? (56 - index) : (120 - index);
engineUpdate(padding, 0, padLen);
// System.out.println("Inserting: " + bitsProcessed);
StandaloneByteArrayAccess.i2bBig4((int)(bitsProcessed >>> 32), buffer, 56);
StandaloneByteArrayAccess.i2bBig4((int)bitsProcessed, buffer, 60);
implCompress(buffer, 0);
StandaloneByteArrayAccess.i2bBig(state, 0, out, ofs, 20);
}
// Constants for each round
private final static int round1_kt = 0x5a827999;
private final static int round2_kt = 0x6ed9eba1;
private final static int round3_kt = 0x8f1bbcdc;
private final static int round4_kt = 0xca62c1d6;
/**
* Compute a the hash for the current block.
*
* This is in the same vein as Peter Gutmann's algorithm listed in
* the back of Applied Cryptography, Compact implementation of
* "old" NIST Secure Hash Algorithm.
*/
void implCompress(byte[] buf, int ofs) {
if (debug) {
System.out.print("StandaloneSHA.implC: " );
for (int i=ofs; i<buf.length; i++) {
System.out.format("%02X",buf[i]);
}
System.out.println();
}
StandaloneByteArrayAccess.b2iBig(buf, ofs, W, 0, 64);
// The first 16 ints have the byte stream, compute the rest of
// the buffer
for (int t = 16; t <= 79; t++) {
int temp = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
W[t] = (temp << 1) | (temp >>> 31);
}
int a = state[0];
int b = state[1];
int c = state[2];
int d = state[3];
int e = state[4];
// Round 1
for (int i = 0; i < 20; i++) {
int temp = ((a<<5) | (a>>>(32-5))) +
((b&c)|((~b)&d))+ e + W[i] + round1_kt;
e = d;
d = c;
c = ((b<<30) | (b>>>(32-30)));
b = a;
a = temp;
}
// Round 2
for (int i = 20; i < 40; i++) {
int temp = ((a<<5) | (a>>>(32-5))) +
(b ^ c ^ d) + e + W[i] + round2_kt;
e = d;
d = c;
c = ((b<<30) | (b>>>(32-30)));
b = a;
a = temp;
}
// Round 3
for (int i = 40; i < 60; i++) {
int temp = ((a<<5) | (a>>>(32-5))) +
((b&c)|(b&d)|(c&d)) + e + W[i] + round3_kt;
e = d;
d = c;
c = ((b<<30) | (b>>>(32-30)));
b = a;
a = temp;
}
// Round 4
for (int i = 60; i < 80; i++) {
int temp = ((a<<5) | (a>>>(32-5))) +
(b ^ c ^ d) + e + W[i] + round4_kt;
e = d;
d = c;
c = ((b<<30) | (b>>>(32-30)));
b = a;
a = temp;
}
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
}
}
......@@ -179,18 +179,4 @@ public class MonitoredVmUtil {
}
}
/**
* Returns true if the target VM is a kernel VM
*
* @param vm the target MonitoredVm
*/
public static boolean isKernelVM(MonitoredVm vm) throws MonitorException {
StringMonitor jvmCapabilities =
(StringMonitor)vm.findByName("sun.rt.jvmCapabilities");
if (jvmCapabilities == null) {
return false;
} else {
return jvmCapabilities.stringValue().charAt(IS_KERNEL_VM) == '1';
}
}
}
......@@ -34,10 +34,7 @@ import sun.misc.URLClassPath;
* BootClassLoaderHook defines an interface for a hook to inject
* into the bootstrap class loader.
*
* In jkernel build, the sun.jkernel.DownloadManager is set as
* a BootClassLoaderHook by the jkernel VM after the VM is initialized.
*
* In other JDK builds, no hook is set.
* With jkernel now removed, no hook is set
*/
public abstract class BootClassLoaderHook {
private static BootClassLoaderHook bootLoaderHook = null;
......
......@@ -138,7 +138,6 @@ public abstract class HotSpotAttachProvider extends AttachProvider {
*/
void testAttachable(String id) throws AttachNotSupportedException {
MonitoredVm mvm = null;
boolean isKernelVM = false;
try {
VmIdentifier vmid = new VmIdentifier(id);
MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
......@@ -148,7 +147,6 @@ public abstract class HotSpotAttachProvider extends AttachProvider {
// it's attachable; so return false
return;
}
isKernelVM = MonitoredVmUtil.isKernelVM(mvm);
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
ThreadDeath td = (ThreadDeath)t;
......@@ -163,11 +161,8 @@ public abstract class HotSpotAttachProvider extends AttachProvider {
}
// we're sure it's not attachable; throw exception
if (isKernelVM) {
throw new AttachNotSupportedException("Kernel VM does not support the attach mechanism");
} else {
throw new AttachNotSupportedException("The VM does not support the attach mechanism");
}
throw new AttachNotSupportedException(
"The VM does not support the attach mechanism");
}
......
......@@ -49,7 +49,6 @@ static jboolean GetPublicJREHome(char *path, jint pathsize);
static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
char *jvmpath, jint jvmpathsize);
static jboolean GetJREPath(char *path, jint pathsize);
static void EnsureJreInstallation(const char *jrepath);
/* We supports warmup for UI stack that is performed in parallel
* to VM initialization.
......@@ -201,9 +200,6 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
exit(2);
}
/* Do this before we read jvm.cfg and after jrepath is initialized */
EnsureJreInstallation(jrepath);
/* Find the specified JVM type */
if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) {
JLI_ReportErrorMessage(CFG_ERROR7);
......@@ -296,68 +292,6 @@ LoadMSVCRT()
return JNI_TRUE;
}
/*
* The preJVMStart is a function in the jkernel.dll, which
* performs the final step of synthesizing back the decomposed
* modules (partial install) to the full JRE. Any tool which
* uses the JRE must peform this step to ensure the complete synthesis.
* The EnsureJreInstallation function calls preJVMStart based on
* the conditions outlined below, noting that the operation
* will fail silently if any of conditions are not met.
* NOTE: this call must be made before jvm.dll is loaded, or jvm.cfg
* is read, since jvm.cfg will be modified by the preJVMStart.
* 1. Are we on a supported platform.
* 2. Find the location of the JRE or the Kernel JRE.
* 3. check existence of JREHOME/lib/bundles
* 4. check jkernel.dll and invoke the entry-point
*/
typedef VOID (WINAPI *PREJVMSTART)();
static void
EnsureJreInstallation(const char* jrepath)
{
HINSTANCE handle;
char tmpbuf[MAXPATHLEN];
PREJVMSTART PreJVMStart;
struct stat s;
/* Make sure the jrepath contains something */
if ((void*)jrepath[0] == NULL) {
return;
}
/* 32 bit windows only please */
if (JLI_StrCmp(GetArch(), "i386") != 0 ) {
return;
}
/* Does our bundle directory exist ? */
JLI_Snprintf(tmpbuf, sizeof(tmpbuf), "%s\\lib\\bundles", jrepath);
JLI_TraceLauncher("EnsureJreInstallation: %s\n", tmpbuf);
if (stat(tmpbuf, &s) != 0) {
return;
}
/* Does our jkernel dll exist ? */
JLI_Snprintf(tmpbuf, sizeof(tmpbuf), "%s\\bin\\jkernel.dll", jrepath);
if (stat(tmpbuf, &s) != 0) {
return;
}
/* The Microsoft C Runtime Library needs to be loaded first. */
if (!LoadMSVCRT()) {
return;
}
/* Load the jkernel.dll */
if ((handle = LoadLibrary(tmpbuf)) == 0) {
return;
}
/* Get the function address */
PreJVMStart = (PREJVMSTART)GetProcAddress(handle, "preJVMStart");
if (PreJVMStart == NULL) {
FreeLibrary(handle);
return;
}
PreJVMStart();
FreeLibrary(handle);
return;
}
/*
* Find path to JRE based on .exe's location or registry settings.
......
/*
* Copyright (c) 2008, 2009, 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 BUFFER_SIZE
#define BUFFER_SIZE 2048
#endif
#define E_JDHELPER_TIMEOUT 12002
#define E_JDHELPER_NAME_NOT_RESOLVED 12007
#define E_JDHELPER_CANNOT_CONNECT 12029
#include <jni.h>
#include "DownloadDialog.h"
class DownloadHelper {
public:
DownloadHelper();
~DownloadHelper();
HRESULT doDownload();
void setFile(LPCTSTR pszFileName) {
m_pszFileName = pszFileName;
}
void setURL(LPCTSTR pszURL) {
m_pszURL = pszURL;
}
void setNameText(LPTSTR pszNameText) {
m_pszNameText = pszNameText;
}
void setShowProgressDialog(BOOL showProgress) {
m_showProgressDialog = showProgress;
}
void setDownloadDialog(CDownloadDialog* dialog) {
m_dlg = dialog;
}
void setJavaVM(JavaVM *jvm) {
m_jvm = jvm;
}
private:
HRESULT DownloadFile(const TCHAR* szURL, const TCHAR* szLocalFile,
BOOL bResumable, BOOL bUIFeedback);
BOOL m_showProgressDialog;
LPCTSTR m_pszURL;
LPCTSTR m_pszFileName;
LPTSTR m_pszNameText;
time_t m_startTime;
CComAutoCriticalSection m_csDownload;
CDownloadDialog* m_dlg;
JavaVM* m_jvm;
};
此差异已折叠。
;
; Copyright 2008 - 2009 Sun Microsystems, Inc. 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.
;
LIBRARY jkernel
EXPORTS
preJVMStart @1
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册