Change addCertificate to take byte[] instead of String as we don't know the encoding.
In WebView, if we run into the certificate, we will save it to the Keystore instead of sending it to the WebKit.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package android.webkit;
|
package android.webkit;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
/** Utility class optimized for accumulating bytes, and then spitting
|
/** Utility class optimized for accumulating bytes, and then spitting
|
||||||
them back out. It does not optimize for returning the result in a
|
them back out. It does not optimize for returning the result in a
|
||||||
@@ -94,6 +95,20 @@ class ByteArrayBuilder {
|
|||||||
return mChunks.isEmpty();
|
return mChunks.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return mChunks.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getByteSize() {
|
||||||
|
int total = 0;
|
||||||
|
ListIterator<Chunk> it = mChunks.listIterator(0);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Chunk c = it.next();
|
||||||
|
total += c.mLength;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void clear() {
|
public synchronized void clear() {
|
||||||
Chunk c = getFirstChunk();
|
Chunk c = getFirstChunk();
|
||||||
while (c != null) {
|
while (c != null) {
|
||||||
|
|||||||
@@ -25,16 +25,16 @@ import android.net.http.HttpAuthHeader;
|
|||||||
import android.net.http.RequestHandle;
|
import android.net.http.RequestHandle;
|
||||||
import android.net.http.SslCertificate;
|
import android.net.http.SslCertificate;
|
||||||
import android.net.http.SslError;
|
import android.net.http.SslError;
|
||||||
import android.net.http.SslCertificate;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.security.Keystore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.CacheManager.CacheResult;
|
import android.webkit.CacheManager.CacheResult;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -72,6 +72,8 @@ class LoadListener extends Handler implements EventHandler {
|
|||||||
private static final int HTTP_NOT_FOUND = 404;
|
private static final int HTTP_NOT_FOUND = 404;
|
||||||
private static final int HTTP_PROXY_AUTH = 407;
|
private static final int HTTP_PROXY_AUTH = 407;
|
||||||
|
|
||||||
|
private static final String CERT_MIMETYPE = "application/x-x509-ca-cert";
|
||||||
|
|
||||||
private static int sNativeLoaderCount;
|
private static int sNativeLoaderCount;
|
||||||
|
|
||||||
private final ByteArrayBuilder mDataBuilder = new ByteArrayBuilder(8192);
|
private final ByteArrayBuilder mDataBuilder = new ByteArrayBuilder(8192);
|
||||||
@@ -934,6 +936,12 @@ class LoadListener extends Handler implements EventHandler {
|
|||||||
|
|
||||||
// This commits the headers without checking the response status code.
|
// This commits the headers without checking the response status code.
|
||||||
private void commitHeaders() {
|
private void commitHeaders() {
|
||||||
|
if (mIsMainPageLoader && CERT_MIMETYPE.equals(mMimeType)) {
|
||||||
|
// In the case of downloading certificate, we will save it to the
|
||||||
|
// Keystore in commitLoad. Do not call webcore.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Commit the headers to WebCore
|
// Commit the headers to WebCore
|
||||||
int nativeResponse = createNativeResponse();
|
int nativeResponse = createNativeResponse();
|
||||||
// The native code deletes the native response object.
|
// The native code deletes the native response object.
|
||||||
@@ -974,6 +982,30 @@ class LoadListener extends Handler implements EventHandler {
|
|||||||
private void commitLoad() {
|
private void commitLoad() {
|
||||||
if (mCancelled) return;
|
if (mCancelled) return;
|
||||||
|
|
||||||
|
if (mIsMainPageLoader && CERT_MIMETYPE.equals(mMimeType)) {
|
||||||
|
// In the case of downloading certificate, we will save it to the
|
||||||
|
// Keystore and stop the current loading so that it will not
|
||||||
|
// generate a new history page
|
||||||
|
byte[] cert = new byte[mDataBuilder.getByteSize()];
|
||||||
|
int position = 0;
|
||||||
|
ByteArrayBuilder.Chunk c;
|
||||||
|
while (true) {
|
||||||
|
c = mDataBuilder.getFirstChunk();
|
||||||
|
if (c == null) break;
|
||||||
|
|
||||||
|
if (c.mLength != 0) {
|
||||||
|
System.arraycopy(c.mArray, 0, cert, position, c.mLength);
|
||||||
|
position += c.mLength;
|
||||||
|
}
|
||||||
|
mDataBuilder.releaseChunk(c);
|
||||||
|
}
|
||||||
|
Keystore.getInstance().addCertificate(cert);
|
||||||
|
Toast.makeText(mContext, R.string.certificateSaved,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
mBrowserFrame.stopLoading();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Give the data to WebKit now
|
// Give the data to WebKit now
|
||||||
PerfChecker checker = new PerfChecker();
|
PerfChecker checker = new PerfChecker();
|
||||||
ByteArrayBuilder.Chunk c;
|
ByteArrayBuilder.Chunk c;
|
||||||
|
|||||||
@@ -228,6 +228,8 @@
|
|||||||
<string name="httpErrorFileNotFound">The requested file was not found.</string>
|
<string name="httpErrorFileNotFound">The requested file was not found.</string>
|
||||||
<!-- Displayed when a request failed because there are too many requests right now. -->
|
<!-- Displayed when a request failed because there are too many requests right now. -->
|
||||||
<string name="httpErrorTooManyRequests">Too many requests are being processed. Try again later.</string>
|
<string name="httpErrorTooManyRequests">Too many requests are being processed. Try again later.</string>
|
||||||
|
<!-- Displayed a toast that a certificate is saved in the keystore -->
|
||||||
|
<string name="certificateSaved">The certificate is saved in the system\'s key store.</string>
|
||||||
|
|
||||||
<!-- Sync notifications --> <skip />
|
<!-- Sync notifications --> <skip />
|
||||||
<!-- A notification is shown when there is a sync error. This is the text that will scroll through the notification bar (will be seen by the user as he uses another application). -->
|
<!-- A notification is shown when there is a sync error. This is the text that will scroll through the notification bar (will be seen by the user as he uses another application). -->
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public abstract class Keystore {
|
|||||||
public abstract String generateKeyPair(
|
public abstract String generateKeyPair(
|
||||||
int keyStrengthIndex, String challenge, String organizations);
|
int keyStrengthIndex, String challenge, String organizations);
|
||||||
|
|
||||||
public abstract void addCertificate(String cert);
|
public abstract void addCertificate(byte[] cert);
|
||||||
|
|
||||||
private static class FileKeystore extends Keystore {
|
private static class FileKeystore extends Keystore {
|
||||||
private static final String SERVICE_NAME = "keystore";
|
private static final String SERVICE_NAME = "keystore";
|
||||||
@@ -217,7 +217,7 @@ public abstract class Keystore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCertificate(String cert) {
|
public void addCertificate(byte[] cert) {
|
||||||
// TODO: real implementation
|
// TODO: real implementation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user