Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input Exception #1

Open
korayguney opened this issue May 26, 2018 · 0 comments

Comments

@korayguney
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant