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); }
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 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; }