diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2012-11-25 14:36:20 +0000 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2012-11-25 14:36:20 +0000 |
commit | c3649a2def02c41d837ae1f79dda729ccb91e677 (patch) | |
tree | bea46dff212fdef977fe9094a70a939e8cc21885 /src/tspi/ssl_ui.c | |
download | trousers-upstream.tar.gz |
Imported Upstream version 0.3.9upstream/0.3.9upstream
Diffstat (limited to 'src/tspi/ssl_ui.c')
-rw-r--r-- | src/tspi/ssl_ui.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/tspi/ssl_ui.c b/src/tspi/ssl_ui.c new file mode 100644 index 0000000..5e25895 --- /dev/null +++ b/src/tspi/ssl_ui.c @@ -0,0 +1,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); +} |