88#define pr_fmt (fmt ) "rxperf: " fmt
99#include <linux/module.h>
1010#include <linux/slab.h>
11+ #include <crypto/krb5.h>
1112#include <net/sock.h>
1213#include <net/af_rxrpc.h>
1314#define RXRPC_TRACE_ONLY_DEFINE_ENUMS
@@ -550,9 +551,9 @@ static int rxperf_process_call(struct rxperf_call *call)
550551}
551552
552553/*
553- * Add a key to the security keyring.
554+ * Add an rxkad key to the security keyring.
554555 */
555- static int rxperf_add_key (struct key * keyring )
556+ static int rxperf_add_rxkad_key (struct key * keyring )
556557{
557558 key_ref_t kref ;
558559 int ret ;
@@ -578,6 +579,47 @@ static int rxperf_add_key(struct key *keyring)
578579 return ret ;
579580}
580581
582+ #ifdef CONFIG_RXGK
583+ /*
584+ * Add a yfs-rxgk key to the security keyring.
585+ */
586+ static int rxperf_add_yfs_rxgk_key (struct key * keyring , u32 enctype )
587+ {
588+ const struct krb5_enctype * krb5 = crypto_krb5_find_enctype (enctype );
589+ key_ref_t kref ;
590+ char name [64 ];
591+ int ret ;
592+ u8 key [32 ];
593+
594+ if (!krb5 || krb5 -> key_len > sizeof (key ))
595+ return 0 ;
596+
597+ /* The key is just { 0, 1, 2, 3, 4, ... } */
598+ for (int i = 0 ; i < krb5 -> key_len ; i ++ )
599+ key [i ] = i ;
600+
601+ sprintf (name , "%u:6:1:%u" , RX_PERF_SERVICE , enctype );
602+
603+ kref = key_create_or_update (make_key_ref (keyring , true),
604+ "rxrpc_s" , name ,
605+ key , krb5 -> key_len ,
606+ KEY_POS_VIEW | KEY_POS_READ | KEY_POS_SEARCH |
607+ KEY_USR_VIEW ,
608+ KEY_ALLOC_NOT_IN_QUOTA );
609+
610+ if (IS_ERR (kref )) {
611+ pr_err ("Can't allocate rxperf server key: %ld\n" , PTR_ERR (kref ));
612+ return PTR_ERR (kref );
613+ }
614+
615+ ret = key_link (keyring , key_ref_to_ptr (kref ));
616+ if (ret < 0 )
617+ pr_err ("Can't link rxperf server key: %d\n" , ret );
618+ key_ref_put (kref );
619+ return ret ;
620+ }
621+ #endif
622+
581623/*
582624 * Initialise the rxperf server.
583625 */
@@ -607,9 +649,29 @@ static int __init rxperf_init(void)
607649 goto error_keyring ;
608650 }
609651 rxperf_sec_keyring = keyring ;
610- ret = rxperf_add_key (keyring );
652+ ret = rxperf_add_rxkad_key (keyring );
653+ if (ret < 0 )
654+ goto error_key ;
655+ #ifdef CONFIG_RXGK
656+ ret = rxperf_add_yfs_rxgk_key (keyring , KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96 );
657+ if (ret < 0 )
658+ goto error_key ;
659+ ret = rxperf_add_yfs_rxgk_key (keyring , KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96 );
660+ if (ret < 0 )
661+ goto error_key ;
662+ ret = rxperf_add_yfs_rxgk_key (keyring , KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 );
663+ if (ret < 0 )
664+ goto error_key ;
665+ ret = rxperf_add_yfs_rxgk_key (keyring , KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 );
666+ if (ret < 0 )
667+ goto error_key ;
668+ ret = rxperf_add_yfs_rxgk_key (keyring , KRB5_ENCTYPE_CAMELLIA128_CTS_CMAC );
669+ if (ret < 0 )
670+ goto error_key ;
671+ ret = rxperf_add_yfs_rxgk_key (keyring , KRB5_ENCTYPE_CAMELLIA256_CTS_CMAC );
611672 if (ret < 0 )
612673 goto error_key ;
674+ #endif
613675
614676 ret = rxperf_open_socket ();
615677 if (ret < 0 )
0 commit comments