| 264 |
myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = buf; |
myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = buf; |
| 265 |
} |
} |
| 266 |
|
|
| 267 |
ssh_keyalgo choose_SSH2_keysign_algorithm(char *server_proposal, ssh_keytype keytype) |
static void SSH2_rsa_pubkey_sign_algo_myproposal(PTInstVar pvar, char *buf, int buf_len) |
| 268 |
|
{ |
| 269 |
|
int algo; |
| 270 |
|
int len, i; |
| 271 |
|
char *c_str; |
| 272 |
|
|
| 273 |
|
// 設定された優先順位に応じて buf に並べる |
| 274 |
|
buf[0] = '\0'; |
| 275 |
|
for (i = 0 ; pvar->settings.RSAPubkeySignAlgorithmOrder[i] != 0 ; i++) { |
| 276 |
|
algo = pvar->settings.RSAPubkeySignAlgorithmOrder[i] - '0'; |
| 277 |
|
if (algo == 0) // disabled line |
| 278 |
|
break; |
| 279 |
|
switch (algo) { |
| 280 |
|
case RSA_PUBKEY_SIGN_ALGO_RSA: |
| 281 |
|
c_str = "ssh-rsa,"; |
| 282 |
|
break; |
| 283 |
|
case RSA_PUBKEY_SIGN_ALGO_RSASHA256: |
| 284 |
|
c_str = "rsa-sha2-256,"; |
| 285 |
|
break; |
| 286 |
|
case RSA_PUBKEY_SIGN_ALGO_RSASHA512: |
| 287 |
|
c_str = "rsa-sha2-512,"; |
| 288 |
|
break; |
| 289 |
|
default: |
| 290 |
|
continue; |
| 291 |
|
} |
| 292 |
|
strncat_s(buf, buf_len, c_str, _TRUNCATE); |
| 293 |
|
} |
| 294 |
|
len = strlen(buf); |
| 295 |
|
if (len > 0) |
| 296 |
|
buf[len - 1] = '\0'; // get rid of comma |
| 297 |
|
} |
| 298 |
|
|
| 299 |
|
ssh_keyalgo choose_SSH2_keysign_algorithm(PTInstVar pvar, ssh_keytype keytype) |
| 300 |
{ |
{ |
| 301 |
char buff[128]; |
char buff[128]; |
| 302 |
const struct ssh2_host_key_t *ptr = ssh2_host_key; |
const struct ssh2_host_key_t *ptr = ssh2_host_key; |
| 303 |
|
char *server_proposal = pvar->server_sig_algs; |
| 304 |
|
|
| 305 |
if (keytype == KEY_RSA) { |
if (keytype == KEY_RSA) { |
| 306 |
if (server_proposal == NULL) { |
if (server_proposal == NULL) { |
| 308 |
return KEY_ALGO_RSA; |
return KEY_ALGO_RSA; |
| 309 |
} |
} |
| 310 |
else { |
else { |
| 311 |
choose_SSH2_proposal(server_proposal, "rsa-sha2-512,rsa-sha2-256,ssh-rsa", buff, sizeof(buff)); |
char rsa_myproposal[128]; |
| 312 |
|
SSH2_rsa_pubkey_sign_algo_myproposal(pvar, rsa_myproposal, sizeof(rsa_myproposal)); |
| 313 |
|
choose_SSH2_proposal(server_proposal, rsa_myproposal, buff, sizeof(buff)); |
| 314 |
if (strlen(buff) == 0) { |
if (strlen(buff) == 0) { |
| 315 |
// not found. |
// not found. |
| 316 |
logprintf(LOG_LEVEL_WARNING, "%s: no match sign algorithm.", __FUNCTION__); |
logprintf(LOG_LEVEL_WARNING, "%s: no match sign algorithm.", __FUNCTION__); |
| 333 |
// not reached |
// not reached |
| 334 |
return KEY_ALGO_UNSPEC; |
return KEY_ALGO_UNSPEC; |
| 335 |
} |
} |
| 336 |
|
|
| 337 |
|
void normalize_rsa_pubkey_sign_algo_order(char *buf) |
| 338 |
|
{ |
| 339 |
|
static char default_strings[] = { |
| 340 |
|
RSA_PUBKEY_SIGN_ALGO_RSASHA512, |
| 341 |
|
RSA_PUBKEY_SIGN_ALGO_RSASHA256, |
| 342 |
|
RSA_PUBKEY_SIGN_ALGO_RSA, |
| 343 |
|
RSA_PUBKEY_SIGN_ALGO_NONE, |
| 344 |
|
}; |
| 345 |
|
|
| 346 |
|
normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings)); |
| 347 |
|
} |
| 348 |
|
|
| 349 |
|
/* |
| 350 |
|
* ssh_keyalgo から、鍵に対して標準ではないダイジェスト方式名を返す |
| 351 |
|
* 今のところ rsa-sha2-256, rsa-sha2-512 のときだけ "SHA-256", "SHA-512" を返す |
| 352 |
|
* About ダイアログで、非標準のダイジェスト方式のときだけ表示するため |
| 353 |
|
*/ |
| 354 |
|
char* get_ssh2_hostkey_algorithm_digest_name(ssh_keyalgo algo) |
| 355 |
|
{ |
| 356 |
|
switch (algo) { |
| 357 |
|
case KEY_ALGO_RSASHA256: |
| 358 |
|
return "SHA-256"; |
| 359 |
|
case KEY_ALGO_RSASHA512: |
| 360 |
|
return "SHA-512"; |
| 361 |
|
} |
| 362 |
|
return ""; |
| 363 |
|
} |