Example #1
0
 public static function SignChannel($channelId)
 {
     $signatureKey = COption::GetOptionString("pull", "signature_key", "");
     if ($signatureKey === "" || !is_string($channelId)) {
         return $channelId;
     }
     $signatureAlgo = COption::GetOptionString("pull", "signature_algo", "sha1");
     $hmac = new Sign\HmacAlgorithm();
     $hmac->setHashAlgorithm($signatureAlgo);
     $signer = new Sign\Signer($hmac);
     $signer->setKey($signatureKey);
     return $signer->sign($channelId);
 }
 public static function getSrcWithResize($file = array(), $size = array())
 {
     $file1 = \CFile::ResizeImageGet($file["ID"], $size, BX_RESIZE_IMAGE_PROPORTIONAL, false);
     $src = $file1['src'];
     if ($file['HANDLER_ID'] > 0) {
         $src = "/" . \COption::GetOptionString("main", "upload_dir", "upload") . "/" . $file["SUBDIR"] . "/" . $file["FILE_NAME"];
         $path = $_SERVER["DOCUMENT_ROOT"] . $src;
         if (!(is_file($path) && file_exists($path))) {
             $sign = new Signer();
             $s = $sign->sign($file["ID"] . "x" . $size["width"] . "x" . $size["height"], self::$salt);
             $src = \COption::GetOptionString("main.fileinput", "entryPointUrl", "/bitrix/tools/upload.php") . "?" . http_build_query(array("action" => "uncloud", "mode" => "resize", "file" => $file["ID"], "width" => $size["width"], "height" => $size["height"], "signature" => $s));
         }
     }
     return $src;
 }
Example #3
0
 /**
  * Sets component arResult array
  */
 protected function prepareData()
 {
     $signer = new Main\Security\Sign\Signer();
     $this->arResult['METADATA'] = $this->arParams['METADATA'];
     $this->setDynamicPreview();
     $this->arResult['FIELD_NAME'] = $this->arParams['PARAMS']['arUserField']['FIELD_NAME'];
     if ($this->arResult['METADATA']['ID'] > 0) {
         $this->arResult['FIELD_VALUE'] = $signer->sign($this->arResult['METADATA']['ID'], Main\UrlPreview\UrlPreview::SIGN_SALT);
     } else {
         $this->arResult['FIELD_VALUE'] = null;
     }
     $this->arResult['FIELD_ID'] = $this->arParams['PARAMS']['arUserField']['ID'];
     $this->arResult['ELEMENT_ID'] = $this->arParams['PARAMS']['urlPreviewId'];
     $this->arResult['SELECT_IMAGE'] = $this->editMode && empty($this->arResult['METADATA']['EMBED']) && is_array($this->arResult['METADATA']['EXTRA']) && is_array($this->arResult['METADATA']['EXTRA']['IMAGES']);
     if ($this->arResult['SELECT_IMAGE']) {
         $this->arResult['SELECTED_IMAGE'] = $this->arResult['METADATA']['EXTRA']['SELECTED_IMAGE'] ?: 0;
     } else {
         $this->arResult['METADATA']['CONTAINER']['CLASSES'] = "";
         if (isset($this->arParams['~METADATA']['EMBED']) && $this->arParams['~METADATA']['EMBED'] != '') {
             $this->arResult['METADATA']['EMBED'] = $this->arParams['~METADATA']['EMBED'];
         } else {
             $this->arResult['METADATA']['EMBED'] = null;
         }
         if ($this->arResult['METADATA']['IMAGE_ID'] > 0 && ($imageFile = \CFile::GetFileArray($this->arResult['METADATA']['IMAGE_ID']))) {
             $this->arResult['METADATA']['IMAGE'] = $imageFile['SRC'];
             if ($imageFile['HEIGHT'] > $imageFile['WIDTH'] * 1.5) {
                 $this->arResult['METADATA']['CONTAINER']['CLASSES'] .= " urlpreview__container-left";
             }
         }
         $this->arResult['SHOW_CONTAINER'] = isset($this->arResult['METADATA']['IMAGE']) && $this->arResult['METADATA']['IMAGE'] != '' || isset($this->arResult['METADATA']['EMBED']) && $this->arResult['METADATA']['EMBED'] != '';
         if (isset($this->arResult['METADATA']['IMAGE']) && $this->arResult['METADATA']['IMAGE'] != '' && isset($this->arResult['METADATA']['EMBED']) && $this->arResult['METADATA']['EMBED'] != '') {
             $this->arResult['METADATA']['CONTAINER']['CLASSES'] .= " urlpreview__container-switchable";
             $this->arResult['METADATA']['CONTAINER']['CLASSES'] .= " urlpreview__container-hide-embed";
         }
     }
 }
Example #4
0
 /**
  * @param string $value
  * @param string $time
  * @param string|null $salt
  * @return string
  */
 public function sign($value, $time, $salt = null)
 {
     $timestamp = $this->getTimeStamp($time);
     $value = $value . $this->separator . $timestamp;
     return parent::sign($value, $salt);
 }
Example #5
0
 public function sign($value, $salt = null)
 {
     $valueEnc = base64_encode(Json::encode($value));
     return parent::sign($valueEnc, $salt);
 }
Example #6
0
 /**
  * Sign message with expired time, return string in format:
  *  {message}{separator}{expired timestamp}{separator}{signature}
  *
  * Simple example:
  * <code>
  *  // If salt needed
  *  $foo = (new TimeSigner)->sign('test', '+1 hour', 'my_salt');
  *
  *  // Otherwise
  *  $bar = (new TimeSigner)->sign('test', '+1 day');
  * </code>
  *
  * @param string $value Message for signing.
  * @param string $time Timestamp or datetime description (presented in format accepted by strtotime).
  * @param string|null $salt Salt, if needed.
  * @return string
  */
 public function sign($value, $time, $salt = null)
 {
     $timestamp = $this->getTimeStamp($time);
     $value = $this->pack(array($value, $timestamp));
     return parent::sign($value, $salt);
 }
 /**
  * Hook executed after fetching value of the user type. Signs returned value.
  * @param array $userField Array containing parameters of the user field.
  * @param array $value Unsigned value of the user field.
  * @return string Signed value of the user field.
  */
 public static function onAfterFetch($userField, $value)
 {
     $result = null;
     if (isset($value['VALUE'])) {
         $signer = new Signer();
         $result = $signer->sign((string) $value['VALUE'], UrlPreview::SIGN_SALT);
     }
     return $result;
 }
 public static function sign($params = array())
 {
     $sign = new Signer();
     return $sign->sign(base64_encode(serialize($params)), "fileinput");
 }
Example #9
0
 /**
  * @param $moduleId
  * @param $arFields
  * @return string
  * @throws \Bitrix\Main\ArgumentTypeException
  */
 public static function getSignedTag($moduleId, $arFields)
 {
     $tag = static::getTag($moduleId, $arFields);
     $signer = new Signer();
     return $signer->sign($tag, static::SIGN_SALT_ACTION);
 }