bcpkix-jdk15on-147

return this;
  }
  
  public RevocationDetailsBuilder setSubject(X500Name paramX500Name)
  {
    if (paramX500Name != null) {
      templateBuilder.setSubject(paramX500Name);
    }
    return this;
  }
  
  public RevocationDetails build()
  {
    return new RevocationDetails(new RevDetails(templateBuilder.build()));
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.cmp.RevocationDetailsBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.crmf.CRMFObjectIdentifiers;

public class AuthenticatorControl
  implements Control
{
  private static final ASN1ObjectIdentifier type = CRMFObjectIdentifiers.id_regCtrl_authenticator;
  private final DERUTF8String token;
  
  public AuthenticatorControl(DERUTF8String paramDERUTF8String)
  {
    token = paramDERUTF8String;
  }
  
  public AuthenticatorControl(String paramString)
  {
    token = new DERUTF8String(paramString);
  }
  
  public ASN1ObjectIdentifier getType()
  {
    return type;
  }
  
  public ASN1Encodable getValue()
  {
    return token;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.AuthenticatorControl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

public class CRMFException
  extends Exception
{
  private Throwable cause;
  
  public CRMFException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    cause = paramThrowable;
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.CRMFException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

public class CRMFRuntimeException
  extends RuntimeException
{
  private Throwable cause;
  
  public CRMFRuntimeException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    cause = paramThrowable;
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.CRMFRuntimeException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DEROutputStream;
import org.bouncycastle.asn1.x509.ExtensionsGenerator;
import org.bouncycastle.cert.CertIOException;

class CRMFUtil
{
  static void derEncodeToStream(ASN1Encodable paramASN1Encodable, OutputStream paramOutputStream)
  {
    DEROutputStream localDEROutputStream = new DEROutputStream(paramOutputStream);
    try
    {
      localDEROutputStream.writeObject(paramASN1Encodable);
      localDEROutputStream.close();
    }
    catch (IOException localIOException)
    {
      throw new CRMFRuntimeException("unable to DER encode object: " + localIOException.getMessage(), localIOException);
    }
  }
  
  static void addExtension(ExtensionsGenerator paramExtensionsGenerator, ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean, ASN1Encodable paramASN1Encodable)
    throws CertIOException
  {
    try
    {
      paramExtensionsGenerator.addExtension(paramASN1ObjectIdentifier, paramBoolean, paramASN1Encodable);
    }
    catch (IOException localIOException)
    {
      throw new CertIOException("cannot encode extension: " + localIOException.getMessage(), localIOException);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.CRMFUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.IOException;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.crmf.AttributeTypeAndValue;
import org.bouncycastle.asn1.crmf.CRMFObjectIdentifiers;
import org.bouncycastle.asn1.crmf.CertReqMsg;
import org.bouncycastle.asn1.crmf.CertRequest;
import org.bouncycastle.asn1.crmf.CertTemplate;
import org.bouncycastle.asn1.crmf.Controls;
import org.bouncycastle.asn1.crmf.PKIArchiveOptions;
import org.bouncycastle.asn1.crmf.PKMACValue;
import org.bouncycastle.asn1.crmf.POPOSigningKey;
import org.bouncycastle.asn1.crmf.POPOSigningKeyInput;
import org.bouncycastle.asn1.crmf.ProofOfPossession;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.operator.ContentVerifier;
import org.bouncycastle.operator.ContentVerifierProvider;
import org.bouncycastle.operator.OperatorCreationException;

public class CertificateRequestMessage
{
  public static final int popRaVerified = 0;
  public static final int popSigningKey = 1;
  public static final int popKeyEncipherment = 2;
  public static final int popKeyAgreement = 3;
  private final CertReqMsg certReqMsg;
  private final Controls controls;
  
  private static CertReqMsg parseBytes(byte[] paramArrayOfByte)
    throws IOException
  {
    try
    {
      return CertReqMsg.getInstance(ASN1Primitive.fromByteArray(paramArrayOfByte));
    }
    catch (ClassCastException localClassCastException)
    {
      throw new CertIOException("malformed data: " + localClassCastException.getMessage(), localClassCastException);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CertIOException("malformed data: " + localIllegalArgumentException.getMessage(), localIllegalArgumentException);
    }
  }
  
  public CertificateRequestMessage(byte[] paramArrayOfByte)
    throws IOException
  {
    this(parseBytes(paramArrayOfByte));
  }
  
  public CertificateRequestMessage(CertReqMsg paramCertReqMsg)
  {
    certReqMsg = paramCertReqMsg;
    controls = paramCertReqMsg.getCertReq().getControls();
  }
  
  public CertReqMsg toASN1Structure()
  {
    return certReqMsg;
  }
  
  public CertTemplate getCertTemplate()
  {
    return certReqMsg.getCertReq().getCertTemplate();
  }
  
  public boolean hasControls()
  {
    return controls != null;
  }
  
  public boolean hasControl(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    return findControl(paramASN1ObjectIdentifier) != null;
  }
  
  public Control getControl(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    AttributeTypeAndValue localAttributeTypeAndValue = findControl(paramASN1ObjectIdentifier);
    if (localAttributeTypeAndValue != null)
    {
      if (localAttributeTypeAndValue.getType().equals(CRMFObjectIdentifiers.id_regCtrl_pkiArchiveOptions)) {
        return new PKIArchiveControl(PKIArchiveOptions.getInstance(localAttributeTypeAndValue.getValue()));
      }
      if (localAttributeTypeAndValue.getType().equals(CRMFObjectIdentifiers.id_regCtrl_regToken)) {
        return new RegTokenControl(DERUTF8String.getInstance(localAttributeTypeAndValue.getValue()));
      }
      if (localAttributeTypeAndValue.getType().equals(CRMFObjectIdentifiers.id_regCtrl_authenticator)) {
        return new AuthenticatorControl(DERUTF8String.getInstance(localAttributeTypeAndValue.getValue()));
      }
    }
    return null;
  }
  
  private AttributeTypeAndValue findControl(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    if (controls == null) {
      return null;
    }
    AttributeTypeAndValue[] arrayOfAttributeTypeAndValue = controls.toAttributeTypeAndValueArray();
    AttributeTypeAndValue localAttributeTypeAndValue = null;
    for (int i = 0; i != arrayOfAttributeTypeAndValue.length; i++) {
      if (arrayOfAttributeTypeAndValue[i].getType().equals(paramASN1ObjectIdentifier))
      {
        localAttributeTypeAndValue = arrayOfAttributeTypeAndValue[i];
        break;
      }
    }
    return localAttributeTypeAndValue;
  }
  
  public boolean hasProofOfPossession()
  {
    return certReqMsg.getPopo() != null;
  }
  
  public int getProofOfPossessionType()
  {
    return certReqMsg.getPopo().getType();
  }
  
  public boolean hasSigningKeyProofOfPossessionWithPKMAC()
  {
    ProofOfPossession localProofOfPossession = certReqMsg.getPopo();
    if (localProofOfPossession.getType() == 1)
    {
      POPOSigningKey localPOPOSigningKey = POPOSigningKey.getInstance(localProofOfPossession.getObject());
      return localPOPOSigningKey.getPoposkInput().getPublicKeyMAC() != null;
    }
    return false;
  }
  
  public boolean isValidSigningKeyPOP(ContentVerifierProvider paramContentVerifierProvider)
    throws CRMFException, IllegalStateException
  {
    ProofOfPossession localProofOfPossession = certReqMsg.getPopo();
    if (localProofOfPossession.getType() == 1)
    {
      POPOSigningKey localPOPOSigningKey = POPOSigningKey.getInstance(localProofOfPossession.getObject());
      if ((localPOPOSigningKey.getPoposkInput() != null) && (localPOPOSigningKey.getPoposkInput().getPublicKeyMAC() != null)) {
        throw new IllegalStateException("verification requires password check");
      }
      return verifySignature(paramContentVerifierProvider, localPOPOSigningKey);
    }
    throw new IllegalStateException("not Signing Key type of proof of possession");
  }
  
  public boolean isValidSigningKeyPOP(ContentVerifierProvider paramContentVerifierProvider, PKMACBuilder paramPKMACBuilder, char[] paramArrayOfChar)
    throws CRMFException, IllegalStateException
  {
    ProofOfPossession localProofOfPossession = certReqMsg.getPopo();
    if (localProofOfPossession.getType() == 1)
    {
      POPOSigningKey localPOPOSigningKey = POPOSigningKey.getInstance(localProofOfPossession.getObject());
      if ((localPOPOSigningKey.getPoposkInput() == null) || (localPOPOSigningKey.getPoposkInput().getSender() != null)) {
        throw new IllegalStateException("no PKMAC present in proof of possession");
      }
      PKMACValue localPKMACValue = localPOPOSigningKey.getPoposkInput().getPublicKeyMAC();
      PKMACValueVerifier localPKMACValueVerifier = new PKMACValueVerifier(paramPKMACBuilder);
      if (localPKMACValueVerifier.isValid(localPKMACValue, paramArrayOfChar, getCertTemplate().getPublicKey())) {
        return verifySignature(paramContentVerifierProvider, localPOPOSigningKey);
      }
      return false;
    }
    throw new IllegalStateException("not Signing Key type of proof of possession");
  }
  
  private boolean verifySignature(ContentVerifierProvider paramContentVerifierProvider, POPOSigningKey paramPOPOSigningKey)
    throws CRMFException
  {
    ContentVerifier localContentVerifier;
    try
    {
      localContentVerifier = paramContentVerifierProvider.get(paramPOPOSigningKey.getAlgorithmIdentifier());
    }
    catch (OperatorCreationException localOperatorCreationException)
    {
      throw new CRMFException("unable to create verifier: " + localOperatorCreationException.getMessage(), localOperatorCreationException);
    }
    if (paramPOPOSigningKey.getPoposkInput() != null) {
      CRMFUtil.derEncodeToStream(paramPOPOSigningKey.getPoposkInput(), localContentVerifier.getOutputStream());
    } else {
      CRMFUtil.derEncodeToStream(certReqMsg.getCertReq(), localContentVerifier.getOutputStream());
    }
    return localContentVerifier.verify(paramPOPOSigningKey.getSignature().getBytes());
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return certReqMsg.getEncoded();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.CertificateRequestMessage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Null;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.crmf.AttributeTypeAndValue;
import org.bouncycastle.asn1.crmf.CertReqMsg;
import org.bouncycastle.asn1.crmf.CertRequest;
import org.bouncycastle.asn1.crmf.CertTemplate;
import org.bouncycastle.asn1.crmf.CertTemplateBuilder;
import org.bouncycastle.asn1.crmf.POPOPrivKey;
import org.bouncycastle.asn1.crmf.ProofOfPossession;
import org.bouncycastle.asn1.crmf.SubsequentMessage;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.ExtensionsGenerator;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.operator.ContentSigner;

public class CertificateRequestMessageBuilder
{
  private final BigInteger certReqId;
  private ExtensionsGenerator extGenerator;
  private CertTemplateBuilder templateBuilder;
  private List controls;
  private ContentSigner popSigner;
  private PKMACBuilder pkmacBuilder;
  private char[] password;
  private GeneralName sender;
  private POPOPrivKey popoPrivKey;
  private ASN1Null popRaVerified;
  
  public CertificateRequestMessageBuilder(BigInteger paramBigInteger)
  {
    certReqId = paramBigInteger;
    extGenerator = new ExtensionsGenerator();
    templateBuilder = new CertTemplateBuilder();
    controls = new ArrayList();
  }
  
  public CertificateRequestMessageBuilder setPublicKey(SubjectPublicKeyInfo paramSubjectPublicKeyInfo)
  {
    if (paramSubjectPublicKeyInfo != null) {
      templateBuilder.setPublicKey(paramSubjectPublicKeyInfo);
    }
    return this;
  }
  
  public CertificateRequestMessageBuilder setIssuer(X500Name paramX500Name)
  {
    if (paramX500Name != null) {
      templateBuilder.setIssuer(paramX500Name);
    }
    return this;
  }
  
  public CertificateRequestMessageBuilder setSubject(X500Name paramX500Name)
  {
    if (paramX500Name != null) {
      templateBuilder.setSubject(paramX500Name);
    }
    return this;
  }
  
  public CertificateRequestMessageBuilder setSerialNumber(BigInteger paramBigInteger)
  {
    if (paramBigInteger != null) {
      templateBuilder.setSerialNumber(new ASN1Integer(paramBigInteger));
    }
    return this;
  }
  
  public CertificateRequestMessageBuilder addExtension(ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean, ASN1Encodable paramASN1Encodable)
    throws CertIOException
  {
    CRMFUtil.addExtension(extGenerator, paramASN1ObjectIdentifier, paramBoolean, paramASN1Encodable);
    return this;
  }
  
  public CertificateRequestMessageBuilder addExtension(ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean, byte[] paramArrayOfByte)
  {
    extGenerator.addExtension(paramASN1ObjectIdentifier, paramBoolean, paramArrayOfByte);
    return this;
  }
  
  public CertificateRequestMessageBuilder addControl(Control paramControl)
  {
    controls.add(paramControl);
    return this;
  }
  
  public CertificateRequestMessageBuilder setProofOfPossessionSigningKeySigner(ContentSigner paramContentSigner)
  {
    if ((popoPrivKey != null) || (popRaVerified != null)) {
      throw new IllegalStateException("only one proof of possession allowed");
    }
    popSigner = paramContentSigner;
    return this;
  }
  
  public CertificateRequestMessageBuilder setProofOfPossessionSubsequentMessage(SubsequentMessage paramSubsequentMessage)
  {
    if ((popSigner != null) || (popRaVerified != null)) {
      throw new IllegalStateException("only one proof of possession allowed");
    }
    popoPrivKey = new POPOPrivKey(paramSubsequentMessage);
    return this;
  }
  
  public CertificateRequestMessageBuilder setProofOfPossessionRaVerified()
  {
    if ((popSigner != null) || (popoPrivKey != null)) {
      throw new IllegalStateException("only one proof of possession allowed");
    }
    popRaVerified = DERNull.INSTANCE;
    return this;
  }
  
  public CertificateRequestMessageBuilder setAuthInfoPKMAC(PKMACBuilder paramPKMACBuilder, char[] paramArrayOfChar)
  {
    pkmacBuilder = paramPKMACBuilder;
    password = paramArrayOfChar;
    return this;
  }
  
  public CertificateRequestMessageBuilder setAuthInfoSender(X500Name paramX500Name)
  {
    return setAuthInfoSender(new GeneralName(paramX500Name));
  }
  
  public CertificateRequestMessageBuilder setAuthInfoSender(GeneralName paramGeneralName)
  {
    sender = paramGeneralName;
    return this;
  }
  
  public CertificateRequestMessage build()
    throws CRMFException
  {
    ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
    localASN1EncodableVector.add(new ASN1Integer(certReqId));
    if (!extGenerator.isEmpty()) {
      templateBuilder.setExtensions(extGenerator.generate());
    }
    localASN1EncodableVector.add(templateBuilder.build());
    Object localObject2;
    Object localObject3;
    if (!controls.isEmpty())
    {
      localObject1 = new ASN1EncodableVector();
      localObject2 = controls.iterator();
      while (((Iterator)localObject2).hasNext())
      {
        localObject3 = (Control)((Iterator)localObject2).next();
        ((ASN1EncodableVector)localObject1).add(new AttributeTypeAndValue(((Control)localObject3).getType(), ((Control)localObject3).getValue()));
      }
      localASN1EncodableVector.add(new DERSequence((ASN1EncodableVector)localObject1));
    }
    Object localObject1 = CertRequest.getInstance(new DERSequence(localASN1EncodableVector));
    localASN1EncodableVector = new ASN1EncodableVector();
    localASN1EncodableVector.add((ASN1Encodable)localObject1);
    if (popSigner != null)
    {
      localObject2 = ((CertRequest)localObject1).getCertTemplate();
      if ((((CertTemplate)localObject2).getSubject() == null) || (((CertTemplate)localObject2).getPublicKey() == null))
      {
        localObject3 = ((CertRequest)localObject1).getCertTemplate().getPublicKey();
        ProofOfPossessionSigningKeyBuilder localProofOfPossessionSigningKeyBuilder = new ProofOfPossessionSigningKeyBuilder((SubjectPublicKeyInfo)localObject3);
        if (sender != null)
        {
          localProofOfPossessionSigningKeyBuilder.setSender(sender);
        }
        else
        {
          PKMACValueGenerator localPKMACValueGenerator = new PKMACValueGenerator(pkmacBuilder);
          localProofOfPossessionSigningKeyBuilder.setPublicKeyMac(localPKMACValueGenerator, password);
        }
        localASN1EncodableVector.add(new ProofOfPossession(localProofOfPossessionSigningKeyBuilder.build(popSigner)));
      }
      else
      {
        localObject3 = new ProofOfPossessionSigningKeyBuilder((CertRequest)localObject1);
        localASN1EncodableVector.add(new ProofOfPossession(((ProofOfPossessionSigningKeyBuilder)localObject3).build(popSigner)));
      }
    }
    else if (popoPrivKey != null)
    {
      localASN1EncodableVector.add(new ProofOfPossession(2, popoPrivKey));
    }
    else if (popRaVerified != null)
    {
      localASN1EncodableVector.add(new ProofOfPossession());
    }
    return new CertificateRequestMessage(CertReqMsg.getInstance(new DERSequence(localASN1EncodableVector)));
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.CertificateRequestMessageBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;

public abstract interface Control
{
  public abstract ASN1ObjectIdentifier getType();
  
  public abstract ASN1Encodable getValue();
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.Control
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.crmf.EncryptedValue;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.KeyWrapper;
import org.bouncycastle.operator.OperatorException;
import org.bouncycastle.operator.OutputEncryptor;
import org.bouncycastle.util.Strings;

public class EncryptedValueBuilder
{
  private KeyWrapper wrapper;
  private OutputEncryptor encryptor;
  private EncryptedValuePadder padder;
  
  public EncryptedValueBuilder(KeyWrapper paramKeyWrapper, OutputEncryptor paramOutputEncryptor)
  {
    this(paramKeyWrapper, paramOutputEncryptor, null);
  }
  
  public EncryptedValueBuilder(KeyWrapper paramKeyWrapper, OutputEncryptor paramOutputEncryptor, EncryptedValuePadder paramEncryptedValuePadder)
  {
    wrapper = paramKeyWrapper;
    encryptor = paramOutputEncryptor;
    padder = paramEncryptedValuePadder;
  }
  
  public EncryptedValue build(char[] paramArrayOfChar)
    throws CRMFException
  {
    return encryptData(padData(Strings.toUTF8ByteArray(paramArrayOfChar)));
  }
  
  public EncryptedValue build(X509CertificateHolder paramX509CertificateHolder)
    throws CRMFException
  {
    try
    {
      return encryptData(padData(paramX509CertificateHolder.getEncoded()));
    }
    catch (IOException localIOException)
    {
      throw new CRMFException("cannot encode certificate: " + localIOException.getMessage(), localIOException);
    }
  }
  
  private EncryptedValue encryptData(byte[] paramArrayOfByte)
    throws CRMFException
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    OutputStream localOutputStream = encryptor.getOutputStream(localByteArrayOutputStream);
    try
    {
      localOutputStream.write(paramArrayOfByte);
      localOutputStream.close();
    }
    catch (IOException localIOException)
    {
      throw new CRMFException("cannot process data: " + localIOException.getMessage(), localIOException);
    }
    AlgorithmIdentifier localAlgorithmIdentifier1 = null;
    AlgorithmIdentifier localAlgorithmIdentifier2 = encryptor.getAlgorithmIdentifier();
    DERBitString localDERBitString1;
    try
    {
      wrapper.generateWrappedKey(encryptor.getKey());
      localDERBitString1 = new DERBitString(wrapper.generateWrappedKey(encryptor.getKey()));
    }
    catch (OperatorException localOperatorException)
    {
      throw new CRMFException("cannot wrap key: " + localOperatorException.getMessage(), localOperatorException);
    }
    AlgorithmIdentifier localAlgorithmIdentifier3 = wrapper.getAlgorithmIdentifier();
    ASN1OctetString localASN1OctetString = null;
    DERBitString localDERBitString2 = new DERBitString(localByteArrayOutputStream.toByteArray());
    return new EncryptedValue(localAlgorithmIdentifier1, localAlgorithmIdentifier2, localDERBitString1, localAlgorithmIdentifier3, localASN1OctetString, localDERBitString2);
  }
  
  private byte[] padData(byte[] paramArrayOfByte)
  {
    if (padder != null) {
      return padder.getPaddedData(paramArrayOfByte);
    }
    return paramArrayOfByte;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.EncryptedValueBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

public abstract interface EncryptedValuePadder
{
  public abstract byte[] getPaddedData(byte[] paramArrayOfByte);
  
  public abstract byte[] getUnpaddedData(byte[] paramArrayOfByte);
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.EncryptedValuePadder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.crmf.EncryptedValue;
import org.bouncycastle.asn1.x509.Certificate;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.InputDecryptor;
import org.bouncycastle.util.Strings;
import org.bouncycastle.util.io.Streams;

public class EncryptedValueParser
{
  private EncryptedValue value;
  private EncryptedValuePadder padder;
  
  public EncryptedValueParser(EncryptedValue paramEncryptedValue)
  {
    value = paramEncryptedValue;
  }
  
  public EncryptedValueParser(EncryptedValue paramEncryptedValue, EncryptedValuePadder paramEncryptedValuePadder)
  {
    value = paramEncryptedValue;
    padder = paramEncryptedValuePadder;
  }
  
  private byte[] decryptValue(ValueDecryptorGenerator paramValueDecryptorGenerator)
    throws CRMFException
  {
    if (value.getIntendedAlg() != null) {
      throw new UnsupportedOperationException();
    }
    if (value.getValueHint() != null) {
      throw new UnsupportedOperationException();
    }
    InputDecryptor localInputDecryptor = paramValueDecryptorGenerator.getValueDecryptor(value.getKeyAlg(), value.getSymmAlg(), value.getEncSymmKey().getBytes());
    InputStream localInputStream = localInputDecryptor.getInputStream(new ByteArrayInputStream(value.getEncValue().getBytes()));
    try
    {
      byte[] arrayOfByte = Streams.readAll(localInputStream);
      if (padder != null) {
        return padder.getUnpaddedData(arrayOfByte);
      }
      return arrayOfByte;
    }
    catch (IOException localIOException)
    {
      throw new CRMFException("Cannot parse decrypted data: " + localIOException.getMessage(), localIOException);
    }
  }
  
  public X509CertificateHolder readCertificateHolder(ValueDecryptorGenerator paramValueDecryptorGenerator)
    throws CRMFException
  {
    return new X509CertificateHolder(Certificate.getInstance(decryptValue(paramValueDecryptorGenerator)));
  }
  
  public char[] readPassphrase(ValueDecryptorGenerator paramValueDecryptorGenerator)
    throws CRMFException
  {
    return Strings.fromUTF8ByteArray(decryptValue(paramValueDecryptorGenerator)).toCharArray();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.EncryptedValueParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.security.SecureRandom;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.crypto.generators.MGF1BytesGenerator;
import org.bouncycastle.crypto.params.MGFParameters;

public class FixedLengthMGF1Padder
  implements EncryptedValuePadder
{
  private int length;
  private SecureRandom random;
  private Digest dig = new SHA1Digest();
  
  public FixedLengthMGF1Padder(int paramInt)
  {
    this(paramInt, null);
  }
  
  public FixedLengthMGF1Padder(int paramInt, SecureRandom paramSecureRandom)
  {
    length = paramInt;
    random = paramSecureRandom;
  }
  
  public byte[] getPaddedData(byte[] paramArrayOfByte)
  {
    byte[] arrayOfByte1 = new byte[length];
    byte[] arrayOfByte2 = new byte[dig.getDigestSize()];
    byte[] arrayOfByte3 = new byte[length - dig.getDigestSize()];
    if (random == null) {
      random = new SecureRandom();
    }
    random.nextBytes(arrayOfByte2);
    MGF1BytesGenerator localMGF1BytesGenerator = new MGF1BytesGenerator(dig);
    localMGF1BytesGenerator.init(new MGFParameters(arrayOfByte2));
    localMGF1BytesGenerator.generateBytes(arrayOfByte3, 0, arrayOfByte3.length);
    System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, arrayOfByte2.length);
    System.arraycopy(paramArrayOfByte, 0, arrayOfByte1, arrayOfByte2.length, paramArrayOfByte.length);
    for (int i = arrayOfByte2.length + paramArrayOfByte.length + 1; i != arrayOfByte1.length; i++) {
      arrayOfByte1[i] = ((byte)(1 + random.nextInt(255)));
    }
    for (i = 0; i != arrayOfByte3.length; i++)
    {
      int tmp176_175 = (i + arrayOfByte2.length);
      byte[] tmp176_170 = arrayOfByte1;
      tmp176_170[tmp176_175] = ((byte)(tmp176_170[tmp176_175] ^ arrayOfByte3[i]));
    }
    return arrayOfByte1;
  }
  
  public byte[] getUnpaddedData(byte[] paramArrayOfByte)
  {
    byte[] arrayOfByte1 = new byte[dig.getDigestSize()];
    byte[] arrayOfByte2 = new byte[length - dig.getDigestSize()];
    System.arraycopy(paramArrayOfByte, 0, arrayOfByte1, 0, arrayOfByte1.length);
    MGF1BytesGenerator localMGF1BytesGenerator = new MGF1BytesGenerator(dig);
    localMGF1BytesGenerator.init(new MGFParameters(arrayOfByte1));
    localMGF1BytesGenerator.generateBytes(arrayOfByte2, 0, arrayOfByte2.length);
    for (int i = 0; i != arrayOfByte2.length; i++)
    {
      int tmp90_89 = (i + arrayOfByte1.length);
      byte[] tmp90_84 = paramArrayOfByte;
      tmp90_84[tmp90_89] = ((byte)(tmp90_84[tmp90_89] ^ arrayOfByte2[i]));
    }
    i = 0;
    for (int j = paramArrayOfByte.length - 1; j != arrayOfByte1.length; j--) {
      if (paramArrayOfByte[j] == 0)
      {
        i = j;
        break;
      }
    }
    if (i == 0) {
      throw new IllegalStateException("bad padding in encoding");
    }
    byte[] arrayOfByte3 = new byte[i - arrayOfByte1.length];
    System.arraycopy(paramArrayOfByte, arrayOfByte1.length, arrayOfByte3, 0, arrayOfByte3.length);
    return arrayOfByte3;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.FixedLengthMGF1Padder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.EnvelopedData;
import org.bouncycastle.asn1.crmf.CRMFObjectIdentifiers;
import org.bouncycastle.asn1.crmf.EncryptedKey;
import org.bouncycastle.asn1.crmf.PKIArchiveOptions;
import org.bouncycastle.cms.CMSEnvelopedData;
import org.bouncycastle.cms.CMSException;

public class PKIArchiveControl
  implements Control
{
  public static final int encryptedPrivKey = 0;
  public static final int keyGenParameters = 1;
  public static final int archiveRemGenPrivKey = 2;
  private static final ASN1ObjectIdentifier type = CRMFObjectIdentifiers.id_regCtrl_pkiArchiveOptions;
  private final PKIArchiveOptions pkiArchiveOptions;
  
  public PKIArchiveControl(PKIArchiveOptions paramPKIArchiveOptions)
  {
    pkiArchiveOptions = paramPKIArchiveOptions;
  }
  
  public ASN1ObjectIdentifier getType()
  {
    return type;
  }
  
  public ASN1Encodable getValue()
  {
    return pkiArchiveOptions;
  }
  
  public int getArchiveType()
  {
    return pkiArchiveOptions.getType();
  }
  
  public boolean isEnvelopedData()
  {
    EncryptedKey localEncryptedKey = EncryptedKey.getInstance(pkiArchiveOptions.getValue());
    return !localEncryptedKey.isEncryptedValue();
  }
  
  public CMSEnvelopedData getEnvelopedData()
    throws CRMFException
  {
    try
    {
      EncryptedKey localEncryptedKey = EncryptedKey.getInstance(pkiArchiveOptions.getValue());
      EnvelopedData localEnvelopedData = EnvelopedData.getInstance(localEncryptedKey.getValue());
      return new CMSEnvelopedData(new ContentInfo(CMSObjectIdentifiers.envelopedData, localEnvelopedData));
    }
    catch (CMSException localCMSException)
    {
      throw new CRMFException("CMS parsing error: " + localCMSException.getMessage(), localCMSException.getCause());
    }
    catch (Exception localException)
    {
      throw new CRMFException("CRMF parsing error: " + localException.getMessage(), localException);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.PKIArchiveControl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.IOException;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.EnvelopedData;
import org.bouncycastle.asn1.crmf.CRMFObjectIdentifiers;
import org.bouncycastle.asn1.crmf.EncKeyWithID;
import org.bouncycastle.asn1.crmf.EncryptedKey;
import org.bouncycastle.asn1.crmf.PKIArchiveOptions;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.cms.CMSEnvelopedData;
import org.bouncycastle.cms.CMSEnvelopedDataGenerator;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessableByteArray;
import org.bouncycastle.cms.RecipientInfoGenerator;
import org.bouncycastle.operator.OutputEncryptor;

public class PKIArchiveControlBuilder
{
  private CMSEnvelopedDataGenerator envGen;
  private CMSProcessableByteArray keyContent;
  
  public PKIArchiveControlBuilder(PrivateKeyInfo paramPrivateKeyInfo, GeneralName paramGeneralName)
  {
    EncKeyWithID localEncKeyWithID = new EncKeyWithID(paramPrivateKeyInfo, paramGeneralName);
    try
    {
      keyContent = new CMSProcessableByteArray(CRMFObjectIdentifiers.id_ct_encKeyWithID, localEncKeyWithID.getEncoded());
    }
    catch (IOException localIOException)
    {
      throw new IllegalStateException("unable to encode key and general name info");
    }
    envGen = new CMSEnvelopedDataGenerator();
  }
  
  public PKIArchiveControlBuilder addRecipientGenerator(RecipientInfoGenerator paramRecipientInfoGenerator)
  {
    envGen.addRecipientInfoGenerator(paramRecipientInfoGenerator);
    return this;
  }
  
  public PKIArchiveControl build(OutputEncryptor paramOutputEncryptor)
    throws CMSException
  {
    CMSEnvelopedData localCMSEnvelopedData = envGen.generate(keyContent, paramOutputEncryptor);
    EnvelopedData localEnvelopedData = EnvelopedData.getInstance(localCMSEnvelopedData.getContentInfo().getContent());
    return new PKIArchiveControl(new PKIArchiveOptions(new EncryptedKey(localEnvelopedData)));
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.PKIArchiveControlBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import org.bouncycastle.asn1.cmp.CMPObjectIdentifiers;
import org.bouncycastle.asn1.cmp.PBMParameter;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;
import org.bouncycastle.operator.RuntimeOperatorException;

class PKMACBuilder$1
  implements MacCalculator
{
  ByteArrayOutputStream bOut = new ByteArrayOutputStream();
  
  PKMACBuilder$1(PKMACBuilder paramPKMACBuilder, PBMParameter paramPBMParameter, byte[] paramArrayOfByte) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return new AlgorithmIdentifier(CMPObjectIdentifiers.passwordBasedMac, val$params);
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(val$key);
  }
  
  public OutputStream getOutputStream()
  {
    return bOut;
  }
  
  public byte[] getMac()
  {
    try
    {
      return PKMACBuilder.access$000(this$0).calculateMac(val$key, bOut.toByteArray());
    }
    catch (CRMFException localCRMFException)
    {
      throw new RuntimeOperatorException("exception calculating mac: " + localCRMFException.getMessage(), localCRMFException);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cert.crmf.PKMACBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cert.crmf;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.SecureRandom;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.cmp.CMPObjectIdentifiers;
import org.bouncycastle.asn1.cmp.PBMParameter;
import org.bouncycastle.asn1.iana.IANAObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;
import org.bouncycastle.operator.RuntimeOperatorException;
import org.bouncycastle.util.Strings;

public class PKMACBuilder
{
  private AlgorithmIdentifier owf;
  private int iterationCount;
  private AlgorithmIdentifier mac;
  private int saltLength = 20;
  private SecureRandom random;
  private PKMACValuesCalculator calculator;
  private PBMParameter parameters;
  private int maxIterations;
  
  public PKMACBuilder(PKMACValuesCalculator paramPKMACValuesCalculator)
  {
    this(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1), 1000, new AlgorithmIdentifier(IANAObjectIdentifiers.hmacSHA1, DERNull.INSTANCE), paramPKMACValuesCalculator);
  }
  
  public PKMACBuilder(PKMACValuesCalculator paramPKMACValuesCalculator, int paramInt)
  {
    maxIterations = paramInt;
    calculator = paramPKMACValuesCalculator;
  }
  
  private PKMACBuilder(AlgorithmIdentifier paramAlgorithmIdentifier1, int paramInt, AlgorithmIdentifier paramAlgorithmIdentifier2, PKMACValuesCalculator paramPKMACValuesCalculator)
  {
    owf = paramAlgorithmIdentifier1;
    iterationCount = paramInt;
    mac = paramAlgorithmIdentifier2;
    calculator = paramPKMACValuesCalculator;
  }
  
  public PKMACBuilder setSaltLength(int paramInt)
  {
    if (paramInt < 8) {
      throw new IllegalArgumentException("salt length must be at least 8 bytes");
    }
    saltLength = paramInt;
    return this;
  }
  
  public PKMACBuilder setIterationCount(int paramInt)
  {
    if (paramInt < 100) {
      throw new IllegalArgumentException("iteration count must be at least 100");
    }
    checkIterationCountCeiling(paramInt);
    iterationCount = paramInt;
    return this;
  }
  
  public PKMACBuilder setSecureRandom(SecureRandom paramSecureRandom)
  {
    random = paramSecureRandom;
    return this;
  }
  
  public PKMACBuilder setParameters(PBMParameter paramPBMParameter)
  {
    checkIterationCountCeiling(paramPBMParameter.getIterationCount().getValue().intValue());
    parameters = paramPBMParameter;
    return this;
  }
  
  public MacCalculator build(char[] paramArrayOfChar)
    throws CRMFException
  {
    if (parameters != null) {
      return genCalculator(parameters, paramArrayOfChar);
    }
    byte[] arrayOfByte = new byte[saltLength];
    if (random == null) {
      random = new SecureRandom();
    }
    random.nextBytes(arrayOfByte);
    return genCalculator(new PBMParameter(arrayOfByte, owf, iterationCount, mac), paramArrayOfChar);
  }
  
  private void checkIterationCountCeiling(int paramInt)
  {
    if ((maxIterations > 0) && (paramInt > maxIterations)) {
      throw new IllegalArgumentException("iteration count exceeds limit (" + paramInt + " > " + maxIterations + ")");
    }
  }
  
  private MacCalculator genCalculator(final PBMParameter paramPBMParameter, char[] paramArrayOfChar)
    throws CRMFException
  {
    byte[] arrayOfByte1 = Strings.toUTF8ByteArray(paramArrayOfChar);
    byte[] arrayOfByte2 = paramPBMParameter.getSalt().getOctets();
    byte[] arrayOfByte3 = new byte[arrayOfByte1.length + arrayOfByte2.length];
    System.arraycopy(arrayOfByte1, 0, arrayOfByte3, 0, arrayOfByte1.length);
    System.arraycopy(arrayOfByte2, 0, arrayOfByte3, arrayOfByte1.length, arrayOfByte2.length);
    calculator.setup(paramPBMParameter.getOwf(), paramPBMParameter.getMac());
    int i = paramPBMParameter.getIterationCount().getValue().intValue();
    do
    {
      arrayOfByte3 = calculator.calculateDigest(arrayOfByte3);
      i--;
    } while (i > 0);
    final byte[] arrayOfByte4 = arrayOfByte3;
    new MacCalculator()
    {
      ByteArrayOutputStream bOut = new ByteArrayOutputStream();
      
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return new AlgorithmIdentifier(CMPObjectIdentifiers.passwordBasedMac, paramPBMParameter);
      }
      
      public GenericKey getKey()
      {
        return new GenericKey(arrayOfByte4);
      }
      
      public OutputStream getOutputStream()
      {
        return bOut;
      }
      
      public byte[] getMac()
      {
        try
        {
          return calculator.calculateMac(arrayOfByte4, bOut.toByteArray());
        }
        catch (CRMFException localCRMFException)
        {
          throw new RuntimeOperatorExc
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 26 27 28 29 30 31

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