1*ebfedea0SLionel Sambuc /*- 2*ebfedea0SLionel Sambuc * Copyright (c) 2010 Alistair Crooks <agc@NetBSD.org> 3*ebfedea0SLionel Sambuc * All rights reserved. 4*ebfedea0SLionel Sambuc * 5*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without 6*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions 7*ebfedea0SLionel Sambuc * are met: 8*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 9*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer. 10*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 11*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 12*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution. 13*ebfedea0SLionel Sambuc * 14*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16*ebfedea0SLionel Sambuc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17*ebfedea0SLionel Sambuc * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18*ebfedea0SLionel Sambuc * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19*ebfedea0SLionel Sambuc * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20*ebfedea0SLionel Sambuc * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21*ebfedea0SLionel Sambuc * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22*ebfedea0SLionel Sambuc * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23*ebfedea0SLionel Sambuc * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24*ebfedea0SLionel Sambuc */ 25*ebfedea0SLionel Sambuc #ifndef LIBPAA_H_ 26*ebfedea0SLionel Sambuc #define LIBPAA_H_ 20100908 27*ebfedea0SLionel Sambuc 28*ebfedea0SLionel Sambuc #include <sys/types.h> 29*ebfedea0SLionel Sambuc 30*ebfedea0SLionel Sambuc #include <inttypes.h> 31*ebfedea0SLionel Sambuc #include <stdio.h> 32*ebfedea0SLionel Sambuc 33*ebfedea0SLionel Sambuc #define DEFAULT_HASH_ALG "SHA256" 34*ebfedea0SLionel Sambuc 35*ebfedea0SLionel Sambuc enum { 36*ebfedea0SLionel Sambuc PAA_CHALLENGE_SIZE = 128 37*ebfedea0SLionel Sambuc }; 38*ebfedea0SLionel Sambuc 39*ebfedea0SLionel Sambuc /* constant and secret info for server side */ 40*ebfedea0SLionel Sambuc typedef struct paa_server_info_t { 41*ebfedea0SLionel Sambuc char hostaddress[128]; /* host ip address */ 42*ebfedea0SLionel Sambuc char *secret; /* raw secret of server */ 43*ebfedea0SLionel Sambuc unsigned secretc; /* # of characters used */ 44*ebfedea0SLionel Sambuc char server_signature[512]; /* this is the encoded signature */ 45*ebfedea0SLionel Sambuc int server_signaturec; /* # of chars in encoded sig */ 46*ebfedea0SLionel Sambuc } paa_server_info_t; 47*ebfedea0SLionel Sambuc 48*ebfedea0SLionel Sambuc /* used in server to formulate challenge */ 49*ebfedea0SLionel Sambuc typedef struct paa_challenge_t { 50*ebfedea0SLionel Sambuc const char *realm; /* this is realm of challenge */ 51*ebfedea0SLionel Sambuc const char *domain; /* domain of challenge */ 52*ebfedea0SLionel Sambuc char challenge[512]; /* the output challenge */ 53*ebfedea0SLionel Sambuc int challengec; /* # of chars in challenge */ 54*ebfedea0SLionel Sambuc /* sub-parts of challenge */ 55*ebfedea0SLionel Sambuc char encoded_challenge[512]; /* encoded challenge part */ 56*ebfedea0SLionel Sambuc int encc; /* # of chars in encoded challenge */ 57*ebfedea0SLionel Sambuc } paa_challenge_t; 58*ebfedea0SLionel Sambuc 59*ebfedea0SLionel Sambuc /* used in client to formulate response */ 60*ebfedea0SLionel Sambuc typedef struct paa_response_t { 61*ebfedea0SLionel Sambuc const char *userid; /* identity to be used for signature */ 62*ebfedea0SLionel Sambuc const char *realm; /* realm that client wants */ 63*ebfedea0SLionel Sambuc char challenge[PAA_CHALLENGE_SIZE]; /* input challenge */ 64*ebfedea0SLionel Sambuc int challengec; /* # if chars in input */ 65*ebfedea0SLionel Sambuc char response[PAA_CHALLENGE_SIZE * 2]; /* output response */ 66*ebfedea0SLionel Sambuc int respc; /* # of chars in output */ 67*ebfedea0SLionel Sambuc } paa_response_t; 68*ebfedea0SLionel Sambuc 69*ebfedea0SLionel Sambuc /* this struct holds the identity information in the paa response */ 70*ebfedea0SLionel Sambuc typedef struct paa_identity_t { 71*ebfedea0SLionel Sambuc char userid[32]; /* verified identity */ 72*ebfedea0SLionel Sambuc char client[128]; /* client address */ 73*ebfedea0SLionel Sambuc char realm[128]; /* client realm */ 74*ebfedea0SLionel Sambuc char domain[128]; /* client domain */ 75*ebfedea0SLionel Sambuc int64_t timestamp; /* time of response */ 76*ebfedea0SLionel Sambuc } paa_identity_t; 77*ebfedea0SLionel Sambuc 78*ebfedea0SLionel Sambuc /* support functions */ 79*ebfedea0SLionel Sambuc int paa_write_file(const char *, char *, unsigned); 80*ebfedea0SLionel Sambuc int paa_read_file(const char *, char *, size_t); 81*ebfedea0SLionel Sambuc 82*ebfedea0SLionel Sambuc /* server initialisations - one time */ 83*ebfedea0SLionel Sambuc int paa_server_init(paa_server_info_t *, unsigned); 84*ebfedea0SLionel Sambuc 85*ebfedea0SLionel Sambuc /* body of pubkey access authentication challenge/response/check functionality */ 86*ebfedea0SLionel Sambuc int paa_format_challenge(paa_challenge_t *, paa_server_info_t *, char *, size_t); 87*ebfedea0SLionel Sambuc int paa_format_response(paa_response_t *, netpgp_t *, char *, char *, size_t); 88*ebfedea0SLionel Sambuc int paa_check_response(paa_challenge_t *, paa_identity_t *, netpgp_t *, char *); 89*ebfedea0SLionel Sambuc 90*ebfedea0SLionel Sambuc /* who are ya? */ 91*ebfedea0SLionel Sambuc int paa_print_identity(FILE *, paa_identity_t *); 92*ebfedea0SLionel Sambuc 93*ebfedea0SLionel Sambuc #endif 94