Package br.net.woodstock.rockframework.security.cert.impl

Source Code of br.net.woodstock.rockframework.security.cert.impl.BouncyCastleCRLRequest

package br.net.woodstock.rockframework.security.cert.impl;

import java.io.Serializable;
import java.math.BigInteger;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Set;

import org.bouncycastle.asn1.x500.X500Name;

import br.net.woodstock.rockframework.core.RockFrameworkVersion;
import br.net.woodstock.rockframework.core.util.DateBuilder;
import br.net.woodstock.rockframework.core.util.DateField;
import br.net.woodstock.rockframework.core.utils.Conditions;
import br.net.woodstock.rockframework.security.Identity;
import br.net.woodstock.rockframework.security.cert.CRLEntry;
import br.net.woodstock.rockframework.security.cert.CRLRequest;
import br.net.woodstock.rockframework.security.sign.SignatureType;
import br.net.woodstock.rockframework.security.util.BouncyCastleProviderHelper;

public class BouncyCastleCRLRequest implements Serializable {

  private static final long  serialVersionUID  = RockFrameworkVersion.VERSION;

  private Identity      issuer;

  private SignatureType    signType;

  private BigInteger      number;

  private Date        nextUpdate;

  private byte[]        oldCrl;

  private Set<CRLEntry>    entries;

  public BouncyCastleCRLRequest(final CRLRequest request) {
    super();
    this.issuer = request.getIssuer();
    this.signType = request.getSignType();
    this.number = request.getNumber();
    this.nextUpdate = request.getNextUpdate();
    this.entries = request.getEntries();

    if (this.number == null) {
      this.number = BigInteger.ONE;
    }

    if (this.nextUpdate == null) {
      DateBuilder builder = new DateBuilder();
      builder.add(DateField.DAY_OF_MONTH, 1);
      this.nextUpdate = builder.build();
    }
  }

  public Identity getIssuer() {
    return this.issuer;
  }

  public void setIssuer(final Identity issuer) {
    this.issuer = issuer;
  }

  public SignatureType getSignType() {
    return this.signType;
  }

  public void setSignType(final SignatureType signType) {
    this.signType = signType;
  }

  public BigInteger getNumber() {
    return this.number;
  }

  public void setNumber(final BigInteger number) {
    this.number = number;
  }

  public Date getNextUpdate() {
    return this.nextUpdate;
  }

  public void setNextUpdate(final Date nextUpdate) {
    this.nextUpdate = nextUpdate;
  }

  public byte[] getOldCrl() {
    return this.oldCrl;
  }

  public void setOldCrl(final byte[] oldCrl) {
    this.oldCrl = oldCrl;
  }

  public Set<CRLEntry> getEntries() {
    return this.entries;
  }

  public void setEntries(final Set<CRLEntry> entries) {
    this.entries = entries;
  }

  // Aux
  public String getSignAlgorithm() {
    return this.getSignType().getAlgorithm();
  }

  public PrivateKey getIssuerPrivateKey() {
    Identity identity = this.getIssuer();
    if (identity != null) {
      return identity.getPrivateKey();
    }
    return null;
  }

  public X509Certificate getIssuerCertificate() {
    Identity identity = this.getIssuer();
    if (identity != null) {
      Certificate[] chain = identity.getChain();
      if (Conditions.isNotEmpty(chain)) {
        return (X509Certificate) chain[0];
      }
    }
    return null;
  }

  public X500Name getIssuerX500Name() {
    Identity identity = this.getIssuer();
    if (identity != null) {
      Certificate[] chain = identity.getChain();
      if (Conditions.isNotEmpty(chain)) {
        X509Certificate certificate = (X509Certificate) chain[0];
        return BouncyCastleProviderHelper.toX500Name(certificate.getIssuerX500Principal());
      }
    }
    return null;
  }

}
TOP

Related Classes of br.net.woodstock.rockframework.security.cert.impl.BouncyCastleCRLRequest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.