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 32 struct 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 48 struct keylist 49 { 50 int key_alg; 51 void *key_key; 52 char *key_stringkey; 53 struct keylist *key_next; 54 }; 55 56 struct 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 */ 114 extern char **keynote_values; 115 extern char *keynote_privkey; 116 117 extern struct assertion *keynote_current_assertion; 118 119 extern struct environment *keynote_init_list; 120 extern struct environment *keynote_temp_list; 121 122 extern struct keylist *keynote_keypred_keylist; 123 124 extern struct keynote_session *keynote_sessions[SESSIONTABLESIZE]; 125 extern struct keynote_session *keynote_current_session; 126 127 extern int keynote_exceptionflag; 128 extern int keynote_used_variable; 129 extern int keynote_returnvalue; 130 extern int keynote_justrecord; 131 extern int keynote_donteval; 132 extern int keynote_errno; 133 134 /* Extern definitions */ 135 extern int knlineno; 136 137 /* Function prototypes */ 138 extern int keynote_env_add(char *, char *, struct environment **, 139 unsigned int, int); 140 extern char *keynote_env_lookup(char *, struct environment **, unsigned int); 141 extern int keynote_env_delete(char *, struct environment **, unsigned int); 142 extern struct keylist *keynote_keylist_find(struct keylist *, char *); 143 extern struct environment *keynote_get_envlist(char *, char *, int); 144 extern struct assertion *keynote_parse_assertion(char *, int, int); 145 extern int keynote_evaluate_authorizer(struct assertion *, int); 146 extern struct assertion *keynote_find_assertion(void *, int, int); 147 extern void keynote_env_cleanup(struct environment **, unsigned int); 148 extern int keynote_get_key_algorithm(char *, int *, int *); 149 extern int keynote_sigverify_assertion(struct assertion *); 150 extern int keynote_evaluate_assertion(struct assertion *); 151 extern int keynote_parse_keypred(struct assertion *, int); 152 extern int keynote_keylist_add(struct keylist **, char *); 153 extern int keynote_add_htable(struct assertion *, int); 154 extern void keynote_free_assertion(struct assertion *); 155 extern int keynote_in_action_authorizers(void *, int); 156 extern struct keynote_session *keynote_find_session(int); 157 extern void keynote_keylist_free(struct keylist *); 158 extern void keynote_free_env(struct environment *); 159 extern int keynote_sremove_assertion(int, int); 160 extern unsigned int keynote_stringhash(char *, unsigned int); 161 extern char *keynote_get_private_key(char *); 162 extern void keynote_free_key(void *, int); 163 extern int keynote_evaluate_query(void); 164 extern int keynote_lex_add(void *, int); 165 extern void keynote_lex_remove(void *); 166 extern void keynote_cleanup_kth(void); 167 extern int keynote_retindex(char *); 168 extern void knerror(char *); 169 extern int knparse(void); 170 extern int knlex(void); 171 #endif /* __ASSERTION_H__ */ 172