Commit 66276d29 authored by pgouvas's avatar pgouvas
Browse files

added cetificate generation and usage

parent 4f8fdd38
......@@ -8,3 +8,11 @@ keytool -list -v keystore.jks
keytool -keypasswd -new changeit -keystore keystore.jks -storepass changeit -alias superadmin -keypass LPOqrkHPt+NOt311kmuzrGfS
API Spec: https://download.primekey.se/docs/EJBCA-Enterprise/6_15_2/ws/org/ejbca/core/protocol/ws/client/gen/EjbcaWS.html
https://www.ibm.com/support/knowledgecenter/en/SSKTMJ_9.0.1/admin/conf_keyusageextensionsandextendedkeyusage_r.html
keytool -list -v -keystore test.p12 -storepass user2 -storetype PKCS12
[Dolphin]
Timestamp=2020,1,8,17,26,35
Version=4
ViewMode=1
package eu.ubitech.ejbca.client;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
/**
*
* @author pgouvas
*/
public class BinaryValue implements Serializable {
public BinaryValue() {
}
private byte[] content;
public BinaryValue(byte[] content) {
this.content = content;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
package eu.ubitech.ejbca.client;
/**
*
* @author Panagiotis Gouvas (pgouvas@ubitech.eu)
*/
public class CertificateRequest {
private String username;
private Boolean onlyvalid;
public CertificateRequest(String username, Boolean onlyvalid) {
this.username = username;
this.onlyvalid = onlyvalid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Boolean getOnlyvalid() {
return onlyvalid;
}
public void setOnlyvalid(Boolean onlyvalid) {
this.onlyvalid = onlyvalid;
}
}//EoC
package eu.ubitech.ejbca.client;
/**
*
* @author Panagiotis Gouvas (pgouvas@ubitech.eu)
*/
public class PKCS12Request {
private String username;
private String password;
private String hardTokenSN;
private String keyspec; // that the generated key should have, examples are 2048 for RSA or secp256r1 for ECDSA.
private String keyalg; // the generated key should have, RSA, ECDSA. Use one of the constants in AlgorithmConstants.KEYALGORITHM_..
public PKCS12Request(String username, String password, String hardTokenSN, String keyspec, String keyalg) {
this.username = username;
this.password = password;
this.hardTokenSN = hardTokenSN;
this.keyspec = keyspec;
this.keyalg = keyalg;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getHardTokenSN() {
return hardTokenSN;
}
public void setHardTokenSN(String hardTokenSN) {
this.hardTokenSN = hardTokenSN;
}
public String getKeyspec() {
return keyspec;
}
public void setKeyspec(String keyspec) {
this.keyspec = keyspec;
}
public String getKeyalg() {
return keyalg;
}
public void setKeyalg(String keyalg) {
this.keyalg = keyalg;
}
}
package eu.ubitech.ejbca.rest;
import eu.ubitech.ejbca.client.BinaryValue;
import eu.ubitech.ejbca.client.CertificateRequest;
import eu.ubitech.ejbca.client.EjbcaUser;
import eu.ubitech.ejbca.client.EjbcaWSClientImpl;
import eu.ubitech.ejbca.client.PKCS12Request;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.ejbca.core.protocol.ws.AuthorizationDeniedException_Exception;
import org.ejbca.core.protocol.ws.CADoesntExistsException_Exception;
import org.ejbca.core.protocol.ws.Certificate;
import org.ejbca.core.protocol.ws.EjbcaException_Exception;
import org.ejbca.core.protocol.ws.KeyStore;
import org.ejbca.core.protocol.ws.NameAndId;
import org.ejbca.core.protocol.ws.NotFoundException_Exception;
import org.ejbca.core.protocol.ws.Pkcs12Req;
import org.ejbca.core.protocol.ws.RevokeStatus;
import org.ejbca.core.protocol.ws.UserDataVOWS;
import org.ejbca.core.protocol.ws.UserMatch;
......@@ -86,18 +94,29 @@ public class RestCAController {
}//EoM
@RequestMapping(path = "/2", method = RequestMethod.GET)
public void testx(HttpServletRequest request) {
// RevokeStatus revokestatus = ca.getEjbcaRAWS().pkcs12Req(arg0, arg1, arg2, arg3, arg4)
// logger.info("RevokeStatus: "+revokestatus);
@RequestMapping(path = "/createKeystore", method = RequestMethod.POST)
public BinaryValue createKeystore(@RequestBody PKCS12Request request) {
org.ejbca.core.protocol.ws.KeyStore pkcs12Req = null;
try {
pkcs12Req = ca.getEjbcaRAWS().pkcs12Req(request.getUsername(), request.getPassword(), request.getHardTokenSN(), request.getKeyspec(), request.getKeyalg());
} catch (AuthorizationDeniedException_Exception | NotFoundException_Exception | EjbcaException_Exception | CADoesntExistsException_Exception ex) {
Logger.getLogger(RestCAController.class.getName()).log(Level.SEVERE, null, ex);
}
return new BinaryValue(pkcs12Req.getKeystoreData());
}//EoM
@RequestMapping(path = "/2", method = RequestMethod.GET)
public void test2(HttpServletRequest request) {
RevokeStatus revokestatus = ca.checkCertificateRevokeStatus("CN=ManagementCA", "-628002118");
logger.info("RevokeStatus: "+revokestatus);
@RequestMapping(path = "/getCertificates", method = RequestMethod.POST)
public Object[] getCertificates(@RequestBody CertificateRequest request) {
List<Certificate> certificates = null;
try {
certificates = ca.getEjbcaRAWS().findCerts(request.getUsername(),request.getOnlyvalid());
logger.info("getCertificates: "+certificates.size());
} catch (AuthorizationDeniedException_Exception | EjbcaException_Exception ex) {
Logger.getLogger(RestCAController.class.getName()).log(Level.SEVERE, null, ex);
}
return certificates.toArray();
}//EoM
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.819+02:00
* 2020-01-08T17:15:51.699+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.792+02:00
* 2020-01-08T17:15:51.666+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.762+02:00
* 2020-01-08T17:15:51.632+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.739+02:00
* 2020-01-08T17:15:51.609+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.756+02:00
* 2020-01-08T17:15:51.623+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.749+02:00
* 2020-01-08T17:15:51.617+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.878+02:00
* 2020-01-08T17:15:51.764+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.862+02:00
* 2020-01-08T17:15:51.745+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.851+02:00
* 2020-01-08T17:15:51.734+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.874+02:00
* 2020-01-08T17:15:51.757+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.787+02:00
* 2020-01-08T17:15:51.658+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.868+02:00
* 2020-01-08T17:15:51.751+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.829+02:00
* 2020-01-08T17:15:51.711+02:00
* Generated source version: 3.3.2
*/
......
......@@ -6,7 +6,7 @@ import javax.xml.ws.WebFault;
/**
* This class was generated by Apache CXF 3.3.2
* 2020-01-07T15:38:54.769+02:00
* 2020-01-08T17:15:51.638+02:00
* Generated source version: 3.3.2
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment