1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <sys/types.h>
#include <string.h>
#include <openssl/ui.h>
#include "trousers/tss.h"
#include "spi_utils.h"
static TSS_RESULT do_ui(BYTE *string, UINT32 *string_len, BYTE *popup, int verify)
{
char pin_buf[UI_MAX_SECRET_STRING_LENGTH + 1];
char verify_buf[UI_MAX_SECRET_STRING_LENGTH + 1];
char *popup_nl;
UI *ui;
BYTE *unicode;
TSS_RESULT ret = TSS_E_FAIL;
popup_nl = malloc(strlen((char *)popup) + 2);
if (!popup_nl)
return TSS_E_OUTOFMEMORY;
ui = UI_new();
if (!ui)
goto no_ui;
sprintf(popup_nl, "%s\n", (char *)popup);
if (!UI_add_info_string(ui, popup_nl)) {
printf("add info fail\n");
goto out;
}
/* UI_add_input_string() doesn't count for the null terminator in its last */
/* parameter, that's why we statically allocated 1 more byte to pin_buf */
if (!UI_add_input_string(ui, "Enter PIN:", 0, pin_buf, 1, UI_MAX_SECRET_STRING_LENGTH)) {
printf("add input fail\n");
goto out;
}
if (verify &&
!UI_add_verify_string(ui, "Verify PIN:", 0, verify_buf, 1, UI_MAX_SECRET_STRING_LENGTH, pin_buf)) {
printf("Add verify fail\n");
goto out;
}
if (UI_process(ui))
goto out;
ret = TSS_SUCCESS;
unicode = Trspi_Native_To_UNICODE((BYTE *)pin_buf, string_len);
memset(string, 0, UI_MAX_SECRET_STRING_LENGTH);
memcpy(string, unicode, *string_len);
out:
UI_free(ui);
no_ui:
free(popup_nl);
return ret;
}
/*
* DisplayPINWindow()
*
* Popup the dialog to collect an existing password.
*
* string - buffer that the password will be passed back to caller in
* popup - UTF-8 string to be displayed in the title bar of the dialog box
*
*/
TSS_RESULT DisplayPINWindow(BYTE *string, UINT32 *string_len, BYTE *popup)
{
return do_ui(string, string_len, popup, 0);
}
/*
* DisplayNewPINWindow()
*
* Popup the dialog to collect a new password.
*
* string - buffer that the password will be passed back to caller in
* popup - UTF-8 string to be displayed in the title bar of the dialog box
*
*/
TSS_RESULT DisplayNewPINWindow(BYTE *string, UINT32 *string_len, BYTE *popup)
{
return do_ui(string, string_len, popup, 1);
}
|