mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 04:31:05 +08:00
Add .gitignore and Cargo.toml files, and update connect.py and main.rs
Refactor authentication key handling in main.rs Add event handler for any event Fix authentication signature generation | 我tm直接就是一个感动中国 aaaaaa | key!
This commit is contained in:
parent
8dfbf1d7ab
commit
29c43e64e6
|
@ -77,10 +77,13 @@ def connect():
|
|||
|
||||
@sio.on('requireAuth')
|
||||
async def require_auth(salt: str, versions: Dict[str, str]):
|
||||
print(f"{Fore.BLUE}versions: {versions}{Style.RESET_ALL}")
|
||||
print(f"{Fore.BLUE}versions: {versions}{Style.RESET_ALL}\n{type(salt)}|{salt=}")
|
||||
# 准备数据
|
||||
sign = SigningKey(bytes.fromhex(KEY))
|
||||
signature = sign.sign(bytes.fromhex(salt))
|
||||
|
||||
# 发送数据
|
||||
print(f"{len(signature.signature)=} {type(signature.signature)=}")
|
||||
await sio.emit('auth', signature.signature)
|
||||
print(f"{Fore.BLUE}send auth emit{Style.RESET_ALL}")
|
||||
|
||||
|
|
1
ica-rs/.gitignore
vendored
Normal file
1
ica-rs/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target
|
1634
ica-rs/Cargo.lock
generated
Normal file
1634
ica-rs/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
ica-rs/Cargo.toml
Normal file
13
ica-rs/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "ica-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
ed25519 = "2.2.3"
|
||||
ed25519-dalek = "2.1.0"
|
||||
hex = "0.4.3"
|
||||
rust_socketio = "0.4.4"
|
||||
serde_json = "1.0.108"
|
85
ica-rs/src/main.rs
Normal file
85
ica-rs/src/main.rs
Normal file
|
@ -0,0 +1,85 @@
|
|||
use ed25519_dalek::{Signature, Signer, SigningKey};
|
||||
use rust_socketio::{ClientBuilder, Payload, RawClient, Event};
|
||||
use std::time::Duration;
|
||||
|
||||
static KEY: &str = "";
|
||||
static HOST: &str = "";
|
||||
|
||||
#[allow(unused)]
|
||||
fn require_auth_callback(payload: Payload, client: RawClient) {
|
||||
let auth_key = match payload {
|
||||
Payload::String(str) => Some(str),
|
||||
Payload::Binary(_) => None,
|
||||
}
|
||||
.unwrap();
|
||||
// 去除前后的 "
|
||||
let auth_key = &auth_key[1..auth_key.len() - 1];
|
||||
|
||||
println!("auth_key: {}", auth_key);
|
||||
|
||||
let array_key: [u8; 32] = hex::decode(KEY).unwrap().try_into().unwrap();
|
||||
|
||||
let signing_key: SigningKey = SigningKey::from_bytes(&array_key);
|
||||
|
||||
let salt = hex::decode(auth_key).unwrap();
|
||||
let signature: Signature = signing_key.sign(salt.as_slice());
|
||||
// let sign = hex::encode(signature.to_bytes());
|
||||
let sign = signature.to_bytes().to_vec();
|
||||
client.emit("auth", sign).unwrap();
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn any_event(event: Event, payload: Payload, _client: RawClient) {
|
||||
// println!("event: {} | {:#?}", event, payload);
|
||||
match payload {
|
||||
Payload::Binary(bin) => println!("event: {} |bin: {:?}", event, bin),
|
||||
Payload::String(str) => println!("event: {} |str: {:?}", event, str),
|
||||
}
|
||||
}
|
||||
|
||||
fn ws_main() {
|
||||
// define a callback which is called when a payload is received
|
||||
// this callback gets the payload as well as an instance of the
|
||||
// socket to communicate with the server
|
||||
let connect_call_back = |payload: Payload, _client: RawClient| {
|
||||
println!("Connect callback: {:#?}", payload);
|
||||
};
|
||||
|
||||
// get a socket that is connected to the admin namespace
|
||||
|
||||
let socket = ClientBuilder::new(HOST)
|
||||
// .namespace("/admin")
|
||||
.on_any(any_event)
|
||||
.on("connect", connect_call_back)
|
||||
.on("requireAuth", require_auth_callback)
|
||||
.connect()
|
||||
.expect("Connection failed");
|
||||
|
||||
std::thread::sleep(Duration::from_secs(10));
|
||||
|
||||
socket.disconnect().expect("Disconnect failed")
|
||||
}
|
||||
|
||||
fn sign_main() {
|
||||
// 生成 SingningKey
|
||||
let array_key: [u8; 32] = hex::decode(KEY).unwrap().try_into().unwrap();
|
||||
let signing_key: SigningKey = SigningKey::from_bytes(&array_key);
|
||||
|
||||
// 要签名的东西
|
||||
let data = "187d0b21becfa7a49e97afc00646e169";
|
||||
let data = hex::decode(data).unwrap();
|
||||
|
||||
// 签名
|
||||
let signature: Signature = signing_key.sign(data.as_slice());
|
||||
|
||||
// 生成签名
|
||||
let sign = hex::encode(signature.to_bytes());
|
||||
|
||||
println!("sign: {} {:?} {}", sign, signature.to_bytes(), signature.to_bytes().len());
|
||||
// println!("hex: {}", hex::encode());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
sign_main();
|
||||
ws_main();
|
||||
}
|
Loading…
Reference in New Issue
Block a user