1/* $OpenBSD: assertion.h,v 1.6 2024/05/21 11:13:08 jsg Exp $ */
2/*
3 * The author of this code is Angelos D. Keromytis (angelos@dsl.cis.upenn.edu)
4 *
5 * This code was written by Angelos D. Keromytis in Philadelphia, PA, USA,
6 * in April-May 1998
7 *
8 * Copyright (C) 1998, 1999 by Angelos D. Keromytis.
9 *
10 * Permission to use, copy, and modify this software with or without fee
11 * is hereby granted, provided that this entire notice is included in
12 * all copies of any software which is or includes a copy or
13 * modification of this software.
14 *
15 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTY. IN PARTICULAR, THE AUTHORS MAKES NO
17 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
18 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
19 * PURPOSE.
20 */
21
22#ifndef __ASSERTION_H__
23#define __ASSERTION_H__
24
25/*
26 * These can be changed to reflect more assertions/session or more
27 * sessions respectively
28 */
29#define HASHTABLESIZE                   37
30#define SESSIONTABLESIZE                37
31
32struct keynote_session
33{
34    int                     ks_id;
35    int                     ks_assertioncounter;
36    int                     ks_values_num;
37    struct environment     *ks_env_table[HASHTABLESIZE];
38    struct environment     *ks_env_regex;
39    struct keylist         *ks_action_authorizers;
40    struct assertion       *ks_assertion_table[HASHTABLESIZE];
41    char                  **ks_values;
42    char                   *ks_authorizers_cache;
43    char                   *ks_values_cache;
44    struct keynote_session *ks_prev;
45    struct keynote_session *ks_next;
46};
47
48struct keylist
49{
50    int             key_alg;
51    void           *key_key;
52    char           *key_stringkey;
53    struct keylist *key_next;
54};
55
56struct assertion
57{
58    void               *as_authorizer;
59    char               *as_buf;
60    char               *as_signature;
61    char	       *as_authorizer_string_s;
62    char               *as_authorizer_string_e;
63    char               *as_keypred_s;
64    char               *as_keypred_e;
65    char               *as_conditions_s;
66    char               *as_conditions_e;
67    char               *as_signature_string_s;
68    char               *as_signature_string_e;
69    char	       *as_comment_s;
70    char	       *as_comment_e;
71    char	       *as_startofsignature;
72    char	       *as_allbutsignature;
73    int                 as_id;
74    int			as_signeralgorithm;
75    int                 as_result;
76    int			as_error;
77    unsigned char	as_flags;
78    unsigned char	as_internalflags;
79    char		as_kresult;
80    char                as_sigresult;
81    struct keylist     *as_keylist;
82    struct environment *as_env;
83    struct assertion   *as_next;
84};
85
86/* Internal flags */
87#define ASSERT_IFLAG_WEIRDLICS   0x0001  /* Needs Licensees re-processing */
88#define ASSERT_IFLAG_WEIRDAUTH   0x0002  /* Needs Authorizer re-processing */
89#define ASSERT_IFLAG_WEIRDSIG	 0x0004  /* Needs Signature re-processing */
90#define ASSERT_IFLAG_NEEDPROC    0x0008  /* Needs "key field" processing */
91#define ASSERT_IFLAG_PROCESSED   0x0010  /* Handled repositioning already */
92
93#define KRESULT_UNTOUCHED	0
94#define KRESULT_IN_PROGRESS	1	/* For cycle detection */
95#define KRESULT_DONE            2
96
97#define KEYWORD_VERSION		1
98#define KEYWORD_LOCALINIT      	2
99#define KEYWORD_AUTHORIZER     	3
100#define KEYWORD_LICENSEES	4
101#define KEYWORD_CONDITIONS	5
102#define KEYWORD_SIGNATURE	6
103#define KEYWORD_COMMENT		7
104
105#define KEYNOTE_FLAG_EXPORTALL	0x1
106
107/* List types for cleanup */
108#define LEXTYPE_CHAR		0x1
109
110/* Length of random initializer */
111#define KEYNOTE_RAND_INIT_LEN           1024
112
113/* Variables */
114extern char **keynote_values;
115extern char *keynote_privkey;
116
117extern struct assertion *keynote_current_assertion;
118
119extern struct environment *keynote_init_list;
120extern struct environment *keynote_temp_list;
121
122extern struct keylist *keynote_keypred_keylist;
123
124extern struct keynote_session *keynote_sessions[SESSIONTABLESIZE];
125extern struct keynote_session *keynote_current_session;
126
127extern int keynote_exceptionflag;
128extern int keynote_used_variable;
129extern int keynote_returnvalue;
130extern int keynote_justrecord;
131extern int keynote_donteval;
132extern int keynote_errno;
133
134/* Extern definitions */
135extern int knlineno;
136
137/* Function prototypes */
138extern int keynote_env_add(char *, char *, struct environment **,
139                           unsigned int, int);
140extern char *keynote_env_lookup(char *, struct environment **, unsigned int);
141extern int keynote_env_delete(char *, struct environment **, unsigned int);
142extern struct keylist *keynote_keylist_find(struct keylist *, char *);
143extern struct environment *keynote_get_envlist(char *, char *, int);
144extern struct assertion *keynote_parse_assertion(char *, int, int);
145extern int keynote_evaluate_authorizer(struct assertion *, int);
146extern struct assertion *keynote_find_assertion(void *, int, int);
147extern void keynote_env_cleanup(struct environment **, unsigned int);
148extern int keynote_get_key_algorithm(char *, int *, int *);
149extern int keynote_sigverify_assertion(struct assertion *);
150extern int keynote_evaluate_assertion(struct assertion *);
151extern int keynote_parse_keypred(struct assertion *, int);
152extern int keynote_keylist_add(struct keylist **, char *);
153extern int keynote_add_htable(struct assertion *, int);
154extern void keynote_free_assertion(struct assertion *);
155extern int keynote_in_action_authorizers(void *, int);
156extern struct keynote_session *keynote_find_session(int);
157extern void keynote_keylist_free(struct keylist *);
158extern void keynote_free_env(struct environment *);
159extern int  keynote_sremove_assertion(int, int);
160extern unsigned int keynote_stringhash(char *, unsigned int);
161extern char *keynote_get_private_key(char *);
162extern void keynote_free_key(void *, int);
163extern int keynote_evaluate_query(void);
164extern int keynote_lex_add(void *, int);
165extern void keynote_lex_remove(void *);
166extern void keynote_cleanup_kth(void);
167extern int keynote_retindex(char *);
168extern void knerror(char *);
169extern int knparse(void);
170extern int knlex(void);
171#endif /* __ASSERTION_H__ */
172