mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-15 16:44:36 +02:00
Merge
This commit is contained in:
commit
a8c5f1e59a
64 changed files with 1781 additions and 378 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 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
|
||||
|
@ -31,6 +31,7 @@ package java.math;
|
|||
|
||||
import static java.math.BigInteger.LONG_MASK;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Immutable, arbitrary-precision signed decimal numbers. A
|
||||
|
@ -424,9 +425,14 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||
* @since 1.5
|
||||
*/
|
||||
public BigDecimal(char[] in, int offset, int len, MathContext mc) {
|
||||
// protect against huge length.
|
||||
if (offset + len > in.length || offset < 0)
|
||||
throw new NumberFormatException("Bad offset or len arguments for char[] input.");
|
||||
// protect against huge length, negative values, and integer overflow
|
||||
try {
|
||||
Objects.checkFromIndexSize(offset, len, in.length);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new NumberFormatException
|
||||
("Bad offset or len arguments for char[] input.");
|
||||
}
|
||||
|
||||
// This is the primary string to BigDecimal constructor; all
|
||||
// incoming strings end up here; it uses explicit (inline)
|
||||
// parsing for speed and generates at most one intermediate
|
||||
|
|
|
@ -307,10 +307,8 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
public BigInteger(byte[] val, int off, int len) {
|
||||
if (val.length == 0) {
|
||||
throw new NumberFormatException("Zero length BigInteger");
|
||||
} else if ((off < 0) || (off >= val.length) || (len < 0) ||
|
||||
(len > val.length - off)) { // 0 <= off < val.length
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
Objects.checkFromIndexSize(off, len, val.length);
|
||||
|
||||
if (val[off] < 0) {
|
||||
mag = makePositive(val, off, len);
|
||||
|
@ -395,12 +393,8 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
public BigInteger(int signum, byte[] magnitude, int off, int len) {
|
||||
if (signum < -1 || signum > 1) {
|
||||
throw(new NumberFormatException("Invalid signum value"));
|
||||
} else if ((off < 0) || (len < 0) ||
|
||||
(len > 0 &&
|
||||
((off >= magnitude.length) ||
|
||||
(len > magnitude.length - off)))) { // 0 <= off < magnitude.length
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
Objects.checkFromIndexSize(off, len, magnitude.length);
|
||||
|
||||
// stripLeadingZeroBytes() returns a zero length array if len == 0
|
||||
this.mag = stripLeadingZeroBytes(magnitude, off, len);
|
||||
|
@ -1239,6 +1233,14 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
private static final double LOG_TWO = Math.log(2.0);
|
||||
|
||||
static {
|
||||
assert 0 < KARATSUBA_THRESHOLD
|
||||
&& KARATSUBA_THRESHOLD < TOOM_COOK_THRESHOLD
|
||||
&& TOOM_COOK_THRESHOLD < Integer.MAX_VALUE
|
||||
&& 0 < KARATSUBA_SQUARE_THRESHOLD
|
||||
&& KARATSUBA_SQUARE_THRESHOLD < TOOM_COOK_SQUARE_THRESHOLD
|
||||
&& TOOM_COOK_SQUARE_THRESHOLD < Integer.MAX_VALUE :
|
||||
"Algorithm thresholds are inconsistent";
|
||||
|
||||
for (int i = 1; i <= MAX_CONSTANT; i++) {
|
||||
int[] magnitude = new int[1];
|
||||
magnitude[0] = i;
|
||||
|
@ -1562,6 +1564,18 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
* @return {@code this * val}
|
||||
*/
|
||||
public BigInteger multiply(BigInteger val) {
|
||||
return multiply(val, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a BigInteger whose value is {@code (this * val)}. If
|
||||
* the invocation is recursive certain overflow checks are skipped.
|
||||
*
|
||||
* @param val value to be multiplied by this BigInteger.
|
||||
* @param isRecursion whether this is a recursive invocation
|
||||
* @return {@code this * val}
|
||||
*/
|
||||
private BigInteger multiply(BigInteger val, boolean isRecursion) {
|
||||
if (val.signum == 0 || signum == 0)
|
||||
return ZERO;
|
||||
|
||||
|
@ -1589,6 +1603,63 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
if ((xlen < TOOM_COOK_THRESHOLD) && (ylen < TOOM_COOK_THRESHOLD)) {
|
||||
return multiplyKaratsuba(this, val);
|
||||
} else {
|
||||
//
|
||||
// In "Hacker's Delight" section 2-13, p.33, it is explained
|
||||
// that if x and y are unsigned 32-bit quantities and m and n
|
||||
// are their respective numbers of leading zeros within 32 bits,
|
||||
// then the number of leading zeros within their product as a
|
||||
// 64-bit unsigned quantity is either m + n or m + n + 1. If
|
||||
// their product is not to overflow, it cannot exceed 32 bits,
|
||||
// and so the number of leading zeros of the product within 64
|
||||
// bits must be at least 32, i.e., the leftmost set bit is at
|
||||
// zero-relative position 31 or less.
|
||||
//
|
||||
// From the above there are three cases:
|
||||
//
|
||||
// m + n leftmost set bit condition
|
||||
// ----- ---------------- ---------
|
||||
// >= 32 x <= 64 - 32 = 32 no overflow
|
||||
// == 31 x >= 64 - 32 = 32 possible overflow
|
||||
// <= 30 x >= 64 - 31 = 33 definite overflow
|
||||
//
|
||||
// The "possible overflow" condition cannot be detected by
|
||||
// examning data lengths alone and requires further calculation.
|
||||
//
|
||||
// By analogy, if 'this' and 'val' have m and n as their
|
||||
// respective numbers of leading zeros within 32*MAX_MAG_LENGTH
|
||||
// bits, then:
|
||||
//
|
||||
// m + n >= 32*MAX_MAG_LENGTH no overflow
|
||||
// m + n == 32*MAX_MAG_LENGTH - 1 possible overflow
|
||||
// m + n <= 32*MAX_MAG_LENGTH - 2 definite overflow
|
||||
//
|
||||
// Note however that if the number of ints in the result
|
||||
// were to be MAX_MAG_LENGTH and mag[0] < 0, then there would
|
||||
// be overflow. As a result the leftmost bit (of mag[0]) cannot
|
||||
// be used and the constraints must be adjusted by one bit to:
|
||||
//
|
||||
// m + n > 32*MAX_MAG_LENGTH no overflow
|
||||
// m + n == 32*MAX_MAG_LENGTH possible overflow
|
||||
// m + n < 32*MAX_MAG_LENGTH definite overflow
|
||||
//
|
||||
// The foregoing leading zero-based discussion is for clarity
|
||||
// only. The actual calculations use the estimated bit length
|
||||
// of the product as this is more natural to the internal
|
||||
// array representation of the magnitude which has no leading
|
||||
// zero elements.
|
||||
//
|
||||
if (!isRecursion) {
|
||||
// The bitLength() instance method is not used here as we
|
||||
// are only considering the magnitudes as non-negative. The
|
||||
// Toom-Cook multiplication algorithm determines the sign
|
||||
// at its end from the two signum values.
|
||||
if (bitLength(mag, mag.length) +
|
||||
bitLength(val.mag, val.mag.length) >
|
||||
32L*MAX_MAG_LENGTH) {
|
||||
reportOverflow();
|
||||
}
|
||||
}
|
||||
|
||||
return multiplyToomCook3(this, val);
|
||||
}
|
||||
}
|
||||
|
@ -1674,7 +1745,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
int ystart = ylen - 1;
|
||||
|
||||
if (z == null || z.length < (xlen+ ylen))
|
||||
z = new int[xlen+ylen];
|
||||
z = new int[xlen+ylen];
|
||||
|
||||
long carry = 0;
|
||||
for (int j=ystart, k=ystart+1+xstart; j >= 0; j--, k--) {
|
||||
|
@ -1808,16 +1879,16 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
|
||||
BigInteger v0, v1, v2, vm1, vinf, t1, t2, tm1, da1, db1;
|
||||
|
||||
v0 = a0.multiply(b0);
|
||||
v0 = a0.multiply(b0, true);
|
||||
da1 = a2.add(a0);
|
||||
db1 = b2.add(b0);
|
||||
vm1 = da1.subtract(a1).multiply(db1.subtract(b1));
|
||||
vm1 = da1.subtract(a1).multiply(db1.subtract(b1), true);
|
||||
da1 = da1.add(a1);
|
||||
db1 = db1.add(b1);
|
||||
v1 = da1.multiply(db1);
|
||||
v1 = da1.multiply(db1, true);
|
||||
v2 = da1.add(a2).shiftLeft(1).subtract(a0).multiply(
|
||||
db1.add(b2).shiftLeft(1).subtract(b0));
|
||||
vinf = a2.multiply(b2);
|
||||
db1.add(b2).shiftLeft(1).subtract(b0), true);
|
||||
vinf = a2.multiply(b2, true);
|
||||
|
||||
// The algorithm requires two divisions by 2 and one by 3.
|
||||
// All divisions are known to be exact, that is, they do not produce
|
||||
|
@ -1983,6 +2054,17 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
* @return {@code this<sup>2</sup>}
|
||||
*/
|
||||
private BigInteger square() {
|
||||
return square(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a BigInteger whose value is {@code (this<sup>2</sup>)}. If
|
||||
* the invocation is recursive certain overflow checks are skipped.
|
||||
*
|
||||
* @param isRecursion whether this is a recursive invocation
|
||||
* @return {@code this<sup>2</sup>}
|
||||
*/
|
||||
private BigInteger square(boolean isRecursion) {
|
||||
if (signum == 0) {
|
||||
return ZERO;
|
||||
}
|
||||
|
@ -1995,6 +2077,15 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
if (len < TOOM_COOK_SQUARE_THRESHOLD) {
|
||||
return squareKaratsuba();
|
||||
} else {
|
||||
//
|
||||
// For a discussion of overflow detection see multiply()
|
||||
//
|
||||
if (!isRecursion) {
|
||||
if (bitLength(mag, mag.length) > 16L*MAX_MAG_LENGTH) {
|
||||
reportOverflow();
|
||||
}
|
||||
}
|
||||
|
||||
return squareToomCook3();
|
||||
}
|
||||
}
|
||||
|
@ -2146,13 +2237,13 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
a0 = getToomSlice(k, r, 2, len);
|
||||
BigInteger v0, v1, v2, vm1, vinf, t1, t2, tm1, da1;
|
||||
|
||||
v0 = a0.square();
|
||||
v0 = a0.square(true);
|
||||
da1 = a2.add(a0);
|
||||
vm1 = da1.subtract(a1).square();
|
||||
vm1 = da1.subtract(a1).square(true);
|
||||
da1 = da1.add(a1);
|
||||
v1 = da1.square();
|
||||
vinf = a2.square();
|
||||
v2 = da1.add(a2).shiftLeft(1).subtract(a0).square();
|
||||
v1 = da1.square(true);
|
||||
vinf = a2.square(true);
|
||||
v2 = da1.add(a2).shiftLeft(1).subtract(a0).square(true);
|
||||
|
||||
// The algorithm requires two divisions by 2 and one by 3.
|
||||
// All divisions are known to be exact, that is, they do not produce
|
||||
|
@ -2323,10 +2414,11 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
// The remaining part can then be exponentiated faster. The
|
||||
// powers of two will be multiplied back at the end.
|
||||
int powersOfTwo = partToSquare.getLowestSetBit();
|
||||
long bitsToShift = (long)powersOfTwo * exponent;
|
||||
if (bitsToShift > Integer.MAX_VALUE) {
|
||||
long bitsToShiftLong = (long)powersOfTwo * exponent;
|
||||
if (bitsToShiftLong > Integer.MAX_VALUE) {
|
||||
reportOverflow();
|
||||
}
|
||||
int bitsToShift = (int)bitsToShiftLong;
|
||||
|
||||
int remainingBits;
|
||||
|
||||
|
@ -2336,9 +2428,9 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
remainingBits = partToSquare.bitLength();
|
||||
if (remainingBits == 1) { // Nothing left but +/- 1?
|
||||
if (signum < 0 && (exponent&1) == 1) {
|
||||
return NEGATIVE_ONE.shiftLeft(powersOfTwo*exponent);
|
||||
return NEGATIVE_ONE.shiftLeft(bitsToShift);
|
||||
} else {
|
||||
return ONE.shiftLeft(powersOfTwo*exponent);
|
||||
return ONE.shiftLeft(bitsToShift);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -2383,13 +2475,16 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
if (bitsToShift + scaleFactor <= 62) { // Fits in long?
|
||||
return valueOf((result << bitsToShift) * newSign);
|
||||
} else {
|
||||
return valueOf(result*newSign).shiftLeft((int) bitsToShift);
|
||||
return valueOf(result*newSign).shiftLeft(bitsToShift);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return valueOf(result*newSign);
|
||||
}
|
||||
} else {
|
||||
if ((long)bitLength() * exponent / Integer.SIZE > MAX_MAG_LENGTH) {
|
||||
reportOverflow();
|
||||
}
|
||||
|
||||
// Large number algorithm. This is basically identical to
|
||||
// the algorithm above, but calls multiply() and square()
|
||||
// which may use more efficient algorithms for large numbers.
|
||||
|
@ -2409,7 +2504,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
// Multiply back the (exponentiated) powers of two (quickly,
|
||||
// by shifting left)
|
||||
if (powersOfTwo > 0) {
|
||||
answer = answer.shiftLeft(powersOfTwo*exponent);
|
||||
answer = answer.shiftLeft(bitsToShift);
|
||||
}
|
||||
|
||||
if (signum < 0 && (exponent&1) == 1) {
|
||||
|
@ -3584,7 +3679,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
for (int i=1; i< len && pow2; i++)
|
||||
pow2 = (mag[i] == 0);
|
||||
|
||||
n = (pow2 ? magBitLength -1 : magBitLength);
|
||||
n = (pow2 ? magBitLength - 1 : magBitLength);
|
||||
} else {
|
||||
n = magBitLength;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 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
|
||||
|
@ -120,7 +120,7 @@ public class GCMParameterSpec implements AlgorithmParameterSpec {
|
|||
|
||||
// Input sanity check
|
||||
if ((src == null) ||(len < 0) || (offset < 0)
|
||||
|| ((len + offset) > src.length)) {
|
||||
|| (len > (src.length - offset))) {
|
||||
throw new IllegalArgumentException("Invalid buffer arguments");
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@ import java.net.URL;
|
|||
* credentials without prompting) should only be tried with trusted sites.
|
||||
*/
|
||||
public abstract class NTLMAuthenticationCallback {
|
||||
private static volatile NTLMAuthenticationCallback callback =
|
||||
new DefaultNTLMAuthenticationCallback();
|
||||
private static volatile NTLMAuthenticationCallback callback;
|
||||
|
||||
public static void setNTLMAuthenticationCallback(
|
||||
NTLMAuthenticationCallback callback) {
|
||||
|
@ -50,10 +49,5 @@ public abstract class NTLMAuthenticationCallback {
|
|||
* transparent Authentication.
|
||||
*/
|
||||
public abstract boolean isTrustedSite(URL url);
|
||||
|
||||
static class DefaultNTLMAuthenticationCallback extends NTLMAuthenticationCallback {
|
||||
@Override
|
||||
public boolean isTrustedSite(URL url) { return true; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -624,11 +624,10 @@ public class FileChannelImpl
|
|||
{
|
||||
// Untrusted target: Use a newly-erased buffer
|
||||
int c = Math.min(icount, TRANSFER_SIZE);
|
||||
ByteBuffer bb = Util.getTemporaryDirectBuffer(c);
|
||||
ByteBuffer bb = ByteBuffer.allocate(c);
|
||||
long tw = 0; // Total bytes written
|
||||
long pos = position;
|
||||
try {
|
||||
Util.erase(bb);
|
||||
while (tw < icount) {
|
||||
bb.limit(Math.min((int)(icount - tw), TRANSFER_SIZE));
|
||||
int nr = read(bb, pos);
|
||||
|
@ -649,8 +648,6 @@ public class FileChannelImpl
|
|||
if (tw > 0)
|
||||
return tw;
|
||||
throw x;
|
||||
} finally {
|
||||
Util.releaseTemporaryDirectBuffer(bb);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -734,11 +731,10 @@ public class FileChannelImpl
|
|||
{
|
||||
// Untrusted target: Use a newly-erased buffer
|
||||
int c = (int)Math.min(count, TRANSFER_SIZE);
|
||||
ByteBuffer bb = Util.getTemporaryDirectBuffer(c);
|
||||
ByteBuffer bb = ByteBuffer.allocate(c);
|
||||
long tw = 0; // Total bytes written
|
||||
long pos = position;
|
||||
try {
|
||||
Util.erase(bb);
|
||||
while (tw < count) {
|
||||
bb.limit((int)Math.min((count - tw), (long)TRANSFER_SIZE));
|
||||
// ## Bug: Will block reading src if this channel
|
||||
|
@ -759,8 +755,6 @@ public class FileChannelImpl
|
|||
if (tw > 0)
|
||||
return tw;
|
||||
throw x;
|
||||
} finally {
|
||||
Util.releaseTemporaryDirectBuffer(bb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
############################################################
|
||||
# Default Networking Configuration File
|
||||
# Default Networking Configuration File
|
||||
#
|
||||
# This file may contain default values for the networking system properties.
|
||||
# These values are only used when the system properties are not specified
|
||||
|
@ -110,3 +110,23 @@ jdk.http.auth.tunneling.disabledSchemes=Basic
|
|||
#
|
||||
# jdk.httpclient.allowRestrictedHeaders=host
|
||||
#
|
||||
#
|
||||
# Transparent NTLM HTTP authentication mode on Windows. Transparent authentication
|
||||
# can be used for the NTLM scheme, where the security credentials based on the
|
||||
# currently logged in user's name and password can be obtained directly from the
|
||||
# operating system, without prompting the user. This property has three possible
|
||||
# values which regulate the behavior as shown below. Other unrecognized values
|
||||
# are handled the same as 'disabled'. Note, that NTLM is not considered to be a
|
||||
# strongly secure authentication scheme and care should be taken before enabling
|
||||
# this mechanism.
|
||||
#
|
||||
# Transparent authentication never used.
|
||||
#jdk.http.ntlm.transparentAuth=disabled
|
||||
#
|
||||
# Enabled for all hosts.
|
||||
#jdk.http.ntlm.transparentAuth=allHosts
|
||||
#
|
||||
# Enabled for hosts that are trusted in Windows Internet settings
|
||||
#jdk.http.ntlm.transparentAuth=trustedHosts
|
||||
#
|
||||
jdk.http.ntlm.transparentAuth=disabled
|
||||
|
|
|
@ -93,10 +93,13 @@ public class NTLMAuthentication extends AuthenticationInfo {
|
|||
|
||||
/**
|
||||
* Returns true if the given site is trusted, i.e. we can try
|
||||
* transparent Authentication.
|
||||
* transparent Authentication. Shouldn't be called since
|
||||
* capability not supported on Unix
|
||||
*/
|
||||
public static boolean isTrustedSite(URL url) {
|
||||
return NTLMAuthCallback.isTrustedSite(url);
|
||||
if (NTLMAuthCallback != null)
|
||||
return NTLMAuthCallback.isTrustedSite(url);
|
||||
return false;
|
||||
}
|
||||
|
||||
private void init0() {
|
||||
|
|
|
@ -584,6 +584,8 @@ static void initLoopbackRoutes() {
|
|||
|
||||
if (loRoutesTemp == 0) {
|
||||
free(loRoutes);
|
||||
loRoutes = NULL;
|
||||
nRoutes = 0;
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.UnknownHostException;
|
|||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import sun.net.NetProperties;
|
||||
import sun.net.www.HeaderParser;
|
||||
import sun.net.www.protocol.http.AuthenticationInfo;
|
||||
import sun.net.www.protocol.http.AuthScheme;
|
||||
|
@ -56,11 +57,33 @@ public class NTLMAuthentication extends AuthenticationInfo {
|
|||
private static final String defaultDomain;
|
||||
/* Whether cache is enabled for NTLM */
|
||||
private static final boolean ntlmCache;
|
||||
|
||||
enum TransparentAuth {
|
||||
DISABLED, // disable for all hosts (default)
|
||||
TRUSTED_HOSTS, // use Windows trusted hosts settings
|
||||
ALL_HOSTS // attempt for all hosts
|
||||
}
|
||||
|
||||
private static final TransparentAuth authMode;
|
||||
|
||||
static {
|
||||
Properties props = GetPropertyAction.privilegedGetProperties();
|
||||
defaultDomain = props.getProperty("http.auth.ntlm.domain", "domain");
|
||||
String ntlmCacheProp = props.getProperty("jdk.ntlm.cache", "true");
|
||||
ntlmCache = Boolean.parseBoolean(ntlmCacheProp);
|
||||
String modeProp = java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return NetProperties.get("jdk.http.ntlm.transparentAuth");
|
||||
}
|
||||
});
|
||||
|
||||
if ("trustedHosts".equalsIgnoreCase(modeProp))
|
||||
authMode = TransparentAuth.TRUSTED_HOSTS;
|
||||
else if ("allHosts".equalsIgnoreCase(modeProp))
|
||||
authMode = TransparentAuth.ALL_HOSTS;
|
||||
else
|
||||
authMode = TransparentAuth.DISABLED;
|
||||
}
|
||||
|
||||
private void init0() {
|
||||
|
@ -166,9 +189,21 @@ public class NTLMAuthentication extends AuthenticationInfo {
|
|||
* transparent Authentication.
|
||||
*/
|
||||
public static boolean isTrustedSite(URL url) {
|
||||
return NTLMAuthCallback.isTrustedSite(url);
|
||||
if (NTLMAuthCallback != null)
|
||||
return NTLMAuthCallback.isTrustedSite(url);
|
||||
|
||||
switch (authMode) {
|
||||
case TRUSTED_HOSTS:
|
||||
return isTrustedSite(url.toString());
|
||||
case ALL_HOSTS:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static native boolean isTrustedSite(String url);
|
||||
|
||||
/**
|
||||
* Not supported. Must use the setHeaders() method
|
||||
*/
|
||||
|
@ -218,5 +253,4 @@ public class NTLMAuthentication extends AuthenticationInfo {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
106
src/java.base/windows/native/libnet/NTLMAuthentication.c
Normal file
106
src/java.base/windows/native/libnet/NTLMAuthentication.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (c) 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <windows.h>
|
||||
#include "jni_util.h"
|
||||
#include <urlmon.h>
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthentication_isTrustedSite(JNIEnv *env, jclass clazz, jstring url )
|
||||
{
|
||||
|
||||
HRESULT hr;
|
||||
DWORD dwZone;
|
||||
DWORD pPolicy = 0;
|
||||
IInternetSecurityManager *spSecurityManager;
|
||||
jboolean ret;
|
||||
|
||||
// Create IInternetSecurityManager
|
||||
hr = CoInternetCreateSecurityManager(NULL, &spSecurityManager, (DWORD)0);
|
||||
if (FAILED(hr)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
const LPCWSTR bstrURL = (LPCWSTR)((*env)->GetStringChars(env, url, NULL));
|
||||
if (bstrURL == NULL) {
|
||||
if (!(*env)->ExceptionCheck(env))
|
||||
JNU_ThrowOutOfMemoryError(env, NULL);
|
||||
spSecurityManager->lpVtbl->Release(spSecurityManager);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Determines the policy for the URLACTION_CREDENTIALS_USE action and display
|
||||
// a user interface, if the policy indicates that the user should be queried
|
||||
hr = spSecurityManager->lpVtbl->ProcessUrlAction(
|
||||
spSecurityManager,
|
||||
bstrURL,
|
||||
URLACTION_CREDENTIALS_USE,
|
||||
(LPBYTE)&pPolicy,
|
||||
sizeof(DWORD), 0, 0, 0, 0);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
ret = JNI_FALSE;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
// If these two User Authentication Logon options is selected
|
||||
// Anonymous logon
|
||||
// Prompt for user name and password
|
||||
if (pPolicy == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY ||
|
||||
pPolicy == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER) {
|
||||
ret = JNI_FALSE;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
// Option "Automatic logon with current user name and password" is selected
|
||||
if (pPolicy == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK) {
|
||||
ret = JNI_TRUE;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
// Option "Automatic logon only in intranet zone" is selected
|
||||
if (pPolicy == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT) {
|
||||
|
||||
// Gets the zone index from the specified URL
|
||||
hr = spSecurityManager->lpVtbl->MapUrlToZone(
|
||||
spSecurityManager, bstrURL, &dwZone, 0);
|
||||
if (FAILED(hr)) {
|
||||
ret = JNI_FALSE;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
// Check if the URL is in Local or Intranet zone
|
||||
if (dwZone == URLZONE_INTRANET || dwZone == URLZONE_LOCAL_MACHINE) {
|
||||
ret = JNI_TRUE;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
}
|
||||
ret = JNI_FALSE;
|
||||
|
||||
cleanupAndReturn:
|
||||
(*env)->ReleaseStringChars(env, url, bstrURL);
|
||||
spSecurityManager->lpVtbl->Release(spSecurityManager);
|
||||
return ret;
|
||||
}
|
|
@ -273,7 +273,7 @@ int enumInterfaces(JNIEnv *env, netif **netifPP)
|
|||
// But in rare case it fails, we allow 'char' to be displayed
|
||||
curr->displayName = (char *)malloc(ifrowP->dwDescrLen + 1);
|
||||
} else {
|
||||
curr->displayName = (wchar_t *)malloc(wlen*(sizeof(wchar_t))+1);
|
||||
curr->displayName = (wchar_t *)malloc((wlen+1)*sizeof(wchar_t));
|
||||
}
|
||||
|
||||
curr->name = (char *)malloc(strlen(dev_name) + 1);
|
||||
|
@ -316,7 +316,7 @@ int enumInterfaces(JNIEnv *env, netif **netifPP)
|
|||
free(curr);
|
||||
return -1;
|
||||
} else {
|
||||
curr->displayName[wlen*(sizeof(wchar_t))] = '\0';
|
||||
((wchar_t *)curr->displayName)[wlen] = L'\0';
|
||||
curr->dNameIsUnicode = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 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
|
||||
|
@ -95,6 +95,10 @@ Java_sun_nio_ch_DatagramDispatcher_readv0(JNIEnv *env, jclass clazz,
|
|||
jint fd = fdval(env, fdo);
|
||||
struct iovec *iovp = (struct iovec *)address;
|
||||
WSABUF *bufs = malloc(len * sizeof(WSABUF));
|
||||
if (bufs == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, NULL);
|
||||
return IOS_THROWN;
|
||||
}
|
||||
|
||||
/* copy iovec into WSABUF */
|
||||
for(i=0; i<len; i++) {
|
||||
|
@ -182,6 +186,10 @@ Java_sun_nio_ch_DatagramDispatcher_writev0(JNIEnv *env, jclass clazz,
|
|||
jint fd = fdval(env, fdo);
|
||||
struct iovec *iovp = (struct iovec *)address;
|
||||
WSABUF *bufs = malloc(len * sizeof(WSABUF));
|
||||
if (bufs == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, NULL);
|
||||
return IOS_THROWN;
|
||||
}
|
||||
|
||||
/* copy iovec into WSABUF */
|
||||
for(i=0; i<len; i++) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 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
|
||||
|
@ -219,6 +219,10 @@ Java_sun_nio_ch_WindowsSelectorImpl_resetWakeupSocket0(JNIEnv *env, jclass this,
|
|||
/* Prepare corresponding buffer if needed, and then read */
|
||||
if (bytesToRead > WAKEUP_SOCKET_BUF_SIZE) {
|
||||
char* buf = (char*)malloc(bytesToRead);
|
||||
if (buf == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, NULL);
|
||||
return;
|
||||
}
|
||||
recv(scinFd, buf, bytesToRead, 0);
|
||||
free(buf);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue