public static function create() { $status = false; $net = new Gnet(); if (GsonCrypt::cryptoInstalled()) { if (!self::isCreated()) { GsonCrypt::keygen(config::$accountId); } $cert = GsonCrypt::getcert(); $csr = gio::readrawfile($cert); $m = Gmsg::create(Gmsg::prepare($csr, "signcert", config::$SRA)); $m = GsonCrypt::seal($m, config::$SRA); $r = $net->send($m, true); $r = GsonCrypt::unseal($r); $r = Gmsg::extract($r); if ($r['status']) { $data = $r['response']; if ($r['status'] == 1 && $data) { gio::saverawfile($data, $cert); gio::savetofile($data, GsonCrypt::getkey()); gio::output(sprintf("The account '%s' was created succesfully")); $status = true; } else { gio::output($r['response']); } } else { unlink(GsonCrypt::getkey(null, true)); gio::output($r['response']); } } else { gio::output("Kindly install the cryptographic library tools."); } $net = null; return $status; }
public function dosave($arr, $ref = null) { $ref = $ref ? $ref : config::$walfile; $loc = Tools::makepath(array("wal", "{$ref}")); switch ($ref) { case "wal": magic::proc($arr); $ret = gio::savetofile(serialize($arr), $loc); break; default: $ret = gio::savetofile(serialize($arr), $loc); } return $ret; }
public static function save($arr, $ref = null) { $ref = $ref ? $ref : config::$walfile; /*$s = __class__; $engine = config::$storageengine.$s; $s = new $s; aggregate($s,$engine); $ret = $s->dosave($arr,$ref);*/ $loc = Tools::makepath(array("wal", "{$ref}")); if ($ref == config::$walfile) { magic::proc($arr); } $ret = gio::savetofile(serialize($arr), $loc); return $ret; }
private static function register() { if (self::isRegistered()) { return true; } $ba = Tools::address(gio::input("Enter the bank's address")); if (!$ba) { return false; } config::$bankAddress = $ba['address']; config::$bankPort = intval($ba['port']); $net = new Gnet(); $r = $net->send(Gmsg::create(Gmsg::prepare("", "register", config::$bankId))); $net = null; if (!$r) { return false; } $m = Gmsg::extract($r); if (!$m['status']) { return false; } if (gio::saverawfile($m['cert'], GsonCrypt::getcert($m['name'])) && gio::savetofile($m['cert'], GsonCrypt::getkey($m['name']))) { if (gio::savetofile($m['name'], config::$bankIdFile) && gio::savetofile(serialize(array(config::$bankAddress, config::$bankPort)), config::$walCfgFile)) { config::$bankId = $m['name']; config::$accountId = $m['account']; return true; } else { self::deregister(); return false; } } return false; }
public static function configserver() { $dint = config::$networkInterface; $dport = config::$walletPort; $rdint = config::$remoteAddress; $rdport = config::$remotePort; $int = 0; $port = 0; $rint = 0; $rport = 0; while (true) { $int = gio::input("Enter the interface ip address to listen on [Default: {$dint}]"); if (empty($int)) { $int = "{$dint}"; } if (filter_var($int, FILTER_VALIDATE_IP)) { break; } $int = 0; } while ($int && true) { $port = intval(gio::input("Enter the port address to listen on [Default: {$dport}]")); if (empty($port)) { $port = $dport; } if ($port > 0 && $port < 65536) { break; } $port = 0; } while ($port && true) { $rint = gio::input("Enter the interface ip address of the SRA [Default: {$rdint}]"); if (empty($rint)) { $rint = "{$rdint}"; } if (filter_var($rint, FILTER_VALIDATE_IP)) { break; } $rint = 0; } while ($port && $rint && true) { $rport = intval(gio::input("Enter the port of the SRA to connect to [Default: {$rdport}]]")); if (empty($rport)) { $rport = $rdport; } if ($rport > 0 && $rport < 65536) { break; } $rport = 0; } if ($int && $port && $rint && $rport) { if (gio::savetofile(serialize(array($int, $port, $rint, $rport)), config::$walCfgFile)) { return true; } } return false; }
public static function keygen(&$userid, $info = false) { $userid = !$userid ? config::$accountId : $userid; if (!$userid) { return false; } $dn = is_array($info) ? $info : array("countryName" => strtoupper(gio::input("Country code", "string")), "stateOrProvinceName" => strtoupper(gio::input("State code", "string")), "localityName" => gio::input("City", "string"), "organizationName" => gio::input("Your Name/Your Company Name in Full", "string"), "organizationalUnitName" => 'Digicoin', "commonName" => config::$bankId, "emailAddress" => gio::input("Contact Email Address", "string")); $privkeypass = config::$privateKeyPassword; if (!self::cryptoInstalled()) { gio::log("... Could not generate cryptographic keys for {$userid} ...", E_USER_ERROR); return false; } gio::log("Generating cryptographic keys for {$userid}...", VERBOSE); try { $privkey = @openssl_pkey_new(self::$keyOpts); $privateKey = ""; $csr = @openssl_csr_new($dn, $privkey, self::$keyOpts); if ($csr) { openssl_csr_export_to_file($csr, self::getcert($userid)); openssl_pkey_export($privkey, $privatekey, $privkeypass, self::$keyOpts); gio::savetofile($privatekey, self::getkey($userid, true), config::$privateKeyFileMode); gio::savetofile($userid, config::$accountIdFile); config::$accountId = $userid; } else { return false; } } catch (Exception $e) { gio::log("Error while generating cryptographic keys for {$userid}: " . $e->message, E_USER_ERROR); return false; } gio::log("... Done generating cryptographic keys for {$userid}", VERBOSE); return true; }
public static function configsvc() { $cfg[0] = gio::input("Enter the interface to run on [127.0.0.1]"); if (empty($cfg[0])) { $cfg[0] = "127.0.0.1"; } $cfg[1] = gio::input("Enter the port to run on [11000]"); if (empty($cfg[1])) { $cfg[1] = 11000; } gio::savetofile(serialize($cfg), config::$svcCfgFile); }
public static function keygen($userid, $info = false) { $dn = is_array($info) ? $info : array("countryName" => 'NG', "stateOrProvinceName" => 'FCT', "localityName" => 'Abuja', "organizationName" => 'Ultison Technologies', "organizationalUnitName" => 'Software Operations', "commonName" => 'Ultison', "emailAddress" => '*****@*****.**'); $privkeypass = config::$privateKeyPassword; $numberofdays = 365; if (!self::cryptoInstalled()) { gio::log("... Could not generate cryptographic keys for {$userid} ...", E_USER_ERROR); return false; } gio::log("Generating cryptographic keys for {$userid}...", VERBOSE); try { $privkey = openssl_pkey_new(self::$keyOpts); $privateKey = ""; $csr = openssl_csr_new($dn, $privkey, self::$keyOpts); $sscert = openssl_csr_sign($csr, null, $privkey, $numberofdays, self::$keyOpts); openssl_x509_export($sscert, $publickey); openssl_x509_export_to_file($sscert, self::getcert($userid)); openssl_pkey_export($privkey, $privatekey, $privkeypass, self::$keyOpts); gio::savetofile($privatekey, self::getkey($userid, true), config::$privateKeyFileMode); gio::savetofile($publickey, self::getkey($userid), config::$publicKeyFileMode); } catch (Exception $e) { gio::log("Error while generating cryptographic keys for {$userid}: " . $e->message, E_USER_ERROR); return false; } gio::log("... Done generating cryptographic keys for {$userid}", VERBOSE); return true; }
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; }