aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib/crypt.php
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-06-03 14:19:31 +0200
committerBjörn Schießle <schiessle@owncloud.com>2013-06-03 14:19:31 +0200
commit471d2b732c504d7231aa7f343f5cda8a701fa447 (patch)
tree4aba6d147e98cccf6ba91aec216247fe8886eb84 /apps/files_encryption/lib/crypt.php
parenta134ffcf2cce4dcd2c41ccd49a5b6306260bb0f3 (diff)
downloadnextcloud-server-471d2b732c504d7231aa7f343f5cda8a701fa447.tar.gz
nextcloud-server-471d2b732c504d7231aa7f343f5cda8a701fa447.zip
introduce decryptPrivateKey() method which also checks if the result is a valid private key to avoid additional checks on various places
Diffstat (limited to 'apps/files_encryption/lib/crypt.php')
-rwxr-xr-xapps/files_encryption/lib/crypt.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index ddeb3590f60..8c96e536415 100755
--- a/apps/files_encryption/lib/crypt.php
+++ b/apps/files_encryption/lib/crypt.php
@@ -352,6 +352,34 @@ class Crypt {
}
/**
+ * @brief Decrypt private key and check if the result is a valid keyfile
+ * @param string $encryptedKey encrypted keyfile
+ * @param string $passphrase to decrypt keyfile
+ * @returns encrypted private key or false
+ *
+ * This function decrypts a file
+ */
+ public static function decryptPrivateKey($encryptedKey, $passphrase) {
+
+ $plainKey = self::symmetricDecryptFileContent($encryptedKey, $passphrase);
+
+ // check if this a valid private key
+ $res = openssl_pkey_get_private($plainKey);
+ if(is_resource($res)) {
+ $sslInfo = openssl_pkey_get_details($res);
+ if(!isset($sslInfo['key'])) {
+ $plainKey = false;
+ }
+ } else {
+ $plainKey = false;
+ }
+
+ return $plainKey;
+
+ }
+
+
+ /**
* @brief Creates symmetric keyfile content using a generated key
* @param string $plainContent content to be encrypted
* @returns array keys: key, encrypted