I am a big fan of OpenVPN and I use OpenVPN for both work and personal purposes. Using VPN is an integral part for me as I rely on it to manage my VPC at work and also to manage my privacy online. I use OpenVPN network manager to connect with the VPN in my Ubuntu machine. Unfortunately OpenVPN network manager does not seem to be happy if the certificates and key files are inline in the configuration file. So All those certificates needs to be separated into individual files and linked to the config file. I got fed up with creating these configuration files for all the users. So as any decent hacker would do, I decided to write a bash script to split or merge back a openVPN config file.
The script has a very minimum dependency and all the commands used are available in most of the Linux distributions.
- sed (Stream editor)
The following script can be used to merge or split a OpenVPN configuration file.
To specify the script that a split operation to be performed, -p flag is set. Source is a required argument through which the path to the OpenVPN configuration file is specified.
$ ./ovpn_config_merge_split.sh -p --source [path_to_config] --destination [destination_path]
To merge the config file back to one file with all the certificates and keys inline. You can pass -m flag to the script which will set the script to merge mode. The script can automatically try to detect the certificates and keys from the config file if the path are specified in the OpenVPN config file else the certificates and keys can be passed as argument to the script.
$ ./ovpn_config_merge_split.sh -m=auto --source [path_to_config] --destination [destination_path]
or to manually specify all the certs and keys
$ ./ovpn_config_merge_split.sh -m --source [path_to_config] --destination [destination_path] --ca [filepath] --cert [filepath] --key [filepath] --tls-auth [filepath]