@@ -2,7 +2,7 @@ use std::net::{SocketAddr, ToSocketAddrs};
22use std:: num:: ParseIntError ;
33use std:: str:: FromStr ;
44
5- use clap:: { App , AppSettings , Arg , ArgGroup } ;
5+ use clap:: { App , AppSettings , Arg } ;
66use hex:: FromHex ;
77use itertools:: Itertools ;
88use regex:: Regex ;
@@ -63,6 +63,10 @@ pub struct CliConfig {
6363 pub tcp_addrs : Vec < SocketAddr > ,
6464 /// DHT SecretKey
6565 pub sk : Option < SecretKey > ,
66+ /// True if the SecretKey was passed as an argument instead of environment
67+ /// variable. Necessary to print a warning since the logger backend is not
68+ /// initialized when we parse arguments.
69+ pub sk_passed_as_arg : bool ,
6670 /// Path to the file where DHT keys are stored.
6771 pub keys_file : Option < String > ,
6872 /// List of bootstrap nodes.
@@ -98,19 +102,24 @@ pub fn cli_parse() -> CliConfig {
98102 . takes_value ( true )
99103 . use_delimiter ( true )
100104 . required_unless ( "udp-address" ) )
101- . group ( ArgGroup :: with_name ( "credentials" )
102- . args ( & [ "secret-key" , "keys-file" ] )
103- . required ( true ) )
104105 . arg ( Arg :: with_name ( "secret-key" )
105106 . short ( "s" )
106107 . long ( "secret-key" )
107- . help ( "DHT secret key" )
108- . takes_value ( true ) )
108+ . help ( "DHT secret key. Note that you should not pass the key via \
109+ arguments due to security reasons. Use this argument for \
110+ test purposes only. In the real world use the environment \
111+ variable instead")
112+ . takes_value ( true )
113+ . conflicts_with ( "keys-file" )
114+ . env ( "TOX_SECRET_KEY" )
115+ . hidden ( true ) )
109116 . arg ( Arg :: with_name ( "keys-file" )
110117 . short ( "k" )
111118 . long ( "keys-file" )
112119 . help ( "Path to the file where DHT keys are stored" )
113- . takes_value ( true ) )
120+ . takes_value ( true )
121+ . required_unless ( "secret-key" )
122+ . conflicts_with ( "secret-key" ) )
114123 . arg ( Arg :: with_name ( "bootstrap-node" )
115124 . short ( "b" )
116125 . long ( "bootstrap-node" )
@@ -174,6 +183,8 @@ pub fn cli_parse() -> CliConfig {
174183 SecretKey :: from_slice ( & sk_bytes) . expect ( "Invalid DHT secret key" )
175184 } ) ;
176185
186+ let sk_passed_as_arg = matches. occurrences_of ( "secret-key" ) > 0 ;
187+
177188 let keys_file = matches. value_of ( "keys-file" ) . map ( |s| s. to_owned ( ) ) ;
178189
179190 let bootstrap_nodes = matches
@@ -208,6 +219,7 @@ pub fn cli_parse() -> CliConfig {
208219 udp_addr,
209220 tcp_addrs,
210221 sk,
222+ sk_passed_as_arg,
211223 keys_file,
212224 bootstrap_nodes,
213225 threads_config,
0 commit comments