\r
$res = openssl_pkey_new(array('private_key_bits' => 4096));\r
\r
- // Get private key\r
- openssl_pkey_export($res, $privateKey);\r
+ if ($res === false) {\r
+ \OCP\Util::writeLog('Encryption library', 'couldn\'t generate users key-pair for ' . \OCP\User::getUser(), \OCP\Util::ERROR);\r
+ $result = false;\r
+ } else {\r
+\r
+ // Get private key\r
+ openssl_pkey_export($res, $privateKey);\r
\r
- // Get public key\r
- $publicKey = openssl_pkey_get_details($res);\r
+ // Get public key\r
+ $publicKey = openssl_pkey_get_details($res);\r
\r
- $publicKey = $publicKey['key'];\r
+ $publicKey = $publicKey['key'];\r
\r
- return (array(\r
- 'publicKey' => $publicKey,\r
- 'privateKey' => $privateKey\r
- ));\r
+ $result = array(\r
+ 'publicKey' => $publicKey,\r
+ 'privateKey' => $privateKey\r
+ );\r
+ }\r
\r
+ return $result;\r
}\r
\r
/**\r
public static function symmetricEncryptFileContent($plainContent, $passphrase = '') {\r
\r
if (!$plainContent) {\r
-\r
+ \OCP\Util::writeLog('Encryption library', 'symmetrically encryption failed, no content given.', \OCP\Util::ERROR);\r
return false;\r
-\r
}\r
\r
$iv = self::generateIv();\r
\r
if ($encryptedContent = self::encrypt($plainContent, $iv, $passphrase)) {\r
-\r
// Combine content to encrypt with IV identifier and actual IV\r
$catfile = self::concatIv($encryptedContent, $iv);\r
-\r
$padded = self::addPadding($catfile);\r
\r
return $padded;\r
\r
} else {\r
-\r
\OCP\Util::writeLog('Encryption library', 'Encryption (symmetric) of keyfile content failed', \OCP\Util::ERROR);\r
-\r
return false;\r
-\r
}\r
\r
}\r
// Generate keypair
$keypair = Crypt::createKeypair();
- \OC_FileProxy::$enabled = false;
+ if ($keypair) {
- // Save public key
- $this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
+ \OC_FileProxy::$enabled = false;
- // Encrypt private key with user pwd as passphrase
- $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase);
+ // Encrypt private key with user pwd as passphrase
+ $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase);
- // Save private key
- $this->view->file_put_contents($this->privateKeyPath, $encryptedPrivateKey);
+ // Save key-pair
+ if ($encryptedPrivateKey) {
+ $this->view->file_put_contents($this->privateKeyPath, $encryptedPrivateKey);
+ $this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
+ }
- \OC_FileProxy::$enabled = true;
+ \OC_FileProxy::$enabled = true;
+ }
} else {
// check if public-key exists but private-key is missing