diff --git a/iniDataForMacOs b/iniDataForMacOs index df2ff7b..99ce46c 100755 Binary files a/iniDataForMacOs and b/iniDataForMacOs differ diff --git a/main.go b/main.go index a26b8de..d56831a 100644 --- a/main.go +++ b/main.go @@ -190,17 +190,17 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) { } -func verify_signature(signature string, nonce int64, timestamp int64, data interface{}) bool { +func verify_signature(signature string, nonce string, timestamp int64, data interface{}) bool { key := "qZ6v1&H#Wjx+yRm2D@*sJF$tnfL83Ia" fmt.Printf("Received signature: %s\n", signature) fmt.Printf("Received timestamp: %d\n", timestamp) - fmt.Printf("Received nonce: %d\n", nonce) + fmt.Printf("Received nonce: %s\n", nonce) fmt.Printf("Received data: %v\n", data) received_signature := signature received_timestamp, _ := strconv.ParseInt(fmt.Sprintf("%v", timestamp), 10, 64) - received_nonce, _ := strconv.Atoi(fmt.Sprintf("%v", nonce)) + received_nonce := nonce //strconv.Atoi(fmt.Sprintf("%v", nonce)) if time.Now().Unix()-received_timestamp > 7200 { fmt.Println("Timestamp expired") @@ -209,7 +209,7 @@ func verify_signature(signature string, nonce int64, timestamp int64, data inter received_data_bytes, _ := json.Marshal(data) received_data := string(received_data_bytes) - expected_data := fmt.Sprintf("%d|%d|%s", received_timestamp, received_nonce, received_data) + expected_data := fmt.Sprintf("%d|%s|%s", received_timestamp, received_nonce, received_data) fmt.Printf("Expected data: %s\n", expected_data) mac := hmac.New(sha256.New, []byte(key)) @@ -1203,5 +1203,5 @@ type TaskData struct { type Signature struct { Signature string `json:"signature"` Timestamp int64 `json:"timestamp"` - Nonce int64 `json:"nonce"` + Nonce string `json:"nonce"` } diff --git a/sign_message.php b/sign_message.php index 4af2311..87561d5 100644 --- a/sign_message.php +++ b/sign_message.php @@ -2,9 +2,9 @@ function sign_message($data) { $timestamp = time(); - $nonce = mt_rand(100000, 999999); // 生成一个六位随机数 + $nonce = generate_random_string(64); // 生成一个六位随机数,包含大小写字母和数字 $message = "$timestamp|$nonce|" . json_encode($data); - $key = 'qZ6v1&H#Wjx+yRm2D@*sJF$tnfL83Ia'; // 签名密钥,请自行设置 + $key = 'qZ6v1&H#Wjx+yRm2D@*sJF$tnfL83Ia'; $signature = hash_hmac('sha256', $message, $key); $signed_message = array( 'TaskData' => $data, @@ -17,6 +17,16 @@ function sign_message($data) { return json_encode($signed_message); } +function generate_random_string($length) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()_-+='; + $random_string = ''; + for ($i = 0; $i < $length; $i++) { + $index = mt_rand(0, strlen($characters) - 1); + $random_string .= $characters[$index]; + } + return $random_string; +} + $data = array( "command" => "lastCall", "excluded_filename" => "lastCall.txt",