summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-01-27 02:40:31 +0100
committerGravatar Nikias Bassen2019-01-27 02:40:31 +0100
commita2dfb1b27e34b75b81e81537ba8711f42d3f7f06 (patch)
tree4d8f65c954a36a6a666998185171cd1dac837596 /tools
parent4481d1be86fd2068747cf8912d1402fa18c2134c (diff)
downloadlibideviceactivation-a2dfb1b27e34b75b81e81537ba8711f42d3f7f06.tar.gz
libideviceactivation-a2dfb1b27e34b75b81e81537ba8711f42d3f7f06.tar.bz2
ideviceactivation: Mask input for secure input fields
Diffstat (limited to 'tools')
-rw-r--r--tools/ideviceactivation.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/tools/ideviceactivation.c b/tools/ideviceactivation.c
index a930d5d..93e6717 100644
--- a/tools/ideviceactivation.c
+++ b/tools/ideviceactivation.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include <plist/plist.h>
#include <libimobiledevice/lockdown.h>
@@ -36,6 +37,13 @@
#include <libimobiledevice/mobileactivation.h>
#include <libideviceactivation.h>
+#ifdef WIN32
+#include <windows.h>
+#include <conio.h>
+#else
+#include <termios.h>
+#endif
+
static void print_usage(int argc, char **argv)
{
char *name = NULL;
@@ -58,6 +66,48 @@ static void print_usage(int argc, char **argv)
printf("Homepage: <http://libimobiledevice.org>\n");
}
+#ifdef WIN32
+#define BS_CC '\b'
+#define my_getch getch
+#else
+#define BS_CC 0x7f
+static int my_getch(void)
+{
+ struct termios oldt, newt;
+ int ch;
+ tcgetattr(STDIN_FILENO, &oldt);
+ newt = oldt;
+ newt.c_lflag &= ~(ICANON | ECHO);
+ tcsetattr(STDIN_FILENO, TCSANOW, &newt);
+ ch = getchar();
+ tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
+ return ch;
+}
+#endif
+
+static void get_user_input(char *buf, int maxlen, int secure)
+{
+ int len = 0;
+ int c;
+
+ while ((c = my_getch())) {
+ if ((c == '\r') || (c == '\n')) {
+ break;
+ } else if (isprint(c)) {
+ if (len < maxlen-1)
+ buf[len++] = c;
+ fputc((secure) ? '*' : c, stdout);
+ } else if (c == BS_CC) {
+ if (len > 0) {
+ fputs("\b \b", stdout);
+ len--;
+ }
+ }
+ }
+ fputs("\n", stdout);
+ buf[len] = 0;
+}
+
int main(int argc, char *argv[])
{
idevice_t device = NULL;
@@ -461,9 +511,18 @@ int main(int argc, char *argv[])
if (idevice_activation_response_field_requires_input(response, field_key)) {
idevice_activation_response_get_label(response, field_key, &field_label);
if (interactive) {
- printf("input %s: ", field_label ? field_label : field_key);
+ char *field_placeholder = NULL;
+ int secure = idevice_activation_response_field_secure_input(response, field_key);
+ idevice_activation_response_get_placeholder(response, field_key, &field_placeholder);
+ printf("input %s", field_label ? field_label : field_key);
+ if (field_placeholder) {
+ printf(" (%s)", field_placeholder);
+ free(field_placeholder);
+ }
+ printf(": ");
+ fflush(stdout);
fflush(stdin);
- scanf("%1023s", input);
+ get_user_input(input, 1023, secure);
} else {
fprintf(stderr, "Server requires input for '%s' but we're not running interactively.\n", field_label ? field_label : field_key);
strcpy(input, "");