package cn.unitid.matrix.pkiservice.test.svs;

import cn.unitid.matrix.pkiservice.sdk.ApiException;
import cn.unitid.matrix.pkiservice.sdk.PkiClient;
import cn.unitid.matrix.pkiservice.sdk.PkiOkhttpClient;
import cn.unitid.matrix.pkiservice.sdk.svs.request.OcspVerifyRequest;
import cn.unitid.matrix.pkiservice.sdk.svs.response.OcspVerifyResponse;

/**
 * @author Shy
 * @className OcspVerifyTest
 * @description OCSP校验测试
 * @date 2022/8/15 11:04
 **/
public class OcspVerifyTest {
    public static void main(String[] args) {
        // 提供的URL
        String url = "http://localhost:20402";

        // 您的appKey
        String appKey = "4WLraMuAwd";

        // 您的appSecret
        String appSecret = "iZFq9hKUU2VEKQShHT9QvuBRP6Jb8KNV";

        // 1.原客户端
        PkiClient pkiClient = new PkiOkhttpClient(url, appKey, appSecret);

        OcspVerifyRequest ocspVerifyRequest = new OcspVerifyRequest();

        //设置待验证证书
        ocspVerifyRequest.setCert("MIIB6zCCAY+gAwIBAgIGAXKnMMauMAwGCCqBHM9VAYN1BQAwSTELMAkGA1UEBhMCQ04xDjAMBgNVBAoTBUdNU1NMMRAwDgYDVQQLEwdQS0kvU00yMRgwFgYDVQQDEw9Sb290Q0EgZm9yIFRlc3QwIhgPMjAxNTEyMzExNjAwMDBaGA8yMDM1MTIzMDE2MDAwMFowSzELMAkGA1UEBhMCQ04xDjAMBgNVBAoTBUdNU1NMMRAwDgYDVQQLEwdQS0kvU00yMRowGAYDVQQDExFNaWRkbGVDQSBmb3IgVGVzdDBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABA4uB1fiqJjs1uR6bFIrtxvLFuoU0x+uPPxrslzodyTG1Mj9dJpm4AUjT9q2bL4cj7H73qWJNpwArnZr7fCc3A2jWzBZMBsGA1UdIwQUMBKAEJxp7A+6GjnFr+gk67KcEgQwGQYDVR0OBBIEEPl/VbQnlDNiplbKb8xdGv8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAMYwDAYIKoEcz1UBg3UFAANIADBFAiA31tn0qKz6G0YgGjWd6/ULMyqfTzoL82Y7EkvxbOpX/AIhAKCJYkDp62cvbKvj/Njc2dIe5BN+DGhO5JOhIyo4oWE3");

        // 指定ocsp请求地址
        //ocspVerifyRequest.setOcspUrl("");

        //设置ca证书
        //ocspVerifyRequest.setCaCert();

        try {
            OcspVerifyResponse response = pkiClient.execute(ocspVerifyRequest);
            if (response.isSuccess()) {
                System.out.println("成功：" + response.getBody());
            } else {
                System.out.println("失败：" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }


    }
}
