Esempio n. 1
0
 /**
  * Create a new encryption keypair
  * @return array publicKey, privatekey
  */
 public static function createKeypair()
 {
     $return = false;
     $res = Helper::getOpenSSLPkey();
     if ($res === false) {
         \OCP\Util::writeLog('Encryption library', 'couldn\'t generate users key-pair for ' . \OCP\User::getUser(), \OCP\Util::ERROR);
         while ($msg = openssl_error_string()) {
             \OCP\Util::writeLog('Encryption library', 'openssl_pkey_new() fails:  ' . $msg, \OCP\Util::ERROR);
         }
     } elseif (openssl_pkey_export($res, $privateKey, null, Helper::getOpenSSLConfig())) {
         // Get public key
         $keyDetails = openssl_pkey_get_details($res);
         $publicKey = $keyDetails['key'];
         $return = array('publicKey' => $publicKey, '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);
         while ($errMsg = openssl_error_string()) {
             \OCP\Util::writeLog('Encryption library', $errMsg, \OCP\Util::ERROR);
         }
     }
     return $return;
 }