X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/8b8cf871e5471e658dda0836db678e0d68027e8c..bdea0743e4f42352a813c2da3c267dcca6d6871c:/puttygen.c diff --git a/puttygen.c b/puttygen.c index 564067ae..9b360905 100644 --- a/puttygen.c +++ b/puttygen.c @@ -22,9 +22,6 @@ /* * TODO: - * - have some means of verifying passphrase changes against typos - * - prompt before overwriting an existing file - * - check the return value from saversakey() * - test the generated keys for actual working-RSA-key-hood * - variable key size */ @@ -302,7 +299,8 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, IDC_PKSTATIC, IDC_KEYDISPLAY, IDC_FPSTATIC, IDC_FINGERPRINT, IDC_COMMENTSTATIC, IDC_COMMENTEDIT, - IDC_PASSPHRASESTATIC, IDC_PASSPHRASEEDIT, + IDC_PASSPHRASE1STATIC, IDC_PASSPHRASE1EDIT, + IDC_PASSPHRASE2STATIC, IDC_PASSPHRASE2EDIT, IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS, IDC_GENSTATIC, IDC_GENERATE, IDC_LOADSTATIC, IDC_LOAD, @@ -315,7 +313,8 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, IDC_PKSTATIC, IDC_KEYDISPLAY, IDC_FPSTATIC, IDC_FINGERPRINT, IDC_COMMENTSTATIC, IDC_COMMENTEDIT, - IDC_PASSPHRASESTATIC, IDC_PASSPHRASEEDIT, 0 }; + IDC_PASSPHRASE1STATIC, IDC_PASSPHRASE1EDIT, + IDC_PASSPHRASE2STATIC, IDC_PASSPHRASE2EDIT, 0 }; static const char generating_msg[] = "Please wait while a key is generated..."; static const char entropy_msg[] = @@ -331,6 +330,8 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, { struct ctlpos cp, cp2; + /* Accelerators used: acglops */ + ctlposinit(&cp, hwnd, 10, 10, 10); bartitle(&cp, "Public and private key generation for PuTTY", IDC_TITLE); @@ -351,8 +352,10 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, SendDlgItemMessage(hwnd, IDC_FINGERPRINT, EM_SETREADONLY, 1, 0); staticedit(&cp, "Key &comment:", IDC_COMMENTSTATIC, IDC_COMMENTEDIT, 70); - staticpassedit(&cp, "Key p&assphrase:", IDC_PASSPHRASESTATIC, - IDC_PASSPHRASEEDIT, 70); + staticpassedit(&cp, "Key p&assphrase:", IDC_PASSPHRASE1STATIC, + IDC_PASSPHRASE1EDIT, 70); + staticpassedit(&cp, "C&onfirm passphrase:", IDC_PASSPHRASE2STATIC, + IDC_PASSPHRASE2EDIT, 70); endbox(&cp); beginbox(&cp, "Actions", IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS); @@ -480,8 +483,18 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, if (state->key_exists) { char filename[FILENAME_MAX]; char passphrase[PASSPHRASE_MAXLEN]; - GetDlgItemText(hwnd, IDC_PASSPHRASEEDIT, - passphrase, sizeof(passphrase)-1); + char passphrase2[PASSPHRASE_MAXLEN]; + GetDlgItemText(hwnd, IDC_PASSPHRASE1EDIT, + passphrase, sizeof(passphrase)); + GetDlgItemText(hwnd, IDC_PASSPHRASE2EDIT, + passphrase2, sizeof(passphrase2)); + if (strcmp(passphrase, passphrase2)) { + MessageBox(hwnd, + "The two passphrases given do not match.", + "PuTTYgen Error", + MB_OK | MB_ICONERROR); + break; + } if (!*passphrase) { int ret; ret = MessageBox(hwnd, @@ -494,10 +507,25 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, } if (prompt_keyfile(hwnd, "Save private key as:", filename, 1)) { - /* FIXME: prompt before overwriting */ - saversakey(filename, &state->key, &state->aux, - *passphrase ? passphrase : NULL); - /* FIXME: check return value */ + int ret; + FILE *fp = fopen(filename, "r"); + if (fp) { + char buffer[FILENAME_MAX+80]; + fclose(fp); + sprintf(buffer, "Overwrite existing file\n%.*s?", + FILENAME_MAX, filename); + ret = MessageBox(hwnd, buffer, "PuTTYgen Warning", + MB_YESNO | MB_ICONWARNING); + if (ret != IDYES) + break; + } + ret = saversakey(filename, &state->key, &state->aux, + *passphrase ? passphrase : NULL); + if (ret <= 0) { + MessageBox(hwnd, "Unable to save key file", + "PuTTYgen Error", + MB_OK | MB_ICONERROR); + } } } break; @@ -551,7 +579,9 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, */ { char buf[128]; - SetDlgItemText(hwnd, IDC_PASSPHRASEEDIT, + SetDlgItemText(hwnd, IDC_PASSPHRASE1EDIT, + passphrase); + SetDlgItemText(hwnd, IDC_PASSPHRASE2EDIT, passphrase); SetDlgItemText(hwnd, IDC_COMMENTEDIT, state->key.comment); @@ -619,7 +649,8 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, * because we will warn (Are You Sure?) before allowing * the user to save an unprotected private key. */ - SetDlgItemText(hwnd, IDC_PASSPHRASEEDIT, ""); + SetDlgItemText(hwnd, IDC_PASSPHRASE1EDIT, ""); + SetDlgItemText(hwnd, IDC_PASSPHRASE2EDIT, ""); /* * Set the comment. */