Getting the X509Certificate Serial Number out of the ClaimSet

The ClaimSet is quite interesting and extracting the Serial number from the certificate was something that wasn’t that straight forward using FindClaims which takes the ClaimType Enumerator. For this you can cast the claim set into a X509CertificateClaimSet and get the Serial Number

        public string GetCertificateSerialNumber()
            foreach (ClaimSet cs in OperationContext.Current.ServiceSecurityContext.AuthorizationContext.ClaimSets)
                if (cs is X509CertificateClaimSet)
                    return ((X509CertificateClaimSet)cs).SerialNumber;

            return null;

Hello Indigo – A Simple WCF Service


namespace Microsoft.Samples{    using System;    using System.ServiceModel;    using System.ServiceModel.Channels;    class SimpleService    {        static void Main(string[] args)        {            Binding binding = new NetTcpBinding();            string address = "net.tcp://localhost";            ServiceHost host = new ServiceHost(typeof(EchoService), new Uri(address));            host.AddServiceEndpoint(typeof(IEchoService), binding, "");            host.Open();            ChannelFactory cf = new ChannelFactory(binding, address);            IEchoService proxy = cf.CreateChannel();            Console.WriteLine(proxy.Echo("Hello Indigo."));            ((IChannel)proxy).Close();            host.Close();        }    }    [ServiceContract]    interface IEchoService    {        [OperationContract]        string Echo(string input);    }    class EchoService : IEchoService    {        public string Echo(string input)        {            return "Echo : " + input;        }    }}


SimpleService.cs (1.07 kb)

Script for setting up Certificates for WCF

I thought this script might be quite useful to set up certificates for testing with services hosted in IIS. This uses 3 tools present in the SDK folder.
1. makecert
2. certmgr
3. FindPrivateKey
You can find these in the WCF samples.

Note: Make sure you run this from the Windows SDK prompt and check the cert stores for the certifcates.


echo off
echo ************
echo Client cert setup starting
echo ************
set SERVER_NAME=localhost

echo ****************
echo Cleanup starting
echo ****************

echo ————————-
echo del client certs
echo ————————-
certmgr -del -r CurrentUser -s My -c -n %CLIENT_NAME%
certmgr -del -r CurrentUser -s TrustedPeople -c -n %SERVER_NAME%

echo ————————-
echo del service certs
echo ————————-
certmgr -del -r LocalMachine -s My -c -n %SERVER_NAME%
certmgr -del -r LocalMachine -s TrustedPeople -c -n %CLIENT_NAME%

echo *****************
echo Cleanup completed
echo *****************

echo ************
echo making client cert
echo ************
makecert.exe -sr CurrentUser -ss MY -a sha1 -n CN=%CLIENT_NAME% -sky exchange -pe
echo ************
echo copying client cert to server’s CurrentUserstore
echo ************
certmgr.exe -add -r CurrentUser -s My -c -n %CLIENT_NAME% -r LocalMachine -s TrustedPeople

echo ************
echo Server cert setup starting
echo ************
echo making server cert
echo ************
makecert.exe -sr LocalMachine -ss MY -a sha1 -n CN=%SERVER_NAME% -sky exchange -pe
echo ************
echo copying server cert to client’s CurrentUser store
echo ************
certmgr.exe -add -r LocalMachine -s My -c -n %SERVER_NAME% -r CurrentUser -s TrustedPeople

echo ************
echo setting privileges on server certificates
echo ************
for /F “delims=” %%i in (‘”FindPrivateKey.exe” My LocalMachine -n CN^=%SERVER_NAME% -a’) do set PRIVATE_KEY_FILE=%%i
(ver | findstr “5.1″) && set WP_ACCOUNT=%COMPUTERNAME%ASPNET
echo Y|cacls.exe “%PRIVATE_KEY_FILE%” /E /G “%WP_ACCOUNT%”:R

Taking down the wall

Well there are times when you just want to loose control and stop living. Well anti-blogging was something I was thinking of for a while.
Ok 2 sentences totally unrelalated. I know. But the point is i wanted to keep myself from writing anything. I wondered if people read this crap i put down. I say this cause I sometimes believe this is what they feel. But then again I should not call it crap cause then I rate myself low.

Anyway the point is that I realized I like putting down my flow of thoughts in words. And mostly this is just a maze of unrelated sentences trying to come to a point of a single centric notion. When you go around a cicle looking straight everything seem fine as long as you realize that its a circular path you are taking. Assume you were going in a spiral model. When do you realize that this is the path. You see the road you took a while ago in parallel and then again this and this in parallel to the previous one.
In short the spiral nature of my thoughts are only evident when I realize that I have already been through this space and time before and I have moved closer to my goal of realization.

The goal is not yet defined, I feel I will not know I am there until i come across every thought the emotion I had again and without difference and that the spiral model of my thoughts.

For someone who had just tried to comprehend the above. “I move so fast in my thoughts that I forget to realize that I leave my listeners in a parallel road waiting to follow.”
By the time i reach the point i go on and on till everyone is there.

Its a thought process that many have told me and I am trying to rectify.
May god help me.

On a lighter note. There is this Jayabheri Silicon County is a really nice place to hang out on a sunday Morning.