Annotation of embedaddon/libpdel/ppp/ppp_auth_chap_md5.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:
! 48: #include <openssl/md5.h>
! 49:
! 50: #define CHAP_MD5_CHALLENGE_LEN 16
! 51:
! 52: static ppp_auth_chap_set_id_t ppp_auth_chap_md5_set_id;
! 53: static ppp_auth_chap_hash_t ppp_auth_chap_md5_hash;
! 54: static ppp_auth_chap_equal_t ppp_auth_chap_md5_equal;
! 55: static ppp_auth_chap_final_t ppp_auth_chap_md5_final;
! 56:
! 57: const struct ppp_auth_chap_type ppp_auth_chap_md5 = {
! 58: ppp_auth_chap_md5_set_id,
! 59: ppp_auth_chap_md5_hash,
! 60: ppp_auth_chap_md5_equal,
! 61: ppp_auth_chap_md5_final,
! 62: 0,
! 63: CHAP_MD5_CHALLENGE_LEN,
! 64: offsetof(struct ppp_auth_cred_chap_md5, hash),
! 65: MD5_DIGEST_LENGTH
! 66: };
! 67:
! 68: static void
! 69: ppp_auth_chap_md5_set_id(struct ppp_auth_cred_chap *cred, u_char id)
! 70: {
! 71: cred->u.md5.id = id;
! 72: }
! 73:
! 74: static void
! 75: ppp_auth_chap_md5_hash(struct ppp_auth_cred_chap *chap,
! 76: const void *secret, size_t slen)
! 77: {
! 78: struct ppp_auth_cred_chap_md5 *const md5 = &chap->u.md5;
! 79: MD5_CTX ctx;
! 80:
! 81: MD5_Init(&ctx);
! 82: MD5_Update(&ctx, &md5->id, 1);
! 83: MD5_Update(&ctx, secret, slen);
! 84: MD5_Update(&ctx, &chap->chal_data, chap->chal_len);
! 85: MD5_Final(md5->hash, &ctx);
! 86: }
! 87:
! 88: static int
! 89: ppp_auth_chap_md5_equal(struct ppp_auth_cred_chap *chap1,
! 90: struct ppp_auth_cred_chap *chap2)
! 91: {
! 92: struct ppp_auth_cred_chap_md5 *const md5_1 = &chap1->u.md5;
! 93: struct ppp_auth_cred_chap_md5 *const md5_2 = &chap2->u.md5;
! 94:
! 95: return (memcmp(md5_1->hash, md5_2->hash, MD5_DIGEST_LENGTH) == 0);
! 96: }
! 97:
! 98: static int
! 99: ppp_auth_chap_md5_final(struct ppp_auth_cred_chap *cred, struct ppp_log *log,
! 100: int valid, const u_char *payload, size_t len, const u_char *authresp)
! 101: {
! 102: char buf[256];
! 103:
! 104: /* Display message */
! 105: ppp_util_ascify(buf, sizeof(buf), payload, len);
! 106: ppp_log_put(log, LOG_INFO, "message: %s", buf);
! 107: return (0);
! 108: }
! 109:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>