Merge "Clean up SslError"
This commit is contained in:
@@ -19,7 +19,8 @@ package android.net.http;
|
|||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One or more individual SSL errors and the associated SSL certificate
|
* This class represents a set of one or more SSL errors and the associated SSL
|
||||||
|
* certificate.
|
||||||
*/
|
*/
|
||||||
public class SslError {
|
public class SslError {
|
||||||
|
|
||||||
@@ -48,16 +49,17 @@ public class SslError {
|
|||||||
*/
|
*/
|
||||||
public static final int SSL_DATE_INVALID = 4;
|
public static final int SSL_DATE_INVALID = 4;
|
||||||
/**
|
/**
|
||||||
* The certificate is invalid
|
* A generic error occurred
|
||||||
*/
|
*/
|
||||||
public static final int SSL_INVALID = 5;
|
public static final int SSL_INVALID = 5;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of different SSL errors (update if you add a new SSL error!!!)
|
* The number of different SSL errors.
|
||||||
* @deprecated This constant is not necessary for using the SslError API and
|
* @deprecated This constant is not necessary for using the SslError API and
|
||||||
* can change from release to release.
|
* can change from release to release.
|
||||||
*/
|
*/
|
||||||
|
// Update if you add a new SSL error!!!
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final int SSL_MAX_ERROR = 6;
|
public static final int SSL_MAX_ERROR = 6;
|
||||||
|
|
||||||
@@ -78,55 +80,55 @@ public class SslError {
|
|||||||
final String mUrl;
|
final String mUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SSL error set object
|
* Creates a new SslError object using the supplied error and certificate.
|
||||||
|
* The URL will be set to the empty string.
|
||||||
* @param error The SSL error
|
* @param error The SSL error
|
||||||
* @param certificate The associated SSL certificate
|
* @param certificate The associated SSL certificate
|
||||||
* @deprecated Use {@link #SslError(int, SslCertificate, String)}
|
* @deprecated Use {@link #SslError(int, SslCertificate, String)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SslError(int error, SslCertificate certificate) {
|
public SslError(int error, SslCertificate certificate) {
|
||||||
addError(error);
|
this(error, certificate, "");
|
||||||
if (certificate == null) {
|
|
||||||
throw new NullPointerException("certificate is null.");
|
|
||||||
}
|
|
||||||
mCertificate = certificate;
|
|
||||||
mUrl = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SSL error set object
|
* Creates a new SslError object using the supplied error and certificate.
|
||||||
|
* The URL will be set to the empty string.
|
||||||
* @param error The SSL error
|
* @param error The SSL error
|
||||||
* @param certificate The associated SSL certificate
|
* @param certificate The associated SSL certificate
|
||||||
* @deprecated Use {@link #SslError(int, X509Certificate, String)}
|
* @deprecated Use {@link #SslError(int, X509Certificate, String)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SslError(int error, X509Certificate certificate) {
|
public SslError(int error, X509Certificate certificate) {
|
||||||
addError(error);
|
this(error, certificate, "");
|
||||||
if (certificate == null) {
|
|
||||||
throw new NullPointerException("certificate is null.");
|
|
||||||
}
|
|
||||||
mCertificate = new SslCertificate(certificate);
|
|
||||||
mUrl = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SSL error set object
|
* Creates a new SslError object using the supplied error, certificate and
|
||||||
|
* URL.
|
||||||
* @param error The SSL error
|
* @param error The SSL error
|
||||||
* @param certificate The associated SSL certificate
|
* @param certificate The associated SSL certificate
|
||||||
* @param url The associated URL.
|
* @param url The associated URL
|
||||||
*/
|
*/
|
||||||
public SslError(int error, SslCertificate certificate, String url) {
|
public SslError(int error, SslCertificate certificate, String url) {
|
||||||
|
assert certificate != null;
|
||||||
|
assert url != null;
|
||||||
addError(error);
|
addError(error);
|
||||||
if (certificate == null) {
|
|
||||||
throw new NullPointerException("certificate is null.");
|
|
||||||
}
|
|
||||||
mCertificate = certificate;
|
mCertificate = certificate;
|
||||||
if (url == null) {
|
|
||||||
throw new NullPointerException("url is null.");
|
|
||||||
}
|
|
||||||
mUrl = url;
|
mUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new SslError object using the supplied error, certificate and
|
||||||
|
* URL.
|
||||||
|
* @param error The SSL error
|
||||||
|
* @param certificate The associated SSL certificate
|
||||||
|
* @param url The associated URL
|
||||||
|
*/
|
||||||
|
public SslError(int error, X509Certificate certificate, String url) {
|
||||||
|
this(error, new SslCertificate(certificate), url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an SslError object from a chromium error code.
|
* Creates an SslError object from a chromium error code.
|
||||||
* @param error The chromium error code
|
* @param error The chromium error code
|
||||||
@@ -138,56 +140,42 @@ public class SslError {
|
|||||||
int error, SslCertificate cert, String url) {
|
int error, SslCertificate cert, String url) {
|
||||||
// The chromium error codes are in:
|
// The chromium error codes are in:
|
||||||
// external/chromium/net/base/net_error_list.h
|
// external/chromium/net/base/net_error_list.h
|
||||||
if (error > -200 || error < -299) {
|
assert (error >= -299 && error <= -200);
|
||||||
throw new NullPointerException("Not a valid chromium SSL error code.");
|
|
||||||
}
|
|
||||||
if (error == -200)
|
if (error == -200)
|
||||||
return new SslError(SSL_IDMISMATCH, cert, url);
|
return new SslError(SSL_IDMISMATCH, cert, url);
|
||||||
if (error == -201)
|
if (error == -201)
|
||||||
return new SslError(SSL_DATE_INVALID, cert, url);
|
return new SslError(SSL_DATE_INVALID, cert, url);
|
||||||
if (error == -202)
|
if (error == -202)
|
||||||
return new SslError(SSL_UNTRUSTED, cert, url);
|
return new SslError(SSL_UNTRUSTED, cert, url);
|
||||||
// Map all other errors to SSL_INVALID
|
// Map all other codes to SSL_INVALID.
|
||||||
return new SslError(SSL_INVALID, cert, url);
|
return new SslError(SSL_INVALID, cert, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SSL error set object
|
* Gets the SSL certificate associated with this object.
|
||||||
* @param error The SSL error
|
* @return The SSL certificate, non-null.
|
||||||
* @param certificate The associated SSL certificate
|
|
||||||
* @param url The associated URL.
|
|
||||||
*/
|
|
||||||
public SslError(int error, X509Certificate certificate, String url) {
|
|
||||||
addError(error);
|
|
||||||
if (certificate == null) {
|
|
||||||
throw new NullPointerException("certificate is null.");
|
|
||||||
}
|
|
||||||
mCertificate = new SslCertificate(certificate);
|
|
||||||
if (url == null) {
|
|
||||||
throw new NullPointerException("url is null.");
|
|
||||||
}
|
|
||||||
mUrl = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The SSL certificate associated with the error set, non-null.
|
|
||||||
*/
|
*/
|
||||||
public SslCertificate getCertificate() {
|
public SslCertificate getCertificate() {
|
||||||
return mCertificate;
|
return mCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The URL associated with the error set, non-null.
|
* Gets the URL associated with this object.
|
||||||
* "" if one of the deprecated constructors is used.
|
* @return The URL, non-null.
|
||||||
*/
|
*/
|
||||||
|
// TODO: When the WebView constructs an instance of this object, we
|
||||||
|
// actually provide only the hostname, not the full URL. We should consider
|
||||||
|
// deprecating this method, adding a new getHost() method and updating the
|
||||||
|
// constructor arguments. See http://b/5410252.
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return mUrl;
|
return mUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the SSL error to the error set
|
* Adds the supplied SSL error to the set.
|
||||||
* @param error The SSL error to add
|
* @param error The SSL error to add
|
||||||
* @return True iff the error being added is a known SSL error
|
* @return True if the error being added is a known SSL error, otherwise
|
||||||
|
* false.
|
||||||
*/
|
*/
|
||||||
public boolean addError(int error) {
|
public boolean addError(int error) {
|
||||||
boolean rval = (0 <= error && error < SslError.SSL_MAX_ERROR);
|
boolean rval = (0 <= error && error < SslError.SSL_MAX_ERROR);
|
||||||
@@ -199,8 +187,9 @@ public class SslError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param error The SSL error to check
|
* Determines whether this object includes the supplied error.
|
||||||
* @return True iff the set includes the error
|
* @param error The SSL error to check for
|
||||||
|
* @return True if this object includes the error, otherwise false.
|
||||||
*/
|
*/
|
||||||
public boolean hasError(int error) {
|
public boolean hasError(int error) {
|
||||||
boolean rval = (0 <= error && error < SslError.SSL_MAX_ERROR);
|
boolean rval = (0 <= error && error < SslError.SSL_MAX_ERROR);
|
||||||
@@ -212,7 +201,8 @@ public class SslError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The primary, most severe, SSL error in the set
|
* Gets the most severe SSL error in this object's set of errors.
|
||||||
|
* @return The most severe SSL error.
|
||||||
*/
|
*/
|
||||||
public int getPrimaryError() {
|
public int getPrimaryError() {
|
||||||
if (mErrors != 0) {
|
if (mErrors != 0) {
|
||||||
@@ -228,12 +218,12 @@ public class SslError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A String representation of this SSL error object
|
* Returns a string representation of this object.
|
||||||
* (used mostly for debugging).
|
* @return A String representation of this object.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "primary error: " + getPrimaryError() +
|
return "primary error: " + getPrimaryError() +
|
||||||
" certificate: " + getCertificate() +
|
" certificate: " + getCertificate() +
|
||||||
" on URL: " + getUrl();
|
" on URL: " + getUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user