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