/** * The main page handler, outputs a 1x1 pixel image. */ public function get() { if ($t = Request::get('t', 'encrypted')) { // Track an encrypted link. if (!Tracker::trackLink($t)) { Logger::error('Failed to track encrypted link: ' . Encryption::aesDecrypt($t, Configuration::get('tracker.key'))); } } elseif (Configuration::get('tracker.allow_unencrypted') && ($tracker = Request::get('tracker', 'int'))) { // Track an unencrypted link. $user = Request::get('user', 'int') ?: ClientUser::createInstance()->id; $sub = Request::get('sub', 'int'); Tracker::trackEventID($tracker, $sub, $user); } // Output a single pixel image. header('Content-Type: image/png'); echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='); exit; }
/** * Load a user by an encrypted reference. * * @param string $cypher_string * The encrypted email address. * * @return bool|User * The user if loading was successful. */ public static function loadByEncryptedUserReference($cypher_string) { $email = Encryption::aesDecrypt($cypher_string, Configuration::get('user.key')); return static::loadByEmail($email); }
public function executeGenerateAesKey() { echo 'Key: ' . Encryption::generateAesKey() . "\n\n"; }
/** * Add a tracker hit from an encrypted link. * * @param string $tracker_string * Encrypted data. * * @return boolean * Whether the link was tracked. */ public static function trackLink($tracker_string) { // Decrypt and decode the string with the private key. $string = Encryption::aesDecrypt($tracker_string, Configuration::get('tracker.key')); if ($data = json_decode($string, true)) { // Track the data. self::trackEventID($data['tracker'], $data['sub'], $data['user']); return true; } return false; }
public static function decrypt($data) { // TODO: use remote AES encryption method for isolated HSM. $table_key = Configuration::get('lightning.table.encryption_key'); return Encryption::aesDecrypt($data, $table_key); }