【问题标题】:One-time-passwords with mediawiki AuthPlugin使用 mediawiki AuthPlugin 的一次性密码
【发布时间】:2014-10-23 21:05:15
【问题描述】:

我创建了一个 AuthPlugin 扩展来执行 SecurID 一次性密码身份验证。到目前为止,一切都很好。我可以在第一次登录时验证和创建用户。但是,第一次登录总是验证两次。它第一次验证以创建用户,第二次验证以实际登录。您可能会在这里看到问题:第一次使用一次性密码,因此用户未登录。后续登录工作正常.

我已经追踪到/includes/specials/SpecialUserlogin.php 的第一次身份验证调用(我不确定调用的是哪一个,但我可以找到有问题的并删除它):

<?php
/**
 * Make a new user account using the loaded data.
 * @private
 * @throws PermissionsError|ReadOnlyError
 * @return Status
 */
public function addNewAccountInternal() {
    // ...snip...
    // If we are not allowing users to login locally, we should be checking
    // to see if the user is actually able to authenticate to the authenti-
    // cation server before they create an account (otherwise, they can
    // create a local account and login as any domain user). We only need
    // to check this for domains that aren't local.
    if ( 'local' != $this->mDomain && $this->mDomain != '' ) {
        if (
            !$wgAuth->canCreateAccounts() &&
            (
                !$wgAuth->userExists( $this->mUsername ) ||
                !$wgAuth->authenticate( $this->mUsername, $this->mPassword )
            )
        ) {
            return Status::newFatal( 'wrongpassword' );
        }
    }

//...snip...
/**
 * Attempt to automatically create a user on login. Only succeeds if there
 * is an external authentication method which allows it.
 *
 * @param $user User
 *
 * @return integer Status code
 */
function attemptAutoCreate( $user ) {
   // ...snip...
    if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword ) ) {
        wfDebug( __METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n" );

        return self::WRONG_PLUGIN_PASS;
    }

所以,如果所有用户都需要使用一次性密码系统进行身份验证(如果我阻止从本地帐户登录和创建本地帐户),那么删除有问题的 authenticate 调用是否有问题?我在这里非常不安全吗?还是有更好的方法来做到这一点?除了扩展AuthPlugin,我还应该做些什么吗?例如,我重写了这些AuthPlugin 方法:

<?php
/**
 * Return true to prevent logins that don't authenticate here from being
 * checked against the local database's password fields.
 *
 * This is just a question, and shouldn't perform any actions.
 *
 * @return bool
 */
public function strict() {
    return true;
}

/**
 * Check if a user should authenticate locally if the global authentication fails.
 * If either this or strict() returns true, local authentication is not used.
 *
 * @param string $username Username.
 * @return bool
 */
public function strictUserAuth( $username ) {
    return true;
}

我想避免预先创建所有用户并让他们保持同步,但这是避免初始重复身份验证调用的一种方法。

顺便说一句,我认为会话的真正身份验证调用发生在includes/User.php

<?php
public function checkPassword( $password ) {
    global $wgAuth, $wgLegacyEncoding;
    $this->load();

    // Certain authentication plugins do NOT want to save
    // domain passwords in a mysql database, so we should
    // check this (in case $wgAuth->strict() is false).

    if ( $wgAuth->authenticate( $this->getName(), $password ) ) {
        return true;

【问题讨论】:

    标签: php authentication mediawiki one-time-password


    【解决方案1】:

    我认为最好的方法是使用与 wikitech.wikimedia.org 上使用的 TwoFactorAuthentication 扩展相同的方式。

    在检查用户数据之前,您可以使用AbortLogin Hook 检查您的一次性密码。问题:您必须确保一次性密码仅在用户成功登录时标记为“已使用”。

    (希望您不要将“普通”用户密码替换为“仅”一次密码)。

    【讨论】:

    • 我喜欢你的回答,但这并不是真正的双重因素......它只是一个没有静态密码的一次性密码。所以,没有静态密码来进行身份验证(除非我在这里遗漏了一些东西)。
    • 啊,我想我有点误解了你的问题 :) 为了避免第一次调用身份验证,在你的 AuthPlugin 中实现 getDomain() 并只返回 'local' 就足够了。跨度>
    • 谢谢 - 我会检查一下,看看我发现了什么。
    猜你喜欢
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多