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