-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenterroom.php
More file actions
106 lines (86 loc) · 2.82 KB
/
enterroom.php
File metadata and controls
106 lines (86 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?
// Cryptoblog Chatroom Entering Interface
// Copyleft by Elemential 2015
// Licensed under LGPL 3.0
require_once("config.php");
require_once("verify.php");
require_once("message.php");
header("Content-type: application/json");
$return_value = [ "valid" => false ];
$con = CryptoblogConfig::getConnection();
$inputMessage = new CryptoblogMessage($_REQUEST['data'], $_REQUEST['peerid'], CryptoblogMessage::ENCRYPTED);
if( $inputMessage -> getValid() )
{
$data = $inputMessage -> getMessage();
$valid = $inputMessage -> getValid();
if($valid)
{
$query = sprintf(
"SELECT id,name,link
FROM %1\$s
WHERE link = '%2\$s'
ORDER BY id
LIMIT 1",
CryptoblogConfig::getTableName("rooms"),
$data["message"]["roomid"]);
$result = $con -> query($query);
$roomid = ($row = $result -> fetch_assoc()) ? intval($row['id']) : 0;
$roomname = ($row) ? $row['name'] : "";
$roomlink = ($row) ? $row['link'] : "";
$query = sprintf(
"UPDATE %1\$s
SET room = %2\$d
WHERE id = %3\$d",
CryptoblogConfig::getTableName("peers"),
$roomid,
$_REQUEST['peerid']);
$result = $con -> query($query);
/*
$query = sprintf(
"SELECT comkey
FROM %1\$s
WHERE id = %2\$d
LIMIT 1",
CryptoblogConfig::getTableName("peers"),
$_REQUEST["peerid"]);
$result = $con -> query($query);
$roomsign = false;
if($row = $result -> fetch_assoc())
{
$comkey = openssl_get_privatekey( $row['comkey'], CryptoblogConfig::RSA_PASSPHARSE );
openssl_sign($roomid,$roomsign,$comkey);
$roomsign = bin2hex($roomsign);
}
*/
$query = sprintf(
"SELECT id,pubkey
FROM %1\$s
WHERE room = %2\$d
AND id != %3\$d
AND UNIX_TIMESTAMP(last) > %4\$s",
CryptoblogConfig::getTableName("peers"),
$data["message"]["roomid"],
$_REQUEST["peerid"],
time()-10);
$result = $con -> query($query);
$peers = [];
while($row = $result -> fetch_assoc())
{
$peers[] = [
"id" => $row["id"],
"key" => $row["pubkey"]
];
}
$decrypted = [
"peers" => $peers,
"roomname" => $roomname,
"roomlink" => $roomlink
//"roomsign" => $roomsign //We don't need to sign this since our database cannot be manipulated by our clients
];
$message = new CryptoblogMessage($decrypted, $_REQUEST['peerid'], CryptoblogMessage::DECRYPTED);
$return_value["data"] = $message -> getMessage();
$return_value["valid"] = $message -> getValid();
}
}
echo json_encode( $return_value );
?>