Subversion Repositories php_clientchallenge

Rev

Rev 4 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
/*
2
 * php_clientchallenge
6 daniel-mar 3
 * Copyright 2021-2022 Daniel Marschall, ViaThinkSoft
2 daniel-mar 4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
18
function vts_validated_call(getChallengeScript, callback, params, error_cb) {
19
        $.ajax({
20
                type: "POST",
21
                url: getChallengeScript,
22
                data: {
23
                },
24
                success: function(data) {
6 daniel-mar 25
                        if ("error" in data) {
26
                                error_cb(null,null,data["error"]);
27
                                return;
28
                        }
2 daniel-mar 29
                        var starttime = data[0];
30
                        var ip_target = data[1];
31
                        var challenge = data[2];
32
                        var min = data[3];
33
                        var max = data[4];
4 daniel-mar 34
                        var challenge_integrity = data[5];
2 daniel-mar 35
                        for (i=min; i<=max; i++) {
36
                                if (challenge == sha3_512(starttime+"/"+ip_target+"/"+i)) {
37
                                        var answer = i;
4 daniel-mar 38
                                        var vts_validation_result = JSON.stringify([starttime, ip_target, challenge, answer, challenge_integrity]);
2 daniel-mar 39
                                        callback(params, vts_validation_result);
40
                                        break;
41
                                }
42
                        }
43
                },
44
                error: error_cb
45
        });
46
}