Commit 265084d8ab9e6d3735aaaa853eb432f11de234d4
1 parent
5d32071a
Exists in
master
and in
3 other branches
Refactoring CRL check engine.
Showing
4 changed files
with
188 additions
and
4 deletions
Show diff stats
lib3270.cbp
@@ -50,6 +50,9 @@ | @@ -50,6 +50,9 @@ | ||
50 | <Unit filename="src/core/ansi.c"> | 50 | <Unit filename="src/core/ansi.c"> |
51 | <Option compilerVar="CC" /> | 51 | <Option compilerVar="CC" /> |
52 | </Unit> | 52 | </Unit> |
53 | + <Unit filename="src/core/array.c"> | ||
54 | + <Option compilerVar="CC" /> | ||
55 | + </Unit> | ||
53 | <Unit filename="src/core/bounds.c"> | 56 | <Unit filename="src/core/bounds.c"> |
54 | <Option compilerVar="CC" /> | 57 | <Option compilerVar="CC" /> |
55 | </Unit> | 58 | </Unit> |
@@ -225,6 +228,7 @@ | @@ -225,6 +228,7 @@ | ||
225 | <Unit filename="src/include/3270ds.h" /> | 228 | <Unit filename="src/include/3270ds.h" /> |
226 | <Unit filename="src/include/ansic.h" /> | 229 | <Unit filename="src/include/ansic.h" /> |
227 | <Unit filename="src/include/arpa_telnet.h" /> | 230 | <Unit filename="src/include/arpa_telnet.h" /> |
231 | + <Unit filename="src/include/array.h" /> | ||
228 | <Unit filename="src/include/cg.h" /> | 232 | <Unit filename="src/include/cg.h" /> |
229 | <Unit filename="src/include/config.h" /> | 233 | <Unit filename="src/include/config.h" /> |
230 | <Unit filename="src/include/config.h.in" /> | 234 | <Unit filename="src/include/config.h.in" /> |
@@ -0,0 +1,79 @@ | @@ -0,0 +1,79 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como array.c e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + | ||
31 | +/** | ||
32 | + * @brief Handle text arrays. | ||
33 | + */ | ||
34 | + | ||
35 | + #include <lib3270.h> | ||
36 | + #include <lib3270/log.h> | ||
37 | + #include <array.h> | ||
38 | + #include <string.h> | ||
39 | + | ||
40 | +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ | ||
41 | + | ||
42 | +LIB3270_STRING_ARRAY * lib3270_string_array_new(void) | ||
43 | +{ | ||
44 | + LIB3270_STRING_ARRAY * array = lib3270_malloc(sizeof(LIB3270_STRING_ARRAY)); | ||
45 | + memset(array,0,sizeof(LIB3270_STRING_ARRAY)); | ||
46 | + | ||
47 | + return array; | ||
48 | +} | ||
49 | + | ||
50 | +void lib3270_string_array_free(LIB3270_STRING_ARRAY *array) | ||
51 | +{ | ||
52 | + size_t ix; | ||
53 | + | ||
54 | + if(array) | ||
55 | + { | ||
56 | + for(ix = 0; ix < array->length; ix++) | ||
57 | + lib3270_free((char *) array->str[ix]); | ||
58 | + | ||
59 | + lib3270_free(array->str); | ||
60 | + lib3270_free(array); | ||
61 | + } | ||
62 | +} | ||
63 | + | ||
64 | +LIB3270_INTERNAL void lib3270_string_array_append(LIB3270_STRING_ARRAY *array, const char *str) | ||
65 | +{ | ||
66 | + if(array->str) | ||
67 | + { | ||
68 | + array->str = lib3270_realloc(array->str,(array->length + 1) * sizeof(char *)); | ||
69 | + } | ||
70 | + else | ||
71 | + { | ||
72 | + array->str = lib3270_malloc(sizeof(char *)); | ||
73 | + array->length = 0; // Just in case. | ||
74 | + } | ||
75 | + | ||
76 | + array->str[array->length++] = strdup(str); | ||
77 | + | ||
78 | +} | ||
79 | + |
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | +/** | ||
31 | + * @file array.h | ||
32 | + * @brief Global declarations for array.c. | ||
33 | + */ | ||
34 | + | ||
35 | +#ifndef LIB3270_ARRAY_H_INCLUDED | ||
36 | + | ||
37 | + #define LIB3270_ARRAY_H_INCLUDED | ||
38 | + | ||
39 | + #include <lib3270.h> | ||
40 | + | ||
41 | + typedef struct _lib3270_string_array | ||
42 | + { | ||
43 | + size_t length; ///< @brief Number of elements. | ||
44 | + const char **str; | ||
45 | + } LIB3270_STRING_ARRAY; | ||
46 | + | ||
47 | + LIB3270_INTERNAL LIB3270_STRING_ARRAY * lib3270_string_array_new(void); | ||
48 | + LIB3270_INTERNAL void lib3270_string_array_free(LIB3270_STRING_ARRAY *object); | ||
49 | + LIB3270_INTERNAL void lib3270_string_array_append(LIB3270_STRING_ARRAY *object, const char *str); | ||
50 | + | ||
51 | + inline void lib3270_autoptr_cleanup_LIB3270_STRING_ARRAY(LIB3270_STRING_ARRAY **ptr) | ||
52 | + { | ||
53 | + lib3270_string_array_free(*ptr); | ||
54 | + } | ||
55 | + | ||
56 | +#endif // LIB3270_ARRAY_H_INCLUDED |
src/ssl/negotiate.c
@@ -41,6 +41,7 @@ | @@ -41,6 +41,7 @@ | ||
41 | #include <openssl/err.h> | 41 | #include <openssl/err.h> |
42 | #include <openssl/x509_vfy.h> | 42 | #include <openssl/x509_vfy.h> |
43 | #include <openssl/x509v3.h> | 43 | #include <openssl/x509v3.h> |
44 | + #include <array.h> | ||
44 | 45 | ||
45 | #ifndef SSL_ST_OK | 46 | #ifndef SSL_ST_OK |
46 | #define SSL_ST_OK 3 | 47 | #define SSL_ST_OK 3 |
@@ -134,16 +135,60 @@ static int background_ssl_init(H3270 *hSession, void *message) | @@ -134,16 +135,60 @@ static int background_ssl_init(H3270 *hSession, void *message) | ||
134 | 135 | ||
135 | #if !defined(SSL_DEFAULT_CRL_URL) && defined(SSL_ENABLE_CRL_CHECK) | 136 | #if !defined(SSL_DEFAULT_CRL_URL) && defined(SSL_ENABLE_CRL_CHECK) |
136 | 137 | ||
137 | -static int getCRLFromDistPoints(CRL_DIST_POINTS * dist_points, SSL_ERROR_MESSAGE *message) | 138 | +static int getCRLFromDistPoints(H3270 *hSession, CRL_DIST_POINTS * dist_points, SSL_ERROR_MESSAGE *message) |
138 | { | 139 | { |
139 | - int ix; | 140 | + int ix, i, gtype; |
141 | + lib3270_autoptr(LIB3270_STRING_ARRAY) uris = lib3270_string_array_new(); | ||
142 | + | ||
143 | + // https://nougat.cablelabs.com/DLNA-RUI/openssl/commit/57912ed329f870b237f2fd9f2de8dec3477d1729 | ||
140 | 144 | ||
141 | for(ix = 0; ix < sk_DIST_POINT_num(dist_points); ix++) { | 145 | for(ix = 0; ix < sk_DIST_POINT_num(dist_points); ix++) { |
142 | 146 | ||
143 | - debug("CRL(%d):", ix); | 147 | + DIST_POINT *dp = sk_DIST_POINT_value(dist_points, ix); |
148 | + | ||
149 | + if(!dp->distpoint || dp->distpoint->type != 0) | ||
150 | + continue; | ||
151 | + | ||
152 | + GENERAL_NAMES *gens = dp->distpoint->name.fullname; | ||
153 | + | ||
154 | + for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) | ||
155 | + { | ||
156 | + GENERAL_NAME *gen = sk_GENERAL_NAME_value(gens, i); | ||
157 | + ASN1_STRING *uri = GENERAL_NAME_get0_value(gen, >ype); | ||
158 | + if(uri) | ||
159 | + { | ||
160 | + const unsigned char * data = ASN1_STRING_get0_data(uri); | ||
161 | + if(data) | ||
162 | + { | ||
163 | + lib3270_string_array_append(uris,(char *) data); | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + } | ||
168 | + | ||
169 | + } | ||
170 | + | ||
171 | +#ifdef DEBUG | ||
172 | + { | ||
173 | + for(ix = 0; ix < uris->length; ix++) | ||
174 | + { | ||
175 | + debug("%u: %s", (unsigned int) ix, uris->str[ix]); | ||
176 | + } | ||
177 | + } | ||
178 | +#endif // DEBUG | ||
144 | 179 | ||
180 | + /* | ||
181 | + if(hSession->ssl.crl.url) | ||
182 | + { | ||
183 | + // Check if we already have the URL. | ||
145 | 184 | ||
185 | + | ||
186 | + // The URL is invalid or not to this cert, remove it! | ||
187 | + lib3270_free(hSession->ssl.crl.url); | ||
188 | + hSession->ssl.crl.url = NULL; | ||
146 | } | 189 | } |
190 | + */ | ||
191 | + | ||
147 | 192 | ||
148 | return 0; | 193 | return 0; |
149 | } | 194 | } |
@@ -247,7 +292,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) | @@ -247,7 +292,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) | ||
247 | return EACCES; | 292 | return EACCES; |
248 | } | 293 | } |
249 | 294 | ||
250 | - if(getCRLFromDistPoints(dist_points, (SSL_ERROR_MESSAGE *) message)) | 295 | + if(getCRLFromDistPoints(hSession, dist_points, (SSL_ERROR_MESSAGE *) message)) |
251 | return EACCES; | 296 | return EACCES; |
252 | 297 | ||
253 | #endif // !SSL_DEFAULT_CRL_URL && SSL_ENABLE_CRL_CHECK | 298 | #endif // !SSL_DEFAULT_CRL_URL && SSL_ENABLE_CRL_CHECK |