1/*
2 * dhcpcd - DHCP client daemon
3 * Copyright (c) 2006-2019 Roy Marples <roy@marples.name>
4 * All rights reserved
5
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#ifndef AUTH_H
29#define AUTH_H
30
31#include "config.h"
32
33#ifdef HAVE_SYS_QUEUE_H
34#include <sys/queue.h>
35#endif
36
37#define DHCPCD_AUTH_SEND (1 << 0)
38#define DHCPCD_AUTH_REQUIRE (1 << 1)
39#define DHCPCD_AUTH_RDM_COUNTER (1 << 2)
40
41#define DHCPCD_AUTH_SENDREQUIRE (DHCPCD_AUTH_SEND | DHCPCD_AUTH_REQUIRE)
42
43#define AUTH_PROTO_TOKEN 0
44#define AUTH_PROTO_DELAYED 1
45#define AUTH_PROTO_DELAYEDREALM 2
46#define AUTH_PROTO_RECONFKEY 3
47
48#define AUTH_ALG_NONE 0
49#define AUTH_ALG_HMAC_MD5 1
50
51#define AUTH_RDM_MONOTONIC 0
52
53struct token {
54 TAILQ_ENTRY(token) next;
55 uint32_t secretid;
56 size_t realm_len;
57 unsigned char *realm;
58 size_t key_len;
59 unsigned char *key;
60 time_t expire;
61};
62
63TAILQ_HEAD(token_head, token);
64
65struct auth {
66 int options;
67#ifdef AUTH
68 uint8_t protocol;
69 uint8_t algorithm;
70 uint8_t rdm;
71 uint64_t last_replay;
72 uint8_t last_replay_set;
73 struct token_head tokens;
74 uint32_t token_snd_secretid;
75 uint32_t token_rcv_secretid;
76#endif
77};
78
79struct authstate {
80 uint64_t replay;
81 struct token *token;
82 struct token *reconf;
83};
84
85void dhcp_auth_reset(struct authstate *);
86
87const struct token * dhcp_auth_validate(struct authstate *,
88 const struct auth *,
89 const void *, size_t, int, int,
90 const void *, size_t);
91
92ssize_t dhcp_auth_encode(struct auth *, const struct token *,
93 void *, size_t, int, int,
94 void *, size_t);
95#endif
96