1
- /* $OpenBSD: authfd.c,v 1.133 2023/03/09 21:06:24 jcs Exp $ */
1
+ /* $OpenBSD: authfd.c,v 1.134 2023/12/18 14:46:56 djm Exp $ */
2
2
/*
3
3
* Author: Tatu Ylonen <ylo@cs.hut.fi>
4
4
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -504,9 +504,10 @@ encode_dest_constraint(struct sshbuf *m, const struct dest_constraint *dc)
504
504
}
505
505
506
506
static int
507
- encode_constraints (struct sshbuf * m , u_int life , u_int confirm , u_int maxsign ,
508
- const char * provider , struct dest_constraint * * dest_constraints ,
509
- size_t ndest_constraints )
507
+ encode_constraints (struct sshbuf * m , u_int life , u_int confirm ,
508
+ u_int maxsign , const char * provider ,
509
+ struct dest_constraint * * dest_constraints , size_t ndest_constraints ,
510
+ int cert_only , struct sshkey * * certs , size_t ncerts )
510
511
{
511
512
int r ;
512
513
struct sshbuf * b = NULL ;
@@ -550,6 +551,27 @@ encode_constraints(struct sshbuf *m, u_int life, u_int confirm, u_int maxsign,
550
551
"restrict-destination-v00@openssh.com" )) != 0 ||
551
552
(r = sshbuf_put_stringb (m , b )) != 0 )
552
553
goto out ;
554
+ sshbuf_free (b );
555
+ b = NULL ;
556
+ }
557
+ if (ncerts != 0 ) {
558
+ if ((b = sshbuf_new ()) == NULL ) {
559
+ r = SSH_ERR_ALLOC_FAIL ;
560
+ goto out ;
561
+ }
562
+ for (i = 0 ; i < ncerts ; i ++ ) {
563
+ if ((r = sshkey_puts (certs [i ], b )) != 0 )
564
+ goto out ;
565
+ }
566
+ if ((r = sshbuf_put_u8 (m ,
567
+ SSH_AGENT_CONSTRAIN_EXTENSION )) != 0 ||
568
+ (r = sshbuf_put_cstring (m ,
569
+ "associated-certs-v00@openssh.com" )) != 0 ||
570
+ (r = sshbuf_put_u8 (m , cert_only != 0 )) != 0 ||
571
+ (r = sshbuf_put_stringb (m , b )) != 0 )
572
+ goto out ;
573
+ sshbuf_free (b );
574
+ b = NULL ;
553
575
}
554
576
r = 0 ;
555
577
out :
@@ -607,7 +629,7 @@ ssh_add_identity_constrained(int sock, struct sshkey *key,
607
629
}
608
630
if (constrained &&
609
631
(r = encode_constraints (msg , life , confirm , maxsign ,
610
- provider , dest_constraints , ndest_constraints )) != 0 )
632
+ provider , dest_constraints , ndest_constraints , 0 , NULL , 0 )) != 0 )
611
633
goto out ;
612
634
if ((r = ssh_request_reply_decode (sock , msg )) != 0 )
613
635
goto out ;
@@ -662,10 +684,11 @@ ssh_remove_identity(int sock, const struct sshkey *key)
662
684
int
663
685
ssh_update_card (int sock , int add , const char * reader_id , const char * pin ,
664
686
u_int life , u_int confirm ,
665
- struct dest_constraint * * dest_constraints , size_t ndest_constraints )
687
+ struct dest_constraint * * dest_constraints , size_t ndest_constraints ,
688
+ int cert_only , struct sshkey * * certs , size_t ncerts )
666
689
{
667
690
struct sshbuf * msg ;
668
- int r , constrained = (life || confirm || dest_constraints );
691
+ int r , constrained = (life || confirm || dest_constraints || certs );
669
692
u_char type ;
670
693
671
694
if (add ) {
@@ -683,7 +706,8 @@ ssh_update_card(int sock, int add, const char *reader_id, const char *pin,
683
706
goto out ;
684
707
if (constrained &&
685
708
(r = encode_constraints (msg , life , confirm , 0 , NULL ,
686
- dest_constraints , ndest_constraints )) != 0 )
709
+ dest_constraints , ndest_constraints ,
710
+ cert_only , certs , ncerts )) != 0 )
687
711
goto out ;
688
712
if ((r = ssh_request_reply_decode (sock , msg )) != 0 )
689
713
goto out ;
0 commit comments