package com.worklight.wlclient.fips;

import android.content.Context;
import android.util.Log;
import com.worklight.common.Logger;
import com.worklight.nativeandroid.common.WLUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import org.apache.http.Header;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.io.AbstractSessionInputBuffer;
import org.apache.http.impl.io.HttpResponseParser;
import org.apache.http.io.HttpMessageParser;
import org.apache.http.message.BasicLineParser;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

public class FipsHttpClient
  implements HttpClient
{
  private static final String LOG_TAG = FipsHttpClient.class.getSimpleName();
  private static final String UNIMPLEMENTED_METHOD_MSG = "FipsHttpClient does not implement this method";
  private static Context ctx = null;
  private static final Logger logger = Logger.getInstance(FipsHttpClient.class.getName());
  private ClientConnectionManager mManager;
  private HttpParams mParams;
  private MicroVPNLib nativeLib;
  private long share;
  private int uvpn;

  protected FipsHttpClient()
  {
    if (!java.lang.Thread.currentThread().getStackTrace()[2].toString().contains("FipsHttpClientTest"))
      throw new RuntimeException("This constructor is for unit tests only, and should not be called in production code!");
    this.mParams = new BasicHttpParams();
  }

  public FipsHttpClient(ClientConnectionManager paramClientConnectionManager, HttpParams paramHttpParams)
  {
    WLUtils.loadLib(ctx, "libcrypto.so.1.0.0");
    WLUtils.loadLib(ctx, "libssl.so.1.0.0");
    this.nativeLib = new MicroVPNLib();
    if (this.nativeLib.FIPSInit() != 1)
      throw new RuntimeException("FIPS initialization failed.");
    this.share = this.nativeLib.curlInit();
    if (this.share == -1L)
      throw new RuntimeException("HTTP client initialization failed.");
    if (paramHttpParams == null)
    {
      paramHttpParams = new BasicHttpParams();
      HttpConnectionParams.setStaleCheckingEnabled(paramHttpParams, false);
      HttpConnectionParams.setConnectionTimeout(paramHttpParams, 60000);
      HttpConnectionParams.setSoTimeout(paramHttpParams, 60000);
      HttpConnectionParams.setSocketBufferSize(paramHttpParams, 8192);
      HttpClientParams.setRedirecting(paramHttpParams, false);
    }
    this.mParams = paramHttpParams;
    this.mManager = paramClientConnectionManager;
    this.uvpn = 0;
  }

  public static void setCtx(Context paramContext)
  {
    try
    {
      ctx = paramContext;
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public <T> T execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest, ResponseHandler<? extends T> paramResponseHandler)
  {
    throw new RuntimeException("FipsHttpClient does not implement this method");
  }

  public <T> T execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest, ResponseHandler<? extends T> paramResponseHandler, HttpContext paramHttpContext)
  {
    throw new RuntimeException("FipsHttpClient does not implement this method");
  }

  public <T> T execute(HttpUriRequest paramHttpUriRequest, ResponseHandler<? extends T> paramResponseHandler)
  {
    throw new RuntimeException("FipsHttpClient does not implement this method");
  }

  public <T> T execute(HttpUriRequest paramHttpUriRequest, ResponseHandler<? extends T> paramResponseHandler, HttpContext paramHttpContext)
  {
    throw new RuntimeException("FipsHttpClient does not implement this method");
  }

  public HttpResponse execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest)
  {
    throw new RuntimeException("FipsHttpClient does not implement this method");
  }

  public HttpResponse execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest, HttpContext paramHttpContext)
  {
    throw new RuntimeException("FipsHttpClient does not implement this method");
  }

  public HttpResponse execute(HttpUriRequest paramHttpUriRequest)
    throws IOException
  {
    try
    {
      HttpResponse localHttpResponse = execute(paramHttpUriRequest, (HttpContext)null);
      return localHttpResponse;
    }
    catch (IOException localIOException)
    {
      logger.error("IOException: ", localIOException);
    }
    return null;
  }

  public HttpResponse execute(HttpUriRequest paramHttpUriRequest, HttpContext paramHttpContext)
    throws IOException
  {
    String str1 = paramHttpUriRequest.getMethod().toString();
    String str2 = paramHttpUriRequest.getURI().toString();
    Object localObject = "";
    Header[] arrayOfHeader = paramHttpUriRequest.getAllHeaders();
    String[] arrayOfString1 = new String[arrayOfHeader.length];
    for (int i = 0; i < arrayOfHeader.length; i++)
      arrayOfString1[i] = (arrayOfHeader[i].getName() + ": " + arrayOfHeader[i].getValue());
    if (str1 == "POST");
    try
    {
      String str3 = EntityUtils.toString(((HttpEntityEnclosingRequest)paramHttpUriRequest).getEntity());
      localObject = str3;
      arrayOfString2 = new String[5];
      arrayOfString2[0] = ("redirect: " + HttpClientParams.isRedirecting(this.mParams));
      if (HttpConnectionParams.getConnectionTimeout(this.mParams) > 0)
      {
        arrayOfString2[1] = ("connectTO: " + HttpConnectionParams.getConnectionTimeout(this.mParams));
        if (HttpConnectionParams.getSoTimeout(this.mParams) <= 0)
          break label379;
        arrayOfString2[2] = ("socketTO: " + HttpConnectionParams.getSoTimeout(this.mParams));
        if (HttpConnectionParams.getSocketBufferSize(this.mParams) <= 0)
          break label389;
        arrayOfString2[3] = ("socketSize: " + HttpConnectionParams.getSocketBufferSize(this.mParams));
        arrayOfString2[4] = ("CAPath: " + ctx.getFilesDir());
        return parseCurlResponse(this.nativeLib.curlExecute(this.share, this.uvpn, str2, str1, (String)localObject, arrayOfString1, arrayOfString2));
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        String[] arrayOfString2;
        logger.debug("IOException: " + localIOException);
        continue;
        arrayOfString2[1] = "connectTO: 30";
        continue;
        label379: arrayOfString2[2] = "socketTO: 30";
        continue;
        label389: arrayOfString2[3] = "socketSize: 0";
      }
    }
  }

  public String executeRaw(String paramString1, String paramString2, String paramString3, String[] paramArrayOfString)
    throws IOException
  {
    Log.d(FipsHttpClient.class.getName(), "entering executeRaw(),  url = " + paramString1);
    Log.d(FipsHttpClient.class.getName(), "entering executeRaw(),  httpMethod = " + paramString2);
    Log.d(FipsHttpClient.class.getName(), "entering executeRaw(),  headers = " + paramArrayOfString);
    Log.d(FipsHttpClient.class.getName(), "entering executeRaw(),  body = " + paramString3);
    logger.debug("entering executeRaw(), ");
    String[] arrayOfString = new String[5];
    arrayOfString[0] = ("redirect: " + HttpClientParams.isRedirecting(this.mParams));
    if (HttpConnectionParams.getConnectionTimeout(this.mParams) > 0)
    {
      arrayOfString[1] = ("connectTO: " + HttpConnectionParams.getConnectionTimeout(this.mParams));
      if (HttpConnectionParams.getSoTimeout(this.mParams) <= 0)
        break label347;
      arrayOfString[2] = ("socketTO: " + HttpConnectionParams.getSoTimeout(this.mParams));
      label239: if (HttpConnectionParams.getSocketBufferSize(this.mParams) <= 0)
        break label357;
      arrayOfString[3] = ("socketSize: " + HttpConnectionParams.getSocketBufferSize(this.mParams));
    }
    while (true)
    {
      arrayOfString[4] = ("CAPath: " + ctx.getFilesDir());
      return new String(this.nativeLib.curlExecute(this.share, this.uvpn, paramString1, paramString2, paramString3, paramArrayOfString, arrayOfString));
      arrayOfString[1] = "connectTO: 30";
      break;
      label347: arrayOfString[2] = "socketTO: 30";
      break label239;
      label357: arrayOfString[3] = "socketSize: 0";
    }
  }

  public ClientConnectionManager getConnectionManager()
  {
    return this.mManager;
  }

  public HttpParams getParams()
  {
    return this.mParams;
  }

  protected HttpResponse parseCurlResponse(final byte[] paramArrayOfByte)
    throws IOException
  {
    HttpResponseParser localHttpResponseParser = new HttpResponseParser(new AbstractSessionInputBuffer()
    {
      public boolean isDataAvailable(int paramAnonymousInt)
        throws IOException
      {
        throw new RuntimeException("SessionInputBuffer.isDataAvailable was unexpectedly called.");
      }
    }
    , new BasicLineParser(), new DefaultHttpResponseFactory(), new BasicHttpParams());
    try
    {
      HttpResponse localHttpResponse = (HttpResponse)localHttpResponseParser.parse();
      int i = Integer.valueOf(localHttpResponse.getFirstHeader("Content-Length").getValue()).intValue();
      byte[] arrayOfByte = new byte[i];
      System.arraycopy(paramArrayOfByte, paramArrayOfByte.length - i, arrayOfByte, 0, i);
      InputStreamEntity localInputStreamEntity = new InputStreamEntity(new ByteArrayInputStream(arrayOfByte), i);
      localInputStreamEntity.setContentType(localHttpResponse.getFirstHeader("Content-Type"));
      localHttpResponse.setEntity(localInputStreamEntity);
      return localHttpResponse;
    }
    catch (HttpException localHttpException)
    {
      logger.error("Problem parsing Curl response: ", localHttpException);
      throw new IOException(localHttpException);
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.worklight.wlclient.fips.FipsHttpClient
 * JD-Core Version:    0.6.2
 */