Browse code

Document common uses of 'echo' directive, re-enable logging for 'echo'.

The 'echo' command can be used to signal information to an OpenVPN
GUI driving the openvpn core via management interface. Which commands
exists and their syntax has so far been mostly undocumented.

Condense the long and good discussion between Selva Nair and
Jonathan K. Bullard into doc/gui-notes.txt (initial draft from
Jonathan, comments from Selva and Arne), with a pointer added
to doc/management-notes.txt.

See:

https://sourceforge.net/p/openvpn/mailman/openvpn-users/thread/CAEsd45T%2Bd
6FUJ9Po0KHwtHjfuL9Q2D-poG8yFtY45Qyh%2BtHjkg%40mail.gmail.com/#msg36136236

and

https://sourceforge.net/p/openvpn/mailman/openvpn-devel/thread/CAKuzo_jPThh
vXTJAtzhqVUVOLPW1VGu6h2jQhVsHicY8P2WRqA%40mail.gmail.com/#msg36141193

for the details.

Re-enable logging of 'echo' statements, but only for the particular
class of messages starting with 'echo msg...'.

v2:
incorporate feedback from Selva Nair, correct >ECHO examples

v3:
add "msg*" support status for Windows GUI (11.22.0) and Android (Planned)

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20210118162850.24214-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21443.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Gert Doering authored on 2021/01/19 01:28:50
Showing 4 changed files
... ...
@@ -15,7 +15,7 @@ MAINTAINERCLEANFILES = \
15 15
 SUBDIRS = doxygen
16 16
 
17 17
 dist_doc_DATA = \
18
-	management-notes.txt
18
+	management-notes.txt gui-notes.txt
19 19
 
20 20
 dist_noinst_DATA = \
21 21
 	README.plugins interactive-service-notes.rst \
22 22
new file mode 100644
... ...
@@ -0,0 +1,369 @@
0
+Management Interface "echo" protocol
1
+
2
+================================================================================
3
+THIS IS A PRELIMINARY VERSION OF THIS DOCUMENT. ALL INFORMATION IN IT
4
+IS SUBJECT TO CHANGE.
5
+================================================================================
6
+
7
+
8
+    CONTENTS
9
+        THE OPENVPN --ECHO OPTION
10
+        ENVIRONMENT COMMAND
11
+        MESSSAGE COMMANDS
12
+        PASSWORD COMMANDS
13
+        QUOTING
14
+        COMMMAND DETAILS
15
+
16
+
17
+=========================
18
+THE OPENVPN --ECHO OPTION
19
+=========================
20
+
21
+The OpenVPN --echo option causes commands to be sent out through the
22
+management interface, typically to a Graphic User Interface (GUI) such
23
+as "OpenVPN for Android", "Tunnelblick" (for macOS), or "Windows
24
+OpenVPN GUI". It can be included in a configuration file or on a
25
+command line, or can be pushed from the server.
26
+
27
+This document describes the commands that can be sent and how they are
28
+interpreted by various GUIs.
29
+
30
+ * OpenVPN does not process the commands in an --echo option; it only
31
+sends them out through the management interface.
32
+
33
+ * "echo" commands are processed by the GUI if, as, when, and in the
34
+order they are received. If no GUI is present the processing of
35
+commands may be delayed, the commands may never be processed, or only
36
+some commands may be processed. (That can happen if OpenVPN discards
37
+commands because its buffer for the commands fills up.)
38
+
39
+ * There is no mechanism for the GUI to acknowledge the receipt,
40
+success, or failure of a command.
41
+
42
+ * "echo" commands are stored by OpenVPN (within limits, see the next
43
+point) and sent only when the GUI requests them through the management
44
+interface. "echo" commands in the configuration file or the command
45
+line are typically requested and processed at the start of a
46
+connection attempt. "echo" commands that are pushed by the server are
47
+also typically asked for at the start of a connection attempt but can
48
+be sent at any time. They are processed in the middle of a connection
49
+attempt or after a connection is established, as the "push" options
50
+are received by the client from the server.
51
+
52
+  * OpenVPN's storage for echo commands is limited in size, so a large
53
+number of commands or commands with long messages may require that
54
+some commands be removed from the storage. If that happens, some of
55
+the commands may not be sent through the management interface when a
56
+GUI does connect to it or asks for the "echo" commands.
57
+
58
+ * On SIGUSR1 and SIGHUP connection restarts, "echo" commands that
59
+were sent through the management interface and have been saved by
60
+OpenVPN are sent again and will be re-processed by the GUI. (The
61
+message commands include a mechanism for muting (skipping) duplicate
62
+messages, see MESSAGE COMMANDS, below.)
63
+
64
+ * OpenVPN limits the number of separate arguments in each line of a
65
+configuration file. Arguments may be quoted to work around this
66
+limitation, see QUOTING, below.
67
+
68
+ * OpenVPN limits the size of each "echo" command sent over the
69
+management interface to 255 bytes, including overhead characters. To
70
+allow messages of arbitrary length, several message commands can be
71
+concatenated together before being displayed to the user, see MESSAGE
72
+COMMANDS, below.
73
+
74
+ * There no indication to the GUI of the source of the command
75
+(configuration file, command line option, or pushed from a server). It
76
+might be possible for the GUI to deduce that a command was pushed from
77
+a server because of timing or other management interface interactions.
78
+
79
+
80
+===================
81
+ENVIRONMENT COMMAND
82
+===================
83
+
84
+Typically, a GUI allows users to specify shell commands (typically
85
+scripts) to run at certain points in the connection/disconnection
86
+process, in addition to those provided by OpenVPN options such as
87
+"--up" and "--down".
88
+
89
+The "setenv" command can be used to set environment variables that are
90
+available to the scripts run by the GUI. Each "setenv" command
91
+specifies a value for one environment variable that is available to
92
+the scripts that the GUI runs.
93
+
94
+This is similar to Openvpn's "--setenv" option, which specifies an
95
+additional environment variable that is included in the environment
96
+variables that are available to the scripts that OpenVPN runs.
97
+
98
+
99
+=================
100
+MESSSAGE COMMANDS
101
+=================
102
+
103
+Four commands can be used to display a message to the user from the
104
+OpenVPN configuration or server:
105
+
106
+    msg
107
+    msg-n
108
+    msg-window
109
+    msg-notify
110
+
111
+"msg" and "msg-n" commands are concatenated to construct a message.
112
+When a "msg-window"or "msg-notify" command is received the message is
113
+displayed to the user.
114
+
115
+Identical messages (same title, text, and destination) received during
116
+one connection may be ignored or muted. Some GUIs may only show the
117
+first message for a connection, or the first message shown in a window
118
+and the first message shown as a notification.
119
+
120
+
121
+=================
122
+PASSWORD COMMANDS
123
+=================
124
+
125
+Three commands can be used to control the GUI's storage of usernames,
126
+passwords, and private keys:
127
+
128
+    disable-save-passwords
129
+    forget-passwords
130
+    save-passwords
131
+
132
+
133
+=======
134
+QUOTING
135
+=======
136
+
137
+ * In a configuration file, the rest of the line is parsed into
138
+separate arguments  and then 'echo' and the arguments are passed, each
139
+separated by a single space, through the management interface. For
140
+example:
141
+
142
+    echo     argument1 argument2
143
+    echo    "     argument1      argument2"
144
+
145
+will be sent through the management interface as
146
+
147
+    >ECHO:timestamp,argument1 argument2
148
+    >ECHO:timestamp,     argument1      argument2
149
+
150
+ * In a command line option, the single argument following "--echo" is
151
+parsed similarly, so
152
+
153
+    --echo   argument1     argument2
154
+    --echo   "    argument1     argument2"
155
+
156
+will be sent through the management interface as
157
+
158
+    >ECHO:timestamp,argument1 argument2
159
+    >ECHO:timestamp,     argument1      argument2
160
+
161
+ * In a "push" option in a server configuration file, the single
162
+option following "push" is parsed similarly, so
163
+
164
+    push "echo argument1 argument2 argument3   argument4"
165
+    push "echo '    argument1 argument2 argument3   argument4'"
166
+
167
+will be sent through the management interface as
168
+
169
+    >ECHO:timestamp,argument1 argument2 argument3 argument4
170
+    >ECHO:timestamp,     argument1 argument2 argument3   argument4
171
+
172
+
173
+================
174
+COMMMAND DETAILS
175
+================
176
+
177
+
178
+COMMAND -- disable-save-passwords
179
+---------------------------------
180
+
181
+Syntax: disable-save-passwords
182
+
183
+The GUI is instructed to not allow the user to save passwords or
184
+private keys for the configuration. The user is still allowed to save
185
+usernames. Any passwords or private keys that have been saved will be
186
+forgotten.
187
+
188
+This command will be effective at startup only if present in the
189
+configuration file or as a command line option. If pushed from the
190
+server, saving passwords will be disabled in password prompts only
191
+after the initial prompt has been shown to the user.
192
+
193
+    Android: ??????
194
+
195
+    Tunnelblick: Planned. This command will disable saving of
196
+passwords or private keys and forget any saved usernames, passwords,
197
+or private keys regardless of the normal (non-forced) global or
198
+per-configuration settings. A computer administrator can "force" this
199
+setting, overriding this command.
200
+
201
+    Windows OpenVPN GUI: Planned. This command will disable saving of
202
+passwords or private keys and forget any saved usernames, passwords,
203
+or private keys regardless of any global settings.
204
+
205
+
206
+COMMAND -- forget-passwords
207
+---------------------------
208
+
209
+Syntax: forget-passwords
210
+
211
+The GUI is instructed to forget any usernames, passwords, and private
212
+keys it has saved for the configuration. Useful when pushed from the
213
+server so that it is processed after authentication.
214
+
215
+    Android: ??????
216
+
217
+    Tunnelblick: Planned.
218
+
219
+    Windows OpenVPN GUI: supported since release 2.4.1 (GUI version 11.5.0)
220
+
221
+
222
+COMMAND -- msg
223
+--------------
224
+
225
+Syntax: msg text
226
+
227
+The text is appended to any previous text from "msg" or "msg-n"
228
+commands, and a newline is appended after that.
229
+
230
+A trailing newline will be removed from the completed message before
231
+it is displayed to the user.
232
+
233
+The text may include any UTF-8 character except a comma (","), CR
234
+(0x0D), LF (0x0A), or NUL (0x00).
235
+
236
+The text may not contain percent ("%") except in "percent encoding"
237
+sequences. To display a percent sign, use %25.
238
+
239
+The text may not contain commas (",") because of constraints imposed
240
+by OpenVPN. Commas should be encoded using "percent encoding" (URL
241
+encoding): a '%' character followed by two hexadecimal digits, the
242
+high- and then low-nibble of the ASCII code for the character to be
243
+shown. Examples: a comma is encoded as %2C or %2c; a percent sign is
244
+encoded as %25.
245
+
246
+Text containing comment characters # and ; must be enclosed in quotes to
247
+survive after option parsing by openvpn.
248
+
249
+The insertion of line endings (CR, LF) in the text is discouraged
250
+because it is OS dependent. Instead, use the "msg" command, which
251
+appends a line ending appropriate for the OS on which the GUI is
252
+running.
253
+
254
+    Android: Planned.
255
+
256
+    Tunnelblick: Planned.
257
+
258
+    Windows OpenVPN GUI: supported since release v2.4.11 / v2.5.1
259
+			 (GUI version v11.22.0)
260
+
261
+COMMAND -- msg-n
262
+----------------
263
+
264
+Syntax: msg-n text
265
+
266
+The text is appended to any previous text from "msg"" or "msg-n""
267
+commands. (Like "msg" except that no newline is appended.)
268
+
269
+See "COMMAND -- msg" for details about "text".
270
+
271
+    Android: Planned.
272
+
273
+    Tunnelblick: Planned.
274
+
275
+    Windows OpenVPN GUI: supported since release v2.4.11 / v2.5.1
276
+			 (GUI version v11.22.0)
277
+
278
+COMMAND -- msg-notify
279
+---------------------
280
+
281
+Syntax: msg-notify title
282
+
283
+The text from previous "msg" and/or "msg-n" commands is displayed to
284
+the user as a notification with title "title" and the previous text is
285
+forgotten.
286
+
287
+    Android: Planned.
288
+
289
+    Tunnelblick: Planned.
290
+
291
+    Windows OpenVPN GUI: supported since release v2.4.11 / v2.5.1
292
+			 (GUI version v11.22.0)
293
+
294
+Note: The max length that will correctly display as a notification
295
+message is OS dependent.
296
+
297
+
298
+COMMAND -- msg-window title
299
+---------------------------
300
+
301
+Syntax: msg-window title
302
+
303
+The text from previous "msg" and/or "msg-n" commands is displayed to
304
+the user in a non-modal popup window with title "title" and the
305
+previous text is forgotten.  How the title is displayed exactly is left
306
+to the implementation. Could be set as the window title or as a
307
+differently formatted text as the heading of the message, for example.
308
+
309
+    Android: Planned.
310
+
311
+    Tunnelblick: Planned.
312
+
313
+    Windows OpenVPN GUI: supported since release v2.4.11 / v2.5.1
314
+			 (GUI version v11.22.0)
315
+
316
+
317
+COMMAND -- save-passwords
318
+-------------------------
319
+
320
+Syntax: save-passwords
321
+
322
+The GUI is instructed to allow the user to save usernames, passwords
323
+and private keys for the configuration.
324
+
325
+This command will be effective at startup only if present in the
326
+configuration file or as a command line option. If pushed from the
327
+server, saving passwords will be allowed in password prompts only
328
+after the initial prompt has been shown to the user.
329
+
330
+This command typically has the effect of presenting the password
331
+dialogs to the user with a "save password" checkbox checked. The user
332
+may still uncheck it during the dialog.
333
+
334
+    Android: ??????
335
+
336
+    Tunnelblick: Planned. Tunnelblick ignores this command. Usernames,
337
+passwords, and private keys may be saved by default, and this command
338
+will not override the separate Tunnelblick global or per-configuration
339
+settings used to disable saving them.
340
+
341
+    Windows OpenVPN GUI: Supported since release 2.4.1 (GUI version 11.5.0)
342
+
343
+
344
+COMMAND -- setenv
345
+-----------------
346
+
347
+Syntax: setenv name value
348
+
349
+Sets an environment variable that will be available to the scripts run
350
+by the GUI.
351
+
352
+This will set environment variable "OPENVPN_name" to value "value" for
353
+the scripts run by the GUI. "name" is changed to "OPENVPN_name" to
354
+prevent overwriting sensitive variables such as PATH. Variables are
355
+set in the order received, with later values replacing earlier ones
356
+for the same "name".
357
+
358
+Names may include only alphanumeric characters and underscores. A
359
+"setenv" command with an invalid name will be ignored.
360
+
361
+    Android: ??????
362
+
363
+    Tunnelblick: Planned.
364
+
365
+    Windows OpenVPN GUI: supported since release v2.4.7 (GUI version v11.12.0)
366
+The variables set by "setenv" are merged with those for the process
367
+environment.  In case of duplicate names the one in the setenv list is
368
+chosen.
... ...
@@ -137,6 +137,16 @@ history while simultaneously activating real-time updates:
137 137
 The size of the echo buffer is currently hardcoded to 100
138 138
 messages.
139 139
 
140
+
141
+Generally speaking, the OpenVPN Core does not understand echo
142
+messages at all (so a cooperating GUI and Server can use this
143
+mechanism for arbitrary information transport).
144
+
145
+This said, a few echo commands have been agreed upon between the
146
+community maintained OpenVPN Windows GUI and Tunnelblick for MacOS,
147
+and documentation of these can be found in doc/gui-notes.txt.
148
+
149
+
140 150
 COMMAND -- exit, quit
141 151
 ---------------------
142 152
 
... ...
@@ -5306,13 +5306,14 @@ add_option(struct options *options,
5306 5306
         }
5307 5307
         if (good)
5308 5308
         {
5309
-#if 0
5310
-            /* removed for now since ECHO can potentially include
5311
-             * security-sensitive strings */
5312
-            msg(M_INFO, "%s:%s",
5313
-                pull_mode ? "ECHO-PULL" : "ECHO",
5314
-                BSTR(&string));
5315
-#endif
5309
+            /* only message-related ECHO are logged, since other ECHOs
5310
+             * can potentially include security-sensitive strings */
5311
+            if (strncmp(p[1], "msg", 3) == 0)
5312
+            {
5313
+                msg(M_INFO, "%s:%s",
5314
+                    pull_mode ? "ECHO-PULL" : "ECHO",
5315
+                    BSTR(&string));
5316
+            }
5316 5317
 #ifdef ENABLE_MANAGEMENT
5317 5318
             if (management)
5318 5319
             {