Plugin Directory

Changeset 1760657


Ignore:
Timestamp:
11/08/2017 10:05:53 AM (8 years ago)
Author:
frankverhoeven
Message:

remove crypt crap

Location:
fv-community-news/trunk/fvcn-includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fv-community-news/trunk/fvcn-includes/fvcn-core-classes.php

    r595527 r1760657  
    9595
    9696    /**
    97      * getCrypt()
    98      *
    99      * @version 20120709
    100      * @return FvCommunityNews_Crypt
    101      */
    102     public function getCrypt()
    103     {
    104         if (isset($this->_objects['crypt'])) {
    105             return $this->_objects['crypt'];
    106         }
    107 
    108         return $this->_objects['crypt'] = new FvCommunityNews_Crypt( fvcn_get_option('_fvcn_sync_key') );
    109     }
    110 
    111     /**
    11297     * getJavascript()
    11398     *
     
    166151        }
    167152
    168         return $this->_objects['sync'] = new FvCommunityNews_Sync( $this->getCrypt() );
     153        return $this->_objects['sync'] = new FvCommunityNews_Sync();
    169154    }
    170155
  • fv-community-news/trunk/fvcn-includes/fvcn-core-sync.php

    r595527 r1760657  
    1313if (!defined('ABSPATH')) {
    1414    die('Direct access is not allowed!');
    15 }
    16 
    17 
    18 /**
    19  * FvCommunityNews_Crypt
    20  *
    21  * Rijndael 128 bit encryption.
    22  *
    23  * @author Frank Verhoeven <info@frank-verhoeven.com>
    24  */
    25 class FvCommunityNews_Crypt
    26 {
    27     const CIPHER = MCRYPT_RIJNDAEL_128;
    28     const MODE   = MCRYPT_MODE_CBC;
    29    
    30     /**
    31      * @var string
    32      */
    33     protected $_key = null;
    34    
    35     /**
    36      * @var string
    37      */
    38     protected $_iv  = null;
    39    
    40     /**
    41      * __construct()
    42      *
    43      * @version 20120701
    44      * @param string $key
    45      * @param string $iv
    46      */
    47     public function __construct($key, $iv=null)
    48     {
    49         $this->setKey($key);
    50        
    51         if (null !== $iv) {
    52             $this->setIv($iv);
    53         }
    54     }
    55    
    56     /**
    57      * canEncrypt()
    58      *
    59      * @version 20120701
    60      * @return bool
    61      */
    62     public function canEncrypt()
    63     {
    64         return extension_loaded('mcrypt');
    65     }
    66    
    67     /**
    68      * setKey()
    69      *
    70      * @version 20120701
    71      * @param string $key
    72      * @return FvCommunityNews_Crypt
    73      */
    74     public function setKey($key)
    75     {
    76         $this->_key = (string) $key;
    77         return $this;
    78     }
    79    
    80     /**
    81      * getKey()
    82      *
    83      * @version 20120701
    84      * @return string
    85      */
    86     public function getKey()
    87     {
    88         if (strlen($this->_key) > mcrypt_get_key_size(self::CIPHER, self::MODE)) {
    89             return substr($this->_key, 1, mcrypt_get_key_size(self::CIPHER, self::MODE));
    90         }
    91        
    92         return $this->_key;
    93     }
    94    
    95     /**
    96      * createIv()
    97      *
    98      * @version 20120701
    99      * @return string
    100      */
    101     public function createIv()
    102     {
    103         $iv = mcrypt_create_iv(mcrypt_get_iv_size(self::CIPHER, self::MODE), MCRYPT_RAND);
    104        
    105         if (false === $iv) {
    106             throw new Exception('Failed to create an initialization vector.');
    107         }
    108        
    109         return $this->setIv( $iv )->getIv();
    110     }
    111    
    112     /**
    113      * setIv()
    114      *
    115      * @version 20120701
    116      * @param string $iv
    117      * @return FvCommunityNews_Crypt
    118      */
    119     public function setIv($iv)
    120     {
    121         if (0 !== mcrypt_get_iv_size(self::CIPHER, self::MODE) && strlen($iv) != mcrypt_get_iv_size(self::CIPHER, self::MODE)) {
    122             throw new Exception('Invallid IV size.');
    123         }
    124        
    125         $this->_iv = $iv;
    126         return $this;
    127     }
    128    
    129     /**
    130      * getIv()
    131      *
    132      * @version 20120701
    133      * @return string
    134      */
    135     public function getIv()
    136     {
    137         if (null !== $this->_iv) {
    138             return $this->_iv;
    139         }
    140        
    141         return $this->createIv();
    142     }
    143    
    144     /**
    145      * encrypt()
    146      *
    147      * @version 20120701
    148      * @param string $value
    149      * @return string
    150      */
    151     public function encrypt($value)
    152     {
    153         $encrypted = mcrypt_encrypt(self::CIPHER, $this->getKey(), trim($value), self::MODE, $this->getIv());
    154        
    155         return base64_encode( $encrypted );
    156     }
    157    
    158     /**
    159      * decrypt()
    160      *
    161      * @version 20120701
    162      * @param string $value
    163      * @return string
    164      */
    165     public function decrypt($value)
    166     {
    167         $decrypted = mcrypt_decrypt(self::CIPHER, $this->getKey(), base64_decode($value), self::MODE, $this->getIv());
    168        
    169         return rtrim($decrypted, "\0\4");
    170     }
    17115}
    17216
     
    20145     */
    20246    protected $_registered = false;
    203    
    204     /**
    205      * @var FvCommunityNews_Crypt
    206      */
    207     protected $_crypt   = null;
    208    
     47
    20948    /**
    21049     * __construct()
    21150     *
    21251     * @version 20120716
    213      * @param FvCommunityNews_Crypt $crypt
    214      */
    215     public function __construct(FvCommunityNews_Crypt $crypt)
    216     {
    217         $this->_crypt = $crypt;
     52     */
     53    public function __construct()
     54    {
    21855        $this->_setupOptions();
    21956       
     
    285122    protected function _encryptData(array $data, $root=true)
    286123    {
    287         if (!$this->_crypt->canEncrypt()) {
    288             if ($root) {
    289                 $data['encrypted'] = false;
    290             }
    291            
    292             return $data;
    293         }
    294        
    295         foreach ($data as $key=>$val) {
    296             if (is_array($val)) {
    297                 $data[ $key ] = $this->_encryptData($val, false);
    298             } else {
    299                 $data[ $key ] = $this->_crypt->encrypt($val);
    300             }
    301         }
    302        
    303         if ($root) {
    304             $data['encrypted']  = true;
    305             $data['validator']  = $this->_crypt->encrypt( home_url('/') );
    306             $data['iv']         = base64_encode( $this->_crypt->getIv() );
    307         }
    308        
    309124        return $data;
    310125    }
     
    385200        return $this;
    386201    }
    387    
    388     /**
    389     * increasePostViewCount()
    390     *
    391     * @version 20120712
    392      * @paran int $postId
    393     * @return FvCommunityNews_Sync
    394     */
     202
     203    /**
     204    * increasePostViewCount()
     205    *
     206    * @version 20120712
     207     * @param int $postId
     208    * @return FvCommunityNews_Sync
     209    */
    395210    public function increasePostViewCount($postId)
    396211    {
  • fv-community-news/trunk/fvcn-includes/fvcn-core-validate.php

    r595527 r1760657  
    392392    public function isValid($value)
    393393    {
    394         $crypt = new FvCommunityNews_Crypt( hash('sha256', wp_create_nonce('fvcn-post-form-time-key')) );
    395         if ($crypt->canEncrypt()) {
    396             $value = explode(':', $value);
    397             if (2 != count($value)) {
    398                 return false;
    399             }
    400            
    401             try {
    402                 $time = (int) $crypt->setIv( base64_decode($value[0]) )->decrypt($value[1]);
    403             } catch (Exception $e) {
    404                 return false;
    405             }
    406         } else {
    407             $time = (int) base64_decode($value);
    408         }
    409        
     394        $time = (int) base64_decode($value);
     395
    410396        // min 15 sec, max 1 hour
    411397        if ($time+15 > time() || time()-3600 > $time) {
  • fv-community-news/trunk/fvcn-includes/fvcn-post-template.php

    r603255 r1760657  
    12441244    <input type="hidden" name="fvcn_post_form_action" id="fvcn_post_form_action" value="fvcn-new-post" />
    12451245    <?php wp_nonce_field('fvcn-new-post', 'fvcn_post_form_nonce'); ?>
    1246    
    1247     <?php
    1248     $crypt = new FvCommunityNews_Crypt( hash('sha256', wp_create_nonce('fvcn-post-form-time-key')) );
    1249    
    1250     if ($crypt->canEncrypt()) {
    1251         $value = base64_encode($crypt->getIv()) . ':' . $crypt->encrypt( time() );
    1252     } else {
    1253         $value = base64_encode( time() );
    1254     }
    1255     ?>
    1256    
     1246    <?php $value = base64_encode( time() ); ?>
    12571247    <input type="hidden" name="fvcn_post_form_time_key" id="fvcn_post_form_time_key" value="<?php echo $value; ?>" />
    12581248   
Note: See TracChangeset for help on using the changeset viewer.