This tool allows for the temporary creation of a VPN server. You can create it, use it for however long you need, and then promptly destroy it.
ShardVPN has only been tested on macOS, and may or may not work as expected with other operating systems. It is still under development, and may change drastically over time.
ShardVPN is named for the Shards in Brandon Sanderson's series The Stormlight Archive.
Ten heartbeats.
One.
That was how long it took to summon a Shardblade. If Dalinar's heart was racing, the time was shorter. If he was relaxed, it took longer. Two.
- The Way of Kings by Brandon Sanderson, p. 202.
Before you are able to use ShardVPN, you will need to have the following required dependencies.
- A copy of this repository on your local machine
- An AWS account, with the proper credentials (see Setting up AWS Credentials)
- Terraform installed on your local machine (see Installing Terraform)
- An RSA key pair stored on your local machine at
~/.ssh/terraform_rsa
(see Setting up the Key Pair)
ShardVPN uses Terraform to create, set up, and tear down the necessary AWS resources on which the VPN runs. Terraform can only operate with the resources on your account that you grant it access to. At this time, the following permissions are required:
- AmazonS3FullAccess
- AmazonEC2FullAccess
- IAMFullAccess
- CloudWatchLogsFullAccess
- AmazonEC2ContainerServiceFullAccess
In the end, your local AWS credentials file must grant ShardVPN the above permissions. I recommend setting up these permissions in the following manner:
- Go to the IAM service in your AWS account.
- Create a user. You may name it whatever you like.
- Create a group. You may name this whatever you like, but I recommend giving it an identifiable name, like 'shard_vpn'.
- Assign the user to the group.
- In the group, attach the permission policies listed above.
- In the user, go to the 'Security Credentials' page and create an access key.
- Open your local AWS credentials file at
~/.aws/credentials
. If you do not yet have this file, create it. You can learn more about this here. - Include the credentials you created under a profile for ShardVPN, like so:
Note: If you want to name the profile something else, you can - but you must change the
[shard_vpn] aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
aws_credentials_profile
variable insettings.tfvars
, in the main repository folder.
On macOS, I find using Homebrew to be the easiest way to install Terraform:
brew install terraform
Otherwise, see https://www.terraform.io/ for installation instructions.
At one point, Terraform needs to SSH into an EC2 instance in order to upload and run a script. It does this using an
RSA key. The key pair must be stored on your local system at ~/.ssh/terraform_rsa
. If you need instructions for
generating this key, I have always found
this link
to be helpful.
Once you have all of the dependencies set up, you can run ShardVPN as follows:
- Navigate to the main ShardVPN folder.
- If you are running ShardVPN for the first time, run
initialize_terraform.sh
. - Run
build_vpn_from_scratch.sh
. - Once the script has finished running, go to the S3 service in your AWS account.
- In the 'shard-vpn-keys' bucket, you will see a number of files. Once your VPN server has initialized, a file with
the
name
shard-vpn-client.ovpn
will appear. This takes ~3 minutes. - Download the
shard-vpn-client.ovpn
file. - Use the
shard-vpn-client.ovpn
file with your favourite OpenVPN-compatible VPN software to establish a connection with the server.- If you are using macOS, I recommend Tunnelblick
- Presto! You should now be connected to your own private VPN server!
This script does the following:
- Runs
terraform apply
from the main folder, which create the S3 bucket where the certificates and keys are stored. - Runs
terraform apply
from the foldercertifier
, which creates an EC2 instance that generates all of the necessary keys and certificates required for a client - server VPN connection. - Runs
terraform destroy
from the foldercertifier
to tear down that EC2 server, as it is no longer needed. - Runs
terraform apply
from the folderdrive
, which creates the VPN server that your local machine will connect to.
If you wish, you may run these commands manually to achieve the same result. You can even SSH into the servers yourself using the RSA key you generated, if you want to have a look around.
In the root folder, there is a settings.tfvars
file where user settings may be defined.
At this point, the following settings may be defined:
aws_credentials_profile
- The profile in your aws credentials file that ShardVPN should use
traffic_protocol
- The protocol (udp or tcp) that you want ShardVPN to use. Default: udp
- UDP protocol will use port 1194, while TCP will use port 443
- If you started ShardVPN using the
build_vpn_from_scratch.sh
script, then rundestroy_drive.sh
from the main folder.
This script does the following:
- Runs
terraform destroy
from the main folder, to remove the 'shard-vpn-keys' bucket. - Runs
terraform destroy
from the folderdrive
, which tears down the VPN server.
If you wish, you may run these commands manually to achieve the same result.
Below are some of the security measures that ShardVPN is built with.
Separation of the Certificate Authority from the VPN server
The Certificate Authority (CA) is used to sign the server and client keys and certificates. This identifies them as trustworthy (i.e. the server knows the client is trustworthy, and vice versa). If an outside source were to gain access to the CA key, new keys could be generated to gain access to the VPN.
In order to mitigate this risk, once the keys and certificates are generated, the certifier server, which contains the CA key, is torn down. No further keys or certificates can be generated at this point beyond what has been placed in the S3 bucket.
Note that while there is a CA certificate placed in the S3 bucket, this is NOT the CA key. The CA certificate is only used to verify that other certificates were signed by the CA key, and cannot itself sign anything.
SHA256 Authentication of all Data
All data packets passing between the ShardVPN client and server are signed and authenticated using the SSL SHA-256 cryptographic hash algorithm.
SHA256 Encryption of all Control Channel Packets
A control channel packet is a packet of data sent between the client and server during the initial connection and later shutdown phases.
All control channel packets are encrypted using a SSL SHA-256 hash algorithm in order to mask their contents. This helps to prevent Man-in-the-Middle attacks, and also helps to keep these packets from being identified as being part of a VPN.
Encryption of all Data Channel Packets
A data channel packet is any packet of data sent over the VPN after a connection has been initialized.
All data channel packets are encrypted with one of the following ciphers, in order of descending preference:
- AES-256-GCM
- AES-128-GCM
- AES-256-CBC
If your OpenVPN software is using OpenVPN 2.4 or higher, AES-256-GCM will be the default. For older versions, AES-256-CBC will be used.
DNS options are not being set properly
You must ensure that the client configuration file has permission to manually set network settings on your local machine. This is because ShardVPN will set your machine to use Google's DNS servers.
To fix this in Tunnelblick, simply open Tunnelblick, go to "Advanced", and make sure that "Allow changes to manually-set network settings" is selected.