This is Part 2 in a series about integrating OpenSSL into an existing C++ project. Â In Part 1Â I presented a scenario that would necessitate such integration and I outlined the contours of the problem. Â
In essence, the goal of adding OpenSSL to a project is to add the “S” to your C++ based HTTP server — thus getting you an HTTPS server. Â I wanted to use this second post to give source code, but before that I need to step you through the install and build process of OpenSSL. Â In a future installment, I will present the C++ object which will be downloadable. Â
This seris is made possible because of the graciousness of Power Admin;Â the final project will be available on their web site. Â Included in that release are the scripts for Certificate use and generation via a Certificate Authority. Â
Step 1: Download and install OpenSSL.Â
Even as I write, I see that there is a new version of OpenSSL available: Jan 2009 (version 0.9.8.j).  When I started this series, it was based upon the earlier Sept 2008 version of OpenSSL (0.9.8.i).  The difference in versions is designated by the letters “i” and “j”.  I will update our code and scripts to account for any changes as needed.  The scripts I am going to give you will build and integrate OpenSSL into Visual C++. I have made it so that you simply run one command line script and your OpenSSL will be ready to use.
For myself, I installed OpenSSL here:
   C:\PowerAdmin\OpenSSL\openssl-0.9.8j>
The install came in a tar.gz file.  You will need an extraction utility that unpacks those kinds of files.  I used WinRAR (I like WinRAR because it shows up when I right click on a file in explorer).
Note that the unpack process gave me two errors:
1) Â C:\Users\Steve\Desktop\openssl-0.9.8j.tar.gz.tar: Cannot open ..\fips\aes\fips_aes_data (openssl-0.9.8j\test\fips_aes_data –> ..\fips\aes\fips_aes_data)2) C:\Users\Steve\Desktop\openssl-0.9.8j.tar.gz.tar: Symbolic link points to missing file
Â
Step 2. Install Perl
OpenSSL uses Perl to generate binaries. I use Larry Wall’s Perl — found at www.Perl.org. Â I have version 5.10.0 built for MSWin32-x86-multi-thread. Â The download page for Perl is here.
After you install, make sure that the Perl binary directories are in your environment path variable. I installed Perl in the root at c:\perl, and so I have these in my path:
   C:\Perl\site\bin;C:\Perl\bin;
Step 3: Download and run VC_BUILD.CMD
This step may be where I am the most helpful to you. I wrote my own VC_BUILD.CMD file for you to run. Â I have made it so that one command builds OpenSSL for Visual C++. Â With this script, you can build release or debug versions based upon command line options.
You must put VC_BUILD.CMD where you installed OpenSSL. In my case, it is here:Â Â Â Â
   C:\PowerAdmin\OpenSSL\openssl-0.9.8j\vc_build.cmd
You must edit that file and change two lines to point to your OpenSSL install and to your Visual C++ install. To do that, you need only modify the following:
set MY_PATH=C:/PowerAdmin/OpenSSL/openssl-0.9.8j
set VCVARS=”C:\Program Files\Microsoft Visual Studio 9.0\vc\bin\vcvars32.bat”
Once you have done that, go to a CMD prompt and traverse to the directory containing vc_build.cmd. Once there, simply run vc_build:
vc_build
That is all it takes to build the release version of OpenSSL (producing DLLs and LIBs for your use).Â
When OpenSSL is finished building, you can find the results in the Out32DLL directory. That directory is located here:
   C:\PowerAdmin\OpenSSL\openssl-0.9.8j\out32dll>
You can also build a debug version of OpenSSL by using the “-d” option:
vc_build -d
Running that will create the following debug directory:
   C:\PowerAdmin\OpenSSL\openssl-0.9.8j\out32dll.dbg>
Click on the image to go to Amazon and order a copy. Â This book was the basis for my work. Â It is not complete in all respects, but it is sufficient for helping you understand the OpenSSL command line and other aspects of the software that you now installed and built.
Pingback: Philosophy, Technology and Math » Blog Archive » Adding OpenSSL to an existing Visual C++ Socket Program in C++
You saved my life. Worked great for Windows XP SP2, using Strawberry Perl 5.10.0.6, openSSL-0.9.8j and Microsoft Visual Studio 9.0 Express Edition.
Thanks alot!
This makes me glad! I have an updated build script that fixes a problem in the scripts you have. Namely, I think that the DEBUG build is not really building DEBUG, or the RELEASE is not really building RELEASE (I forget which it was).
Anyway, I have updated scripts I may upload, but they are on my broken computer and I am repairing it. Let me know if you want the updated version and I will try and make the time to get it to you.
Oana provides more details here at codeproblemsandfixes.blogspot.com:
http://codeproblemsandfixes.blogspot.com/2009/10/build-openssl-on-windows-xp.html
A good tutorial, though I wish if you had completed it to the point “My goal is to release a free OpenSSL C++ class that developers can quickly and easily integrate into existing code…”
Below are the links that will help people understand further from where Steve left…
A detail helpful material by IBM : http://www.ibm.com/developerworks/linux/library/l-openssl/index.html
A C++ code example : https://thunked.org/programming/openssl-wrapper-class-t72.html