Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java getRevokedCertificate(BigInteger)方法始终返回null_Java_Android_Eclipse_Biginteger_X509 - Fatal编程技术网

Java getRevokedCertificate(BigInteger)方法始终返回null

Java getRevokedCertificate(BigInteger)方法始终返回null,java,android,eclipse,biginteger,x509,Java,Android,Eclipse,Biginteger,X509,我试图通过在.crl文件中搜索某个证书的条目来检查该证书是否已被吊销。为此,我使用了一个简单的代码,在这里,只要点击一个按钮,就可以下载.crl文件,然后在其中搜索证书的序列号 使用 问题是,方法getRevokedCertificate总是返回null,尽管我确信被吊销证书的序列号在.crl文件中。我可以肯定,因为方法crl.getRevokedCertificates().toString()打印了一些条目,我从这些条目中提取序列号 下面的代码是可复制的,由Android Studio制作。

我试图通过在.crl文件中搜索某个证书的条目来检查该证书是否已被吊销。为此,我使用了一个简单的代码,在这里,只要点击一个按钮,就可以下载.crl文件,然后在其中搜索证书的序列号

使用

问题是,方法
getRevokedCertificate
总是返回null,尽管我确信被吊销证书的序列号在.crl文件中。我可以肯定,因为方法
crl.getRevokedCertificates().toString()
打印了一些条目,我从这些条目中提取序列号

下面的代码是可复制的,由Android Studio制作。只需要一个按钮

public void getCRL(View view) throws  IOException {
    // Force downloading on main thread
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // Where is the crl?
    String stURL = "http://www.trustcenter.de/crl/v2/tcclass0.crl";
    URL url = new URL(stURL);

    // Open connection
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        // Get .crtFile
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509CRL crl = (X509CRL) cf.generateCRL(in);
        Log.d("All revoked: ", crl.getRevokedCertificates().toString());

        // Test what certificate? Serial number
        String STcertSN = "550B00010002F12E05BFE98E3627";
        BigInteger certSN = new BigInteger(STcertSN,16);
        Log.d("Serial number in decimal: ", certSN.toString());

        // See if revoked
        X509CRLEntry isRevoked = crl.getRevokedCertificate(certSN);

        if (isRevoked != null) {
            Log.d("Revoking: ", isRevoked.toString());
        } else {
            Log.d("Revoing: ","Was not revoked");
        }

    } catch (Exception e) {
        Log.e("uri","Failed at everything");
    }
    finally {
            urlConnection.disconnect();
    }
}
编辑: 我现在已经在Eclipse中尝试了相同的代码。代码似乎工作正常-我收到了关于发现的吊销证书的消息。

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.cert.CertificateFactory;
import java.security.cert.X509CRL;
import java.security.cert.X509CRLEntry;

public class crt {
    public static void main(String[] args) {
        System.out.println("hello");
        try {
        getCRL();
    } catch (IOException e) {
        e.printStackTrace();
    }

}


public static void getCRL() throws  IOException {
    // Where is the crl?
    String stURL = "http://www.trustcenter.de/crl/v2/tcclass0.crl";
    URL url = new URL(stURL);

    // Open connection
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        // Get .crtFile
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509CRL crl = (X509CRL) cf.generateCRL(in);
        System.out.println("All revoked: " + crl.getRevokedCertificates().toString());

        // Test what certificate? Serial number
        String STcertSN = "550B00010002F12E05BFE98E3627";
        BigInteger certSN = new BigInteger(STcertSN,16);
        System.out.println("Serial number in decimal: "+ certSN.toString());

        // See if revoked
        X509CRLEntry isRevoked = crl.getRevokedCertificate(certSN);

        if (isRevoked != null) {
            System.out.println("FOUND REVOKED CERTIFICATE ALARM!: "+ isRevoked.toString());
        } else {
            System.out.println("Revoing: "+"Was not revoked");
        }

    } catch (Exception e) {
        System.out.println("uri" +"Failed at everything");
    }
    finally {
            urlConnection.disconnect();
    }
}
}

如果这是安卓系统中的一个bug,我如何报告它?

并且您不会得到任何异常,对吗?你查过日志了吗?没有,没有例外。我正在读取日志,以获取已吊销证书的序列号,并获取响应
未吊销
,这是由返回的null引起的。除非我没有捕捉到一些,并且它们没有被注意到。您是在查看完整的logcat还是通过
d
进行过滤?使用
无过滤器进行检查。没有例外。