xref: /openbsd/lib/libkeynote/keynote.h (revision 4d8bb350)
1 /* $OpenBSD: keynote.h,v 1.16 2004/06/24 21:34:33 msf 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 __KEYNOTE_H__
23 #define __KEYNOTE_H__
24 
25 struct environment
26 {
27     char               *env_name;
28     char               *env_value;
29     int                 env_flags;
30     regex_t             env_regex;
31     struct environment *env_next;
32 };
33 
34 struct keynote_deckey
35 {
36     int   dec_algorithm;
37     void *dec_key;
38 };
39 
40 struct keynote_binary
41 {
42     int   bn_len;
43     char *bn_key;
44 };
45 
46 struct keynote_keylist
47 {
48     int                     key_alg;
49     void                   *key_key;
50     char                   *key_stringkey;
51     struct keynote_keylist *key_next;
52 };
53 
54 #define SIG_DSA_SHA1_HEX              "sig-dsa-sha1-hex:"
55 #define SIG_DSA_SHA1_HEX_LEN          strlen(SIG_DSA_SHA1_HEX)
56 #define SIG_DSA_SHA1_BASE64           "sig-dsa-sha1-base64:"
57 #define SIG_DSA_SHA1_BASE64_LEN       strlen(SIG_DSA_SHA1_BASE64)
58 #define SIG_RSA_SHA1_PKCS1_HEX        "sig-rsa-sha1-hex:"
59 #define SIG_RSA_SHA1_PKCS1_HEX_LEN    strlen(SIG_RSA_SHA1_PKCS1_HEX)
60 #define SIG_RSA_SHA1_PKCS1_BASE64     "sig-rsa-sha1-base64:"
61 #define SIG_RSA_SHA1_PKCS1_BASE64_LEN strlen(SIG_RSA_SHA1_PKCS1_BASE64)
62 #define SIG_RSA_MD5_PKCS1_HEX         "sig-rsa-md5-hex:"
63 #define SIG_RSA_MD5_PKCS1_HEX_LEN     strlen(SIG_RSA_MD5_PKCS1_HEX)
64 #define SIG_RSA_MD5_PKCS1_BASE64      "sig-rsa-md5-base64:"
65 #define SIG_RSA_MD5_PKCS1_BASE64_LEN  strlen(SIG_RSA_MD5_PKCS1_BASE64)
66 #define SIG_ELGAMAL_SHA1_HEX          "sig-elgamal-sha1-hex:"
67 #define SIG_ELGAMAL_SHA1_HEX_LEN      strlen(SIG_ELGAMAL_SHA1_HEX)
68 #define SIG_ELGAMAL_SHA1_BASE64       "sig-elgamal-sha1-base64:"
69 #define SIG_ELGAMAL_SHA1_BASE64_LEN   strlen(SIG_ELGAMAL_SHA1_BASE64)
70 #define SIG_PGP_NATIVE                "sig-pgp:"
71 #define SIG_PGP_NATIVE_LEN            strlen(SIG_PGP_NATIVE)
72 #define SIG_X509_SHA1_BASE64          "sig-x509-sha1-base64:"
73 #define SIG_X509_SHA1_BASE64_LEN      strlen(SIG_X509_SHA1_BASE64)
74 #define SIG_X509_SHA1_HEX             "sig-x509-sha1-hex:"
75 #define SIG_X509_SHA1_HEX_LEN         strlen(SIG_X509_SHA1_HEX)
76 
77 #define SIGRESULT_UNTOUCHED     0
78 #define SIGRESULT_FALSE         1
79 #define SIGRESULT_TRUE          2
80 
81 #define ENVIRONMENT_FLAG_FUNC   0x0001 /* This is a callback function */
82 #define ENVIRONMENT_FLAG_REGEX  0x0002 /* Regular expression for name */
83 
84 #define ASSERT_FLAG_LOCAL       0x0001 /*
85 					* Trusted assertion -- means
86 					* signature is not verified, and
87 					* authorizer field can
88 					* include symbolic names.
89 				        */
90 #define ASSERT_FLAG_SIGGEN      0x0002 /*
91 					* Be a bit more lax with the
92 					* contents of the Signature:
93 					* field; to be used in
94 					* assertion signing only.
95 					*/
96 #define ASSERT_FLAG_SIGVER	0x0004 /*
97 					* To be used in signature verification
98 					* only.
99 					*/
100 #define RESULT_FALSE            0
101 #define RESULT_TRUE             1
102 
103 #define KEYNOTE_CALLBACK_INITIALIZE		"_KEYNOTE_CALLBACK_INITIALIZE"
104 #define KEYNOTE_CALLBACK_CLEANUP		"_KEYNOTE_CALLBACK_CLEANUP"
105 
106 #define KEYNOTE_VERSION_STRING			"2"
107 
108 #define ERROR_MEMORY	       -1
109 #define ERROR_SYNTAX	       -2
110 #define ERROR_NOTFOUND         -3
111 #define ERROR_SIGN_FAILURE     -4
112 
113 #define KEYNOTE_ALGORITHM_UNSPEC       -1
114 #define KEYNOTE_ALGORITHM_NONE		0
115 #define KEYNOTE_ALGORITHM_DSA		1
116 #define KEYNOTE_ALGORITHM_ELGAMAL	2
117 #define KEYNOTE_ALGORITHM_PGP		3
118 #define KEYNOTE_ALGORITHM_BINARY        4
119 #define KEYNOTE_ALGORITHM_X509          5
120 #define KEYNOTE_ALGORITHM_RSA		6
121 
122 #define KEYNOTE_ERROR_ANY        0
123 #define KEYNOTE_ERROR_SYNTAX     1
124 #define KEYNOTE_ERROR_MEMORY     2
125 #define KEYNOTE_ERROR_SIGNATURE  3
126 
127 #define ENCODING_NONE		   0
128 #define ENCODING_HEX		   1
129 #define ENCODING_BASE64		   2
130 #define ENCODING_NATIVE		   3	/* For things like PGP */
131 
132 #define INTERNAL_ENC_NONE	   0
133 #define INTERNAL_ENC_PKCS1	   1
134 #define INTERNAL_ENC_ASN1          2
135 #define INTERNAL_ENC_NATIVE	   3	/* For things like PGP */
136 
137 #define KEYNOTE_PUBLIC_KEY         0
138 #define KEYNOTE_PRIVATE_KEY        1
139 
140 extern int keynote_errno;
141 
142 __BEGIN_DECLS
143 /* Session API */
144 int    kn_init(void);
145 int    kn_add_assertion(int, char *, int, int);
146 int    kn_remove_assertion(int, int);
147 int    kn_add_action(int, char *, char *, int);
148 int    kn_remove_action(int, char *);
149 int    kn_add_authorizer(int, char *);
150 int    kn_remove_authorizer(int, char *);
151 int    kn_do_query(int, char **, int);
152 int    kn_get_failed(int, int, int);
153 int    kn_cleanup_action_environment(int);
154 int    kn_close(int);
155 void   kn_free_key(struct keynote_deckey *);
156 char  *kn_get_string(char *);
157 
158 /* Simple API */
159 int    kn_query(struct environment *, char **, int, char **, int *, int,
160 		char **, int *, int, char **, int);
161 
162 /* Aux. routines */
163 char **kn_read_asserts(char *, int, int *);
164 int    kn_keycompare(void *, void *, int);
165 void  *kn_get_authorizer(int, int, int *);
166 struct keynote_keylist *kn_get_licensees(int, int);
167 
168 /* ASCII-encoding API */
169 int    kn_encode_base64(unsigned char const *, unsigned int, char *,
170 			unsigned int);
171 int    kn_decode_base64(char const *, unsigned char *, unsigned int);
172 int    kn_encode_hex(unsigned char *, char **, int);
173 int    kn_decode_hex(char *, char **);
174 
175 /* Key-encoding API */
176 int    kn_decode_key(struct keynote_deckey *, char *, int);
177 char  *kn_encode_key(struct keynote_deckey *, int, int, int);
178 
179 /* Crypto API */
180 char  *kn_sign_assertion(char *, int, char *, char *, int);
181 int    kn_verify_assertion(char *, int);
182 __END_DECLS
183 #endif /* __KEYNOTE_H__ */
184