Merge "java.security.cert: update classes in java.security.cert"
diff --git a/luni/src/main/java/android/system/Os.java b/luni/src/main/java/android/system/Os.java
index c43c1ba..63246d6 100644
--- a/luni/src/main/java/android/system/Os.java
+++ b/luni/src/main/java/android/system/Os.java
@@ -466,7 +466,12 @@
/** @hide */ public static void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptByte(fd, level, option, value); }
/** @hide */ public static void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { Libcore.os.setsockoptIfreq(fd, level, option, value); }
- /** @hide */ public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); }
+
+ /**
+ * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">setsockopt(2)</a>.
+ */
+ public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); }
+
/** @hide */ public static void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptIpMreqn(fd, level, option, value); }
/** @hide */ public static void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { Libcore.os.setsockoptGroupReq(fd, level, option, value); }
/** @hide */ public static void setsockoptGroupSourceReq(FileDescriptor fd, int level, int option, StructGroupSourceReq value) throws ErrnoException { Libcore.os.setsockoptGroupSourceReq(fd, level, option, value); }
diff --git a/luni/src/main/java/android/system/OsConstants.java b/luni/src/main/java/android/system/OsConstants.java
index 31f84e9..140d71d 100644
--- a/luni/src/main/java/android/system/OsConstants.java
+++ b/luni/src/main/java/android/system/OsConstants.java
@@ -495,6 +495,7 @@
public static final int S_IXOTH = placeholder();
public static final int S_IXUSR = placeholder();
public static final int TCP_NODELAY = placeholder();
+ public static final int TCP_USER_TIMEOUT = placeholder();
/** @hide */ public static final int TIOCOUTQ = placeholder();
/** @hide */ public static final int UNIX_PATH_MAX = placeholder();
public static final int WCONTINUED = placeholder();
diff --git a/luni/src/main/native/NetworkUtilities.cpp b/luni/src/main/native/NetworkUtilities.cpp
index b285a01..bf438fa 100644
--- a/luni/src/main/native/NetworkUtilities.cpp
+++ b/luni/src/main/native/NetworkUtilities.cpp
@@ -140,8 +140,12 @@
jbyte* dst = reinterpret_cast<jbyte*>(&sin6.sin6_addr.s6_addr);
env->GetByteArrayRegion(addressBytes.get(), 0, 16, dst);
// ...and set the scope id...
- static jfieldID scopeFid = env->GetFieldID(JniConstants::inet6AddressClass, "scope_id", "I");
- sin6.sin6_scope_id = env->GetIntField(inetAddress, scopeFid);
+ static jfieldID holder6Fid = env->GetFieldID(JniConstants::inet6AddressClass,
+ "holder6",
+ "Ljava/net/Inet6Address$Inet6AddressHolder;");
+ ScopedLocalRef<jobject> holder6(env, env->GetObjectField(inetAddress, holder6Fid));
+ static jfieldID scopeFid = env->GetFieldID(JniConstants::inet6AddressHolderClass, "scope_id", "I");
+ sin6.sin6_scope_id = env->GetIntField(holder6.get(), scopeFid);
sa_len = sizeof(sockaddr_in6);
return true;
}
diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp
index 1293fe7..e6aff37 100644
--- a/luni/src/main/native/android_system_OsConstants.cpp
+++ b/luni/src/main/native/android_system_OsConstants.cpp
@@ -551,6 +551,9 @@
initConstant(env, c, "S_IXOTH", S_IXOTH);
initConstant(env, c, "S_IXUSR", S_IXUSR);
initConstant(env, c, "TCP_NODELAY", TCP_NODELAY);
+#if defined(TCP_USER_TIMEOUT)
+ initConstant(env, c, "TCP_USER_TIMEOUT", TCP_USER_TIMEOUT);
+#endif
initConstant(env, c, "TIOCOUTQ", TIOCOUTQ);
// UNIX_PATH_MAX is mentioned in some versions of unix(7), but not actually declared.
initConstant(env, c, "UNIX_PATH_MAX", sizeof(sockaddr_un::sun_path));
diff --git a/luni/src/test/java/libcore/android/system/OsConstantsTest.java b/luni/src/test/java/libcore/android/system/OsConstantsTest.java
index 080464d..a98707c 100644
--- a/luni/src/test/java/libcore/android/system/OsConstantsTest.java
+++ b/luni/src/test/java/libcore/android/system/OsConstantsTest.java
@@ -30,4 +30,9 @@
assertTrue(OsConstants.IFA_F_TENTATIVE > 0);
}
+
+ // introduced for http://b/30402085
+ public void testTcpUserTimeoutIsDefined() {
+ assertTrue(OsConstants.TCP_USER_TIMEOUT > 0);
+ }
}
diff --git a/luni/src/test/java/libcore/io/OsTest.java b/luni/src/test/java/libcore/io/OsTest.java
index 5a2b95c..f34d099 100644
--- a/luni/src/test/java/libcore/io/OsTest.java
+++ b/luni/src/test/java/libcore/io/OsTest.java
@@ -571,6 +571,39 @@
}
}
+ /**
+ * Tests that TCP_USER_TIMEOUT can be set on a TCP socket, but doesn't test
+ * that it behaves as expected.
+ */
+ public void test_socket_tcpUserTimeout_setAndGet() throws Exception {
+ final FileDescriptor fd = Libcore.os.socket(AF_INET, SOCK_STREAM, 0);
+ try {
+ int v = Libcore.os.getsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_USER_TIMEOUT);
+ assertEquals(0, v); // system default value
+ int newValue = 3000;
+ Libcore.os.setsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_USER_TIMEOUT,
+ newValue);
+ assertEquals(newValue, Libcore.os.getsockoptInt(fd, OsConstants.IPPROTO_TCP,
+ OsConstants.TCP_USER_TIMEOUT));
+ // No need to reset the value to 0, since we're throwing the socket away
+ } finally {
+ Libcore.os.close(fd);
+ }
+ }
+
+ public void test_socket_tcpUserTimeout_doesNotWorkOnDatagramSocket() throws Exception {
+ final FileDescriptor fd = Libcore.os.socket(AF_INET, SOCK_DGRAM, 0);
+ try {
+ Libcore.os.setsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_USER_TIMEOUT,
+ 3000);
+ fail("datagram (connectionless) sockets shouldn't support TCP_USER_TIMEOUT");
+ } catch (ErrnoException expected) {
+ // expected
+ } finally {
+ Libcore.os.close(fd);
+ }
+ }
+
private static void assertStartsWith(byte[] expectedContents, byte[] container) {
for (int i = 0; i < expectedContents.length; i++) {
if (expectedContents[i] != container[i]) {
diff --git a/ojluni/src/main/java/java/net/Inet6Address.java b/ojluni/src/main/java/java/net/Inet6Address.java
index 1fa8e04..013c4ca 100644
--- a/ojluni/src/main/java/java/net/Inet6Address.java
+++ b/ojluni/src/main/java/java/net/Inet6Address.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -26,10 +26,13 @@
package java.net;
-import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
import java.util.Enumeration;
+import java.util.Arrays;
import libcore.io.Libcore;
import static android.system.OsConstants.*;
@@ -183,73 +186,226 @@
public static final InetAddress LOOPBACK = new Inet6Address("ip6-localhost",
new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 0);
- /**
- * Holds a 128-bit (16 bytes) IPv6 address.
- *
- * @serial
- */
- byte[] ipaddress;
+ private class Inet6AddressHolder {
- /**
- * scope_id. The scope specified when the object is created. If the object is created
- * with an interface name, then the scope_id is not determined until the time it is needed.
- */
- private int scope_id = 0;
+ private Inet6AddressHolder() {
+ ipaddress = new byte[INADDRSZ];
+ }
- /**
- * This will be set to true when the scope_id field contains a valid
- * integer scope_id.
- */
- private boolean scope_id_set = false;
+ private Inet6AddressHolder(
+ byte[] ipaddress, int scope_id, boolean scope_id_set,
+ NetworkInterface ifname, boolean scope_ifname_set)
+ {
+ this.ipaddress = ipaddress;
+ this.scope_id = scope_id;
+ this.scope_id_set = scope_id_set;
+ this.scope_ifname_set = scope_ifname_set;
+ this.scope_ifname = ifname;
+ }
- /**
- * scoped interface. scope_id is derived from this as the scope_id of the first
- * address whose scope is the same as this address for the named interface.
- */
- private transient NetworkInterface scope_ifname = null;
+ /**
+ * Holds a 128-bit (16 bytes) IPv6 address.
+ */
+ byte[] ipaddress;
- /**
- * set if the object is constructed with a scoped interface instead of a
- * numeric scope id.
- */
- private boolean scope_ifname_set = false;
+ /**
+ * scope_id. The scope specified when the object is created. If the object
+ * is created with an interface name, then the scope_id is not determined
+ * until the time it is needed.
+ */
+ int scope_id; // 0
+
+ /**
+ * This will be set to true when the scope_id field contains a valid
+ * integer scope_id.
+ */
+ boolean scope_id_set; // false
+
+ /**
+ * scoped interface. scope_id is derived from this as the scope_id of the first
+ * address whose scope is the same as this address for the named interface.
+ */
+ NetworkInterface scope_ifname; // null
+
+ /**
+ * set if the object is constructed with a scoped
+ * interface instead of a numeric scope id.
+ */
+ boolean scope_ifname_set; // false;
+
+ void setAddr(byte addr[]) {
+ if (addr.length == INADDRSZ) { // normal IPv6 address
+ System.arraycopy(addr, 0, ipaddress, 0, INADDRSZ);
+ }
+ }
+
+ void init(byte addr[], int scope_id) {
+ setAddr(addr);
+
+ // Android-changed: was >= 0
+ if (scope_id > 0) {
+ this.scope_id = scope_id;
+ this.scope_id_set = true;
+ }
+ }
+
+ void init(byte addr[], NetworkInterface nif)
+ throws UnknownHostException
+ {
+ setAddr(addr);
+
+ if (nif != null) {
+ this.scope_id = deriveNumericScope(ipaddress, nif);
+ this.scope_id_set = true;
+ this.scope_ifname = nif;
+ this.scope_ifname_set = true;
+ }
+ }
+
+ /* ----- android-removed -----
+ String getHostAddress() {
+ String s = numericToTextFormat(ipaddress);
+ if (scope_ifname != null) { // must check this first
+ s = s + "%" + scope_ifname.getName();
+ } else if (scope_id_set) {
+ s = s + "%" + scope_id;
+ }
+ return s;
+ } */
+
+ public boolean equals(Object o) {
+ if (! (o instanceof Inet6AddressHolder)) {
+ return false;
+ }
+ Inet6AddressHolder that = (Inet6AddressHolder)o;
+
+ return Arrays.equals(this.ipaddress, that.ipaddress);
+ }
+
+ public int hashCode() {
+ if (ipaddress != null) {
+
+ int hash = 0;
+ int i=0;
+ while (i<INADDRSZ) {
+ int j=0;
+ int component=0;
+ while (j<4 && i<INADDRSZ) {
+ component = (component << 8) + ipaddress[i];
+ j++;
+ i++;
+ }
+ hash += component;
+ }
+ return hash;
+
+ } else {
+ return 0;
+ }
+ }
+
+ boolean isIPv4CompatibleAddress() {
+ if ((ipaddress[0] == 0x00) && (ipaddress[1] == 0x00) &&
+ (ipaddress[2] == 0x00) && (ipaddress[3] == 0x00) &&
+ (ipaddress[4] == 0x00) && (ipaddress[5] == 0x00) &&
+ (ipaddress[6] == 0x00) && (ipaddress[7] == 0x00) &&
+ (ipaddress[8] == 0x00) && (ipaddress[9] == 0x00) &&
+ (ipaddress[10] == 0x00) && (ipaddress[11] == 0x00)) {
+ return true;
+ }
+ return false;
+ }
+
+ boolean isMulticastAddress() {
+ return ((ipaddress[0] & 0xff) == 0xff);
+ }
+
+ boolean isAnyLocalAddress() {
+ byte test = 0x00;
+ for (int i = 0; i < INADDRSZ; i++) {
+ test |= ipaddress[i];
+ }
+ return (test == 0x00);
+ }
+
+ boolean isLoopbackAddress() {
+ byte test = 0x00;
+ for (int i = 0; i < 15; i++) {
+ test |= ipaddress[i];
+ }
+ return (test == 0x00) && (ipaddress[15] == 0x01);
+ }
+
+ boolean isLinkLocalAddress() {
+ return ((ipaddress[0] & 0xff) == 0xfe
+ && (ipaddress[1] & 0xc0) == 0x80);
+ }
+
+
+ boolean isSiteLocalAddress() {
+ return ((ipaddress[0] & 0xff) == 0xfe
+ && (ipaddress[1] & 0xc0) == 0xc0);
+ }
+
+ boolean isMCGlobal() {
+ return ((ipaddress[0] & 0xff) == 0xff
+ && (ipaddress[1] & 0x0f) == 0x0e);
+ }
+
+ boolean isMCNodeLocal() {
+ return ((ipaddress[0] & 0xff) == 0xff
+ && (ipaddress[1] & 0x0f) == 0x01);
+ }
+
+ boolean isMCLinkLocal() {
+ return ((ipaddress[0] & 0xff) == 0xff
+ && (ipaddress[1] & 0x0f) == 0x02);
+ }
+
+ boolean isMCSiteLocal() {
+ return ((ipaddress[0] & 0xff) == 0xff
+ && (ipaddress[1] & 0x0f) == 0x05);
+ }
+
+ boolean isMCOrgLocal() {
+ return ((ipaddress[0] & 0xff) == 0xff
+ && (ipaddress[1] & 0x0f) == 0x08);
+ }
+ }
+
+ private final transient Inet6AddressHolder holder6;
private static final long serialVersionUID = 6880410070516793377L;
Inet6Address() {
super();
- holder().hostName = null;
- ipaddress = new byte[INADDRSZ];
- holder().family = AF_INET6;
+ holder.init(null, AF_INET6);
+ holder6 = new Inet6AddressHolder();
}
/* checking of value for scope_id should be done by caller
* scope_id must be >= 0, or -1 to indicate not being set
*/
Inet6Address(String hostName, byte addr[], int scope_id) {
- holder().hostName = hostName;
- if (addr.length == INADDRSZ) { // normal IPv6 address
- holder().family = AF_INET6;
- ipaddress = addr.clone();
- }
- // Android change, was >= 0.
- if (scope_id > 0) {
- this.scope_id = scope_id;
- scope_id_set = true;
- }
+ holder.init(hostName, AF_INET6);
+ holder6 = new Inet6AddressHolder();
+ holder6.init(addr, scope_id);
}
Inet6Address(String hostName, byte addr[]) {
+ holder6 = new Inet6AddressHolder();
try {
initif (hostName, addr, null);
} catch (UnknownHostException e) {} /* cant happen if ifname is null */
}
Inet6Address (String hostName, byte addr[], NetworkInterface nif) throws UnknownHostException {
+ holder6 = new Inet6AddressHolder();
initif (hostName, addr, nif);
}
Inet6Address (String hostName, byte addr[], String ifname) throws UnknownHostException {
+ holder6 = new Inet6AddressHolder();
initstr (hostName, addr, ifname);
}
@@ -339,16 +495,13 @@
private void initif(String hostName, byte addr[],NetworkInterface nif) throws UnknownHostException {
holder().hostName = hostName;
+ int family = -1;
+ holder6.init(addr, nif);
+
if (addr.length == INADDRSZ) { // normal IPv6 address
- holder().family = AF_INET6;
- ipaddress = addr.clone();
+ family = AF_INET6;
}
- if (nif != null) {
- this.scope_ifname = nif;
- scope_ifname_set = true;
- scope_id = deriveNumericScope (nif);
- scope_id_set = true;
- }
+ holder.init(hostName, family);
}
/* check the two Ipv6 addresses and return false if they are both
@@ -356,18 +509,22 @@
* (ie. one is sitelocal and the other linklocal)
* return true otherwise.
*/
- private boolean differentLocalAddressTypes(Inet6Address other) {
- if (isLinkLocalAddress() && !other.isLinkLocalAddress()) {
+ private static boolean isDifferentLocalAddressType(
+ byte[] thisAddr, byte[] otherAddr) {
+
+ if (Inet6Address.isLinkLocalAddress(thisAddr) &&
+ !Inet6Address.isLinkLocalAddress(otherAddr)) {
return false;
}
- if (isSiteLocalAddress() && !other.isSiteLocalAddress()) {
+ if (Inet6Address.isSiteLocalAddress(thisAddr) &&
+ !Inet6Address.isSiteLocalAddress(otherAddr)) {
return false;
}
return true;
}
- private int deriveNumericScope (NetworkInterface ifc) throws UnknownHostException {
+ private static int deriveNumericScope (byte[] thisAddr, NetworkInterface ifc) throws UnknownHostException {
Enumeration<InetAddress> addresses = ifc.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
@@ -376,12 +533,12 @@
}
Inet6Address ia6_addr = (Inet6Address)addr;
/* check if site or link local prefixes match */
- if (!differentLocalAddressTypes(ia6_addr)){
+ if (!isDifferentLocalAddressType(thisAddr, ia6_addr.getAddress())){
/* type not the same, so carry on searching */
continue;
}
/* found a matching address - return its scope_id */
- return ia6_addr.scope_id;
+ return ia6_addr.getScopeId();
}
throw new UnknownHostException ("no scope_id found");
}
@@ -396,41 +553,62 @@
while (en.hasMoreElements()) {
NetworkInterface ifc = en.nextElement();
if (ifc.getName().equals (ifname)) {
- Enumeration addresses = ifc.getInetAddresses();
- while (addresses.hasMoreElements()) {
- InetAddress addr = (InetAddress)addresses.nextElement();
- if (!(addr instanceof Inet6Address)) {
- continue;
- }
- Inet6Address ia6_addr = (Inet6Address)addr;
- /* check if site or link local prefixes match */
- if (!differentLocalAddressTypes(ia6_addr)){
- /* type not the same, so carry on searching */
- continue;
- }
- /* found a matching address - return its scope_id */
- return ia6_addr.scope_id;
- }
+ return deriveNumericScope(holder6.ipaddress, ifc);
}
}
throw new UnknownHostException ("No matching address found for interface : " +ifname);
}
/**
+ * @serialField ipaddress byte[]
+ * @serialField scope_id int
+ * @serialField scope_id_set boolean
+ * @serialField scope_ifname_set boolean
+ * @serialField ifname String
+ */
+
+ private static final ObjectStreamField[] serialPersistentFields = {
+ new ObjectStreamField("ipaddress", byte[].class),
+ new ObjectStreamField("scope_id", int.class),
+ new ObjectStreamField("scope_id_set", boolean.class),
+ new ObjectStreamField("scope_ifname_set", boolean.class),
+ new ObjectStreamField("ifname", String.class)
+ };
+
+ private static final long FIELDS_OFFSET;
+ private static final sun.misc.Unsafe UNSAFE;
+
+ static {
+ try {
+ sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
+ FIELDS_OFFSET = unsafe.objectFieldOffset(
+ Inet6Address.class.getDeclaredField("holder6"));
+ UNSAFE = unsafe;
+ } catch (ReflectiveOperationException e) {
+ throw new Error(e);
+ }
+ }
+
+ /**
* restore the state of this object from stream
* including the scope information, only if the
* scoped interface name is valid on this system
*/
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
- scope_ifname = null;
- scope_ifname_set = false;
+ NetworkInterface scope_ifname = null;
+ // Android-changed: was getClass().getClassLoader() != null
if (getClass().getClassLoader() != Class.class.getClassLoader()) {
throw new SecurityException ("invalid address type");
}
- s.defaultReadObject();
+ ObjectInputStream.GetField gf = s.readFields();
+ byte[] ipaddress = (byte[])gf.get("ipaddress", null);
+ int scope_id = (int)gf.get("scope_id", -1);
+ boolean scope_id_set = (boolean)gf.get("scope_id_set", false);
+ boolean scope_ifname_set = (boolean)gf.get("scope_ifname_set", false);
+ String ifname = (String)gf.get("ifname", null);
if (ifname != null && !"".equals (ifname)) {
try {
@@ -442,8 +620,9 @@
scope_ifname_set = false;
scope_id = 0;
} else {
+ scope_ifname_set = true;
try {
- scope_id = deriveNumericScope (scope_ifname);
+ scope_id = deriveNumericScope (ipaddress, scope_ifname);
} catch (UnknownHostException e) {
// typically should not happen, but it may be that
// the machine being used for deserialization has
@@ -451,8 +630,8 @@
}
}
} catch (SocketException e) {}
-
}
+
/* if ifname was not supplied, then the numeric info is used */
ipaddress = ipaddress.clone();
@@ -466,6 +645,35 @@
if (holder().getFamily() != AF_INET6) {
throw new InvalidObjectException("invalid address family type");
}
+
+ Inet6AddressHolder h = new Inet6AddressHolder(
+ ipaddress, scope_id, scope_id_set, scope_ifname, scope_ifname_set
+ );
+
+ UNSAFE.putObject(this, FIELDS_OFFSET, h);
+ }
+
+ /**
+ * default behavior is overridden in order to write the
+ * scope_ifname field as a String, rather than a NetworkInterface
+ * which is not serializable
+ */
+ private synchronized void writeObject(ObjectOutputStream s)
+ throws IOException
+ {
+ String ifname = null;
+
+ if (holder6.scope_ifname != null) {
+ ifname = holder6.scope_ifname.getName();
+ holder6.scope_ifname_set = true;
+ }
+ ObjectOutputStream.PutField pfields = s.putFields();
+ pfields.put("ipaddress", holder6.ipaddress);
+ pfields.put("scope_id", holder6.scope_id);
+ pfields.put("scope_id_set", holder6.scope_id_set);
+ pfields.put("scope_ifname_set", holder6.scope_ifname_set);
+ pfields.put("ifname", ifname);
+ s.writeFields();
}
/**
@@ -480,7 +688,7 @@
*/
@Override
public boolean isMulticastAddress() {
- return ((ipaddress[0] & 0xff) == 0xff);
+ return holder6.isMulticastAddress();
}
/**
@@ -493,11 +701,7 @@
*/
@Override
public boolean isAnyLocalAddress() {
- byte test = 0x00;
- for (int i = 0; i < INADDRSZ; i++) {
- test |= ipaddress[i];
- }
- return (test == 0x00);
+ return holder6.isAnyLocalAddress();
}
/**
@@ -510,11 +714,7 @@
*/
@Override
public boolean isLoopbackAddress() {
- byte test = 0x00;
- for (int i = 0; i < 15; i++) {
- test |= ipaddress[i];
- }
- return (test == 0x00) && (ipaddress[15] == 0x01);
+ return holder6.isLoopbackAddress();
}
/**
@@ -522,10 +722,16 @@
*
* @return a {@code boolean} indicating if the InetAddress is a link local
* address; or false if address is not a link local unicast address.
+ *
* @since 1.4
*/
@Override
public boolean isLinkLocalAddress() {
+ return holder6.isLinkLocalAddress();
+ }
+
+ /* static version of above */
+ static boolean isLinkLocalAddress(byte[] ipaddress) {
return ((ipaddress[0] & 0xff) == 0xfe
&& (ipaddress[1] & 0xc0) == 0x80);
}
@@ -540,6 +746,11 @@
*/
@Override
public boolean isSiteLocalAddress() {
+ return holder6.isSiteLocalAddress();
+ }
+
+ /* static version of above */
+ static boolean isSiteLocalAddress(byte[] ipaddress) {
return ((ipaddress[0] & 0xff) == 0xfe
&& (ipaddress[1] & 0xc0) == 0xc0);
}
@@ -555,8 +766,7 @@
*/
@Override
public boolean isMCGlobal() {
- return ((ipaddress[0] & 0xff) == 0xff
- && (ipaddress[1] & 0x0f) == 0x0e);
+ return holder6.isMCGlobal();
}
/**
@@ -570,8 +780,7 @@
*/
@Override
public boolean isMCNodeLocal() {
- return ((ipaddress[0] & 0xff) == 0xff
- && (ipaddress[1] & 0x0f) == 0x01);
+ return holder6.isMCNodeLocal();
}
/**
@@ -585,8 +794,7 @@
*/
@Override
public boolean isMCLinkLocal() {
- return ((ipaddress[0] & 0xff) == 0xff
- && (ipaddress[1] & 0x0f) == 0x02);
+ return holder6.isMCLinkLocal();
}
/**
@@ -600,35 +808,32 @@
*/
@Override
public boolean isMCSiteLocal() {
- return ((ipaddress[0] & 0xff) == 0xff
- && (ipaddress[1] & 0x0f) == 0x05);
+ return holder6.isMCSiteLocal();
}
/**
* Utility routine to check if the multicast address has organization scope.
*
- * @return a {@code boolean} indicating if the address has
- * is a multicast address of organization-local scope,
- * false if it is not of organization-local scope
- * or it is not a multicast address
+ * @return a {@code boolean} indicating if the address has is a multicast
+ * address of organization-local scope, false if it is not of
+ * organization-local scope or it is not a multicast address
+ *
* @since 1.4
*/
@Override
public boolean isMCOrgLocal() {
- return ((ipaddress[0] & 0xff) == 0xff
- && (ipaddress[1] & 0x0f) == 0x08);
+ return holder6.isMCOrgLocal();
}
-
/**
- * Returns the raw IP address of this {@code InetAddress}
- * object. The result is in network byte order: the highest order
- * byte of the address is in {@code getAddress()[0]}.
+ * Returns the raw IP address of this {@code InetAddress} object. The result
+ * is in network byte order: the highest order byte of the address is in
+ * {@code getAddress()[0]}.
*
* @return the raw IP address of this object.
*/
@Override
public byte[] getAddress() {
- return ipaddress.clone();
+ return holder6.ipaddress.clone();
}
/**
@@ -636,10 +841,11 @@
* an interface. If no scoped_id is set, the returned value is zero.
*
* @return the scopeId, or zero if not set.
+ *
* @since 1.5
*/
- public int getScopeId () {
- return scope_id;
+ public int getScopeId() {
+ return holder6.scope_id;
}
/**
@@ -649,30 +855,25 @@
* @return the scoped interface, or null if not set.
* @since 1.5
*/
- public NetworkInterface getScopedInterface () {
- return scope_ifname;
+ public NetworkInterface getScopedInterface() {
+ return holder6.scope_ifname;
}
/**
- * Returns the IP address string in textual presentation. If the instance was created
- * specifying a scope identifier then the scope id is appended to the IP address preceded by
- * a "%" (per-cent) character. This can be either a numeric value or a string, depending on which
- * was used to createthe instance.
+ * Returns the IP address string in textual presentation. If the instance
+ * was created specifying a scope identifier then the scope id is appended
+ * to the IP address preceded by a "%" (per-cent) character. This can be
+ * either a numeric value or a string, depending on which was used to create
+ * the instance.
*
* @return the raw IP address in a string format.
*/
@Override
public String getHostAddress() {
-
/* ----- BEGIN android -----
- getnameinfo returns smarter representations
- String s = numericToTextFormat(ipaddress);
- if (scope_ifname_set) {
- s = s + "%" + scope_ifname.getName();
- } else if (scope_id_set) {
- s = s + "%" + scope_id;
- }
- return s;*/
+ * getnameinfo returns smarter representations
+ return holder6.getHostAddress();
+ */
return Libcore.os.getnameinfo(this, NI_NUMERICHOST); // Can't throw.
// ----- END android -----
@@ -685,81 +886,51 @@
*/
@Override
public int hashCode() {
- if (ipaddress != null) {
-
- int hash = 0;
- int i=0;
- while (i<INADDRSZ) {
- int j=0;
- int component=0;
- while (j<4 && i<INADDRSZ) {
- component = (component << 8) + ipaddress[i];
- j++;
- i++;
- }
- hash += component;
- }
- return hash;
-
- } else {
- return 0;
- }
+ return holder6.hashCode();
}
/**
- * Compares this object against the specified object.
- * The result is {@code true} if and only if the argument is
- * not {@code null} and it represents the same IP address as
- * this object.
- * <p>
- * Two instances of {@code InetAddress} represent the same IP
- * address if the length of the byte arrays returned by
- * {@code getAddress} is the same for both, and each of the
- * array components is the same for the byte arrays.
+ * Compares this object against the specified object. The result is {@code
+ * true} if and only if the argument is not {@code null} and it represents
+ * the same IP address as this object.
+ *
+ * <p> Two instances of {@code InetAddress} represent the same IP address
+ * if the length of the byte arrays returned by {@code getAddress} is the
+ * same for both, and each of the array components is the same for the byte
+ * arrays.
*
* @param obj the object to compare against.
- * @return {@code true} if the objects are the same;
- * {@code false} otherwise.
+ *
+ * @return {@code true} if the objects are the same; {@code false} otherwise.
+ *
* @see java.net.InetAddress#getAddress()
*/
@Override
public boolean equals(Object obj) {
- if (obj == null ||
- !(obj instanceof Inet6Address))
+ if (obj == null || !(obj instanceof Inet6Address))
return false;
Inet6Address inetAddr = (Inet6Address)obj;
- for (int i = 0; i < INADDRSZ; i++) {
- if (ipaddress[i] != inetAddr.ipaddress[i])
- return false;
- }
-
- return true;
+ return holder6.equals(inetAddr.holder6);
}
/**
* Utility routine to check if the InetAddress is an
* IPv4 compatible IPv6 address.
*
- * @return a {@code boolean} indicating if the InetAddress is
- * an IPv4 compatible IPv6 address; or false if address is IPv4 address.
+ * @return a {@code boolean} indicating if the InetAddress is an IPv4
+ * compatible IPv6 address; or false if address is IPv4 address.
+ *
* @since 1.4
*/
public boolean isIPv4CompatibleAddress() {
- if ((ipaddress[0] == 0x00) && (ipaddress[1] == 0x00) &&
- (ipaddress[2] == 0x00) && (ipaddress[3] == 0x00) &&
- (ipaddress[4] == 0x00) && (ipaddress[5] == 0x00) &&
- (ipaddress[6] == 0x00) && (ipaddress[7] == 0x00) &&
- (ipaddress[8] == 0x00) && (ipaddress[9] == 0x00) &&
- (ipaddress[10] == 0x00) && (ipaddress[11] == 0x00)) {
- return true;
- }
- return false;
+ return holder6.isIPv4CompatibleAddress();
}
// Utilities
private final static int INT16SZ = 2;
+
/*
* Convert IPv6 binary address into presentation (printable) format.
*
@@ -768,36 +939,15 @@
* textual representation format
* @since 1.4
*/
- static String numericToTextFormat(byte[] src)
- {
- StringBuffer sb = new StringBuffer(39);
+ static String numericToTextFormat(byte[] src) {
+ StringBuilder sb = new StringBuilder(39);
for (int i = 0; i < (INADDRSZ / INT16SZ); i++) {
sb.append(Integer.toHexString(((src[i<<1]<<8) & 0xff00)
| (src[(i<<1)+1] & 0xff)));
-
if (i < (INADDRSZ / INT16SZ) -1 ) {
sb.append(":");
}
}
return sb.toString();
}
-
- /**
- * Following field is only used during (de)/serialization
- */
- private String ifname;
-
- /**
- * default behavior is overridden in order to write the
- * scope_ifname field as a String, rather than a NetworkInterface
- * which is not serializable
- */
- private synchronized void writeObject(java.io.ObjectOutputStream s)
- throws IOException
- {
- if (scope_ifname_set) {
- ifname = scope_ifname.getName();
- }
- s.defaultWriteObject();
- }
}
diff --git a/ojluni/src/main/java/java/net/InetAddress.java b/ojluni/src/main/java/java/net/InetAddress.java
index edfdb00..b5dc761 100644
--- a/ojluni/src/main/java/java/net/InetAddress.java
+++ b/ojluni/src/main/java/java/net/InetAddress.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -208,6 +208,14 @@
this.family = family;
}
+ void init(String hostName, int family) {
+ this.originalHostName = hostName;
+ this.hostName = hostName;
+ if (family != -1) {
+ this.family = family;
+ }
+ }
+
String hostName;
String getHostName() {
diff --git a/ojluni/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java b/ojluni/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java
index d86bbbc..e50cfd2 100644
--- a/ojluni/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java
+++ b/ojluni/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -30,8 +30,8 @@
/**
* An interface to an object capable of generating DSA key pairs.
*
- * <p>The <code>initialize</code> methods may each be called any number
- * of times. If no <code>initialize</code> method is called on a
+ * <p>The {@code initialize} methods may each be called any number
+ * of times. If no {@code initialize} method is called on a
* DSAKeyPairGenerator, the default is to generate 1024-bit keys, using
* precomputed p, q and g parameters and an instance of SecureRandom as
* the random bit source.
@@ -42,26 +42,29 @@
* <ol>
*
* <li>Get a key pair generator for the DSA algorithm by calling the
- * KeyPairGenerator <code>getInstance</code> method with "DSA"
- * as its argument.<p>
+ * KeyPairGenerator {@code getInstance} method with "DSA"
+ * as its argument.
*
* <li>Initialize the generator by casting the result to a DSAKeyPairGenerator
* and calling one of the
- * <code>initialize</code> methods from this DSAKeyPairGenerator interface.<p>
+ * {@code initialize} methods from this DSAKeyPairGenerator interface.
*
- * <li>Generate a key pair by calling the <code>generateKeyPair</code>
+ * <li>Generate a key pair by calling the {@code generateKeyPair}
* method from the KeyPairGenerator class.
*
* </ol>
*
* <p>Note: it is not always necessary to do do algorithm-specific
* initialization for a DSA key pair generator. That is, it is not always
- * necessary to call an <code>initialize</code> method in this interface.
- * Algorithm-independent initialization using the <code>initialize</code> method
+ * necessary to call an {@code initialize} method in this interface.
+ * Algorithm-independent initialization using the {@code initialize} method
* in the KeyPairGenerator
* interface is all that is needed when you accept defaults for algorithm-specific
* parameters.
*
+ * <p>Note: Some earlier implementations of this interface may not support
+ * larger sizes of DSA parameters such as 2048 and 3072-bit.
+ *
* @see java.security.KeyPairGenerator
*/
public interface DSAKeyPairGenerator {
@@ -77,8 +80,8 @@
* @param random the random bit source to use to generate key bits;
* can be null.
*
- * @exception InvalidParameterException if the <code>params</code>
- * value is invalid or null.
+ * @exception InvalidParameterException if the {@code params}
+ * value is invalid, null, or unsupported.
*/
public void initialize(DSAParams params, SecureRandom random)
throws InvalidParameterException;
@@ -89,7 +92,7 @@
* If a SecureRandom bit source is needed but not supplied, i.e.
* null, a default SecureRandom instance will be used.
*
- * <p>If <code>genParams</code> is true, this method generates new
+ * <p>If {@code genParams} is true, this method generates new
* p, q and g parameters. If it is false, the method uses precomputed
* parameters for the modulus length requested. If there are no
* precomputed parameters for that modulus length, an exception will be
@@ -97,7 +100,7 @@
* default parameters for modulus lengths of 512 and 1024 bits.
*
* @param modlen the modulus length in bits. Valid values are any
- * multiple of 8 between 512 and 1024, inclusive.
+ * multiple of 64 between 512 and 1024, inclusive, 2048, and 3072.
*
* @param random the random bit source to use to generate key bits;
* can be null.
@@ -105,10 +108,9 @@
* @param genParams whether or not to generate new parameters for
* the modulus length requested.
*
- * @exception InvalidParameterException if <code>modlen</code> is not
- * between 512 and 1024, or if <code>genParams</code> is false and
- * there are no precomputed parameters for the requested modulus
- * length.
+ * @exception InvalidParameterException if {@code modlen} is
+ * invalid, or unsupported, or if {@code genParams} is false and there
+ * are no precomputed parameters for the requested modulus length.
*/
public void initialize(int modlen, boolean genParams, SecureRandom random)
throws InvalidParameterException;
diff --git a/ojluni/src/main/java/java/security/interfaces/DSAParams.java b/ojluni/src/main/java/java/security/interfaces/DSAParams.java
index f20b8ec..b672ad5 100644
--- a/ojluni/src/main/java/java/security/interfaces/DSAParams.java
+++ b/ojluni/src/main/java/java/security/interfaces/DSAParams.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -42,23 +42,23 @@
public interface DSAParams {
/**
- * Returns the prime, <code>p</code>.
+ * Returns the prime, {@code p}.
*
- * @return the prime, <code>p</code>.
+ * @return the prime, {@code p}.
*/
public BigInteger getP();
/**
- * Returns the subprime, <code>q</code>.
+ * Returns the subprime, {@code q}.
*
- * @return the subprime, <code>q</code>.
+ * @return the subprime, {@code q}.
*/
public BigInteger getQ();
/**
- * Returns the base, <code>g</code>.
+ * Returns the base, {@code g}.
*
- * @return the base, <code>g</code>.
+ * @return the base, {@code g}.
*/
public BigInteger getG();
}
diff --git a/ojluni/src/main/java/java/security/interfaces/DSAPrivateKey.java b/ojluni/src/main/java/java/security/interfaces/DSAPrivateKey.java
index a0d1893..81ab358 100644
--- a/ojluni/src/main/java/java/security/interfaces/DSAPrivateKey.java
+++ b/ojluni/src/main/java/java/security/interfaces/DSAPrivateKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -50,9 +50,9 @@
static final long serialVersionUID = 7776497482533790279L;
/**
- * Returns the value of the private key, <code>x</code>.
+ * Returns the value of the private key, {@code x}.
*
- * @return the value of the private key, <code>x</code>.
+ * @return the value of the private key, {@code x}.
*/
public BigInteger getX();
}
diff --git a/ojluni/src/main/java/java/security/interfaces/DSAPublicKey.java b/ojluni/src/main/java/java/security/interfaces/DSAPublicKey.java
index b273738..e56b795 100644
--- a/ojluni/src/main/java/java/security/interfaces/DSAPublicKey.java
+++ b/ojluni/src/main/java/java/security/interfaces/DSAPublicKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -50,9 +50,9 @@
static final long serialVersionUID = 1234526332779022332L;
/**
- * Returns the value of the public key, <code>y</code>.
+ * Returns the value of the public key, {@code y}.
*
- * @return the value of the public key, <code>y</code>.
+ * @return the value of the public key, {@code y}.
*/
public BigInteger getY();
}
diff --git a/ojluni/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java b/ojluni/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java
index 19cddce..f85d96a 100644
--- a/ojluni/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java
+++ b/ojluni/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2013, 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
@@ -46,6 +46,11 @@
public interface RSAMultiPrimePrivateCrtKey extends RSAPrivateKey {
+ /**
+ * The type fingerprint that is set to indicate
+ * serialization compatibility with a previous
+ * version of the type.
+ */
static final long serialVersionUID = 618058533534628008L;
/**
diff --git a/ojluni/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java b/ojluni/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java
index 670af46..0408fea 100644
--- a/ojluni/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java
+++ b/ojluni/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, 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
@@ -39,6 +39,11 @@
public interface RSAPrivateCrtKey extends RSAPrivateKey {
+ /**
+ * The type fingerprint that is set to indicate
+ * serialization compatibility with a previous
+ * version of the type.
+ */
static final long serialVersionUID = -5682214253527700368L;
/**
diff --git a/ojluni/src/main/java/java/security/interfaces/RSAPrivateKey.java b/ojluni/src/main/java/java/security/interfaces/RSAPrivateKey.java
index 522c5ba..5d69ad6 100644
--- a/ojluni/src/main/java/java/security/interfaces/RSAPrivateKey.java
+++ b/ojluni/src/main/java/java/security/interfaces/RSAPrivateKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, 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
@@ -39,6 +39,11 @@
public interface RSAPrivateKey extends java.security.PrivateKey, RSAKey
{
+ /**
+ * The type fingerprint that is set to indicate
+ * serialization compatibility with a previous
+ * version of the type.
+ */
static final long serialVersionUID = 5187144804936595022L;
/**
diff --git a/ojluni/src/main/java/java/security/interfaces/RSAPublicKey.java b/ojluni/src/main/java/java/security/interfaces/RSAPublicKey.java
index 04d80cf..a698c05 100644
--- a/ojluni/src/main/java/java/security/interfaces/RSAPublicKey.java
+++ b/ojluni/src/main/java/java/security/interfaces/RSAPublicKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, 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
@@ -36,6 +36,11 @@
public interface RSAPublicKey extends java.security.PublicKey, RSAKey
{
+ /**
+ * The type fingerprint that is set to indicate
+ * serialization compatibility with a previous
+ * version of the type.
+ */
static final long serialVersionUID = -8727434096241101194L;
/**
diff --git a/ojluni/src/main/java/java/security/interfaces/package-info.java b/ojluni/src/main/java/java/security/interfaces/package-info.java
new file mode 100644
index 0000000..a2d77da
--- /dev/null
+++ b/ojluni/src/main/java/java/security/interfaces/package-info.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1998, 2013, 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.
+ */
+
+/**
+ * Provides interfaces for generating RSA (Rivest, Shamir and
+ * Adleman AsymmetricCipher algorithm)
+ * keys as defined in the RSA Laboratory Technical Note
+ * PKCS#1, and DSA (Digital Signature
+ * Algorithm) keys as defined in NIST's FIPS-186.
+ * <P>
+ * Note that these interfaces are intended only for key
+ * implementations whose key material is accessible and
+ * available. These interfaces are not intended for key
+ * implementations whose key material resides in
+ * inaccessible, protected storage (such as in a
+ * hardware device).
+ * <P>
+ * For more developer information on how to use these
+ * interfaces, including information on how to design
+ * {@code Key} classes for hardware devices, please refer
+ * to these cryptographic provider developer guides:
+ * <ul>
+ * <li><a href=
+ * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/crypto/HowToImplAProvider.html">
+ * <b>How to Implement a Provider for the
+ * Java™ Cryptography Architecture
+ * </b></a></li>
+ * </ul>
+ *
+ * <h2>Package Specification</h2>
+ *
+ * <ul>
+ * <li>PKCS #1: RSA Encryption Standard, Version 1.5, November 1993 </li>
+ * <li>Federal Information Processing Standards Publication (FIPS PUB) 186:
+ * Digital Signature Standard (DSS) </li>
+ * </ul>
+ *
+ * <h2>Related Documentation</h2>
+ *
+ * For further documentation, please see:
+ * <ul>
+ * <li>
+ * <a href=
+ * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/crypto/CryptoSpec.html">
+ * <b>Java™
+ * Cryptography Architecture API Specification and Reference
+ * </b></a></li>
+ * </ul>
+ *
+ * @since JDK1.1
+ */
+package java.security.interfaces;
diff --git a/ojluni/src/main/native/Inet6Address.c b/ojluni/src/main/native/Inet6Address.c
index ad2d978..6f0ac57 100644
--- a/ojluni/src/main/native/Inet6Address.c
+++ b/ojluni/src/main/native/Inet6Address.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -36,30 +36,33 @@
*/
jclass ia6_class;
+jfieldID ia6_holder6ID;
+
jfieldID ia6_ipaddressID;
jfieldID ia6_scopeidID;
jfieldID ia6_scopeidsetID;
jfieldID ia6_scopeifnameID;
-jfieldID ia6_scopeifnamesetID;
jmethodID ia6_ctrID;
static void Inet6Address_init(JNIEnv *env) {
+ jclass ia6h_class;
jclass c = (*env)->FindClass(env, "java/net/Inet6Address");
CHECK_NULL(c);
ia6_class = (*env)->NewGlobalRef(env, c);
CHECK_NULL(ia6_class);
- ia6_ipaddressID = (*env)->GetFieldID(env, ia6_class, "ipaddress", "[B");
+ ia6h_class = (*env)->FindClass(env, "java/net/Inet6Address$Inet6AddressHolder");
+ CHECK_NULL(ia6h_class);
+ ia6_holder6ID = (*env)->GetFieldID(env, ia6_class, "holder6", "Ljava/net/Inet6Address$Inet6AddressHolder;");
+ CHECK_NULL(ia6_holder6ID);
+ ia6_ipaddressID = (*env)->GetFieldID(env, ia6h_class, "ipaddress", "[B");
CHECK_NULL(ia6_ipaddressID);
- ia6_scopeidID = (*env)->GetFieldID(env, ia6_class, "scope_id", "I");
+ ia6_scopeidID = (*env)->GetFieldID(env, ia6h_class, "scope_id", "I");
CHECK_NULL(ia6_scopeidID);
- ia6_scopeidsetID = (*env)->GetFieldID(env, ia6_class, "scope_id_set", "Z");
- CHECK_NULL(ia6_scopeidID);
- ia6_scopeifnameID = (*env)->GetFieldID(env, ia6_class, "scope_ifname", "Ljava/net/NetworkInterface;");
+ ia6_scopeidsetID = (*env)->GetFieldID(env, ia6h_class, "scope_id_set", "Z");
+ CHECK_NULL(ia6_scopeidsetID);
+ ia6_scopeifnameID = (*env)->GetFieldID(env, ia6h_class, "scope_ifname", "Ljava/net/NetworkInterface;");
CHECK_NULL(ia6_scopeifnameID);
- ia6_scopeifnamesetID = (*env)->GetFieldID(env, ia6_class, "scope_ifname_set", "Z");
- CHECK_NULL(ia6_scopeifnamesetID);
ia6_ctrID = (*env)->GetMethodID(env, ia6_class, "<init>", "()V");
- CHECK_NULL(ia6_ctrID);
}
void register_java_net_Inet6Address(JNIEnv* env) {
diff --git a/ojluni/src/main/native/Inet6AddressImpl.c b/ojluni/src/main/native/Inet6AddressImpl.c
index f57a8d2..85f2314 100644
--- a/ojluni/src/main/native/Inet6AddressImpl.c
+++ b/ojluni/src/main/native/Inet6AddressImpl.c
@@ -65,8 +65,6 @@
static jclass ni_ia6cls;
static jmethodID ni_ia4ctrID;
static jmethodID ni_ia6ctrID;
-static jfieldID ni_ia6ipaddressID;
-static int initialized = 0;
/*
* Class: java_net_Inet6AddressImpl
diff --git a/ojluni/src/main/native/NetworkInterface.c b/ojluni/src/main/native/NetworkInterface.c
index 0daf4db..5879df4 100644
--- a/ojluni/src/main/native/NetworkInterface.c
+++ b/ojluni/src/main/native/NetworkInterface.c
@@ -101,7 +101,6 @@
static jmethodID ni_ia4ctrID;
static jmethodID ni_ia6ctrID;
static jmethodID ni_ibctrID;
-static jfieldID ni_ia6ipaddressID;
static jfieldID ni_ibaddressID;
static jfieldID ni_ib4broadcastID;
static jfieldID ni_ib4maskID;
@@ -147,7 +146,6 @@
ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V");
- ni_ia6ipaddressID = (*env)->GetFieldID(env, ni_ia6cls, "ipaddress", "[B");
ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
ni_ib4broadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
@@ -281,11 +279,9 @@
if (family == AF_INET6) {
jbyte *bytes = (jbyte *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr);
- jbyteArray ipaddress = (*env)->GetObjectField(env, iaObj, ni_ia6ipaddressID);
jbyte caddr[16];
int i;
-
- (*env)->GetByteArrayRegion(env, ipaddress, 0, 16, caddr);
+ getInet6Address_ipaddress(env, iaObj, (char *)caddr);
i = 0;
while (i < 16) {
if (caddr[i] != bytes[i]) {
@@ -478,21 +474,15 @@
int scope=0;
iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
if (iaObj) {
- jbyteArray ipaddress = (*env)->NewByteArray(env, 16);
- if (ipaddress == NULL) {
+ int ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
+ if (ret == JNI_FALSE) {
return NULL;
}
- (*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
- (jbyte *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
-
scope = ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id;
-
if (scope != 0) { /* zero is default value, no need to set */
- (*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
- (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
- (*env)->SetObjectField(env, iaObj, ia6_scopeifnameID, netifObj);
+ setInet6Address_scopeid(env, iaObj, scope);
+ setInet6Address_scopeifname(env, iaObj, netifObj);
}
- (*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress);
}
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
if (ibObj) {
diff --git a/ojluni/src/main/native/PlainDatagramSocketImpl.c b/ojluni/src/main/native/PlainDatagramSocketImpl.c
index c04acc6..d7edb5f 100644
--- a/ojluni/src/main/native/PlainDatagramSocketImpl.c
+++ b/ojluni/src/main/native/PlainDatagramSocketImpl.c
@@ -1847,8 +1847,8 @@
caddr[14] = ((address >> 8) & 0xff);
caddr[15] = (address & 0xff);
} else {
- ipaddress = (*env)->GetObjectField(env, iaObj, ia6_ipaddressID);
- (*env)->GetByteArrayRegion(env, ipaddress, 0, 16, caddr);
+ // Android-changed: explicit cast to suppress compiler warning.
+ getInet6Address_ipaddress(env, iaObj, (char*)caddr);
}
memcpy((void *)&(mname6.ipv6mr_multiaddr), caddr, sizeof(struct in6_addr));
diff --git a/ojluni/src/main/native/net_util.c b/ojluni/src/main/native/net_util.c
index a656ed3..af6a893 100644
--- a/ojluni/src/main/native/net_util.c
+++ b/ojluni/src/main/native/net_util.c
@@ -72,26 +72,116 @@
extern jfieldID iac_addressID;
extern jfieldID iac_familyID;
+/**
+ * set_ methods return JNI_TRUE on success JNI_FALSE on error
+ * get_ methods that return +ve int return -1 on error
+ * get_ methods that return objects return NULL on error.
+ */
+jobject getInet6Address_scopeifname(JNIEnv *env, jobject iaObj) {
+ jobject holder;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, NULL);
+ return (*env)->GetObjectField(env, holder, ia6_scopeifnameID);
+}
+
+int setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) {
+ jobject holder;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, JNI_FALSE);
+ (*env)->SetObjectField(env, holder, ia6_scopeifnameID, scopeifname);
+ return JNI_TRUE;
+}
+
+int getInet6Address_scopeid_set(JNIEnv *env, jobject iaObj) {
+ jobject holder;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, -1);
+ return (*env)->GetBooleanField(env, holder, ia6_scopeidsetID);
+}
+
+int getInet6Address_scopeid(JNIEnv *env, jobject iaObj) {
+ jobject holder;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, -1);
+ return (*env)->GetIntField(env, holder, ia6_scopeidID);
+}
+
+int setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) {
+ jobject holder;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, JNI_FALSE);
+ (*env)->SetIntField(env, holder, ia6_scopeidID, scopeid);
+ if (scopeid > 0) {
+ (*env)->SetBooleanField(env, holder, ia6_scopeidsetID, JNI_TRUE);
+ }
+ return JNI_TRUE;
+}
+
+
+int getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) {
+ jobject holder, addr;
+ jbyteArray barr;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, JNI_FALSE);
+ addr = (*env)->GetObjectField(env, holder, ia6_ipaddressID);
+ CHECK_NULL_RETURN(addr, JNI_FALSE);
+ (*env)->GetByteArrayRegion(env, addr, 0, 16, (jbyte *)dest);
+ return JNI_TRUE;
+}
+
+int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) {
+ jobject holder;
+ jbyteArray addr;
+
+ // Android-changed: initInetAddrs(env);
+ holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+ CHECK_NULL_RETURN(holder, JNI_FALSE);
+ addr = (jbyteArray)(*env)->GetObjectField(env, holder, ia6_ipaddressID);
+ if (addr == NULL) {
+ addr = (*env)->NewByteArray(env, 16);
+ CHECK_NULL_RETURN(addr, JNI_FALSE);
+ (*env)->SetObjectField(env, holder, ia6_ipaddressID, addr);
+ }
+ (*env)->SetByteArrayRegion(env, addr, 0, 16, (jbyte *)address);
+ return JNI_TRUE;
+}
+
void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) {
jobject holder;
+ // Android-changed: initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
(*env)->SetIntField(env, holder, iac_addressID, address);
}
void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) {
jobject holder;
+ // Android-changed: initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
(*env)->SetIntField(env, holder, iac_familyID, family);
}
void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) {
jobject holder;
+ // Android-changed: initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
(*env)->SetObjectField(env, holder, iac_hostNameID, host);
}
int getInetAddress_addr(JNIEnv *env, jobject iaObj) {
jobject holder;
+ // Android-changed: initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
return (*env)->GetIntField(env, holder, iac_addressID);
}
@@ -99,12 +189,14 @@
int getInetAddress_family(JNIEnv *env, jobject iaObj) {
jobject holder;
+ // Android-changed: initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
return (*env)->GetIntField(env, holder, iac_familyID);
}
jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
jobject holder;
+ // Android-changed: initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
return (*env)->GetObjectField(env, holder, iac_hostNameID);
}
@@ -112,6 +204,7 @@
JNIEXPORT jobject JNICALL
NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
jobject iaObj;
+ // Android-changed: initInetAddrs(env);
#ifdef AF_INET6
if (him->sa_family == AF_INET6) {
jbyteArray ipaddress;
@@ -139,6 +232,7 @@
} else {
static jclass inet6Cls = 0;
jint scope;
+ int ret;
if (inet6Cls == 0) {
jclass c = (*env)->FindClass(env, "java/net/Inet6Address");
CHECK_NULL_RETURN(c, NULL);
@@ -148,18 +242,13 @@
}
iaObj = (*env)->NewObject(env, inet6Cls, ia6_ctrID);
CHECK_NULL_RETURN(iaObj, NULL);
- ipaddress = (*env)->NewByteArray(env, 16);
- CHECK_NULL_RETURN(ipaddress, NULL);
- (*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
- (jbyte *)&(him6->sin6_addr));
-
- (*env)->SetObjectField(env, iaObj, ia6_ipaddressID, ipaddress);
-
+ ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
+ // Android-changed: Appease compiler type checking.
+ // CHECK_NULL_RETURN(ret, NULL);
+ if (ret == JNI_FALSE) return NULL;
setInetAddress_family(env, iaObj, IPv6);
scope = getScopeID(him);
- (*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
- if (scope > 0)
- (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
+ setInet6Address_scopeid(env, iaObj, scope);
}
*port = ntohs(him6->sin6_port);
} else
@@ -225,9 +314,8 @@
if (family == AF_INET) {
return JNI_FALSE;
}
- ipaddress = (*env)->GetObjectField(env, iaObj, ia6_ipaddressID);
- scope = (*env)->GetIntField(env, iaObj, ia6_scopeidID);
- (*env)->GetByteArrayRegion(env, ipaddress, 0, 16, caddrCur);
+ scope = getInet6Address_scopeid(env, iaObj);
+ getInet6Address_ipaddress(env, iaObj, (char *)caddrCur);
if (NET_IsEqual(caddrNew, caddrCur) && cmpScopeID(scope, him)) {
return JNI_TRUE;
} else {
diff --git a/ojluni/src/main/native/net_util.h b/ojluni/src/main/native/net_util.h
index 2f5cffd..8888877 100644
--- a/ojluni/src/main/native/net_util.h
+++ b/ojluni/src/main/native/net_util.h
@@ -58,6 +58,19 @@
extern jfieldID iac_hostNameID;
extern jfieldID ia_preferIPv6AddressID;
+/** (Inet6Address accessors)
+ * set_ methods return JNI_TRUE on success JNI_FALSE on error
+ * get_ methods that return int/boolean, return -1 on error
+ * get_ methods that return objects return NULL on error.
+ */
+extern jobject getInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj);
+extern int setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname);
+extern int getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj);
+extern int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj);
+extern int setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid);
+extern int getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest);
+extern int setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address);
+
extern void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address);
extern void setInetAddress_family(JNIEnv *env, jobject iaObj, int family);
extern void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject h);
@@ -93,11 +106,11 @@
/* Inet6Address fields */
extern jclass ia6_class;
+extern jfieldID ia6_holder6ID;
extern jfieldID ia6_ipaddressID;
extern jfieldID ia6_scopeidID;
extern jfieldID ia6_scopeidsetID;
extern jfieldID ia6_scopeifnameID;
-extern jfieldID ia6_scopeifnamesetID;
extern jmethodID ia6_ctrID;
/************************************************************************
diff --git a/ojluni/src/main/native/net_util_md.c b/ojluni/src/main/native/net_util_md.c
index d45a0e6..f1d60fe 100644
--- a/ojluni/src/main/native/net_util_md.c
+++ b/ojluni/src/main/native/net_util_md.c
@@ -772,8 +772,7 @@
caddr[15] = (address & 0xff);
}
} else {
- ipaddress = (*env)->GetObjectField(env, iaObj, ia6_ipaddressID);
- (*env)->GetByteArrayRegion(env, ipaddress, 0, 16, caddr);
+ getInet6Address_ipaddress(env, iaObj, (char *)caddr);
}
memset((char *)him6, 0, sizeof(struct sockaddr_in6));
him6->sin6_port = htons(port);
@@ -791,7 +790,7 @@
// was constructed with a specific scope_id or NetworkInterface).
if (family != IPv4) {
if (ia6_scopeidID) {
- int scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_scopeidID);
+ int scope_id = getInet6Address_scopeid(env, iaObj);
if (scope_id > 0) {
him6->sin6_scope_id = scope_id;
}
diff --git a/openjdk_java_files.mk b/openjdk_java_files.mk
index abe9e34..0f5f09b 100644
--- a/openjdk_java_files.mk
+++ b/openjdk_java_files.mk
@@ -590,6 +590,7 @@
ojluni/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java \
ojluni/src/main/java/java/security/interfaces/RSAPrivateKey.java \
ojluni/src/main/java/java/security/interfaces/RSAPublicKey.java \
+ ojluni/src/main/java/java/security/interfaces/package-info.java \
ojluni/src/main/java/java/security/InvalidAlgorithmParameterException.java \
ojluni/src/main/java/java/security/InvalidKeyException.java \
ojluni/src/main/java/java/security/InvalidParameterException.java \