Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/SslUtil.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/SslUtil.java b/android_webview/java/src/org/chromium/android_webview/SslUtil.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0e2beec8c013d9a62e5827c7fb165f3e79e1e106 |
| --- /dev/null |
| +++ b/android_webview/java/src/org/chromium/android_webview/SslUtil.java |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.android_webview; |
| + |
| +import android.net.http.SslCertificate; |
| +import android.net.http.SslError; |
| +import android.util.Log; |
| + |
| +import org.chromium.net.NetError; |
| +import org.chromium.net.X509Util; |
| + |
| +import java.security.KeyStoreException; |
| +import java.security.NoSuchAlgorithmException; |
| +import java.security.cert.CertificateException; |
| +import java.security.cert.X509Certificate; |
| + |
| +public class SslUtil { |
| + private static final String TAG = SslUtil.class.getSimpleName(); |
| + |
| + /** |
| + * Creates an SslError object from a chromium net error code. |
| + */ |
| + public static SslError SslErrorFromNetErrorCode(int error, SslCertificate cert, String url) { |
| + assert (error >= NetError.ERR_CERT_END && error <= NetError.ERR_CERT_COMMON_NAME_INVALID); |
| + if (error == NetError.ERR_CERT_COMMON_NAME_INVALID) |
| + return new SslError(SslError.SSL_IDMISMATCH, cert, url); |
| + if (error == NetError.ERR_CERT_DATE_INVALID) |
| + return new SslError(SslError.SSL_DATE_INVALID, cert, url); |
| + if (error == NetError.ERR_CERT_AUTHORITY_INVALID) |
| + return new SslError(SslError.SSL_UNTRUSTED, cert, url); |
| + // Map all other codes to SSL_INVALID. |
| + return new SslError(SslError.SSL_INVALID, cert, url); |
|
benm (inactive)
2013/02/25 12:16:38
nit: would a switch look neater?
sgurun-gerrit only
2013/02/25 19:45:22
Done.
|
| + } |
| + |
| + public static SslCertificate getCertificateFromDerBytes(byte[] derBytes) { |
| + if (derBytes == null) { |
| + return null; |
| + } |
| + |
| + try { |
| + X509Certificate x509Certificate = |
| + X509Util.createCertificateFromBytes(derBytes); |
| + return new SslCertificate(x509Certificate); |
| + } catch (CertificateException e) { |
| + // A SSL related exception must have occured. This shouldn't happen. |
| + Log.w(TAG, "Could not read certificate: " + e); |
| + } catch (KeyStoreException e) { |
| + // A SSL related exception must have occured. This shouldn't happen. |
| + Log.w(TAG, "Could not read certificate: " + e); |
| + } catch (NoSuchAlgorithmException e) { |
| + // A SSL related exception must have occured. This shouldn't happen. |
| + Log.w(TAG, "Could not read certificate: " + e); |
| + } |
| + return null; |
| + } |
| +} |