not-yet-commons-ssl-0.3.11

16:39:19.759 INFO  jd.cli.Main - Decompiling not-yet-commons-ssl-0.3.11.jar
package org.apache.commons.httpclient.contrib.ssl;

import java.io.IOException;
import java.net.URL;
import java.security.GeneralSecurityException;
import org.apache.commons.ssl.HttpSecureProtocol;
import org.apache.commons.ssl.KeyMaterial;
import org.apache.commons.ssl.TrustMaterial;

public class AuthSSLProtocolSocketFactory
  extends HttpSecureProtocol
{
  public AuthSSLProtocolSocketFactory(URL keystoreUrl, String keystorePassword, URL truststoreUrl, String truststorePassword)
    throws GeneralSecurityException, IOException
  {
    if (keystoreUrl != null)
    {
      char[] ksPass = null;
      if (keystorePassword != null) {
        ksPass = keystorePassword.toCharArray();
      }
      KeyMaterial km = new KeyMaterial(keystoreUrl, ksPass);
      super.setKeyMaterial(km);
    }
    if (truststoreUrl != null)
    {
      char[] tsPass = null;
      if (truststorePassword != null) {
        tsPass = truststorePassword.toCharArray();
      }
      TrustMaterial tm = new KeyMaterial(truststoreUrl, tsPass);
      super.setTrustMaterial(tm);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.contrib.ssl.AuthSSLProtocolSocketFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient.contrib.ssl;

import java.io.IOException;
import java.security.GeneralSecurityException;
import org.apache.commons.ssl.HttpSecureProtocol;
import org.apache.commons.ssl.TrustMaterial;

public class EasySSLProtocolSocketFactory
  extends HttpSecureProtocol
{
  public EasySSLProtocolSocketFactory()
    throws GeneralSecurityException, IOException
  {
    super.useDefaultJavaCiphers();
    super.setTrustMaterial(TrustMaterial.TRUST_ALL);
    super.setCheckHostname(false);
    super.setCheckExpiry(false);
    super.setCheckCRL(false);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient.contrib.ssl;

import java.io.IOException;
import java.security.GeneralSecurityException;
import org.apache.commons.ssl.HttpSecureProtocol;

public class StrictSSLProtocolSocketFactory
  extends HttpSecureProtocol
{
  public StrictSSLProtocolSocketFactory(boolean verifyHostname)
    throws GeneralSecurityException, IOException
  {
    super.setCheckHostname(verifyHostname);
  }
  
  public StrictSSLProtocolSocketFactory()
    throws GeneralSecurityException, IOException
  {
    this(true);
  }
  
  public void setHostnameVerification(boolean verifyHostname)
  {
    super.setCheckHostname(verifyHostname);
  }
  
  public boolean getHostnameVerification()
  {
    return super.getCheckHostname();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.contrib.ssl.StrictSSLProtocolSocketFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient.contrib.ssl;

import java.io.IOException;
import java.security.GeneralSecurityException;
import org.apache.commons.ssl.HttpSecureProtocol;
import org.apache.commons.ssl.KeyMaterial;

public class TrustSSLProtocolSocketFactory
  extends HttpSecureProtocol
{
  public TrustSSLProtocolSocketFactory(String pathToTrustStore)
    throws GeneralSecurityException, IOException
  {
    this(pathToTrustStore, null);
  }
  
  public TrustSSLProtocolSocketFactory(String pathToTrustStore, char[] password)
    throws GeneralSecurityException, IOException
  {
    KeyMaterial km = new KeyMaterial(pathToTrustStore, password);
    super.setTrustMaterial(km);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.contrib.ssl.TrustSSLProtocolSocketFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.ssl.util.Hex;

class ASN1Structure
{
  List derIntegers = new LinkedList();
  Set oids = new TreeSet();
  String oid1;
  String oid2;
  String oid3;
  byte[] salt;
  byte[] iv;
  int iterationCount;
  int keySize;
  byte[] bigPayload;
  byte[] smallPayload;
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer(256);
    buf.append("------ ASN.1 PKCS Structure ------");
    buf.append("\noid1:    ");
    buf.append(oid1);
    if (oid2 != null)
    {
      buf.append("\noid2:    ");
      buf.append(oid2);
    }
    buf.append("\nsalt:   ");
    if (salt != null) {
      buf.append(Hex.encode(salt));
    } else {
      buf.append("[null]");
    }
    buf.append("\nic:      ");
    buf.append(Integer.toString(iterationCount));
    if (keySize != 0)
    {
      buf.append("\nkeySize: ");
      buf.append(Integer.toString(keySize * 8));
    }
    if (oid2 != null)
    {
      buf.append("\noid3:    ");
      buf.append(oid3);
    }
    if (oid2 != null)
    {
      buf.append("\niv:      ");
      if (iv != null) {
        buf.append(Hex.encode(iv));
      } else {
        buf.append("[null]");
      }
    }
    if (bigPayload != null)
    {
      buf.append("\nbigPayload-length:   ");
      buf.append(bigPayload.length);
    }
    if (smallPayload != null)
    {
      buf.append("\nsmallPayload-length: ");
      buf.append(smallPayload.length);
    }
    if (!oids.isEmpty())
    {
      Iterator it = oids.iterator();
      buf.append("\nAll oids:");
      while (it.hasNext())
      {
        buf.append("\n");
        buf.append((String)it.next());
      }
    }
    return buf.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.ASN1Structure
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import org.apache.commons.ssl.asn1.ASN1InputStream;
import org.apache.commons.ssl.asn1.DEREncodable;
import org.apache.commons.ssl.asn1.DERInteger;
import org.apache.commons.ssl.asn1.DERObjectIdentifier;
import org.apache.commons.ssl.asn1.DEROctetString;
import org.apache.commons.ssl.asn1.DERPrintableString;
import org.apache.commons.ssl.asn1.DERSequence;
import org.apache.commons.ssl.asn1.DERSet;
import org.apache.commons.ssl.asn1.DERTaggedObject;
import org.apache.commons.ssl.util.Hex;

public class ASN1Util
{
  public static boolean DEBUG = false;
  public static final BigInteger BIGGEST = new BigInteger(Integer.toString(Integer.MAX_VALUE));
  
  public static ASN1Structure analyze(byte[] asn1)
    throws IOException
  {
    ASN1InputStream asn = new ASN1InputStream(asn1);
    DERSequence seq = (DERSequence)asn.readObject();
    ASN1Structure pkcs8 = new ASN1Structure();
    analyze(seq, pkcs8, 0);
    return pkcs8;
  }
  
  public static void main(String[] args)
    throws Exception
  {
    DEBUG = true;
    FileInputStream in = new FileInputStream(args[0]);
    byte[] bytes = Util.streamToBytes(in);
    List list = PEMUtil.decode(bytes);
    if (!list.isEmpty()) {
      bytes = ((PEMItem)list.get(0)).getDerBytes();
    }
    ASN1Structure asn1 = analyze(bytes);
    while (bigPayload != null)
    {
      System.out.println("------------------------------------------");
      System.out.println(asn1);
      System.out.println("------------------------------------------");
      asn1 = analyze(bigPayload);
    }
  }
  
  public static void analyze(DEREncodable seq, ASN1Structure pkcs8, int depth)
  {
    String tag = null;
    if (depth >= 2) {
      derIntegers = null;
    }
    Enumeration en;
    Enumeration en;
    if ((seq instanceof DERSequence))
    {
      en = ((DERSequence)seq).getObjects();
    }
    else
    {
      Enumeration en;
      if ((seq instanceof DERSet))
      {
        en = ((DERSet)seq).getObjects();
      }
      else if ((seq instanceof DERTaggedObject))
      {
        DERTaggedObject derTag = (DERTaggedObject)seq;
        tag = Integer.toString(derTag.getTagNo());
        Vector v = new Vector();
        v.add(derTag.getObject());
        en = v.elements();
      }
      else
      {
        throw new IllegalArgumentException("DEREncodable must be one of: DERSequence, DERSet, DERTaggedObject");
      }
    }
    while ((en != null) && (en.hasMoreElements()))
    {
      DEREncodable obj = (DEREncodable)en.nextElement();
      if ((!(obj instanceof DERSequence)) && (!(obj instanceof DERSet)) && (!(obj instanceof DERTaggedObject)))
      {
        String str = obj.toString();
        String name = obj.getClass().getName();
        name = name.substring(name.lastIndexOf('.') + 1);
        if (tag != null) {
          name = " [tag=" + tag + "] " + name;
        }
        for (int i = 0; i < depth; i++) {
          name = "  " + name;
        }
        if ((obj instanceof DERInteger))
        {
          DERInteger dInt = (DERInteger)obj;
          if (derIntegers != null) {
            derIntegers.add(dInt);
          }
          BigInteger big = dInt.getValue();
          int intValue = big.intValue();
          if ((BIGGEST.compareTo(big) >= 0) && (intValue > 0)) {
            if (iterationCount == 0) {
              iterationCount = intValue;
            } else if (keySize == 0) {
              keySize = intValue;
            }
          }
          str = dInt.getValue().toString();
        }
        else if ((obj instanceof DERObjectIdentifier))
        {
          DERObjectIdentifier id = (DERObjectIdentifier)obj;
          str = id.getId();
          oids.add(str);
          if (oid1 == null) {
            oid1 = str;
          } else if (oid2 == null) {
            oid2 = str;
          } else if (oid3 == null) {
            oid3 = str;
          }
        }
        else
        {
          derIntegers = null;
          if ((obj instanceof DEROctetString))
          {
            DEROctetString oct = (DEROctetString)obj;
            byte[] octets = oct.getOctets();
            int len = Math.min(10, octets.length);
            boolean probablyBinary = false;
            for (int i = 0; i < len; i++)
            {
              byte b = octets[i];
              boolean isBinary = (b > 128) || (b < 0);
              if (isBinary)
              {
                probablyBinary = true;
                break;
              }
            }
            if ((probablyBinary) && (octets.length > 64))
            {
              if (bigPayload == null) {
                bigPayload = octets;
              }
              str = "probably binary";
            }
            else
            {
              str = Hex.encode(octets);
              if (octets.length <= 64) {
                if (octets.length % 8 == 0)
                {
                  if (salt == null) {
                    salt = octets;
                  } else if (iv == null) {
                    iv = octets;
                  }
                }
                else if (smallPayload == null) {
                  smallPayload = octets;
                }
              }
            }
            str = str + " (length=" + octets.length + ")";
          }
          else if ((obj instanceof DERPrintableString))
          {
            DERPrintableString dps = (DERPrintableString)obj;
            str = dps.getString();
          }
        }
        if (DEBUG) {
          System.out.println(name + ": [" + str + "]");
        }
      }
      else
      {
        if ((tag != null) && (DEBUG))
        {
          String name = obj.getClass().getName();
          name = name.substring(name.lastIndexOf('.') + 1);
          name = " [tag=" + tag + "] " + name;
          for (int i = 0; i < depth; i++) {
            name = "  " + name;
          }
          System.out.println(name);
        }
        analyze(obj, pkcs8, depth + 1);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.ASN1Util
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.math.BigInteger;
import org.apache.commons.ssl.util.UTF8;

public class Base64
{
  private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
  private static final int DEFAULT_BUFFER_SIZE = 8192;
  static final int CHUNK_SIZE = 76;
  static final byte[] CHUNK_SEPARATOR = { 13, 10 };
  private static final byte[] STANDARD_ENCODE_TABLE = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47 };
  private static final byte[] URL_SAFE_ENCODE_TABLE = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 95 };
  private static final byte PAD = 61;
  private static final byte[] DECODE_TABLE = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
  private static final int MASK_6BITS = 63;
  private static final int MASK_8BITS = 255;
  private final byte[] encodeTable;
  private final int lineLength;
  private final byte[] lineSeparator;
  private final int decodeSize;
  private final int encodeSize;
  private byte[] buffer;
  private int pos;
  private int readPos;
  private int currentLinePos;
  private int modulus;
  private boolean eof;
  private int x;
  
  public Base64()
  {
    this(false);
  }
  
  public Base64(boolean urlSafe)
  {
    this(76, CHUNK_SEPARATOR, urlSafe);
  }
  
  public Base64(int lineLength)
  {
    this(lineLength, CHUNK_SEPARATOR);
  }
  
  public Base64(int lineLength, byte[] lineSeparator)
  {
    this(lineLength, lineSeparator, false);
  }
  
  public Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
  {
    if (lineSeparator == null)
    {
      lineLength = 0;
      lineSeparator = CHUNK_SEPARATOR;
    }
    this.lineLength = (lineLength > 0 ? lineLength / 4 * 4 : 0);
    this.lineSeparator = new byte[lineSeparator.length];
    System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
    if (lineLength > 0) {
      encodeSize = (4 + lineSeparator.length);
    } else {
      encodeSize = 4;
    }
    decodeSize = (encodeSize - 1);
    if (containsBase64Byte(lineSeparator))
    {
      String sep = UTF8.toString(lineSeparator);
      throw new IllegalArgumentException("lineSeperator must not contain base64 characters: [" + sep + "]");
    }
    encodeTable = (urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE);
  }
  
  public boolean isUrlSafe()
  {
    return encodeTable == URL_SAFE_ENCODE_TABLE;
  }
  
  boolean hasData()
  {
    return buffer != null;
  }
  
  int avail()
  {
    return buffer != null ? pos - readPos : 0;
  }
  
  private void resizeBuffer()
  {
    if (buffer == null)
    {
      buffer = new byte['?'];
      pos = 0;
      readPos = 0;
    }
    else
    {
      byte[] b = new byte[buffer.length * 2];
      System.arraycopy(buffer, 0, b, 0, buffer.length);
      buffer = b;
    }
  }
  
  int readResults(byte[] b, int bPos, int bAvail)
  {
    if (buffer != null)
    {
      int len = Math.min(avail(), bAvail);
      if (buffer != b)
      {
        System.arraycopy(buffer, readPos, b, bPos, len);
        readPos += len;
        if (readPos >= pos) {
          buffer = null;
        }
      }
      else
      {
        buffer = null;
      }
      return len;
    }
    return eof ? -1 : 0;
  }
  
  void setInitialBuffer(byte[] out, int outPos, int outAvail)
  {
    if ((out != null) && (out.length == outAvail))
    {
      buffer = out;
      pos = outPos;
      readPos = outPos;
    }
  }
  
  void encode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0)
    {
      eof = true;
      if ((buffer == null) || (buffer.length - pos < encodeSize)) {
        resizeBuffer();
      }
      switch (modulus)
      {
      case 1: 
        buffer[(pos++)] = encodeTable[(x >> 2 & 0x3F)];
        buffer[(pos++)] = encodeTable[(x << 4 & 0x3F)];
        if (encodeTable == STANDARD_ENCODE_TABLE)
        {
          buffer[(pos++)] = 61;
          buffer[(pos++)] = 61;
        }
        break;
      case 2: 
        buffer[(pos++)] = encodeTable[(x >> 10 & 0x3F)];
        buffer[(pos++)] = encodeTable[(x >> 4 & 0x3F)];
        buffer[(pos++)] = encodeTable[(x << 2 & 0x3F)];
        if (encodeTable == STANDARD_ENCODE_TABLE) {
          buffer[(pos++)] = 61;
        }
        break;
      }
      if ((lineLength > 0) && (pos > 0))
      {
        System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
        pos += lineSeparator.length;
      }
    }
    else
    {
      for (int i = 0; i < inAvail; i++)
      {
        if ((buffer == null) || (buffer.length - pos < encodeSize)) {
          resizeBuffer();
        }
        modulus = (++modulus % 3);
        int b = in[(inPos++)];
        if (b < 0) {
          b += 256;
        }
        x = ((x << 8) + b);
        if (0 == modulus)
        {
          buffer[(pos++)] = encodeTable[(x >> 18 & 0x3F)];
          buffer[(pos++)] = encodeTable[(x >> 12 & 0x3F)];
          buffer[(pos++)] = encodeTable[(x >> 6 & 0x3F)];
          buffer[(pos++)] = encodeTable[(x & 0x3F)];
          currentLinePos += 4;
          if ((lineLength > 0) && (lineLength <= currentLinePos))
          {
            System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
            pos += lineSeparator.length;
            currentLinePos = 0;
          }
        }
      }
    }
  }
  
  void decode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0) {
      eof = true;
    }
    for (int i = 0; i < inAvail; i++)
    {
      if ((buffer == null) || (buffer.length - pos < decodeSize)) {
        resizeBuffer();
      }
      byte b = in[(inPos++)];
      if (b == 61)
      {
        eof = true;
        break;
      }
      if ((b >= 0) && (b < DECODE_TABLE.length))
      {
        int result = DECODE_TABLE[b];
        if (result >= 0)
        {
          modulus = (++modulus % 4);
          x = ((x << 6) + result);
          if (modulus == 0)
          {
            buffer[(pos++)] = ((byte)(x >> 16 & 0xFF));
            buffer[(pos++)] = ((byte)(x >> 8 & 0xFF));
            buffer[(pos++)] = ((byte)(x & 0xFF));
          }
        }
      }
    }
    if ((eof) && (modulus != 0))
    {
      x <<= 6;
      switch (modulus)
      {
      case 2: 
        x <<= 6;
        buffer[(pos++)] = ((byte)(x >> 16 & 0xFF));
        break;
      case 3: 
        buffer[(pos++)] = ((byte)(x >> 16 & 0xFF));
        buffer[(pos++)] = ((byte)(x >> 8 & 0xFF));
      }
    }
  }
  
  public static boolean isBase64(byte octet)
  {
    return (octet == 61) || ((octet >= 0) && (octet < DECODE_TABLE.length) && (DECODE_TABLE[octet] != -1));
  }
  
  public static boolean isArrayByteBase64(byte[] arrayOctet)
  {
    for (int i = 0; i < arrayOctet.length; i++) {
      if ((!isBase64(arrayOctet[i])) && (!isWhiteSpace(arrayOctet[i]))) {
        return false;
      }
    }
    return true;
  }
  
  private static boolean containsBase64Byte(byte[] arrayOctet)
  {
    for (int i = 0; i < arrayOctet.length; i++) {
      if (isBase64(arrayOctet[i])) {
        return true;
      }
    }
    return false;
  }
  
  public static byte[] encodeBase64(byte[] binaryData)
  {
    return encodeBase64(binaryData, false);
  }
  
  public static String encodeBase64String(byte[] binaryData)
  {
    return UTF8.toString(encodeBase64(binaryData, true));
  }
  
  public static byte[] encodeBase64URLSafe(byte[] binaryData)
  {
    return encodeBase64(binaryData, false, true);
  }
  
  public static String encodeBase64URLSafeString(byte[] binaryData)
  {
    return UTF8.toString(encodeBase64(binaryData, false, true));
  }
  
  public static byte[] encodeBase64Chunked(byte[] binaryData)
  {
    return encodeBase64(binaryData, true);
  }
  
  public Object decode(Object pObject)
  {
    if ((pObject instanceof byte[])) {
      return decode((byte[])pObject);
    }
    if ((pObject instanceof String)) {
      return decode((String)pObject);
    }
    throw new IllegalArgumentException("Parameter supplied to Base64 decode is not a byte[] or a String");
  }
  
  public byte[] decode(String pArray)
  {
    return decode(UTF8.toBytes(pArray));
  }
  
  public byte[] decode(byte[] pArray)
  {
    reset();
    if ((pArray == null) || (pArray.length == 0)) {
      return pArray;
    }
    long len = pArray.length * 3 / 4;
    byte[] buf = new byte[(int)len];
    setInitialBuffer(buf, 0, buf.length);
    decode(pArray, 0, pArray.length);
    decode(pArray, 0, -1);
    
    byte[] result = new byte[pos];
    readResults(result, 0, result.length);
    return result;
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked)
  {
    return encodeBase64(binaryData, isChunked, false);
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)
  {
    return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE);
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)
  {
    if ((binaryData == null) || (binaryData.length == 0)) {
      return binaryData;
    }
    long len = getEncodeLength(binaryData, 76, CHUNK_SEPARATOR);
    if (len > maxResultSize) {
      throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len + ") than the specified maxium size of " + maxResultSize);
    }
    Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
    return b64.encode(binaryData);
  }
  
  public static byte[] decodeBase64(String base64String)
  {
    return new Base64().decode(base64String);
  }
  
  public static byte[] decodeBase64(byte[] base64Data)
  {
    return new Base64().decode(base64Data);
  }
  
  /**
   * @deprecated
   */
  static byte[] discardWhitespace(byte[] data)
  {
    byte[] groomedData = new byte[data.length];
    int bytesCopied = 0;
    for (int i = 0; i < data.length; i++) {
      switch (data[i])
      {
      case 9: 
      case 10: 
      case 13: 
      case 32: 
        break;
      default: 
        groomedData[(bytesCopied++)] = data[i];
      }
    }
    byte[] packedData = new byte[bytesCopied];
    System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
    return packedData;
  }
  
  private static boolean isWhiteSpace(byte byteToCheck)
  {
    switch (byteToCheck)
    {
    case 9: 
    case 10: 
    case 13: 
    case 32: 
      return true;
    }
    return false;
  }
  
  public Object encode(Object pObject)
  {
    if (!(pObject instanceof byte[])) {
      throw new IllegalArgumentException("Parameter supplied to Base64 encode is not a byte[]");
    }
    return encode((byte[])pObject);
  }
  
  public String encodeToString(byte[] pArray)
  {
    return UTF8.toString(encode(pArray));
  }
  
  public byte[] encode(byte[] pArray)
  {
    reset();
    if ((pArray == null) || (pArray.length == 0)) {
      return pArray;
    }
    long len = getEncodeLength(pArray, lineLength, lineSeparator);
    byte[] buf = new byte[(int)len];
    setInitialBuffer(buf, 0, buf.length);
    encode(pArray, 0, pArray.length);
    encode(pArray, 0, -1);
    if (buffer != buf) {
      readResults(buf, 0, buf.length);
    }
    if ((isUrlSafe()) && (pos < buf.length))
    {
      byte[] smallerBuf = new byte[pos];
      System.arraycopy(buf, 0, smallerBuf, 0, pos);
      buf = smallerBuf;
    }
    return buf;
  }
  
  private static long getEncodeLength(byte[] pArray, int chunkSize, byte[] chunkSeparator)
  {
    chunkSize = chunkSize / 4 * 4;
    
    long len = pArray.length * 4 / 3;
    long mod = len % 4L;
    if (mod != 0L) {
      len += 4L - mod;
    }
    if (chunkSize > 0)
    {
      boolean lenChunksPerfectly = len % chunkSize == 0L;
      len += len / chunkSize * chunkSeparator.length;
      if (!lenChunksPerfectly) {
        len += chunkSeparator.length;
      }
    }
    return len;
  }
  
  public static BigInteger decodeInteger(byte[] pArray)
  {
    return new BigInteger(1, decodeBase64(pArray));
  }
  
  public static byte[] encodeInteger(BigInteger bigInt)
  {
    if (bigInt == null) {
      throw new NullPointerException("encodeInteger called with null parameter");
    }
    return encodeBase64(toIntegerBytes(bigInt), false);
  }
  
  static byte[] toIntegerBytes(BigInteger bigInt)
  {
    int bitlen = bigInt.bitLength();
    
    bitlen = bitlen + 7 >> 3 << 3;
    byte[] bigBytes = bigInt.toByteArray();
    if ((bigInt.bitLength() % 8 != 0) && (bigInt.bitLength() / 8 + 1 == bitlen / 8)) {
      return bigBytes;
    }
    int startSrc = 0;
    int len = bigBytes.length;
    if (bigInt.bitLength() % 8 == 0)
    {
      startSrc = 1;
      len--;
    }
    int startDst = bitlen / 8 - len;
    byte[] resizedBytes = new byte[bitlen / 8];
    System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len);
    return resizedBytes;
  }
  
  private void reset()
  {
    buffer = null;
    pos = 0;
    readPos = 0;
    currentLinePos = 0;
    modulus = 0;
    eof = false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.Base64
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Base64InputStream
  extends FilterInputStream
{
  private final boolean doEncode;
  private final Base64 base64;
  private final byte[] singleByte = new byte[1];
  
  public Base64InputStream(InputStream in)
  {
    this(in, false);
  }
  
  public Base64InputStream(InputStream in, boolean doEncode)
  {
    super(in);
    this.doEncode = doEncode;
    base64 = new Base64();
  }
  
  public Base64InputStream(InputStream in, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(in);
    this.doEncode = doEncode;
    base64 = new Base64(lineLength, lineSeparator);
  }
  
  public int read()
    throws IOException
  {
    int r = read(singleByte, 0, 1);
    while (r == 0) {
      r = read(singleByte, 0, 1);
    }
    if (r > 0) {
      return singleByte[0] < 0 ? 256 + singleByte[0] : singleByte[0];
    }
    return -1;
  }
  
  public int read(byte[] b, int offset, int len)
    throws IOException
  {
    if (b == null) {
      throw new NullPointerException();
    }
    if ((offset < 0) || (len < 0)) {
      throw new IndexOutOfBoundsException();
    }
    if ((offset > b.length) || (offset + len > b.length)) {
      throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
      return 0;
    }
    if (!base64.hasData())
    {
      byte[] buf = new byte[doEncode ? '?' : '?'];
      int c = in.read(buf);
      if ((c > 0) && (b.length == len)) {
        base64.setInitialBuffer(b, offset, len);
      }
      if (doEncode) {
        base64.encode(buf, 0, c);
      } else {
        base64.decode(buf, 0, c);
      }
    }
    return base64.readResults(b, offset, len);
  }
  
  public boolean markSupported()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.Base64InputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Base64OutputStream
  extends FilterOutputStream
{
  private final boolean doEncode;
  private final Base64 base64;
  private final byte[] singleByte = new byte[1];
  
  public Base64OutputStream(OutputStream out)
  {
    this(out, true);
  }
  
  public Base64OutputStream(OutputStream out, boolean doEncode)
  {
    super(out);
    this.doEncode = doEncode;
    base64 = new Base64();
  }
  
  public Base64OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(out);
    this.doEncode = doEncode;
    base64 = new Base64(lineLength, lineSeparator);
  }
  
  public void write(int i)
    throws IOException
  {
    singleByte[0] = ((byte)i);
    write(singleByte, 0, 1);
  }
  
  public void write(byte[] b, int offset, int len)
    throws IOException
  {
    if (b == null) {
      throw new NullPointerException();
    }
    if ((offset < 0) || (len < 0)) {
      throw new IndexOutOfBoundsException();
    }
    if ((offset > b.length) || (offset + len > b.length)) {
      throw new IndexOutOfBoundsException();
    }
    if (len > 0)
    {
      if (doEncode) {
        base64.encode(b, offset, len);
      } else {
        base64.decode(b, offset, len);
      }
      flush(false);
    }
  }
  
  private void flush(boolean propogate)
    throws IOException
  {
    int avail = base64.avail();
    if (avail > 0)
    {
      byte[] buf = new byte[avail];
      int c = base64.readResults(buf, 0, avail);
      if (c > 0) {
        out.write(buf, 0, c);
      }
    }
    if (propogate) {
      out.flush();
    }
  }
  
  public void flush()
    throws IOException
  {
    flush(true);
  }
  
  public void close()
    throws IOException
  {
    if (doEncode) {
      base64.encode(singleByte, 0, -1);
    } else {
      base64.decode(singleByte, 0, -1);
    }
    flush();
    out.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.Base64OutputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.security.GeneralSecurityException;
import javax.net.SocketFactory;

public class CRLSocket
  extends SSLClient
{
  private static final CRLSocket secureInstance;
  private static final CRLSocket plainInstance;
  
  static
  {
    CRLSocket sf1 = null;CRLSocket sf2 = null;
    try
    {
      sf1 = new CRLSocket();
      sf2 = new CRLSocket();
      sf2.setIsSecure(false);
    }
    catch (Exception e)
    {
      System.out.println("could not create CRLSocket: " + e);
      e.printStackTrace();
    }
    finally
    {
      secureInstance = sf1;
      plainInstance = sf2;
    }
  }
  
  private CRLSocket()
    throws GeneralSecurityException, IOException
  {
    if (TrustMaterial.JSSE_CACERTS != null) {
      setTrustMaterial(TrustMaterial.JSSE_CACERTS);
    } else {
      setTrustMaterial(TrustMaterial.CACERTS);
    }
    setConnectTimeout(5000);
    setSoTimeout(5000);
    setCheckCRL(false);
  }
  
  public static SocketFactory getDefault()
  {
    return getSecureInstance();
  }
  
  public static CRLSocket getSecureInstance()
  {
    return secureInstance;
  }
  
  public static CRLSocket getPlainInstance()
  {
    return plainInstance;
  }
  
  public static void main(String[] args)
    throws Exception
  {
    String host = args[0];
    String port = args[1];
    String hello = "HEAD / HTTP/1.1\r\nHost:" + host + ":" + port + "\r\n\r\n";
    
    byte[] helloBytes = hello.getBytes("UTF-8");
    
    System.out.println("About to getInstance() ");
    CRLSocket sf = getPlainInstance();
    long now = System.currentTimeMillis();
    System.out.println("About to create socket: [" + host + ":" + port + "]");
    Socket s = sf.createSocket(host, Integer.parseInt(port));
    long delay = System.currentTimeMillis() - now;
    System.out.println("Created socket! took " + delay + "ms ");
    OutputStream out = s.getOutputStream();
    out.write(helloBytes);
    out.flush();
    
    System.out.println("\n" + new String(helloBytes, "UTF-8"));
    
    InputStream in = s.getInputStream();
    int c = in.read();
    StringBuffer buf = new StringBuffer();
    System.out.println("Reading: ");
    System.out.println("================================================================================");
    while (c >= 0)
    {
      byte b = (byte)c;
      buf.append((char)b);
      System.out.print((char)b);
      if (-1 != buf.toString().indexOf("\r\n\r\n")) {
        break;
      }
      c = in.read();
    }
    in.close();
    out.close();
    s.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.CRLSocket
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.IOException;

public class CRLUtil
{
  public static String getURLToCRL(byte[] extension2_5_29_31)
    throws IOException
  {
    throw new UnsupportedOperationException("not yet implemented");
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.CRLUtil
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.math.BigInteger;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.Date;

class Certificates$1
  implements Certificates.SerializableComparator
{
  public int compare(Object o1, Object o2)
  {
    X509Certificate c1 = (X509Certificate)o1;
    X509Certificate c2 = (X509Certificate)o2;
    if (c1 == c2) {
      return 0;
    }
    if (c1 == null) {
      return -1;
    }
    if (c2 == null) {
      return 1;
    }
    if (c1.equals(c2)) {
      return 0;
    }
    Date d1 = c1.getNotAfter();
    Date d2 = c2.getNotAfter();
    int c = d1.compareTo(d2);
    if (c == 0)
    {
      String s1 = JavaImpl.getSubjectX500(c1);
      String s2 = JavaImpl.getSubjectX500(c2);
      c = s1.compareTo(s2);
      if (c == 0)
      {
        s1 = JavaImpl.getIssuerX500(c1);
        s2 = JavaImpl.getIssuerX500(c2);
        c = s1.compareTo(s2);
        if (c == 0)
        {
          BigInteger big1 = c1.getSerialNumber();
          BigInteger big2 = c2.getSerialNumber();
          c = big1.compareTo(big2);
          if (c == 0) {
            try
            {
              byte[] b1 = c1.getEncoded();
              byte[] b2 = c2.getEncoded();
              int len1 = b1.length;
              int len2 = b2.length;
              for (int i = 0; (i < len1) && (i < len2); i++)
              {
                c = b1[i] - b2[i];
                if (c != 0) {
                  break;
                }
              }
              if (c == 0) {
                c = b1.length - b2.length;
              }
            }
            catch (CertificateEncodingException cee)
            {
              c = 0;
            }
          }
        }
      }
    }
    return c;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.Certificates.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.security.cert.CRL;
import java.security.cert.CRLException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.HashSet;
import java.util.Set;
import javax.net.ssl.HttpsURLConnection;

class Certificates$CRLHolder
{
  private final String urlString;
  private File tempCRLFile;
  private long creationTime;
  private Set passedTest = new HashSet();
  private Set failedTest = new HashSet();
  
  Certificates$CRLHolder(String urlString)
  {
    if (urlString == null) {
      throw new NullPointerException("urlString can't be null");
    }
    this.urlString = urlString;
  }
  
  public synchronized boolean checkCRL(X509Certificate cert)
    throws CertificateException
  {
    CRL crl = null;
    long now = System.currentTimeMillis();
    if (now - creationTime > 86400000L)
    {
      if ((tempCRLFile != null) && (tempCRLFile.exists())) {
        tempCRLFile.delete();
      }
      tempCRLFile = null;
      passedTest.clear();
    }
    BigInteger fingerprint = Certificates.getFingerprint(cert);
    if (failedTest.contains(fingerprint)) {
      throw new CertificateException("Revoked by CRL (cached response)");
    }
    if (passedTest.contains(fingerprint)) {
      return true;
    }
    if (tempCRLFile == null) {
      try
      {
        URL url = new URL(urlString);
        URLConnection urlConn = url.openConnection();
        if ((urlConn instanceof HttpsURLConnection))
        {
          HttpsURLConnection httpsConn = (HttpsURLConnection)urlConn;
          httpsConn.setSSLSocketFactory(CRLSocket.getSecureInstance());
        }
        else if ((urlConn instanceof HttpURLConnection))
        {
          HttpURLConnection httpConn = (HttpURLConnection)urlConn;
          try
          {
            Class c = httpConn.getClass();
            Method setConnTimeOut = c.getDeclaredMethod("setConnectTimeout", new Class[] { Integer.TYPE });
            Method setReadTimeout = c.getDeclaredMethod("setReadTimeout", new Class[] { Integer.TYPE });
            setConnTimeOut.invoke(httpConn, new Integer[] { new Integer(5000) });
            setReadTimeout.invoke(httpConn, new Integer[] { new Integer(5000) });
          }
          catch (NoSuchMethodException nsme) {}catch (Exception e)
          {
            throw new RuntimeException("can't set timeout", e);
          }
        }
        File tempFile = File.createTempFile("crl", ".tmp");
        tempFile.deleteOnExit();
        
        OutputStream out = new FileOutputStream(tempFile);
        out = new BufferedOutputStream(out);
        InputStream in = new BufferedInputStream(urlConn.getInputStream());
        try
        {
          Util.pipeStream(in, out);
        }
        catch (IOException ioe)
        {
          tempFile.delete();
          throw ioe;
        }
        tempCRLFile = tempFile;
        creationTime = System.currentTimeMillis();
      }
      catch (IOException ioe) {}
    }
    if ((tempCRLFile != null) && (tempCRLFile.exists())) {
      try
      {
        InputStream in = new FileInputStream(tempCRLFile);
        in = new BufferedInputStream(in);
        synchronized (Certificates.CF)
        {
          crl = Certificates.CF.generateCRL(in);
        }
        in.close();
        if (crl.isRevoked(cert))
        {
          passedTest.remove(fingerprint);
          failedTest.add(fingerprint);
          throw new CertificateException("Revoked by CRL");
        }
        passedTest.add(fingerprint);
      }
      catch (IOException ioe) {}catch (CRLException crle) {}
    }
    return crl != null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.Certificates.CRLHolder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.Serializable;
import java.util.Comparator;

public abstract interface Certificates$SerializableComparator
  extends Comparator, Serializable
{}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.Certificates.SerializableComparator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl;

import java.io.BufferedInputStream
1 2 3 4 5 6 7 8 9 10 11 12 13

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd