<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Enclave code has to be in Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114590#M1396</link>
    <description>&lt;P&gt;Enclave code has to be written in c/c++.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Below link has some example code link &amp;nbsp;to call those c/c++ interfaces from other native interface capabilities.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/605347" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/605347&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;If the link for samples &amp;nbsp;doesn't work, you can directly check here:&amp;nbsp;https://software.intel.com/en-us/sgx/code-samples&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;

&lt;P&gt;Shivananda&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2017 11:51:37 GMT</pubDate>
    <dc:creator>Shivananda_H_Intel</dc:creator>
    <dc:date>2017-05-25T11:51:37Z</dc:date>
    <item>
      <title>SGX error unsealing data in Java but working in C++</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114589#M1395</link>
      <description>&lt;P&gt;I'm using in Ubuntu intel sgx to seal and unseal data.&lt;/P&gt;

&lt;P&gt;I have both implementation in C and Java.&lt;/P&gt;

&lt;P&gt;The example is simple:&lt;/P&gt;

&lt;UL&gt;
	&lt;LI&gt;Seal the data&lt;/LI&gt;
	&lt;LI&gt;Restart the program&lt;/LI&gt;
	&lt;LI&gt;Unseal the data&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This works fine in&lt;STRONG&gt; C++&lt;/STRONG&gt; but when I'm using J&lt;STRONG&gt;ava&lt;/STRONG&gt; the program gives segmentation fault.&lt;/P&gt;

&lt;P&gt;I guess that is related with the Makefile options that I need to setup the library to use in Java, that are the following:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;App_SO_Name := libSGXEnclave.so

$(App_SO_Name): App/Enclave_u.o $(App_Cpp_Objects)
	@echo "LINK =&amp;gt;  $@"
	@$(CXX) $^ $(App_Link_Flags) -shared -o $@&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;The remaining part of the Makefile and other things related with the code can be found in&amp;nbsp;https://github.com/digawp/hello-enclave/&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;I'm available to give further information regarding this issue.&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 17:00:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114589#M1395</guid>
      <dc:creator>João_R_</dc:creator>
      <dc:date>2017-05-24T17:00:19Z</dc:date>
    </item>
    <item>
      <title>Enclave code has to be</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114590#M1396</link>
      <description>&lt;P&gt;Enclave code has to be written in c/c++.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Below link has some example code link &amp;nbsp;to call those c/c++ interfaces from other native interface capabilities.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/605347" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/605347&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;If the link for samples &amp;nbsp;doesn't work, you can directly check here:&amp;nbsp;https://software.intel.com/en-us/sgx/code-samples&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;

&lt;P&gt;Shivananda&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 11:51:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114590#M1396</guid>
      <dc:creator>Shivananda_H_Intel</dc:creator>
      <dc:date>2017-05-25T11:51:37Z</dc:date>
    </item>
    <item>
      <title>The following example</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114591#M1397</link>
      <description>&lt;P style="box-sizing: border-box; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px;"&gt;&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;The following example describes the process of unsealing in both examples. Yes I'm using Jni. I comment the place where the program crashes.&lt;/SPAN&gt;&lt;BR style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;" /&gt;
	&lt;BR style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;" /&gt;
	&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;Java / JNI example&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;JNIEXPORT jstring JNICALL Java_Joao_unseal(
  JNIEnv *env, jobject obj, jstring javaString) {
if (initialize_enclave(&amp;amp;global_eid, "enclave.token", "enclave.signed.so") &amp;lt; 0) {
std::cout &amp;lt;&amp;lt; "Fail to initialize enclave." &amp;lt;&amp;lt; std::endl;
       return NULL;
}
 sgx_status_t status;
    sgx_status_t ecall_status;

  const char * teste;

size_t sealed_size = sizeof(sgx_sealed_data_t) + sizeof(teste);
    uint8_t* sealed_data = (uint8_t*) malloc(sealed_size);

FILE *fp;
  fp = fopen("simple.zod", "a+");
  int numRead = fread(sealed_data,sealed_size, 1, fp );
  if (numRead == 0) {
        return NULL;
        }
fclose(fp);
   
    status = unseal(global_eid, &amp;amp;ecall_status,
            (sgx_sealed_data_t*)sealed_data, sealed_size,
            (uint8_t*)&amp;amp;teste,  sizeof(teste));

    if (!is_ecall_successful(status, "Unsealing failed :(", ecall_status)) {
        return NULL;
    }

    std::cout &amp;lt;&amp;lt; "&lt;SPAN style="font-weight: 700; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px;"&gt;&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;UnSeal&lt;/SPAN&gt;&lt;/SPAN&gt; round trip success! Receive back final -&amp;gt; " &amp;lt;&amp;lt; teste &amp;lt;&amp;lt; "end"&amp;lt;&amp;lt; std::endl;  // the error is at this point
    return (env)-&amp;gt;NewStringUTF("teste");
}

&lt;/PRE&gt;

&lt;P style="box-sizing: border-box; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px;"&gt;&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;The error is in the print function:&lt;/SPAN&gt;&lt;BR style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;" /&gt;
	&lt;STRONG&gt;&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;std::cout &amp;lt;&amp;lt; "UnSeal round trip success! Receive back final -&amp;gt; " &amp;lt;&amp;lt; teste &amp;lt;&amp;lt; "end"&amp;lt;&amp;lt; std::endl&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;BR style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;" /&gt;
	&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;C++ code that I use is this:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;int  unseal(){
if (initialize_enclave(&amp;amp;global_eid, "enclave.token", "enclave.signed.so") &amp;lt; 0) {
std::cout &amp;lt;&amp;lt; "Fail to initialize enclave." &amp;lt;&amp;lt; std::endl;
       return NULL;
}
 sgx_status_t status;
    sgx_status_t ecall_status;

  const char * teste;

size_t sealed_size = sizeof(sgx_sealed_data_t) + sizeof(teste);
    uint8_t* sealed_data = (uint8_t*) malloc(sealed_size);

FILE *fp;
  fp = fopen("simple.zod", "a+");
  int numRead = fread(sealed_data,sealed_size, 1, fp );
  if (numRead == 0) {
        return NULL;
        }
fclose(fp);

    status = unseal(global_eid, &amp;amp;ecall_status,
            (sgx_sealed_data_t*)sealed_data, sealed_size,
            (uint8_t*)&amp;amp;teste,  sizeof(teste));


    if (!is_ecall_successful(status, "Unsealing failed :(", ecall_status)) {
        return NULL;
    }
 
    std::cout &amp;lt;&amp;lt; "Seal round trip success! Receive back final -&amp;gt; " &amp;lt;&amp;lt; teste &amp;lt;&amp;lt; "end"&amp;lt;&amp;lt; std::endl;


return 1;
}
&lt;/PRE&gt;

&lt;P style="box-sizing: border-box; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px;"&gt;&lt;BR style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;" /&gt;
	&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;Note that I can unseal if I do not stop the program. The problem is when I start the program again.&lt;/SPAN&gt;&lt;BR style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;" /&gt;
	&lt;SPAN style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;"&gt;I can give information regarding the seal process or make the project fully available.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 13:30:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/SGX-error-unsealing-data-in-Java-but-working-in-C/m-p/1114591#M1397</guid>
      <dc:creator>João_R_</dc:creator>
      <dc:date>2017-05-25T13:30:00Z</dc:date>
    </item>
  </channel>
</rss>

