2 * PuTTY key generation front end.
11 #define PUTTY_DO_GLOBALS
17 #define WM_DONEKEY (WM_XUSER + 1)
19 #define DEFAULT_KEYSIZE 1024
21 /* ----------------------------------------------------------------------
22 * Progress report code. This is really horrible :-)
24 #define PHASE1TOTAL 0x10000
25 #define PHASE2TOTAL 0x10000
26 #define PHASE3TOTAL 0x04000
28 #define PHASE2START (PHASE1TOTAL)
29 #define PHASE3START (PHASE1TOTAL + PHASE2TOTAL)
30 #define TOTALTOTAL (PHASE1TOTAL + PHASE2TOTAL + PHASE3TOTAL)
31 #define PROGRESSBIGRANGE 65535
32 #define DIVISOR ((TOTALTOTAL + PROGRESSBIGRANGE - 1) / PROGRESSBIGRANGE)
33 #define PROGRESSRANGE (TOTALTOTAL / DIVISOR)
35 unsigned phase1param
, phase1current
, phase1n
;
36 unsigned phase2param
, phase2current
, phase2n
;
41 static void progress_update(void *param
, int phase
, int iprogress
) {
42 struct progress
*p
= (struct progress
*)param
;
43 unsigned progress
= iprogress
;
48 p
->phase1param
= 0x10000 + progress
;
49 p
->phase1current
= 0x10000; p
->phase1n
= 0;
52 p
->phase2param
= 0x10000 + progress
;
53 p
->phase2current
= 0x10000; p
->phase2n
= 0;
56 p
->phase3mult
= PHASE3TOTAL
/ progress
;
59 while (p
->phase1n
< progress
) {
61 p
->phase1current
*= p
->phase1param
;
62 p
->phase1current
/= 0x10000;
64 position
= PHASE1START
+ 0x10000 - p
->phase1current
;
67 while (p
->phase2n
< progress
) {
69 p
->phase2current
*= p
->phase2param
;
70 p
->phase2current
/= 0x10000;
72 position
= PHASE2START
+ 0x10000 - p
->phase2current
;
75 position
= PHASE3START
+ progress
* p
->phase3mult
;
79 SendMessage(p
->progbar
, PBM_SETPOS
, position
/ DIVISOR
, 0);
84 #define PASSPHRASE_MAXLEN 512
86 struct PassphraseProcStruct
{
92 * Dialog-box function for the passphrase box.
94 static int CALLBACK
PassphraseProc(HWND hwnd
, UINT msg
,
95 WPARAM wParam
, LPARAM lParam
) {
96 static char *passphrase
;
97 struct PassphraseProcStruct
*p
;
101 SetForegroundWindow(hwnd
);
102 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0,
103 SWP_NOMOVE
| SWP_NOSIZE
| SWP_SHOWWINDOW
);
108 { /* centre the window */
112 hw
= GetDesktopWindow();
113 if (GetWindowRect (hw
, &rs
) && GetWindowRect (hwnd
, &rd
))
114 MoveWindow (hwnd
, (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
)/2,
115 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
)/2,
116 rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, TRUE
);
119 p
= (struct PassphraseProcStruct
*)lParam
;
120 passphrase
= p
->passphrase
;
122 SetDlgItemText(hwnd
, 101, p
->comment
);
126 switch (LOWORD(wParam
)) {
136 case 102: /* edit box */
137 if (HIWORD(wParam
) == EN_CHANGE
) {
138 GetDlgItemText (hwnd
, 102, passphrase
, PASSPHRASE_MAXLEN
-1);
139 passphrase
[PASSPHRASE_MAXLEN
-1] = '\0';
152 * Prompt for a key file. Assumes the filename buffer is of size
155 static int prompt_keyfile(HWND hwnd
, char *dlgtitle
,
156 char *filename
, int save
) {
158 memset(&of
, 0, sizeof(of
));
159 #ifdef OPENFILENAME_SIZE_VERSION_400
160 of
.lStructSize
= OPENFILENAME_SIZE_VERSION_400
;
162 of
.lStructSize
= sizeof(of
);
165 of
.lpstrFilter
= "All Files\0*\0\0\0";
166 of
.lpstrCustomFilter
= NULL
;
168 of
.lpstrFile
= filename
; *filename
= '\0';
169 of
.nMaxFile
= FILENAME_MAX
;
170 of
.lpstrFileTitle
= NULL
;
171 of
.lpstrInitialDir
= NULL
;
172 of
.lpstrTitle
= dlgtitle
;
175 return GetSaveFileName(&of
);
177 return GetOpenFileName(&of
);
181 * This function is needed to link with the DES code. We need not
182 * have it do anything at all.
184 void logevent(char *msg
) {
188 * Dialog-box function for the Licence box.
190 static int CALLBACK
LicenceProc (HWND hwnd
, UINT msg
,
191 WPARAM wParam
, LPARAM lParam
) {
197 { /* centre the window */
201 hw
= GetDesktopWindow();
202 if (GetWindowRect (hw
, &rs
) && GetWindowRect (hwnd
, &rd
))
203 MoveWindow (hwnd
, (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
)/2,
204 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
)/2,
205 rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, TRUE
);
210 switch (LOWORD(wParam
)) {
224 * Dialog-box function for the About box.
226 static int CALLBACK
AboutProc (HWND hwnd
, UINT msg
,
227 WPARAM wParam
, LPARAM lParam
) {
233 { /* centre the window */
237 hw
= GetDesktopWindow();
238 if (GetWindowRect (hw
, &rs
) && GetWindowRect (hwnd
, &rd
))
239 MoveWindow (hwnd
, (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
)/2,
240 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
)/2,
241 rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, TRUE
);
244 SetDlgItemText (hwnd
, 100, ver
);
247 switch (LOWORD(wParam
)) {
252 EnableWindow(hwnd
, 0);
253 DialogBox (hinst
, MAKEINTRESOURCE(214), NULL
, LicenceProc
);
254 EnableWindow(hwnd
, 1);
255 SetActiveWindow(hwnd
);
267 * Thread to generate a key.
269 struct rsa_key_thread_params
{
270 HWND progressbar
; /* notify this with progress */
271 HWND dialog
; /* notify this on completion */
272 int keysize
; /* bits in key */
275 static DWORD WINAPI
generate_rsa_key_thread(void *param
) {
276 struct rsa_key_thread_params
*params
=
277 (struct rsa_key_thread_params
*)param
;
278 struct progress prog
;
279 prog
.progbar
= params
->progressbar
;
281 rsa_generate(params
->key
, params
->keysize
, progress_update
, &prog
);
283 PostMessage(params
->dialog
, WM_DONEKEY
, 0, 0);
289 struct MainDlgState
{
290 int collecting_entropy
;
291 int generation_thread_exists
;
293 int entropy_got
, entropy_required
, entropy_size
;
296 char **commentptr
; /* points to key.comment or ssh2key.comment */
297 struct ssh2_userkey ssh2key
;
302 static void hidemany(HWND hwnd
, const int *ids
, int hideit
) {
304 ShowWindow(GetDlgItem(hwnd
, *ids
++), (hideit ? SW_HIDE
: SW_SHOW
));
308 static void setupbigedit1(HWND hwnd
, int id
, struct RSAKey
*key
) {
312 dec1
= bignum_decimal(key
->exponent
);
313 dec2
= bignum_decimal(key
->modulus
);
314 buffer
= smalloc(strlen(dec1
)+strlen(dec2
)+
315 strlen(key
->comment
)+30);
316 sprintf(buffer
, "%d %s %s %s",
317 ssh1_bignum_bitcount(key
->modulus
),
318 dec1
, dec2
, key
->comment
);
319 SetDlgItemText(hwnd
, id
, buffer
);
325 static void setupbigedit2(HWND hwnd
, int id
, struct ssh2_userkey
*key
) {
326 unsigned char *pub_blob
;
331 pub_blob
= key
->alg
->public_blob(key
->data
, &pub_len
);
332 buffer
= smalloc(strlen(key
->alg
->name
) + 4*((pub_len
+2)/3) +
333 strlen(key
->comment
) + 3);
334 strcpy(buffer
, key
->alg
->name
);
335 p
= buffer
+ strlen(buffer
);
338 while (i
< pub_len
) {
339 int n
= (pub_len
-i
< 3 ? pub_len
-i
: 3);
340 base64_encode_atom(pub_blob
+i
, n
, p
);
345 strcpy(p
, key
->comment
);
346 SetDlgItemText(hwnd
, id
, buffer
);
352 * Dialog-box function for the main PuTTYgen dialog box.
354 static int CALLBACK
MainDlgProc (HWND hwnd
, UINT msg
,
355 WPARAM wParam
, LPARAM lParam
) {
357 controlidstart
= 100,
363 IDC_PKSTATIC
, IDC_KEYDISPLAY
,
364 IDC_FPSTATIC
, IDC_FINGERPRINT
,
365 IDC_COMMENTSTATIC
, IDC_COMMENTEDIT
,
366 IDC_PASSPHRASE1STATIC
, IDC_PASSPHRASE1EDIT
,
367 IDC_PASSPHRASE2STATIC
, IDC_PASSPHRASE2EDIT
,
369 IDC_GENSTATIC
, IDC_GENERATE
,
370 IDC_LOADSTATIC
, IDC_LOAD
,
371 IDC_SAVESTATIC
, IDC_SAVE
,
373 IDC_TYPESTATIC
, IDC_KEYSSH1
, IDC_KEYSSH2RSA
,
374 IDC_BITSSTATIC
, IDC_BITS
,
377 static const int nokey_ids
[] = { IDC_NOKEY
, 0 };
378 static const int generating_ids
[] = { IDC_GENERATING
, IDC_PROGRESS
, 0 };
379 static const int gotkey_ids
[] = {
380 IDC_PKSTATIC
, IDC_KEYDISPLAY
,
381 IDC_FPSTATIC
, IDC_FINGERPRINT
,
382 IDC_COMMENTSTATIC
, IDC_COMMENTEDIT
,
383 IDC_PASSPHRASE1STATIC
, IDC_PASSPHRASE1EDIT
,
384 IDC_PASSPHRASE2STATIC
, IDC_PASSPHRASE2EDIT
, 0 };
385 static const char generating_msg
[] =
386 "Please wait while a key is generated...";
387 static const char entropy_msg
[] =
388 "Please generate some randomness by moving the mouse over the blank area.";
389 struct MainDlgState
*state
;
396 { /* centre the window */
400 hw
= GetDesktopWindow();
401 if (GetWindowRect (hw
, &rs
) && GetWindowRect (hwnd
, &rd
))
402 MoveWindow (hwnd
, (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
)/2,
403 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
)/2,
404 rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, TRUE
);
407 state
= smalloc(sizeof(*state
));
408 state
->generation_thread_exists
= FALSE
;
409 state
->collecting_entropy
= FALSE
;
410 state
->entropy
= NULL
;
411 state
->key_exists
= FALSE
;
412 SetWindowLong(hwnd
, GWL_USERDATA
, (LONG
)state
);
414 struct ctlpos cp
, cp2
;
416 /* Accelerators used: acglops */
418 ctlposinit(&cp
, hwnd
, 10, 10, 10);
419 bartitle(&cp
, "Public and private key generation for PuTTY",
424 statictext(&cp2
, "No key.", IDC_NOKEY
);
428 progressbar(&cp2
, IDC_PROGRESS
);
430 "&Public key for pasting into authorized_keys file:",
431 IDC_PKSTATIC
, IDC_KEYDISPLAY
, 7);
432 SendDlgItemMessage(hwnd
, IDC_KEYDISPLAY
, EM_SETREADONLY
, 1, 0);
433 staticedit(&cp
, "Key fingerprint:", IDC_FPSTATIC
,
434 IDC_FINGERPRINT
, 75);
435 SendDlgItemMessage(hwnd
, IDC_FINGERPRINT
, EM_SETREADONLY
, 1, 0);
436 staticedit(&cp
, "Key &comment:", IDC_COMMENTSTATIC
,
437 IDC_COMMENTEDIT
, 75);
438 staticpassedit(&cp
, "Key p&assphrase:", IDC_PASSPHRASE1STATIC
,
439 IDC_PASSPHRASE1EDIT
, 75);
440 staticpassedit(&cp
, "C&onfirm passphrase:", IDC_PASSPHRASE2STATIC
,
441 IDC_PASSPHRASE2EDIT
, 75);
443 beginbox(&cp
, "Actions",
445 staticbtn(&cp
, "Generate a public/private key pair",
446 IDC_GENSTATIC
, "&Generate", IDC_GENERATE
);
447 staticbtn(&cp
, "Load an existing private key file",
448 IDC_LOADSTATIC
, "&Load", IDC_LOAD
);
449 staticbtn(&cp
, "Save the generated key to a new file",
450 IDC_SAVESTATIC
, "&Save", IDC_SAVE
);
452 beginbox(&cp
, "Parameters",
454 radioline(&cp
, "Type of key to generate:", IDC_TYPESTATIC
, 2,
455 "SSH&1 (RSA)", IDC_KEYSSH1
,
456 "SSH2 &RSA", IDC_KEYSSH2RSA
, NULL
);
457 staticedit(&cp
, "Number of &bits in a generated key:",
458 IDC_BITSSTATIC
, IDC_BITS
, 20);
461 CheckRadioButton(hwnd
, IDC_KEYSSH1
, IDC_KEYSSH2RSA
, IDC_KEYSSH1
);
462 SetDlgItemInt(hwnd
, IDC_BITS
, DEFAULT_KEYSIZE
, FALSE
);
465 * Initially, hide the progress bar and the key display,
466 * and show the no-key display. Also disable the Save
467 * button, because with no key we obviously can't save
470 hidemany(hwnd
, nokey_ids
, FALSE
);
471 hidemany(hwnd
, generating_ids
, TRUE
);
472 hidemany(hwnd
, gotkey_ids
, TRUE
);
473 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 0);
477 state
= (struct MainDlgState
*)GetWindowLong(hwnd
, GWL_USERDATA
);
478 if (state
->collecting_entropy
&&
480 state
->entropy_got
< state
->entropy_required
) {
481 state
->entropy
[state
->entropy_got
++] = lParam
;
482 state
->entropy
[state
->entropy_got
++] = GetMessageTime();
483 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
,
484 state
->entropy_got
, 0);
485 if (state
->entropy_got
>= state
->entropy_required
) {
486 struct rsa_key_thread_params
*params
;
490 * Seed the entropy pool
492 random_add_heavynoise(state
->entropy
, state
->entropy_size
);
493 memset(state
->entropy
, 0, state
->entropy_size
);
494 sfree(state
->entropy
);
495 state
->collecting_entropy
= FALSE
;
497 SetDlgItemText(hwnd
, IDC_GENERATING
, generating_msg
);
498 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETRANGE
, 0,
499 MAKELPARAM(0, PROGRESSRANGE
));
500 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
, 0, 0);
502 params
= smalloc(sizeof(*params
));
503 params
->progressbar
= GetDlgItem(hwnd
, IDC_PROGRESS
);
504 params
->dialog
= hwnd
;
505 params
->keysize
= state
->keysize
;
506 params
->key
= &state
->key
;
508 if (!CreateThread(NULL
, 0, generate_rsa_key_thread
,
509 params
, 0, &threadid
)) {
510 MessageBox(hwnd
, "Out of thread resources",
511 "Key generation error",
512 MB_OK
| MB_ICONERROR
);
515 state
->generation_thread_exists
= TRUE
;
521 switch (LOWORD(wParam
)) {
522 case IDC_COMMENTEDIT
:
523 if (HIWORD(wParam
) == EN_CHANGE
) {
524 state
= (struct MainDlgState
*)
525 GetWindowLong(hwnd
, GWL_USERDATA
);
526 if (state
->key_exists
) {
527 HWND editctl
= GetDlgItem(hwnd
, IDC_COMMENTEDIT
);
528 int len
= GetWindowTextLength(editctl
);
529 if (*state
->commentptr
)
530 sfree(*state
->commentptr
);
531 *state
->commentptr
= smalloc(len
+1);
532 GetWindowText(editctl
, *state
->commentptr
, len
+1);
534 setupbigedit2(hwnd
, IDC_KEYDISPLAY
, &state
->ssh2key
);
536 setupbigedit1(hwnd
, IDC_KEYDISPLAY
, &state
->key
);
542 EnableWindow(hwnd
, 0);
543 DialogBox (hinst
, MAKEINTRESOURCE(213), NULL
, AboutProc
);
544 EnableWindow(hwnd
, 1);
545 SetActiveWindow(hwnd
);
548 state
= (struct MainDlgState
*)GetWindowLong(hwnd
, GWL_USERDATA
);
549 if (!state
->generation_thread_exists
) {
551 state
->keysize
= GetDlgItemInt(hwnd
, IDC_BITS
,
553 if (!ok
) state
->keysize
= DEFAULT_KEYSIZE
;
554 /* If we ever introduce a new key type, check it here! */
555 state
->ssh2
= !IsDlgButtonChecked(hwnd
, IDC_KEYSSH1
);
556 if (state
->keysize
< 256) {
557 int ret
= MessageBox(hwnd
,
558 "PuTTYgen will not generate a key"
559 " smaller than 256 bits.\n"
560 "Key length reset to 256. Continue?",
562 MB_ICONWARNING
| MB_OKCANCEL
);
565 state
->keysize
= 256;
566 SetDlgItemInt(hwnd
, IDC_BITS
, 256, FALSE
);
568 hidemany(hwnd
, nokey_ids
, TRUE
);
569 hidemany(hwnd
, generating_ids
, FALSE
);
570 hidemany(hwnd
, gotkey_ids
, TRUE
);
571 EnableWindow(GetDlgItem(hwnd
, IDC_GENERATE
), 0);
572 EnableWindow(GetDlgItem(hwnd
, IDC_LOAD
), 0);
573 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 0);
574 state
->key_exists
= FALSE
;
575 SetDlgItemText(hwnd
, IDC_GENERATING
, entropy_msg
);
576 state
->collecting_entropy
= TRUE
;
579 * My brief statistical tests on mouse movements
580 * suggest that there are about 2.5 bits of
581 * randomness in the x position, 2.5 in the y
582 * position, and 1.7 in the message time, making
583 * 5.7 bits of unpredictability per mouse movement.
584 * However, other people have told me it's far less
585 * than that, so I'm going to be stupidly cautious
586 * and knock that down to a nice round 2. With this
587 * method, we require two words per mouse movement,
588 * so with 2 bits per mouse movement we expect 2
589 * bits every 2 words.
591 state
->entropy_required
= (state
->keysize
/2) * 2;
592 state
->entropy_got
= 0;
593 state
->entropy_size
= (state
->entropy_required
*
594 sizeof(*state
->entropy
));
595 state
->entropy
= smalloc(state
->entropy_size
);
597 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETRANGE
, 0,
598 MAKELPARAM(0, state
->entropy_required
));
599 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
, 0, 0);
603 state
= (struct MainDlgState
*)GetWindowLong(hwnd
, GWL_USERDATA
);
604 if (state
->key_exists
) {
605 char filename
[FILENAME_MAX
];
606 char passphrase
[PASSPHRASE_MAXLEN
];
607 char passphrase2
[PASSPHRASE_MAXLEN
];
608 GetDlgItemText(hwnd
, IDC_PASSPHRASE1EDIT
,
609 passphrase
, sizeof(passphrase
));
610 GetDlgItemText(hwnd
, IDC_PASSPHRASE2EDIT
,
611 passphrase2
, sizeof(passphrase2
));
612 if (strcmp(passphrase
, passphrase2
)) {
614 "The two passphrases given do not match.",
616 MB_OK
| MB_ICONERROR
);
621 ret
= MessageBox(hwnd
,
622 "Are you sure you want to save this key\n"
623 "without a passphrase to protect it?",
625 MB_YESNO
| MB_ICONWARNING
);
629 if (prompt_keyfile(hwnd
, "Save private key as:",
632 FILE *fp
= fopen(filename
, "r");
634 char buffer
[FILENAME_MAX
+80];
636 sprintf(buffer
, "Overwrite existing file\n%.*s?",
637 FILENAME_MAX
, filename
);
638 ret
= MessageBox(hwnd
, buffer
, "PuTTYgen Warning",
639 MB_YESNO
| MB_ICONWARNING
);
644 ret
= ssh2_save_userkey(filename
, &state
->ssh2key
,
645 *passphrase ? passphrase
: NULL
);
647 ret
= saversakey(filename
, &state
->key
,
648 *passphrase ? passphrase
: NULL
);
651 MessageBox(hwnd
, "Unable to save key file",
653 MB_OK
| MB_ICONERROR
);
659 state
= (struct MainDlgState
*)GetWindowLong(hwnd
, GWL_USERDATA
);
660 if (!state
->generation_thread_exists
) {
661 char filename
[FILENAME_MAX
];
662 if (prompt_keyfile(hwnd
, "Load private key:",
664 char passphrase
[PASSPHRASE_MAXLEN
];
669 struct PassphraseProcStruct pps
;
670 struct RSAKey newkey1
;
671 struct ssh2_userkey
*newkey2
;
673 ver
= keyfile_version(filename
);
675 MessageBox(NULL
, "Couldn't load private key.",
676 "PuTTYgen Error", MB_OK
| MB_ICONERROR
);
682 needs_pass
= rsakey_encrypted(filename
, &comment
);
684 needs_pass
= ssh2_userkey_encrypted(filename
, &comment
);
685 pps
.passphrase
= passphrase
;
686 pps
.comment
= comment
;
690 dlgret
= DialogBoxParam(hinst
,
691 MAKEINTRESOURCE(210),
692 NULL
, PassphraseProc
,
701 ret
= loadrsakey(filename
, &newkey1
, passphrase
);
703 newkey2
= ssh2_load_userkey(filename
, passphrase
);
704 if (newkey2
== SSH2_WRONG_PASSPHRASE
)
712 if (comment
) sfree(comment
);
714 MessageBox(NULL
, "Couldn't load private key.",
715 "PuTTYgen Error", MB_OK
| MB_ICONERROR
);
716 } else if (ret
== 1) {
717 EnableWindow(GetDlgItem(hwnd
, IDC_GENERATE
), 1);
718 EnableWindow(GetDlgItem(hwnd
, IDC_LOAD
), 1);
719 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 1);
721 * Now update the key controls with all the
725 SetDlgItemText(hwnd
, IDC_PASSPHRASE1EDIT
,
727 SetDlgItemText(hwnd
, IDC_PASSPHRASE2EDIT
,
734 state
->commentptr
= &state
->key
.comment
;
735 state
->key
= newkey1
;
738 * Set the key fingerprint.
740 savecomment
= state
->key
.comment
;
741 state
->key
.comment
= NULL
;
742 rsa_fingerprint(buf
, sizeof(buf
), &state
->key
);
743 state
->key
.comment
= savecomment
;
745 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, buf
);
747 * Construct a decimal representation
748 * of the key, for pasting into
749 * .ssh/authorized_keys on a Unix box.
751 setupbigedit1(hwnd
, IDC_KEYDISPLAY
, &state
->key
);
757 state
->commentptr
= &state
->ssh2key
.comment
;
758 state
->ssh2key
= *newkey2
; /* structure copy */
761 savecomment
= state
->ssh2key
.comment
;
762 state
->ssh2key
.comment
= NULL
;
764 ssh2key
.alg
->fingerprint(state
->ssh2key
.data
);
765 state
->ssh2key
.comment
= savecomment
;
767 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, fp
);
770 setupbigedit2(hwnd
, IDC_KEYDISPLAY
, &state
->ssh2key
);
772 SetDlgItemText(hwnd
, IDC_COMMENTEDIT
,
776 * Finally, hide the progress bar and show
779 hidemany(hwnd
, nokey_ids
, TRUE
);
780 hidemany(hwnd
, generating_ids
, TRUE
);
781 hidemany(hwnd
, gotkey_ids
, FALSE
);
782 state
->key_exists
= TRUE
;
790 state
= (struct MainDlgState
*)GetWindowLong(hwnd
, GWL_USERDATA
);
791 state
->generation_thread_exists
= FALSE
;
792 state
->key_exists
= TRUE
;
793 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
, PROGRESSRANGE
, 0);
794 EnableWindow(GetDlgItem(hwnd
, IDC_GENERATE
), 1);
795 EnableWindow(GetDlgItem(hwnd
, IDC_LOAD
), 1);
796 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 1);
798 state
->ssh2key
.data
= &state
->key
;
799 state
->ssh2key
.alg
= &ssh_rsa
;
800 state
->commentptr
= &state
->ssh2key
.comment
;
802 state
->commentptr
= &state
->key
.comment
;
805 * Invent a comment for the key. We'll do this by including
806 * the date in it. This will be so horrifyingly ugly that
807 * the user will immediately want to change it, which is
810 *state
->commentptr
= smalloc(30);
816 strftime(*state
->commentptr
, 30, "rsa-key-%Y%m%d", tm
);
820 * Now update the key controls with all the key data.
825 * Blank passphrase, initially. This isn't dangerous,
826 * because we will warn (Are You Sure?) before allowing
827 * the user to save an unprotected private key.
829 SetDlgItemText(hwnd
, IDC_PASSPHRASE1EDIT
, "");
830 SetDlgItemText(hwnd
, IDC_PASSPHRASE2EDIT
, "");
834 SetDlgItemText(hwnd
, IDC_COMMENTEDIT
, *state
->commentptr
);
836 * Set the key fingerprint.
838 savecomment
= *state
->commentptr
;
839 *state
->commentptr
= NULL
;
842 fp
= state
->ssh2key
.alg
->fingerprint(state
->ssh2key
.data
);
843 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, fp
);
847 rsa_fingerprint(buf
, sizeof(buf
), &state
->key
);
848 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, buf
);
850 *state
->commentptr
= savecomment
;
852 * Construct a decimal representation of the key, for
853 * pasting into .ssh/authorized_keys on a Unix box.
856 setupbigedit2(hwnd
, IDC_KEYDISPLAY
, &state
->ssh2key
);
858 setupbigedit1(hwnd
, IDC_KEYDISPLAY
, &state
->key
);
862 * Finally, hide the progress bar and show the key data.
864 hidemany(hwnd
, nokey_ids
, TRUE
);
865 hidemany(hwnd
, generating_ids
, TRUE
);
866 hidemany(hwnd
, gotkey_ids
, FALSE
);
869 state
= (struct MainDlgState
*)GetWindowLong(hwnd
, GWL_USERDATA
);
877 int WINAPI
WinMain(HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
) {
878 InitCommonControls();
881 return DialogBox(hinst
, MAKEINTRESOURCE(201), NULL
, MainDlgProc
) != IDOK
;