← Back to overview
April 4, 2011 · Belgian eID

Belgian eID and .NET - Part 1: Getting Started

Lately I’ve been looking into federated authentication and now I want to go further and see how the Belgian eID fits in this story. But the amount of documentation (especially for .NET) seems blurry, incomplete and outdated to say the least. That’s why I’m planning to write a few articles that will help you get on your way to use the eID in your .NET applications.

Before we get started I do need to mention the free eIDnative library (http://www.eidnative.be/) that could fit your needs. The problem I have with this library is that from time to time I experienced some nasty bugs like "An attempt was made to write to read only memory". And since the library hasn’t been updated in almost a year it doesn’t feel good to use this library in a production scenario.

This is the reason why I’m opting for the official way (using the official middleware and SDK). But this is where we bump into the first issue. What should you do to get the bits and bytes to create a working sample? If you have looked around you’ll see a few outdated blog posts, some forum posts, a few projects on code.google.com and also pages on eid.belgium.be (http://eid.belgium.be/nl/Achtergrondinfo/DeeIDtechnisch/). Finally I decided to go for code.google.com since you’ll get a complete overview of the existing solutions and seen the high activity this is where you’ll be able to find newest versions of the middleware and the SDK.

Note: You can save yourself a lot of work by just downloading the library but if you follow this guide you’ll be able to modify the middleware afterwards.

The bits and bytes

The online repository (http://code.google.com/p/eid-mw/source/browse/) allows you to browse branches and the current trunk (containing the unreleased version of the middleware). I’ll be discussing how to start working with version 3.5.5 of the middleware.

Note that this is an SVN repository and we’ll need to get the whole 3.5.5 branch locally. Before downloading the branch I created the following structure on my local disk:

What we’ll need to do next is install TortoiseSVN (http://tortoisesvn.net/downloads.html) and check out the 3.5.5 branch. This is very easy to do since TortoiseSVN is a simple shell extension. You just need to right click the eid-mw-3.5.5 folder you just created and click the *SVN Checkout… *button.

TortoiseSVN will need you to enter the URL of the repository you’re trying to check out. Since we’re only interested in the 3.5.5 branch we’ll be using the following URL: http://eid-mw.googlecode.com/svn/branches/355/

Press OK and the complete branch will be downloaded locally. Whenever a new version is made available you can use this technqiue to get the latest version. Follow the eID website (http://eid.belgium.be/nl/) or the Google Code page (http://eid-mw.googlecode.com/) to see if a new version is released.

Setting up the prerequisites

The rest of this article will explain how to get everything in the right place to build the required dll files. This will allow you to create a portable version of the middleware and also to make modifications where needed. In the next article I’ll show how you can remove the annoying dialog that asks the end user for permission.

Here is a list of all prerequisites I needed on my machine to get everything working:

In the files you checked out there’s also a file named beidmiddlewareeasybuild.pdf. This file explains which prerequisites you need, which scripts you need to adapt/run/… but that didn’t seem to work well for me. This is why I decided to do it my way. Besides that, the branch contains a solution that can help you to easily build all files… but it still took me a few hours to get all the pre-requisites in the right place and get everything to work correctly.

Setting up OpenSSL

Browse to the eid-mw-3.5.5\eid-mw_src\eidmw_Builds\ directory and open the BeidEasyBuildVS2008.sln solution file (if you’re working with VS2010 you’ll be prompted to convert the solution). You’ll probably see a few projects marked as unavailable but that’s not an issue for now. Right click the libCSWrapper project and choose build. After a few minutes you’ll see a bunch of errors:

These errors are mostly due to the prerequisites not being in the right place. First we should fix the OpenSSL problem. Install Win32OpenSSL-098r.exe and select the option to copy DLLs to the OpenSSL binaries directory of the OpenSSL installation. After the installation completes you should copy the whole OpenSSL directory to eid-mw-3.5.5\eid-mw_src\ThirdParty** and rename it to **openssl.0.9.8g

Browse to eid-mw-3.5.5\eid-mw_src\ThirdParty\openssl.0.9.8g\ and take the following actions:

The directory should look like this:

If you try to build you’ll see less errors, but we’re not done yet.

Setting up Xerces

Extract xerces-c-3.1.1.zip and copy the directory ‘xerces-c-3.1.1\src\xercesc’ to ‘eid-mw-3.5.5\eid-mw_src\ThirdParty\xercesc’. The applayer project needs a few header files so it’s time to configure the project for this. Right click the applayer project and click Properties. After that go to VC++ Directories and edit the Include Directories. Add both ‘eid-mw-3.5.5\eid-mw_src\ThirdParty\’ and *‘eid-mw-3.5.5\eid-mw_src\ThirdParty\xercesc’ *to the Include Directories:

Now go to the ‘eid-mw-3.5.5\eid-mw_src\ThirdParty\xercesc\util’ directoryand rename Xercesautoconfconfig.msvc.hpp to Xercesautoconfconfig.hpp

After this is done go to ‘xerces-c-3.1.1\projects\Win32\VC10\xerces-all’ (from the zip file you extracted) and open the solution xerces-all.sln. Build the whole solution, we’ll need some of the output for later. Don’t forget to change the configuration from Debug to Release.

Setting up swigwin

Extract swigwin-1.3.35.zip and copy the contents of ‘swigwin-1.3.35\swigwin-1.3.35\’ to ‘eid-mw-3.5.5\eid-mw_src\ThirdParty\swigwin\’. We’ll need this for later.

Building

Now the prerequisites have been set up it’s time to start building. I’m not planning to debug the application so I decided to change the build configuration from Debug to Release. After that right click the libCSWrapper project and choose Build. You’ll still see a few errors but that’s not a problem. Go to the ‘eid-mw-3.5.5\eid-mw_src\eidmw_Builds\Release’ directory copy the file to ‘eid-mw-3.5.5\eid-mw_src\eidmw_Binaries35\Release’. After copying the file rename it to beid35common.lib (in the Binaries32\Release’ directory).

To avoid confusion this is how the files should be set up:

Once this is done right click DlgsWin32 project and choose Build and do the same for the cardlayer project. Repeat the previous step for the new files; this is how everything should look like:

Go to the OpenSSL installation directory, copy the *.lib files from OpenSSL\lib\ to ‘eid-mw-3.5.5\eid-mw_src\eidmw_Binaries35\Release\’. After copying them you need to append 09_8g’ to the filename. As a result you should have the following files:

Previously you needed to build the xerces solution. Now it’s time to use the output of this project. Copy the file ‘xerces-c-3.1.1\Build\Win32\VC10\Release\xerces-c3.lib’ to ‘eid-mw-3.5.5\eid-mw_src\eidmw_Binaries35\Release\xerces-c3.lib’.

Now build the applayer project and also for this project you’ll need to copy the *.lib file and rename it. The contents of the Release directory should look like this:

The whole eID setup comes with a batch file ‘setpath.bat’ that allows you to customize directories containing the external dependencies but this batch file doesn’t seem to work. Open the project file ‘eid-mw-3.5.5\eid-mw_src\eidmw\eidlibCSWrapper\beid35libCSWrapperVS2008.vcxproj’ with a text editor (like notepad) and replace each instance of %BEIDDIRSWIG% with the full path to your swigwin directory. In my case this is X:\SVN\eid-mw-3.5.5\eid-mw_src\ThirdParty\swigwin (make sure there is no trailing backslash at the end).

Go back to Visual Studio and you should get a notice that a project was modified outside Visual Studio. Press the Reload button to… reload the project. Finally build the projects libCS35 and libCSWrapper by right clicking them and choosing Build. It could be that the common project still gives you 2 errors but that’s nothing.

If all goes well you should see 2 new files in ‘eid-mw-3.5.5\eid-mw_src\eidmw_Binaries35\Release’:

That’s it, you’ve done it! The eID middleware 3.5.5 has been built and can now be used in .NET applications. As I mentioned before the next article will show you how to make a small modification to the middleware.

A sample application

After building the projects you’ll have a bunch of files in the ‘eid-mw-3.5.5\eid-mw_src\eidmw_Binaries35\Release’ directory. You’ll need to use these files to create the sample application. I created a sample console application, referenced beid35libCS.dll and built the project.

Before you can actually start the project you’ll need to copy the following files to the output directory:

The code for the sample application is fairly simple:

try  
{
    BEID_ReaderSet readerSet = BEID_ReaderSet.instance();
    BEID_ReaderContext reader = readerSet.getReader();

    if (reader.isCardPresent())
    {
        BEID_EIDCard card = reader.getEIDCard();
        BEID_EId doc = card.getID();

        string firstname = doc.getFirstName();
        Console.WriteLine("Firstname: " + firstname);
        string lastname = doc.getSurname();
        Console.WriteLine("Lastname: " + lastname);
        string birthdate = doc.getDateOfBirth();
        Console.WriteLine("Birthdate: " + birthdate);
    }

    BEID_ReaderSet.releaseSDK();
}
catch (Exception ex)  
{
    Console.WriteLine(ex);
}

Console.Read();  

When you execute the application you should see the following (make sure you have an eID card plugged into the reader):

Sample application: SanLib.eID.Test.zip (931.99 kb)

Enjoy…

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus