Move ui and cstp stuff out of ssl.c
[platform/upstream/openconnect.git] / ssl_ui.c
1 /*
2  * Open AnyConnect (SSL + DTLS) client
3  *
4  * © 2008 David Woodhouse <dwmw2@infradead.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to:
18  *
19  *   Free Software Foundation, Inc.
20  *   51 Franklin Street, Fifth Floor,
21  *   Boston, MA 02110-1301 USA
22  */
23 #include <openssl/ssl.h>
24 #include <openssl/ui.h>
25
26 /* OpenSSL UI method calls. These are just stubs, to show how it's done */
27 /* While we can set user data on the calls from the TPM setup, we can't
28    set it on the calls for PEM certificate passphrases, AFAICT. */
29 static int ui_open(UI *ui)
30 {
31         /* Fall through to default OpenSSL UI */
32         return UI_method_get_opener(UI_OpenSSL())(ui);
33 }
34
35 static int ui_read(UI *ui, UI_STRING *uis)
36 {
37         /* Fall through to default OpenSSL UI */
38         return UI_method_get_reader(UI_OpenSSL())(ui, uis);
39 }
40 static int ui_write(UI *ui, UI_STRING *uis)
41 {
42         /* Fall through to default OpenSSL UI */
43         return UI_method_get_writer(UI_OpenSSL())(ui, uis);
44
45 }
46 static int ui_close(UI *ui)
47 {
48         /* Fall through to default OpenSSL UI */
49         return UI_method_get_closer(UI_OpenSSL())(ui);
50 }
51
52 int set_openssl_ui(void)
53 {
54         UI_METHOD *ui_method = UI_create_method("AnyConnect VPN UI");
55
56         /* Set up a UI method of our own for password/passphrase requests */
57         UI_method_set_opener(ui_method, ui_open);
58         UI_method_set_reader(ui_method, ui_read);
59         UI_method_set_writer(ui_method, ui_write);
60         UI_method_set_closer(ui_method, ui_close);
61
62         UI_set_default_method(ui_method);
63
64         return 0;
65 }
66