summaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2011-04-20 23:06:24 +0200
committerSamuel Lidén Borell <samuel@slbdata.se>2011-04-20 23:06:24 +0200
commit0e422fd5691b60520e79a0da446efa45f9b5ddfb (patch)
tree4e78a5e23fe5ad189e8f7e3e0088d0307a7443ca /client
parentb8d1227b8cb3e3b216ea03605f0b20c320330d20 (diff)
downloadfribid-0e422fd5691b60520e79a0da446efa45f9b5ddfb.tar.gz
fribid-0e422fd5691b60520e79a0da446efa45f9b5ddfb.tar.bz2
fribid-0e422fd5691b60520e79a0da446efa45f9b5ddfb.zip
Implement password policys
This patch adds support for the parameters MinLen, MinChars and MinDigits. I didn't add MaxLen because I think it's stupid to prohibit long passwords :)
Diffstat (limited to 'client')
-rw-r--r--client/gtk.c50
-rw-r--r--client/main.c7
-rw-r--r--client/platform.h3
-rwxr-xr-xclient/sendreq.sh9
-rwxr-xr-xclient/testsign.sh4
5 files changed, 67 insertions, 6 deletions
diff --git a/client/gtk.c b/client/gtk.c
index ee29039..bcc2d46 100644
--- a/client/gtk.c
+++ b/client/gtk.c
@@ -126,6 +126,9 @@ static bool signDialogShown;
static GtkDialog *keygenDialog;
static GtkEntry *keygenPasswordEntry;
static GtkEntry *keygenRepeatPasswordEntry;
+static int keygenPasswordMinLen;
+static int keygenPasswordMinDigits;
+static int keygenPasswordMinNonDigits;
static bool keygenDialogShown;
/**
@@ -557,11 +560,27 @@ void platform_startChoosePassword(const char *name, unsigned long parentWindowId
keygenDialogShown = false;
}
+void platform_setPasswordPolicy(int minLength, int minNonDigits, int minDigits) {
+ keygenPasswordMinLen = minLength;
+ keygenPasswordMinNonDigits = minNonDigits;
+ keygenPasswordMinDigits = minDigits;
+}
+
void platform_endChoosePassword() {
gtk_widget_destroy(GTK_WIDGET(keygenDialog));
}
+static bool weakPassword(int length, int minimum, const char *format) {
+ if (length < minimum) {
+ char *error = rasprintf(format, minimum);
+ showMessage(GTK_MESSAGE_ERROR, error);
+ g_free(error);
+ return TRUE;
+ }
+ return FALSE;
+}
+
bool platform_choosePassword(char *password, long password_maxlen) {
// Restrict the password to the length of the preallocated
// password buffer
@@ -589,8 +608,37 @@ bool platform_choosePassword(char *password, long password_maxlen) {
continue;
}
+ // Check password policy
+ const char *pwtext = gtk_entry_get_text(keygenPasswordEntry);
+ int pwlen = g_utf8_strlen(pwtext, -1);
+
+ int numDigits = 0;
+ int numNonDigits = 0;
+ const char *c = pwtext;
+ while (*c) {
+ if (*c >= '0' && *c <= '9') numDigits++;
+ else numNonDigits++;
+ c = g_utf8_find_next_char(c, NULL);
+ }
+
+ if (weakPassword(pwlen, keygenPasswordMinLen,
+ ngettext("The password must be at least one character",
+ "The password must be at least %d characters",
+ keygenPasswordMinLen)) ||
+ weakPassword(numNonDigits, keygenPasswordMinNonDigits,
+ ngettext("The password must have at least one character that is not a digit",
+ "The password must have at least %d characters that are not digits",
+ keygenPasswordMinNonDigits)) ||
+ weakPassword(numDigits, keygenPasswordMinDigits,
+ ngettext("The password must have at least one digit",
+ "The password must have at least %d digits",
+ keygenPasswordMinDigits))) {
+ // Not OK
+ continue;
+ }
+
// Copy the password to the secure buffer
- strncpy(password, gtk_entry_get_text(keygenPasswordEntry), password_maxlen-1);
+ strncpy(password, pwtext, password_maxlen-1);
// Be sure to terminate this under all circumstances
password[password_maxlen-1] = '\0';
return true;
diff --git a/client/main.c b/client/main.c
index 228ae4c..3fa5716 100644
--- a/client/main.c
+++ b/client/main.c
@@ -207,6 +207,10 @@ void pipeData() {
RegutilInfo input;
memset(&input, 0, sizeof(input));
+ input.minPasswordLength = pipe_readInt(stdin);
+ input.minPasswordNonDigits = pipe_readInt(stdin);
+ input.minPasswordDigits = pipe_readInt(stdin);
+
while (pipe_readInt(stdin) == PLS_MoreData) {
// PKCS10
RegutilPKCS10 *pkcs10 = malloc(sizeof(RegutilPKCS10));
@@ -238,6 +242,9 @@ void pipeData() {
if (!password || !password_maxsize) goto createReq_end;
platform_startChoosePassword(name, browserWindowId);
+ platform_setPasswordPolicy(input.minPasswordLength,
+ input.minPasswordNonDigits,
+ input.minPasswordDigits);
if (bankid_versionHasExpired()) {
platform_versionExpiredError();
diff --git a/client/platform.h b/client/platform.h
index bf94214..b18486a 100644
--- a/client/platform.h
+++ b/client/platform.h
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2009-2010 Samuel Lidén Borell <samuel@slbdata.se>
+ Copyright (c) 2009-2011 Samuel Lidén Borell <samuel@slbdata.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -107,6 +107,7 @@ bool platform_sign(Token **token, char *password, int password_maxlen);
/* Password selection (and key generation) dialog */
void platform_startChoosePassword(const char *name, unsigned long parentWindowId);
+void platform_setPasswordPolicy(int minLength, int minNonDigits, int minDigits);
void platform_endChoosePassword();
bool platform_choosePassword(char *password, long password_maxlen);
diff --git a/client/sendreq.sh b/client/sendreq.sh
index 26bbeea..24dc8d9 100755
--- a/client/sendreq.sh
+++ b/client/sendreq.sh
@@ -14,6 +14,11 @@ EndOfData() { sendint 0; }
#### Send request ####
CreateRequest
+# Password policy
+sendint 12 # Minimum length
+sendint 4 # Minimum number of non-digits
+sendint 1 # Minimum number of digits
+
# PKCS10
MoreData
sendint 1 # KeyUsage
@@ -35,8 +40,8 @@ sendstring true
echo 'hack'
-} | valgrind --leak-check=no -q ./sign --internal--ipc=7 | tr ';' '\n' | {
-#} | ./sign --internal--ipc=7 | tr ';' '\n' | {
+} | valgrind --leak-check=no -q ./sign --internal--ipc=8 | tr ';' '\n' | {
+#} | ./sign --internal--ipc=8 | tr ';' '\n' | {
#### Parse response ####
read error
diff --git a/client/testsign.sh b/client/testsign.sh
index 72c0a37..45c9bc3 100755
--- a/client/testsign.sh
+++ b/client/testsign.sh
@@ -29,8 +29,8 @@ sendstring '' # hidden data (optional)
echo 'hack'
-#} | valgrind --leak-check=no -q ./sign --internal--ipc=7 | tr ';' '\n' | {
-} | ./sign --internal--ipc=7 | tr ';' '\n' | {
+#} | valgrind --leak-check=no -q ./sign --internal--ipc=8 | tr ';' '\n' | {
+} | ./sign --internal--ipc=8 | tr ';' '\n' | {
#### Parse response ####
read error