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

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

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.security.cert.impl;

import java.io.Serializable;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;

import org.bouncycastle.asn1.x500.X500Name;

import br.net.woodstock.rockframework.core.RockFrameworkVersion;
import br.net.woodstock.rockframework.core.utils.Conditions;
import br.net.woodstock.rockframework.security.Identity;
import br.net.woodstock.rockframework.security.cert.OCSPRequest;
import br.net.woodstock.rockframework.security.sign.SignatureType;
import br.net.woodstock.rockframework.security.util.BouncyCastleProviderHelper;

public class BouncyCastleOCSPRequest implements Serializable {

  private static final long  serialVersionUID  = RockFrameworkVersion.VERSION;

  private Identity      issuer;

  private SignatureType    signType;

  private byte[]        request;

  public BouncyCastleOCSPRequest(final OCSPRequest request) {
    super();
    this.issuer = request.getIssuer();
    this.signType = request.getSignType();
    this.request = request.getRequest();
  }

  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 byte[] getRequest() {
    return this.request;
  }

  public void setRequest(final byte[] request) {
    this.request = request;
  }

  // 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.BouncyCastleOCSPRequest

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.