Ejemplo n.º 1
0
  private DERBitString getPublicKeyDetails(JCEECPublicKey pub) {
    try {
      SubjectPublicKeyInfo info =
          SubjectPublicKeyInfo.getInstance(ASN1Object.fromByteArray(pub.getEncoded()));

      return info.getPublicKeyData();
    } catch (IOException e) { // should never happen
      return null;
    }
  }
Ejemplo n.º 2
0
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    byte[] enc = (byte[]) in.readObject();

    populateFromPrivKeyInfo(PrivateKeyInfo.getInstance(ASN1Object.fromByteArray(enc)));

    this.algorithm = (String) in.readObject();
    this.withCompression = in.readBoolean();
    this.attrCarrier = new PKCS12BagAttributeCarrierImpl();

    attrCarrier.readObject(in);
  }
Ejemplo n.º 3
0
  private BasicOCSPResp generateResponse(
      String signatureName,
      PrivateKey key,
      X509Certificate[] chain,
      Date producedAt,
      String provider,
      SecureRandom random)
      throws OCSPException, NoSuchProviderException {
    Iterator it = list.iterator();
    DERObjectIdentifier signingAlgorithm;

    try {
      signingAlgorithm = OCSPUtil.getAlgorithmOID(signatureName);
    } catch (Exception e) {
      throw new IllegalArgumentException("unknown signing algorithm specified");
    }

    ASN1EncodableVector responses = new ASN1EncodableVector();

    while (it.hasNext()) {
      try {
        responses.add(((ResponseObject) it.next()).toResponse());
      } catch (Exception e) {
        throw new OCSPException("exception creating Request", e);
      }
    }

    ResponseData tbsResp =
        new ResponseData(
            responderID.toASN1Object(),
            new DERGeneralizedTime(producedAt),
            new DERSequence(responses),
            responseExtensions);

    Signature sig = null;

    try {
      sig = OCSPUtil.createSignatureInstance(signatureName, provider);
      if (random != null) {
        sig.initSign(key, random);
      } else {
        sig.initSign(key);
      }
    } catch (NoSuchProviderException e) {
      // TODO Why this special case?
      throw e;
    } catch (GeneralSecurityException e) {
      throw new OCSPException("exception creating signature: " + e, e);
    }

    DERBitString bitSig = null;

    try {
      sig.update(tbsResp.getEncoded(ASN1Encodable.DER));

      bitSig = new DERBitString(sig.sign());
    } catch (Exception e) {
      throw new OCSPException("exception processing TBSRequest: " + e, e);
    }

    AlgorithmIdentifier sigAlgId = OCSPUtil.getSigAlgID(signingAlgorithm);

    DERSequence chainSeq = null;
    if (chain != null && chain.length > 0) {
      ASN1EncodableVector v = new ASN1EncodableVector();
      try {
        for (int i = 0; i != chain.length; i++) {
          v.add(
              new X509CertificateStructure(
                  (ASN1Sequence) ASN1Object.fromByteArray(chain[i].getEncoded())));
        }
      } catch (IOException e) {
        throw new OCSPException("error processing certs", e);
      } catch (CertificateEncodingException e) {
        throw new OCSPException("error encoding certs", e);
      }

      chainSeq = new DERSequence(v);
    }

    return new BasicOCSPResp(new BasicOCSPResponse(tbsResp, sigAlgId, bitSig, chainSeq));
  }