Exemplo n.º 1
0
 public static function decrypt($msg, $rcptid)
 {
     gio::log("Decrypting message ...");
     $priv_key = GsonCrypt::getkey($rcptid, true, true);
     $res1 = openssl_get_privatekey($priv_key, config::$privateKeyPassword);
     $tt = explode(":::", $msg);
     $cnt = count($tt);
     $i = 0;
     while ($i < $cnt) {
         openssl_private_decrypt($tt[$i], $str1, $res1);
         @($str .= $str1);
         $i++;
     }
     gio::log("... Done decrypting message");
     return $str;
 }
Exemplo n.º 2
0
 public static function isCreated()
 {
     $k = GsonCrypt::getkey(null, true);
     return file_exists($k);
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 public static function mercorder($oid, $account, $merc)
 {
     $v = GsonCrypt::verify($merc, $account);
     if (!$v) {
         return array(0, "Unable to verify the account key");
     }
     if ($v != md5(gio::readfile(GsonCrypt::getkey($account)))) {
         return array(0, "Incorrect Key");
     }
     $r = self::status($oid, $account, true);
     return $r;
 }
Exemplo n.º 5
0
 private static function deregister()
 {
     @unlink(GsonCrypt::getkey(config::$bankId));
     @unlink(GsonCrypt::getcert(config::$bankId));
     @unlink(config::$bankIdFile);
     @unlink(config::$walCfgFile);
     @(config::$bankId = null);
 }
Exemplo n.º 6
0
 private static function rollback()
 {
     @unlink(GsonCrypt::getkey(null));
     @unlink(GsonCrypt::getkey(null, true));
     @unlink(GsonCrypt::getcert());
     @unlink(config::$accountIdFile);
     @unlink(config::$walCfgFile);
     @(config::$accountId = null);
 }
Exemplo n.º 7
0
 public static function signcert($account, $csr, $numberofdays = 0, $serial = "")
 {
     if (empty($serial)) {
         $serial = time();
     }
     $cert = null;
     if (empty($numberofdays) || !is_numeric($numberofdays)) {
         $numberofdays = 7;
     }
     gio::log("Signing certificate with serial: {$serial} valid for {$numberofdays} days ...", VERBOSE);
     $mycert = self::getcert(null, true);
     $privkey = self::getkey(null, true, true);
     $sscert = openssl_csr_sign($csr, $mycert, $privkey, $numberofdays, self::$keyOpts, $serial);
     if ($sscert) {
         openssl_x509_export($sscert, $cert);
     }
     if ($cert) {
         gio::log("... Done signing certificate with serial: {$serial}", VERBOSE);
         gio::saverawfile($cert, GsonCrypt::getkey($account));
     } else {
         gio::log("... Error signing certificate with serial: {$serial} ...", E_USER_WARNING);
     }
     return $cert;
 }
Exemplo n.º 8
0
 public static function process($msg)
 {
     $status = 1;
     $sender = "";
     $res = "";
     $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"];
         $sender = $parts["sender"];
         $recipient = $parts["recipient"];
         if ($recipient && !account::exists($recipient)) {
             $status = 0;
             $res = "The recipient account {$recipient} does not reside here";
             $rply = Gmsg::create(array("status" => $status, "response" => $res));
         } else {
             switch ($action) {
                 case "mrequest":
                     $r = transaction::request($mess['m'], $sender, $mess['k']);
                     $rply = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     break;
                 case "mstatus":
                     $r = transaction::mercorder($mess['m'], $sender, $mess['k']);
                     $rply = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     break;
                 case "statusrequest":
                     $r = transaction::status($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "paymentrequest":
                     $r = transaction::request($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "pullrequests":
                     $r = transaction::pullrequests($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "pullcoins":
                     $r = account::pullcoins($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "clearrequests":
                     $r = transaction::clearrequests($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "notification":
                     $r = transaction::notification($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "acknowledgement":
                     $r = transaction::acknowledgement($mess, config::$SRA);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "deposit":
                     $r = account::deposit($mess, $recipient);
                     if (!$r) {
                         $status = 0;
                         $res = "Deposit failed";
                     } else {
                         $res = "Deposit was successful";
                     }
                     break;
                 case "revokecert":
                     $net = new Gnet();
                     $rply = $net->send("{$mess}", true);
                     $net = null;
                     break;
                 case "signcert":
                     $net = new Gnet();
                     $rply = $net->send("{$mess}", true);
                     $net = null;
                     break;
                 case "register":
                     $k = GsonCrypt::getcert();
                     if (is_readable($k)) {
                         $res = gio::readfile($k);
                         if (!$res) {
                             $status = 0;
                         }
                     }
                     $rply = Gmsg::create(array("status" => $status, "cert" => $res, "name" => config::$accountId, "account" => account::makenew()));
                     break;
                 case "create":
                     $status = gio::savetofile($mess, GsonCrypt::getkey("{$sender}"));
                     $res = $status ? "successful" : "failed";
                     $rply = Gmsg::create(array("status" => $status, "response" => $res));
                     break;
                 case "remove":
                     $res = "";
                     $ret = array("status" => $status, "response" => $res);
                     $rply = self::create($ret);
                     $rply = GsonCrypt::seal("{$rply}", "{$sender}");
                     unlink(GsonCrypt::getkey($sender));
                     break;
                 case "exchangecert":
                     $status = 0;
                     if (!file_exists(GsonCrypt::getcert("{$sender}"))) {
                         $status = gio::saverawfile($mess, GsonCrypt::getcert("{$sender}"));
                     }
                     $k = GsonCrypt::getcert();
                     if ($status && is_readable($k)) {
                         $res = gio::readfile($k);
                         if (!$res) {
                             $status = 0;
                         }
                     }
                     $rply = Gmsg::create(array("status" => $status, "cert" => $res));
                     break;
                 case "reverb":
                     $res = $mess;
                     break;
                 default:
                     $status = 0;
                     $res = "Invalid Operation!";
             }
         }
     }
     if (!isset($rply)) {
         $ret = array("status" => $status, "response" => $res);
         $rply = self::create($ret);
         $rply = $sender ? GsonCrypt::seal("{$rply}", "{$sender}") : "{$rply}";
     }
     return $rply;
 }