Welcome to the IPFire Wiki

This wiki is a community-maintained resource about everything there is to know about IPFire. Join us and help us improving it!

Looking for something?

Use the search and find answers to everything about IPFire. If you cannot find what you are looking for, join our community and talk to fellow IPFire users, developers and everybody else involved in the project.

IPFire Community

Differences in Revisions: ios_v2

»
add new image. rework steps to create unified file
#Configure iPad and iPhone for OpenVPN v2
Work-in-progress...
 
 
## Preparations
* Install the iOS app [OpenVPN Connect](https://apps.apple.com/app/openvpn-connect/id590379981)
* [Configure](https://wiki.ipfire.org/configuration/services/openvpn/config) and create an OpenVPN client for your iPhone or iPad device.
* Make sure you document the **PKCS12 File Password:**. It will be needed in the next few steps.
 
There are a few different ways to create a unified file for use on an iOS device (iPhone or iPad device). It can be done manually by cutting and pasting information from various files. Or it can be done with one if the bash scripts below.
 
To get started go to the menu **Service** > **OpenVPN**, scroll to the **Connection Status and Control** section and click on the **Download Client Package (zip)** icon.
 
![](./connection_status_control_v2.png "Download Client Package (zip)")
 
 
##Single unified file (manual method)
Manual method: maybe for a separate web page.
 
There are 5 sections to a unified ovpn file:
 
1. Locate the OpenVPN client conf file
* File is obtained from the **Download Client Package (zip)** above.
* Download and copy the `.ovpn` file to a new file (with different file name)
* Download and copy the `.ovpn` file to a new file
2. Add `key-direction bidirectional` to the end of this section
* added after the `.ovpn` file and before the next section starting at `<ca>`
* for example: the new file will be named: `myPhone.ovpn`
2. Add these lines to the end `myPhone.ovpn`:
```
key-direction bidirectional
<ca>
```
3. Locate the **Root Certificate** / CA Directive
* Open the OpenVPN webpage (**Service** > **OpenVPN**), scroll down to the **Certificate Authorities and -Keys**
* Download the **Root Certificate** by clicking on the floppy disk. Locate the `cacert.pem` file in the Downloads folder.
* Copy the contents to the `.ovpn` file
* Copy the contents of `cacert.pem` to end of the `myPhone.ovpn`
* Add these lines to the end `myPhone.ovpn`:
```
</ca>
<cert>
```
4. Locate the Cert ? / Cert Directive
* .
5. Locate TA key tls-auth
 
5. Locate the private key
* .
* Add these lines to the end `myPhone.ovpn`:
```
</key>
<tls-auth>
```
6. Locate TA key tls-auth
* The `ta.key` file is obtained from the **Download Client Package (zip)** above.
* Copy the contents of `ta.key` to end of the `myPhone.ovpn`
* Add this line to the end `myPhone.ovpn`:
```
</tls-auth>
```
 
Done creating the unified ovpn file!
 
![](./iphone_example.ovpn.png "Example iphone.ovpn")
![](./iphone_example.ovpn_v2.png "Example iphone.ovpn")
 
 
##Single unified file (scripted method)
Includes:
 
* ovpn info?
* CA directive
* Cert directive
* Key directive
* tls-auth?
 
###IPFire side code
Installed on IPFire box
 
Copy the following to a directory on the IPFire box.
 
filename = `openvpncmd.sh`
 
```bash
#!/bin/bash
set -e
#set -x
# OpenVPN script for IPCop/iOS, www.magnuswedberg.com
#
# Launch via:
# openvpncmd ovpn_file password(PKCS12 File Password)
#
# $1 param = YourNewOpenVPNfile.ovpn
# $2 param = PKCS12 Password
#
 
if (( $# < 2 )); then
# TODO: print usage
echo "Usage: openvpncmd ovpn_file password(PKCS12 File Password)"
exit 1
fi
 
cp "$1" tmp.ovpn
PKCS12_PW="$2" # PKCS12 File Password
 
# Convert windows file to linux file (drop Carriage Returns)
sed -i 's/\r$//g' tmp.ovpn
 
# get key & value from input ovpn file
while IFS=" " read -r key value remainder
do
#echo "key=$key" ; echo "value=$value" ; echo "remainder=$remainder" ; echo
case "$key" in
verify-x509-name )
RedIPaddr="$value"
;;
*pkcs12 )
pkcs12File="$value"
;;
esac
done < tmp.ovpn
 
# Comment out the "tls-auth ta.key" line and the "pkcs12 *.p12" line
sed -i -E -e 's/^tls-auth /#tls-auth /' -e 's/^pkcs12 /#pkcs12 /' tmp.ovpn
 
p12File=/var/ipfire/ovpn/certs/"$pkcs12File"
FILE="$p12File"
 
fn=$(basename "$FILE")
 
#bn="${fn%%.*}"
ovpnFile="${fn%%.*}".ovpn
 
cp tmp.ovpn $ovpnFile
rm tmp.ovpn
echo "key-direction bidirectional" >> $ovpnFile
 
 
echo "<ca>" >> $ovpnFile
cat /var/ipfire/ovpn/ca/cacert.pem | sed '/^-----BEGIN CERTIFICATE-----/,$!d' >> $ovpnFile
echo "</ca>" >> $ovpnFile
 
echo "<cert>" >> $ovpnFile
openssl pkcs12 -in $p12File -clcerts -nokeys -password pass:$PKCS12_PW | sed '/^-----BEGIN CERTIFICATE-----/,$!d' >> $ovpnFile
echo "</cert>" >> $ovpnFile
 
echo "<key>" >> $ovpnFile
openssl pkcs12 -nocerts -in $p12File -passin pass:$PKCS12_PW -passout pass:$PKCS12_PW | sed '/^-----BEGIN ENCRYPTED PRIVATE KEY-----/,$!d' >> $ovpnFile
echo "</key>" >> $ovpnFile
 
echo "<tls-auth>" >> $ovpnFile
cat /var/ipfire/ovpn/certs/ta.key | sed '/^-----BEGIN OpenVPN Static key V1-----/,$!d' >> $ovpnFile
echo "</tls-auth>" >> $ovpnFile
 
#echo "ovpn file = "
#cat $ovpnFile; echo
exit
```
 
 
 
 
###Client side code
installed on your desktop or laptop
 
 
 
##Separate file for iOS keychain
[OpenVPN - How do I use a client certificate and private key from the iOS Keychain?](https://openvpn.net/faq/how-do-i-use-a-client-certificate-and-private-key-from-the-ios-keychain/)
 
1st file includes:
 
* ovpn info?
* CA directive
 
2nd file includes:
 
* Cert directive
* Key directive
* tls-auth?
 
 
##Links
* [OpenVPN - What Is A VPN?](https://openvpn.net/what-is-a-vpn/)
* [OpenVPN - FAQ regarding OpenVPN Connect iOS](https://openvpn.net/vpn-server-resources/faq-regarding-openvpn-connect-ios/)
* [Forensic Analysis of OpenVPN on iOS](https://www.farleyforensics.com/2019/06/07/forensic-analysis-of-openvpn-on-ios/)