@@ -30,8 +30,8 @@ static void rxrpc_destroy_s(struct key *);
3030static void rxrpc_describe_s (const struct key * , struct seq_file * );
3131
3232/*
33- * rxrpc server defined keys take "<serviceId>:<securityIndex>" as the
34- * description and an 8-byte decryption key as the payload
33+ * rxrpc server keys take "<serviceId>:<securityIndex>[:<sec-specific>] " as the
34+ * description and the key material as the payload.
3535 */
3636struct key_type key_type_rxrpc_s = {
3737 .name = "rxrpc_s" ,
@@ -45,64 +45,62 @@ struct key_type key_type_rxrpc_s = {
4545};
4646
4747/*
48- * Vet the description for an RxRPC server key
48+ * Vet the description for an RxRPC server key.
4949 */
5050static int rxrpc_vet_description_s (const char * desc )
5151{
52- unsigned long num ;
52+ unsigned long service , sec_class ;
5353 char * p ;
5454
55- num = simple_strtoul (desc , & p , 10 );
56- if (* p != ':' || num > 65535 )
55+ service = simple_strtoul (desc , & p , 10 );
56+ if (* p != ':' || service > 65535 )
5757 return - EINVAL ;
58- num = simple_strtoul (p + 1 , & p , 10 );
59- if (* p || num < 1 || num > 255 )
58+ sec_class = simple_strtoul (p + 1 , & p , 10 );
59+ if (( * p && * p != ':' ) || sec_class < 1 || sec_class > 255 )
6060 return - EINVAL ;
6161 return 0 ;
6262}
6363
6464/*
6565 * Preparse a server secret key.
66- *
67- * The data should be the 8-byte secret key.
6866 */
6967static int rxrpc_preparse_s (struct key_preparsed_payload * prep )
7068{
71- struct crypto_skcipher * ci ;
69+ const struct rxrpc_security * sec ;
70+ unsigned int service , sec_class ;
71+ int n ;
7272
7373 _enter ("%zu" , prep -> datalen );
7474
75- if (prep -> datalen != 8 )
75+ if (! prep -> orig_description )
7676 return - EINVAL ;
7777
78- memcpy (& prep -> payload .data [2 ], prep -> data , 8 );
78+ if (sscanf (prep -> orig_description , "%u:%u%n" , & service , & sec_class , & n ) != 2 )
79+ return - EINVAL ;
7980
80- ci = crypto_alloc_skcipher ("pcbc(des)" , 0 , CRYPTO_ALG_ASYNC );
81- if (IS_ERR (ci )) {
82- _leave (" = %ld" , PTR_ERR (ci ));
83- return PTR_ERR (ci );
84- }
81+ sec = rxrpc_security_lookup (sec_class );
82+ if (!sec )
83+ return - ENOPKG ;
8584
86- if (crypto_skcipher_setkey (ci , prep -> data , 8 ) < 0 )
87- BUG ();
85+ prep -> payload .data [1 ] = (struct rxrpc_security * )sec ;
8886
89- prep -> payload .data [0 ] = ci ;
90- _leave (" = 0" );
91- return 0 ;
87+ return sec -> preparse_server_key (prep );
9288}
9389
9490static void rxrpc_free_preparse_s (struct key_preparsed_payload * prep )
9591{
96- if (prep -> payload .data [0 ])
97- crypto_free_skcipher (prep -> payload .data [0 ]);
92+ const struct rxrpc_security * sec = prep -> payload .data [1 ];
93+
94+ if (sec )
95+ sec -> free_preparse_server_key (prep );
9896}
9997
10098static void rxrpc_destroy_s (struct key * key )
10199{
102- if ( key -> payload .data [0 ]) {
103- crypto_free_skcipher ( key -> payload . data [ 0 ]);
104- key -> payload . data [ 0 ] = NULL ;
105- }
100+ const struct rxrpc_security * sec = key -> payload .data [1 ];
101+
102+ if ( sec )
103+ sec -> destroy_server_key ( key );
106104}
107105
108106static void rxrpc_describe_s (const struct key * key , struct seq_file * m )
0 commit comments