Sockets implementing hybrid encryption using Crypto++. Developed and tested under Linux.
- Crypto++ 8.5 (version available as of July 21, 2021)
- Crypto++ PEM Pack 8.2.0 (version available as of July 21, 2021)
- Download Crypto++.
- Download Crypto++ PEM Pack (Documentation here).
- Move to Crypto++'s directory:
$ cd cryptopp_dir
- Extract (uncompress) Crypto++ PEM Pack:
$ 7z x cryptopp_pem.zip
- Install both the library and PEM Pack:
$ make -j 4
$ make test
$ sudo make install
- More intstructions about Crypto++'s installation can be found here.
- More instructions about Crypto++ PEM Pack's installation can be found here.
To use Secure_Socket copy the files included in the src folder of this repo in your project's source and header files directory. Once both .cpp and .hpp files are in their corresponding directories, in order to use the library simply #include "Secure_Socket.hpp"
in your files.
In order to use Secure_Socket in your Windows-based environment you must follow these steps:
(All these steps were done using Microsoft Visual Studio 2017 version 15.9.38)
- Download Crypto++.
- Download Cryptopp-PEM. I recommend cloning the repository rather than downloading the release since the repository itself is updated whereas the release is not.
- Unzip the contents of Cryptopp-PEM in the same folder as Crypto++'s headers and sources.
- Look for a file called
cryptlib.vcxproj
. - Open it in Microsoft Visual Studio.
- In the
Solution Explorer
window you should see 4 projects:cryptdll
,cryptest
,cryptlib
anddlltest
. Each one of the is detailed here. In short,cryptlib
allows you to build Crypto++ as a STATIC library and, on the other hand,cryptdll
builds it as a DYNAMIC library (linked). - Select the project you want to build (for example, cryptlib).
- Open the dropdown menu.
- Right click
Header Files
-> Add -> Existing Item and selectpem.h
andpem_common.h
. - Right click
Source Files
-> Add -> Existing Item and selectpem_common.cpp
,pem_read.cpp
and.pem_write.cpp
- Manually add
#include "pch.h"
at the beginning ofpem_common.cpp
,pem_read.cpp
and.pem_write.cpp
(right over#include "cryptlib.h")
. - Select the target you desire to build the library for : Win32 or *x64 and Debug, DLL-Import Debug, DLL-Import Release or Release.
- Right-click on the project you want to build (either
cryptdll
orcryptlib
) and select build.32 - The output files will be generated after the building process in the same path as the
cryptlib.vcxproj
file. Visual Studio will print the output path in its console anyways.
After successfully building Crypto++ in your Windows environment, the time to use it has come.
- Open your project in Microsoft Visual Studio.
- Right-click on your project -> Properties.
- Open the C/C++ drop-down menu -> General.
- Include the Crypto++ path (directory of .cpp and .h files) in the
Additional Include Directories
field.
- Include the Crypto++ path (directory of .cpp and .h files) in the
- Open the Linker drop-down menu -> Input.
- Include
cryptlib.lib
andWs2_32.lib
in theAdditional Dependencies
field.
- Include
- Open the Linker drop-down menu -> General.
- Include the path of the compiled Crypto++ and Cryptopp-PEM library (path of
cryptlib.lib
, usually something like ...\x64\Output\Release)
In order to include this repository as a project into Microsot Visual Studio you can clone it straight from Github. You will need the Github Extension for Microsoft Visual Studio. Intructions on how to install it can be found here. Once you cloned the repository, you must define the tasks so as to be able to build the project. To do so:
- If you need to define properties for your project, you may notice that the "Properties" option is missing. In fact, you may not even be able to switch to "Solution explorer", remaining stuck in the "Folder view" perspective. This happens because there are no solution-related files in the project. In order to fix this I created a new project (File -> New -> Project From Existing Code) specifying as source path the directory where the repo was cloned.
- You should be able to define the libraries, as specified in the previos section Including Crypto++ in your project.
- If you get an error like
error MSB8036: The Windows SDK version X.X was not found.
when trying to build the library, you can either change your project's properties (instructions here) or download the specified Windows SDK from here. - If you get one or more errors with codes like
LNK2019
,LNK2001
orLNK1120
when building your application, make sure you included the right library (absolute path) in theAdditional Dependencies
field of Linker -> Input menu. - If you get an error like
1>LINK : fatal error LNK1104: cannot open file 'C:\Users\User\Desktop\cryptopp-master\cryptopp-master\x64\Output\Release.obj'
, you must... more info here. - If you get an error like
error C2039: 'toupper': is not a member of 'std'
orerror C2039: 'isspace': is not a member of 'std'
or any other variant, it is because, despite what Microsoft says in the docs, it seems like cctype does not include std. The solution is to manually change everystd::toupper()
call to::toupper()
and everystd::isspace()
to::isspace()
, as stated here. This is not necessary anymore, as it is stated in the issue previously linked. - If you are using the library and get an error like
[!] Error binding socket! Error: 10049 ABORTING [!]
it is because, somehow, it cannot connect to the specified IP. It happened to us when usinglocalhost
. Changing it to127.0.0.1
worked.
Change paths accordingly
Client example:
$ g++ client.cpp Secure_Socket.cpp --std=c++11 -l cryptopp -o client.out
Server example:
$ g++ server.cpp Secure_Socket.cpp --std=c++11 -l cryptopp -o server.out
$ openssl genrsa -des3 -out private.pem 2048
$ openssl rsa -in private.pem -outform PEM -pubout -out public.pem
$ openssl rsa -in private.pem -out private_unencrypted.pem -outform PEM
- Cryptopp repo - https://github.com/weidai11/cryptopp
- Cryptopp-PEM repo - https://github.com/noloader/cryptopp-pem
- Cryptopp-PEM issue - noloader/cryptopp-pem#10
- Cryptopp main wiki - https://www.cryptopp.com/wiki/Main_Page
- Cryptopp Visual Studio wiki - https://www.cryptopp.com/wiki/Visual_Studio
- Cryptopp PEM Pack wiki - https://www.cryptopp.com/wiki/PEM_Pack
Licensed under the GNU GPLv3 license.