Skip to content

Commit 3be3d66

Browse files
authored
Merge pull request #176 from pshipton/0.36rc1
Merge jdk-17.0.6+10 to 0.36
2 parents 2842f5c + 8eeae1f commit 3be3d66

File tree

26 files changed

+290
-218
lines changed

26 files changed

+290
-218
lines changed

closed/openjdk-tag.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
OPENJDK_TAG := jdk-17.0.6+9
1+
OPENJDK_TAG := jdk-17.0.6+10

make/conf/version-numbers.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ DEFAULT_VERSION_CLASSFILE_MINOR=0
3939
DEFAULT_VERSION_DOCS_API_SINCE=11
4040
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="16 17"
4141
DEFAULT_JDK_SOURCE_TARGET_VERSION=17
42-
DEFAULT_PROMOTED_VERSION_PRE=ea
42+
DEFAULT_PROMOTED_VERSION_PRE=

make/data/currency/CurrencyData.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ formatVersion=3
3232
# Version of the currency code information in this class.
3333
# It is a serial number that accompanies with each amendment.
3434

35-
dataVersion=173
35+
dataVersion=174
3636

3737
# List of all valid ISO 4217 currency codes.
3838
# To ensure compatibility, do not remove codes.
@@ -189,7 +189,7 @@ CR=CRC
189189
# COTE D'IVOIRE
190190
CI=XOF
191191
# CROATIA
192-
HR=HRK
192+
HR=HRK;2022-12-31-23-00-00;EUR
193193
# CUBA
194194
CU=CUP
195195
# Cura\u00e7ao

src/java.base/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import sun.security.provider.ParameterCache;
3636
import static sun.security.util.SecurityProviderConstants.DEF_DH_KEY_SIZE;
37+
import static sun.security.util.SecurityProviderConstants.getDefDHPrivateExpSize;
3738

3839
/**
3940
* This class represents the key pair generator for Diffie-Hellman key pairs.
@@ -60,9 +61,6 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi {
6061
// The size in bits of the prime modulus
6162
private int pSize;
6263

63-
// The size in bits of the random exponent (private value)
64-
private int lSize;
65-
6664
// The source of randomness
6765
private SecureRandom random;
6866

@@ -71,7 +69,8 @@ public DHKeyPairGenerator() {
7169
initialize(DEF_DH_KEY_SIZE, null);
7270
}
7371

74-
private static void checkKeySize(int keysize)
72+
// pkg private; used by DHParameterGenerator class as well
73+
static void checkKeySize(int keysize, int expSize)
7574
throws InvalidParameterException {
7675

7776
if ((keysize < 512) || (keysize > 8192) || ((keysize & 0x3F) != 0)) {
@@ -80,6 +79,13 @@ private static void checkKeySize(int keysize)
8079
"from 512 to 8192 (inclusive). " +
8180
"The specific key size " + keysize + " is not supported");
8281
}
82+
83+
// optional, could be 0 if not specified
84+
if ((expSize < 0) || (expSize > keysize)) {
85+
throw new InvalidParameterException
86+
("Exponent size must be positive and no larger than" +
87+
" modulus size");
88+
}
8389
}
8490

8591
/**
@@ -91,21 +97,17 @@ private static void checkKeySize(int keysize)
9197
* @param random the source of randomness
9298
*/
9399
public void initialize(int keysize, SecureRandom random) {
94-
checkKeySize(keysize);
100+
checkKeySize(keysize, 0);
95101

96-
// Use the built-in parameters (ranging from 512 to 8192)
97-
// when available.
98-
this.params = ParameterCache.getCachedDHParameterSpec(keysize);
99-
100-
// Due to performance issue, only support DH parameters generation
101-
// up to 1024 bits.
102-
if ((this.params == null) && (keysize > 1024)) {
103-
throw new InvalidParameterException(
104-
"Unsupported " + keysize + "-bit DH parameter generation");
102+
try {
103+
// Use the built-in parameters (ranging from 512 to 8192)
104+
// when available.
105+
this.params = ParameterCache.getDHParameterSpec(keysize, random);
106+
} catch (GeneralSecurityException e) {
107+
throw new InvalidParameterException(e.getMessage());
105108
}
106109

107110
this.pSize = keysize;
108-
this.lSize = 0;
109111
this.random = random;
110112
}
111113

@@ -130,22 +132,13 @@ public void initialize(AlgorithmParameterSpec algParams,
130132
("Inappropriate parameter type");
131133
}
132134

133-
params = (DHParameterSpec)algParams;
135+
params = (DHParameterSpec) algParams;
134136
pSize = params.getP().bitLength();
135137
try {
136-
checkKeySize(pSize);
138+
checkKeySize(pSize, params.getL());
137139
} catch (InvalidParameterException ipe) {
138140
throw new InvalidAlgorithmParameterException(ipe.getMessage());
139141
}
140-
141-
// exponent size is optional, could be 0
142-
lSize = params.getL();
143-
144-
// Require exponentSize < primeSize
145-
if ((lSize != 0) && (lSize > pSize)) {
146-
throw new InvalidAlgorithmParameterException
147-
("Exponent size must not be larger than modulus size");
148-
}
149142
this.random = random;
150143
}
151144

@@ -159,24 +152,12 @@ public KeyPair generateKeyPair() {
159152
random = SunJCE.getRandom();
160153
}
161154

162-
if (params == null) {
163-
try {
164-
params = ParameterCache.getDHParameterSpec(pSize, random);
165-
} catch (GeneralSecurityException e) {
166-
// should never happen
167-
throw new ProviderException(e);
168-
}
169-
}
170-
171155
BigInteger p = params.getP();
172156
BigInteger g = params.getG();
173157

174-
if (lSize <= 0) {
175-
lSize = pSize >> 1;
176-
// use an exponent size of (pSize / 2) but at least 384 bits
177-
if (lSize < 384) {
178-
lSize = 384;
179-
}
158+
int lSize = params.getL();
159+
if (lSize == 0) { // not specified; use our own default
160+
lSize = getDefDHPrivateExpSize(params);
180161
}
181162

182163
BigInteger x;

src/java.base/share/classes/com/sun/crypto/provider/DHParameterGenerator.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,17 +59,21 @@ public final class DHParameterGenerator extends AlgorithmParameterGeneratorSpi {
5959
// The source of randomness
6060
private SecureRandom random = null;
6161

62-
private static void checkKeySize(int keysize)
62+
private static void checkSupport(int keysize, int exponentSize)
6363
throws InvalidParameterException {
6464

6565
boolean supported = ((keysize == 2048) || (keysize == 3072) ||
6666
((keysize >= 512) && (keysize <= 1024) && ((keysize & 0x3F) == 0)));
6767

6868
if (!supported) {
6969
throw new InvalidParameterException(
70-
"DH key size must be multiple of 64 and range " +
70+
"Supported DH key size must be multiple of 64 and range " +
7171
"from 512 to 1024 (inclusive), or 2048, 3072. " +
72-
"The specific key size " + keysize + " is not supported");
72+
"The specified key size " + keysize + " is not supported");
73+
}
74+
75+
if (exponentSize != 0) {
76+
DHKeyPairGenerator.checkKeySize(keysize, exponentSize);
7377
}
7478
}
7579

@@ -83,7 +87,8 @@ private static void checkKeySize(int keysize)
8387
*/
8488
@Override
8589
protected void engineInit(int keysize, SecureRandom random) {
86-
checkKeySize(keysize);
90+
checkSupport(keysize, 0);
91+
8792
this.primeSize = keysize;
8893
this.random = random;
8994
}
@@ -108,21 +113,17 @@ protected void engineInit(AlgorithmParameterSpec genParamSpec,
108113
("Inappropriate parameter type");
109114
}
110115

111-
DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
112-
primeSize = dhParamSpec.getPrimeSize();
113-
exponentSize = dhParamSpec.getExponentSize();
114-
if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
115-
throw new InvalidAlgorithmParameterException(
116-
"Exponent size (" + exponentSize +
117-
") must be positive and less than modulus size (" +
118-
primeSize + ")");
119-
}
116+
DHGenParameterSpec dhParamSpec = (DHGenParameterSpec) genParamSpec;
117+
int primeSize = dhParamSpec.getPrimeSize();
118+
int exponentSize = dhParamSpec.getExponentSize();
120119
try {
121-
checkKeySize(primeSize);
120+
checkSupport(primeSize, exponentSize);
122121
} catch (InvalidParameterException ipe) {
123122
throw new InvalidAlgorithmParameterException(ipe.getMessage());
124123
}
125124

125+
this.primeSize = primeSize;
126+
this.exponentSize = exponentSize;
126127
this.random = random;
127128
}
128129

src/java.base/share/classes/java/net/InetAddress.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,10 @@ private static InetAddress[] getAllByName(String host, InetAddress reqAddr)
13601360
InetAddress[] ret = new InetAddress[1];
13611361
if(addr != null) {
13621362
if (addr.length == Inet4Address.INADDRSZ) {
1363+
if (numericZone != -1 || ifname != null) {
1364+
// IPv4-mapped address must not contain zone-id
1365+
throw new UnknownHostException(host + ": invalid IPv4-mapped address");
1366+
}
13631367
ret[0] = new Inet4Address(null, addr);
13641368
} else {
13651369
if (ifname != null) {
@@ -1404,22 +1408,23 @@ private static int checkNumericZone (String s) throws UnknownHostException {
14041408
int percent = s.indexOf ('%');
14051409
int slen = s.length();
14061410
int digit, zone=0;
1411+
int multmax = Integer.MAX_VALUE / 10; // for int overflow detection
14071412
if (percent == -1) {
14081413
return -1;
14091414
}
14101415
for (int i=percent+1; i<slen; i++) {
14111416
char c = s.charAt(i);
1412-
if (c == ']') {
1413-
if (i == percent+1) {
1414-
/* empty per-cent field */
1415-
return -1;
1416-
}
1417-
break;
1417+
if ((digit = IPAddressUtil.parseAsciiDigit(c, 10)) < 0) {
1418+
return -1;
14181419
}
1419-
if ((digit = Character.digit (c, 10)) < 0) {
1420+
if (zone > multmax) {
14201421
return -1;
14211422
}
14221423
zone = (zone * 10) + digit;
1424+
if (zone < 0) {
1425+
return -1;
1426+
}
1427+
14231428
}
14241429
return zone;
14251430
}

src/java.base/share/classes/sun/net/util/IPAddressUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ private static boolean isHexFieldStart(CharBuffer cb) {
785785
}
786786

787787
// Parse ASCII digit in given radix
788-
private static int parseAsciiDigit(char c, int radix) {
788+
public static int parseAsciiDigit(char c, int radix) {
789789
assert radix == OCTAL || radix == DECIMAL || radix == HEXADECIMAL;
790790
if (radix == HEXADECIMAL) {
791791
return parseAsciiHexDigit(c);

src/java.base/share/classes/sun/security/provider/ParameterCache.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.security.spec.*;
3535

3636
import javax.crypto.spec.DHParameterSpec;
37+
import sun.security.util.SafeDHParameterSpec;
3738

3839
/**
3940
* Cache for DSA and DH parameter specs. Used by the KeyPairGenerators
@@ -55,6 +56,26 @@ private ParameterCache() {
5556
// cache of DH parameters
5657
private static final Map<Integer,DHParameterSpec> dhCache;
5758

59+
// convert DHParameterSpec to SafeDHParameterSpec if its parameters are
60+
// safe primes; validation takes time but should be worthwhile for the
61+
// parameter cache since the parameters may be reused many times.
62+
private static DHParameterSpec makeSafe(DHParameterSpec spec) {
63+
if (spec instanceof SafeDHParameterSpec) {
64+
return spec;
65+
}
66+
67+
BigInteger p = spec.getP();
68+
BigInteger g = spec.getG();
69+
70+
boolean isSafe = (g.equals(BigInteger.TWO) && p.testBit(0) &&
71+
p.shiftRight(1).isProbablePrime(100));
72+
if (isSafe) {
73+
return new SafeDHParameterSpec(p, g, spec.getL());
74+
} else {
75+
return spec;
76+
}
77+
}
78+
5879
/**
5980
* Return cached DSA parameters for the given length combination of
6081
* prime and subprime, or null if none are available in the cache.
@@ -74,7 +95,7 @@ public static DSAParameterSpec getCachedDSAParameterSpec(int primeLen,
7495
* are available in the cache.
7596
*/
7697
public static DHParameterSpec getCachedDHParameterSpec(int keyLength) {
77-
return dhCache.get(Integer.valueOf(keyLength));
98+
return dhCache.get(keyLength);
7899
}
79100

80101
/**
@@ -132,7 +153,7 @@ public static DHParameterSpec getDHParameterSpec(int keyLength,
132153
gen.init(keyLength, random);
133154
AlgorithmParameters params = gen.generateParameters();
134155
spec = params.getParameterSpec(DHParameterSpec.class);
135-
dhCache.put(Integer.valueOf(keyLength), spec);
156+
dhCache.put(keyLength, makeSafe(spec));
136157
return spec;
137158
}
138159

@@ -394,6 +415,12 @@ public static DSAParameterSpec getNewDSAParameterSpec(int primeLen,
394415
// the common generator
395416
BigInteger dhG = BigInteger.TWO;
396417

418+
// Self generated following the approach from RFC 2412 Appendix E but
419+
// using random source instead of binary expansion of pi
420+
BigInteger dhP512 = new BigInteger(
421+
"FFFFFFFFFFFFFFFF8B479B3A6E8DE86C294188F0BF2CD86C" +
422+
"DB950ADB36D0F61FD51E46F69C99ED95ABE5A7BBB230A6ED" +
423+
"1D0B4506B5317284FFFFFFFFFFFFFFFF", 16);
397424
//
398425
// From RFC 7296
399426

@@ -562,16 +589,18 @@ public static DSAParameterSpec getNewDSAParameterSpec(int primeLen,
562589
"9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71" +
563590
"60C980DD98EDD3DFFFFFFFFFFFFFFFFF", 16);
564591

565-
// use DSA parameters for DH for sizes not defined in RFC 7296, 3526
566-
dhCache.put(Integer.valueOf(512), new DHParameterSpec(p512, g512));
567-
568-
dhCache.put(Integer.valueOf(768), new DHParameterSpec(dhP768, dhG));
569-
dhCache.put(Integer.valueOf(1024), new DHParameterSpec(dhP1024, dhG));
570-
dhCache.put(Integer.valueOf(1536), new DHParameterSpec(dhP1536, dhG));
571-
dhCache.put(Integer.valueOf(2048), new DHParameterSpec(dhP2048, dhG));
572-
dhCache.put(Integer.valueOf(3072), new DHParameterSpec(dhP3072, dhG));
573-
dhCache.put(Integer.valueOf(4096), new DHParameterSpec(dhP4096, dhG));
574-
dhCache.put(Integer.valueOf(6144), new DHParameterSpec(dhP6144, dhG));
575-
dhCache.put(Integer.valueOf(8192), new DHParameterSpec(dhP8192, dhG));
592+
// self-generated safe prime
593+
dhCache.put(512, new SafeDHParameterSpec(dhP512, dhG));
594+
595+
// from RFC 7296
596+
dhCache.put(768, new SafeDHParameterSpec(dhP768, dhG));
597+
dhCache.put(1024, new SafeDHParameterSpec(dhP1024, dhG));
598+
// from RFC 3526
599+
dhCache.put(1536, new SafeDHParameterSpec(dhP1536, dhG));
600+
dhCache.put(2048, new SafeDHParameterSpec(dhP2048, dhG));
601+
dhCache.put(3072, new SafeDHParameterSpec(dhP3072, dhG));
602+
dhCache.put(4096, new SafeDHParameterSpec(dhP4096, dhG));
603+
dhCache.put(6144, new SafeDHParameterSpec(dhP6144, dhG));
604+
dhCache.put(8192, new SafeDHParameterSpec(dhP8192, dhG));
576605
}
577606
}

0 commit comments

Comments
 (0)