提交 0379765d 编写于 作者: A asaha

Merge

......@@ -857,6 +857,11 @@ c9254e01820639526f803dbe05080fce0d33db98 jdk8u162-b08
95df717479b19f5ea244afc67434827f2f851287 jdk8u162-b11
ddae5cb11d6c04130b8002b852bc7f80e0c8bcd2 jdk8u162-b12
8e40acfcc41a631f5922824712d4336742652eac jdk8u162-b31
c00bdbbd9a77150f565298af9c305d7e6863eb59 jdk8u162-b32
70a653814e61a5552312345308b85330fa8f27bc jdk8u162-b33
f1f949ac13549c6fb3766279848539b124ad835e jdk8u162-b34
b3de2b1e82fb2427cd40bb230aa26d9b7d8fb09c jdk8u162-b35
e03fff22900242d92a97839a9c095bb106bdc68f jdk8u162-b36
b6195815c4bbbf275f1aefd337d805eb66f2b5b8 jdk8u171-b00
f1792a59f1fa20e47fe5d4561754012440564bec jdk8u171-b01
cac020298633fc736f5e21afddf00145665ef0a7 jdk8u171-b02
......
#
# Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2001, 2018, 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
......@@ -59,6 +59,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_FileChannelImpl_position0;
Java_sun_nio_ch_FileChannelImpl_transferTo0;
Java_sun_nio_ch_FileChannelImpl_unmap0;
Java_sun_nio_ch_FileDispatcherImpl_allocate0;
Java_sun_nio_ch_FileDispatcherImpl_close0;
Java_sun_nio_ch_FileDispatcherImpl_closeIntFD;
Java_sun_nio_ch_FileDispatcherImpl_force0;
......
#
# Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2001, 2018, 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
......@@ -42,6 +42,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_FileChannelImpl_position0;
Java_sun_nio_ch_FileChannelImpl_transferTo0;
Java_sun_nio_ch_FileChannelImpl_unmap0;
Java_sun_nio_ch_FileDispatcherImpl_allocate0;
Java_sun_nio_ch_FileDispatcherImpl_close0;
Java_sun_nio_ch_FileDispatcherImpl_closeIntFD;
Java_sun_nio_ch_FileDispatcherImpl_force0;
......
#
# Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2001, 2018, 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,6 +47,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_FileChannelImpl_position0;
Java_sun_nio_ch_FileChannelImpl_transferTo0;
Java_sun_nio_ch_FileChannelImpl_unmap0;
Java_sun_nio_ch_FileDispatcherImpl_allocate0;
Java_sun_nio_ch_FileDispatcherImpl_close0;
Java_sun_nio_ch_FileDispatcherImpl_closeIntFD;
Java_sun_nio_ch_FileDispatcherImpl_force0;
......
/*
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2018, 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
......@@ -660,15 +660,24 @@ SetJvmEnvironment(int argc, char **argv) {
* arguments are for the application (i.e. the main class name, or
* the -jar argument).
*/
if ((i > 0 && *arg != '-')
|| JLI_StrCmp(arg, "-version") == 0
|| JLI_StrCmp(arg, "-fullversion") == 0
|| JLI_StrCmp(arg, "-help") == 0
|| JLI_StrCmp(arg, "-?") == 0
|| JLI_StrCmp(arg, "-jar") == 0
|| JLI_StrCmp(arg, "-X") == 0
) {
return;
if (i > 0) {
char *prev = argv[i - 1];
// skip non-dash arg preceded by class path specifiers
if (*arg != '-' &&
((JLI_StrCmp(prev, "-cp") == 0
|| JLI_StrCmp(prev, "-classpath") == 0))) {
continue;
}
if (*arg != '-'
|| JLI_StrCmp(arg, "-version") == 0
|| JLI_StrCmp(arg, "-fullversion") == 0
|| JLI_StrCmp(arg, "-help") == 0
|| JLI_StrCmp(arg, "-?") == 0
|| JLI_StrCmp(arg, "-jar") == 0
|| JLI_StrCmp(arg, "-X") == 0) {
return;
}
}
/*
* The following case checks for "-XX:NativeMemoryTracking=value".
......
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
......@@ -889,57 +889,62 @@ public class FileChannelImpl
if (!isOpen())
return null;
long filesize;
do {
filesize = nd.size(fd);
} while ((filesize == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
if (filesize < position + size) { // Extend file size
if (!writable) {
throw new IOException("Channel not open for writing " +
"- cannot extend file to required size");
}
int rv;
long mapSize;
int pagePosition;
synchronized (positionLock) {
long filesize;
do {
rv = nd.truncate(fd, position + size);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
filesize = nd.size(fd);
} while ((filesize == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
}
if (size == 0) {
addr = 0;
// a valid file descriptor is not required
FileDescriptor dummy = new FileDescriptor();
if ((!writable) || (imode == MAP_RO))
return Util.newMappedByteBufferR(0, 0, dummy, null);
else
return Util.newMappedByteBuffer(0, 0, dummy, null);
}
int pagePosition = (int)(position % allocationGranularity);
long mapPosition = position - pagePosition;
long mapSize = size + pagePosition;
try {
// If no exception was thrown from map0, the address is valid
addr = map0(imode, mapPosition, mapSize);
} catch (OutOfMemoryError x) {
// An OutOfMemoryError may indicate that we've exhausted memory
// so force gc and re-attempt map
System.gc();
try {
Thread.sleep(100);
} catch (InterruptedException y) {
Thread.currentThread().interrupt();
if (filesize < position + size) { // Extend file size
if (!writable) {
throw new IOException("Channel not open for writing " +
"- cannot extend file to required size");
}
int rv;
do {
rv = nd.allocate(fd, position + size);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
}
if (size == 0) {
addr = 0;
// a valid file descriptor is not required
FileDescriptor dummy = new FileDescriptor();
if ((!writable) || (imode == MAP_RO))
return Util.newMappedByteBufferR(0, 0, dummy, null);
else
return Util.newMappedByteBuffer(0, 0, dummy, null);
}
pagePosition = (int)(position % allocationGranularity);
long mapPosition = position - pagePosition;
mapSize = size + pagePosition;
try {
// If map0 did not throw an exception, the address is valid
addr = map0(imode, mapPosition, mapSize);
} catch (OutOfMemoryError y) {
// After a second OOME, fail
throw new IOException("Map failed", y);
} catch (OutOfMemoryError x) {
// An OutOfMemoryError may indicate that we've exhausted
// memory so force gc and re-attempt map
System.gc();
try {
Thread.sleep(100);
} catch (InterruptedException y) {
Thread.currentThread().interrupt();
}
try {
addr = map0(imode, mapPosition, mapSize);
} catch (OutOfMemoryError y) {
// After a second OOME, fail
throw new IOException("Map failed", y);
}
}
}
} // synchronized
// On Windows, and potentially other platforms, we need an open
// file descriptor for some mapping operations.
......
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2018, 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
......@@ -40,6 +40,8 @@ abstract class FileDispatcher extends NativeDispatcher {
abstract int truncate(FileDescriptor fd, long size) throws IOException;
abstract int allocate(FileDescriptor fd, long size) throws IOException;
abstract long size(FileDescriptor fd) throws IOException;
abstract int lock(FileDescriptor fd, boolean blocking, long pos, long size,
......
/*
* Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
......@@ -132,26 +132,33 @@ class EndEntityChecker {
return new EndEntityChecker(type, variant);
}
void check(X509Certificate cert, Object parameter)
throws CertificateException {
void check(X509Certificate cert, Object parameter,
boolean checkUnresolvedCritExts) throws CertificateException {
if (variant.equals(Validator.VAR_GENERIC)) {
// no checks
return;
} else if (variant.equals(Validator.VAR_TLS_SERVER)) {
checkTLSServer(cert, (String)parameter);
return; // no checks
}
Set<String> exts = getCriticalExtensions(cert);
if (variant.equals(Validator.VAR_TLS_SERVER)) {
checkTLSServer(cert, (String)parameter, exts);
} else if (variant.equals(Validator.VAR_TLS_CLIENT)) {
checkTLSClient(cert);
checkTLSClient(cert, exts);
} else if (variant.equals(Validator.VAR_CODE_SIGNING)) {
checkCodeSigning(cert);
checkCodeSigning(cert, exts);
} else if (variant.equals(Validator.VAR_JCE_SIGNING)) {
checkCodeSigning(cert);
checkCodeSigning(cert, exts);
} else if (variant.equals(Validator.VAR_PLUGIN_CODE_SIGNING)) {
checkCodeSigning(cert);
checkCodeSigning(cert, exts);
} else if (variant.equals(Validator.VAR_TSA_SERVER)) {
checkTSAServer(cert);
checkTSAServer(cert, exts);
} else {
throw new CertificateException("Unknown variant: " + variant);
}
// if neither VAR_GENERIC variant nor unknown variant
if (checkUnresolvedCritExts) {
checkRemainingExtensions(exts);
}
}
/**
......@@ -219,10 +226,8 @@ class EndEntityChecker {
* authentication.
* @throws CertificateException if not.
*/
private void checkTLSClient(X509Certificate cert)
private void checkTLSClient(X509Certificate cert, Set<String> exts)
throws CertificateException {
Set<String> exts = getCriticalExtensions(cert);
if (checkKeyUsage(cert, KU_SIGNATURE) == false) {
throw new ValidatorException
("KeyUsage does not allow digital signatures",
......@@ -245,8 +250,6 @@ class EndEntityChecker {
exts.remove(SimpleValidator.OID_KEY_USAGE);
exts.remove(SimpleValidator.OID_EXTENDED_KEY_USAGE);
exts.remove(SimpleValidator.OID_NETSCAPE_CERT_TYPE);
checkRemainingExtensions(exts);
}
/**
......@@ -255,10 +258,8 @@ class EndEntityChecker {
* specification for details.
* @throws CertificateException if not.
*/
private void checkTLSServer(X509Certificate cert, String parameter)
throws CertificateException {
Set<String> exts = getCriticalExtensions(cert);
private void checkTLSServer(X509Certificate cert, String parameter,
Set<String> exts) throws CertificateException {
if (KU_SERVER_ENCRYPTION.contains(parameter)) {
if (checkKeyUsage(cert, KU_KEY_ENCIPHERMENT) == false) {
throw new ValidatorException
......@@ -303,18 +304,14 @@ class EndEntityChecker {
exts.remove(SimpleValidator.OID_KEY_USAGE);
exts.remove(SimpleValidator.OID_EXTENDED_KEY_USAGE);
exts.remove(SimpleValidator.OID_NETSCAPE_CERT_TYPE);
checkRemainingExtensions(exts);
}
/**
* Check whether this certificate can be used for code signing.
* @throws CertificateException if not.
*/
private void checkCodeSigning(X509Certificate cert)
private void checkCodeSigning(X509Certificate cert, Set<String> exts)
throws CertificateException {
Set<String> exts = getCriticalExtensions(cert);
if (checkKeyUsage(cert, KU_SIGNATURE) == false) {
throw new ValidatorException
("KeyUsage does not allow digital signatures",
......@@ -341,8 +338,6 @@ class EndEntityChecker {
// remove extensions we checked
exts.remove(SimpleValidator.OID_KEY_USAGE);
exts.remove(SimpleValidator.OID_EXTENDED_KEY_USAGE);
checkRemainingExtensions(exts);
}
/**
......@@ -350,10 +345,8 @@ class EndEntityChecker {
* server (see RFC 3161, section 2.3).
* @throws CertificateException if not.
*/
private void checkTSAServer(X509Certificate cert)
private void checkTSAServer(X509Certificate cert, Set<String> exts)
throws CertificateException {
Set<String> exts = getCriticalExtensions(cert);
if (checkKeyUsage(cert, KU_SIGNATURE) == false) {
throw new ValidatorException
("KeyUsage does not allow digital signatures",
......@@ -376,7 +369,5 @@ class EndEntityChecker {
// remove extensions we checked
exts.remove(SimpleValidator.OID_KEY_USAGE);
exts.remove(SimpleValidator.OID_EXTENDED_KEY_USAGE);
checkRemainingExtensions(exts);
}
}
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
......@@ -143,6 +143,7 @@ public abstract class Validator {
*/
public final static String VAR_PLUGIN_CODE_SIGNING = "plugin code signing";
private final String type;
final EndEntityChecker endEntityChecker;
final String variant;
......@@ -154,6 +155,7 @@ public abstract class Validator {
volatile Date validationDate;
Validator(String type, String variant) {
this.type = type;
this.variant = variant;
endEntityChecker = EndEntityChecker.getInstance(type, variant);
}
......@@ -261,7 +263,16 @@ public abstract class Validator {
// omit EE extension check if EE cert is also trust anchor
if (chain.length > 1) {
endEntityChecker.check(chain[0], parameter);
// EndEntityChecker does not need to check unresolved critical
// extensions when validating with a TYPE_PKIX Validator.
// A TYPE_PKIX Validator will already have run checks on all
// certs' extensions, including checks by any PKIXCertPathCheckers
// included in the PKIXParameters, so the extra checks would be
// redundant.
boolean checkUnresolvedCritExts =
(type == TYPE_PKIX) ? false : true;
endEntityChecker.check(chain[0], parameter,
checkUnresolvedCritExts);
}
return chain;
......
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
......@@ -80,6 +80,10 @@ class FileDispatcherImpl extends FileDispatcher {
return truncate0(fd, size);
}
int allocate(FileDescriptor fd, long size) throws IOException {
return allocate0(fd, size);
}
long size(FileDescriptor fd) throws IOException {
return size0(fd);
}
......@@ -142,6 +146,9 @@ class FileDispatcherImpl extends FileDispatcher {
static native int truncate0(FileDescriptor fd, long size)
throws IOException;
static native int allocate0(FileDescriptor fd, long size)
throws IOException;
static native long size0(FileDescriptor fd) throws IOException;
static native int lock0(FileDescriptor fd, boolean blocking, long pos,
......
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, 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,10 @@
* questions.
*/
#if defined(__linux__)
#define _FILE_OFFSET_BITS 64
#endif
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
......@@ -208,6 +212,25 @@ jint
handleSetLength(FD fd, jlong length)
{
int result;
#if defined(__linux__)
/*
* On Linux, if the file size is being increased, then ftruncate64()
* will modify the metadata value of the size without actually allocating
* any blocks which can cause a SIGBUS error if the file is subsequently
* memory-mapped.
*/
struct stat64 sb;
if (fstat64(fd, &sb) == 0 && length > sb.st_blocks*512) {
RESTARTABLE(posix_fallocate(fd, 0, length), result);
// Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
if (result == 0) {
return 0;
} else if (errno != EOPNOTSUPP && errno != ENOSYS) {
return result;
}
}
#endif
RESTARTABLE(ftruncate64(fd, length), result);
return result;
}
......
/*
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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,10 @@
* questions.
*/
#if defined(__linux__)
#define _FILE_OFFSET_BITS 64
#endif
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
......@@ -178,6 +182,30 @@ Java_sun_nio_ch_FileDispatcherImpl_truncate0(JNIEnv *env, jobject this,
"Truncation failed");
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_allocate0(JNIEnv *env, jobject this,
jobject fdo, jlong size)
{
#if defined(__linux__)
/*
* On Linux, if the file size is being increased, then ftruncate64()
* will modify the metadata value of the size without actually allocating
* any blocks which can cause a SIGBUS error if the file is subsequently
* memory-mapped.
*/
// Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
int result = posix_fallocate(fdval(env, fdo), 0, size);
if (result == 0) {
return 0;
} else if (errno != EOPNOTSUPP && errno != ENOSYS) {
return handle(env, result, "Allocation failed");
}
#endif
return handle(env,
ftruncate64(fdval(env, fdo), size),
"Truncation failed");
}
JNIEXPORT jlong JNICALL
Java_sun_nio_ch_FileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo)
{
......
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
......@@ -93,6 +93,11 @@ class FileDispatcherImpl extends FileDispatcher {
return truncate0(fd, size);
}
int allocate(FileDescriptor fd, long size) throws IOException {
// truncate0() works for extending and truncating file size
return truncate0(fd, size);
}
long size(FileDescriptor fd) throws IOException {
return size0(fd);
}
......
/*
* Copyright (c) 2017, 2018, 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.
*/
/* @test
* @ignore This test has huge disk space requirements
* @bug 8168628
* @summary Test extending files to very large sizes without hitting a SIGBUS
* @requires (os.family == "linux")
* @run main/othervm/timeout=600 -Xms4g -Xmx4g FileExtensionAndMap
* @run main/othervm/timeout=600 -Xms4g -Xmx4g FileExtensionAndMap true
*/
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Semaphore;
import java.util.stream.IntStream;
public class FileExtensionAndMap {
private static final ExecutorService CACHED_EXECUTORSERVICE =
Executors.newCachedThreadPool();
private static final String TMPDIR = System.getProperty("test.dir", ".");
private static boolean useRaf = false;
public static void main(String args[]) throws Exception {
if (args.length > 2) {
throw new IllegalArgumentException
("Arguments: [true|false [targetFolder]]");
}
String defaultFolder = TMPDIR + File.separator + "target";
if (args.length > 0) {
useRaf = Boolean.valueOf(args[0]);
if (args.length > 1) {
defaultFolder = args[1];
}
}
final String targetFolder = defaultFolder;
Path p = Paths.get(targetFolder);
boolean targetExists = Files.exists(p);
if (!targetExists) {
Files.createDirectory(p);
}
System.out.printf("Using RandomAccessFile: %s; target folder: %s%n",
useRaf, targetFolder);
ForkJoinPool fjPool = new ForkJoinPool(3);
fjPool.submit(() -> {
IntStream.range(0, 20).parallel().forEach((index) -> {
String fileName = "testBigFile_" + index + ".dat";
Path source = null;
Path target = null;
try {
source = Paths.get(TMPDIR, fileName);
testCreateBigFile(source);
target = Paths.get(targetFolder, fileName);
testFileCopy(source, target);
} catch (Throwable th) {
System.err.println("Error copying file with fileName: "
+ fileName + " : " + th.getMessage());
th.printStackTrace(System.err);
} finally {
try {
if (source != null) {
Files.deleteIfExists(source);
}
} catch (Throwable ignored) {
}
try {
if (target != null) {
Files.deleteIfExists(target);
}
} catch (Throwable ignored) {
}
}
});
}).join();
if (!targetExists) {
Files.delete(p);
}
}
private static void testFileCopy(Path source, Path target)
throws IOException {
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
System.out.println("Finished copying file with fileName: "
+ source.getFileName());
}
private static void testCreateBigFile(Path segmentFile)
throws IOException {
final Semaphore concurrencySemaphore = new Semaphore(5);
long fileSize = 3L * 1024L * 1024L * 1024L;
int blockSize = 10 * 1024 * 1024;
int loopCount = (int) Math.floorDiv(fileSize, blockSize);
String fileName = segmentFile.getFileName().toString();
if (useRaf) {
try (RandomAccessFile raf
= new RandomAccessFile(segmentFile.toFile(), "rw")) {
raf.setLength(fileSize);
try (FileChannel fc = raf.getChannel()) {
for (int i = 0; i < loopCount; i++) {
final long startPosition = 1L * blockSize * i;
concurrencySemaphore.acquireUninterruptibly();
CACHED_EXECUTORSERVICE.submit(() -> {
writeTemplateData(fileName, fc, startPosition,
blockSize, concurrencySemaphore);
});
}
} finally {
concurrencySemaphore.acquireUninterruptibly(5);
}
}
} else {
Path file = Files.createFile(segmentFile);
try (FileChannel fc = FileChannel.open(file,
StandardOpenOption.READ, StandardOpenOption.WRITE)) {
for (int i = 0; i < loopCount; i++) {
final long startPosition = 1L * blockSize * i;
concurrencySemaphore.acquireUninterruptibly();
CACHED_EXECUTORSERVICE.submit(() -> {
writeTemplateData(fileName, fc, startPosition,
blockSize, concurrencySemaphore);
});
}
}
}
}
private static void writeTemplateData(String fileName,
FileChannel fc, long startPosition, int blockSize,
Semaphore concurrencySemaphore) {
try {
byte[] EMPTY_RECORD = new byte[blockSize / 256];
MappedByteBuffer mappedByteBuffer = fc.map(MapMode.READ_WRITE,
startPosition, blockSize);
IntStream.range(0, 256).forEach((recordIndex) -> {
try {
mappedByteBuffer.position((int) (recordIndex *
EMPTY_RECORD.length));
mappedByteBuffer.put(EMPTY_RECORD, 0, EMPTY_RECORD.length);
} catch (Throwable th) {
System.err.println
("Error in FileExtensionAndMap.writeTemplateData empty record for fileName: "
+ fileName + ", startPosition: " + startPosition + ", recordIndex: "
+ recordIndex + " : " + th.getMessage());
th.printStackTrace(System.err);
}
});
mappedByteBuffer.force();
} catch (Throwable th) {
if (!(th instanceof ClosedChannelException)) {
System.err.println
("Error in FileExtensionAndMap.writeTemplateData empty record for fileName: "
+ fileName + ", startPosition: " + startPosition + " : "
+ th.getMessage());
th.printStackTrace(System.err);
}
} finally {
concurrencySemaphore.release();
}
}
}
/*
* Copyright (c) 2015, 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.
*/
/*
* @test
* @bug 8076117
* @summary EndEntityChecker should not process custom extensions
* after PKIX validation
*/
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.CertPathValidatorException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.PKIXBuilderParameters;
import java.security.cert.PKIXCertPathChecker;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import sun.security.validator.KeyStores;
import sun.security.validator.Validator;
public class EndEntityExtensionCheck {
/*
* Owner: CN=TestCA
* Issuer: CN=TestCA
*/
private static final String CA =
"-----BEGIN CERTIFICATE-----\n" +
"MIICgDCCAj2gAwIBAgIEC18hWjALBgcqhkjOOAQDBQAwETEPMA0GA1UEAxMGVGVz\n" +
"dENBMB4XDTE1MDQwNzIyMzUyMFoXDTI1MDQwNjIyMzUyMFowETEPMA0GA1UEAxMG\n" +
"VGVzdENBMIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2\n" +
"EbdSPO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdr\n" +
"mVClpJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXz\n" +
"rith1yrv8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+Gghdab\n" +
"Pd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6Ewo\n" +
"FhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhR\n" +
"kImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoDgYUAAoGBAJOWy2hVy4iNwsi/idWG\n" +
"oksr9IZxQIFR2YavoUmD+rIgfYUpiCihzftDLMMaNYqp9PPxuOyoIPGPbwmKpAs5\n" +
"nq6gLwH2lSsN+EwyV2SJ0J26PHiMuRNZWWfKR3cpEqbQVb0CmvqSpj8zYfamPzp7\n" +
"eXSWwahzgLCGJM3SgCfDFC0uoyEwHzAdBgNVHQ4EFgQU7tLD8FnWM+r6jBr+mCXs\n" +
"8G5yBpgwCwYHKoZIzjgEAwUAAzAAMC0CFQCHCtzC3S0ST0EZBucikVui4WXD8QIU\n" +
"L3Oxy6989/FhZlZWJlhqc1ungEQ=\n" +
"-----END CERTIFICATE-----";
/*
* Owner: CN=TestEE
* Issuer: CN=TestCA
* Contains a custom critical extension with OID 1.2.3.4:
* #1: ObjectId: 1.2.3.4 Criticality=true
* 0000: 00 00
*/
private static final String EE =
"-----BEGIN CERTIFICATE-----\n" +
"MIICrTCCAmugAwIBAgIELjciKzALBgcqhkjOOAQDBQAwETEPMA0GA1UEAxMGVGVz\n" +
"dENBMB4XDTE1MDQwNzIzMDA1OFoXDTE1MDcwNjIzMDA1OFowETEPMA0GA1UEAxMG\n" +
"VGVzdEVFMIIBtzCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2\n" +
"EbdSPO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdr\n" +
"mVClpJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXz\n" +
"rith1yrv8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+Gghdab\n" +
"Pd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6Ewo\n" +
"FhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhR\n" +
"kImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoDgYQAAoGAN97otrAJEuUg/O97vScI\n" +
"01xs1jqTz5o0PGpKiDDJNB3tCCUbLqXoBQBvSefQ8vYL3mmlEJLxlwfbajRmJQp0\n" +
"tUy5SUCZHk3MdoKxSvrqYnVpYwJHFXKWs6lAawxfuWbkm9SREuepOWnVzy2ecf5z\n" +
"hvy9mgEBfi4E9Cy8Byq2TpyjUDBOMAwGAyoDBAEB/wQCAAAwHwYDVR0jBBgwFoAU\n" +
"7tLD8FnWM+r6jBr+mCXs8G5yBpgwHQYDVR0OBBYEFNRVqt5F+EAuJ5x1IZLDkoMs\n" +
"mDj4MAsGByqGSM44BAMFAAMvADAsAhQyNGhxIp5IshN1zqLs4pUY214IMAIUMmTL\n" +
"3ZMpMAjITbuHHlFNUqZ7A9s=\n" +
"-----END CERTIFICATE-----";
public static void main(String[] args) throws Exception {
X509Certificate[] chain = createChain();
/* Test 1: Test SimpleValidator
* SimpleValidator doesn't check for unsupported critical
* extensions in the end entity certificate, and leaves that up
* to EndEntityChecker, which should catch such extensions.
*/
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setCertificateEntry("testca", chain[chain.length - 1]);
Validator v = Validator.getInstance(Validator.TYPE_SIMPLE,
Validator.VAR_TLS_CLIENT,
KeyStores.getTrustedCerts(ks));
try {
v.validate(chain);
throw new Exception("Chain should not have validated " +
"successfully.");
} catch (CertificateException ex) {
// EE cert has an unsupported critical extension that is not
// checked by SimpleValidator's extension checks, so this
// failure is expected
}
/* Test 2: Test PKIXValidator without custom checker
* PKIXValidator accepts PKIXParameters that can contain
* custom PKIXCertPathCheckers, which would be run against
* each cert in the chain, including EE certs.
* Check that if PKIXValidator is not provided a custom
* PKIXCertPathChecker for an unknown critical extension in
* the EE cert, chain validation will fail.
*/
TrustAnchor ta = new TrustAnchor(chain[chain.length - 1], null);
Set<TrustAnchor> tas = new HashSet<>();
tas.add(ta);
PKIXBuilderParameters params = new PKIXBuilderParameters(tas, null);
params.setDate(new Date(115, 5, 1)); // 2015-05-01
params.setRevocationEnabled(false);
v = Validator.getInstance(Validator.TYPE_PKIX,
Validator.VAR_TLS_CLIENT,
params);
try {
v.validate(chain);
throw new Exception("Chain should not have validated " +
"successfully.");
} catch (CertificateException ex) {
// EE cert has an unsupported critical extension and
// PKIXValidator was not provided any custom checker
// for it, so this failure ie expected.
}
/* Test 3: Test PKIXValidator with custom checker
* Check that PKIXValidator will successfully validate a chain
* containing an EE cert with a critical custom extension, given
* a corresponding PKIXCertPathChecker for the extension.
*/
params = new PKIXBuilderParameters(tas, null);
params.addCertPathChecker(new CustomChecker());
params.setDate(new Date(115, 5, 1)); // 2015-05-01
params.setRevocationEnabled(false);
v = Validator.getInstance(Validator.TYPE_PKIX,
Validator.VAR_TLS_CLIENT,
params);
v.validate(chain); // This should validate successfully
System.out.println("Tests passed.");
}
public static X509Certificate[] createChain() throws Exception {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate ee = (X509Certificate)
cf.generateCertificate((new ByteArrayInputStream(EE.getBytes())));
X509Certificate ca = (X509Certificate)
cf.generateCertificate((new ByteArrayInputStream(CA.getBytes())));
X509Certificate[] chain = {ee, ca};
return chain;
}
/*
* A custom PKIXCertPathChecker. Looks for a critical extension
* in an end entity certificate with the OID 1.2.3.4.
*/
static class CustomChecker extends PKIXCertPathChecker {
@Override
public void init(boolean forward) throws CertPathValidatorException {
// nothing to do
}
@Override
public boolean isForwardCheckingSupported() {
return false;
}
@Override
public Set<String> getSupportedExtensions() {
Set<String> exts = new HashSet<>();
exts.add("1.2.3.4");
return exts;
}
@Override
public void check(Certificate cert,
Collection<String> unresolvedCritExts)
throws CertPathValidatorException {
X509Certificate currCert = (X509Certificate)cert;
// check that this is an EE cert
if (currCert.getBasicConstraints() == -1) {
if (unresolvedCritExts != null &&
!unresolvedCritExts.isEmpty()) {
unresolvedCritExts.remove("1.2.3.4");
}
}
}
}
}
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018, 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,7 +23,7 @@
/*
* @test
* @bug 7124089 7131021 8042469 8066185
* @bug 7124089 7131021 8042469 8066185 8074373
* @summary Checks for Launcher special flags, such as MacOSX specific flags,
* and JVM NativeMemoryTracking flags.
* @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java
......@@ -270,6 +270,16 @@ public class TestSpecialArgs extends TestHelper {
tr = doExec(envMap, javaCmd, "Foo", "-XX:NativeMemoryTracking=summary");
checkTestResult(tr);
// should accept with no warnings
tr = doExec(javaCmd, "-cp", jarFile.getName(),
"-XX:NativeMemoryTracking=summary", "Foo");
ensureNoWarnings(tr);
// should accept with no warnings
tr = doExec(javaCmd, "-classpath", jarFile.getName(),
"-XX:NativeMemoryTracking=summary", "Foo");
ensureNoWarnings(tr);
// make sure a missing class is handled correctly, because the class
// resolution is performed by the JVM.
tr = doExec(javaCmd, "AbsentClass", "-XX:NativeMemoryTracking=summary");
......@@ -278,6 +288,14 @@ public class TestSpecialArgs extends TestHelper {
}
}
void ensureNoWarnings(TestResult tr) {
checkTestResult(tr);
if (tr.contains("warning: Native Memory Tracking")) {
System.err.println(tr.toString());
throw new RuntimeException("Test Fails");
}
}
void checkTestResult(TestResult tr) {
if (!tr.isOK()) {
System.err.println(tr.toString());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册