public static function process($msg) { $res = ""; $status = 1; $sender = ""; $umsg = GsonCrypt::unseal($msg); if (!$umsg) { $ex = Gmsg::extract($msg); if ($ex && is_array($ex)) { $umsg = $msg; } else { $status = 0; $res = "Unable to decode the message"; } } if ($umsg) { $parts = self::extract($umsg); $action = $parts["op"]; $mess = $parts["msg"]; $recipient = $parts["recipient"]; $sender = $parts["sender"]; if (isset($parts["bank"])) { $sender = $parts["bank"] . "_{$sender}"; } if (strtolower($recipient) != strtolower(config::$accountId)) { $status = 0; $res = config::$accountId . " is not the intended recipient [{$recipient}]"; $rply = Gmsg::create(array("status" => $status, "response" => $res)); } else { switch ($action) { case "notification": $r = transaction::notification($mess, $sender); $m = Gmsg::create(array("status" => $r[0], "response" => $r[1])); $rply = GsonCrypt::sign($m); break; case "revokecert": if (!$sender) { $status = 0; $res = "The sender is unknown"; } else { $res = ""; $ret = array("status" => $status, "response" => $res, "account" => $sender); $rply = self::create($ret); $rply = GsonCrypt::seal("{$rply}", "{$sender}"); @unlink(GsonCrypt::getkey($sender)); /* Buggy: Verify the sender first*/ } break; case "signcert": $k = GsonCrypt::getkey("{$sender}"); if (file_exists($k)) { $status = 2; $res = "This account already exist!"; } else { $res = GsonCrypt::signcert($sender, $mess); if (!$res) { $status = 0; $res = "An error occured while signing the certificate."; } } break; case "reverb": $res = $mess; break; default: $status = 0; $res = "Invalid Operation!"; } } } if (!isset($rply)) { $ret = array("status" => $status, "response" => $res, "account" => $sender); $rply = self::create($ret); $rply = $sender ? GsonCrypt::seal("{$rply}", "{$sender}") : "{$rply}"; } return $rply; }