1*e1cb6e2eSjsg /* $OpenBSD: assertion.h,v 1.6 2024/05/21 11:13:08 jsg Exp $ */ 2983e9580Sangelos /* 3983e9580Sangelos * The author of this code is Angelos D. Keromytis (angelos@dsl.cis.upenn.edu) 4983e9580Sangelos * 5983e9580Sangelos * This code was written by Angelos D. Keromytis in Philadelphia, PA, USA, 6983e9580Sangelos * in April-May 1998 7983e9580Sangelos * 8983e9580Sangelos * Copyright (C) 1998, 1999 by Angelos D. Keromytis. 9983e9580Sangelos * 105e4ac158Sderaadt * Permission to use, copy, and modify this software with or without fee 11983e9580Sangelos * is hereby granted, provided that this entire notice is included in 12983e9580Sangelos * all copies of any software which is or includes a copy or 13983e9580Sangelos * modification of this software. 14983e9580Sangelos * 15983e9580Sangelos * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 16983e9580Sangelos * IMPLIED WARRANTY. IN PARTICULAR, THE AUTHORS MAKES NO 17983e9580Sangelos * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 18983e9580Sangelos * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 19983e9580Sangelos * PURPOSE. 20983e9580Sangelos */ 21983e9580Sangelos 22983e9580Sangelos #ifndef __ASSERTION_H__ 23983e9580Sangelos #define __ASSERTION_H__ 24983e9580Sangelos 25a8a6ad51Sangelos /* 26a8a6ad51Sangelos * These can be changed to reflect more assertions/session or more 27a8a6ad51Sangelos * sessions respectively 28a8a6ad51Sangelos */ 29a8a6ad51Sangelos #define HASHTABLESIZE 37 30a8a6ad51Sangelos #define SESSIONTABLESIZE 37 31a8a6ad51Sangelos 32a8a6ad51Sangelos struct keynote_session 33a8a6ad51Sangelos { 34a8a6ad51Sangelos int ks_id; 35a8a6ad51Sangelos int ks_assertioncounter; 36a8a6ad51Sangelos int ks_values_num; 37a8a6ad51Sangelos struct environment *ks_env_table[HASHTABLESIZE]; 38a8a6ad51Sangelos struct environment *ks_env_regex; 39a8a6ad51Sangelos struct keylist *ks_action_authorizers; 40a8a6ad51Sangelos struct assertion *ks_assertion_table[HASHTABLESIZE]; 41a8a6ad51Sangelos char **ks_values; 42a8a6ad51Sangelos char *ks_authorizers_cache; 43a8a6ad51Sangelos char *ks_values_cache; 44a8a6ad51Sangelos struct keynote_session *ks_prev; 45a8a6ad51Sangelos struct keynote_session *ks_next; 46a8a6ad51Sangelos }; 47983e9580Sangelos 48983e9580Sangelos struct keylist 49983e9580Sangelos { 50983e9580Sangelos int key_alg; 51983e9580Sangelos void *key_key; 52983e9580Sangelos char *key_stringkey; 53983e9580Sangelos struct keylist *key_next; 54983e9580Sangelos }; 55983e9580Sangelos 56983e9580Sangelos struct assertion 57983e9580Sangelos { 58983e9580Sangelos void *as_authorizer; 59983e9580Sangelos char *as_buf; 60983e9580Sangelos char *as_signature; 61983e9580Sangelos char *as_authorizer_string_s; 62983e9580Sangelos char *as_authorizer_string_e; 63983e9580Sangelos char *as_keypred_s; 64983e9580Sangelos char *as_keypred_e; 65983e9580Sangelos char *as_conditions_s; 66983e9580Sangelos char *as_conditions_e; 67983e9580Sangelos char *as_signature_string_s; 68983e9580Sangelos char *as_signature_string_e; 69983e9580Sangelos char *as_comment_s; 70983e9580Sangelos char *as_comment_e; 71983e9580Sangelos char *as_startofsignature; 72983e9580Sangelos char *as_allbutsignature; 73983e9580Sangelos int as_id; 74983e9580Sangelos int as_signeralgorithm; 75983e9580Sangelos int as_result; 76983e9580Sangelos int as_error; 77a8c336f3Sangelos unsigned char as_flags; 78a8c336f3Sangelos unsigned char as_internalflags; 79983e9580Sangelos char as_kresult; 80983e9580Sangelos char as_sigresult; 81983e9580Sangelos struct keylist *as_keylist; 82983e9580Sangelos struct environment *as_env; 83983e9580Sangelos struct assertion *as_next; 84983e9580Sangelos }; 85983e9580Sangelos 86983e9580Sangelos /* Internal flags */ 87983e9580Sangelos #define ASSERT_IFLAG_WEIRDLICS 0x0001 /* Needs Licensees re-processing */ 88983e9580Sangelos #define ASSERT_IFLAG_WEIRDAUTH 0x0002 /* Needs Authorizer re-processing */ 89983e9580Sangelos #define ASSERT_IFLAG_WEIRDSIG 0x0004 /* Needs Signature re-processing */ 90983e9580Sangelos #define ASSERT_IFLAG_NEEDPROC 0x0008 /* Needs "key field" processing */ 91983e9580Sangelos #define ASSERT_IFLAG_PROCESSED 0x0010 /* Handled repositioning already */ 92983e9580Sangelos 93983e9580Sangelos #define KRESULT_UNTOUCHED 0 94983e9580Sangelos #define KRESULT_IN_PROGRESS 1 /* For cycle detection */ 95983e9580Sangelos #define KRESULT_DONE 2 96983e9580Sangelos 97983e9580Sangelos #define KEYWORD_VERSION 1 98983e9580Sangelos #define KEYWORD_LOCALINIT 2 99983e9580Sangelos #define KEYWORD_AUTHORIZER 3 100983e9580Sangelos #define KEYWORD_LICENSEES 4 101983e9580Sangelos #define KEYWORD_CONDITIONS 5 102983e9580Sangelos #define KEYWORD_SIGNATURE 6 103983e9580Sangelos #define KEYWORD_COMMENT 7 104983e9580Sangelos 105983e9580Sangelos #define KEYNOTE_FLAG_EXPORTALL 0x1 106983e9580Sangelos 107a8a6ad51Sangelos /* List types for cleanup */ 108983e9580Sangelos #define LEXTYPE_CHAR 0x1 109983e9580Sangelos 110a8a6ad51Sangelos /* Length of random initializer */ 111a8a6ad51Sangelos #define KEYNOTE_RAND_INIT_LEN 1024 112a8a6ad51Sangelos 113a8a6ad51Sangelos /* Variables */ 114a8a6ad51Sangelos extern char **keynote_values; 115a8a6ad51Sangelos extern char *keynote_privkey; 116a8a6ad51Sangelos 117a8a6ad51Sangelos extern struct assertion *keynote_current_assertion; 118a8a6ad51Sangelos 119a8a6ad51Sangelos extern struct environment *keynote_init_list; 120a8a6ad51Sangelos extern struct environment *keynote_temp_list; 121a8a6ad51Sangelos 122a8a6ad51Sangelos extern struct keylist *keynote_keypred_keylist; 123a8a6ad51Sangelos 124a8a6ad51Sangelos extern struct keynote_session *keynote_sessions[SESSIONTABLESIZE]; 125a8a6ad51Sangelos extern struct keynote_session *keynote_current_session; 126a8a6ad51Sangelos 127a8a6ad51Sangelos extern int keynote_exceptionflag; 128a8a6ad51Sangelos extern int keynote_used_variable; 129a8a6ad51Sangelos extern int keynote_returnvalue; 130a8a6ad51Sangelos extern int keynote_justrecord; 131a8a6ad51Sangelos extern int keynote_donteval; 132a8a6ad51Sangelos extern int keynote_errno; 133a8a6ad51Sangelos 134a8a6ad51Sangelos /* Extern definitions */ 135a8a6ad51Sangelos extern int knlineno; 136a8a6ad51Sangelos 137a8a6ad51Sangelos /* Function prototypes */ 138a8c336f3Sangelos extern int keynote_env_add(char *, char *, struct environment **, 139a8c336f3Sangelos unsigned int, int); 140a8c336f3Sangelos extern char *keynote_env_lookup(char *, struct environment **, unsigned int); 141a8c336f3Sangelos extern int keynote_env_delete(char *, struct environment **, unsigned int); 142a8a6ad51Sangelos extern struct keylist *keynote_keylist_find(struct keylist *, char *); 143a8a6ad51Sangelos extern struct environment *keynote_get_envlist(char *, char *, int); 144a8a6ad51Sangelos extern struct assertion *keynote_parse_assertion(char *, int, int); 145a8a6ad51Sangelos extern int keynote_evaluate_authorizer(struct assertion *, int); 146a8a6ad51Sangelos extern struct assertion *keynote_find_assertion(void *, int, int); 147a8c336f3Sangelos extern void keynote_env_cleanup(struct environment **, unsigned int); 148a8a6ad51Sangelos extern int keynote_get_key_algorithm(char *, int *, int *); 149a8a6ad51Sangelos extern int keynote_sigverify_assertion(struct assertion *); 150a8a6ad51Sangelos extern int keynote_evaluate_assertion(struct assertion *); 151a8a6ad51Sangelos extern int keynote_parse_keypred(struct assertion *, int); 152a8a6ad51Sangelos extern int keynote_keylist_add(struct keylist **, char *); 153a8a6ad51Sangelos extern int keynote_add_htable(struct assertion *, int); 154a8a6ad51Sangelos extern void keynote_free_assertion(struct assertion *); 155a8a6ad51Sangelos extern int keynote_in_action_authorizers(void *, int); 156a8a6ad51Sangelos extern struct keynote_session *keynote_find_session(int); 157a8a6ad51Sangelos extern void keynote_keylist_free(struct keylist *); 158a8a6ad51Sangelos extern void keynote_free_env(struct environment *); 159a8a6ad51Sangelos extern int keynote_sremove_assertion(int, int); 160a8c336f3Sangelos extern unsigned int keynote_stringhash(char *, unsigned int); 161a8a6ad51Sangelos extern char *keynote_get_private_key(char *); 162a8a6ad51Sangelos extern void keynote_free_key(void *, int); 163a8a6ad51Sangelos extern int keynote_evaluate_query(void); 164a8a6ad51Sangelos extern int keynote_lex_add(void *, int); 165a8a6ad51Sangelos extern void keynote_lex_remove(void *); 166a8a6ad51Sangelos extern void keynote_cleanup_kth(void); 167a8a6ad51Sangelos extern int keynote_retindex(char *); 168a8a6ad51Sangelos extern void knerror(char *); 16931ffb508Sderaadt extern int knparse(void); 17031ffb508Sderaadt extern int knlex(void); 171983e9580Sangelos #endif /* __ASSERTION_H__ */ 172