@@ -292,6 +292,16 @@ impl Keys {
292292 }
293293}
294294
295+ fn validate_domain ( domain : & str , source : & str ) -> Result < String > {
296+ let domain = domain. trim ( ) ;
297+ if domain. is_empty ( ) {
298+ return Err ( anyhow:: anyhow!(
299+ "invalid domain from {source}: empty or whitespace-only"
300+ ) ) ;
301+ }
302+ Ok ( domain. to_string ( ) )
303+ }
304+
295305pub ( crate ) async fn update_certs ( cfg : & KmsConfig ) -> Result < ( ) > {
296306 // Read existing keys
297307 let tmp_ca_key = KeyPair :: from_pem ( & fs:: read_to_string ( cfg. tmp_ca_key ( ) ) ?) ?;
@@ -302,20 +312,22 @@ pub(crate) async fn update_certs(cfg: &KmsConfig) -> Result<()> {
302312 let k256_key_bytes = fs:: read ( cfg. k256_key ( ) ) ?;
303313 let k256_key = SigningKey :: from_slice ( & k256_key_bytes) ?;
304314
305- let domain = if cfg. onboard . auto_bootstrap_domain . is_empty ( ) {
306- fs:: read_to_string ( cfg. rpc_domain ( ) ) ?
315+ let domain = if cfg. onboard . auto_bootstrap_domain . trim ( ) . is_empty ( ) {
316+ validate_domain ( & fs:: read_to_string ( cfg. rpc_domain ( ) ) ? , "stored rpc_domain" ) ?
307317 } else {
308- cfg. onboard . auto_bootstrap_domain . clone ( )
318+ validate_domain (
319+ & cfg. onboard . auto_bootstrap_domain ,
320+ "core.onboard.auto_bootstrap_domain" ,
321+ ) ?
309322 } ;
310- let domain = domain. trim ( ) ;
311323
312324 // Regenerate certificates using existing keys
313325 let keys = Keys :: from_keys (
314326 tmp_ca_key,
315327 ca_key,
316328 rpc_key,
317329 k256_key,
318- domain,
330+ & domain,
319331 cfg. onboard . quote_enabled ,
320332 )
321333 . await
@@ -338,9 +350,13 @@ pub(crate) async fn auto_onboard_keys(cfg: &KmsConfig) -> Result<()> {
338350 } else {
339351 format ! ( "{source_url}/prpc" )
340352 } ;
353+ let domain = validate_domain (
354+ & cfg. onboard . auto_bootstrap_domain ,
355+ "core.onboard.auto_bootstrap_domain" ,
356+ ) ?;
341357 let keys = Keys :: onboard (
342358 & source_url,
343- & cfg . onboard . auto_bootstrap_domain ,
359+ & domain ,
344360 cfg. onboard . quote_enabled ,
345361 cfg. pccs_url . clone ( ) ,
346362 )
@@ -351,12 +367,13 @@ pub(crate) async fn auto_onboard_keys(cfg: &KmsConfig) -> Result<()> {
351367}
352368
353369pub ( crate ) async fn bootstrap_keys ( cfg : & KmsConfig ) -> Result < ( ) > {
354- let keys = Keys :: generate (
370+ let domain = validate_domain (
355371 & cfg. onboard . auto_bootstrap_domain ,
356- cfg. onboard . quote_enabled ,
357- )
358- . await
359- . context ( "Failed to generate keys" ) ?;
372+ "core.onboard.auto_bootstrap_domain" ,
373+ ) ?;
374+ let keys = Keys :: generate ( & domain, cfg. onboard . quote_enabled )
375+ . await
376+ . context ( "Failed to generate keys" ) ?;
360377 keys. store ( cfg) ?;
361378 Ok ( ( ) )
362379}
0 commit comments