public bool sendAutKey(byte[] AutId) { byte[] encryptedId = new byte[16]; int status = SecureImageHostWrapper.sendAuthenticationId(AutId, AutId.Length, encryptedId); if (status != STATUS_SUCCEEDED) { return false; } Console.WriteLine(Encoding.UTF8.GetString(encryptedId)); socket.Send(encryptedId); socket.Receive(statusBytes, 0, INT_SIZE, 0); status = BitConverter.ToInt32(statusBytes, 0); if (status == STATUS_FAILED) { //lblGetS2MsgRet.Text = "Server failed to verify S1 message."; Console.WriteLine("Server failed to decrypt autId"); return false; } else { Console.WriteLine("Server decrypt autId"); return true; } }
private void refresh() { while (true) { //refresh the image SecureImageHostWrapper.refresh(); Thread.Sleep(100); } }
private void formClosed(object sender, FormClosedEventArgs e) { Hide(); //stop refreshiong if (refreshThread != null) { refreshThread.Abort(); } StringBuilder builder = new StringBuilder(bufferSize); //de-init library SecureImageHostWrapper.close(builder); //exit application Application.Exit(); }
private void btnShow_Click(object sender, EventArgs e) { //disable the button flickering flickerTimer.Enabled = false; flickerCounter = 0; btnShow.BackColor = SystemColors.Control; //if there is a PAVP session running - close it if (sessionExists) { //stop refreshing if (refreshThread != null) { refreshThread.Abort(); } //close session SecureImageHostWrapper.closePavpSession(); sessionExists = false; } //request library to show the image StringBuilder builder = new StringBuilder(bufferSize); if (SecureImageHostWrapper.showImage(serverData, panel.Handle, builder)) { //get number of times presented image can be shown again sessionExists = true; //lblNumViews.Text = SecureImageHostWrapper.getRemainingTimes().ToString(); //start a refresh thred to refresh the view periodically refreshThread = new Thread(new ThreadStart(refresh)); refreshThread.Start(); //UI code btnShow.Enabled = false; //rbLoad.Enabled = true; rbNew.Enabled = true; //if (rbLoad.Checked) // rbLoad_CheckedChanged(null, null); //else // rbNew_CheckedChanged(null, null); } else { MessageBox.Show("Failed to show image. " + builder.ToString()); } }
private bool processS1() { IntPtr s1Msg = Marshal.AllocHGlobal(S1_MESSAGE_LEN); Console.WriteLine("before s1"); int status = SecureImageHostWrapper.GetS1Message(s1Msg); Console.WriteLine(s1Msg); Console.WriteLine("after s1"); Console.WriteLine(status); if (status != STATUS_SUCCEEDED) { return(false); } else { Marshal.Copy(s1Msg, S1MsgToSend, 0, S1MsgToSend.Length); Marshal.FreeHGlobal(s1Msg); return(true); } }
private void install_Click(object sender, EventArgs e) { SecureImageHostWrapper.installApplet(); }
private bool processS3(StringBuilder bulider) { //lblGetS3MsgRet.Text = String.Empty; int status; IntPtr s3MsgLen = Marshal.AllocHGlobal(INT_SIZE); //Get S3 message length from the trusted application status = SecureImageHostWrapper.GetS3MessageLen(s2Message, s2MsgLen, s3MsgLen); Console.WriteLine("S3 Len: " + s3MsgLen); Console.WriteLine("status: " + status); switch (status) { case FAILED_TO_GET_S3_LEN: //lblGetS3MsgRet.Text = "Error: Failed to get S3 message length."; Console.WriteLine("Error: Failed to get S3 message length."); break; case STATUS_SUCCEEDED: { byte[] S3MsgLenByteArray = new byte[INT_SIZE]; Marshal.Copy(s3MsgLen, S3MsgLenByteArray, 0, S3MsgLenByteArray.Length); byte temp; //convert S3 message length from most significant byte first presentation to most significant byte last presentation for (int i = 0; i < S3MsgLenByteArray.Length / 2; i++) { temp = S3MsgLenByteArray[i]; S3MsgLenByteArray[i] = S3MsgLenByteArray[S3MsgLenByteArray.Length - i - 1]; S3MsgLenByteArray[S3MsgLenByteArray.Length - i - 1] = temp; } int s3MessageLenInt = BitConverter.ToInt32(S3MsgLenByteArray, 0); IntPtr s3Msg = Marshal.AllocHGlobal(s3MessageLenInt); //Get S3 message from the trusted application status = SecureImageHostWrapper.GetS3Message(s2Message, s2MsgLen, s3MessageLenInt, s3Msg); Console.WriteLine("status after getS3: " + status); switch (status) { case INCORRECT_S2_BUFFER: //lblGetS3MsgRet.Text = "Trusted application received an incorrect S2 message."; Console.WriteLine("Trusted application received an incorrect S2 message."); break; case FAILED_TO_PROCESS_S2: //lblGetS3MsgRet.Text = "Failed to process S2."; Console.WriteLine("Failed to process S2."); break; case WRONG_INTEL_SIGNED_CERT_TYPE: //lblGetS3MsgRet.Text = "Verifier's certificate is wrong Intel signed."; Console.WriteLine("Verifier's certificate is wrong Intel signed."); break; case FAILED_TO_GET_SESSION_PARAMS: //lblGetS3MsgRet.Text = "Failed to get session parameters."; Console.WriteLine("Failed to get session parameters."); break; case FAILED_TO_DISPOSE_SIGMA: //lblGetS3MsgRet.Text = "Failed to dispose SIGMA."; Console.WriteLine("Failed to dispose SIGMA."); break; //S3 message received successfully case STATUS_SUCCEEDED: { Console.WriteLine("getS3 Success from applet"); //Send S3 message to server for processing and verification byte[] S3MsgToSend = new byte[s3MessageLenInt]; Marshal.Copy(s3Msg, S3MsgToSend, 0, S3MsgToSend.Length); socket.Send(BitConverter.GetBytes(s3MessageLenInt)); socket.Send(S3MsgToSend); //lblGetS3MsgRet.Text = "S3 message created successfully."; socket.Receive(statusBytes, 0, INT_SIZE, 0); status = BitConverter.ToInt32(statusBytes, 0); //server response if (status == STATUS_SUCCEEDED) { Console.WriteLine("Now both parties have one shared secret and\ncan use any symmetrical encryption algorithm."); } //lblEnd.Text = "Now both parties have one shared secret and\ncan use any symmetrical encryption algorithm."; else { Console.WriteLine("Server failed to verify S3 message."); } //lblEnd.Text = "Server failed to verify S3 message."; break; } default: Console.WriteLine("Failed to perform send and receive operation in\norder to get S3 message."); //lblGetS3MsgRet.Text = "Failed to perform send and receive operation in\norder to get S3 message."; break; } Marshal.FreeHGlobal(s3Msg); //btnGetS3Msg.Enabled = false; break; } default: //lblGetS3MsgRet.Text = "Failed to perform send and receive operation in\norder to get S3 message length."; Console.WriteLine("Failed to perform send and receive operation in\norder to get S3 message length."); break; } Marshal.FreeHGlobal(s3MsgLen); return(true); }