[stunnel-users] Public domain [PATCH] support environment variables in config file

Pierre Delaage delaage.pierre at free.fr
Thu Sep 29 17:52:52 CEST 2016

Hi Dmitry,
Shortly speaking : per user envvars are meaningless for WCE ..phones, as 
there is no way to switch from a user to another on those devices. At a 
time WCE was used on "handeld PC", where things could be slightly different.
So I recommend that, when your customized stunnel is loading conf file, 
and after you have "tokenized" the file to get env-vars name,
you mimic system calls with a stub that always return the same values 
RELATIVE to "." folder,
  ie where the stunnel executable has been installed on the phone.
This is the SOLE path that is reliable on a WCE phone.

Clearly, your envars will be "path to something" I guess : typically 
path to the cert file.
for this example your cert file on a phone will always be in "./mycert.crt".

For a win32 platform, there will be either a system wide stunnel running 
(so who will set up envvars to give to the stunnel env ? another system 
script ? with the risk that this script be modified by malicious code ?),
or a "one user at a time"- wide stunnel running : it will not be 
possible to get many processes running stunnel at the same time (just 
because, whatever envvar you use, all your processes may conflict when 
listening to "accept" sockets) unless ... you customize "accept" port 
through envvars ?
for me this is quite dangerous : customizing accept or -even more 
dangerous- connect ports through envars is really easy in user space for 
any malicious code (to redirect the trafic..).
So I still do not see clearly the interest for stunnel to decode envvars 
on the fly in conf file.

If you are looking for conf file automated generation on large sites, I 
already gave the trick in a 1-line sed command :

cat stunnel_template.conf | sed -r -e "s/^(.*)$/C\:\\Progra~2\\GnuWin32\\bin\\echo.EXE \1/e" > stunnel.conf

You may argue that this trick can lead to same security breach than 
explained above ...but ... NOT for system-wide stunnel for which 
-normally- the stunnel.conf file can NOT be modified.
Even for system-wide stunnel, any malicious sw that can tweak the system 
registry will be able to redirect stunnel trafic...
So this is why I do not encourage this patch.

Apart from that, technically speaking, you can go forward by creating a 
stub for getenv or expandstring w32 functions.

To setup a wce dev environment, see this page : 
The link for evc4 is now broken  : use this instead : 

I will refresh this web page later with more recent stunnel codebase.

Yours sincerely

Le 28/09/2016 20:26, Dmitry Bakshaev a écrit :
> Hello Pierre!
> 2016-09-10 14:00 GMT+04:00 Pierre Delaage <delaage.pierre at free.fr 
> <mailto:delaage.pierre at free.fr>>:
>     Hi Dmitry,
>     I reviewed our previous discussion on setting up stunnel by envvars...
>     On WCE, if you really want to have a unic code to manage envvars...
>     well ok, you have to write a stub for ExpandEnvironmentStrings,
>     that either performs %XX% replacement from predefined values OR
>     reads those values from a wce-specific "pseudo-env-txtfile".
> 1. 
> https://msdn.microsoft.com/en-us/library/ee490554(v=winembedded.60).aspx 
> <https://msdn.microsoft.com/en-us/library/ee490554%28v=winembedded.60%29.aspx>
> registry values under:
> [HKEY_LOCAL_MACHINE\init\BootVars]
> "name" = "value"
> it's like "global","system","shared".
> 2. https://msdn.microsoft.com/en-us/library/aa453706.aspx
> https://msdn.microsoft.com/en-us/library/aa516912.aspx
> it's way to emulate :
> getenv("APPDATA");
> getenv("USERNAME");
> ....
> something like (pseudocode):
> if( !strcmp(name, "APPDATA") ){
>  SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, ...);
>  ...get "value"...
> } else if(!strcmp(name, "USERNAME")){
>  GetUserNameEx(NameWindowsCeLocal ...)
>  ...get "value"...
> } else ...
> yes, syntax for "variables" must be %XX% - same as on windows.
> I think is not necessary to substitute the contents of the config file 
> ("pseudo-env-txtfile") to another config file (stunnel.conf).
>     As there is only ONE user in WCE, it is quite straightforward to
>     write such stub, that will be universal for any wce terminal:
>      the predefined values can be identical for any wce terminal.
> I am not familiar with WCE developlemt tools. I read about it:
> http://stackoverflow.com/questions/3463420/how-to-create-applications-for-windows-ce
> https://en.wikipedia.org/wiki/Windows_CE#Development_tools
> https://www.microsoft.com/en-us/download/details.aspx?id=17284
> https://msdn.microsoft.com/en-us/library/ms905342.aspx
> makew32.bat
> and completely puzzled by the number of versions, variants & etc.
> also I do not have the experience, tools and devices for building and 
> testing WCE apps.
> currently patch done for win32 (using 
> native ExpandEnvironmentStringsA) and *nix (ExpandEnvironmentStringsA 
> stub),
>  it's tested and worked.
>     NB : I already mentioned that (re)configuring stunnel through
>     envars is not safe, at least on Win32 platforms:
>     on those systems, env vars are stored in the registry (and
>     synchronised with specific system calls): every malicious sw that
>     can hack the registry can change env vars, it is of course very
>     easy in we use "user" env vars, not system env vars.
> "user" env vars values has no effect on "system" env vars.
> to change "system"/"other user" env vars admin/owner privileges required.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stunnel.org/pipermail/stunnel-users/attachments/20160929/4582356c/attachment.html>

More information about the stunnel-users mailing list