Loading wifi/java/android/net/wifi/hotspot2/pps/Credential.java +9 −1 Original line number Diff line number Diff line Loading @@ -1216,7 +1216,15 @@ public final class Credential implements Parcelable { Arrays.equals(key1.getEncoded(), key2.getEncoded()); } private static boolean isX509CertificateEquals(X509Certificate cert1, X509Certificate cert2) { /** * Verify two X.509 certificates are identical. * * @param cert1 a certificate to compare * @param cert2 a certificate to compare * @return {@code true} if given certificates are the same each other, {@code false} otherwise. * @hide */ public static boolean isX509CertificateEquals(X509Certificate cert1, X509Certificate cert2) { if (cert1 == null && cert2 == null) { return true; } Loading wifi/java/android/net/wifi/hotspot2/pps/UpdateParameter.java +34 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.net.wifi.hotspot2.pps; import android.net.wifi.ParcelUtil; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; Loading @@ -23,6 +24,7 @@ import android.util.Base64; import android.util.Log; import java.nio.charset.StandardCharsets; import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Objects; Loading Loading @@ -167,7 +169,7 @@ public final class UpdateParameter implements Parcelable { } /** * SHA-256 fingerprint of the certificate located at {@link #trustRootCertUrl} * SHA-256 fingerprint of the certificate located at {@code mTrustRootCertUrl} */ private byte[] mTrustRootCertSha256Fingerprint = null; public void setTrustRootCertSha256Fingerprint(byte[] fingerprint) { Loading @@ -177,6 +179,31 @@ public final class UpdateParameter implements Parcelable { return mTrustRootCertSha256Fingerprint; } /** * CA (Certificate Authority) X509 certificates. */ private X509Certificate mCaCertificate; /** * Set the CA (Certification Authority) certificate associated with Policy/Subscription update. * * @param caCertificate The CA certificate to set * @hide */ public void setCaCertificate(X509Certificate caCertificate) { mCaCertificate = caCertificate; } /** * Get the CA (Certification Authority) certificate associated with Policy/Subscription update. * * @return CA certificate associated and {@code null} if certificate is not set. * @hide */ public X509Certificate getCaCertificate() { return mCaCertificate; } /** * Constructor for creating Policy with default values. */ Loading @@ -202,6 +229,7 @@ public final class UpdateParameter implements Parcelable { mTrustRootCertSha256Fingerprint = Arrays.copyOf(source.mTrustRootCertSha256Fingerprint, source.mTrustRootCertSha256Fingerprint.length); } mCaCertificate = source.mCaCertificate; } @Override Loading @@ -219,6 +247,7 @@ public final class UpdateParameter implements Parcelable { dest.writeString(mBase64EncodedPassword); dest.writeString(mTrustRootCertUrl); dest.writeByteArray(mTrustRootCertSha256Fingerprint); ParcelUtil.writeCertificate(dest, mCaCertificate); } @Override Loading @@ -239,14 +268,15 @@ public final class UpdateParameter implements Parcelable { && TextUtils.equals(mBase64EncodedPassword, that.mBase64EncodedPassword) && TextUtils.equals(mTrustRootCertUrl, that.mTrustRootCertUrl) && Arrays.equals(mTrustRootCertSha256Fingerprint, that.mTrustRootCertSha256Fingerprint); that.mTrustRootCertSha256Fingerprint) && Credential.isX509CertificateEquals(mCaCertificate, that.mCaCertificate); } @Override public int hashCode() { return Objects.hash(mUpdateIntervalInMinutes, mUpdateMethod, mRestriction, mServerUri, mUsername, mBase64EncodedPassword, mTrustRootCertUrl, mTrustRootCertSha256Fingerprint); Arrays.hashCode(mTrustRootCertSha256Fingerprint), mCaCertificate); } @Override Loading Loading @@ -361,6 +391,7 @@ public final class UpdateParameter implements Parcelable { updateParam.setBase64EncodedPassword(in.readString()); updateParam.setTrustRootCertUrl(in.readString()); updateParam.setTrustRootCertSha256Fingerprint(in.createByteArray()); updateParam.setCaCertificate(ParcelUtil.readCertificate(in)); return updateParam; } Loading wifi/tests/src/android/net/wifi/hotspot2/pps/CredentialTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -541,4 +541,20 @@ public class CredentialTest { Credential copyCred = new Credential(sourceCred); assertTrue(copyCred.equals(sourceCred)); } /** * Verify that two certificates are identical. */ @Test public void validateTwoCertificateIdentical() { assertTrue(Credential.isX509CertificateEquals(FakeKeys.CA_CERT1, FakeKeys.CA_CERT1)); } /** * Verify that two certificates are different. */ @Test public void validateTwoCertificateDifferent() { assertFalse(Credential.isX509CertificateEquals(FakeKeys.CA_CERT0, FakeKeys.CA_CERT1)); } } wifi/tests/src/android/net/wifi/hotspot2/pps/UpdateParameterTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,11 @@ package android.net.wifi.hotspot2.pps; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.net.wifi.FakeKeys; import android.os.Parcel; import android.util.Base64; Loading Loading @@ -56,6 +58,7 @@ public class UpdateParameterTest { Base64.encodeToString("password".getBytes(), Base64.DEFAULT)); updateParam.setTrustRootCertUrl("trust.cert.com"); updateParam.setTrustRootCertSha256Fingerprint(new byte[32]); updateParam.setCaCertificate(FakeKeys.CA_CERT0); return updateParam; } Loading @@ -71,6 +74,7 @@ public class UpdateParameterTest { parcel.setDataPosition(0); // Rewind data position back to the beginning for read. UpdateParameter paramFromRead = UpdateParameter.CREATOR.createFromParcel(parcel); assertTrue(paramFromRead.equals(paramToWrite)); assertEquals(paramToWrite.hashCode(), paramFromRead.hashCode()); } /** Loading Loading
wifi/java/android/net/wifi/hotspot2/pps/Credential.java +9 −1 Original line number Diff line number Diff line Loading @@ -1216,7 +1216,15 @@ public final class Credential implements Parcelable { Arrays.equals(key1.getEncoded(), key2.getEncoded()); } private static boolean isX509CertificateEquals(X509Certificate cert1, X509Certificate cert2) { /** * Verify two X.509 certificates are identical. * * @param cert1 a certificate to compare * @param cert2 a certificate to compare * @return {@code true} if given certificates are the same each other, {@code false} otherwise. * @hide */ public static boolean isX509CertificateEquals(X509Certificate cert1, X509Certificate cert2) { if (cert1 == null && cert2 == null) { return true; } Loading
wifi/java/android/net/wifi/hotspot2/pps/UpdateParameter.java +34 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.net.wifi.hotspot2.pps; import android.net.wifi.ParcelUtil; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; Loading @@ -23,6 +24,7 @@ import android.util.Base64; import android.util.Log; import java.nio.charset.StandardCharsets; import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Objects; Loading Loading @@ -167,7 +169,7 @@ public final class UpdateParameter implements Parcelable { } /** * SHA-256 fingerprint of the certificate located at {@link #trustRootCertUrl} * SHA-256 fingerprint of the certificate located at {@code mTrustRootCertUrl} */ private byte[] mTrustRootCertSha256Fingerprint = null; public void setTrustRootCertSha256Fingerprint(byte[] fingerprint) { Loading @@ -177,6 +179,31 @@ public final class UpdateParameter implements Parcelable { return mTrustRootCertSha256Fingerprint; } /** * CA (Certificate Authority) X509 certificates. */ private X509Certificate mCaCertificate; /** * Set the CA (Certification Authority) certificate associated with Policy/Subscription update. * * @param caCertificate The CA certificate to set * @hide */ public void setCaCertificate(X509Certificate caCertificate) { mCaCertificate = caCertificate; } /** * Get the CA (Certification Authority) certificate associated with Policy/Subscription update. * * @return CA certificate associated and {@code null} if certificate is not set. * @hide */ public X509Certificate getCaCertificate() { return mCaCertificate; } /** * Constructor for creating Policy with default values. */ Loading @@ -202,6 +229,7 @@ public final class UpdateParameter implements Parcelable { mTrustRootCertSha256Fingerprint = Arrays.copyOf(source.mTrustRootCertSha256Fingerprint, source.mTrustRootCertSha256Fingerprint.length); } mCaCertificate = source.mCaCertificate; } @Override Loading @@ -219,6 +247,7 @@ public final class UpdateParameter implements Parcelable { dest.writeString(mBase64EncodedPassword); dest.writeString(mTrustRootCertUrl); dest.writeByteArray(mTrustRootCertSha256Fingerprint); ParcelUtil.writeCertificate(dest, mCaCertificate); } @Override Loading @@ -239,14 +268,15 @@ public final class UpdateParameter implements Parcelable { && TextUtils.equals(mBase64EncodedPassword, that.mBase64EncodedPassword) && TextUtils.equals(mTrustRootCertUrl, that.mTrustRootCertUrl) && Arrays.equals(mTrustRootCertSha256Fingerprint, that.mTrustRootCertSha256Fingerprint); that.mTrustRootCertSha256Fingerprint) && Credential.isX509CertificateEquals(mCaCertificate, that.mCaCertificate); } @Override public int hashCode() { return Objects.hash(mUpdateIntervalInMinutes, mUpdateMethod, mRestriction, mServerUri, mUsername, mBase64EncodedPassword, mTrustRootCertUrl, mTrustRootCertSha256Fingerprint); Arrays.hashCode(mTrustRootCertSha256Fingerprint), mCaCertificate); } @Override Loading Loading @@ -361,6 +391,7 @@ public final class UpdateParameter implements Parcelable { updateParam.setBase64EncodedPassword(in.readString()); updateParam.setTrustRootCertUrl(in.readString()); updateParam.setTrustRootCertSha256Fingerprint(in.createByteArray()); updateParam.setCaCertificate(ParcelUtil.readCertificate(in)); return updateParam; } Loading
wifi/tests/src/android/net/wifi/hotspot2/pps/CredentialTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -541,4 +541,20 @@ public class CredentialTest { Credential copyCred = new Credential(sourceCred); assertTrue(copyCred.equals(sourceCred)); } /** * Verify that two certificates are identical. */ @Test public void validateTwoCertificateIdentical() { assertTrue(Credential.isX509CertificateEquals(FakeKeys.CA_CERT1, FakeKeys.CA_CERT1)); } /** * Verify that two certificates are different. */ @Test public void validateTwoCertificateDifferent() { assertFalse(Credential.isX509CertificateEquals(FakeKeys.CA_CERT0, FakeKeys.CA_CERT1)); } }
wifi/tests/src/android/net/wifi/hotspot2/pps/UpdateParameterTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,11 @@ package android.net.wifi.hotspot2.pps; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.net.wifi.FakeKeys; import android.os.Parcel; import android.util.Base64; Loading Loading @@ -56,6 +58,7 @@ public class UpdateParameterTest { Base64.encodeToString("password".getBytes(), Base64.DEFAULT)); updateParam.setTrustRootCertUrl("trust.cert.com"); updateParam.setTrustRootCertSha256Fingerprint(new byte[32]); updateParam.setCaCertificate(FakeKeys.CA_CERT0); return updateParam; } Loading @@ -71,6 +74,7 @@ public class UpdateParameterTest { parcel.setDataPosition(0); // Rewind data position back to the beginning for read. UpdateParameter paramFromRead = UpdateParameter.CREATOR.createFromParcel(parcel); assertTrue(paramFromRead.equals(paramToWrite)); assertEquals(paramToWrite.hashCode(), paramFromRead.hashCode()); } /** Loading