Skip to content

reverseame/Secure_Socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Secure Socket

Sockets implementing hybrid encryption using Crypto++. Developed and tested under Linux.

License: GPL v3

Requirements

Installation

Unix

Requirements

  1. Download Crypto++.
  2. Download Crypto++ PEM Pack (Documentation here).
  3. Move to Crypto++'s directory:
$ cd cryptopp_dir
  1. Extract (uncompress) Crypto++ PEM Pack:
$ 7z x cryptopp_pem.zip
  1. 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.

Secure_Socket

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.

Windows

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)

Crypto++ installation

  1. Download Crypto++.
  2. Download Cryptopp-PEM. I recommend cloning the repository rather than downloading the release since the repository itself is updated whereas the release is not.
  3. Unzip the contents of Cryptopp-PEM in the same folder as Crypto++'s headers and sources.
  4. Look for a file called cryptlib.vcxproj.
  5. Open it in Microsoft Visual Studio.
  6. In the Solution Explorer window you should see 4 projects: cryptdll, cryptest, cryptlib and dlltest. 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).
  7. Select the project you want to build (for example, cryptlib).
  8. Open the dropdown menu.
  9. Right click Header Files -> Add -> Existing Item and select pem.h and pem_common.h.
  10. Right click Source Files -> Add -> Existing Item and select pem_common.cpp, pem_read.cpp and .pem_write.cpp
  11. Manually add #include "pch.h" at the beginning of pem_common.cpp, pem_read.cpp and .pem_write.cpp (right over #include "cryptlib.h").
  12. Select the target you desire to build the library for : Win32 or *x64 and Debug, DLL-Import Debug, DLL-Import Release or Release.
  13. Right-click on the project you want to build (either cryptdll or cryptlib) and select build.32
  14. 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.

Including Crypto++ in your project.

After successfully building Crypto++ in your Windows environment, the time to use it has come.

  1. Open your project in Microsoft Visual Studio.
  2. Right-click on your project -> Properties.
  3. Open the C/C++ drop-down menu -> General.
    1. Include the Crypto++ path (directory of .cpp and .h files) in the Additional Include Directories field.
  4. Open the Linker drop-down menu -> Input.
    1. Include cryptlib.lib and Ws2_32.lib in the Additional Dependencies field.
  5. Open the Linker drop-down menu -> General.
  6. Include the path of the compiled Crypto++ and Cryptopp-PEM library (path of cryptlib.lib, usually something like ...\x64\Output\Release)

Cloning this project into Visual Studio

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:

  1. 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.
  2. You should be able to define the libraries, as specified in the previos section Including Crypto++ in your project.

Troubleshooting

  • 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 or LNK1120 when building your application, make sure you included the right library (absolute path) in the Additional 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' or error 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 every std::toupper() call to ::toupper() and every std::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 using localhost. Changing it to 127.0.0.1 worked.

Compilation (Unix)

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

Generate RSA keys (Unix)

$ 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

Useful links

License

Licensed under the GNU GPLv3 license.