futu_backend/auth/commconfig/
mod.rs1mod accessors;
18mod fetch;
19mod parsers;
20mod totp;
21mod types;
22
23#[cfg(test)]
24mod tests;
25
26#[cfg(test)]
28pub(super) use super::*;
29
30pub use accessors::{
32 broker_auth_webtcp_identity, default_webtcp_identity_for_client_type,
33 forced_ip_for_attribution, ips_for_attribution, ips_for_broker, ips_for_web_identity,
34 spawn_refresher, webtcp_addrs_for_identity, webtcp_hardcoded_addrs,
35};
36pub use fetch::server_now_ts;
37pub use fetch::{SharedCommConfig, empty_snapshot, fetch_all};
38pub use parsers::{api_root_for_client, client_version_dotted, is_web_identity};
39pub use totp::gen_totp_sha1;
40pub use types::{
41 AuthGuaranteedDomainMap, CONN_WEB_AU, CONN_WEB_CA, CONN_WEB_CN, CONN_WEB_HK, CONN_WEB_JP,
42 CONN_WEB_MY, CONN_WEB_SG, CONN_WEB_US, CommonConfigSnapshot, ForcedIpEntry, ForcedIpMap,
43 GuaranteedBrokerIpMap, GuaranteedIpMap, GuaranteedWebIpMap,
44};
45
46pub fn common_http_auth_token(unix_ts: i64) -> Option<String> {
52 gen_totp_sha1(types::AUTH_TOKEN_KEY_B32, unix_ts, 30)
53}
54
55pub fn common_http_client_token(unix_ts: i64) -> Option<String> {
62 if unix_ts <= 0 {
63 return None;
64 }
65
66 let unix_ts = unix_ts.to_string();
67 let mut block = [0u8; 16];
68 let bytes = unix_ts.as_bytes();
69 let len = bytes.len().min(block.len());
70 block[..len].copy_from_slice(&bytes[..len]);
71
72 use aes::cipher::{BlockEncrypt, KeyInit, generic_array::GenericArray};
73 let cipher = aes::Aes128::new_from_slice(types::AUTH_TOKEN_KEY_B32.as_bytes()).ok()?;
74 let mut block = GenericArray::clone_from_slice(&block);
75 cipher.encrypt_block(&mut block);
76 Some(hex::encode(block))
77}
78
79#[cfg(test)]
81pub(super) use accessors::delay_until_next_refresh;
82#[cfg(test)]
83pub(super) use fetch::server_now_ts_at;
84#[cfg(test)]
85pub(super) use parsers::{
86 is_broker_identity, parse_auth_guaranteed_domain_list, parse_forced_ip, parse_guaranteed_ip,
87 parse_web_tcp_config_identity, value_kind,
88};
89#[cfg(test)]
90pub(super) use std::collections::HashMap;
91#[cfg(test)]
92pub(super) use totp::base32_decode;