|
39 | 39 | $HTTP_RAW_POST_DATA = file_get_contents('php://input');
|
40 | 40 | }
|
41 | 41 |
|
42 |
| -if (!empty($CFG->mnet_rpcdebug)) { |
43 |
| - error_log("HTTP_RAW_POST_DATA"); |
44 |
| - error_log($HTTP_RAW_POST_DATA); |
45 |
| -} |
| 42 | +mnet_debug("HTTP_RAW_POST_DATA", 2); |
| 43 | +mnet_debug($HTTP_RAW_POST_DATA, 2); |
46 | 44 |
|
47 | 45 | if (!isset($_SERVER)) {
|
48 | 46 | exit(mnet_server_fault(712, "phperror"));
|
|
58 | 56 | $plaintextmessage = mnet_server_strip_encryption($HTTP_RAW_POST_DATA);
|
59 | 57 | $xmlrpcrequest = mnet_server_strip_signature($plaintextmessage);
|
60 | 58 | } catch (Exception $e) {
|
| 59 | + mnet_debug('encryption strip exception thrown: ' . $e->getMessage()); |
61 | 60 | exit(mnet_server_fault($e->getCode(), $e->getMessage(), $e->a));
|
62 | 61 | }
|
63 | 62 |
|
64 |
| -if (!empty($CFG->mnet_rpcdebug)) { |
65 |
| - error_log("XMLRPC Payload"); |
66 |
| - error_log(print_r($xmlrpcrequest,1)); |
67 |
| -} |
| 63 | +mnet_debug('XMLRPC Payload', 2); |
| 64 | +mnet_debug($xmlrpcrequest, 2); |
68 | 65 |
|
69 | 66 | if($remoteclient->pushkey == true) {
|
70 | 67 | // The peer used one of our older public keys, we will return a
|
71 | 68 | // signed/encrypted error message containing our new public key
|
72 | 69 | // Sign message with our old key, and encrypt to the peer's private key.
|
| 70 | + mnet_debug('sending back new key'); |
73 | 71 | exit(mnet_server_fault_xml(7025, $mnet->public_key, $remoteclient->useprivatekey));
|
74 | 72 | }
|
75 | 73 | // Have a peek at what the request would be if we were to process it
|
76 | 74 | $params = xmlrpc_decode_request($xmlrpcrequest, $method);
|
| 75 | +mnet_debug("incoming mnet request $method"); |
77 | 76 |
|
78 | 77 | // One of three conditions need to be met before we continue processing this request:
|
79 | 78 | // 1. Request is properly encrypted and signed
|
|
85 | 84 | try {
|
86 | 85 | // main dispatch call. will echo the response directly
|
87 | 86 | mnet_server_dispatch($xmlrpcrequest);
|
| 87 | + mnet_debug('exiting cleanly'); |
88 | 88 | exit;
|
89 | 89 | } catch (Exception $e) {
|
| 90 | + mnet_debug('dispatch exception thrown: ' . $e->getMessage()); |
90 | 91 | exit(mnet_server_fault($e->getCode(), $e->getMessage(), $e->a));
|
91 | 92 | }
|
92 | 93 | }
|
93 | 94 | // if we get to here, something is wrong
|
94 | 95 | // so detect a few common cases and send appropriate errors
|
95 | 96 | if (($remoteclient->request_was_encrypted == false) && ($remoteclient->plaintext_is_ok() == false)) {
|
| 97 | + mnet_debug('non encrypted request'); |
96 | 98 | exit(mnet_server_fault(7021, 'forbidden-transport'));
|
97 | 99 | }
|
98 | 100 |
|
99 | 101 | if ($remoteclient->request_was_signed == false) {
|
100 | 102 | // Request was not signed
|
| 103 | + mnet_debug('non signed request'); |
101 | 104 | exit(mnet_server_fault(711, 'verifysignature-error'));
|
102 | 105 | }
|
103 | 106 |
|
104 | 107 | if ($remoteclient->signatureok == false) {
|
105 | 108 | // We were unable to verify the signature
|
| 109 | + mnet_debug('non verified signature'); |
106 | 110 | exit(mnet_server_fault(710, 'verifysignature-invalid'));
|
107 | 111 | }
|
| 112 | +mnet_debug('unknown error'); |
108 | 113 | exit(mnet_server_fault(7000, 'unknownerror'));
|
0 commit comments