Merge pull request #3788 from owncloud/more_error_messages

add some more error messages, in case something went wrong
This commit is contained in:
Björn Schießle 2013-06-20 02:12:01 -07:00
commit c4aa3fac7e
2 changed files with 28 additions and 26 deletions

View File

@ -51,21 +51,26 @@ class Crypt {
*/ */
public static function createKeypair() { public static function createKeypair() {
$return = false;
$res = openssl_pkey_new(array('private_key_bits' => 4096)); $res = openssl_pkey_new(array('private_key_bits' => 4096));
// Get private key if ($res === false) {
openssl_pkey_export($res, $privateKey); \OCP\Util::writeLog('Encryption library', 'couldn\'t generate users key-pair for ' . \OCP\User::getUser(), \OCP\Util::ERROR);
} elseif (openssl_pkey_export($res, $privateKey)) {
// Get public key // Get public key
$publicKey = openssl_pkey_get_details($res); $publicKey = openssl_pkey_get_details($res);
$publicKey = $publicKey['key']; $publicKey = $publicKey['key'];
return (array( $return = array(
'publicKey' => $publicKey, 'publicKey' => $publicKey,
'privateKey' => $privateKey 'privateKey' => $privateKey
)); );
} else {
\OCP\Util::writeLog('Encryption library', 'couldn\'t export users private key, please check your servers openSSL configuration.' . \OCP\User::getUser(), \OCP\Util::ERROR);
}
return $return;
} }
/** /**
@ -287,28 +292,22 @@ class Crypt {
public static function symmetricEncryptFileContent($plainContent, $passphrase = '') { public static function symmetricEncryptFileContent($plainContent, $passphrase = '') {
if (!$plainContent) { if (!$plainContent) {
\OCP\Util::writeLog('Encryption library', 'symmetrically encryption failed, no content given.', \OCP\Util::ERROR);
return false; return false;
} }
$iv = self::generateIv(); $iv = self::generateIv();
if ($encryptedContent = self::encrypt($plainContent, $iv, $passphrase)) { if ($encryptedContent = self::encrypt($plainContent, $iv, $passphrase)) {
// Combine content to encrypt with IV identifier and actual IV // Combine content to encrypt with IV identifier and actual IV
$catfile = self::concatIv($encryptedContent, $iv); $catfile = self::concatIv($encryptedContent, $iv);
$padded = self::addPadding($catfile); $padded = self::addPadding($catfile);
return $padded; return $padded;
} else { } else {
\OCP\Util::writeLog('Encryption library', 'Encryption (symmetric) of keyfile content failed', \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', 'Encryption (symmetric) of keyfile content failed', \OCP\Util::ERROR);
return false; return false;
} }
} }

View File

@ -228,18 +228,21 @@ class Util {
// Generate keypair // Generate keypair
$keypair = Crypt::createKeypair(); $keypair = Crypt::createKeypair();
\OC_FileProxy::$enabled = false; if ($keypair) {
// Save public key \OC_FileProxy::$enabled = false;
$this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
// Encrypt private key with user pwd as passphrase // Encrypt private key with user pwd as passphrase
$encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase); $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase);
// Save private key // Save key-pair
if ($encryptedPrivateKey) {
$this->view->file_put_contents($this->privateKeyPath, $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 { } else {
// check if public-key exists but private-key is missing // check if public-key exists but private-key is missing