forked from organicmaps/organicmaps
[android] Fixed review notes https://github.com/mapsme/omim/pull/9683/files#r225575675
This commit is contained in:
parent
f14b93d95f
commit
5da5ba04f0
3 changed files with 17 additions and 28 deletions
android
|
@ -74,7 +74,6 @@ set(
|
|||
com/mapswithme/opengl/androidoglcontextfactory.cpp
|
||||
com/mapswithme/opengl/gl3stub.c
|
||||
com/mapswithme/platform/HttpThread.cpp
|
||||
com/mapswithme/util/HttpUploader.cpp
|
||||
com/mapswithme/platform/HttpUserAgent.cpp
|
||||
com/mapswithme/platform/GuiThread.cpp
|
||||
com/mapswithme/platform/Language.cpp
|
||||
|
@ -85,6 +84,7 @@ set(
|
|||
com/mapswithme/platform/SecureStorage.cpp
|
||||
com/mapswithme/platform/SocketImpl.cpp
|
||||
com/mapswithme/util/Config.cpp
|
||||
com/mapswithme/util/HttpUploader.cpp
|
||||
com/mapswithme/util/HttpClient.cpp
|
||||
com/mapswithme/util/Language.cpp
|
||||
com/mapswithme/util/LoggerFactory.cpp
|
||||
|
|
|
@ -11,8 +11,8 @@ import java.io.InputStream;
|
|||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class ClientCertTLSSocketFactory {
|
||||
|
||||
public class ClientCertTLSSocketFactory
|
||||
{
|
||||
private static final String PROTOCOL = "TLS";
|
||||
private static final String ALGORITHM = "X509";
|
||||
private static final String KEY_STORE_TYPE = "PKCS12";
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.io.OutputStream;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
@ -82,7 +81,20 @@ public final class HttpUploader
|
|||
{
|
||||
URL url = new URL(mUrl);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
onPrepareConnection(connection);
|
||||
connection.setConnectTimeout(Constants.CONNECTION_TIMEOUT_MS);
|
||||
connection.setReadTimeout(Constants.READ_TIMEOUT_MS);
|
||||
connection.setUseCaches(false);
|
||||
connection.setRequestMethod(mMethod);
|
||||
connection.setDoOutput(mMethod.equals("POST"));
|
||||
if ("https".equals(connection.getURL().getProtocol()) && mNeedClientAuth)
|
||||
{
|
||||
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
|
||||
String cert = HttpUploader.nativeUserBindingCertificate();
|
||||
String pwd = HttpUploader.nativeUserBindingPassword();
|
||||
byte[] decodedCert = Base64.decode(cert, Base64.DEFAULT);
|
||||
SSLSocketFactory socketFactory = ClientCertTLSSocketFactory.create(decodedCert, pwd.toCharArray());
|
||||
httpsConnection.setSSLSocketFactory(socketFactory);
|
||||
}
|
||||
|
||||
long fileSize = StorageUtils.getFileSize(mFilePath);
|
||||
StringBuilder paramsBuilder = new StringBuilder();
|
||||
|
@ -132,29 +144,6 @@ public final class HttpUploader
|
|||
return new Result(status, message);
|
||||
}
|
||||
|
||||
private void onPrepareConnection(@NonNull HttpURLConnection connection) throws ProtocolException
|
||||
{
|
||||
connection.setConnectTimeout(Constants.CONNECTION_TIMEOUT_MS);
|
||||
connection.setReadTimeout(Constants.READ_TIMEOUT_MS);
|
||||
connection.setUseCaches(false);
|
||||
connection.setRequestMethod(mMethod);
|
||||
connection.setDoOutput(mMethod.equals("POST"));
|
||||
if ("https".equals(connection.getURL().getProtocol()) && mNeedClientAuth)
|
||||
{
|
||||
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
|
||||
setupClientCert(httpsConnection);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupClientCert(@NonNull HttpsURLConnection connection)
|
||||
{
|
||||
String cert = HttpUploader.nativeUserBindingCertificate();
|
||||
String pwd = HttpUploader.nativeUserBindingPassword();
|
||||
byte[] decodedCert = Base64.decode(cert, Base64.DEFAULT);
|
||||
SSLSocketFactory socketFactory = ClientCertTLSSocketFactory.create(decodedCert, pwd.toCharArray());
|
||||
connection.setSSLSocketFactory(socketFactory);
|
||||
}
|
||||
|
||||
private static void setStreamingMode(@NonNull HttpURLConnection connection, long bodyLength)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||
|
|
Loading…
Add table
Reference in a new issue