android: Set preferred language for remediation instructions
[strongswan.git] / src / frontends / android / jni / libandroidbridge / charonservice.h
1 /*
2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup libandroidbridge libandroidbridge
20 *
21 * @defgroup android_backend backend
22 * @ingroup libandroidbridge
23 *
24 * @defgroup android_byod byod
25 * @ingroup libandroidbridge
26 *
27 * @defgroup android_kernel kernel
28 * @ingroup libandroidbridge
29 *
30 * @defgroup charonservice charonservice
31 * @{ @ingroup libandroidbridge
32 */
33
34 #ifndef CHARONSERVICE_H_
35 #define CHARONSERVICE_H_
36
37 #include "vpnservice_builder.h"
38 #include "kernel/network_manager.h"
39
40 #include <library.h>
41 #include <collections/linked_list.h>
42
43 typedef enum android_vpn_state_t android_vpn_state_t;
44 typedef enum android_imc_state_t android_imc_state_t;
45 typedef struct charonservice_t charonservice_t;
46
47 /**
48 * VPN status codes. As defined in CharonVpnService.java
49 */
50 enum android_vpn_state_t {
51 CHARONSERVICE_CHILD_STATE_UP = 1,
52 CHARONSERVICE_CHILD_STATE_DOWN,
53 CHARONSERVICE_AUTH_ERROR,
54 CHARONSERVICE_PEER_AUTH_ERROR,
55 CHARONSERVICE_LOOKUP_ERROR,
56 CHARONSERVICE_UNREACHABLE_ERROR,
57 CHARONSERVICE_GENERIC_ERROR,
58 };
59
60 /**
61 * Final IMC state as defined in ImcState.java
62 */
63 enum android_imc_state_t {
64 ANDROID_IMC_STATE_UNKNOWN = 0,
65 ANDROID_IMC_STATE_ALLOW = 1,
66 ANDROID_IMC_STATE_BLOCK = 2,
67 ANDROID_IMC_STATE_ISOLATE = 3,
68 };
69
70 /**
71 * Public interface of charonservice.
72 *
73 * Used to communicate with CharonVpnService via JNI
74 */
75 struct charonservice_t {
76
77 /**
78 * Update the status in the Java domain (UI)
79 *
80 * @param code status code
81 * @return TRUE on success
82 */
83 bool (*update_status)(charonservice_t *this, android_vpn_state_t code);
84
85 /**
86 * Update final IMC state in the Java domain (UI)
87 *
88 * @param state IMC state
89 * @return TRUE on success
90 */
91 bool (*update_imc_state)(charonservice_t *this, android_imc_state_t state);
92
93 /**
94 * Add a remediation instruction via JNI
95 *
96 * @param instr remediation instruction
97 * @return TRUE on success
98 */
99 bool (*add_remediation_instr)(charonservice_t *this, char *instr);
100
101 /**
102 * Install a bypass policy for the given socket using the protect() Method
103 * of the Android VpnService interface.
104 *
105 * Use -1 as fd to re-bypass previously bypassed sockets.
106 *
107 * @param fd socket file descriptor
108 * @param family socket protocol family
109 * @return TRUE if operation successful
110 */
111 bool (*bypass_socket)(charonservice_t *this, int fd, int family);
112
113 /**
114 * Get a list of trusted certificates via JNI
115 *
116 * @return list of DER encoded certificates (as chunk_t*),
117 * NULL on failure
118 */
119 linked_list_t *(*get_trusted_certificates)(charonservice_t *this);
120
121 /**
122 * Get the configured user certificate chain via JNI
123 *
124 * The first item in the returned list is the user certificate followed
125 * by any remaining elements of the certificate chain.
126 *
127 * @return list of DER encoded certificates (as chunk_t*),
128 * NULL on failure
129 */
130 linked_list_t *(*get_user_certificate)(charonservice_t *this);
131
132 /**
133 * Get the configured private key via JNI
134 *
135 * @param pubkey the public key as extracted from the certificate
136 * @return PrivateKey object, NULL on failure
137 */
138 private_key_t *(*get_user_key)(charonservice_t *this, public_key_t *pubkey);
139
140 /**
141 * Get the current vpnservice_builder_t object
142 *
143 * @return VpnService.Builder instance
144 */
145 vpnservice_builder_t *(*get_vpnservice_builder)(charonservice_t *this);
146
147 /**
148 * Get the current network_manager_t object
149 *
150 * @return NetworkManager instance
151 */
152 network_manager_t *(*get_network_manager)(charonservice_t *this);
153 };
154
155 /**
156 * The single instance of charonservice_t.
157 *
158 * Set between JNI calls to initializeCharon() and deinitializeCharon().
159 */
160 extern charonservice_t *charonservice;
161
162 #endif /** CHARONSERVICE_H_ @}*/