Skip to contentSkip to conversation

psw in pem_passphrase_callback() static or not?

Openvpn-devel Mathias Sundman 2 participants 2 messages Aug 9, 2004

lore
Share & tools
lore
#0 lore raw

When i first looked at the pem_passphrase_callback() function in ssl.c, I though that the intention was to save the passphrase so the key could be reloaded after a ping-restart, because you use:

static char passbuf[256];

So, I was surprised when my GUI now asked me for the passphrase a second time (after a ping-restart).

A closer look at the function revealed that you do a CLEAR(passbuf) before returning.

So, I just wonder, was the intention to save the passphrase or not? If not, why do declare passbuf as static?

Also, is it safe todo
if (!strlen (passbuf)) when passbuf has not get been assigned any string?

Signature · 4 lines
_____________________________________________________________
Mathias Sundman                  (^)   ASCII Ribbon Campaign
NILINGS AB                        X    NO HTML/RTF in e-mail
Tel: +46-(0)8-666 32 28          / \   NO Word docs in e-mail
#1 lore raw
Quoted 11 lines · Mathias Sundman

When i first looked at the pem_passphrase_callback() function in ssl.c, I though that the intention was to save the passphrase so the key could be reloaded after a ping-restart, because you use:

static char passbuf[256];

So, I was surprised when my GUI now asked me for the passphrase a second time (after a ping-restart).

A closer look at the function revealed that you do a CLEAR(passbuf) before returning.

Yes, the intention is to only hold the password long enough to give it to OpenSSL, when it calls pem_password_callback.

But the function is written in such a way that by not doing the CLEAR(passbuf), the password will be cached across restarts. Also --persist-key might prevent OpenSSL from calling pem_password_callback again on restart.

It might be useful to change this behavior to cache by default, and then have an option to disable the caching. In general, OpenVPN tries not to cache sensitive data in virtual memory for longer than necessary.

Quoted 2 lines

So, I just wonder, was the intention to save the passphrase or not? If not, why do declare passbuf as static?

It's static because pem_password_callback is called twice. Once to get the password from stdin (called from options.c), and then once to return it to OpenSSL (called from inside OpenSSL).

Quoted 3 lines

Also, is it safe todo
if (!strlen (passbuf))
when passbuf has not get been assigned any string?

Yes, statics are guaranteed to be zeroed on program startup (unlike automatics).

James