public function testCrypt()
 {
     // setup
     $testOcUser = '******';
     $testRcUser = '******';
     // reset
     OCP\Config::$USERVALUES = array();
     $result = OC_RoundCube_App::generateKeyPair($testOcUser, 'Passw0rd!');
     $privateKey = OC_RoundCube_App::getPrivateKey($testOcUser, 'Passw0rd!');
     $this->assertNotNull($privateKey, 'Private key should not be empty.');
     $encryptedMailData = OC_RoundCube_App::cryptEmailIdentity($testOcUser, $testRcUser, 'Passw0rd!', false);
     $mail_user = OC_RoundCube_App::decryptMyEntry($encryptedMailData['mail_user'], $privateKey);
     $mail_pass = OC_RoundCube_App::decryptMyEntry($encryptedMailData['mail_password'], $privateKey);
     $this->assertEquals($mail_user, $testRcUser);
     $this->assertEquals($mail_pass, 'Passw0rd!');
 }
Esempio n. 2
0
" id="requesttoken"> 
		<input type="hidden" name="appname" value="roundcube">
		<fieldset class="<?php 
    echo $cfgClass;
    ?>
" id="roundcube">
		<h2>
			<?php 
    p($l->t('RoundCube Mailaccount'));
    ?>
		</h2>
		<?php 
    $enable_auto_login = OCP\Config::getAppValue('roundcube', 'autoLogin', false);
    if (!$enable_auto_login) {
        $username = OCP\User::getUser();
        $privKey = OC_RoundCube_App::getPrivateKey($username, false);
        foreach ($mail_userdata_entries as $mail_userdata) {
            $mail_username = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_user'], $privKey);
            $mail_password = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_password'], $privKey);
            // TODO use template and add button for adding entries
            ?>
				<input type="text" id="rc_mail_username" name="rc_mail_username"
					value="<?php 
            echo $mail_username;
            ?>
" placeholder="<?php 
            p($l->t('Email Login Name'));
            ?>
" /> 
				<input type="password" id="rc_mail_password" name="rc_mail_password"
					placeholder="<?php 
 /**
  * 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);
     }
 }
Esempio n. 4
0
// set the passwort in session to fill the hidden login form with revertet and base64 encoded pass
// the *yourkey* must the same string as in autologin.php to replace this after revert and decode


OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('roundcube');

$table_exists = OC_RoundCube_DB_Util::tableExists();

$html_output = "";
if (!$table_exists) {
	OCP\Util::writeLog('roundcube', 'tpl.mail.php: DB table entries not created ...', OCP\Util::INFO);
	$html_output = $html_output . $this -> inc("part.error.db");
} else {
	$ocUser = OCP\User::getUser();
	$privKey = OC_RoundCube_App::getPrivateKey($ocUser,false);
	$mail_userdata_entries = OC_RoundCube_App::checkLoginData(OCP\User::getUser());
	// TODO create dropdown list
	$mail_userdata = $mail_userdata_entries[0];

	//
	// Nope. Already logged in at the start. Then starting to support
	// multiple accounts, a re-login with other credentials than the
	// default ID could be provided.
	//

	$disable_control_nav = OCP\Config::getAppValue('roundcube', 'removeControlNav', false);
	$enable_autologin = OCP\Config::getAppValue('roundcube', 'autoLogin', false);

	$maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
	$rc_host = OCP\Config::getAppValue('roundcube', 'rcHost', '');
 /**
  * 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);
     }
 }