Skip to content

Commit a4043da

Browse files
committed
Limit rekey to current hostkey type
During rekey dropbear process may be running with user privileges, that can't write a new hostkey when auto-generating keys. Only offer the original hostkey when rekeying, also for non-autogenerate case.
1 parent 73e4e70 commit a4043da

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/runopts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern runopts opts;
6161
int readhostkey(const char * filename, sign_key * hostkey,
6262
enum signkey_type *type);
6363
void load_all_hostkeys(void);
64+
void disable_sig_except(enum signature_type sig_type);
6465

6566
typedef struct svr_runopts {
6667

src/svr-kex.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ void recv_msg_kexdh_init() {
9999
}
100100
#endif
101101

102+
if (!ses.kexstate.donesecondkex) {
103+
/* Disable other signature types.
104+
* During future rekeying, privileges may have been dropped
105+
* so other keys won't be loadable.
106+
* This must occur after send_msg_ext_info() which uses the hostkey list */
107+
disable_sig_except(ses.newkeys->algo_signature);
108+
}
109+
102110
ses.requirenext = SSH_MSG_NEWKEYS;
103111
TRACE(("leave recv_msg_kexdh_init"))
104112
}

src/svr-runopts.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ static void disablekey(enum signature_type type) {
515515
}
516516
}
517517

518+
void disable_sig_except(enum signature_type allow_type) {
519+
int i;
520+
TRACE(("Disabling other sigs except %d", allow_type));
521+
for (i = 0; sigalgs[i].name != NULL; i++) {
522+
enum signature_type sig_type = sigalgs[i].val;
523+
if (sig_type != allow_type) {
524+
sigalgs[i].usable = 0;
525+
}
526+
}
527+
}
528+
518529
static void loadhostkey_helper(const char *name, void** src, void** dst, int fatal_duplicate) {
519530
if (*dst) {
520531
if (fatal_duplicate) {

0 commit comments

Comments
 (0)