makecert and creating ssl or signing certificates

Credit to this blogger for this post.  I am reposting the contents here just incase the blog goes away as if very common.

Another blog about CERTIFICATES that is useful…

How to Set Up Site Bindings in Internet Information Services (IIS)

 

 

I’ve been asked to post my makecert scripts for creating self-signed certificates (one for SSL and the other for signing). I use both of these scripts as .bat files. These scripts accept one parameter — the CN (common name) you want the certificate to match. For the SSL cert this must match the host name. For signing it’s just a unique name. Both of these need to be run from an administrative command prompt because the scripts install the certificate into the local machine’s personal certificate store. If you need the public key portion (.cer) then you’d have to open mmc and export it. Also, notice the expiration in the scripts — this is something you might want to change based upon your situation.

The first script is for creating SSL certificates. This is good for setting up SSL on your local IIS for a new web site (you’d need to ensure the host is indicated and SNI is configured). Although the SSL certificate won’t be trusted until you configure the cert as trusted on the client machine. Here are the .bat file contents:

makecert -r -pe -n "CN=%1" -b 01/01/2015 -e 01/01/2020 -eku 1.3.6.1.5.5.7.3.1 -sky exchange -a sha256 -len 2048 -ss my -sr localMachine

The second script is for creating signing certificates (for things like token signing within a token service such as IdentityServer). Here are the .bat file contents:

makecert -r -pe -n "CN=%1" -b 01/01/2015 -e 01/01/2020 -eku 1.3.6.1.5.5.7.3.3 -sky signature -a sha256 -len 2048 -ss my -sr LocalMachine

HTH

log4Net logging

I struggled a bit with understanding this tool

These articles helped a ton:

The basics

http://www.codeproject.com/Articles/140911/log4net-Tutorial

More advance

http://www.codeproject.com/Articles/406634/Creating-a-custom-log-net-appender

Then custom table example:

 

<appender name=”ADONetAppender_SqlServer” type=”log4net.Appender.AdoNetAppender”>
<bufferSize value=”1″ />
<connectionType value=”System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />
<connectionString value=”Data Source=Jcdc-d-sql-001\dev;Database=log4Net;User Id=int_serv;Password=Int@2015!;” />
<filter type=”log4net.Filter.LevelRangeFilter”>
<levelMin value=”FATAL” />
<levelMax value=”FATAL” />
</filter>
<!–<connectionString value=”data source=JCDC-D-SQL-001\DEV;initial catalog=log4net;integrated security=true;persist security info=True;User ID=jcdev\lafrance.warren” />–>
<commandText value=”INSERT INTO AppLog ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)” />
<parameter>
<parameterName value=”@log_date” />
<dbType value=”DateTime” />
<!–
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%date{yyyy’-‘MM’-‘dd HH’:’mm’:’ss’.’fff}” />
</layout>
–>
<layout type=”log4net.Layout.RawTimeStampLayout” />
</parameter>
<parameter>
<parameterName value=”@thread” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%thread” />
</layout>
</parameter>
<parameter>
<parameterName value=”@log_level” />
<dbType value=”String” />
<size value=”50″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%level” />
</layout>
</parameter>
<parameter>
<parameterName value=”@logger” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%logger” />
</layout>
</parameter>
<parameter>
<parameterName value=”@message” />
<dbType value=”String” />
<size value=”4000″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%message” />
</layout>
</parameter>
<parameter>
<parameterName value=”@exception” />
<dbType value=”String” />
<size value=”2000″ />
<layout type=”log4net.Layout.ExceptionLayout” />
</parameter>
</appender>
<!–Configure the AdoNetAppender to connect to MS SQL Server –>
<appender name=”InfoAppender_SqlServer” type=”log4net.Appender.AdoNetAppender”>
<level value=”INFO” />

<filter type=”log4net.Filter.StringMatchFilter”>
<stringToMatch value=”Sending Message” />
</filter>
<filter type=”log4net.Filter.LevelRangeFilter”>
<levelMin value=”INFO” />
<levelMax value=”INFO” />
</filter>
<bufferSize value=”1″ />
<connectionType value=”System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />
<connectionString value=”Data Source=Jcdc-d-sql-001\dev;Database=log4Net;User Id=int_serv;Password=Int@2015!;” />
<commandText value=”INSERT INTO [dbo].[EmailLog] ([Date],[Thread],[Level],[Logger],[Message],[Exception],[StartDate],[EndDate],[DeliveryFrequency],[Address] ,[Parms] ,[Body],[sirsLogNumber], [sirsIncidentNumber]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @StartDate,@EndDate,@DeliveryFrequency,@Address,@Parms,@Body, @sirsLogNumber, @sirsIncidentNumber)” />

<parameter>
<parameterName value=”@log_date” />
<dbType value=”DateTime” />
<!–
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%date{yyyy’-‘MM’-‘dd HH’:’mm’:’ss’.’fff}” />
</layout>
–>
<layout type=”log4net.Layout.RawTimeStampLayout” />
</parameter>
<parameter>
<parameterName value=”@thread” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%thread” />
</layout>
</parameter>
<parameter>
<parameterName value=”@log_level” />
<dbType value=”String” />
<size value=”50″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%level” />
</layout>
</parameter>
<parameter>
<parameterName value=”@logger” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%logger” />
</layout>
</parameter>
<parameter>
<parameterName value=”@message” />
<dbType value=”String” />
<size value=”4000″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%message” />
</layout>
</parameter>
<parameter>
<parameterName value=”@exception” />
<dbType value=”String” />
<size value=”2000″ />
<layout type=”log4net.Layout.ExceptionLayout” />
</parameter>

<parameter>
<parameterName value=”@DeliveryFrequency” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{DeliveryFrequency}” />
</layout>
</parameter>

<parameter>
<parameterName value=”@StartDate” />
<dbType value=”DateTime” />
<layout type=”log4net.Layout.RawTimeStampLayout”>
<conversionPattern value=”%property{StartDate}” />
</layout>
</parameter>
<parameter>
<parameterName value=”@EndDate” />
<dbType value=”DateTime” />
<layout type=”log4net.Layout.RawTimeStampLayout”>
<conversionPattern value=”%property{EndDate}” />
</layout>
</parameter>
<!–@sirsLogNumber–>
<parameter>
<parameterName value=”@sirsLogNumber” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{sirsLogNumber}” />
</layout>
</parameter>
<!–@sirsIncidentNumber–>
<parameter>
<parameterName value=”@sirsIncidentNumber” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{sirsIncidentNumber}” />
</layout>
</parameter>
<!–@address–>
<parameter>
<parameterName value=”@Address” />
<dbType value=”String” />
<size value=”-1″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{Address}” />
</layout>
</parameter>
<!–@parms–>
<parameter>
<parameterName value=”@Parms” />
<dbType value=”String” />
<size value=”-1″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{Parms}” />
</layout>
</parameter>
<!–@body–>
<parameter>
<parameterName value=”@Body” />
<dbType value=”String” />
<size value=”-1″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{Body}” />
</layout>
</parameter>
</appender>