mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
Refactoring to prepare for extra public key types.
The OpenSSH key importer and exporter were structured in the assumption that the strong commonality of format between OpenSSH RSA and DSA keys would persist across all key types. Moved code around so it's now clear that this is a peculiarity of those _particular_ two key types which will not apply to others we add alongside them. Also, a boolean 'is_dsa' in winpgen.c has been converted into a more sensible key type enumeration, and the individually typed key pointers have been piled on top of each other in a union. This is a pure refactoring change which should have no functional effect.
This commit is contained in:

committed by
Simon Tatham

parent
a2b64dca47
commit
df0ac30d46
@ -315,6 +315,8 @@ static int CALLBACK AboutProc(HWND hwnd, UINT msg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef enum {RSA, DSA, ECDSA} keytype;
|
||||
|
||||
/*
|
||||
* Thread to generate a key.
|
||||
*/
|
||||
@ -322,9 +324,11 @@ struct rsa_key_thread_params {
|
||||
HWND progressbar; /* notify this with progress */
|
||||
HWND dialog; /* notify this on completion */
|
||||
int keysize; /* bits in key */
|
||||
int is_dsa;
|
||||
struct RSAKey *key;
|
||||
struct dss_key *dsskey;
|
||||
keytype keytype;
|
||||
union {
|
||||
struct RSAKey *key;
|
||||
struct dss_key *dsskey;
|
||||
};
|
||||
};
|
||||
static DWORD WINAPI generate_rsa_key_thread(void *param)
|
||||
{
|
||||
@ -335,7 +339,7 @@ static DWORD WINAPI generate_rsa_key_thread(void *param)
|
||||
|
||||
progress_update(&prog, PROGFN_INITIALISE, 0, 0);
|
||||
|
||||
if (params->is_dsa)
|
||||
if (params->keytype == DSA)
|
||||
dsa_generate(params->dsskey, params->keysize, progress_update, &prog);
|
||||
else
|
||||
rsa_generate(params->key, params->keysize, progress_update, &prog);
|
||||
@ -352,12 +356,15 @@ struct MainDlgState {
|
||||
int key_exists;
|
||||
int entropy_got, entropy_required, entropy_size;
|
||||
int keysize;
|
||||
int ssh2, is_dsa;
|
||||
int ssh2;
|
||||
keytype keytype;
|
||||
char **commentptr; /* points to key.comment or ssh2key.comment */
|
||||
struct ssh2_userkey ssh2key;
|
||||
unsigned *entropy;
|
||||
struct RSAKey key;
|
||||
struct dss_key dsskey;
|
||||
union {
|
||||
struct RSAKey key;
|
||||
struct dss_key dsskey;
|
||||
};
|
||||
HMENU filemenu, keymenu, cvtmenu;
|
||||
};
|
||||
|
||||
@ -990,7 +997,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
params->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
|
||||
params->dialog = hwnd;
|
||||
params->keysize = state->keysize;
|
||||
params->is_dsa = state->is_dsa;
|
||||
params->keytype = state->keytype;
|
||||
params->key = &state->key;
|
||||
params->dsskey = &state->dsskey;
|
||||
|
||||
@ -1070,7 +1077,10 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
state->keysize = DEFAULT_KEYSIZE;
|
||||
/* If we ever introduce a new key type, check it here! */
|
||||
state->ssh2 = !IsDlgButtonChecked(hwnd, IDC_KEYSSH1);
|
||||
state->is_dsa = IsDlgButtonChecked(hwnd, IDC_KEYSSH2DSA);
|
||||
state->keytype = RSA;
|
||||
if (IsDlgButtonChecked(hwnd, IDC_KEYSSH2DSA)) {
|
||||
state->keytype = DSA;
|
||||
}
|
||||
if (state->keysize < 256) {
|
||||
int ret = MessageBox(hwnd,
|
||||
"PuTTYgen will not generate a key"
|
||||
@ -1276,7 +1286,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
MAKELPARAM(0, PROGRESSRANGE));
|
||||
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, PROGRESSRANGE, 0);
|
||||
if (state->ssh2) {
|
||||
if (state->is_dsa) {
|
||||
if (state->keytype == DSA) {
|
||||
state->ssh2key.data = &state->dsskey;
|
||||
state->ssh2key.alg = &ssh_dss;
|
||||
} else {
|
||||
@ -1297,7 +1307,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
{
|
||||
struct tm tm;
|
||||
tm = ltime();
|
||||
if (state->is_dsa)
|
||||
if (state->keytype == DSA)
|
||||
strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", &tm);
|
||||
else
|
||||
strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", &tm);
|
||||
|
Reference in New Issue
Block a user