NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
ssl.h File Reference

Handling of SSL encryption. More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
+ Include dependency graph for ssl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CertMenuData
 Certificate data to use in the Menu. More...
 

Functions

 ARRAY_HEAD (CertArray, const char *)
 Array of text making up a Certificate. More...
 
void cert_array_clear (struct CertArray *carr)
 Free all memory of a CertArray. More...
 
int mutt_ssl_socket_setup (struct Connection *conn)
 Set up SSL socket mulitplexor. More...
 
int dlg_verify_certificate (const char *title, struct CertArray *carr, bool allow_always, bool allow_skip)
 Ask the user to validate the certificate. More...
 

Detailed Description

Handling of SSL encryption.

Authors
  • Tommi Komulainen

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file ssl.h.

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( CertArray  ,
const char *   
)

Array of text making up a Certificate.

◆ cert_array_clear()

void cert_array_clear ( struct CertArray *  carr)

Free all memory of a CertArray.

Parameters
carrArray of text to clear
Note
Array is emptied, but not freed

Definition at line 158 of file dlg_verifycert.c.

159{
160 const char **line = NULL;
161 ARRAY_FOREACH(line, carr)
162 {
163 FREE(line);
164 }
165}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define FREE(x)
Definition: memory.h:43
+ Here is the caller graph for this function:

◆ mutt_ssl_socket_setup()

int mutt_ssl_socket_setup ( struct Connection conn)

Set up SSL socket mulitplexor.

Parameters
connConnection to a server
Return values
0Success
-1Error

Definition at line 1123 of file gnutls.c.

1124{
1125 if (tls_init() < 0)
1126 return -1;
1127
1128 conn->open = tls_socket_open;
1129 conn->read = tls_socket_read;
1130 conn->write = tls_socket_write;
1131 conn->close = tls_socket_close;
1132 conn->poll = tls_socket_poll;
1133
1134 return 0;
1135}
static int tls_init(void)
Set up Gnu TLS.
Definition: gnutls.c:91
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition: gnutls.c:1001
static int tls_socket_open(struct Connection *conn)
Open a TLS socket - Implements Connection::open() -.
Definition: gnutls.c:1026
static int tls_socket_poll(struct Connection *conn, time_t wait_secs)
Check whether a socket read would block - Implements Connection::poll() -.
Definition: gnutls.c:986
static int tls_socket_read(struct Connection *conn, char *buf, size_t count)
Read data from a TLS socket - Implements Connection::read() -.
Definition: gnutls.c:1043
static int tls_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a TLS socket - Implements Connection::write() -.
Definition: gnutls.c:1070
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition: connection.h:106
int(* write)(struct Connection *conn, const char *buf, size_t count)
Definition: connection.h:93
int(* close)(struct Connection *conn)
Definition: connection.h:117
int(* open)(struct Connection *conn)
Definition: connection.h:67
int(* read)(struct Connection *conn, char *buf, size_t count)
Definition: connection.h:80
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_verify_certificate()

int dlg_verify_certificate ( const char *  title,
struct CertArray *  carr,
bool  allow_always,
bool  allow_skip 
)

Ask the user to validate the certificate.

Parameters
titleMenu title
carrCertificate text to display
allow_alwaysIf true, allow the user to always accept the certificate
allow_skipIf true, allow the user to skip the verification
Return values
1Reject certificate (or menu aborted)
2Accept certificate once
3Accept certificate always/skip (see notes)
4Accept certificate skip

The possible retvals will depend on the parameters. The options are given in the order: Reject, Once, Always, Skip. The retval represents the chosen option.

Definition at line 182 of file dlg_verifycert.c.

184{
186
187 struct CertMenuData mdata = { carr };
188
189 struct Menu *menu = dlg->wdata;
190 menu->mdata = &mdata;
191 menu->mdata_free = NULL; // Menu doesn't own the data
193 menu->max = ARRAY_SIZE(carr);
194
195 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
196 sbar_set_title(sbar, title);
197
198 if (allow_always)
199 {
200 if (allow_skip)
201 {
202 mdata.prompt = _("(r)eject, accept (o)nce, (a)ccept always, (s)kip");
203 /* L10N: The letters correspond to the choices in the string:
204 "(r)eject, accept (o)nce, (a)ccept always, (s)kip"
205 This is an interactive certificate confirmation prompt for an SSL connection. */
206 mdata.keys = _("roas");
207 }
208 else
209 {
210 mdata.prompt = _("(r)eject, accept (o)nce, (a)ccept always");
211 /* L10N: The letters correspond to the choices in the string:
212 "(r)eject, accept (o)nce, (a)ccept always"
213 This is an interactive certificate confirmation prompt for an SSL connection. */
214 mdata.keys = _("roa");
215 }
216 }
217 else
218 {
219 if (allow_skip)
220 {
221 mdata.prompt = _("(r)eject, accept (o)nce, (s)kip");
222 /* L10N: The letters correspond to the choices in the string:
223 "(r)eject, accept (o)nce, (s)kip"
224 This is an interactive certificate confirmation prompt for an SSL connection. */
225 mdata.keys = _("ros");
226 }
227 else
228 {
229 mdata.prompt = _("(r)eject, accept (o)nce");
230 /* L10N: The letters correspond to the choices in the string:
231 "(r)eject, accept (o)nce"
232 This is an interactive certificate confirmation prompt for an SSL connection. */
233 mdata.keys = _("ro");
234 }
235 }
237
238 bool old_ime = OptIgnoreMacroEvents;
240
241 // ---------------------------------------------------------------------------
242 // Event Loop
243 int choice = 0;
244 int op = OP_NULL;
245 do
246 {
247 window_redraw(NULL);
249
250 // Try to catch dialog keys before ops
251 if (menu_dialog_dokey(menu, &op) != 0)
252 {
253 struct KeyEvent event = km_dokey_event(MENU_GENERIC);
254 if (event.ch == 'q')
255 op = OP_EXIT;
256 else
257 op = event.op;
258 }
259
260 if (op == OP_TIMEOUT)
261 continue;
262
263 // Convert menubar movement to scrolling
265
266 if (op <= OP_MAX)
267 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
268 else
269 mutt_debug(LL_DEBUG1, "Got choice %d\n", op - OP_MAX);
270
271 switch (op)
272 {
273 case -1: // Abort: Ctrl-G
274 case OP_EXIT: // Q)uit
275 case OP_MAX + 1: // R)eject
276 choice = 1;
277 break;
278 case OP_MAX + 2: // O)nce
279 choice = 2;
280 break;
281 case OP_MAX + 3: // A)lways / S)kip
282 choice = 3;
283 break;
284 case OP_MAX + 4: // S)kip
285 choice = 4;
286 break;
287
288 case OP_JUMP:
289 case OP_JUMP_1:
290 case OP_JUMP_2:
291 case OP_JUMP_3:
292 case OP_JUMP_4:
293 case OP_JUMP_5:
294 case OP_JUMP_6:
295 case OP_JUMP_7:
296 case OP_JUMP_8:
297 case OP_JUMP_9:
298 mutt_error(_("Jumping is not implemented for dialogs"));
299 continue;
300
301 case OP_SEARCH:
302 case OP_SEARCH_NEXT:
303 case OP_SEARCH_OPPOSITE:
304 case OP_SEARCH_REVERSE:
305 mutt_error(_("Search is not implemented for this menu"));
306 continue;
307 }
308
309 (void) menu_function_dispatcher(menu->win, op);
310 } while (choice == 0);
311 // ---------------------------------------------------------------------------
312
313 OptIgnoreMacroEvents = old_ime;
314
315 simple_dialog_free(&dlg);
316
317 return choice;
318}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
@ MT_COLOR_PROMPT
Question/user input.
Definition: color.h:60
static int menu_dialog_dokey(struct Menu *menu, int *id)
Check if there are any menu key events to process.
static int menu_dialog_translate_op(int op)
Convert menubar movement to scrolling.
static const struct Mapping VerifyHelp[]
Help Bar for the Certificate Verification dialog.
bool OptIgnoreMacroEvents
(pseudo) don't process macro/push/exec events while set
Definition: globals.c:71
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
#define mutt_error(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static void cert_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Create a string to display in a Menu - Implements Menu::make_entry() -.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
struct KeyEvent km_dokey_event(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:637
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void msgwin_set_text(enum ColorId cid, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:233
#define _(a)
Definition: message.h:28
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
@ WT_DLG_CERTIFICATE
Certificate Dialog, dlg_verify_certificate()
Definition: mutt_window.h:81
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
#define OP_TIMEOUT
Definition: opcodes.h:32
@ OP_MAX
Definition: opcodes.h:378
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
Certificate data to use in the Menu.
Definition: ssl.h:42
struct CertArray * carr
Lines of the Certificate.
Definition: ssl.h:43
char * prompt
Prompt for user, similar to mutt_multi_choice.
Definition: ssl.h:44
char * keys
Keys used in the prompt.
Definition: ssl.h:45
An event such as a keypress.
Definition: keymap.h:65
int op
Function opcode, e.g. OP_HELP.
Definition: keymap.h:67
int ch
Raw key pressed.
Definition: keymap.h:66
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
void * wdata
Private data.
Definition: mutt_window.h:145
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function: