am 3af8e938: Change addCertificate to take byte[] instead of String as we don\'t know the encoding.
Merge commit '3af8e9389e008c0076b86cc6b3c6f005e7473d10' * commit '3af8e9389e008c0076b86cc6b3c6f005e7473d10': Change addCertificate to take byte[] instead of String as we don't know the encoding.
This commit is contained in:
committed by
The Android Open Source Project
commit
b0774438ea
@@ -17,6 +17,7 @@
|
||||
package android.webkit;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/** Utility class optimized for accumulating bytes, and then spitting
|
||||
them back out. It does not optimize for returning the result in a
|
||||
@@ -94,6 +95,20 @@ class ByteArrayBuilder {
|
||||
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() {
|
||||
Chunk c = getFirstChunk();
|
||||
while (c != null) {
|
||||
|
||||
@@ -25,16 +25,16 @@ import android.net.http.HttpAuthHeader;
|
||||
import android.net.http.RequestHandle;
|
||||
import android.net.http.SslCertificate;
|
||||
import android.net.http.SslError;
|
||||
import android.net.http.SslCertificate;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.security.Keystore;
|
||||
import android.util.Log;
|
||||
import android.webkit.CacheManager.CacheResult;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -70,6 +70,8 @@ class LoadListener extends Handler implements EventHandler {
|
||||
private static final int HTTP_NOT_FOUND = 404;
|
||||
private static final int HTTP_PROXY_AUTH = 407;
|
||||
|
||||
private static final String CERT_MIMETYPE = "application/x-x509-ca-cert";
|
||||
|
||||
private static int sNativeLoaderCount;
|
||||
|
||||
private final ByteArrayBuilder mDataBuilder = new ByteArrayBuilder(8192);
|
||||
@@ -919,6 +921,12 @@ class LoadListener extends Handler implements EventHandler {
|
||||
|
||||
// This commits the headers without checking the response status code.
|
||||
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
|
||||
int nativeResponse = createNativeResponse();
|
||||
// The native code deletes the native response object.
|
||||
@@ -959,6 +967,30 @@ class LoadListener extends Handler implements EventHandler {
|
||||
private void commitLoad() {
|
||||
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
|
||||
PerfChecker checker = new PerfChecker();
|
||||
ByteArrayBuilder.Chunk c;
|
||||
|
||||
@@ -228,6 +228,8 @@
|
||||
<string name="httpErrorFileNotFound">The requested file was not found.</string>
|
||||
<!-- 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>
|
||||
<!-- 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>
|
||||
|
||||
<!-- Account notifications --> <skip />
|
||||
<!-- A notification is shown when the AccountManager is unable to
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class Keystore {
|
||||
public abstract String generateKeyPair(
|
||||
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 final String SERVICE_NAME = "keystore";
|
||||
@@ -217,7 +217,7 @@ public abstract class Keystore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCertificate(String cert) {
|
||||
public void addCertificate(byte[] cert) {
|
||||
// TODO: real implementation
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user