klakegg / pkix-ocsp Goto Github PK
View Code? Open in Web Editor NEWLicense: Mozilla Public License 2.0
License: Mozilla Public License 2.0
Hi,
At first, your OCSP source code is excellent. I am trying to use your code, I wrote a main method to test it. My source code is at below;
`package net.klakegg.pkix.ocsp;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
public class MainTest {
public static String serverCert= "certs/spidrserver.pem";
public static String intCert= "certs/spidrinter.pem";
public static String rootCert= "certs/spidrroot.pem";
static byte[] certDataServer = Base64.decodeBase64(serverCert.getBytes());
static byte[] certDataInt = Base64.decodeBase64(intCert.getBytes());
static byte[] certDataRoot = Base64.decodeBase64(rootCert.getBytes());
static File certFile = new File(serverCert);
public static void isFileExist(){
if (certFile.exists()){
System.out.println("Certificate founded!");
}else {
System.out.println("Certificate NOT FOUND!");
}
}
public static void main(String[] args) throws OcspException {
isFileExist();
X509Certificate certificate = createCert(certDataInt);
X509Certificate issuer = createCert(certDataRoot);
// Create OCSP Client using builder.
OcspClient client = OcspClient.builder()
.set(OcspClient.EXCEPTION_ON_UNKNOWN, false) // Remove to trigger exception on 'UNKNOWN'.
.set(OcspClient.EXCEPTION_ON_REVOKED, false) // Remove to trigger exception on 'REVOKED'.
.build();
// Verify certificate (issuer certificate required).
// CertificateIssuer issuer1 = CertificateIssuer.generate(issuer);
CertificateResult response = client.verify(certificate, issuer);
// Prints 'GOOD', 'REVOKED' or 'UNKNOWN'.
System.out.println(response.getStatus());
}
public static X509Certificate createCert(byte[] certData){
try {
CertificateFactory cf=CertificateFactory.getInstance("X509");
X509Certificate cert=(X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certData));
return cert;
}
catch ( Exception e) {
throw new RuntimeException(e);
}
}
}
`
When I try to run this code, I have encountered a "java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input Exception"
Can you have any idea to solve this problem?
Thanks...
Koray
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.