|
1 | | -/* $OpenBSD: ssh-agent.c,v 1.302 2023/12/18 14:46:56 djm Exp $ */ |
| 1 | +/* $OpenBSD: ssh-agent.c,v 1.303 2023/12/18 14:48:08 djm Exp $ */ |
2 | 2 | /* |
3 | 3 | * Author: Tatu Ylonen <[email protected]> |
4 | 4 | * Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland |
@@ -130,6 +130,7 @@ typedef struct socket_entry { |
130 | 130 | struct sshbuf *request; |
131 | 131 | size_t nsession_ids; |
132 | 132 | struct hostkey_sid *session_ids; |
| 133 | + int session_bind_attempted; |
133 | 134 | } SocketEntry; |
134 | 135 |
|
135 | 136 | u_int sockets_alloc = 0; |
@@ -477,6 +478,10 @@ identity_permitted(Identity *id, SocketEntry *e, char *user, |
477 | 478 | e->nsession_ids, id->ndest_constraints); |
478 | 479 | if (id->ndest_constraints == 0) |
479 | 480 | return 0; /* unconstrained */ |
| 481 | + if (e->session_bind_attempted && e->nsession_ids == 0) { |
| 482 | + error_f("previous session bind failed on socket"); |
| 483 | + return -1; |
| 484 | + } |
480 | 485 | if (e->nsession_ids == 0) |
481 | 486 | return 0; /* local use */ |
482 | 487 | /* |
@@ -556,6 +561,12 @@ identity_permitted(Identity *id, SocketEntry *e, char *user, |
556 | 561 | return 0; |
557 | 562 | } |
558 | 563 |
|
| 564 | +static int |
| 565 | +socket_is_remote(SocketEntry *e) |
| 566 | +{ |
| 567 | + return e->session_bind_attempted || (e->nsession_ids != 0); |
| 568 | +} |
| 569 | + |
559 | 570 | /* return matching private key for given public key */ |
560 | 571 | static Identity * |
561 | 572 | lookup_identity(struct sshkey *key) |
@@ -1367,7 +1378,7 @@ process_add_identity(SocketEntry *e) |
1367 | 1378 | if (strcasecmp(sk_provider, "internal") == 0) { |
1368 | 1379 | debug_f("internal provider"); |
1369 | 1380 | } else { |
1370 | | - if (e->nsession_ids != 0 && !remote_add_provider) { |
| 1381 | + if (socket_is_remote(e) && !remote_add_provider) { |
1371 | 1382 | verbose("failed add of SK provider \"%.100s\": " |
1372 | 1383 | "remote addition of providers is disabled", |
1373 | 1384 | sk_provider); |
@@ -1565,7 +1576,7 @@ process_add_smartcard_key(SocketEntry *e) |
1565 | 1576 | goto send; |
1566 | 1577 | } |
1567 | 1578 | dump_dest_constraints(__func__, dest_constraints, ndest_constraints); |
1568 | | - if (e->nsession_ids != 0 && !remote_add_provider) { |
| 1579 | + if (socket_is_remote(e) && !remote_add_provider) { |
1569 | 1580 | verbose("failed PKCS#11 add of \"%.100s\": remote addition of " |
1570 | 1581 | "providers is disabled", provider); |
1571 | 1582 | goto send; |
@@ -1680,6 +1691,7 @@ process_ext_session_bind(SocketEntry *e) |
1680 | 1691 | u_char fwd = 0; |
1681 | 1692 |
|
1682 | 1693 | debug2_f("entering"); |
| 1694 | + e->session_bind_attempted = 1; |
1683 | 1695 | if ((r = sshkey_froms(e->request, &key)) != 0 || |
1684 | 1696 | (r = sshbuf_froms(e->request, &sid)) != 0 || |
1685 | 1697 | (r = sshbuf_froms(e->request, &sig)) != 0 || |
|
0 commit comments