Giter Club home page Giter Club logo

pkix-ocsp's Introduction

OCSP Client

Build Status Codecov

Getting started

Include dependency in your pom.xml:

<dependency>
    <groupId>net.klakegg.pkix</groupId>
    <artifactId>pkix-ocsp</artifactId>
    <version>0.9.0</version>
</dependency>

Create your own validator:

// 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).
CertificateResult response = client.verify(certificate, issuer);

// Prints 'GOOD', 'REVOKED' or 'UNKNOWN'.
System.out.println(response.getStatus());

pkix-ocsp's People

Contributors

klakegg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pkix-ocsp's Issues

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.