gremove unused code
This commit is contained in:
parent
bf04a21973
commit
93771f735b
|
@ -473,60 +473,6 @@ class Crypt {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encrypts content symmetrically and generates keyfile asymmetrically
|
||||
* @returns array containing catfile and new keyfile.
|
||||
* keys: data, key
|
||||
* @note this method is a wrapper for combining other crypt class methods
|
||||
*/
|
||||
public static function keyEncryptKeyfile( $plainContent, $publicKey, $path ) {
|
||||
|
||||
$user = \OCP\User::getUser();
|
||||
$view = new \OC_FilesystemView('/');
|
||||
$util = new Util($view, $user);
|
||||
|
||||
// Encrypt plain data, generate keyfile & encrypted file
|
||||
$cryptedData = self::symmetricEncryptFileContentKeyfile( $plainContent );
|
||||
|
||||
// Encrypt keyfile
|
||||
|
||||
$sharingEnabled = \OCP\Share::isEnabled();
|
||||
|
||||
// if file exists try to get sharing users
|
||||
if($view->file_exists($path)) {
|
||||
$uniqueUserIds = $util->getSharingUsersArray( $sharingEnabled, $path, $user );
|
||||
} else {
|
||||
$uniqueUserIds[] = $user;
|
||||
}
|
||||
|
||||
// Fetch public keys for all users who will share the file
|
||||
$publicKeys = Keymanager::getPublicKeys( $view, $uniqueUserIds );
|
||||
|
||||
// Encrypt plain keyfile to multiple sharefiles
|
||||
$multiEncrypted = Crypt::multiKeyEncrypt( $cryptedData['key'], $publicKeys );
|
||||
|
||||
return array( 'data' => $cryptedData['encrypted'], 'filekey' => $multiEncrypted['data'], 'sharekeys' => $multiEncrypted['keys'] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Takes catfile, keyfile, and private key, and
|
||||
* performs decryption
|
||||
* @returns decrypted content
|
||||
* @note this method is a wrapper for combining other crypt class methods
|
||||
*/
|
||||
public static function keyDecryptKeyfile( $catfile, $keyfile, $privateKey ) {
|
||||
|
||||
// Decrypt the keyfile with the user's private key
|
||||
$decryptedKeyfile = self::keyDecrypt( $keyfile, $privateKey );
|
||||
|
||||
// Decrypt the catfile symmetrically using the decrypted keyfile
|
||||
$decryptedData = self::symmetricDecryptFileContent( $catfile, $decryptedKeyfile );
|
||||
|
||||
return $decryptedData;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Symmetrically encrypt a file by combining encrypted component data blocks
|
||||
*/
|
||||
|
@ -743,13 +689,17 @@ class Crypt {
|
|||
|
||||
}
|
||||
|
||||
public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase, $path ) {
|
||||
public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKeys, $newPassphrase, $path ) {
|
||||
|
||||
$decrypted = self::legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase );
|
||||
|
||||
$recrypted = self::keyEncryptKeyfile( $decrypted, $publicKey, $path );
|
||||
// Encrypt plain data, generate keyfile & encrypted file
|
||||
$cryptedData = self::symmetricEncryptFileContentKeyfile( $decrypted );
|
||||
|
||||
return $recrypted;
|
||||
// Encrypt plain keyfile to multiple sharefiles
|
||||
$multiEncrypted = Crypt::multiKeyEncrypt( $cryptedData['key'], $publicKeys );
|
||||
|
||||
return array( 'data' => $cryptedData['encrypted'], 'filekey' => $multiEncrypted['data'], 'sharekeys' => $multiEncrypted['keys'] );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -683,7 +683,6 @@ class Util {
|
|||
|
||||
// Close access to original file
|
||||
// $this->view->fclose( $plainHandle1 ); // not implemented in view{}
|
||||
|
||||
// Delete original plain file so we can rename enc file later
|
||||
$this->view->unlink($rawPath);
|
||||
|
||||
|
@ -701,7 +700,6 @@ class Util {
|
|||
|
||||
// Add the file to the cache
|
||||
\OC\Files\Filesystem::putFileInfo($plainFile['path'], array('encrypted' => true, 'size' => $size), '');
|
||||
|
||||
}
|
||||
|
||||
// Encrypt legacy encrypted files
|
||||
|
@ -715,8 +713,20 @@ class Util {
|
|||
// Fetch data from file
|
||||
$legacyData = $this->view->file_get_contents($legacyFile['path']);
|
||||
|
||||
$sharingEnabled = \OCP\Share::isEnabled();
|
||||
|
||||
// if file exists try to get sharing users
|
||||
if ($view->file_exists($legacyFile['path'])) {
|
||||
$uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $legacyFile['path'], $this->userId);
|
||||
} else {
|
||||
$uniqueUserIds[] = $this->userId;
|
||||
}
|
||||
|
||||
// Fetch public keys for all users who will share the file
|
||||
$publicKeys = Keymanager::getPublicKeys($this->view, $uniqueUserIds);
|
||||
|
||||
// Recrypt data, generate catfile
|
||||
$recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKey, $newPassphrase, $legacyFile['path'] );
|
||||
$recrypted = Crypt::legacyKeyRecryptKeyfile($legacyData, $legacyPassphrase, $publicKey, $newPassphrase, $legacyFile['path'], $publicKeys);
|
||||
|
||||
$rawPath = $legacyFile['path'];
|
||||
$relPath = $this->stripUserFilesPath($rawPath);
|
||||
|
@ -734,23 +744,18 @@ class Util {
|
|||
|
||||
// Add the file to the cache
|
||||
\OC\Files\Filesystem::putFileInfo($rawPath, array('encrypted' => true, 'size' => $size), '');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
\OC_FileProxy::$enabled = true;
|
||||
|
||||
// If files were found, return true
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
// If no files were found, return false
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -514,47 +514,6 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
}
|
||||
|
||||
// What is the point of this test? It doesn't use keyEncryptKeyfile()
|
||||
function testKeyEncryptKeyfile() {
|
||||
|
||||
# TODO: Don't repeat encryption from previous tests, use PHPUnit test interdependency instead
|
||||
|
||||
// Generate keypair
|
||||
$pair1 = Encryption\Crypt::createKeypair();
|
||||
|
||||
// Encrypt plain data, generate keyfile & encrypted file
|
||||
$cryptedData = Encryption\Crypt::symmetricEncryptFileContentKeyfile( $this->dataUrl );
|
||||
|
||||
// Encrypt keyfile
|
||||
$cryptedKey = Encryption\Crypt::keyEncrypt( $cryptedData['key'], $pair1['publicKey'] );
|
||||
|
||||
// Decrypt keyfile
|
||||
$decryptKey = Encryption\Crypt::keyDecrypt( $cryptedKey, $pair1['privateKey'] );
|
||||
|
||||
// Decrypt encrypted file
|
||||
$decryptData = Encryption\Crypt::symmetricDecryptFileContent( $cryptedData['encrypted'], $decryptKey );
|
||||
|
||||
$this->assertEquals( $this->dataUrl, $decryptData );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test functionality of keyEncryptKeyfile() and
|
||||
* keyDecryptKeyfile()
|
||||
*/
|
||||
function testKeyDecryptKeyfile() {
|
||||
|
||||
$encrypted = Encryption\Crypt::keyEncryptKeyfile( $this->dataShort, $this->genPublicKey );
|
||||
|
||||
$this->assertNotEquals( $encrypted['data'], $this->dataShort );
|
||||
|
||||
$decrypted = Encryption\Crypt::keyDecryptKeyfile( $encrypted['data'], $encrypted['key'], $this->genPrivateKey );
|
||||
|
||||
$this->assertEquals( $decrypted, $this->dataShort );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief test encryption using legacy blowfish method
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue