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!');
 }
Example #2
0
<?php

// Init owncloud
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('roundcube');
// CSRF checks
OCP\JSON::callCheck();
$l = new OC_L10N('roundcube');
if (isset($_POST['appname']) && $_POST['appname'] == "roundcube") {
    $ocUser = OCP\User::getUser();
    $result = OC_RoundCube_App::cryptEmailIdentity($ocUser, $_POST['rc_mail_username'], $_POST['rc_mail_password']);
    if ($result) {
        // update login credentials
        $maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
        $rc_host = OCP\Config::getAppValue('roundcube', 'rcHost', '');
        if ($rc_host == '') {
            $rc_host = OC_Request::serverHost();
        }
        $rc_port = OCP\Config::getAppValue('roundcube', 'rcPort', null);
        OC_RoundCube_App::login($rc_host, $rc_port, $maildir, $_POST['rc_mail_username'], $_POST['rc_mail_password']);
    } else {
        OC_JSON::error(array("data" => array("message" => $l->t("Unable to store email credentials in the data-base."))));
        return false;
    }
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Not submitted for us."))));
    return false;
}
OCP\JSON::success(array('data' => array('message' => $l->t('Email-user credentials successfully stored.'))));
return true;
 /**
  * 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);
     }
 }