1
- /* $OpenBSD: ssh.c,v 1.575 2022/07/01 00:36:30 djm Exp $ */
1
+ /* $OpenBSD: ssh.c,v 1.576 2022/09/17 10:33:18 djm Exp $ */
2
2
/*
3
3
* Author: Tatu Ylonen <[email protected] >
4
4
* Copyright (c) 1995 Tatu Ylonen <[email protected] >, Espoo, Finland
@@ -516,14 +516,22 @@ resolve_canonicalize(char **hostp, int port)
516
516
}
517
517
518
518
/*
519
- * Check the result of hostkey loading, ignoring some errors and
520
- * fatal()ing for others.
519
+ * Check the result of hostkey loading, ignoring some errors and either
520
+ * discarding the key or fatal()ing for others.
521
521
*/
522
522
static void
523
- check_load (int r , const char * path , const char * message )
523
+ check_load (int r , struct sshkey * * k , const char * path , const char * message )
524
524
{
525
525
switch (r ) {
526
526
case 0 :
527
+ /* Check RSA keys size and discard if undersized */
528
+ if (k != NULL && * k != NULL &&
529
+ (r = sshkey_check_rsa_length (* k ,
530
+ options .required_rsa_size )) != 0 ) {
531
+ error_r (r , "load %s \"%s\"" , message , path );
532
+ free (* k );
533
+ * k = NULL ;
534
+ }
527
535
break ;
528
536
case SSH_ERR_INTERNAL_ERROR :
529
537
case SSH_ERR_ALLOC_FAIL :
@@ -1578,15 +1586,16 @@ main(int ac, char **av)
1578
1586
if ((o) >= sensitive_data.nkeys) \
1579
1587
fatal_f("pubkey out of array bounds"); \
1580
1588
check_load(sshkey_load_public(p, &(sensitive_data.keys[o]), NULL), \
1581
- p, "pubkey"); \
1589
+ &(sensitive_data.keys[o]), p, "pubkey"); \
1582
1590
if (sensitive_data.keys[o] != NULL) \
1583
1591
debug2("hostbased key %d: %s key from \"%s\"", o, \
1584
1592
sshkey_ssh_name(sensitive_data.keys[o]), p); \
1585
1593
} while (0)
1586
1594
#define L_CERT (p ,o ) do { \
1587
1595
if ((o) >= sensitive_data.nkeys) \
1588
1596
fatal_f("cert out of array bounds"); \
1589
- check_load(sshkey_load_cert(p, &(sensitive_data.keys[o])), p, "cert"); \
1597
+ check_load(sshkey_load_cert(p, &(sensitive_data.keys[o])), \
1598
+ &(sensitive_data.keys[o]), p, "cert"); \
1590
1599
if (sensitive_data.keys[o] != NULL) \
1591
1600
debug2("hostbased key %d: %s cert from \"%s\"", o, \
1592
1601
sshkey_ssh_name(sensitive_data.keys[o]), p); \
@@ -2265,7 +2274,7 @@ load_public_identity_files(const struct ssh_conn_info *cinfo)
2265
2274
filename = default_client_percent_dollar_expand (cp , cinfo );
2266
2275
free (cp );
2267
2276
check_load (sshkey_load_public (filename , & public , NULL ),
2268
- filename , "pubkey" );
2277
+ & public , filename , "pubkey" );
2269
2278
debug ("identity file %s type %d" , filename ,
2270
2279
public ? public -> type : -1 );
2271
2280
free (options .identity_files [i ]);
@@ -2284,7 +2293,7 @@ load_public_identity_files(const struct ssh_conn_info *cinfo)
2284
2293
continue ;
2285
2294
xasprintf (& cp , "%s-cert" , filename );
2286
2295
check_load (sshkey_load_public (cp , & public , NULL ),
2287
- filename , "pubkey" );
2296
+ & public , filename , "pubkey" );
2288
2297
debug ("identity file %s type %d" , cp ,
2289
2298
public ? public -> type : -1 );
2290
2299
if (public == NULL ) {
@@ -2315,7 +2324,7 @@ load_public_identity_files(const struct ssh_conn_info *cinfo)
2315
2324
free (cp );
2316
2325
2317
2326
check_load (sshkey_load_public (filename , & public , NULL ),
2318
- filename , "certificate" );
2327
+ & public , filename , "certificate" );
2319
2328
debug ("certificate file %s type %d" , filename ,
2320
2329
public ? public -> type : -1 );
2321
2330
free (options .certificate_files [i ]);
0 commit comments