Samuel Tan | d7ed851 | 2015-08-13 16:11:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dhcpcd - DHCP client daemon |
| 3 | * Copyright (c) 2006-2015 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 | #define DHCPCD_AUTH_SEND (1 << 0) |
| 34 | #define DHCPCD_AUTH_REQUIRE (1 << 1) |
| 35 | #define DHCPCD_AUTH_RDM_COUNTER (1 << 2) |
| 36 | |
| 37 | #define DHCPCD_AUTH_SENDREQUIRE (DHCPCD_AUTH_SEND | DHCPCD_AUTH_REQUIRE) |
| 38 | |
| 39 | #define AUTH_PROTO_TOKEN 0 |
| 40 | #define AUTH_PROTO_DELAYED 1 |
| 41 | #define AUTH_PROTO_DELAYEDREALM 2 |
| 42 | #define AUTH_PROTO_RECONFKEY 3 |
| 43 | |
| 44 | #define AUTH_ALG_HMAC_MD5 1 |
| 45 | |
| 46 | #define AUTH_RDM_MONOTONIC 0 |
| 47 | |
| 48 | struct token { |
| 49 | TAILQ_ENTRY(token) next; |
| 50 | uint32_t secretid; |
| 51 | size_t realm_len; |
| 52 | unsigned char *realm; |
| 53 | size_t key_len; |
| 54 | unsigned char *key; |
| 55 | time_t expire; |
| 56 | }; |
| 57 | |
| 58 | TAILQ_HEAD(token_head, token); |
| 59 | |
| 60 | struct auth { |
| 61 | int options; |
| 62 | uint8_t protocol; |
| 63 | uint8_t algorithm; |
| 64 | uint8_t rdm; |
| 65 | uint64_t last_replay; |
| 66 | uint8_t last_replay_set; |
| 67 | struct token_head tokens; |
| 68 | }; |
| 69 | |
| 70 | struct authstate { |
| 71 | uint64_t replay; |
| 72 | struct token *token; |
| 73 | struct token *reconf; |
| 74 | }; |
| 75 | |
| 76 | void dhcp_auth_reset(struct authstate *); |
| 77 | |
| 78 | const struct token * dhcp_auth_validate(struct authstate *, |
| 79 | const struct auth *, |
| 80 | const uint8_t *, size_t, int, int, |
| 81 | const uint8_t *, size_t); |
| 82 | |
| 83 | ssize_t dhcp_auth_encode(struct auth *, const struct token *, |
| 84 | uint8_t *, size_t, int, int, |
| 85 | uint8_t *, size_t); |
| 86 | #endif |