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
)
43 struct progress
*p
= (struct progress
*) param
;
44 unsigned progress
= iprogress
;
49 p
->phase1param
= 0x10000 + progress
;
50 p
->phase1current
= 0x10000;
54 p
->phase2param
= 0x10000 + progress
;
55 p
->phase2current
= 0x10000;
59 p
->phase3mult
= PHASE3TOTAL
/ progress
;
62 while (p
->phase1n
< progress
) {
64 p
->phase1current
*= p
->phase1param
;
65 p
->phase1current
/= 0x10000;
67 position
= PHASE1START
+ 0x10000 - p
->phase1current
;
70 while (p
->phase2n
< progress
) {
72 p
->phase2current
*= p
->phase2param
;
73 p
->phase2current
/= 0x10000;
75 position
= PHASE2START
+ 0x10000 - p
->phase2current
;
78 position
= PHASE3START
+ progress
* p
->phase3mult
;
82 * Shouldn't happen, but having a default clause placates
83 * gcc -Wall, which would otherwise complain that
84 * `position' might be used uninitialised.
89 SendMessage(p
->progbar
, PBM_SETPOS
, position
/ DIVISOR
, 0);
94 #define PASSPHRASE_MAXLEN 512
96 struct PassphraseProcStruct
{
102 * Dialog-box function for the passphrase box.
104 static int CALLBACK
PassphraseProc(HWND hwnd
, UINT msg
,
105 WPARAM wParam
, LPARAM lParam
)
107 static char *passphrase
= NULL
;
108 struct PassphraseProcStruct
*p
;
112 SetForegroundWindow(hwnd
);
113 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0,
114 SWP_NOMOVE
| SWP_NOSIZE
| SWP_SHOWWINDOW
);
119 { /* centre the window */
123 hw
= GetDesktopWindow();
124 if (GetWindowRect(hw
, &rs
) && GetWindowRect(hwnd
, &rd
))
126 (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
) / 2,
127 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
) / 2,
128 rd
.right
- rd
.left
, rd
.bottom
- rd
.top
, TRUE
);
131 p
= (struct PassphraseProcStruct
*) lParam
;
132 passphrase
= p
->passphrase
;
134 SetDlgItemText(hwnd
, 101, p
->comment
);
136 SetDlgItemText(hwnd
, 102, passphrase
);
139 switch (LOWORD(wParam
)) {
149 case 102: /* edit box */
150 if ((HIWORD(wParam
) == EN_CHANGE
) && passphrase
) {
151 GetDlgItemText(hwnd
, 102, passphrase
,
152 PASSPHRASE_MAXLEN
- 1);
153 passphrase
[PASSPHRASE_MAXLEN
- 1] = '\0';
166 * Prompt for a key file. Assumes the filename buffer is of size
169 static int prompt_keyfile(HWND hwnd
, char *dlgtitle
,
170 char *filename
, int save
)
173 memset(&of
, 0, sizeof(of
));
174 #ifdef OPENFILENAME_SIZE_VERSION_400
175 of
.lStructSize
= OPENFILENAME_SIZE_VERSION_400
;
177 of
.lStructSize
= sizeof(of
);
180 of
.lpstrFilter
= "All Files\0*\0\0\0";
181 of
.lpstrCustomFilter
= NULL
;
183 of
.lpstrFile
= filename
;
185 of
.nMaxFile
= FILENAME_MAX
;
186 of
.lpstrFileTitle
= NULL
;
187 of
.lpstrInitialDir
= NULL
;
188 of
.lpstrTitle
= dlgtitle
;
191 return GetSaveFileName(&of
);
193 return GetOpenFileName(&of
);
197 * This function is needed to link with the DES code. We need not
198 * have it do anything at all.
200 void logevent(char *msg
)
205 * Dialog-box function for the Licence box.
207 static int CALLBACK
LicenceProc(HWND hwnd
, UINT msg
,
208 WPARAM wParam
, LPARAM lParam
)
215 { /* centre the window */
219 hw
= GetDesktopWindow();
220 if (GetWindowRect(hw
, &rs
) && GetWindowRect(hwnd
, &rd
))
222 (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
) / 2,
223 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
) / 2,
224 rd
.right
- rd
.left
, rd
.bottom
- rd
.top
, TRUE
);
229 switch (LOWORD(wParam
)) {
243 * Dialog-box function for the About box.
245 static int CALLBACK
AboutProc(HWND hwnd
, UINT msg
,
246 WPARAM wParam
, LPARAM lParam
)
253 { /* centre the window */
257 hw
= GetDesktopWindow();
258 if (GetWindowRect(hw
, &rs
) && GetWindowRect(hwnd
, &rd
))
260 (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
) / 2,
261 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
) / 2,
262 rd
.right
- rd
.left
, rd
.bottom
- rd
.top
, TRUE
);
265 SetDlgItemText(hwnd
, 100, ver
);
268 switch (LOWORD(wParam
)) {
273 EnableWindow(hwnd
, 0);
274 DialogBox(hinst
, MAKEINTRESOURCE(214), NULL
, LicenceProc
);
275 EnableWindow(hwnd
, 1);
276 SetActiveWindow(hwnd
);
288 * Thread to generate a key.
290 struct rsa_key_thread_params
{
291 HWND progressbar
; /* notify this with progress */
292 HWND dialog
; /* notify this on completion */
293 int keysize
; /* bits in key */
296 static DWORD WINAPI
generate_rsa_key_thread(void *param
)
298 struct rsa_key_thread_params
*params
=
299 (struct rsa_key_thread_params
*) param
;
300 struct progress prog
;
301 prog
.progbar
= params
->progressbar
;
303 rsa_generate(params
->key
, params
->keysize
, progress_update
, &prog
);
305 PostMessage(params
->dialog
, WM_DONEKEY
, 0, 0);
311 struct MainDlgState
{
312 int collecting_entropy
;
313 int generation_thread_exists
;
315 int entropy_got
, entropy_required
, entropy_size
;
318 char **commentptr
; /* points to key.comment or ssh2key.comment */
319 struct ssh2_userkey ssh2key
;
324 static void hidemany(HWND hwnd
, const int *ids
, int hideit
)
327 ShowWindow(GetDlgItem(hwnd
, *ids
++), (hideit ? SW_HIDE
: SW_SHOW
));
331 static void setupbigedit1(HWND hwnd
, int id
, struct RSAKey
*key
)
336 dec1
= bignum_decimal(key
->exponent
);
337 dec2
= bignum_decimal(key
->modulus
);
338 buffer
= smalloc(strlen(dec1
) + strlen(dec2
) +
339 strlen(key
->comment
) + 30);
340 sprintf(buffer
, "%d %s %s %s",
341 bignum_bitcount(key
->modulus
), dec1
, dec2
, key
->comment
);
342 SetDlgItemText(hwnd
, id
, buffer
);
348 static void setupbigedit2(HWND hwnd
, int id
, struct ssh2_userkey
*key
)
350 unsigned char *pub_blob
;
355 pub_blob
= key
->alg
->public_blob(key
->data
, &pub_len
);
356 buffer
= smalloc(strlen(key
->alg
->name
) + 4 * ((pub_len
+ 2) / 3) +
357 strlen(key
->comment
) + 3);
358 strcpy(buffer
, key
->alg
->name
);
359 p
= buffer
+ strlen(buffer
);
362 while (i
< pub_len
) {
363 int n
= (pub_len
- i
< 3 ? pub_len
- i
: 3);
364 base64_encode_atom(pub_blob
+ i
, n
, p
);
369 strcpy(p
, key
->comment
);
370 SetDlgItemText(hwnd
, id
, buffer
);
376 * Dialog-box function for the main PuTTYgen dialog box.
378 static int CALLBACK
MainDlgProc(HWND hwnd
, UINT msg
,
379 WPARAM wParam
, LPARAM lParam
)
382 controlidstart
= 100,
388 IDC_PKSTATIC
, IDC_KEYDISPLAY
,
389 IDC_FPSTATIC
, IDC_FINGERPRINT
,
390 IDC_COMMENTSTATIC
, IDC_COMMENTEDIT
,
391 IDC_PASSPHRASE1STATIC
, IDC_PASSPHRASE1EDIT
,
392 IDC_PASSPHRASE2STATIC
, IDC_PASSPHRASE2EDIT
,
394 IDC_GENSTATIC
, IDC_GENERATE
,
395 IDC_LOADSTATIC
, IDC_LOAD
,
396 IDC_SAVESTATIC
, IDC_SAVE
,
398 IDC_TYPESTATIC
, IDC_KEYSSH1
, IDC_KEYSSH2RSA
,
399 IDC_BITSSTATIC
, IDC_BITS
,
402 static const int nokey_ids
[] = { IDC_NOKEY
, 0 };
403 static const int generating_ids
[] =
404 { IDC_GENERATING
, IDC_PROGRESS
, 0 };
405 static const int gotkey_ids
[] = {
406 IDC_PKSTATIC
, IDC_KEYDISPLAY
,
407 IDC_FPSTATIC
, IDC_FINGERPRINT
,
408 IDC_COMMENTSTATIC
, IDC_COMMENTEDIT
,
409 IDC_PASSPHRASE1STATIC
, IDC_PASSPHRASE1EDIT
,
410 IDC_PASSPHRASE2STATIC
, IDC_PASSPHRASE2EDIT
, 0
412 static const char generating_msg
[] =
413 "Please wait while a key is generated...";
414 static const char entropy_msg
[] =
415 "Please generate some randomness by moving the mouse over the blank area.";
416 struct MainDlgState
*state
;
423 { /* centre the window */
427 hw
= GetDesktopWindow();
428 if (GetWindowRect(hw
, &rs
) && GetWindowRect(hwnd
, &rd
))
430 (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
) / 2,
431 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
) / 2,
432 rd
.right
- rd
.left
, rd
.bottom
- rd
.top
, TRUE
);
435 state
= smalloc(sizeof(*state
));
436 state
->generation_thread_exists
= FALSE
;
437 state
->collecting_entropy
= FALSE
;
438 state
->entropy
= NULL
;
439 state
->key_exists
= FALSE
;
440 SetWindowLong(hwnd
, GWL_USERDATA
, (LONG
) state
);
442 struct ctlpos cp
, cp2
;
444 /* Accelerators used: acglops */
446 ctlposinit(&cp
, hwnd
, 10, 10, 10);
447 bartitle(&cp
, "Public and private key generation for PuTTY",
449 beginbox(&cp
, "Key", IDC_BOX_KEY
);
451 statictext(&cp2
, "No key.", IDC_NOKEY
);
453 statictext(&cp2
, "", IDC_GENERATING
);
454 progressbar(&cp2
, IDC_PROGRESS
);
456 "&Public key for pasting into authorized_keys file:",
457 IDC_PKSTATIC
, IDC_KEYDISPLAY
, 7);
458 SendDlgItemMessage(hwnd
, IDC_KEYDISPLAY
, EM_SETREADONLY
, 1, 0);
459 staticedit(&cp
, "Key fingerprint:", IDC_FPSTATIC
,
460 IDC_FINGERPRINT
, 75);
461 SendDlgItemMessage(hwnd
, IDC_FINGERPRINT
, EM_SETREADONLY
, 1,
463 staticedit(&cp
, "Key &comment:", IDC_COMMENTSTATIC
,
464 IDC_COMMENTEDIT
, 75);
465 staticpassedit(&cp
, "Key p&assphrase:", IDC_PASSPHRASE1STATIC
,
466 IDC_PASSPHRASE1EDIT
, 75);
467 staticpassedit(&cp
, "C&onfirm passphrase:",
468 IDC_PASSPHRASE2STATIC
, IDC_PASSPHRASE2EDIT
, 75);
470 beginbox(&cp
, "Actions", IDC_BOX_ACTIONS
);
471 staticbtn(&cp
, "Generate a public/private key pair",
472 IDC_GENSTATIC
, "&Generate", IDC_GENERATE
);
473 staticbtn(&cp
, "Load an existing private key file",
474 IDC_LOADSTATIC
, "&Load", IDC_LOAD
);
475 staticbtn(&cp
, "Save the generated key to a new file",
476 IDC_SAVESTATIC
, "&Save", IDC_SAVE
);
478 beginbox(&cp
, "Parameters", IDC_BOX_PARAMS
);
479 radioline(&cp
, "Type of key to generate:", IDC_TYPESTATIC
, 2,
480 "SSH&1 (RSA)", IDC_KEYSSH1
,
481 "SSH2 &RSA", IDC_KEYSSH2RSA
, NULL
);
482 staticedit(&cp
, "Number of &bits in a generated key:",
483 IDC_BITSSTATIC
, IDC_BITS
, 20);
486 CheckRadioButton(hwnd
, IDC_KEYSSH1
, IDC_KEYSSH2RSA
, IDC_KEYSSH1
);
487 SetDlgItemInt(hwnd
, IDC_BITS
, DEFAULT_KEYSIZE
, FALSE
);
490 * Initially, hide the progress bar and the key display,
491 * and show the no-key display. Also disable the Save
492 * button, because with no key we obviously can't save
495 hidemany(hwnd
, nokey_ids
, FALSE
);
496 hidemany(hwnd
, generating_ids
, TRUE
);
497 hidemany(hwnd
, gotkey_ids
, TRUE
);
498 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 0);
502 state
= (struct MainDlgState
*) GetWindowLong(hwnd
, GWL_USERDATA
);
503 if (state
->collecting_entropy
&&
504 state
->entropy
&& state
->entropy_got
< state
->entropy_required
) {
505 state
->entropy
[state
->entropy_got
++] = lParam
;
506 state
->entropy
[state
->entropy_got
++] = GetMessageTime();
507 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
,
508 state
->entropy_got
, 0);
509 if (state
->entropy_got
>= state
->entropy_required
) {
510 struct rsa_key_thread_params
*params
;
514 * Seed the entropy pool
516 random_add_heavynoise(state
->entropy
, state
->entropy_size
);
517 memset(state
->entropy
, 0, state
->entropy_size
);
518 sfree(state
->entropy
);
519 state
->collecting_entropy
= FALSE
;
521 SetDlgItemText(hwnd
, IDC_GENERATING
, generating_msg
);
522 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETRANGE
, 0,
523 MAKELPARAM(0, PROGRESSRANGE
));
524 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
, 0, 0);
526 params
= smalloc(sizeof(*params
));
527 params
->progressbar
= GetDlgItem(hwnd
, IDC_PROGRESS
);
528 params
->dialog
= hwnd
;
529 params
->keysize
= state
->keysize
;
530 params
->key
= &state
->key
;
532 if (!CreateThread(NULL
, 0, generate_rsa_key_thread
,
533 params
, 0, &threadid
)) {
534 MessageBox(hwnd
, "Out of thread resources",
535 "Key generation error",
536 MB_OK
| MB_ICONERROR
);
539 state
->generation_thread_exists
= TRUE
;
545 switch (LOWORD(wParam
)) {
546 case IDC_COMMENTEDIT
:
547 if (HIWORD(wParam
) == EN_CHANGE
) {
548 state
= (struct MainDlgState
*)
549 GetWindowLong(hwnd
, GWL_USERDATA
);
550 if (state
->key_exists
) {
551 HWND editctl
= GetDlgItem(hwnd
, IDC_COMMENTEDIT
);
552 int len
= GetWindowTextLength(editctl
);
553 if (*state
->commentptr
)
554 sfree(*state
->commentptr
);
555 *state
->commentptr
= smalloc(len
+ 1);
556 GetWindowText(editctl
, *state
->commentptr
, len
+ 1);
558 setupbigedit2(hwnd
, IDC_KEYDISPLAY
,
561 setupbigedit1(hwnd
, IDC_KEYDISPLAY
, &state
->key
);
567 EnableWindow(hwnd
, 0);
568 DialogBox(hinst
, MAKEINTRESOURCE(213), NULL
, AboutProc
);
569 EnableWindow(hwnd
, 1);
570 SetActiveWindow(hwnd
);
574 (struct MainDlgState
*) GetWindowLong(hwnd
, GWL_USERDATA
);
575 if (!state
->generation_thread_exists
) {
577 state
->keysize
= GetDlgItemInt(hwnd
, IDC_BITS
, &ok
, FALSE
);
579 state
->keysize
= DEFAULT_KEYSIZE
;
580 /* If we ever introduce a new key type, check it here! */
581 state
->ssh2
= !IsDlgButtonChecked(hwnd
, IDC_KEYSSH1
);
582 if (state
->keysize
< 256) {
583 int ret
= MessageBox(hwnd
,
584 "PuTTYgen will not generate a key"
585 " smaller than 256 bits.\n"
586 "Key length reset to 256. Continue?",
588 MB_ICONWARNING
| MB_OKCANCEL
);
591 state
->keysize
= 256;
592 SetDlgItemInt(hwnd
, IDC_BITS
, 256, FALSE
);
594 hidemany(hwnd
, nokey_ids
, TRUE
);
595 hidemany(hwnd
, generating_ids
, FALSE
);
596 hidemany(hwnd
, gotkey_ids
, TRUE
);
597 EnableWindow(GetDlgItem(hwnd
, IDC_GENERATE
), 0);
598 EnableWindow(GetDlgItem(hwnd
, IDC_LOAD
), 0);
599 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 0);
600 state
->key_exists
= FALSE
;
601 SetDlgItemText(hwnd
, IDC_GENERATING
, entropy_msg
);
602 state
->collecting_entropy
= TRUE
;
605 * My brief statistical tests on mouse movements
606 * suggest that there are about 2.5 bits of
607 * randomness in the x position, 2.5 in the y
608 * position, and 1.7 in the message time, making
609 * 5.7 bits of unpredictability per mouse movement.
610 * However, other people have told me it's far less
611 * than that, so I'm going to be stupidly cautious
612 * and knock that down to a nice round 2. With this
613 * method, we require two words per mouse movement,
614 * so with 2 bits per mouse movement we expect 2
615 * bits every 2 words.
617 state
->entropy_required
= (state
->keysize
/ 2) * 2;
618 state
->entropy_got
= 0;
619 state
->entropy_size
= (state
->entropy_required
*
620 sizeof(*state
->entropy
));
621 state
->entropy
= smalloc(state
->entropy_size
);
623 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETRANGE
, 0,
624 MAKELPARAM(0, state
->entropy_required
));
625 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
, 0, 0);
630 (struct MainDlgState
*) GetWindowLong(hwnd
, GWL_USERDATA
);
631 if (state
->key_exists
) {
632 char filename
[FILENAME_MAX
];
633 char passphrase
[PASSPHRASE_MAXLEN
];
634 char passphrase2
[PASSPHRASE_MAXLEN
];
635 GetDlgItemText(hwnd
, IDC_PASSPHRASE1EDIT
,
636 passphrase
, sizeof(passphrase
));
637 GetDlgItemText(hwnd
, IDC_PASSPHRASE2EDIT
,
638 passphrase2
, sizeof(passphrase2
));
639 if (strcmp(passphrase
, passphrase2
)) {
641 "The two passphrases given do not match.",
642 "PuTTYgen Error", MB_OK
| MB_ICONERROR
);
647 ret
= MessageBox(hwnd
,
648 "Are you sure you want to save this key\n"
649 "without a passphrase to protect it?",
651 MB_YESNO
| MB_ICONWARNING
);
655 if (prompt_keyfile(hwnd
, "Save private key as:",
658 FILE *fp
= fopen(filename
, "r");
660 char buffer
[FILENAME_MAX
+ 80];
662 sprintf(buffer
, "Overwrite existing file\n%.*s?",
663 FILENAME_MAX
, filename
);
664 ret
= MessageBox(hwnd
, buffer
, "PuTTYgen Warning",
665 MB_YESNO
| MB_ICONWARNING
);
670 ret
= ssh2_save_userkey(filename
, &state
->ssh2key
,
671 *passphrase ? passphrase
:
674 ret
= saversakey(filename
, &state
->key
,
675 *passphrase ? passphrase
: NULL
);
678 MessageBox(hwnd
, "Unable to save key file",
679 "PuTTYgen Error", MB_OK
| MB_ICONERROR
);
686 (struct MainDlgState
*) GetWindowLong(hwnd
, GWL_USERDATA
);
687 if (!state
->generation_thread_exists
) {
688 char filename
[FILENAME_MAX
];
689 if (prompt_keyfile(hwnd
, "Load private key:", filename
, 0)) {
690 char passphrase
[PASSPHRASE_MAXLEN
];
695 struct PassphraseProcStruct pps
;
696 struct RSAKey newkey1
;
697 struct ssh2_userkey
*newkey2
= NULL
;
699 ver
= keyfile_version(filename
);
701 MessageBox(NULL
, "Couldn't load private key.",
702 "PuTTYgen Error", MB_OK
| MB_ICONERROR
);
708 needs_pass
= rsakey_encrypted(filename
, &comment
);
711 ssh2_userkey_encrypted(filename
, &comment
);
712 pps
.passphrase
= passphrase
;
713 pps
.comment
= comment
;
717 dlgret
= DialogBoxParam(hinst
,
718 MAKEINTRESOURCE(210),
719 NULL
, PassphraseProc
,
729 loadrsakey(filename
, &newkey1
, passphrase
);
732 ssh2_load_userkey(filename
, passphrase
);
733 if (newkey2
== SSH2_WRONG_PASSPHRASE
)
744 MessageBox(NULL
, "Couldn't load private key.",
745 "PuTTYgen Error", MB_OK
| MB_ICONERROR
);
746 } else if (ret
== 1) {
747 EnableWindow(GetDlgItem(hwnd
, IDC_GENERATE
), 1);
748 EnableWindow(GetDlgItem(hwnd
, IDC_LOAD
), 1);
749 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 1);
751 * Now update the key controls with all the
755 SetDlgItemText(hwnd
, IDC_PASSPHRASE1EDIT
,
757 SetDlgItemText(hwnd
, IDC_PASSPHRASE2EDIT
,
764 state
->commentptr
= &state
->key
.comment
;
765 state
->key
= newkey1
;
768 * Set the key fingerprint.
770 savecomment
= state
->key
.comment
;
771 state
->key
.comment
= NULL
;
772 rsa_fingerprint(buf
, sizeof(buf
),
774 state
->key
.comment
= savecomment
;
776 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, buf
);
778 * Construct a decimal representation
779 * of the key, for pasting into
780 * .ssh/authorized_keys on a Unix box.
782 setupbigedit1(hwnd
, IDC_KEYDISPLAY
,
790 &state
->ssh2key
.comment
;
791 state
->ssh2key
= *newkey2
; /* structure copy */
794 savecomment
= state
->ssh2key
.comment
;
795 state
->ssh2key
.comment
= NULL
;
798 fingerprint(state
->ssh2key
.data
);
799 state
->ssh2key
.comment
= savecomment
;
801 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, fp
);
804 setupbigedit2(hwnd
, IDC_KEYDISPLAY
,
807 SetDlgItemText(hwnd
, IDC_COMMENTEDIT
,
811 * Finally, hide the progress bar and show
814 hidemany(hwnd
, nokey_ids
, TRUE
);
815 hidemany(hwnd
, generating_ids
, TRUE
);
816 hidemany(hwnd
, gotkey_ids
, FALSE
);
817 state
->key_exists
= TRUE
;
825 state
= (struct MainDlgState
*) GetWindowLong(hwnd
, GWL_USERDATA
);
826 state
->generation_thread_exists
= FALSE
;
827 state
->key_exists
= TRUE
;
828 SendDlgItemMessage(hwnd
, IDC_PROGRESS
, PBM_SETPOS
, PROGRESSRANGE
,
830 EnableWindow(GetDlgItem(hwnd
, IDC_GENERATE
), 1);
831 EnableWindow(GetDlgItem(hwnd
, IDC_LOAD
), 1);
832 EnableWindow(GetDlgItem(hwnd
, IDC_SAVE
), 1);
834 state
->ssh2key
.data
= &state
->key
;
835 state
->ssh2key
.alg
= &ssh_rsa
;
836 state
->commentptr
= &state
->ssh2key
.comment
;
838 state
->commentptr
= &state
->key
.comment
;
841 * Invent a comment for the key. We'll do this by including
842 * the date in it. This will be so horrifyingly ugly that
843 * the user will immediately want to change it, which is
846 *state
->commentptr
= smalloc(30);
852 strftime(*state
->commentptr
, 30, "rsa-key-%Y%m%d", tm
);
856 * Now update the key controls with all the key data.
861 * Blank passphrase, initially. This isn't dangerous,
862 * because we will warn (Are You Sure?) before allowing
863 * the user to save an unprotected private key.
865 SetDlgItemText(hwnd
, IDC_PASSPHRASE1EDIT
, "");
866 SetDlgItemText(hwnd
, IDC_PASSPHRASE2EDIT
, "");
870 SetDlgItemText(hwnd
, IDC_COMMENTEDIT
, *state
->commentptr
);
872 * Set the key fingerprint.
874 savecomment
= *state
->commentptr
;
875 *state
->commentptr
= NULL
;
878 fp
= state
->ssh2key
.alg
->fingerprint(state
->ssh2key
.data
);
879 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, fp
);
883 rsa_fingerprint(buf
, sizeof(buf
), &state
->key
);
884 SetDlgItemText(hwnd
, IDC_FINGERPRINT
, buf
);
886 *state
->commentptr
= savecomment
;
888 * Construct a decimal representation of the key, for
889 * pasting into .ssh/authorized_keys on a Unix box.
892 setupbigedit2(hwnd
, IDC_KEYDISPLAY
, &state
->ssh2key
);
894 setupbigedit1(hwnd
, IDC_KEYDISPLAY
, &state
->key
);
898 * Finally, hide the progress bar and show the key data.
900 hidemany(hwnd
, nokey_ids
, TRUE
);
901 hidemany(hwnd
, generating_ids
, TRUE
);
902 hidemany(hwnd
, gotkey_ids
, FALSE
);
905 state
= (struct MainDlgState
*) GetWindowLong(hwnd
, GWL_USERDATA
);
913 int WINAPI
WinMain(HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
)
915 InitCommonControls();
918 return DialogBox(hinst
, MAKEINTRESOURCE(201), NULL
,
919 MainDlgProc
) != IDOK
;