From 1abd5b3e6f11ef9d7076685c56ef942fa0dd77e4 Mon Sep 17 00:00:00 2001 From: Kristian Monsen Date: Tue, 12 Jul 2011 22:59:15 +0100 Subject: [PATCH] Part of fix for bug 4997380: Some error types unknown to SslError Mapping chromium error codes from net/base/net_error_list.h to SslError codes. Change-Id: Ie4f98974e23969c3b5ae1f8c4413772cf93603b9 --- api/14.txt | 2 +- api/current.txt | 4 ++- core/java/android/net/http/SslError.java | 39 ++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/api/14.txt b/api/14.txt index d25d2b99ed009..ad8e1c59e0805 100644 --- a/api/14.txt +++ b/api/14.txt @@ -11206,7 +11206,7 @@ package android.net.http { method public boolean hasError(int); field public static final int SSL_EXPIRED = 1; // 0x1 field public static final int SSL_IDMISMATCH = 2; // 0x2 - field public static final int SSL_MAX_ERROR = 4; // 0x4 + field public static final int SSL_MAX_ERROR = 6; // 0x6 field public static final int SSL_NOTYETVALID = 0; // 0x0 field public static final int SSL_UNTRUSTED = 3; // 0x3 } diff --git a/api/current.txt b/api/current.txt index d3333f025f34e..2e1ad7f6c7e1b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11510,9 +11510,11 @@ package android.net.http { method public int getPrimaryError(); method public java.lang.String getUrl(); method public boolean hasError(int); + field public static final int SSL_DATE_INVALID = 4; // 0x4 field public static final int SSL_EXPIRED = 1; // 0x1 field public static final int SSL_IDMISMATCH = 2; // 0x2 - field public static final int SSL_MAX_ERROR = 4; // 0x4 + field public static final int SSL_INVALID = 5; // 0x5 + field public static final deprecated int SSL_MAX_ERROR = 6; // 0x6 field public static final int SSL_NOTYETVALID = 0; // 0x0 field public static final int SSL_UNTRUSTED = 3; // 0x3 } diff --git a/core/java/android/net/http/SslError.java b/core/java/android/net/http/SslError.java index 1e1cb49dabadb..08c669232c5d8 100644 --- a/core/java/android/net/http/SslError.java +++ b/core/java/android/net/http/SslError.java @@ -30,7 +30,7 @@ public class SslError { /** * The certificate is not yet valid */ - public static final int SSL_NOTYETVALID = 0; + public static final int SSL_NOTYETVALID = 0; /** * The certificate has expired */ @@ -43,12 +43,23 @@ public class SslError { * The certificate authority is not trusted */ public static final int SSL_UNTRUSTED = 3; + /** + * The date of the certificate is invalid + */ + public static final int SSL_DATE_INVALID = 4; + /** + * The certificate is invalid + */ + public static final int SSL_INVALID = 5; /** * The number of different SSL errors (update if you add a new SSL error!!!) + * @deprecated This constant is not necessary for using the SslError API and + * can change from release to release. */ - public static final int SSL_MAX_ERROR = 4; + @Deprecated + public static final int SSL_MAX_ERROR = 6; /** * The SSL error set bitfield (each individual error is an bit index; @@ -116,6 +127,30 @@ public class SslError { mUrl = 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 + */ + public static SslError SslErrorFromChromiumErrorCode( + int error, SslCertificate cert, String url) { + // The chromium error codes are in: + // external/chromium/net/base/net_error_list.h + if (error > -200 || error < -299) { + throw new NullPointerException("Not a valid chromium SSL error code."); + } + 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 errors to SSL_INVALID + return new SslError(SSL_INVALID, cert, url); + } + /** * Creates a new SSL error set object * @param error The SSL error