1
- use std:: collections:: HashMap ;
2
- use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
3
- use std:: time:: { Duration , Instant } ;
4
-
5
1
use clap:: Clap ;
6
2
use crypto:: digest:: Digest ;
7
3
use crypto:: sha2:: Sha224 ;
4
+ use std:: collections:: HashMap ;
5
+ use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
6
+ use std:: time:: { Duration , Instant } ;
8
7
use trust_dns_resolver:: Resolver ;
9
8
10
9
pub struct DnsEntry {
@@ -21,8 +20,8 @@ pub struct Opts {
21
20
pub log_file : Option < String > ,
22
21
#[ clap( short = "a" , long, help = "listen address for server" ) ]
23
22
pub local_addr : String ,
24
- #[ clap( required = true , short, long, help = "passwords for negotiation" ) ]
25
- password : Vec < String > ,
23
+ #[ clap( short, long, help = "passwords for negotiation" ) ]
24
+ password : String ,
26
25
#[ clap( short = "L" , long, default_value = "2" , help = "log level, 0 for trace, 1 for debug, 2 for info, 3 for warning, 4 for error, 5 for off" ) ]
27
26
pub log_level : u8 ,
28
27
#[ clap( short, long, default_value = "255" , help = "set marker used by tproxy" ) ]
@@ -32,7 +31,7 @@ pub struct Opts {
32
31
#[ clap( skip) ]
33
32
dns_cache_duration : Duration ,
34
33
#[ clap( skip) ]
35
- sha_pass : Vec < String > ,
34
+ sha_pass : String ,
36
35
#[ clap( skip) ]
37
36
pub pass_len : usize ,
38
37
#[ clap( skip) ]
@@ -129,28 +128,24 @@ impl Opts {
129
128
130
129
fn digest_pass ( & mut self ) {
131
130
let mut encoder = Sha224 :: new ( ) ;
132
- self . sha_pass . clear ( ) ;
133
- for pass in & self . password {
134
- encoder. reset ( ) ;
135
- encoder. input ( pass. as_bytes ( ) ) ;
136
- let result = encoder. result_str ( ) ;
137
- self . pass_len = result. len ( ) ;
138
- log:: info!( "sha224({}) = {}, length = {}" , pass, result, self . pass_len) ;
139
- self . sha_pass . push ( result) ;
140
- }
131
+ encoder. reset ( ) ;
132
+ encoder. input ( self . password . as_bytes ( ) ) ;
133
+ let result = encoder. result_str ( ) ;
134
+ self . pass_len = result. len ( ) ;
135
+ log:: info!( "sha224({}) = {}, length = {}" , self . password, result, self . pass_len) ;
136
+ self . sha_pass = result;
141
137
}
142
138
143
139
pub fn check_pass ( & self , pass : & str ) -> Option < & String > {
144
- for i in 0 .. self . sha_pass . len ( ) {
145
- if self . sha_pass [ i ] . eq ( pass ) {
146
- return Some ( & self . password [ i ] ) ;
147
- }
140
+ if self . sha_pass . eq ( pass ) {
141
+ Some ( & self . password )
142
+ } else {
143
+ None
148
144
}
149
- None
150
145
}
151
146
152
147
pub fn get_pass ( & self ) -> & String {
153
- self . sha_pass . get ( 0 ) . unwrap ( )
148
+ & self . sha_pass
154
149
}
155
150
156
151
pub fn update_dns ( & mut self , domain : String , address : IpAddr ) {
0 commit comments