public function testKeyGeneration() { // reset OCP\Config::$USERVALUES = array(); $result = OC_RoundCube_App::generateKeyPair('user', 'pass'); $privateKey = $result['privateKey']; $publicKey = $result['publicKey']; //$this->assertEquals(get_resource_type($privateKey), 'OpenSSL key'); $this->assertNotNull($privateKey, 'Private key should not be empty.'); $this->assertNotNull($publicKey, 'Public key should not be empty.'); $readPrivateKey = OC_RoundCube_App::getPrivateKey('user', 'pass'); $readPublicKey = OC_RoundCube_App::getPublicKey('user'); $this->assertEquals($publicKey, $readPublicKey); }
/** * listener which gets invoked if password is changed within owncloud * @param unknown $params userdata */ public static function changePasswordListener($params) { $username = $params['uid']; $password = $params['password']; // Try to fetch from session $oldPrivKey = OC_RoundCube_App::getPrivateKey($username, false); // Take the chance to alter the priv/pubkey pair OC_RoundCube_App::generateKeyPair($username, $password); $privKey = OC_RoundCube_App::getPrivateKey($username, $password); $pubKey = OC_RoundCube_App::getPublicKey($username); if ($oldPrivKey !== false) { // Fetch credentials from data-base $mail_userdata_entries = OC_RoundCube_App::checkLoginData($username); foreach ($mail_userdata_entries as $mail_userdata) { $mail_username = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_user'], $oldPrivKey); $mail_password = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_password'], $oldPrivKey); $myID = $mail_userdata['id']; $mail_username = OC_RoundCube_App::cryptMyEntry($mail_username, $pubKey); $mail_password = OC_RoundCube_App::cryptMyEntry($mail_password, $pubKey); $stmt = OCP\DB::prepare("UPDATE *PREFIX*roundcube SET mail_user = ?, mail_password = ? WHERE id = ?"); OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->changePasswordListener():' . 'Updated mail password data due to password changed for user ' . $username, OCP\Util::DEBUG); $result = $stmt->execute(array($mail_username, $mail_password, $myID)); } } else { OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->changePasswordListener():' . 'No private key for ' . $username, OCP\Util::DEBUG); } }
/** * listener which gets invoked if password is changed within owncloud * * @param unknown $params * userdata */ public static function changePasswordListener($params) { $username = $params['uid']; $password = $params['password']; // Try to fetch from session $oldPrivKey = OC_RoundCube_App::getSessionVariable(OC_RoundCube_App::SESSION_ATTR_RCPRIVKEY); // Take the chance to alter the priv/pubkey pair OC_RoundCube_App::generateKeyPair($username, $password); $privKey = OC_RoundCube_App::getPrivateKey($username, $password); $pubKey = OC_RoundCube_App::getPublicKey($username); if ($oldPrivKey !== false) { // Fetch credentials from data-base $mail_userdata_entries = OC_RoundCube_App::checkLoginData($username); foreach ($mail_userdata_entries as $mail_userdata) { $mail_username = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_user'], $oldPrivKey); $mail_password = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_password'], $oldPrivKey); OC_RoundCube_App::cryptEmailIdentity($username, $mail_username, $mail_password); OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->changePasswordListener():' . 'Updated mail password data due to password changed for user ' . $username, OCP\Util::DEBUG); } } else { OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->changePasswordListener():' . 'No private key for ' . $username, OCP\Util::DEBUG); } }