generate random key name for share key to avoid name conflicts

This commit is contained in:
Björn Schießle 2013-05-13 15:15:35 +02:00
parent a6ef25ba08
commit d1e2e47592
4 changed files with 69 additions and 54 deletions

View File

@ -365,9 +365,9 @@ class Hooks {
$userIds = \OC_Group::usersInGroup($params['shareWith']);
} else {
} else if ( $params['shareType'] == \OCP\Share::SHARE_TYPE_LINK ){
$userIds = array( $params['shareWith'] );
$userIds = array( $util->getPublicShareKeyId() );
}

View File

@ -45,10 +45,17 @@ class Session {
$this->view->mkdir( 'owncloud_private_key' );
}
$publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId');
if ($publicShareKeyId === null) {
$publicShareKeyId = substr(md5(time()),0,8);
\OC_Appconfig::setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId);
}
if (
! $this->view->file_exists( "/public-keys/owncloud.public.key" )
|| ! $this->view->file_exists( "/owncloud_private_key/owncloud.private.key" )
! $this->view->file_exists( "/public-keys/".$publicShareKeyId.".public.key" )
|| ! $this->view->file_exists( "/owncloud_private_key/".$publicShareKeyId.".private.key" )
) {
//FIXME: Bug: for some reason file_exists is returning
@ -57,23 +64,23 @@ class Session {
// our app.php is being executed 18 times per page load
// , causing 18 new keypairs and huge performance hit.
// $keypair = Crypt::createKeypair();
//
// \OC_FileProxy::$enabled = false;
//
// // Save public key
//
// if (!$view->is_dir('/public-keys')) {
// $view->mkdir('/public-keys');
// }
//
// $this->view->file_put_contents( '/public-keys/owncloud.public.key', $keypair['publicKey'] );
//
// // Encrypt private key empthy passphrase
// $encryptedPrivateKey = Crypt::symmetricEncryptFileContent( $keypair['privateKey'], '' );
//
// // Save private key
// $this->view->file_put_contents( '/owncloud_private_key/owncloud.private.key', $encryptedPrivateKey );
$keypair = Crypt::createKeypair();
\OC_FileProxy::$enabled = false;
// Save public key
if (!$view->is_dir('/public-keys')) {
$view->mkdir('/public-keys');
}
$this->view->file_put_contents( '/public-keys/'.$publicShareKeyId.'.public.key', $keypair['publicKey'] );
// Encrypt private key empthy passphrase
$encryptedPrivateKey = Crypt::symmetricEncryptFileContent( $keypair['privateKey'], '' );
// Save private key
$this->view->file_put_contents( '/owncloud_private_key/'.$publicShareKeyId.'.private.key', $encryptedPrivateKey );
\OC_FileProxy::$enabled = true;

View File

@ -108,6 +108,7 @@ class Util {
private $shareKeysPath; // Dir containing env keys for shared files
private $publicKeyPath; // Path to user's public key
private $privateKeyPath; // Path to user's private key
private $publicShareKeyId;
public function __construct( \OC_FilesystemView $view, $userId, $client = false ) {
@ -123,7 +124,7 @@ class Util {
$this->shareKeysPath = $this->encryptionDir . '/' . 'share-keys';
$this->publicKeyPath = $this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
$this->privateKeyPath = $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
$this->publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId');
}
public function ready() {
@ -211,6 +212,10 @@ class Util {
return true;
}
public function getPublicShareKeyId() {
return $this->publicShareKeyId;
}
/**
* @brief Check whether pwd recovery is enabled for a given user
@ -792,7 +797,7 @@ class Util {
// Check that the user is encryption capable, or is the
// public system user 'ownCloud' (for public shares)
if (
$user == 'owncloud'
$user == $this->publicShareKeyId
or $util->ready()
) {

View File

@ -133,17 +133,17 @@ class Share {
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
*/
public static function getUsersSharingFile( $path, $user, $includeOwner = false, $removeDuplicates = true ) {
public static function getUsersSharingFile($path, $user, $includeOwner = false, $removeDuplicates = true) {
$path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
$path = '';
$shares = array();
$view = new \OC\Files\View('/'.$user.'/files/');
$view = new \OC\Files\View('/' . $user . '/files/');
foreach ($path_parts as $p) {
$path .= '/'.$p;
$path .= '/' . $p;
$meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path));
$source = $meta['fileid'];
// Fetch all shares of this file path from DB
$query = \OC_DB::prepare(
'SELECT share_with
@ -152,14 +152,14 @@ class Share {
WHERE
item_source = ? AND share_type = ?'
);
$result = $query->execute( array( $source, self::SHARE_TYPE_USER ) );
if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
$result = $query->execute(array($source, self::SHARE_TYPE_USER));
if (\OC_DB::isError($result)) {
\OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
}
while( $row = $result->fetchRow() ) {
while ($row = $result->fetchRow()) {
$shares[] = $row['share_with'];
}
@ -172,44 +172,47 @@ class Share {
WHERE
item_source = ? AND share_type = ?'
);
$result = $query->execute( array( $source, self::SHARE_TYPE_GROUP ) );
if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
$result = $query->execute(array($source, self::SHARE_TYPE_GROUP));
if (\OC_DB::isError($result)) {
\OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
}
while( $row = $result->fetchRow() ) {
while ($row = $result->fetchRow()) {
$usersInGroup = \OC_Group::usersInGroup($row['share_with']);
$shares = array_merge($shares, $usersInGroup);
}
//check for public link shares
$query = \OC_DB::prepare(
'SELECT share_with
$publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId');
if ($publicShareKeyId) {
//check for public link shares
$query = \OC_DB::prepare(
'SELECT share_with
FROM
`*PREFIX*share`
WHERE
item_source = ? AND share_type = ?'
);
$result = $query->execute( array( $source, self::SHARE_TYPE_LINK ) );
if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
}
if ($result->fetchRow()) {
$shares[] = "owncloud";
);
$result = $query->execute(array($source, self::SHARE_TYPE_LINK));
if (\OC_DB::isError($result)) {
\OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
}
if ($result->fetchRow()) {
$shares[] = $publicShareKeyId;
}
}
}
// Include owner in list of users, if requested
if ( $includeOwner ) {
if ($includeOwner) {
$shares[] = $user;
}
return array_unique($shares);
return array_unique($shares);
}
/**