This shows you the differences between two versions of the page.

Link to this comparison view

ep:labs:08 [2018/03/07 11:01]
emilian.radoi [App.cpp]
ep:labs:08 [2020/12/02 18:12] (current)
radu.mantu [Lab 08 - I/O Monitoring (Windows)]
Line 1: Line 1:
-====== Lab 08 ======+====== Lab 08 - I/O Monitoring (Windows) ​======
-===== App.cpp =====+<note important>​
-<​code>​ +You can download the **Windows 10 VM** via {{:​ep:​labs:​ep_win10_vm.7z.torrent.txt}}
-#include <stdio.h> +DokuWiki is not configured to accept //.torrent// files so remove the //.txt// extension. 
-#include <sys/types.h> /* open */ +After thatyou know what to do...
-#include <sys/stat.h> /* open *+
-#include <​fcntl.h>​ /​* O_CREATO_RDONLY */ +
-#include <unistd.h> /* close, lseek, read, write */+
-#include "​Enclave_u.h" +Alternatively,​ you can install the following on your own Windows machine: 
-#include "​sgx_urts.h" +  * **[[https://​go.microsoft.com/​fwlink/?​linkid=2120254 | ADK]]** - make sure to check //**Windows Performance Analyser**//​ and //**Windows Performance Recorder**//​
-#include "​sgx_utils/sgx_utils.h"+  * **[[https://​visualstudio.microsoft.com/​downloads/​ | Visual Studio Community Edition]]** - select //C++ development//​.  
 +  * **[[https://docs.microsoft.com/​en-us/​sysinternals/​downloads/​sysinternals-suite | Sysinternals suite]]**
-/* Global Enclave ID */ +</note>
-sgx_enclave_id_t global_eid;+
-/* OCall implementations */ 
-void ocall_print(const char* str) { 
-    printf("​%s\n",​ str); 
-void ocall_write_file(const char* filename, const char* buf, size_t buf_len) { +===== Objectives =====
- int fd; +
- ssize_t wr_bytes; +
- fd  ​open(filename,​ O_RDWR | O_CREAT, 0644); +
- wr_bytes ​write(fd, buf, buf_len); +
- close(fd);​ +
-void ocall_read_file(const charfilename, charbuf, size_t buf_len) { +  * How to determine the root sources of having intensive disk usage/​RAM/​CPU and intensive networking using **Task Manager** (ProcessesPerformanceApp historyStart-upUsers, Details, Services). 
- int fd; +  * Analyzing performance issues due to intensive disk use using **Windows Performance Recorder**, **Process Monitor** and **Process Explorer**. 
- ssize_t no_bytes; +  * Monitor the disk activity, identify who is generating it and how to figure out the issue by looking at the pdbs and the code.
- fd  = open(filenameO_RDWR | O_CREAT0644); +
- no_bytes = read(fdbufbuf_len); +
- buf[no_bytes] = '​\0';​ +
- close(fd);​ +
-int main(int argc, char const *argv[]) { 
-    int sum_result; 
-    unsigned int rand_no; 
-    sgx_status_t status; 
-  ​ 
-    /* Enclave Initialization */  
-    if (initialize_enclave(&​global_eid,​ "​enclave.token",​ "​enclave.signed.so"​) < 0) { 
-        printf("​Fail to initialize enclave.\n"​);​ 
-        return 1; 
-    } 
-    ​/* Call simple method inside enclave ​*/  +===== Introduction ===== 
-    status ​= get_sum(global_eid&​sum_result34); + 
-    if (status != SGX_SUCCESS{ +Since computers started to surface, for many people it was a mystery what was happening behind the screen and it seemed magical when it wasn't working and even more magical when it was working. Since Linux is open-source,​ all sorts of tools appeared over time to analyse problems when they came up. On Windows on the other hand, the system being closed made it harder for tools to appear. 
-        ​printf("ECall failed.\n"​); + 
-        ​return 1; +The first tools were provided by Sysinternals. These were written by Mike Rusinovich, who chose to make public tools such as “File monitor” and “Registry monitor”, which were later combined into “Process monitor”. The tools were so good that even Microsoft'​s support teams were using them. Seeing their usefulness and appreciating the know-how of their operating system, Microsoft decided to buy Sysinternals,​ so now the original website redirects to https://​technet.microsoft.com/​en-us/​sysinternals (outside Romania it probably redirects to different link due to localization reasons that consider the language of the country where redirection is made). 
-    } + 
-    ​printf("Sum from enclave%d\n"sum_result);+On this website can be found some of the tools that will be used in this tutorial - Process Monitor, Process Explorer, VMMap, Autoruns. Starting with Windows 7, Microsoft has begun to invest more and more in the performance of the system and in ways to monitor the system'​s performance. Some tools already existed since Windows 2000, but they were only used internally. 
 +===== Tutorials & Tasks ===== 
 +===== Task Manager ===== 
 +Shows the process name responsible for constant disk thrashing either by reads or writes.  
 +To start Task manager use the shortcut: //**Ctrl + Shift + Esc**//. 
 +**Tabs description:​** 
 +  * **Processes tab** shows all the running processes and their current resource usage in terms of CPU, Memory, Disk and Network. 
 +  * **Performance tab** shows the usage level of the computer'​s main resources in the last 60 seconds. 
 +  * The **App history tab** was first added to Windows 8, and it shows the resource consumption of metro applications. Metro applications are touch-screen-friendly applications written especially for Microsoft'​s WinRT programming interfaces. 
 +  * The **Start-up tab** shows all the applications that start at start-up, (or at least in Microsoft'​s vision - this will be further detailed in the Autoruns section), and their impact on the boot time. It is helpful to check this tab in case your computer takes a long to to start up. 
 +  * **Users tab** shows the resource consumption of every logged in user.  
 +  * **Details tab** shows details for each process - pid, status, the user under which it runs. Right-clicking the column headers bar, offers the possibility to add or remove columns. The following columns: Handles, Threads, Image Path Name and Command Line are very useful: the first one (Handles) when investigating a handle leakthe second one (Threads) in the case of investigating processes that create too many threadsthe third one (Image Path Name) to find out the path from where the process was startedand the last one (Command Lineto find out the parameters with which it was started.  
 +  * **Services tab** shows the service status. A Windows service can be considered similar to a Linux daemon: a process without a visual interface, offering services to user-created processes. 
 +  * Task Manager can be used to identify which process uses a lot of RAM, CPU, accesses the disk many times or generates a lot of traffic on the network at a certain moment (Services tab). However, it does not offer information ​if in the long run, that same process is the one that generated the slowdown of the system. It does offer some information for longer periods of time, in the Start-up tab, which shows what process had higher impact at start-up, but does not specify the area that was impacted ​(disk space, RAM, CPU). 
 +  * You can sort by I/O read or I/O Writes, but no option to sort the results by Total I/O (combined Read & Write). 
 +To overcome Task manager’s limitation, and to perform a thorough analysis, use the excellent Resource Monitor ​(Resmon) utility, which is built-in to Windows. 
 +Here [[https://​drive.google.com/​file/​d/​1z1J6lgoYfBOZF7acEzR8gEq1MH1OZgaf/​view]] you have a visual representation of the previous mentioned steps. 
 +== 01. [20p] Task Manager == 
 +  - Watch the video and go through the tutorial 
 +  - Which program is constantly reading or writing to your hard disk? 
 +:!: :!: NON-DEMO TASK  
 +**How to:** 
 +  * Open Task Managerand select the Details tab. 
 +  * Right-click on the column header (Name, PID, Status etcand click Select Columns. 
 +  * Enable the following checkboxes and click OK. 
 +<note tip> 
 +I/O read bytes is the number of bytes read in input/​output operations generated by a process, including file, network, and device I/Os. 
 +Whereas I/O write bytes is the number of bytes written in input/​output operations by a process, including file, network, and device I/Os. 
 +I/O Read Bytes & I/O Write Bytes directed to CONSOLE (console input object) handles are not counted. 
 +  * Next, sort the listings by I/O Read bytes and see which application is generating the maximum I/O (in bytes/sec). Similarly, sort by I/O Write bytes to see which program is writing to the hard disk continuously. 
 +  * Once you identify the program, decide if you need the program or not. Leave it as it is if the I/O operations are justified. Else, remove the program or consult its documentation to tweak the settings if any. For instance, one of your browser extensions may cause high disk or CPU usage. You need to isolate the extension, add-on or the browser’s feature causing the trouble. 
 +===== Windows Performance Recorder ===== 
 +<note warning>​ 
 +Datafile: Logs.exe and GoodLog.exe 
 +Installing Windows ADK will install Windows Performance Recorder. Check by clicking the windows button and typing “windows performance recorder”. 
 +Start **Windows Performance Recorder** by pressing Enter. You will see the following:​ 
 +{{:​ep:​laboratoare:​ep4_wpr-record.jpg?​400|}} ​  
 +</​spoiler> ​  
     ​     ​
-    seal_secret(global_eid);​ +Click the **More options** button to get the list shown in the screenshot right below.
-    unseal_secret(global_eid);​+
-    /* TODOUsing an ECALL that generates a random unsigned int, +<​spoiler>​ 
-    get a random number between 3 and 42. */ +{{:ep:​laboratoare:​ep4_wpr-select.jpg?​400|}}  ​ 
-    status = generate_random_number(global_eid,​ &​rand_no);​ +</spoiler> ​   
-    printf("​Rand no from enclave: %u\n", rand_no); +
-    return 0; +
-</code>+Make sure that you select the same check boxes as in the screenshot, but do not click start just yet. Create a new directory and copy the **Logs.exe** and **GoodLog.exe** files into this directory. The behaviour of these two executables is similar to logging applications that write logs to the disk. Open a terminal and change the path to the directory where you copied the files.  
 +{{:​ep:​laboratoare:​ep4_badlogs.jpg?​400|}} ​  
 +Start **Windows Performance Recorder** and right after run GoodLog.exe and then Logs.exe. Once the two applications finish running, click the Save button in Windows Performance Recorder.
 + ​{{:​ep:​laboratoare:​ep4_goodlogs.jpg?​400|}} ​
 +</​spoiler> ​     ​
-===== Enclave.cpp ===== 
-<​code>​+After the capture is saved, the Open option will become available in **Windows Performance Analyzer**. When clicking the Open button it should open a window such as the one below. ​
-#include "​sgx_trts.h"​ +<​spoiler>​ 
-#include "​sgx_tseal.h" ​ +{{:​ep:​laboratoare:​ep4_wpa-cpu1.jpg?​400|}}  ​ 
-#include "​string.h"​ +</​spoiler>​ 
-#include "​Enclave_t.h"​ +     ​ 
-#​include<​stdio.h>+Double clicking on Storage should display the following window. Analyse the resources.
 +{{:​ep:​laboratoare:​ep4_wpa-cpu2.jpg?​400|}}  ​
 +</​spoiler> ​      
-#define SECRET_FILE "​enclave_secret"​+In the upper-left corner of the newly opened window it can select Disk Usage, Utilization by Disk. Click on Utilization by Disk and select: Utilization by Process, Path Name, and Stack. This will generate the following output. ​
-int get_sum(int a, int b) { +<​spoiler>​ 
- /* TODOCall OCALL that prints a debug message */ + {{:ep:​laboratoare:​ep4_wpa-cpu3.jpg?​400|}}   
- return a + b; +</​spoiler> ​    
-void printf(const char *fmt, ...+The graph looks interesting in Task ManagerProcesses can be selected for observing their activity on the diskIt can be noticed that our processes are not shown. Run Logs.exe again while keeping Task Manager on
-    char buf[BUFSIZ] = {'​\0'​};​ +
-    va_list ap; +
-    va_start(ap,​ fmt); +
-    vsnprintf(buf,​ BUFSIZ, fmt, ap); +
-    va_end(ap);​ +
-    ocall_print(buf);​ +
-unsigned int generate_random_number() ​+<​spoiler>​ 
-     +{{:​ep:​laboratoare:​ep4_logstaskmanagerdisk.jpg?​400|}}  ​ 
-    ​unsigned int rand_number ​0; +</​spoiler> ​    
-   ​ + 
-    ​sgx_status_t status ​sgx_read_rand((unsigned char*)(&​rand_number), sizeof(rand_number)); + 
-    ​if ​(SGX_SUCCESS != status) { +**Conclusions:​** 
- return ​-42; + 
-    +  * This shows that there is activity on the disk. The question is why doesn'​t Windows Performance Analyzer show it. The way Windows Performance Recorder records activity is based on events generated by the Windows kernel. It registers to track the events, listens to them, and during the recording period it constantly samples which process uses which resource at the time of sampling. 
-    ​return rand_number%42 ​1; +  * It sums up the number of time that a process was caught doing something. In our case, the two processes want to write to the disk, but they are not the ones that get to do the actual writing. They tell the system that they want to write, and the System process schedules the writing. The reason for this is targeting a more efficient disk writing, as the System process is trying to minimise the impact to the disk. This is why our process'​s writing is passed over to the System process. 
 +Here [[https://​drive.google.com/​file/​d/​1DTEnxhv9Tb5TORz1RFT7-v2ojLPW5l7A/​view]] you have a visual representation as well. 
 +== 02. [20p] WPR and WPA  =
 +  - Watch the video and go through the tutorial 
 +===== Process Monitor ===== 
 +//Process Monitor is an excellent troubleshooting tool from Windows Sysinternals that displays the files and registry keys that applications access in real-time. The results can be saved to a log file, which you can send it to an expert for analyzing a problem and troubleshooting it.// 
 +**How to Use Process Monitor to Track Registry and File System Changes?​** 
 +^ Step 1: Running Process Monitor & Configuring Filters ^^ 
 +| **1.** Download Process Monitor from Windows Sysinternals site. || 
 +| **2.** Extract the zip file contents to a folder of your choice. || 
 +| **3.** Run the Process Monitor application. || 
 +| **4.** Include the processes that you want to track the activity on. For this example, you want to include Notepad.exe in the (Include) Filters. || 
 +| **5.** Click Add, and click OK. || 
 +| **6.** From the Options menu, click Select Columns. || 
 +| **7.** Under “Event Details”, enable Sequence Number, and click OK. || 
 +You can add multiple entries as well, in case if you want to track few more processes along with Notepad.exe. To keep this example simpler, let’s only track Notepad.exe. ​(You’ll now see the Process Monitor main window tracking the list of registry and file accesses by processes real-time, as and whey they occur.) 
 +^ Step 2: Capturing Events ^^ 
 +**8.** Open Notepad. || 
 +| **9.** Switch to Process Monitor window. || 
 +| **10.** Enable the “Capture” mode (if it’s not already ON). You can see the status of the “Capture” mode via the Process Monitor toolbar. || 
 +| **11.** The highlighted button above is the “Capture” button, which is current disabled. You need to click that button ​(or use Ctrl + E key sequence) to enable capturing of events. || 
 +| **12.** Cleanup the existing events list using Ctrl + X key sequence (Important) and start afresh. || 
 +| **13.** Now switch to Notepad and try to reproduce the problem. || 
 +| **14.** To reproduce the problem (for this example), try writing to HOSTS file (C:​\Windows\System32\Drivers\Etc\HOSTSand saving it. Windows offers to save the file (by showing the Save As dialogwith a different name, or in a different location. So, what happens under the hood when you save to HOSTS file? Process Monitor shows that exactly. || 
 +| **15.** Switch to Process Monitor window, and turn off Capturing ​(Ctrl + Eas soon as you reproduce the problem. Important Note: Don’t take much time to reproduce the problem after enabling capturing. Similarly turn off capturing as soon as you finish reproducing the problem. This is to prevent Process Monitor from recording other unneeded data (which makes analysis part more difficult). You need to do all that as quickly as you can. || 
 +<note warning>​ 
 +The log file above tells us that Notepad encountered an ACCESS DENIED error when writing to the HOSTS file. The solution would be to simply run Notepad elevated (right-click and choose “Run as Administrator”) to be able to write to HOSTS file successfully. 
 +^ Step 3: Saving the Output ^^ 
 +| **16.** In the Process Monitor window, select the File menu and click Save. || 
 +| **17.** Select Native Process Monitor Format (PML), mention the output file name and Path, save the file. || 
 +| **18.** Right-click on the Logfile.PML file, click Send To, and choose Compressed (zipped) folder. This compresses the file by ~90%. Look at the graphic below. You certainly want to zip the log file before sending it to someone. || 
 +You can take also take a look at this video here: https://​drive.google.com/​file/​d/​1ZYdtOq7QsY0nfYDS3e4foPFRVPgO4Qdb/​view. 
 +== 03. [30p] Process Monitor == 
 +<note warning>​ 
 +Download the archive ​{{:​ep:​laboratoare:​logs-final.7z|}} and check if you have “Process Monitor” installed (Windows 10). 
 +//logs-final.7z//: **parola** 
 +//​HandleLeak.7z//:​ **parola7** 
 +//​Task.7z//:​ **parola17** 
 +== [10p] Task A - Checking logging file == 
 +  * Looking at the logs created by the two apps in Process Monitor - bad.log, good.log - they are identical, but Logs.exe has a significantly longer running time compared to GoodLog.exe. Start Process Monitor.  
 +  * If the 4 buttons in the black area on the upper part of the window are selected, Process Monitor will display the activity (in this order) for: registry, files, networking, process and thread activity. By unchecking them, the corresponding events will be no longer displayed. In the menu bar there is the Filter field. If selected, it will trigger a dropdown menu that contains another Filterfield. If this second Filter field is selected, it will open the window shown below. Replicate this on your computer.  
 +  * From the two dropdown menus in the upper part of the context window, select ”Process Name” instead of ”Architecture” and ”is” instead of ”contains”. In the text filed add Logs.exe, click the Add button and then the OKbutton. Open the terminal and run Logs.exe. After the program is done running, save the Process Monitor capture. Use Ctrl X to reset all the events captured in Process Monitor. Go to Filter → Filter area, double-click on the filter that was just added and change Logs.exe with GoodLog.exe,​ then click Add and Ok. Start GoodLog.exe and save the capture once the program finishes running. Scroll down in the two capture-logs until you notice the activity for bad.log respectively good.log. 
-void unseal_secret(){ +<note important>​ 
- char sealed_data[1024];​ +  Notice the difference. On the left-hand side it is shown the faster logging processand on the right-hand side the slower one. Look in the red highlighted area to see the difference. On the left-hand side the logging file is openedfollowed by continuous writingwhile on the right-hand side the file is opened and closed for every writing operation which explains the significant slowdown. ​ 
- char secret[1024];​ +</​note>​
- uint32_t text_size = sizeof(secret);​ +
-  +
- ocall_read_file(SECRET_FILE,​ sealed_data,​ text_size);​ +
- sgx_unseal_data((sgx_sealed_data_t ​*)sealed_dataNULLNULL, (uint8_t*)secret,​ &​text_size);​ +
- printf("​Unsealed secret: %s\n"secret); +
 +  * To recap, Task Manager shows what processes use the disk intensively at the current time, Windows Performance Recorder / Windows Performance Analyzer show who used the disc during a longer time period, although they were showing the activity as belonging to the System process instead of our process. Using Process Monitor we could identify our processes'​ entire activity and we could determine why one is slower than the other. But what if we could find out which line in the code causes the problem? Go back to Process Monitor. Use the window of the badly written logging program (Logs.exe). Go to Options → Configure Symbols, which will open the window shown below. ​
-void seal_secret() ​{ +<​spoiler>​ 
- char* secret = (char*)malloc(10);​ +{{:ep:​laboratoare:​ep4_procmon-symbols.jpg?​400|}} 
-    sgx_status_t status = sgx_read_rand((unsigned char*)secret,​ sizeof(secret));​ +</​spoiler>​
- printf("​Generated secret%s\n", secret); +
-  +
- uint32_t text_size = sizeof(secret);​ +
- uint32_t sealed_size = sgx_calc_sealed_data_size(0,​text_size);​ +
-  +
- sgx_sealed_data_t *sealed_data = (sgx_sealed_data_t *)malloc(sealed_size);​ +
- sgx_seal_data(0,​ NULL, text_size, (uint8_t*)secret,​ sealed_size,​ sealed_data);​ +
-  +
- ocall_write_file(SECRET_FILE,​ (char *)sealed_data,​ sealed_size);​ +
-</code>+  * In the log (D:​\Logs\bad.log) go to CreateFile. Double-click to open the Event Properties window. Choose the Stacktab, scroll down and you can notice that in the main function of main_bad_log.cpp,​ at line 12 the opening takes place. Click the ”Source” button to view the source ​code containing the issue. ​
 +{{:​ep:​laboratoare:​ep4_prcomoncode.jpg?​400|}} ​
-===== Enclave.edl ===== 
-<​code>​+== [20p] Task B - Investigating a handle leak ==
-enclave { +:!: :!: NON-DEMO TASK 
-    //from "​Sealing/​Sealing.edl"​ import *;+
-    trusted ​{ +In {{:​ep:​laboratoare:​logs-final.7z|}} you have another example of two executables:​ **good.exe** and **bad.exe**. Both have the same outcomethe only difference being their running time (one of them is significantly slower). **Identify the problem**.
-        /define ECALLs here. *+
- public int get_sum(int aint b); +
-        public unsigned int generate_random_number(void)+
-    public void seal_secret(void);​ +
-    public void unseal_secret(void);​ +
-    };+
-    untrusted { +**How to:**
-        /define OCALLs here. *+
-        void ocall_print([in,​ string]const charstr); +
-    void ocall_write_file([in,​ string]const charfilename, [in, size=buf_len]const char* buf, size_t buf_len); +
- void ocall_read_file([in,​ string]const char* filename, [out, size=buf_len]char* buf, size_t buf_len); +
-    }; +
-}; +
-===== sgx_utils.cpp =====+  * A handle leak consists of a process that opens files and does not close them. On modern computers if this action is performed millions of times, the system may become unresponsive and will either experience an overall slowdown or the application that causes this will eventually crash. You may think that millions of handles are impossible to reach, so it is not worth paying attention to this problem. However, imagine that there are services running on servers for years. As an example, having a handle leak every 2 seconds amounts for over 10 million handle leaks in a year. How should such problems be investigated?​ 
 +  * **Hint:** Open up a terminal and run HandleLeak.exe. Check out the ”Details” tab in Task Manager after adding the ”Handles” column.
-<​code>​ +== 04[30p] Process Explorer ==
-#include <​cstdio>​ +
-#include <​cstring>​ +
-#include "​sgx_urts.h" +
-#include "​sgx_utils.h"​+
-#ifndef TRUE +:!: :!: NON-DEMO TASK 
-# define TRUE 1 +
-#ifndef FALSE +  * It can be noticed that the number of handles keeps growing. This is clearly a problem, but how do we investigate it?
-# define FALSE 0 +
-/Check error conditions for loading enclave ​*+**How to:**
-void print_error_message(sgx_status_t ret) { +
-    printf("​SGX error code%d\n", ret); +
-/* Initialize the enclave: +  ​* Run it as administrator. It is similar ​to Task Manager. Select ​the process that you are interested in, namely HandleLeak, and press “Ctrl + H”. 
- ​* ​  ​Step 1: try to retrieve ​the launch token saved by last transaction +  “Ctrl + H” opens a window under the ”Process” section that displays all open handles along with information about them. Thus it will display file handles, registry handles, threads handles, and so on. There is another view (Ctrl + D) that displays all the loaded dlls. 
- ​* ​  Step 2: call sgx_create_enclave to initialize an enclave instance +  ​So it can be noticed that the leaks are on the following fileD:\Logs\HandleLeak\leak.txt. This is very useful informationbut it would be better to find out who is responsible for the leak in code. Run Process Monitor with a filter on HandleLeak.exe and to notice the stack where the leakage is happens.
- ​* ​  Step 3: save the launch token if it is updated +
- */ +
-int initialize_enclave(sgx_enclave_id_teid, const std::string& launch_token_pathconst std::​string&​ enclave_name) { +
-    const char* token_path = launch_token_path.c_str(); +
-    sgx_launch_token_t token = {0}; +
-    sgx_status_t ret = SGX_ERROR_UNEXPECTED;​ +
-    int updated = 0;+
-    /* Step 1: try to retrieve the launch token saved by last transaction 
-     ​* ​        if there is no token, then create a new one. 
-     */ 
-    /* try to get the token saved in $HOME */ 
-    FILE* fp = fopen(token_path,​ "​rb"​);​ 
-    if (fp == NULL && (fp = fopen(token_path,​ "​wb"​)) == NULL) { 
-        printf("​Warning:​ Failed to create/open the launch token file \"​%s\"​.\n",​ token_path);​ 
-    } 
-    if (fp !NULL) { +== 05[10p] Feedback ​==
-        /* read the token from saved file */ +
-        size_t read_num ​fread(token,​ 1, sizeof(sgx_launch_token_t),​ fp); +
-        if (read_num != 0 && read_num != sizeof(sgx_launch_token_t)) { +
-            /* if token is invalid, clear the buffer */ +
-            memset(&​token,​ 0x0, sizeof(sgx_launch_token_t));​ +
-            printf("​Warning:​ Invalid launch token read from \"​%s\"​.\n",​ token_path);​ +
-        } +
-    } +
-    /* Step 2: call sgx_create_enclave to initialize an enclave instance */ +
-    /* Debug Support: set 2nd parameter to 1 */ +
-    ret = sgx_create_enclave(enclave_name.c_str(), SGX_DEBUG_FLAG,​ &token, &​updated,​ eid, NULL); +
-    if (ret !SGX_SUCCESS) { +
-        print_error_message(ret);​ +
-        if (fp !NULL) fclose(fp);​ +
-        return -1; +
-    }+
-    /* Step 3save the launch token if it is updated */ +:!: :!: NON-DEMO TASK 
-    if (updated == FALSE || fp == NULL) { +
-        /* if the token is not updated, or file handler is invalid, do not perform saving */ +
-        if (fp != NULL) fclose(fp);​ +
-        return 0; +
-    }+
-    /reopen ​the file with write capablity ​*+  ​Please take a minute to fill in the **[[https://​docs.google.com/​forms/​d/​e/​1FAIpQLSfsMBl2EFu10jJG2qHEiSsR-qYr3wkzQPfDwjhChKnjRtDT_w/​viewform | feedback form]]** for this lab.
-    fp = freopen(token_path,​ "​wb",​ fp); +
-    if (fp == NULL) return 0; +
-    size_t write_num = fwrite(token,​ 1, sizeof(sgx_launch_token_t),​ fp); +
-    if (write_num != sizeof(sgx_launch_token_t)) +
-        printf("​WarningFailed to save launch token to \"​%s\"​.\n", token_path);​ +
-    fclose(fp);​ +
-    return 0; +
-bool is_ecall_successful(sgx_status_t sgx_status, const std::​string&​ err_msg, +{{ :​ep:​laboratoare:​ep4_logo_bitd2.png?300 |}}
-        sgx_status_t ecall_return_value) ​{ +
-    if (sgx_status != SGX_SUCCESS || ecall_return_value != SGX_SUCCESS) ​{ +
-        printf("​%s\n",​ err_msg.c_str()); +
-        print_error_message(sgx_status);​ +
-        print_error_message(ecall_return_value);​ +
-        return false; +
-    ​} +
-    return true; +
-} +
ep/labs/08.1520413292.txt.gz · Last modified: 2018/03/07 11:01 by emilian.radoi
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0