Skip to contentSkip to conversation

options: Fix failing inline tls-auth/crypt with persist-key

PATCH In review David Sommerseth 3 participants 3 messages May 8, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 options: Fix failing inline tls-auth/crypt with persist-key

A configuration file using --persist-key and with inlined --tls-auth or --tls-crypt files was failing in check_file_access(). The file argument to check_file_access() contained the key file and not the file name.

This was because check_file_access_inline() which calls check_file_access() if the file is not inlined was told the file was not an inline file.

The reason the check_file_access_inline() was misled was due to a prior option_postprocess_mutate() call puts these key files into a connection block entry in option_postprocess_mutate_ce(). OpenVPN was modified a long while ago to always use connection blocks in the option structure for simplicity. So the "root" key files would be transferred into a connection entry in this method.

When --persist-key is used, option_postprocess_mutate_ce() will load the key file and "convert" the option into an inline option. But in commit cb2e9218f2bc73fa2 this logic had lost the "inline indicator". The result was that the connection entry had the key file content stored in the object but was "tagged" as a normal file (name) not an inline file.

---
 src/openvpn/options.c | 2 ++
 1 file changed, 2 insertions(+)
src/openvpn/options.c +2 -0
index 611652fd..a37106ce 100644
@@ -2936,6 +2936,7 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
             }
 
             ce->tls_auth_file = (char *)in.data;
+            ce->tls_auth_file_inline = true;
         }
 
         if (ce->tls_crypt_file && !ce->tls_crypt_file_inline)
@@ -2948,6 +2949,7 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
             }
 
             ce->tls_crypt_file = (char *)in.data;
+            ce->tls_crypt_file_inline = true;
         }
     }
 }
Signature · 1 line
2.26.0
Acked-by on v1 1/2
#1 lore raw

Hi,

Quoted 15 lines · David Sommerseth

A configuration file using --persist-key and with inlined --tls-auth or --tls-crypt files was failing in check_file_access(). The file argument to check_file_access() contained the key file and not the file name.

This was because check_file_access_inline() which calls check_file_access() if the file is not inlined was told the file was not an inline file.

The reason the check_file_access_inline() was misled was due to a prior option_postprocess_mutate() call puts these key files into a connection block entry in option_postprocess_mutate_ce(). OpenVPN was modified a long while ago to always use connection blocks in the option structure for simplicity. So the "root" key files would be transferred into a connection entry in this method.

Quoted 7 lines

When --persist-key is used, option_postprocess_mutate_ce() will load the key file and "convert" the option into an inline option. But in commit cb2e9218f2bc73fa2 this logic had lost the "inline indicator". The result was that the connection entry had the key file content stored in the object but was "tagged" as a normal file (name) not an inline file.

Thanks for fixing my bugs :-)
Unfortunately the code has changed a bit since the issue of v1 until v11...so these nasty errors sneaked in.

Signature · 1 line
Antonio Quartulli
#2 lore raw
In reply to David Sommerseth

Your patch has been applied to the master branch.

Have not done any testing, but the code change looks very reasonable and exactly like it would fix the bug :-)

commit e8e410fdc6fb91451d8119b129bac7be00ff81df

Author: David Sommerseth
Date:   Fri May 8 13:42:43 2020 +0200
     options: Fix failing inline tls-auth/crypt with persist-key

     Signed-off-by: David Sommerseth <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19858.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering