Exemplo n.º 1
0
 public function SaveUserInfo($usedb = false)
 {
     if ($this->user_cache["changed"]) {
         $cdata = array("c" => $this->user_cache["ts"], "s" => $this->user_info["sso_id"], "i" => $this->user_info["id"], "e" => $this->user_info["extra"]);
         if (count($this->user_info["tag_map"])) {
             $cdata["t"] = $this->user_info["tag_map"];
             foreach ($cdata["t"] as $key => $val) {
                 $cdata["t"][$key] = 1;
             }
         }
         if ($this->user_info["admin"]) {
             $cdata["a"] = 1;
         }
         if ($usedb && $this->user_cache["hasdb"]) {
             $cdata["b"] = 1;
         }
         if (count($this->user_cache["data"])) {
             $cdata["d"] = $this->user_cache["data"];
         }
         $cdata["p"] = $this->user_cache["ipaddr"];
         $cdata = @json_encode($cdata);
         if (function_exists("gzcompress") && function_exists("gzuncompress")) {
             $cdata = "1:" . @gzcompress($cdata);
         } else {
             $cdata = "0:" . $cdata;
         }
         $vdata = hash_hmac("sha1", $cdata . ":" . SSO_SERVER_APIKEY, pack("H*", SSO_CLIENT_RAND_SEED6), true);
         $vdata = str_replace(array("+", "/", "="), array("-", "_", ""), base64_encode($vdata));
         $mode = SSO_COOKIE_CIPHER == "aes256" ? "aes256" : "blowfish";
         $key = pack("H*", SSO_CLIENT_RAND_SEED);
         $options = array("prefix" => $this->rng->GenerateToken(), "mode" => "CBC", "iv" => pack("H*", SSO_CLIENT_RAND_SEED2), "lightweight" => true);
         if (SSO_COOKIE_DUAL_ENCRYPT) {
             $options["key2"] = pack("H*", SSO_CLIENT_RAND_SEED4);
             $options["iv2"] = pack("H*", SSO_CLIENT_RAND_SEED5);
         }
         if ($mode == "aes256") {
             $cdata = SSO_ExtendedAES::CreateDataPacket($cdata, $key, $options);
         } else {
             $cdata = SSO_Blowfish::CreateDataPacket($cdata, $key, $options);
         }
         $cdata = str_replace(array("+", "/", "="), array("-", "_", ""), base64_encode($cdata));
         if (!isset($this->request[SSO_COOKIE_NAME . "_c"])) {
             $this->SetCookieFixDomain(SSO_COOKIE_NAME . "_c", "1", 0, SSO_COOKIE_PATH, "", SSO_COOKIE_SSL_ONLY);
         }
         if (!isset($this->request[SSO_COOKIE_NAME . "_s"]) || $this->request[SSO_COOKIE_NAME . "_s"] != $cdata) {
             $this->SetCookieFixDomain(SSO_COOKIE_NAME . "_s", $cdata, SSO_COOKIE_TIMEOUT > 0 ? time() + SSO_COOKIE_TIMEOUT : 0, SSO_COOKIE_PATH, "", SSO_COOKIE_SSL_ONLY, true);
         }
         if (!isset($this->request[SSO_COOKIE_NAME . "_v"]) || $this->request[SSO_COOKIE_NAME . "_v"] != $vdata) {
             $this->SetCookieFixDomain(SSO_COOKIE_NAME . "_v", $vdata, SSO_COOKIE_TIMEOUT > 0 && !SSO_COOKIE_EXIT_TIMEOUT ? time() + SSO_COOKIE_TIMEOUT : 0, SSO_COOKIE_PATH, "", SSO_COOKIE_SSL_ONLY, true);
         }
         $this->user_cache["changed"] = false;
     }
 }