代码之家  ›  专栏  ›  技术社区  ›  John

安全HIPAA ePHI加密

  •  4
  • John  · 技术社区  · 16 年前

    我需要做的事情: 2.强大的访问控制 3.支持大量用户和文件(100多万) 5.加密

    建议的解决方案
    0)将web应用放在防火墙后面的安全专用服务器上

    1) 将文件存储在一个文件中,例如secure\u files/,然后使用mod\u rewrite来限制对此目录的访问。

    一些关于:

    #Removes access to the secure_files folder by users.
    RewriteCond %{REQUEST_URI} ^secure_files.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    

    然后使用php脚本打开文件,如果用户有权限这样做。所以我可以用:

    ------
    -SQL
    ------
    
    ------
    - create files table
    -----
    CREATE TABLE `files` (
    id INT NOT NULL AUTO_INCREMENT,
    file_name VARCHAR(50) NOT NULL,
    PRIMARY KEY('id')
    );
    
    ------
    - create files table
    -----
    CREATE TABLE `privileges` (
    uesr_id INT NOT NULL,
    file_id INT NOT NULL,
    );
    
    ------
    - create users table
    -----
    CREATE TABLE `users` (
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR(20) NOT NULL,
    email VARCHAR(50) NOT NULL,
    password CHAR(40) NOT NULL,
    PRIMARY KEY('id')
    );
    
    <?php
    public function get_user_files($filename)
    {
       //this is set during login
       $user_id = $this->session->userdata('user_id');
    
       //check to see if the user has privileges to access the file and gets the file name
       $query = $this->db->join('privileges','privileges.id = files.id')
                         ->select('files.file_name')
                         ->where('privileges.user_id',$user_id)
                         ->where('files.file_name',$file_name)
                         ->limit(1)
                         ->get('files');
    
        $file = $query->row()->files.file_name;
    
       if($file)
       {
        //user has privileges to access the file so include it
        $handle = fopen($file, "rb");
        $data['file'] = fread($handle, filesize($file));
        fclose($handle);
       }
      $this->load->view('files',$data);
    }
    ?>
    

    2) 使用CI会话类将用户添加到会话。

    控制器检查会话是否已设置:

    <?php
    public function __construct()        
        {
            parent::__construct();
    
            if($this->secure(array('userType' => 'user')) == FALSE)
            {
                $this->session->set_flashdata('flashError', 'You must be logged into a valid user account to access this section.');
                $this->session->sess_destroy();
                redirect('login');
            }
        }    
    
    function secure($options = array())
        {            
            $userType = $this->session->userdata('userType');
    
            if(is_array($options['userType']))
            {
                foreach($options['userType'] as $optionUserType)
                {
                    if($optionUserType == $userType) return true;
                }
            }
            else
            {
                if($userType == $options['userType']) return true;
            }
            return false;
        }
    ?>
    

    3) 在多个web服务器之间循环。我从来没有这样做过,所以我不知道怎么做。我不知道如何处理多个数据库服务器。有什么想法/建议吗?

    4) 使用Oracle企业标准数据库审核。我希望我可以使用MySQL,但是我找不到任何审计支持。我可以使用MySQL和PITA。有人用过MySQL的时间点架构(PITA)吗?你能分享你的经历吗?

    谢谢你花时间通读这篇文章。


    采纳自Redux Auth

    关于单向散列。我说加密的错误。我通常会做类似的事情:

    salt_length='9'; { $salt\u length=$此->盐长度; 如果($password===false) { 返回false; $salt=$此->盐(); 返回$password; } 专用函数salt() 返回substr(md5(uniqid(rand(),true)),0,$this->盐(长度); } ?>
    1 回复  |  直到 16 年前
        1
  •  2
  •   Community Mohan Dere    9 年前

    编辑: 在sql数据库中加密敏感数据可抵御3种主要威胁。

    1. 内部威胁:

      系统管理员和开发人员。

    2. SQL注入:

      如果数据库配置正确,sql注入应该只向攻击者提供对应用程序数据库的访问权限,而不提供任何其他权限。在mysql中,请确保 FILE

    3. 更安全的备份:

      分层安全。

    带有单向咸哈希的密码。

    加密和散列不同。加密意味着有一种解密数据的方法。使用密码加密功能是 CWE-257 总是 使用salted散列,sha-256是一个很好的算法。盐应该是盐 Cryptographic nonce

    MySQL的 AES_ENCRYPT() 糟透了,它的用途 ECB mode 这太可怕了。如果函数调用没有IV,则可能是ECB模式,如果IV为null,则违反CWE-329。

    alt text

    使用ECB模式加密:

    alt text

    加密很困难,您必须担心初始化向量、操作模式、密钥存储和string2key函数。绝大多数程序员认为密码学很容易,但他们管理得很认真 mess things up "The Handbook" .

    编辑: 我不太喜欢你的nonce生成,因为它的熵/大小比不好。当你可以用碱性盐时,碱性盐是一种浪费。请记住 (可能所有)消息摘要实现都是二进制安全的。阿尔索 uniqid() 在计算中使用了大量的时间,如果它只使用时间,那么它将违反CWE-337 mt_rand() kicks ass . 还请记住,您可能应该将其存储为base64,然后在哈希函数中使用之前对其进行base64解码。

        public function nonce($size=32){//256 bit == 32byte. 
            for($x=0;$x<$size;$x++){
                $ret.=chr(mt_rand(0,255));
            }
            return base64_encode($ret);
        }