FileDocCategorySizeDatePackage
SslError.javaAPI DocAndroid 5.1 API6950Thu Mar 12 22:22:10 GMT 2015android.net.http

SslError

public class SslError extends Object
This class represents a set of one or more SSL errors and the associated SSL certificate.

Fields Summary
public static final int
SSL_NOTYETVALID
The certificate is not yet valid
public static final int
SSL_EXPIRED
The certificate has expired
public static final int
SSL_IDMISMATCH
Hostname mismatch
public static final int
SSL_UNTRUSTED
The certificate authority is not trusted
public static final int
SSL_DATE_INVALID
The date of the certificate is invalid
public static final int
SSL_INVALID
A generic error occurred
public static final int
SSL_MAX_ERROR
The number of different SSL errors.
int
mErrors
The SSL error set bitfield (each individual error is a bit index; multiple individual errors can be OR-ed)
final SslCertificate
mCertificate
The SSL certificate associated with the error set
final String
mUrl
The URL associated with the error set.
Constructors Summary
public SslError(int error, SslCertificate certificate)
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
certificate The associated SSL certificate
deprecated
Use {@link #SslError(int, SslCertificate, String)}


                                              
    
         
        this(error, certificate, "");
    
public SslError(int error, X509Certificate certificate)
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
certificate The associated SSL certificate
deprecated
Use {@link #SslError(int, X509Certificate, String)}

        this(error, certificate, "");
    
public SslError(int error, SslCertificate certificate, String 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

        assert certificate != null;
        assert url != null;
        addError(error);
        mCertificate = certificate;
        mUrl = url;
    
public SslError(int error, X509Certificate certificate, String 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

        this(error, new SslCertificate(certificate), url);
    
Methods Summary
public static android.net.http.SslErrorSslErrorFromChromiumErrorCode(int error, SslCertificate cert, java.lang.String url)
Creates an SslError object from a chromium error code.

param
error The chromium error code
param
certificate The associated SSL certificate
param
url The associated URL.
hide
chromium error codes only available inside the framework

        // The chromium error codes are in:
        // external/chromium/net/base/net_error_list.h
        assert (error >= -299 && error <= -200);
        if (error == -200)
            return new SslError(SSL_IDMISMATCH, cert, url);
        if (error == -201)
            return new SslError(SSL_DATE_INVALID, cert, url);
        if (error == -202)
            return new SslError(SSL_UNTRUSTED, cert, url);
        // Map all other codes to SSL_INVALID.
        return new SslError(SSL_INVALID, cert, url);
    
public booleanaddError(int error)
Adds the supplied SSL error to the set.

param
error The SSL error to add
return
True if the error being added is a known SSL error, otherwise false.

        boolean rval = (0 <= error && error < SslError.SSL_MAX_ERROR);
        if (rval) {
            mErrors |= (0x1 << error);
        }

        return rval;
    
public SslCertificategetCertificate()
Gets the SSL certificate associated with this object.

return
The SSL certificate, non-null.

        return mCertificate;
    
public intgetPrimaryError()
Gets the most severe SSL error in this object's set of errors. Returns -1 if the set is empty.

return
The most severe SSL error, or -1 if the set is empty.

        if (mErrors != 0) {
            // go from the most to the least severe errors
            for (int error = SslError.SSL_MAX_ERROR - 1; error >= 0; --error) {
                if ((mErrors & (0x1 << error)) != 0) {
                    return error;
                }
            }
            // mErrors should never be set to an invalid value.
            assert false;
        }

        return -1;
    
public java.lang.StringgetUrl()
Gets the URL associated with this object.

return
The URL, non-null.

        return mUrl;
    
public booleanhasError(int error)
Determines whether this object includes the supplied error.

param
error The SSL error to check for
return
True if this object includes the error, otherwise false.

        boolean rval = (0 <= error && error < SslError.SSL_MAX_ERROR);
        if (rval) {
            rval = ((mErrors & (0x1 << error)) != 0);
        }

        return rval;
    
public java.lang.StringtoString()
Returns a string representation of this object.

return
A String representation of this object.

        return "primary error: " + getPrimaryError() +
                " certificate: " + getCertificate() +
                " on URL: " + getUrl();