OpenVPN Protocol
First of all, I will explain what we are trying to develop. Basically, our idea is to make OpenVPN works at kernel level, not at user level, and use the linux cryptoapi instead of openssl. We will not use de /dev/net/tun (that is user level space) and will create some new interfaces (something like openvpn0, openvpn1, etc.).
We have being studying the OpenVPN source code but we get a little overwhelmed. It is not easy to understand all the sources. We need some help, especially to understand correctly the OpenVPN protocol. How the encrypted packet is formed? How the packet is desencrypted? If you add some extra data to the packet? etc, etc...
In a few words, we need the OpenVPN protocol.
We use this simple static-home.conf (Using Blowfish and SHA1 by default)
#################################################
# Sample OpenVPN configuration file for
# home using a pre-shared static key. # # '#' or ';' may be used to delimit comments.
dev tun
ifconfig 10.1.0.2 10.1.0.1
up ./client.up
secret static.key
port 5000
verb 3
#################################################
These are our doubts:
--------------------
1- In the web page (http://openvpn.net/security.html) it says:
"In static key mode, a pre-shared key is generated and shared between both OpenVPN peers before the tunnel is started. This static key contains 4 independent keys: HMAC send, HMAC receive, encrypt, and decrypt. By default in static key mode, both hosts will use the same HMAC key and the same encrypt/ decrypt key. However, using the direction parameter to --secret, it is possible to use all 4 keys independently."
We genereted this static key:
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----4fb804ced58655f5e0ab11d455477fec4131d3ad3995d7d194ebc2d9bed3962862f548089a5c485f3c0ef64aff5860a0ad9c54ee9ec9e795e08b7b5118e5a8daf2bc492fd3dd2f6cb94b3b0d62e324dbbcd662ef2127466ca08147ddb0326eb41f7c46dfa4c2dd766fb2e62eb76ef44c75247095c87f1178942fb9e7a2917d3175ac5d60ef8d25dcc72b4dc81df900f256fad6dc6c2341590db6fe126ce20fec8be8a609b25fd8a45ec47045ef03971a7858b4ff929a9822d636f4a3a1da343a2c424958e4ef8526776c18f34aaf82b077f153221cb453467beb0d154b0f0ca6f68e53bfb5f7f1d94496340c0010f319d5e0619ee4b50fc0f129e1bbf76d3e8a
-----END OpenVPN Static key V1-----
Question: This is a 256 bytes key, which part of this key is used for HMAC and which for encryption/decryption? (We do not use de --secret option)
2- We test OpenVPN like this:
First we send a paquet without OpenVPN running. This is the structure of the packet we get with Ethereal. We use the following command:
#echo "hola" | nc example.com 80
Unencrypted Packet
------------------
Total length=57 bytes
+-----------------------+ | IP HEADER | IP Header length = 20 bytes |-----------------------| | TCP HEADER | TCP Header length = 32 bytes |-----------------------| | DATA | DATA length = 5 bytes | | | hola. | +-----------------------+
Then we start OpenVPN with this command:
#openvpn --config static-home.conf --cipher none
We run:
#echo "hola" | nc 10.1.0.1 80
And we get this
OpenVPN Unencrypted Packet
--------------------------
Total length=113 bytes
+-----------------------+ | IP HEADER | IP Header length = 20 bytes |-----------------------| | UDP HEADER | UDP Header length = 8 bytes |-----------------------| | Original IP HEADER | Orig. IP Header length = 20 bytes |-----------------------| | Original TCP HEADER | Orig. TCP Header length = 32 bytes |-----------------------| | HMAC | HMAC length = 20 bytes |-----------------------| | IV | IV length = ????????? |-----------------------| | Sequence number | Sequence numbre length = 8 bytes |-----------------------| | DATA | DATA length = 5 bytes | hola. | +-----------------------+
(http://openvpn.net/security.html)
"The plaintext of the encrypted envelope is formatted as follows:
64 bit sequence number
payload data, i.e. IP packet or Ethernet frame"
Question: What's the meaning of the sequence number field before the DATA? What contains?
Question: What length does the IV have?
Question: Are correct the lengths we put?
Question: Is correct the packet structure?
Something must be wrong because if you add all the lengths (20 + 8 + 20 + 32 + 20 + 8 + 5) you will get 113 (total packet length) but you did not add the IV length.
And finally we restart OpenVPN with this command:
#openvpn --config static-home.conf
We run:
#echo "hola" | nc 10.1.0.1 80
And we get this
OpenVPN Encrypted Packet
--------------------------
Total length=128 bytes
+-----------------------+ | IP HEADER | IP Header length = 20 bytes |-----------------------| | UDP HEADER | UDP Header length = 8 bytes |-----------------------| | Original IP HEADER | Orig. IP Header length = 20 bytes |-----------------------| | Original TCP HEADER | Orig. TCP Header length = 32 bytes |-----------------------| | HMAC | HMAC length = 20 bytes |-----------------------| | IV | IV length = ????????? |-----------------------| | Sequence number | Sequence numbre length = 8 bytes |-----------------------| | DATA | DATA length = 5 bytes | blabla | |-----------------------| | Rest | Rest = 15??????? (Block cipher, Blowfish) +-----------------------+
(http://openvpn.net/security.html)
"The plaintext of the encrypted envelope is formatted as follows:
64 bit sequence number
payload data, i.e. IP packet or Ethernet frame
The HMAC and explicit IV are outside of the encrypted envelope."
We supposed that the difference between the encrypted and desencryted packet lenght (15 bytes) is because we are using a block cipher (Blowfish - CBC).
Question: Is this correct?
Question: The length of the sequence number plus the length of the payload must be an even multiple of block size?
We will apreciatte a lot your collaboration.
Gervasio Bernal, from Mendoza - Argentina
Pedro Deis, from Mendoza - Argentina
Quoted 5 lines · Gervasio Bernal
First of all, I will explain what we are trying to develop. Basically, our idea is to make OpenVPN works at kernel level, not at user level, and use the linux cryptoapi instead of openssl. We will not use de
/dev/net/tun(that is user level space) and will create some new interfaces (something like openvpn0, openvpn1, etc.).
Obviously you mean to implement the actual traffic protection, encapsulation, etc ... keeping the session mgmt and key exchange at user level ('ala IPSec).
FYI: they are working on this project for their college thesis under my
direction
Quoted 5 lines
...
Gervasio Bernal, from Mendoza - Argentina
Pedro Deis, from Mendoza - Argentina
Regards ...
Signature · 5 lines
--Juanjo OpenVPN udp6/tcp6 support (including MH for ipv4/ipv6) http://www.irrigacion.gov.ar/juanjo/openvpn/ # Juan Jose Ciarlante (JuanJo PGP) jjo ;at; mendoza.gov.ar # # Key fingerprint = 76 60 A5 76 FD D2 53 E3 50 C7 90 20 22 8C F1 2D #
Gervasio Bernal <[email protected]...> writes:
| First of all, I will explain what we are trying to develop. Basically, our idea | is to make OpenVPN works at kernel level, not at user level, and use the linux | cryptoapi instead of openssl.
Just a question.
Why do you want to do this? Performance or something else?
To me running in userspace is one of the really good things about OpenVPN.
Signature · 1 line
Lgb
Quoted 4 lines · Lars Gullik Bjønnes <larsbj <at> gullik.net> writes:
Gervasio Bernal <gervasiobernal <at> speedy.com.ar> writes:
| First of all, I will explain what we are trying to develop. Basically, our
idea
Quoted 1 line
| is to make OpenVPN works at kernel level, not at user level, and use the
linux
Quoted 9 lines
| cryptoapi instead of openssl.
Just a question.
Why do you want to do this? Performance or something else?
To me running in userspace is one of the really good things about OpenVPN.
You are right!, running in userspace is a great thing because it facilitates the portability, but you lose performance. Obviously, if we run it at kernel level we will lose that portability, but we will win performance.
Gervasio Bernal from Mendoza - Argentina
Pedro Deis from Mendoza - Argentina
Quoted 15 lines · Gervasio Bernal
Quoted 4 lines · Lars Gullik Bjønnes <larsbj <at> gullik.net> writes:
Gervasio Bernal <gervasiobernal <at> speedy.com.ar> writes:
| First of all, I will explain what we are trying to develop. Basically, our
idea
Quoted 1 line
| is to make OpenVPN works at kernel level, not at user level, and use the
linux
Quoted 6 lines
| cryptoapi instead of openssl.
Just a question.
Why do you want to do this? Performance or something else?
Quoted 7 lines
Quoted 3 lines
To me running in userspace is one of the really good things about OpenVPN.
You are right!, running in userspace is a great thing because it facilitates the portability, but you lose performance. Obviously, if we run it at kernel level we will lose that portability, but we will win performance.
You also lose the security of running the OpenVPN process outside the kernel as user/group nobody and chrooted to a sandbox.
If someone finds a remote code injection vulnerability, you are much worse off than you would be if you were running as an unprivileged process, chrooted to a sandbox, because now every remote compromise is a full root compromise.
There are also stability issues -- what if there is a crash or assertion failure? Running in kernel space, you will bring down the entire machine. When alpha & beta testing new features, it's important to be able to convince users to test the new code, to help stabilize it. People are going to be less likely to test code that might crash their whole machine as opposed to code which will only bring down a single process.
As far as performance is concerned, you will gain the time it normally takes to switch between user and kernel space. But this time may be small in relation to the much higher cost of crypto operations.
The big question in my mind is whether this possibly small increase in performance will justify the loss of portability, and some level of stability and security.
James
Quoted 3 lines · James Yonan
The big question in my mind is whether this possibly small increase in performance will justify the loss of portability, and some level of stability and security.
Further, I'd think one who wanted to engage in such a tradeoff could use something such as Kernel Mode Linux (which allows one to execute typically user-level programs in kernelspace).
Quoted 6 lines
The big question in my mind is whether this possibly small increase in performance will justify the loss of portability, and some level of stability and security.
James
Agreed.
Is performance such a big issue anyway ? At least for clients, Open VPN's current user-level design is not a throughput bottleneck. And I'm not sure it's all that bad for a gateway either.
What are you going to do with this new design that you can't do today ?
$.02
Mark Beyer