X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=puttygen.c;h=2d2d93355f625158605943b9810c268b18a6eee1;hb=030c75b7db19c25dd59aa8dc40bc906b737761ec;hp=e045c33563425b3ae36e2a234845cada1cc5605e;hpb=9a8c58a64bd9effebee2199d3757a0bcedac83e1;p=PuTTY.git diff --git a/puttygen.c b/puttygen.c index e045c335..2d2d9335 100644 --- a/puttygen.c +++ b/puttygen.c @@ -546,20 +546,16 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg, AppendMenu(menu, MF_POPUP | MF_ENABLED, (UINT) menu1, "&File"); -#if 0 - /* - * Exporting not yet supported, but when we do it we - * should just put this lot back in. - */ menu1 = CreateMenu(); AppendMenu(menu1, MF_ENABLED, IDC_EXPORT_OPENSSH, "Export &OpenSSH key"); +#if 0 AppendMenu(menu1, MF_ENABLED, IDC_EXPORT_SSHCOM, "Export &ssh.com key"); +#endif AppendMenu(menu, MF_POPUP | MF_ENABLED, (UINT) menu1, "&Export"); -#endif menu1 = CreateMenu(); AppendMenu(menu1, MF_ENABLED, IDC_ABOUT, "&About"); @@ -800,12 +796,39 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg, } break; case IDC_SAVE: + case IDC_EXPORT_OPENSSH: + case IDC_EXPORT_SSHCOM: state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA); if (state->key_exists) { char filename[FILENAME_MAX]; char passphrase[PASSPHRASE_MAXLEN]; char passphrase2[PASSPHRASE_MAXLEN]; + int type, realtype; + + if (state->ssh2) + realtype = SSH_KEYTYPE_SSH2; + else + realtype = SSH_KEYTYPE_SSH1; + + if (LOWORD(wParam) == IDC_EXPORT_OPENSSH) + type = SSH_KEYTYPE_OPENSSH; + else if (LOWORD(wParam) == IDC_EXPORT_SSHCOM) + type = SSH_KEYTYPE_SSHCOM; + else + type = realtype; + + if (type != realtype && + import_target_type(type) != realtype) { + char msg[256]; + sprintf(msg, "Cannot export an SSH%d key in an SSH%d" + " format", (state->ssh2 ? 2 : 1), + (state->ssh2 ? 1 : 2)); + MessageBox(hwnd, msg, + "PuTTYgen Error", MB_OK | MB_ICONERROR); + break; + } + GetDlgItemText(hwnd, IDC_PASSPHRASE1EDIT, passphrase, sizeof(passphrase)); GetDlgItemText(hwnd, IDC_PASSPHRASE2EDIT, @@ -840,13 +863,22 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg, if (ret != IDYES) break; } + if (state->ssh2) { - ret = ssh2_save_userkey(filename, &state->ssh2key, - *passphrase ? passphrase : - NULL); + if (type != realtype) + ret = export_ssh2(filename, type, &state->ssh2key, + *passphrase ? passphrase : NULL); + else + ret = ssh2_save_userkey(filename, &state->ssh2key, + *passphrase ? passphrase : + NULL); } else { - ret = saversakey(filename, &state->key, - *passphrase ? passphrase : NULL); + if (type != realtype) + ret = export_ssh1(filename, type, &state->key, + *passphrase ? passphrase : NULL); + else + ret = saversakey(filename, &state->key, + *passphrase ? passphrase : NULL); } if (ret <= 0) { MessageBox(hwnd, "Unable to save key file",