mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-15 05:49:40 +01:00
Compare commits
8 Commits
jdk-21-ga
...
jdk-17.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
040f1053aa | ||
|
|
b24dff5fef | ||
|
|
87b5f1bd82 | ||
|
|
0102000658 | ||
|
|
8f31f0d343 | ||
|
|
4b289d6ab5 | ||
|
|
80dd63d0d7 | ||
|
|
3888c76ac3 |
@@ -28,12 +28,12 @@
|
|||||||
|
|
||||||
DEFAULT_VERSION_FEATURE=17
|
DEFAULT_VERSION_FEATURE=17
|
||||||
DEFAULT_VERSION_INTERIM=0
|
DEFAULT_VERSION_INTERIM=0
|
||||||
DEFAULT_VERSION_UPDATE=0
|
DEFAULT_VERSION_UPDATE=1
|
||||||
DEFAULT_VERSION_PATCH=0
|
DEFAULT_VERSION_PATCH=0
|
||||||
DEFAULT_VERSION_EXTRA1=0
|
DEFAULT_VERSION_EXTRA1=0
|
||||||
DEFAULT_VERSION_EXTRA2=0
|
DEFAULT_VERSION_EXTRA2=0
|
||||||
DEFAULT_VERSION_EXTRA3=0
|
DEFAULT_VERSION_EXTRA3=0
|
||||||
DEFAULT_VERSION_DATE=2021-09-14
|
DEFAULT_VERSION_DATE=2021-10-19
|
||||||
DEFAULT_VERSION_CLASSFILE_MAJOR=61 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
|
DEFAULT_VERSION_CLASSFILE_MAJOR=61 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
|
||||||
DEFAULT_VERSION_CLASSFILE_MINOR=0
|
DEFAULT_VERSION_CLASSFILE_MINOR=0
|
||||||
DEFAULT_VERSION_DOCS_API_SINCE=11
|
DEFAULT_VERSION_DOCS_API_SINCE=11
|
||||||
|
|||||||
@@ -427,6 +427,11 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
|
|||||||
return defineClass(name, res);
|
return defineClass(name, res);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ClassNotFoundException(name, e);
|
throw new ClassNotFoundException(name, e);
|
||||||
|
} catch (ClassFormatError e2) {
|
||||||
|
if (res.getDataError() != null) {
|
||||||
|
e2.addSuppressed(res.getDataError());
|
||||||
|
}
|
||||||
|
throw e2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -27,6 +27,7 @@ package java.util;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InvalidObjectException;
|
import java.io.InvalidObjectException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@@ -1504,23 +1505,28 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||||||
* @throws IOException if an I/O error occurs
|
* @throws IOException if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
@java.io.Serial
|
@java.io.Serial
|
||||||
private void readObject(java.io.ObjectInputStream s)
|
private void readObject(ObjectInputStream s)
|
||||||
throws IOException, ClassNotFoundException {
|
throws IOException, ClassNotFoundException {
|
||||||
// Read in the threshold (ignored), loadfactor, and any hidden stuff
|
|
||||||
s.defaultReadObject();
|
ObjectInputStream.GetField fields = s.readFields();
|
||||||
|
|
||||||
|
// Read loadFactor (ignore threshold)
|
||||||
|
float lf = fields.get("loadFactor", 0.75f);
|
||||||
|
if (lf <= 0 || Float.isNaN(lf))
|
||||||
|
throw new InvalidObjectException("Illegal load factor: " + lf);
|
||||||
|
|
||||||
|
lf = Math.min(Math.max(0.25f, lf), 4.0f);
|
||||||
|
HashMap.UnsafeHolder.putLoadFactor(this, lf);
|
||||||
|
|
||||||
reinitialize();
|
reinitialize();
|
||||||
if (loadFactor <= 0 || Float.isNaN(loadFactor))
|
|
||||||
throw new InvalidObjectException("Illegal load factor: " +
|
|
||||||
loadFactor);
|
|
||||||
s.readInt(); // Read and ignore number of buckets
|
s.readInt(); // Read and ignore number of buckets
|
||||||
int mappings = s.readInt(); // Read number of mappings (size)
|
int mappings = s.readInt(); // Read number of mappings (size)
|
||||||
if (mappings < 0)
|
if (mappings < 0) {
|
||||||
throw new InvalidObjectException("Illegal mappings count: " +
|
throw new InvalidObjectException("Illegal mappings count: " + mappings);
|
||||||
mappings);
|
} else if (mappings == 0) {
|
||||||
else if (mappings > 0) { // (if zero, use defaults)
|
// use defaults
|
||||||
// Size the table using given load factor only if within
|
} else if (mappings > 0) {
|
||||||
// range of 0.25...4.0
|
|
||||||
float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);
|
|
||||||
float fc = (float)mappings / lf + 1.0f;
|
float fc = (float)mappings / lf + 1.0f;
|
||||||
int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ?
|
int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ?
|
||||||
DEFAULT_INITIAL_CAPACITY :
|
DEFAULT_INITIAL_CAPACITY :
|
||||||
@@ -1549,6 +1555,18 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support for resetting final field during deserializing
|
||||||
|
private static final class UnsafeHolder {
|
||||||
|
private UnsafeHolder() { throw new InternalError(); }
|
||||||
|
private static final jdk.internal.misc.Unsafe unsafe
|
||||||
|
= jdk.internal.misc.Unsafe.getUnsafe();
|
||||||
|
private static final long LF_OFFSET
|
||||||
|
= unsafe.objectFieldOffset(HashMap.class, "loadFactor");
|
||||||
|
static void putLoadFactor(HashMap<?, ?> map, float lf) {
|
||||||
|
unsafe.putFloat(map, LF_OFFSET, lf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
// iterators
|
// iterators
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -297,8 +297,8 @@ public class HashSet<E>
|
|||||||
@java.io.Serial
|
@java.io.Serial
|
||||||
private void readObject(java.io.ObjectInputStream s)
|
private void readObject(java.io.ObjectInputStream s)
|
||||||
throws java.io.IOException, ClassNotFoundException {
|
throws java.io.IOException, ClassNotFoundException {
|
||||||
// Read in any hidden serialization magic
|
// Consume and ignore stream fields (currently zero).
|
||||||
s.defaultReadObject();
|
s.readFields();
|
||||||
|
|
||||||
// Read capacity and verify non-negative.
|
// Read capacity and verify non-negative.
|
||||||
int capacity = s.readInt();
|
int capacity = s.readInt();
|
||||||
@@ -313,12 +313,13 @@ public class HashSet<E>
|
|||||||
throw new InvalidObjectException("Illegal load factor: " +
|
throw new InvalidObjectException("Illegal load factor: " +
|
||||||
loadFactor);
|
loadFactor);
|
||||||
}
|
}
|
||||||
|
// Clamp load factor to range of 0.25...4.0.
|
||||||
|
loadFactor = Math.min(Math.max(0.25f, loadFactor), 4.0f);
|
||||||
|
|
||||||
// Read size and verify non-negative.
|
// Read size and verify non-negative.
|
||||||
int size = s.readInt();
|
int size = s.readInt();
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
throw new InvalidObjectException("Illegal size: " +
|
throw new InvalidObjectException("Illegal size: " + size);
|
||||||
size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the capacity according to the size and load factor ensuring that
|
// Set the capacity according to the size and load factor ensuring that
|
||||||
|
|||||||
@@ -187,4 +187,12 @@ public abstract class Resource {
|
|||||||
public CodeSigner[] getCodeSigners() {
|
public CodeSigner[] getCodeSigners() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns non-fatal reading error during data retrieval if there's any.
|
||||||
|
* For example, CRC error when reading a JAR entry.
|
||||||
|
*/
|
||||||
|
public Exception getDataError() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ import java.util.Properties;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
@@ -870,6 +871,7 @@ public class URLClassPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Resource() {
|
return new Resource() {
|
||||||
|
private Exception dataError = null;
|
||||||
public String getName() { return name; }
|
public String getName() { return name; }
|
||||||
public URL getURL() { return url; }
|
public URL getURL() { return url; }
|
||||||
public URL getCodeSourceURL() { return csu; }
|
public URL getCodeSourceURL() { return csu; }
|
||||||
@@ -885,6 +887,18 @@ public class URLClassPath {
|
|||||||
{ return entry.getCertificates(); };
|
{ return entry.getCertificates(); };
|
||||||
public CodeSigner[] getCodeSigners()
|
public CodeSigner[] getCodeSigners()
|
||||||
{ return entry.getCodeSigners(); };
|
{ return entry.getCodeSigners(); };
|
||||||
|
public Exception getDataError()
|
||||||
|
{ return dataError; }
|
||||||
|
public byte[] getBytes() throws IOException {
|
||||||
|
byte[] bytes = super.getBytes();
|
||||||
|
CRC32 crc32 = new CRC32();
|
||||||
|
crc32.update(bytes);
|
||||||
|
if (crc32.getValue() != entry.getCrc()) {
|
||||||
|
dataError = new IOException(
|
||||||
|
"CRC error while extracting entry from JAR file");
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ package sun.security.ssl;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.security.CryptoPrimitive;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.interfaces.ECPublicKey;
|
import java.security.interfaces.ECPublicKey;
|
||||||
@@ -35,6 +36,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||||||
import java.security.spec.ECParameterSpec;
|
import java.security.spec.ECParameterSpec;
|
||||||
import java.security.spec.NamedParameterSpec;
|
import java.security.spec.NamedParameterSpec;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import sun.security.ssl.SSLHandshake.HandshakeMessage;
|
import sun.security.ssl.SSLHandshake.HandshakeMessage;
|
||||||
@@ -317,12 +319,19 @@ final class ECDHClientKeyExchange {
|
|||||||
|
|
||||||
// create the credentials
|
// create the credentials
|
||||||
try {
|
try {
|
||||||
NamedGroup ng = namedGroup; // "effectively final" the lambda
|
SSLCredentials sslCredentials =
|
||||||
// AlgorithmConstraints are checked internally.
|
namedGroup.decodeCredentials(cke.encodedPoint);
|
||||||
SSLCredentials sslCredentials = namedGroup.decodeCredentials(
|
if (shc.algorithmConstraints != null &&
|
||||||
cke.encodedPoint, shc.algorithmConstraints,
|
sslCredentials instanceof
|
||||||
s -> shc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
NamedGroupCredentials namedGroupCredentials) {
|
||||||
"ClientKeyExchange " + ng + ": " + s));
|
if (!shc.algorithmConstraints.permits(
|
||||||
|
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
|
||||||
|
namedGroupCredentials.getPublicKey())) {
|
||||||
|
shc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
||||||
|
"ClientKeyExchange for " + namedGroup +
|
||||||
|
" does not comply with algorithm constraints");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shc.handshakeCredentials.add(sslCredentials);
|
shc.handshakeCredentials.add(sslCredentials);
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
@@ -497,12 +506,19 @@ final class ECDHClientKeyExchange {
|
|||||||
|
|
||||||
// create the credentials
|
// create the credentials
|
||||||
try {
|
try {
|
||||||
NamedGroup ng = namedGroup; // "effectively final" the lambda
|
SSLCredentials sslCredentials =
|
||||||
// AlgorithmConstraints are checked internally.
|
namedGroup.decodeCredentials(cke.encodedPoint);
|
||||||
SSLCredentials sslCredentials = namedGroup.decodeCredentials(
|
if (shc.algorithmConstraints != null &&
|
||||||
cke.encodedPoint, shc.algorithmConstraints,
|
sslCredentials instanceof
|
||||||
s -> shc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
NamedGroupCredentials namedGroupCredentials) {
|
||||||
"ClientKeyExchange " + ng + ": " + s));
|
if (!shc.algorithmConstraints.permits(
|
||||||
|
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
|
||||||
|
namedGroupCredentials.getPublicKey())) {
|
||||||
|
shc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
||||||
|
"ClientKeyExchange for " + namedGroup +
|
||||||
|
" does not comply with algorithm constraints");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shc.handshakeCredentials.add(sslCredentials);
|
shc.handshakeCredentials.add(sslCredentials);
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ package sun.security.ssl;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.security.CryptoPrimitive;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
@@ -37,6 +38,7 @@ import java.security.PublicKey;
|
|||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import sun.security.ssl.SSLHandshake.HandshakeMessage;
|
import sun.security.ssl.SSLHandshake.HandshakeMessage;
|
||||||
@@ -214,10 +216,19 @@ final class ECDHServerKeyExchange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sslCredentials = namedGroup.decodeCredentials(
|
sslCredentials =
|
||||||
publicPoint, handshakeContext.algorithmConstraints,
|
namedGroup.decodeCredentials(publicPoint);
|
||||||
s -> chc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
if (handshakeContext.algorithmConstraints != null &&
|
||||||
"ServerKeyExchange " + namedGroup + ": " + (s)));
|
sslCredentials instanceof
|
||||||
|
NamedGroupCredentials namedGroupCredentials) {
|
||||||
|
if (!handshakeContext.algorithmConstraints.permits(
|
||||||
|
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
|
||||||
|
namedGroupCredentials.getPublicKey())) {
|
||||||
|
chc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
||||||
|
"ServerKeyExchange for " + namedGroup +
|
||||||
|
" does not comply with algorithm constraints");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (GeneralSecurityException ex) {
|
} catch (GeneralSecurityException ex) {
|
||||||
throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
|
throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
|
||||||
"Cannot decode named group: " +
|
"Cannot decode named group: " +
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ package sun.security.ssl;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.security.CryptoPrimitive;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -349,7 +350,8 @@ final class KeyShareExtension {
|
|||||||
NamedGroup ng = NamedGroup.valueOf(entry.namedGroupId);
|
NamedGroup ng = NamedGroup.valueOf(entry.namedGroupId);
|
||||||
if (ng == null || !SupportedGroups.isActivatable(
|
if (ng == null || !SupportedGroups.isActivatable(
|
||||||
shc.algorithmConstraints, ng)) {
|
shc.algorithmConstraints, ng)) {
|
||||||
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
|
if (SSLLogger.isOn &&
|
||||||
|
SSLLogger.isOn("ssl,handshake")) {
|
||||||
SSLLogger.fine(
|
SSLLogger.fine(
|
||||||
"Ignore unsupported named group: " +
|
"Ignore unsupported named group: " +
|
||||||
NamedGroup.nameOf(entry.namedGroupId));
|
NamedGroup.nameOf(entry.namedGroupId));
|
||||||
@@ -359,18 +361,35 @@ final class KeyShareExtension {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
SSLCredentials kaCred =
|
SSLCredentials kaCred =
|
||||||
ng.decodeCredentials(entry.keyExchange,
|
ng.decodeCredentials(entry.keyExchange);
|
||||||
shc.algorithmConstraints,
|
if (shc.algorithmConstraints != null &&
|
||||||
s -> SSLLogger.warning(s));
|
kaCred instanceof
|
||||||
|
NamedGroupCredentials namedGroupCredentials) {
|
||||||
|
if (!shc.algorithmConstraints.permits(
|
||||||
|
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
|
||||||
|
namedGroupCredentials.getPublicKey())) {
|
||||||
|
if (SSLLogger.isOn &&
|
||||||
|
SSLLogger.isOn("ssl,handshake")) {
|
||||||
|
SSLLogger.warning(
|
||||||
|
"key share entry of " + ng + " does not " +
|
||||||
|
" comply with algorithm constraints");
|
||||||
|
}
|
||||||
|
|
||||||
|
kaCred = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kaCred != null) {
|
if (kaCred != null) {
|
||||||
credentials.add(kaCred);
|
credentials.add(kaCred);
|
||||||
}
|
}
|
||||||
} catch (GeneralSecurityException ex) {
|
} catch (GeneralSecurityException ex) {
|
||||||
|
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
|
||||||
SSLLogger.warning(
|
SSLLogger.warning(
|
||||||
"Cannot decode named group: " +
|
"Cannot decode named group: " +
|
||||||
NamedGroup.nameOf(entry.namedGroupId));
|
NamedGroup.nameOf(entry.namedGroupId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!credentials.isEmpty()) {
|
if (!credentials.isEmpty()) {
|
||||||
shc.handshakeCredentials.addAll(credentials);
|
shc.handshakeCredentials.addAll(credentials);
|
||||||
@@ -646,9 +665,20 @@ final class KeyShareExtension {
|
|||||||
|
|
||||||
SSLCredentials credentials = null;
|
SSLCredentials credentials = null;
|
||||||
try {
|
try {
|
||||||
SSLCredentials kaCred = ng.decodeCredentials(
|
SSLCredentials kaCred =
|
||||||
keyShare.keyExchange, chc.algorithmConstraints,
|
ng.decodeCredentials(keyShare.keyExchange);
|
||||||
s -> chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, s));
|
if (chc.algorithmConstraints != null &&
|
||||||
|
kaCred instanceof
|
||||||
|
NamedGroupCredentials namedGroupCredentials) {
|
||||||
|
if (!chc.algorithmConstraints.permits(
|
||||||
|
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
|
||||||
|
namedGroupCredentials.getPublicKey())) {
|
||||||
|
chc.conContext.fatal(Alert.INSUFFICIENT_SECURITY,
|
||||||
|
"key share entry of " + ng + " does not " +
|
||||||
|
" comply with algorithm constraints");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kaCred != null) {
|
if (kaCred != null) {
|
||||||
credentials = kaCred;
|
credentials = kaCred;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -419,12 +419,9 @@ enum NamedGroup {
|
|||||||
return spec.encodePossessionPublicKey(namedGroupPossession);
|
return spec.encodePossessionPublicKey(namedGroupPossession);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSLCredentials decodeCredentials(byte[] encoded,
|
SSLCredentials decodeCredentials(
|
||||||
AlgorithmConstraints constraints,
|
byte[] encoded) throws IOException, GeneralSecurityException {
|
||||||
ExceptionSupplier onConstraintFail)
|
return spec.decodeCredentials(this, encoded);
|
||||||
throws IOException, GeneralSecurityException {
|
|
||||||
return spec.decodeCredentials(
|
|
||||||
this, encoded, constraints, onConstraintFail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SSLPossession createPossession(SecureRandom random) {
|
SSLPossession createPossession(SecureRandom random) {
|
||||||
@@ -436,30 +433,13 @@ enum NamedGroup {
|
|||||||
return spec.createKeyDerivation(hc);
|
return spec.createKeyDerivation(hc);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ExceptionSupplier {
|
|
||||||
void apply(String s) throws SSLException;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A list of operations related to named groups.
|
// A list of operations related to named groups.
|
||||||
private interface NamedGroupScheme {
|
private interface NamedGroupScheme {
|
||||||
default void checkConstraints(PublicKey publicKey,
|
|
||||||
AlgorithmConstraints constraints,
|
|
||||||
ExceptionSupplier onConstraintFail) throws SSLException {
|
|
||||||
if (!constraints.permits(
|
|
||||||
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), publicKey)) {
|
|
||||||
onConstraintFail.apply("key share entry does not "
|
|
||||||
+ "comply with algorithm constraints");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] encodePossessionPublicKey(
|
byte[] encodePossessionPublicKey(
|
||||||
NamedGroupPossession namedGroupPossession);
|
NamedGroupPossession namedGroupPossession);
|
||||||
|
|
||||||
SSLCredentials decodeCredentials(
|
SSLCredentials decodeCredentials(NamedGroup ng,
|
||||||
NamedGroup ng, byte[] encoded,
|
byte[] encoded) throws IOException, GeneralSecurityException;
|
||||||
AlgorithmConstraints constraints,
|
|
||||||
ExceptionSupplier onConstraintFail
|
|
||||||
) throws IOException, GeneralSecurityException;
|
|
||||||
|
|
||||||
SSLPossession createPossession(NamedGroup ng, SecureRandom random);
|
SSLPossession createPossession(NamedGroup ng, SecureRandom random);
|
||||||
|
|
||||||
@@ -524,13 +504,10 @@ enum NamedGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SSLCredentials decodeCredentials(NamedGroup ng, byte[] encoded,
|
public SSLCredentials decodeCredentials(NamedGroup ng,
|
||||||
AlgorithmConstraints constraints,
|
byte[] encoded) throws IOException, GeneralSecurityException {
|
||||||
ExceptionSupplier onConstraintFail
|
|
||||||
) throws IOException, GeneralSecurityException {
|
|
||||||
if (scheme != null) {
|
if (scheme != null) {
|
||||||
return scheme.decodeCredentials(
|
return scheme.decodeCredentials(ng, encoded);
|
||||||
ng, encoded, constraints, onConstraintFail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -567,18 +544,9 @@ enum NamedGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SSLCredentials decodeCredentials(NamedGroup ng, byte[] encoded,
|
public SSLCredentials decodeCredentials(NamedGroup ng,
|
||||||
AlgorithmConstraints constraints,
|
byte[] encoded) throws IOException, GeneralSecurityException {
|
||||||
ExceptionSupplier onConstraintFail
|
return DHKeyExchange.DHECredentials.valueOf(ng, encoded);
|
||||||
) throws IOException, GeneralSecurityException {
|
|
||||||
|
|
||||||
DHKeyExchange.DHECredentials result
|
|
||||||
= DHKeyExchange.DHECredentials.valueOf(ng, encoded);
|
|
||||||
|
|
||||||
checkConstraints(result.getPublicKey(), constraints,
|
|
||||||
onConstraintFail);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -605,18 +573,9 @@ enum NamedGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SSLCredentials decodeCredentials(NamedGroup ng, byte[] encoded,
|
public SSLCredentials decodeCredentials(NamedGroup ng,
|
||||||
AlgorithmConstraints constraints,
|
byte[] encoded) throws IOException, GeneralSecurityException {
|
||||||
ExceptionSupplier onConstraintFail
|
return ECDHKeyExchange.ECDHECredentials.valueOf(ng, encoded);
|
||||||
) throws IOException, GeneralSecurityException {
|
|
||||||
|
|
||||||
ECDHKeyExchange.ECDHECredentials result
|
|
||||||
= ECDHKeyExchange.ECDHECredentials.valueOf(ng, encoded);
|
|
||||||
|
|
||||||
checkConstraints(result.getPublicKey(), constraints,
|
|
||||||
onConstraintFail);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -641,18 +600,9 @@ enum NamedGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SSLCredentials decodeCredentials(NamedGroup ng, byte[] encoded,
|
public SSLCredentials decodeCredentials(NamedGroup ng,
|
||||||
AlgorithmConstraints constraints,
|
byte[] encoded) throws IOException, GeneralSecurityException {
|
||||||
ExceptionSupplier onConstraintFail
|
return XDHKeyExchange.XDHECredentials.valueOf(ng, encoded);
|
||||||
) throws IOException, GeneralSecurityException {
|
|
||||||
|
|
||||||
XDHKeyExchange.XDHECredentials result
|
|
||||||
= XDHKeyExchange.XDHECredentials.valueOf(ng, encoded);
|
|
||||||
|
|
||||||
checkConstraints(result.getPublicKey(), constraints,
|
|
||||||
onConstraintFail);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public final class SSLLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void log(Level level, String msg, Object... params) {
|
private static void log(Level level, String msg, Object... params) {
|
||||||
if (logger.isLoggable(level)) {
|
if (logger != null && logger.isLoggable(level)) {
|
||||||
if (params == null || params.length == 0) {
|
if (params == null || params.length == 0) {
|
||||||
logger.log(level, msg);
|
logger.log(level, msg);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ import java.security.cert.CertificateEncodingException;
|
|||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.security.spec.ECGenParameterSpec;
|
import java.security.spec.ECGenParameterSpec;
|
||||||
import java.security.spec.NamedParameterSpec;
|
import java.security.spec.NamedParameterSpec;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import sun.security.pkcs10.PKCS10;
|
import sun.security.pkcs10.PKCS10;
|
||||||
import sun.security.util.SignatureUtil;
|
import sun.security.util.SignatureUtil;
|
||||||
@@ -304,6 +307,12 @@ public final class CertAndKeyGen {
|
|||||||
try {
|
try {
|
||||||
lastDate = new Date ();
|
lastDate = new Date ();
|
||||||
lastDate.setTime (firstDate.getTime () + validity * 1000);
|
lastDate.setTime (firstDate.getTime () + validity * 1000);
|
||||||
|
Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||||
|
c.setTime(lastDate);
|
||||||
|
if (c.get(Calendar.YEAR) > 9999) {
|
||||||
|
throw new CertificateException("Validity period ends at calendar year " +
|
||||||
|
c.get(Calendar.YEAR) + " which is greater than 9999");
|
||||||
|
}
|
||||||
|
|
||||||
CertificateValidity interval =
|
CertificateValidity interval =
|
||||||
new CertificateValidity(firstDate,lastDate);
|
new CertificateValidity(firstDate,lastDate);
|
||||||
|
|||||||
@@ -1445,8 +1445,7 @@ public final class Main {
|
|||||||
X509CertInfo.DN_NAME);
|
X509CertInfo.DN_NAME);
|
||||||
|
|
||||||
Date firstDate = getStartDate(startDate);
|
Date firstDate = getStartDate(startDate);
|
||||||
Date lastDate = new Date();
|
Date lastDate = getLastDate(firstDate, validity);
|
||||||
lastDate.setTime(firstDate.getTime() + validity*1000L*24L*60L*60L);
|
|
||||||
CertificateValidity interval = new CertificateValidity(firstDate,
|
CertificateValidity interval = new CertificateValidity(firstDate,
|
||||||
lastDate);
|
lastDate);
|
||||||
|
|
||||||
@@ -1560,12 +1559,10 @@ public final class Main {
|
|||||||
X509CertInfo.DN_NAME);
|
X509CertInfo.DN_NAME);
|
||||||
|
|
||||||
Date firstDate = getStartDate(startDate);
|
Date firstDate = getStartDate(startDate);
|
||||||
Date lastDate = (Date) firstDate.clone();
|
Date lastDate = getLastDate(firstDate, validity);
|
||||||
lastDate.setTime(lastDate.getTime() + validity*1000*24*60*60);
|
|
||||||
CertificateValidity interval = new CertificateValidity(firstDate,
|
CertificateValidity interval = new CertificateValidity(firstDate,
|
||||||
lastDate);
|
lastDate);
|
||||||
|
|
||||||
|
|
||||||
PrivateKey privateKey =
|
PrivateKey privateKey =
|
||||||
(PrivateKey)recoverKey(alias, storePass, keyPass).fst;
|
(PrivateKey)recoverKey(alias, storePass, keyPass).fst;
|
||||||
if (sigAlgName == null) {
|
if (sigAlgName == null) {
|
||||||
@@ -3033,8 +3030,7 @@ public final class Main {
|
|||||||
|
|
||||||
// Extend its validity
|
// Extend its validity
|
||||||
Date firstDate = getStartDate(startDate);
|
Date firstDate = getStartDate(startDate);
|
||||||
Date lastDate = new Date();
|
Date lastDate = getLastDate(firstDate, validity);
|
||||||
lastDate.setTime(firstDate.getTime() + validity*1000L*24L*60L*60L);
|
|
||||||
CertificateValidity interval = new CertificateValidity(firstDate,
|
CertificateValidity interval = new CertificateValidity(firstDate,
|
||||||
lastDate);
|
lastDate);
|
||||||
certInfo.set(X509CertInfo.VALIDITY, interval);
|
certInfo.set(X509CertInfo.VALIDITY, interval);
|
||||||
@@ -4695,6 +4691,21 @@ public final class Main {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Date getLastDate(Date firstDate, long validity)
|
||||||
|
throws Exception {
|
||||||
|
Date lastDate = new Date();
|
||||||
|
lastDate.setTime(firstDate.getTime() + validity*1000L*24L*60L*60L);
|
||||||
|
|
||||||
|
Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||||
|
c.setTime(lastDate);
|
||||||
|
if (c.get(Calendar.YEAR) > 9999) {
|
||||||
|
throw new Exception("Validity period ends at calendar year " +
|
||||||
|
c.get(Calendar.YEAR) + " which is greater than 9999");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastDate;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isTrustedCert(Certificate cert) throws KeyStoreException {
|
private boolean isTrustedCert(Certificate cert) throws KeyStoreException {
|
||||||
if (caks != null && caks.getCertificateAlias(cert) != null) {
|
if (caks != null && caks.getCertificateAlias(cert) != null) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -31,9 +31,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A package private utility class to convert indefinite length DER
|
* A package private utility class to convert indefinite length BER
|
||||||
* encoded byte arrays to definite length DER encoded byte arrays.
|
* encoded byte arrays to definite length DER encoded byte arrays.
|
||||||
*
|
* <p>
|
||||||
|
* Note: This class only substitute indefinite length octets to definite
|
||||||
|
* length octets. It does not update the contents even if they are not DER.
|
||||||
|
* <p>
|
||||||
* This assumes that the basic data structure is "tag, length, value"
|
* This assumes that the basic data structure is "tag, length, value"
|
||||||
* triplet. In the case where the length is "indefinite", terminating
|
* triplet. In the case where the length is "indefinite", terminating
|
||||||
* end-of-contents bytes are expected.
|
* end-of-contents bytes are expected.
|
||||||
@@ -42,26 +45,30 @@ import java.util.Arrays;
|
|||||||
*/
|
*/
|
||||||
class DerIndefLenConverter {
|
class DerIndefLenConverter {
|
||||||
|
|
||||||
private static final int TAG_MASK = 0x1f; // bits 5-1
|
|
||||||
private static final int FORM_MASK = 0x20; // bits 6
|
|
||||||
private static final int CLASS_MASK = 0xC0; // bits 8 and 7
|
|
||||||
|
|
||||||
private static final int LEN_LONG = 0x80; // bit 8 set
|
private static final int LEN_LONG = 0x80; // bit 8 set
|
||||||
private static final int LEN_MASK = 0x7f; // bits 7 - 1
|
private static final int LEN_MASK = 0x7f; // bits 7 - 1
|
||||||
private static final int SKIP_EOC_BYTES = 2;
|
|
||||||
|
|
||||||
private byte[] data, newData;
|
private byte[] data, newData;
|
||||||
private int newDataPos, dataPos, dataSize, index;
|
private int newDataPos, dataPos, dataSize, index;
|
||||||
private int unresolved = 0;
|
private int unresolved = 0;
|
||||||
|
|
||||||
|
// A list to store each indefinite length occurrence. Whenever an indef
|
||||||
|
// length is seen, the position after the 0x80 byte is appended to the
|
||||||
|
// list as an integer. Whenever its matching EOC is seen, we know the
|
||||||
|
// actual length and the position value is substituted with a calculated
|
||||||
|
// length octets. At the end, the new DER encoding is a concatenation of
|
||||||
|
// all existing tags, existing definite length octets, existing contents,
|
||||||
|
// and the newly created definte length octets in this list.
|
||||||
private ArrayList<Object> ndefsList = new ArrayList<Object>();
|
private ArrayList<Object> ndefsList = new ArrayList<Object>();
|
||||||
|
|
||||||
|
// Length of extra bytes needed to convert indefinite encoding to definite.
|
||||||
|
// For each resolved indefinite length encoding, the starting 0x80 byte
|
||||||
|
// and the ending 00 00 bytes will be removed and a new definite length
|
||||||
|
// octets will be added. This value might be positive or negative.
|
||||||
private int numOfTotalLenBytes = 0;
|
private int numOfTotalLenBytes = 0;
|
||||||
|
|
||||||
private boolean isEOC(int tag) {
|
private static boolean isEOC(byte[] data, int pos) {
|
||||||
return (((tag & TAG_MASK) == 0x00) && // EOC
|
return data[pos] == 0 && data[pos + 1] == 0;
|
||||||
((tag & FORM_MASK) == 0x00) && // primitive
|
|
||||||
((tag & CLASS_MASK) == 0x00)); // universal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if bit 8 is set then it implies either indefinite length or long form
|
// if bit 8 is set then it implies either indefinite length or long form
|
||||||
@@ -70,9 +77,9 @@ class DerIndefLenConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default package private constructor
|
* Private constructor
|
||||||
*/
|
*/
|
||||||
DerIndefLenConverter() { }
|
private DerIndefLenConverter() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given length byte is of the form
|
* Checks whether the given length byte is of the form
|
||||||
@@ -88,11 +95,14 @@ class DerIndefLenConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the tag and if it is an end-of-contents tag then
|
* Consumes the tag at {@code dataPos}.
|
||||||
* add the current position to the <code>eocList</code> vector.
|
* <p>
|
||||||
|
* If it is EOC then replace the matching start position (i.e. the previous
|
||||||
|
* {@code dataPos} where an indefinite length was found by #parseLength)
|
||||||
|
* in {@code ndefsList} with a length octets for this section.
|
||||||
*/
|
*/
|
||||||
private void parseTag() throws IOException {
|
private void parseTag() throws IOException {
|
||||||
if (isEOC(data[dataPos]) && (data[dataPos + 1] == 0)) {
|
if (isEOC(data, dataPos)) {
|
||||||
int numOfEncapsulatedLenBytes = 0;
|
int numOfEncapsulatedLenBytes = 0;
|
||||||
Object elem = null;
|
Object elem = null;
|
||||||
int index;
|
int index;
|
||||||
@@ -103,6 +113,9 @@ class DerIndefLenConverter {
|
|||||||
if (elem instanceof Integer) {
|
if (elem instanceof Integer) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
// For each existing converted part, 3 bytes (80 at the
|
||||||
|
// beginning and 00 00 at the end) are removed and a
|
||||||
|
// new length octets is added.
|
||||||
numOfEncapsulatedLenBytes += ((byte[])elem).length - 3;
|
numOfEncapsulatedLenBytes += ((byte[])elem).length - 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +127,7 @@ class DerIndefLenConverter {
|
|||||||
numOfEncapsulatedLenBytes;
|
numOfEncapsulatedLenBytes;
|
||||||
byte[] sectionLenBytes = getLengthBytes(sectionLen);
|
byte[] sectionLenBytes = getLengthBytes(sectionLen);
|
||||||
ndefsList.set(index, sectionLenBytes);
|
ndefsList.set(index, sectionLenBytes);
|
||||||
|
assert unresolved > 0;
|
||||||
unresolved--;
|
unresolved--;
|
||||||
|
|
||||||
// Add the number of bytes required to represent this section
|
// Add the number of bytes required to represent this section
|
||||||
@@ -130,34 +144,41 @@ class DerIndefLenConverter {
|
|||||||
* then skip the tag and its 1 byte length of zero.
|
* then skip the tag and its 1 byte length of zero.
|
||||||
*/
|
*/
|
||||||
private void writeTag() {
|
private void writeTag() {
|
||||||
if (dataPos == dataSize)
|
if (dataPos == dataSize) {
|
||||||
return;
|
return;
|
||||||
int tag = data[dataPos++];
|
}
|
||||||
if (isEOC(tag) && (data[dataPos] == 0)) {
|
assert dataPos + 1 < dataSize;
|
||||||
dataPos++; // skip length
|
if (isEOC(data, dataPos)) {
|
||||||
|
dataPos += 2; // skip tag and length
|
||||||
writeTag();
|
writeTag();
|
||||||
} else
|
} else {
|
||||||
newData[newDataPos++] = (byte)tag;
|
newData[newDataPos++] = data[dataPos++];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the length and if it is an indefinite length then add
|
* Parse the length octets started at {@code dataPos}. After this method
|
||||||
* the current position to the <code>ndefsList</code> vector.
|
* is called, {@code dataPos} is placed after the length octets except
|
||||||
|
* -1 is returned.
|
||||||
*
|
*
|
||||||
* @return the length of definite length data next, or -1 if there is
|
* @return a) the length of definite length data next
|
||||||
* not enough bytes to determine it
|
* b) -1, if it is a definite length data next but the length
|
||||||
|
* octets is not complete to determine the actual length
|
||||||
|
* c) 0, if it is an indefinite length. Also, append the current
|
||||||
|
* position to the {@code ndefsList} vector.
|
||||||
* @throws IOException if invalid data is read
|
* @throws IOException if invalid data is read
|
||||||
*/
|
*/
|
||||||
private int parseLength() throws IOException {
|
private int parseLength() throws IOException {
|
||||||
int curLen = 0;
|
if (dataPos == dataSize) {
|
||||||
if (dataPos == dataSize)
|
return 0;
|
||||||
return curLen;
|
}
|
||||||
int lenByte = data[dataPos++] & 0xff;
|
int lenByte = data[dataPos++] & 0xff;
|
||||||
if (isIndefinite(lenByte)) {
|
if (isIndefinite(lenByte)) {
|
||||||
ndefsList.add(dataPos);
|
ndefsList.add(dataPos);
|
||||||
unresolved++;
|
unresolved++;
|
||||||
return curLen;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int curLen = 0;
|
||||||
if (isLongForm(lenByte)) {
|
if (isLongForm(lenByte)) {
|
||||||
lenByte &= LEN_MASK;
|
lenByte &= LEN_MASK;
|
||||||
if (lenByte > 4) {
|
if (lenByte > 4) {
|
||||||
@@ -179,14 +200,17 @@ class DerIndefLenConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the length and if it is an indefinite length
|
* Write the length and value.
|
||||||
* then calculate the definite length from the positions
|
* <p>
|
||||||
* of the indefinite length and its matching EOC terminator.
|
* If it was definite length, just re-write the length and copy the value.
|
||||||
* Then, write the value.
|
* If it was an indefinite length, copy the precalculated definite octets
|
||||||
|
* from {@code ndefsList}. There is no values here because they will be
|
||||||
|
* sub-encodings of a constructed encoding.
|
||||||
*/
|
*/
|
||||||
private void writeLengthAndValue() throws IOException {
|
private void writeLengthAndValue() throws IOException {
|
||||||
if (dataPos == dataSize)
|
if (dataPos == dataSize) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
int curLen = 0;
|
int curLen = 0;
|
||||||
int lenByte = data[dataPos++] & 0xff;
|
int lenByte = data[dataPos++] & 0xff;
|
||||||
if (isIndefinite(lenByte)) {
|
if (isIndefinite(lenByte)) {
|
||||||
@@ -194,8 +218,7 @@ class DerIndefLenConverter {
|
|||||||
System.arraycopy(lenBytes, 0, newData, newDataPos,
|
System.arraycopy(lenBytes, 0, newData, newDataPos,
|
||||||
lenBytes.length);
|
lenBytes.length);
|
||||||
newDataPos += lenBytes.length;
|
newDataPos += lenBytes.length;
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
if (isLongForm(lenByte)) {
|
if (isLongForm(lenByte)) {
|
||||||
lenByte &= LEN_MASK;
|
lenByte &= LEN_MASK;
|
||||||
for (int i = 0; i < lenByte; i++) {
|
for (int i = 0; i < lenByte; i++) {
|
||||||
@@ -210,6 +233,7 @@ class DerIndefLenConverter {
|
|||||||
writeLength(curLen);
|
writeLength(curLen);
|
||||||
writeValue(curLen);
|
writeValue(curLen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void writeLength(int curLen) {
|
private void writeLength(int curLen) {
|
||||||
if (curLen < 128) {
|
if (curLen < 128) {
|
||||||
@@ -296,19 +320,13 @@ class DerIndefLenConverter {
|
|||||||
return numOfLenBytes;
|
return numOfLenBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the value;
|
|
||||||
*/
|
|
||||||
private void parseValue(int curLen) {
|
|
||||||
dataPos += curLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the value;
|
* Write the value;
|
||||||
*/
|
*/
|
||||||
private void writeValue(int curLen) {
|
private void writeValue(int curLen) {
|
||||||
for (int i=0; i < curLen; i++)
|
System.arraycopy(data, dataPos, newData, newDataPos, curLen);
|
||||||
newData[newDataPos++] = data[dataPos++];
|
dataPos += curLen;
|
||||||
|
newDataPos += curLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -323,10 +341,8 @@ class DerIndefLenConverter {
|
|||||||
*/
|
*/
|
||||||
byte[] convertBytes(byte[] indefData) throws IOException {
|
byte[] convertBytes(byte[] indefData) throws IOException {
|
||||||
data = indefData;
|
data = indefData;
|
||||||
dataPos=0; index=0;
|
dataPos = 0;
|
||||||
dataSize = data.length;
|
dataSize = data.length;
|
||||||
int len=0;
|
|
||||||
int unused = 0;
|
|
||||||
|
|
||||||
// parse and set up the vectors of all the indefinite-lengths
|
// parse and set up the vectors of all the indefinite-lengths
|
||||||
while (dataPos < dataSize) {
|
while (dataPos < dataSize) {
|
||||||
@@ -335,14 +351,17 @@ class DerIndefLenConverter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
parseTag();
|
parseTag();
|
||||||
len = parseLength();
|
int len = parseLength();
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
parseValue(len);
|
dataPos += len;
|
||||||
|
if (dataPos < 0) {
|
||||||
|
// overflow
|
||||||
|
throw new IOException("Data overflow");
|
||||||
|
}
|
||||||
if (unresolved == 0) {
|
if (unresolved == 0) {
|
||||||
unused = dataSize - dataPos;
|
assert !ndefsList.isEmpty() && ndefsList.get(0) instanceof byte[];
|
||||||
dataSize = dataPos;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,6 +370,10 @@ class DerIndefLenConverter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int unused = dataSize - dataPos;
|
||||||
|
assert unused >= 0;
|
||||||
|
dataSize = dataPos;
|
||||||
|
|
||||||
newData = new byte[dataSize + numOfTotalLenBytes + unused];
|
newData = new byte[dataSize + numOfTotalLenBytes + unused];
|
||||||
dataPos = 0; newDataPos = 0; index = 0;
|
dataPos = 0; newDataPos = 0; index = 0;
|
||||||
|
|
||||||
@@ -395,7 +418,7 @@ class DerIndefLenConverter {
|
|||||||
if (result == null) {
|
if (result == null) {
|
||||||
int next = in.read(); // This could block, but we need more
|
int next = in.read(); // This could block, but we need more
|
||||||
if (next == -1) {
|
if (next == -1) {
|
||||||
throw new IOException("not all indef len BER resolved");
|
throw new IOException("not enough data to resolve indef len BER");
|
||||||
}
|
}
|
||||||
int more = in.available();
|
int more = in.available();
|
||||||
// expand array to include next and more
|
// expand array to include next and more
|
||||||
|
|||||||
@@ -591,6 +591,13 @@ public class BMPImageReader extends ImageReader implements BMPConstants {
|
|||||||
height = Math.abs(height);
|
height = Math.abs(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metadata.compression == BI_RGB) {
|
||||||
|
long imageDataSize = (width * height * (bitsPerPixel / 8));
|
||||||
|
if (imageDataSize > (bitmapFileSize - bitmapOffset)) {
|
||||||
|
throw new IIOException(I18N.getString("BMPImageReader9"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reset Image Layout so there's only one tile.
|
// Reset Image Layout so there's only one tile.
|
||||||
//Define the color space
|
//Define the color space
|
||||||
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ BMPImageReader5=Input has not been set.
|
|||||||
BMPImageReader6=Unable to read the image header.
|
BMPImageReader6=Unable to read the image header.
|
||||||
BMPImageReader7=Invalid bitmap offset.
|
BMPImageReader7=Invalid bitmap offset.
|
||||||
BMPImageReader8=Invalid bits per pixel in image header.
|
BMPImageReader8=Invalid bits per pixel in image header.
|
||||||
|
BMPImageReader9=Invalid width/height for BI_RGB image data.
|
||||||
BMPImageWriter0=Output is not an ImageOutputStream.
|
BMPImageWriter0=Output is not an ImageOutputStream.
|
||||||
BMPImageWriter1=The image region to be encoded is empty.
|
BMPImageWriter1=The image region to be encoded is empty.
|
||||||
BMPImageWriter2=Only 1 or 3 band image is encoded.
|
BMPImageWriter2=Only 1 or 3 band image is encoded.
|
||||||
|
|||||||
@@ -233,25 +233,52 @@ abstract class RTFParser extends AbstractFilter
|
|||||||
currentCharacters.append(ch);
|
currentCharacters.append(ch);
|
||||||
} else {
|
} else {
|
||||||
/* TODO: Test correct behavior of \bin keyword */
|
/* TODO: Test correct behavior of \bin keyword */
|
||||||
|
|
||||||
if (pendingKeyword.equals("bin")) { /* magic layer-breaking kwd */
|
if (pendingKeyword.equals("bin")) { /* magic layer-breaking kwd */
|
||||||
long parameter = Long.parseLong(currentCharacters.toString());
|
long parameter = 0L;
|
||||||
|
try {
|
||||||
|
parameter = Long.parseLong(currentCharacters.toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
warning("Illegal number format " + currentCharacters.toString()
|
||||||
|
+ " in \bin tag");
|
||||||
|
pendingKeyword = null;
|
||||||
|
currentCharacters = new StringBuffer();
|
||||||
|
state = S_text;
|
||||||
|
// Delimiters here are interpreted as text too
|
||||||
|
if (!Character.isWhitespace(ch))
|
||||||
|
write(ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
pendingKeyword = null;
|
pendingKeyword = null;
|
||||||
state = S_inblob;
|
state = S_inblob;
|
||||||
|
int maxBytes = 4 * 1024 * 1024;
|
||||||
binaryBytesLeft = parameter;
|
binaryBytesLeft = parameter;
|
||||||
if (binaryBytesLeft > Integer.MAX_VALUE)
|
|
||||||
binaryBuf = new ByteArrayOutputStream(Integer.MAX_VALUE);
|
if (binaryBytesLeft > maxBytes) {
|
||||||
else
|
binaryBuf = new ByteArrayOutputStream(maxBytes);
|
||||||
|
} else if (binaryBytesLeft < 0) {
|
||||||
|
binaryBytesLeft = 0;
|
||||||
binaryBuf = new ByteArrayOutputStream((int)binaryBytesLeft);
|
binaryBuf = new ByteArrayOutputStream((int)binaryBytesLeft);
|
||||||
|
} else {
|
||||||
|
binaryBuf = new ByteArrayOutputStream((int) binaryBytesLeft);
|
||||||
|
}
|
||||||
savedSpecials = specialsTable;
|
savedSpecials = specialsTable;
|
||||||
specialsTable = allSpecialsTable;
|
specialsTable = allSpecialsTable;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parameter = Integer.parseInt(currentCharacters.toString());
|
int parameter = 0;
|
||||||
|
try {
|
||||||
|
parameter = Integer.parseInt(currentCharacters.toString());
|
||||||
ok = handleKeyword(pendingKeyword, parameter);
|
ok = handleKeyword(pendingKeyword, parameter);
|
||||||
if (!ok)
|
if (!ok) {
|
||||||
warning("Unknown keyword: " + pendingKeyword +
|
warning("Unknown keyword: " + pendingKeyword +
|
||||||
" (param " + currentCharacters + ")");
|
" (param " + currentCharacters + ")");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
warning("Illegal number format " + currentCharacters.toString()
|
||||||
|
+ " in " + pendingKeyword + " tag");
|
||||||
|
}
|
||||||
pendingKeyword = null;
|
pendingKeyword = null;
|
||||||
currentCharacters = new StringBuffer();
|
currentCharacters = new StringBuffer();
|
||||||
state = S_text;
|
state = S_text;
|
||||||
@@ -280,9 +307,10 @@ abstract class RTFParser extends AbstractFilter
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_inblob:
|
case S_inblob:
|
||||||
|
if (binaryBytesLeft > 0) {
|
||||||
binaryBuf.write(ch);
|
binaryBuf.write(ch);
|
||||||
binaryBytesLeft--;
|
binaryBytesLeft--;
|
||||||
if (binaryBytesLeft == 0) {
|
} else {
|
||||||
state = S_text;
|
state = S_text;
|
||||||
specialsTable = savedSpecials;
|
specialsTable = savedSpecials;
|
||||||
savedSpecials = null;
|
savedSpecials = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user