GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libradius/radius_eapmsk.c Lines: 0 17 0.0 %
Date: 2017-11-07 Branches: 0 8 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: radius_eapmsk.c,v 1.1 2015/07/20 23:52:29 yasuoka Exp $ */
2
3
/*-
4
 * Copyright (c) 2013 Internet Initiative Japan Inc.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE"AUTHOR" AND CONTRIBUTORS AS IS'' AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 * SUCH DAMAGE.
27
 */
28
29
#include <sys/types.h>
30
#include <sys/socket.h>
31
#include <netinet/in.h>
32
33
#include <stdbool.h>
34
#include <stdio.h>
35
#include <stdlib.h>
36
#include <string.h>
37
38
#include <openssl/md5.h>
39
40
#include "radius.h"
41
42
#include "radius_local.h"
43
44
int
45
radius_get_eap_msk(const RADIUS_PACKET * packet, void *buf, size_t * len,
46
    const char *secret)
47
{
48
	/*
49
	 * Unfortunately, the way to pass EAP MSK/EMSK over RADIUS
50
	 * is not standardized.
51
	 */
52
	uint8_t	 buf0[256];
53
	uint8_t	 buf1[256];
54
	size_t	 len0, len1;
55
56
	/*
57
	 * EAP MSK via MPPE keys
58
	 *
59
	 * MSK = MPPE-Recv-Key + MPPE-Send-Key + 32byte zeros
60
	 * http://msdn.microsoft.com/en-us/library/cc224635.aspx
61
	 */
62
	len0 = sizeof(buf0);
63
	len1 = sizeof(buf1);
64
	if (radius_get_mppe_recv_key_attr(packet, buf0, &len0, secret) == 0 &&
65
	    radius_get_mppe_send_key_attr(packet, buf1, &len1, secret) == 0) {
66
		if (len0 < 16 || len1 < 16)
67
			return (-1);
68
		if (*len < 64)
69
			return (-1);
70
		memcpy(buf, buf0, 16);
71
		memcpy(((char *)buf) + 16, buf1, 16);
72
		memset(((char *)buf) + 32, 0, 32);
73
		*len = 64;
74
		return (0);
75
	}
76
77
	return (-1);
78
}