- Creating certificates and keys for OpenVPN server with EasyRSA on MacOS
- Step 1: Resolve MacOS Dependencies
- XCode and Command Line Tools
- OpenSSL
- Step 2: Download EasyRSA
- Step 3: Configure EasyRSA
- Step 4: Generate Certificate Authority (CA)
- Step 5: Generate Server Certificate + Key + DH Parameters
- Step 6: Generate client credentials
- Understanding client config files
- Security reminder
- Next steps
- Router as OpenVPN server
- Running your own server
- Строим OpenVPN мост под Mac OSX
Creating certificates and keys for OpenVPN server with EasyRSA on MacOS
This guide covers how to create certificates and keys for OpenVPN server and clients using the EasyRSA tool on MacOS.
The instructions are very similar for most flavours of linux such as Ubuntu once the correct packages are installed (e.g. on Ubuntu: apt-get install openvpn easy-rsa ).
If privacy and security are of the utmost concern, generate all certificates and keys on a “clean” machine and verify the signatures of each download.
Step 1: Resolve MacOS Dependencies
This guide assumes that you’re running MacOS Sierra or later.
XCode and Command Line Tools
Ensure that you have installed the XCode Command Line Tools.
To check, the command xcode-select -p outputs a file path beginning with /Applications/Xcode.app/ if they are already installed.
If Command Line Tools is not installed, open the Terminal app and enter xcode-select —install to trigger the installation app.
Another way to trigger the installation app is to attempt to use a command line developer tool such as the GNU C compiler gcc (e.g. gcc —version ). If the tools are not installed, you will be greeted by a graphical MacOS installation prompt instead of the expected Terminal output from gcc. You don’t necessarily need the full XCode so you can click the “install” button for just the command line tools.
Work your way through the installer and follow Apple’s steps until you can start working with the necessary commands. The CLI commands will become available to you after you agree to all of Apple’s terms and conditions.
If you experience troubles with the next step, assuming that it is the result of some future change by Apple, it may be beneficial to install the full XCode in addition to the CLI tools. It’s available for free on the App Store, but take note that it’s a hefty multi-gigabyte download.
OpenSSL
EasyRSA requires a late-version of the open-source openssl library.
Apple bundles its own crypto libraries in MacOS but these are generally out of date. At the time of writing, the openssl command bundled with MacOS is not likely compatible with EasyRSA and will produce errors if you try to use it (note: the binary is at /usr/bin/openssl ).
A newer EasyRSA-compatible version of OpenSSL is easy to install with the brew package manager (https://brew.sh/). Installing via brew will not clobber or harm the Apple version that’s already on your system. If you need to install brew , go to the project’s website and follow the simple instructions on the landing page.
Assuming you have brew installed, open a Terminal and run the command:
Brew will download and install openssl to its default package install directory of /usr/local/Cellar .
The package will be installed in “keg only” mode: brew will not create a symlink for its openssl in /usr/local/bin or anywhere else in your $PATH. You will not have a conflicting openssl command, and Apple’s binary will remain intact.
To get EasyRSA to use the openssl binary installed by the brew package, you will need to know its path. Run brew’s package info command and examine the output:
In my example, I could see that openssl resolved to /usr/local/Cellar/openssl/1.0.2n . In your case, this may be a different path due to a more recent version being available in the future. Next, inspect this folder to locate the binary and determine the full path to it. In my example case, the full path to the binary was:
Note down the correct path to the openssl binary for your case. When configuring EasyRSA in the next step, you will need to specify this path in an EASYRSA_OPENSSL variable.
Step 2: Download EasyRSA
Go to https://github.com/OpenVPN/easy-rsa/releases and download the latest .tgz version for your Mac.
Save the file to a folder that you wish to work from (your certificates and keys will be generated here) and unpack it using the Archive utility (double click on it in Finder).
Note that the easy-rsa tools were written with traditional linux/unix-type environments in mind and therefore assume that all paths to the scripts have no spaces in them.
Going forward I will assume the path of your unpacked EasyRSA folder is:
’ character is a shortcut to your home folder that works in Terminal, i.e. on a Mac its a placeholder for /Users/your_username and on a typical linux environment /home/username .
Step 3: Configure EasyRSA
Assuming that the path of your unpacked EasyRSA folder is:
/vpn/easyrsa , open Terminal and navigate to the unpacked folder:
Copy the vars.example “starter” configuration file to vars :
Now customize the initial “starter” configuration file’s settings in vars to reflect your own.
Open it in a text editor and look for the following lines. Uncomment them (i.e. delete the preceding # character) and fill them in with your appropriate values. Specify something for each field below:
Look for the following field and uncomment it:
We’ll be using a 2048-bit key (the current default) for this example so the value will not be changed.
A larger key size is more secure but will result in longer connection + wait times over the VPN. At the time of writing in late 2017, its generally believed that a 2048-bit key is sufficient for most usage scenarios. A 4096-bit key is believed to provide additional privacy vs. more powerful state-sponsored actors.
EasyRSA by default uses the openssl binary found in the $PATH. Find the following line, uncomment it, and update the value with the path to the brew-installed openssl binary from Step 1. For example, in my case, the following line:
Step 4: Generate Certificate Authority (CA)
Navigate into your easyrsa/ folder. For example:
Initialize the PKI (public key infrastructure) with the easyrsa script. This will create a pki/ subfolder:
Create the CA (certificate authority):
You will be prompted to input a Common Name. Input the name server and hit ENTER.
The generated CA certificate can now be found at pki/ca.crt .
Step 5: Generate Server Certificate + Key + DH Parameters
Assuming you’re still inside your easyrsa/ folder from the previous step, generate your server certificate and key:
The generated server certificate can now be found at: pki/issued/server.crt
The generated server key can now be found at: pki/private/server.key
Now generate the Diffie-Hellman (DH) parameters for key exchange. This process can take several minutes depending on your system:
The generated DH parameters can be found at: pki/dh.pem .
You now have all of the files necessary to configure an OpenVPN server.
Step 6: Generate client credentials
You should generate a unique set of credentials for each and every client that will connect to your VPN. You can repeat this step for any client that you need to create credentials for.
All clients in your setup should have a unique name. Change exampleclient in the following to something descriptive that you will recognize and be able to associate with the user/client:
The generated client certificate: pki/issued/exampleclient.crt
The generated client key can be found at: pki/private/exampleclient.key
When distributing credentials to a client, they will need at least these 3 files:
- A client certificate (e.g. pki/issued/exampleclient.crt )
- The corresponding client key (e.g. pki/private/exampleclient.key )
- A copy of the CA certificate ( pki/ca.crt )
These client credentials can be loaded into a VPN app like Tunnelblick or Viscosity along with client configuration information that corresponds to your VPN server’s specific settings.
Understanding client config files
Client configuration information is usually provided in the form of an additional file: a plaintext config file with the .ovpn extension. Both Tunnelblick and Viscosity recognize the .ovpn extension and file format.
Later versions of openvpn support specifying all of the client configuration information, client certificate, client key, and CA certificate as demarcated blocks within the config file itself, so that clients only need to be provided with a single .ovpn file.
Security reminder
It is good to practice to try and keep all .ovpn , certificate, and key files as safe as possible with exposure to as few eyes/hands/hard-disks/clouds/etc as possible. Distribute them as securely as you can to your clients/users.
Next steps
Now you need a working openvpn server and a client that wishes to connect to your VPN!
I hope this guide was helpful to you. For all the server tutorials out there, as far as I know this is one of the few comprehensive guides out there for creating all required certificates and keys on MacOS.
Router as OpenVPN server
If your openvpn server is your router, you can now login to it’s admin control panel and input the server-related certificate + key + DH parameters that you created above.
Before you activate the VPN server, ensure that your router’s firmware is up-to-date and that you have set a long and reasonably secure password for the admin user.
Running your own server
If you are planning to setup your own openvpn server, there are numerous other resources available online to guide you through the server installation and configuration process for a variety of different operating systems.
You will find that you need all the keys and certificates that you created by following this guide.
These resources will generally include guidance for crafting .ovpn client configuration files to include specific settings that correspond to your server’s particular setup, so that clients can successfully connect.
Источник
Строим OpenVPN мост под Mac OSX
Однажды у меня появилась необходимость иметь доступ к локальной сети из удаленного места. Для выполнения данной задачи на iMac был поставлен OSX server в котором был настроен удаленный доступ VPN. Все работало вполне сносно кроме mDNS(Bonjour). Как оказалось данная реализация VPN не поддерживает мультикаст. А он был жизненно необходим из за наличия некоторых специальных приложений которые работают только в локальной сети.
После непродолжительного поиска нашлось несколько решений данной проблемы. Одно из них бесплатное предполагало установку программы «Network Beacon» и прописывания в ней руками путей к службам «Bonjour». Другое решение было платным и предполагало установку специального приложения «ShareTool» которое во первых может строить собственные SSH туннели и во вторых передавать по туннелю информацию о службах на стороне сервера.
Минусов у этого решения два. Первый это то что надо покупать лицензию на каждую машину. Ну и второй заключается в том что это решение все равно костыль. А мне хотелось все сделать как можно чище.
Решением оказалась постройка VPN моста на базе OpenVPN с виртуальным адаптером «tap».
Но как это сделать? В сети я нашел много разных инструкций по настройке подобной конфигурации но ни одного варианта постройки моста под OSX.
И тут я вспомнил как настраивал мост для расширения беспроводной сети и решил сделать все похожим образом.
Шаг первый — Настраиваем OpenVPN
Все последующие шаги будут требовать прав суперпользователя. По этому открываем терминал и сразу переходим в режим безграничных возможностей.
Для начала устанавливаем драйвер TunTap
Загрузить его можно по этой ссылке: tuntap_20111101.tar.gz
Распаковываем, запускаем инсталлятор. После окончания установки загружаем модули в ядро.
Далее устанавливаем и сам OpenVPN посредством MacPorts.
Для тех кто еще не знает — Easy-RSA больше не входит в состав пакета OpenVPN по этому качаем его отдельно по ссылке:
easy-rsa-release-2.x.zip
Для большего удобства копируем содержимое папки «openvpn2» в «/etc/openvpn».
Распаковываем в нее Easy-RSA 2.
Правим под себя vars и генерируем ключи. Правка «vars» заключается в исправлении информации о держателе сертификата и ключа а также изменении (при необходимости) длинны параметров Диффи — Хеллмана.
В заключении генерируем параметры Диффи — Хеллмана.
Правим образец из «/etc/openvpn/sample-config-files/» или создаем новый «server.conf».
Для примера мой вариант
Теперь переходим к следующему этапу создаем мост средствами самой MacOS.
Шаг второй — «Мостостроительство»
Запускаем Системные настройки и выбираем Сеть.
Жмем на шестеренку и выбираем «Управлять виртуальными интерфейсами».
Далее кликаем на плюс и выбираем «Новый мост…».
Здесь мы никогда не увидим наш интерфейс «tap» даже при запущенном сервере OpenVPN. Но как оказалось при всей «дружественности» MacOs дает возможность создать сетевой мост с одним интерфейсом. А это как раз то что нам необходимо. Выбираем адаптер которым мы подключены к сети и обзываем мост по своему усмотрению. Жмем «создать» и «готово».
Далее настраиваем подключение моста также как был настроен сетевой интерфейс и кликаем Применить.
Все, сеть настроена и окно можно закрывать. Оно больше не понадобится.
Теперь можно проверить в терминале наличие моста с одним членом. Запускаем команду «ifconfig» и убеждаемся в наличии моста bridge0 с одним членом в роли которого выступает интерфейс который мы выбрали при его создании.
Следующий этап представляет из себя создание скрипта который должен выполнить две функции. Во первых убедить ядро пропускать пакеты и во вторых добавить интерфейс «tap» в мост.
Шаг третий — Запуск
Создаем файл «/etc/openvpn/scripts/up.sh».
Сохраняем и делаем его исполняемым.
Путь к этому скрипту прописывается в конфигурации сервера и запускается после создания виртуального интерфейса.
Сервер запустился? Если да то убиваем его «Control+C». Если вылетел с ошибками то смотрим с какими и исправляем.
Теперь переходим к автозапуску сервера.
Создаем файл «/Library/LaunchDaemons/org.openvpn.bridge.plist» следующего содержания.
Сохраняем и запускаем сервер.
Все, с запуском сервера справились. Переходим к клиенту.
Шаг четвертый — Клиент
Я коротко опишу только вариант запуска клиента из под MacOS. Так как я подключаюсь к этому серверу с МакБука, и у меня не было необходимости ставить на него Xcode и MacPorts, я решил использовать решение типа «все включено» каким является «Tunnelblick».
Создаем папку конфигурации. Например на рабочем столе. Делать это проще на сервере. Далее будет понятно почему.
В папке создаем файл «config.ovpn» и прописываем конфигурацию.
Сохраняем и копируем в ту же папку ключи и сертификаты созданные в начале.
После копирования ключей и сертификатов необходимо поменять им владельца. Он должен совпадать с пользователем под которым мы строим конфигурацию. За одно покидаем рай суперпользователей.
Далее переименовываем папку с конфигурацией и ключами (имя папки будет названием конфигурации в «Tunnelblick») и добавляем расширение «.tblk»
После этого переносим конфигурацию на клиент с установленным «Tunnelblick» любым удобным способом. После чего открываем «Finder» находим расположение конфигурации и щелкаем по ней дважды. Она автоматически добавится к конфигурациям.
Запускаем «Tunnelblick», выбираем из списка свою конфигурацию и жмем кнопку «Соединится». И если все сделано правильно то через несколько секунд у нас уже есть полный доступ к удаленной локальной сети включая все мультикаст протоколы.
Источник