首页 > 解决方案 > 如何在 Ubuntu 和 Android 上使用英特尔 SGX 服务提供商证书?

问题描述

我已经在英特尔论坛上发布了这个问题,但我的日程安排有限,我需要一个快速的答案,所以我正在联系所有可用的媒体。

我正在开发一个小型英特尔 SGX 应用程序,该应用程序通过 Android 服务提供商进行远程证明。我需要您的帮助,以了解如何使用我在英特尔注册的证书向 IAS 发出 HTTPS 请求(如文档中所引用)。

我有一个小型测试 Java 程序,它向 IAS 发出一个简单的 Retreive SigRL GET 请求,只是为了测试它是否有效。但是当它尝试执行 HTTPS 请求时,我不断收到 SSLHandshakeException。

Java 代码:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;

public class Prog {

    public static void main(String[] args) throws Exception {
        makeRequest();
    }

    public static void makeRequest() throws Exception {

        String url = "https://test-as.sgx.trustedservices.intel.com:443/attestation/sgx/v2/sigrl/00000010";
        URL target = new URL(url);

        /* Force TLSv1.2 */
        SSLContext sc = SSLContext.getInstance("TLSv1.2");
        sc.init(null, null, new java.security.SecureRandom());

        /* Set up HTTP properties. */
        HttpsURLConnection connection = (HttpsURLConnection) target.openConnection();
        connection.setSSLSocketFactory(sc.getSocketFactory());
        connection.setRequestMethod("GET");
        connection.setDoOutput(true);

        /* Obtain and check response status quote. */
        int responseCode = connection.getResponseCode();

        /* Read response body into a String */
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        StringBuffer responseBuffer = new StringBuffer();
        while((inputLine = in.readLine()) != null){
            responseBuffer.append(inputLine);
        }
        in.close();
        String response = responseBuffer.toString();

        /* Evaluate result and print messages. */
        System.out.println("HTTP response status code: " + responseCode + "\n");
        System.out.println(response);
    }

}

控制台输出:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2038)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1135)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
    at Prog.makeRequest(Prog.java:32)
    at Prog.main(Prog.java:13)

本教程生成一个 client.pfx 文件,可用于将证书导入其他平台。我已将此文件复制到运行我的 Java 程序的 Ubuntu 系统并双击它以导入它。一切似乎都很成功,但是在运行程序时我仍然不断收到这些异常。

我还使用(设置)>(锁屏和安全)>(其他安全设置)>(凭据存储/从设备存储安装)中的选项在 Android 上安装了 client.crt 文件。当我尝试从 Android Activity 运行此代码时(仅通过复制粘贴该方法),我得到完全相同的错误。

我需要能够从 Ubuntu 和 Android(7.0,API 24)发出 IAS 请求。我使用本教程生成的证书已经在英特尔注册(我收到了来自英特尔开发人员服务的电子邮件确认和服务提供商 ID)。

原则上,我唯一需要知道的是如何正确使用/安装我在 Ubuntu 和 Android 上生成的证书,以及我是否在程序中正确发出 HTTP 请求。我仍然是一名学生,我需要与新交所合作完成一个项目,所以请以我有限的知识为基础。我将不胜感激。

标签: androidhttpscertificateintelsgx

解决方案


推荐阅读