NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
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...


 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.

  • 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

Definition in file ssl.h.

Function Documentation


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.

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

Definition at line 158 of file dlg_verifycert.c.

160 const char **line = NULL;
161 ARRAY_FOREACH(line, carr)
162 {
163 FREE(line);
164 }
#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.

connConnection to a server
Return values

Definition at line 1123 of file gnutls.c.

1125 if (tls_init() < 0)
1126 return -1;
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;
1134 return 0;
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.

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.

187 struct CertMenuData mdata = { carr };
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);
195 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
196 sbar_set_title(sbar, title);
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 }
238 bool old_ime = OptIgnoreMacroEvents;
241 // ---------------------------------------------------------------------------
242 // Event Loop
243 int choice = 0;
244 int op = OP_NULL;
245 do
246 {
247 window_redraw(NULL);
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 ( == 'q')
255 op = OP_EXIT;
256 else
257 op = event.op;
258 }
260 if (op == OP_TIMEOUT)
261 continue;
263 // Convert menubar movement to scrolling
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);
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;
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;
301 case OP_SEARCH:
302 case OP_SEARCH_NEXT:
305 mutt_error(_("Search is not implemented for this menu"));
306 continue;
307 }
309 (void) menu_function_dispatcher(menu->win, op);
310 } while (choice == 0);
311 // ---------------------------------------------------------------------------
313 OptIgnoreMacroEvents = old_ime;
315 simple_dialog_free(&dlg);
317 return choice;
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
Question/user input.
Definition: color.h:57
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.
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
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
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:604
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:522
Certificate Dialog, dlg_verify_certificate()
Definition: mutt_window.h:81
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
Definition: opcodes.h:378
bool OptIgnoreMacroEvents
(pseudo) don't process macro/push/exec events while set
Definition: options.h:43
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:69
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:96
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
void * mdata
Private data.
Definition: lib.h:137
int max
Number of entries in the menu.
Definition: lib.h:71
void * wdata
Private data.
Definition: mutt_window.h:145
Generic selection list.
Definition: type.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function: