Skip to content
Snippets Groups Projects
Commit bb229f72 authored by Björn Schießle's avatar Björn Schießle
Browse files

write private/public key from the client to the server

parent e5c84488
Branches
No related tags found
No related merge requests found
......@@ -73,8 +73,16 @@ class Keymanager {
* @return bool true/false
*/
public static function setPrivateKey($user, $key) {
$view = new \OC_FilesystemView('/'.$user.'/files_encryption/');
return $view->file_put_contents($user.'.private.key', $key);
\OC_FileProxy::$enabled = false;
$view = new \OC_FilesystemView('/'.$user.'/files_encryption');
if (!$view->file_exists('')) $view->mkdir('');
$result = $view->file_put_contents($user.'.private.key', $key);
\OC_FileProxy::$enabled = true;
return $result;
}
......@@ -86,8 +94,16 @@ class Keymanager {
* @return bool true/false
*/
public static function setPublicKey($user, $key) {
$view = new \OC_FilesystemView('/public-keys/');
return $view->file_put_contents($user.'.public.key', $key);
\OC_FileProxy::$enabled = false;
$view = new \OC_FilesystemView('/public-keys');
if (!$view->file_exists('')) $view->mkdir('');
$result = $view->file_put_contents($user.'.public.key', $key);
\OC_FileProxy::$enabled = true;
return $result;
}
/**
......@@ -103,10 +119,13 @@ class Keymanager {
\OC_FileProxy::$enabled = false;
$view = new \OC_FilesystemView( '/' . $userId . '/' . 'files_encryption' );
return $view->file_put_contents( '/' . $path . '.key', $key );
$path_parts = pathinfo($path);
if (!$view->file_exists($path_parts['dirname'])) $view->mkdir($path_parts['dirname']);
$result = $view->file_put_contents( '/' . $path . '.key', $key );
\OC_FileProxy::$enabled = true;
return $result;
}
}
\ No newline at end of file
......@@ -173,10 +173,20 @@ class OC_OCS {
$user=$ex[$paracount-3];
OC_OCS::publicKeyGet($format,$user);
//keysetpublic
}elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'publickey')){
$user=$ex[$paracount-3];
$key = self::readData('post', 'key', 'string');
OC_OCS::publicKeySet($format,$user, $key);
// keygetprivate
}elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')){
$user=$ex[$paracount-3];
OC_OCS::privateKeyGet($format,$user);
}elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')){
$user=$ex[$paracount-3];
$key = self::readData('post', 'key', 'string');
OC_OCS::privateKeySet($format,$user, $key);
// add more calls here
......@@ -680,12 +690,15 @@ class OC_OCS {
*/
private static function publicKeySet($format, $user, $key) {
$login=OC_OCS::checkpassword();
if($login == $user) {
if(OC_User::userExists($user)){
//TODO: SET public key
echo self::generateXml('', 'ok', 100, 'Public key uploaded');
if(($login==$user)) {
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
if (($key = OCA_Encryption\Keymanager::setPublicKey($user, $key))) {
echo self::generateXml('', 'ok', 100, '');
} else {
echo self::generateXml('', 'fail', 300, 'User does not exist');
echo self::generateXml('', 'fail', 404, 'could not add your public key to the key storage');
}
} else {
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user);
}
}else{
echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
......@@ -727,12 +740,15 @@ class OC_OCS {
*/
private static function privateKeySet($format, $user, $key) {
$login=OC_OCS::checkpassword();
if($login == $user) {
if(OC_User::userExists($user)){
//TODO: SET private key
echo self::generateXml('', 'ok', 100, 'Private key uploaded');
if(($login==$user)) {
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
if (($key = OCA_Encryption\Keymanager::setPrivateKey($user, $key))) {
echo self::generateXml('', 'ok', 100, '');
} else {
echo self::generateXml('', 'fail', 300, 'User does not exist');
echo self::generateXml('', 'fail', 404, 'could not add your private key to the key storage');
}
} else {
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user);
}
}else{
echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment