package com.ikea.shared.network;

import com.ikea.shared.util.L;
import java.security.KeyStore;
import java.security.Principal;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

public class IkeaTrustManager
  implements X509TrustManager
{
  private static final Pattern[] CN_PATTERN;
  private static final Pattern[] O_PATTERN = arrayOfPattern2;
  private static final L sLog = new L(IkeaTrustManager.class.getSimpleName(), 3);
  private X509TrustManager mDelegate;

  static
  {
    Pattern[] arrayOfPattern1 = new Pattern[1];
    arrayOfPattern1[0] = Pattern.compile("cn=(ikea)|(ssl\\.ikea\\.net)");
    CN_PATTERN = arrayOfPattern1;
    Pattern[] arrayOfPattern2 = new Pattern[1];
    arrayOfPattern2[0] = Pattern.compile("o=(ikea)");
  }

  public IkeaTrustManager()
  {
    try
    {
      TrustManagerFactory localTrustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      localTrustManagerFactory.init((KeyStore)null);
      this.mDelegate = ((X509TrustManager)localTrustManagerFactory.getTrustManagers()[0]);
      return;
    }
    catch (RuntimeException localRuntimeException)
    {
      throw localRuntimeException;
    }
    catch (Exception localException)
    {
      throw new RuntimeException(localException);
    }
  }

  private boolean checkCertificate(X509Certificate paramX509Certificate)
    throws CertificateException
  {
    for (boolean bool = false; ; bool = true)
      try
      {
        paramX509Certificate.checkValidity();
        String str = paramX509Certificate.getSubjectDN().getName().toLowerCase(Locale.US);
        int i = 0;
        int j = CN_PATTERN.length;
        while (true)
        {
          if (i < j)
          {
            if (CN_PATTERN[i].matcher(str).find())
              break;
            if (!O_PATTERN[i].matcher(str).find())
              break label117;
            break;
          }
          while (true)
          {
            sLog.d("subject to check " + str + " isValid: " + bool);
            if (!bool)
              break;
            return bool;
            label117: bool = false;
          }
          i++;
        }
      }
      catch (Throwable localThrowable)
      {
        sLog.e("checkCertificate()", localThrowable);
        return false;
      }
  }

  public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString)
    throws CertificateException
  {
    sLog.e("checkClientTrusted()");
    this.mDelegate.checkClientTrusted(paramArrayOfX509Certificate, paramString);
  }

  public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString)
    throws CertificateException
  {
    int i = paramArrayOfX509Certificate.length;
    for (int j = 0; j < i; j++)
      if (checkCertificate(paramArrayOfX509Certificate[j]))
      {
        sLog.i("Server Trusted!");
        return;
      }
    sLog.d("checkServerTrusted() delegate");
    this.mDelegate.checkServerTrusted(paramArrayOfX509Certificate, paramString);
  }

  public X509Certificate[] getAcceptedIssuers()
  {
    sLog.e("getAcceptedIssuers()");
    return this.mDelegate.getAcceptedIssuers();
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.network.IkeaTrustManager
 * JD-Core Version:    0.6.2
 */