Example #1
0
 public function putObjectByFileSecurely($args = array())
 {
     $sek = EncryptionUtil::genereateOnceUsedKey();
     $encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials, $sek);
     if (!isset($args["Content"]) || !is_array($args["Content"]) || !isset($args["Content"]["content"]) || empty($args["Content"]["content"])) {
         throw new Ks3ClientException("please specifie file content in request args");
     }
     $content = $args["Content"];
     $plainTextLength = EncryptionUtil::plainTextLength($args);
     if ($plainTextLength <= 0) {
         throw new Ks3ClientException("get content length failed ,unexpected content length " . $plainTextLength);
     }
     $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
     $args = EncryptionUtil::updateContentMD5Header($args);
     $encryptedLength = EncryptionUtil::getPKCS5EncrypedLength($plainTextLength, mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
     $args["ObjectMeta"]["Content-Length"] = $encryptedLength;
     $args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
     $readCallBack = new AESCBCStreamReadCallBack();
     $readCallBack->iv = $iv;
     $readCallBack->cek = $sek;
     $readCallBack->contentLength = $plainTextLength;
     $args["readCallBack"] = $readCallBack;
     //TODO
     $matdesc = "{}";
     if (ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata") {
         $args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
         $args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
         $args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
     }
     $result = $this->ks3client->putObjectByFile($args);
     if (ENCRYPTPTION_STORAGE_MODE == "InstructionFile") {
         $req = EncryptionUtil::createInstructionFile($args["Bucket"], $args["Key"], base64_encode($encryptedSek), base64_encode($iv), $matdesc);
         $this->ks3client->putObjectByContent($req);
     }
     return $result;
 }