Exemplo n.º 1
0
        public bool WriteKeyToTEE(string id, string username)
        {
            string userid = id;
            string sUrl   = urlBase + "api/startapp?id=" + userid;


            string query;

            using (WebClient cli = new WebClient())
            {
                cli.Headers[HttpRequestHeader.ContentType] = "application/json";
                query = cli.DownloadString(sUrl);
            }



            int responseCode;

            byte[] symmetricKey = new byte[131];

            byte[] publicKey = Convert.FromBase64String(query);



            jhi.SendAndRecv2(session, 3, publicKey, ref symmetricKey, out responseCode);
            symmetricKey = new byte[131];
            jhi.SendAndRecv2(session, 5, publicKey, ref symmetricKey, out responseCode);

            string strsymmetricKey = Convert.ToBase64String(symmetricKey);


            sUrl = urlBase + "api/Symmetric";
            string res  = null;
            string json = "{id:\"" + userid + "\", symmetric:\"" + strsymmetricKey + "\"}";

            using (WebClient cli = new WebClient())
            {
                cli.Headers[HttpRequestHeader.ContentType] = "application/json";
                res = cli.UploadString(sUrl, "POST", json);
            }



            return(true);
        }
Exemplo n.º 2
0
        public static JhiTestResult SendAndReceive()
        {
            Console.Write("Installing App " + echoAppID + "...  ");
            jhi.Install(echoAppID, echoAppPath);
            jhi.Uninstall(echoAppID);
            jhi.Install(echoAppID, echoAppPath);
            Console.WriteLine("Success.");

            Console.Write("Creating session...  ");
            JhiSession echoSession;

            jhi.CreateSession(echoAppID, JHI_SESSION_FLAGS.None, null, out echoSession);
            Console.WriteLine("Success.");

            Console.Write("Starting send and receive...  ");
            int output;

            Byte[] x = new Byte[] { 3, 12, 3 };
            Byte[] y = new Byte[3];
            jhi.SendAndRecv2(echoSession, 1, x, ref y, out output);
            bool result = ArraysEqual(x, y);

            Console.WriteLine("Output matches! - success.");
            jhi.CloseSession(echoSession);
            jhi.Uninstall(echoAppID);
            return(bool_To_JhiTestResult(result));
        }
Exemplo n.º 3
0
        public bool DALCreatSession()
        {
#if AMULET
            // When compiled for Amulet the Jhi.DisableDllValidation flag is set to true
            // in order to load the JHI.dll without DLL verification.
            // This is done because the JHI.dll is not in the regular JHI installation folder,
            // and therefore will not be found by the JhiSharp.dll.
            // After disabling the .dll validation, the JHI.dll will be loaded using the Windows search path
            // and not by the JhiSharp.dll (see http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.100).aspx for
            // details on the search path that is used by Windows to locate a DLL)
            // In this case the JHI.dll will be loaded from the $(OutDir) folder (bin\Amulet by default),
            // which is the directory where the executable module for the current process is located.
            // The JHI.dll was placed in the bin\Amulet folder during project build.
            Jhi.DisableDllValidation = true;
#endif
            jhi = Jhi.Instance;

            // This is the path to the Intel Intel(R) DAL Trusted Application .dalp file that was created by the Intel(R) DAL Eclipse plug-in.
            string appletPath = "C:/Users/User/eclipse/java-2019-12/eclipse\\EH_Project_Dal\\bin\\EH_Project_Dal.dalp";
            // Install the Trusted Application
            //Console.WriteLine("Installing the applet.");
            //JHI_SESSION_INFO info;
            //appletID = "5d6664a0-5e65-4016-9e8c-17e8fa75f894";
            // This is the path to the Intel Intel(R) DAL Trusted Application .dalp file that was created by the Intel(R) DAL Eclipse plug-in.
            //appletPath = "C:/Users/User/eclipse/java-2019-12/eclipse\\Targil3\\bin\\Targil3.dalp";

            //uint count;
            //jhi.Uninstall(appletID);
            //jhi.GetSessionInfo(session, out info);
            //jhi.GetSessionsCount(appletID, out count);
            try
            {
                jhi.Install(appletID, appletPath);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message.ToString());
            }

            // Start a session with the Trusted Application
            byte[] initBuffer = new byte[] { }; // Data to send to the applet onInit function
            // Console.WriteLine("Opening a session.");
            jhi.CreateSession(appletID, JHI_SESSION_FLAGS.None, initBuffer, out session);

            // Send and Receive data to/from the Trusted Application
            byte[] sendBuff = UTF32Encoding.UTF8.GetBytes("Hello"); // A message to send to the TA
            byte[] recvBuff = new byte[2000];                       // A buffer to hold the output data from the TA
            int    responseCode;                                    // The return value that the TA provides using the IntelApplet.setResponseCode method
            int    cmdId = 1;                                       // The ID of the command to be performed by the TA
            // Console.WriteLine("Performing send and receive operation.");
            jhi.SendAndRecv2(session, cmdId, sendBuff, ref recvBuff, out responseCode);
            //Console.Out.WriteLine("Response buffer is " + UTF32Encoding.UTF8.GetString(recvBuff));

            return(true);
        }
Exemplo n.º 4
0
 public void SendAndRecv2(JhiSession Session, int nCommandId, byte[] InBuf, ref byte[] OutBuf, out int ResponseCode, bool enableWrite = false, params UInt32[] filesNameToSend)
 {
     InBuf = insertFSInfoToBuffer(InBuf, enableWrite, filesNameToSend);
     jhi.SendAndRecv2(Session, nCommandId, InBuf, ref OutBuf, out ResponseCode);
     OutBuf = HandleReturnedData(OutBuf);
 }