$util = new Util( $view, $user );\r
\r
// Check that the user is encryption capable\r
- if ( $util->ready() ) {\r
+ if ( $util->ready() && $user == 'ownCloud' ) {\r
// Construct array of just UIDs for Keymanager{}\r
$userIds[] = $user;\r
\r
foreach ( $content as $c) {\r
$path = substr($c['path'], 5);\r
if ( $filesView->is_dir($path) ) {\r
- error_log("dive into $path");\r
$result &= self::updateKeyfile($path);\r
} else {\r
- error_log("encKeyFileToMultipleUsers $path");\r
$shares = \OCP\Share::getUsersSharingFile( $path, true );\r
$result &= self::encKeyfileToMultipleUsers($shares, $path);\r
}\r
}\r
} else {\r
- error_log("encKeyFileToMultipleUsers single file: " . $path);\r
$shares = \OCP\Share::getUsersSharingFile( $path, true );\r
$result = self::encKeyfileToMultipleUsers($shares, $path);\r
}\r
*/
class Session {
+
+ /**
+ * @brief if session is started, check if ownCloud key pair is set up, if not create it
+ *
+ * The ownCloud key pair is used to allow public link sharing even if encryption is enabled
+ */
+ public function __construct() {
+ $view = new \OC\Files\View('/');
+ if (!$view->is_dir('owncloud_private_key')) {
+ $view->mkdir('owncloud_private_key');
+ }
+
+ if (!$view->file_exists("/public-keys/owncloud.public.key") || !$view->file_exists("/owncloud_private_key/owncloud.private.key") ) {
+
+ $keypair = Crypt::createKeypair();
+
+ \OC_FileProxy::$enabled = false;
+ // Save public key
+ $view->file_put_contents( '/public-keys/owncloud.public.key', $keypair['publicKey'] );
+ // Encrypt private key empthy passphrase
+ $encryptedPrivateKey = Crypt::symmetricEncryptFileContent( $keypair['privateKey'], '' );
+ // Save private key
+ error_log("encrypted private key: " . $encryptedPrivateKey );
+ $view->file_put_contents( '/owncloud_private_key/owncloud.private.key', $encryptedPrivateKey );
+
+ \OC_FileProxy::$enabled = true;
+ }
+ }
/**
* @brief Sets user private key to session
}
if ($result->fetchRow()) {
- $shares[] = self::SHARE_TYPE_LINK;
+ $shares[] = "ownCloud";
}
}