Annotation of embedaddon/libpdel/ppp/ppp_auth_chap_msv1.c, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * Copyright (c) 2001-2002 Packet Design, LLC.
        !             4:  * All rights reserved.
        !             5:  * 
        !             6:  * Subject to the following obligations and disclaimer of warranty,
        !             7:  * use and redistribution of this software, in source or object code
        !             8:  * forms, with or without modifications are expressly permitted by
        !             9:  * Packet Design; provided, however, that:
        !            10:  * 
        !            11:  *    (i)  Any and all reproductions of the source or object code
        !            12:  *         must include the copyright notice above and the following
        !            13:  *         disclaimer of warranties; and
        !            14:  *    (ii) No rights are granted, in any manner or form, to use
        !            15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
        !            16:  *         on advertising, endorsements, or otherwise except as such
        !            17:  *         appears in the above copyright notice or in the software.
        !            18:  * 
        !            19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
        !            20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
        !            21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
        !            22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
        !            23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
        !            24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
        !            25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
        !            26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
        !            27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
        !            28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
        !            29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
        !            30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
        !            31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
        !            32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
        !            33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
        !            35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
        !            36:  * THE POSSIBILITY OF SUCH DAMAGE.
        !            37:  *
        !            38:  * Author: Archie Cobbs <archie@freebsd.org>
        !            39:  */
        !            40: 
        !            41: #include "ppp/ppp_defs.h"
        !            42: #include "ppp/ppp_log.h"
        !            43: #include "ppp/ppp_util.h"
        !            44: #include "ppp/ppp_fsm_option.h"
        !            45: #include "ppp/ppp_auth.h"
        !            46: #include "ppp/ppp_auth_chap.h"
        !            47: #include "ppp/ppp_msoft.h"
        !            48: 
        !            49: static ppp_auth_chap_hash_t    ppp_auth_chap_msv1_hash;
        !            50: static ppp_auth_chap_equal_t   ppp_auth_chap_msv1_equal;
        !            51: static ppp_auth_chap_final_t   ppp_auth_chap_msv1_final;
        !            52: 
        !            53: /* MS-CHAP version 1 descriptor */
        !            54: const struct ppp_auth_chap_type ppp_auth_chap_msv1 = {
        !            55:        NULL,
        !            56:        ppp_auth_chap_msv1_hash,
        !            57:        ppp_auth_chap_msv1_equal,
        !            58:        ppp_auth_chap_msv1_final,
        !            59:        1,
        !            60:        PPP_MSOFTV1_CHAL_LEN,
        !            61:        0,
        !            62:        PPP_MSOFT_RESP_LEN
        !            63: };
        !            64: 
        !            65: /* MS-CHAP error codes */
        !            66: const struct mschap_err ppp_mschap_errs[] = {
        !            67:        { 646,  "Restricted logon hours" },
        !            68:        { 647,  "Account disabled" },
        !            69:        { 648,  "Password expired" },
        !            70:        { 649,  "No dialin permission" },
        !            71:        { 691,  "Authentication failure" },
        !            72:        { 709,  "Changing password" },
        !            73:        { 0,    NULL }
        !            74: };
        !            75: 
        !            76: static void
        !            77: ppp_auth_chap_msv1_hash(struct ppp_auth_cred_chap *chap,
        !            78:        const void *secret, size_t slen)
        !            79: {
        !            80:        struct ppp_auth_cred_chap_msv1 *const msv1 = &chap->u.msv1;
        !            81: 
        !            82:        memset(&msv1->lm_hash, 0, sizeof(msv1->lm_hash));
        !            83:        ppp_msoft_nt_challenge_response(chap->chal_data, secret, msv1->nt_hash);
        !            84:        msv1->use_nt = 1;
        !            85: }
        !            86: 
        !            87: static int
        !            88: ppp_auth_chap_msv1_equal(struct ppp_auth_cred_chap *chap1,
        !            89:        struct ppp_auth_cred_chap *chap2)
        !            90: {
        !            91:        struct ppp_auth_cred_chap_msv1 *const msv1_1 = &chap1->u.msv1;
        !            92:        struct ppp_auth_cred_chap_msv1 *const msv1_2 = &chap2->u.msv1;
        !            93: 
        !            94:        if (msv1_1->use_nt != 1 || msv1_2->use_nt != 1)
        !            95:                return (0);
        !            96:        return (memcmp(msv1_1->nt_hash,
        !            97:            msv1_2->nt_hash, PPP_MSOFT_NT_HASH_LEN) == 0);
        !            98: }
        !            99: 
        !           100: static int
        !           101: ppp_auth_chap_msv1_final(struct ppp_auth_cred_chap *cred, struct ppp_log *log,
        !           102:        int valid, const u_char *payload, size_t len, const u_char *authresp)
        !           103: {
        !           104:        char buf[256];
        !           105:        char *s;
        !           106: 
        !           107:        /* Put payload into nul-terminated buffer */
        !           108:        if (len > sizeof(buf) - 1)
        !           109:                len = sizeof(buf) - 1;
        !           110:        memcpy(buf, payload, len);
        !           111:        buf[len] = '\0';
        !           112: 
        !           113:        /* Handle failure message */
        !           114:        if (!valid) {
        !           115:                const struct mschap_err *me;
        !           116:                int err;
        !           117: 
        !           118:                if ((s = strstr(buf, "E=")) == NULL)
        !           119:                        return (0);
        !           120:                if (sscanf(s + 2, "%d", &err) != 1)
        !           121:                        return (0);
        !           122:                for (me = ppp_mschap_errs;
        !           123:                    me->err != err && me->msg != NULL; me++);
        !           124:                ppp_log_put(log, LOG_NOTICE, "error #%d: %s",
        !           125:                    err, me->msg != NULL ? me->msg : "Unknown error");
        !           126:                return (0);
        !           127:        }
        !           128: 
        !           129:        /* Display message */
        !           130:        ppp_util_ascify(buf, sizeof(buf), payload, len);
        !           131:        ppp_log_put(log, LOG_INFO, "message: %s", buf);
        !           132:        return (0);
        !           133: }
        !           134: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>