A Free OpenSSL Visual C++ Object: Part 2

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.

Download VC_BUILD.CMD here.

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>

Step 4. Fixing Problems
We all know one thing abut building software: What works on one machine rarely works on another.  If these steps fail you, then it is time to become familiar with the following textbook:
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.
This blog series essentially unpacks this book via the production of a reusable Visual C++ object — which I hope is of service to the Windows Development community.
Thanks again to Power Admin for making this series possible.
This entry was posted in OpenSSL, Programming and tagged , . Bookmark the permalink.

6 Responses to A Free OpenSSL Visual C++ Object: Part 2

  1. Pingback: Philosophy, Technology and Math » Blog Archive » Adding OpenSSL to an existing Visual C++ Socket Program in C++

  2. Oana says:

    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!

  3. srives says:

    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.

  4. srives says:

    Oana provides more details here at codeproblemsandfixes.blogspot.com:
    http://codeproblemsandfixes.blogspot.com/2009/10/build-openssl-on-windows-xp.html

  5. Ahmed says:

    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…”

  6. Ahmed says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>