<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>azure-for-the-enterprise &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/azure-for-the-enterprise/</link>
	<description>Feed of posts on WordPress.com tagged "azure-for-the-enterprise"</description>
	<pubDate>Thu, 23 May 2013 12:30:41 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Agile path ways into the Azure Universe &ndash; Access Control Service [ACS]]]></title>
<link>http://blog.elastacloud.com/2012/09/23/agile-path-ways-into-the-azure-universe-access-control-service-acs/</link>
<pubDate>Sun, 23 Sep 2012 00:09:31 +0000</pubDate>
<dc:creator>Beth Martin</dc:creator>
<guid>http://blog.elastacloud.com/2012/09/23/agile-path-ways-into-the-azure-universe-access-control-service-acs/</guid>
<description><![CDATA[Preparation Tasks and Concepts The main content of this article depends upon an Azure Service called]]></description>
<content:encoded><![CDATA[<h2>Preparation Tasks and Concepts</h2>
<p>The main content of this article depends upon an Azure Service called ‘Access Control Service’. To make use of this service, you’ll need to sign up for an Azure Account. At the time of writing this article there is a 90 day free trial available.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/azureportal_signonscreen.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="azureportal_signonscreen" alt="azureportal_signonscreen" src="http://azurecoder.files.wordpress.com/2012/09/azureportal_signonscreen_thumb.png?w=511&#038;h=327" height="327" width="511" /></a></p>
<p>You can find the portal entry page and sign up page at this web address : [ <a title="http://www.windowsazure.com/en-us/" href="http://www.windowsazure.com/en-us/">http://www.windowsazure.com/en-us/</a> ]</p>
<p>The wizard will take you through the sign up process, including signing up for a live account if you do not have one currently.</p>
<h3>What is Azure?</h3>
<p>Azure is Microsoft cloud offering , in very simple terms Microsoft provide huge containers full of hardware across the world and from these hardware clusters, Microsoft offer you the ability to:</p>
<ul>
<li>Upload and consume Virtual Machines</li>
<li>Upload your own websites, applications and services</li>
<li>Consume specialist services for example Access Control Service [ACS]</li>
<li>Distribute your content worldwide via the Content Delivery Network [CDN]</li>
<li>Make use of Object based data storage using a variant of  NoSQL concept called Table Storage</li>
<li>Online SQL server instances , known as Azure SQL</li>
<li>Distributed messaging and workflow via powerful and custom service bus offering.</li>
</ul>
<p>In simple terms, Azure gives you the power to focus on writing world class software whilst it handles the hardware and costing concerns. All this power comes with a price tag, but when you take into account the cost of physical data canters Azure is more than competitive. In this article we will only utilise a tiny fraction of the power of Azure, but we would encourage you to explore it in more depth if you haven’t already.</p>
<h3>What Is the Access Control Service [ ACS ] ?</h3>
<p>Web Address – [ <a title="http://msdn.microsoft.com/en-us/library/windowsazure/gg429786.aspx" href="http://msdn.microsoft.com/en-us/library/windowsazure/gg429786.aspx">http://msdn.microsoft.com/en-us/library/windowsazure/gg429786.aspx</a> ]</p>
<p>The Access Control Service offered by Microsoft via the Azure platform is a broker for Single Sign On Solutions. In simple terms this provides the capability for users to Authenticate to use your application. This authentication uses commercial and trusted Identity Providers such as:</p>
<ul>
<li>Google</li>
<li>Windows Live Id</li>
<li>A custom identity provider or a corporate Active Directory.</li>
</ul>
<ul>Once a user has authenticated they are issued with a token. We can receive and use this token as a unique identifier for the user inside the target software system.</ul>
<ul>This is as far as we will go to explain ACS, there is a lot of high quality material available on the internet that covers the basics of getting up and running with ACS . We have included a number of in depth links below, but the rest of this article will focus on Test driving ACS.</ul>
<h4>Adding Internet Identity Providers like Facebook, Google, LiveID and Yahoo to your MVC web application using Windows Azure AppFabric Access Control Service and jQuery in 3 steps</h4>
<p><a title="http://blogs.southworks.net/mwoloski/2011/04/12/adding-internet-identity-providers-like-facebook-google-liveid-and-yahoo-to-your-mvc-web-application-using-windows-azure-appfabric-access-control-service-and-jquery-in-3-steps/" href="http://blogs.southworks.net/mwoloski/2011/04/12/adding-internet-identity-providers-like-facebook-google-liveid-and-yahoo-to-your-mvc-web-application-using-windows-azure-appfabric-access-control-service-and-jquery-in-3-steps/">http://blogs.southworks.net/mwoloski/2011/04/12/adding-internet-identity-providers-like-facebook-google-liveid-and-yahoo-to-your-mvc-web-application-using-windows-azure-appfabric-access-control-service-and-jquery-in-3-steps/</a></p>
<h4>How to Authenticate Web Users with Windows Azure Access Control Service</h4>
<p><a title="http://www.windowsazure.com/en-us/develop/net/how-to-guides/access-control/" href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/access-control/">http://www.windowsazure.com/en-us/develop/net/how-to-guides/access-control/</a></p>
<h4>Re-Introducing the Windows Azure Access Control Service</h4>
<p><a title="http://msdn.microsoft.com/en-us/magazine/gg490345.aspx" href="http://msdn.microsoft.com/en-us/magazine/gg490345.aspx">http://msdn.microsoft.com/en-us/magazine/gg490345.aspx</a></p>
<h3>Behaviour Driven Development and black box testing – Concepts</h3>
<p>Behaviour Driven Development or BDD has been in common use for a number of years, and there are several  flavours available in a number of frameworks. The basis of BDD is that we execute living requirements (or in Agile speak, Stories) which have been written in a English readable representation of the required functionality.</p>
<p>Some frameworks take a Domain Specific Language (DSL) approach to defining the requirements that the BDD tests will execute, a common standard is called Gherkin.</p>
<p>DSL  : [ <a title="http://www.martinfowler.com/bliki/BusinessReadableDSL.html" href="http://www.martinfowler.com/bliki/BusinessReadableDSL.html">http://www.martinfowler.com/bliki/BusinessReadableDSL.html</a> ]</p>
<p>Gherkin : [ <a title="http://www.ryanlanciaux.com/2011/08/14/gherkin-style-bdd-testing-in-net/" href="http://www.ryanlanciaux.com/2011/08/14/gherkin-style-bdd-testing-in-net/">http://www.ryanlanciaux.com/2011/08/14/gherkin-style-bdd-testing-in-net/</a> ]</p>
<p>The framework we will be using in this article is called StoryQ ([ <a title="http://storyq.codeplex.com/" href="http://storyq.codeplex.com/">http://storyq.codeplex.com/</a> ]). We have chosen this framework due to its simplistic approach to specification design, and more importantly its support for coded specifications. To be specific; we write the specification in code and therefore they become part of our living code base.</p>
<h4>Driving the Browser</h4>
<p>Although StoryQ provides a nice step by step format and structure to our Stories, it still leaves the problem that the requirements are written from a high level perspective.</p>
<p>As developers, we could implement a White box style approach where by we do not respect the outer borders of the application. Our Tests would then be allowed to interact with the code, and even substitute parts of the code for Testing objects such as Mocks. We speak about this approach in detail in this article.</p>
<p>[ <a title="http://blog.elastacloud.com/2012/08/21/step-by-step-guides-getting-started-with-specification-driven-development-sdd/" href="http://blog.elastacloud.com/2012/08/21/step-by-step-guides-getting-started-with-specification-driven-development-sdd/">http://blog.elastacloud.com/2012/08/21/step-by-step-guides-getting-started-with-specification-driven-development-sdd/</a> ] .</p>
<p>In this case we have elected to respect the boundaries of the application. We will treat the application as if it is within a black box, into which we can not see or interfere but with who’s public interface (in this case a web page) we can interact.</p>
<p>Having made this decision we now need to find a framework to work with StoryQ. We need to allow our tests to drive a browser and cause it to replicate a users interaction. There are a number of frameworks available , in this case we select the excellent Selenium  + Web driver packages from Nuget.</p>
<p>[ <a title="http://www.nuget.org/packages/Selenium.WebDriver" href="http://www.nuget.org/packages/Selenium.WebDriver">http://www.nuget.org/packages/Selenium.WebDriver</a> ].</p>
<h4>The tools we are using</h4>
<p>Our own development setup is as follows:</p>
<p>·Windows 8 <a href="http://windows.microsoft.com/en-US/windows-8/release-preview">http://windows.microsoft.com/en-US/windows-8/release-preview</a></p>
<p>· Visual Studio 2012 <a href="http://www.microsoft.com/visualstudio/11/en-us">http://www.microsoft.com/visualstudio/11/en-us</a></p>
<p>· Resharper 7 <a href="http://www.jetbrains.com/resharper/whatsnew/index.html">http://www.jetbrains.com/resharper/whatsnew/index.html</a></p>
<p>· NUnit <a href="http://nuget.org/packages/nunit">http://nuget.org/packages/nunit</a></p>
<p>· NUnit Fluent Extensions <a href="http://fluentassertions.codeplex.com/">http://fluentassertions.codeplex.com/</a></p>
<p>- Selenium + Web Driver <a title="http://www.nuget.org/packages/Selenium.WebDriver" href="http://www.nuget.org/packages/Selenium.WebDriver">http://www.nuget.org/packages/Selenium.WebDriver</a></p>
<p>We find that the above combination of software packages makes for an exceptional development environment. Windows 8 is by far the most productive Operating System we have used across any hardware stack. Jet Brains Resharper has become an indispensable tool, without which Visual Studio feels highly limited. NUnit is our preferred testing framework, however you could use MBUnit or XUnit. For those who must stick with a pure Microsoft ALM experience you could also use MSTest.</p>
<h2>What are we trying to achieve</h2>
<p>In the rest of this article we will demonstrate using Selenium + Web Driver to empower our StoryQ tests. We will show how to represent a User logging into Azure [ACS] prior to them accessing our site.</p>
<p>We will show illustrations of the following</p>
<ul>
<li>Web Driver</li>
<li>StoryQ</li>
<li>Azure Access Control Service</li>
<li>Emergent Design</li>
<li>NUnit</li>
<li>Unit Testing a controller action</li>
<li>Selenium Selectors</li>
<li>Identity and Access Tool</li>
</ul>
<h2>Test Driven</h2>
<p>As Test Driven Developers we start with a requirement and a Test -</p>
<blockquote><p>As A User who is not logged in</p>
<p>When I try to access the site</p>
<p>Then I expect to be taken to a login screen</p></blockquote>
<h4>Step 1 : Is to add a Test Assembly this is just a standard class library project.</h4>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image21.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb21.png?w=630&#038;h=354" height="354" width="630" /></a></p>
<h4>Step 2 : Add Nuget references for -</h4>
<ul>
<ul>
<li>Nunit</li>
<li>StoryQ</li>
<li>Fluent Assertions</li>
</ul>
</ul>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/nuget-references-testing-storyq.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="nuget-references-testing-storyq" alt="nuget-references-testing-storyq" src="http://azurecoder.files.wordpress.com/2012/09/nuget-references-testing-storyq_thumb.png?w=630&#038;h=421" height="421" width="630" /></a></p>
<h4>Step 3 : Write a Story -</h4>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image22.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb22.png?w=630&#038;h=257" height="257" width="630" /></a></p>
<h5>Note on Story Planning</h5>
<p>The Story above reflects the spirit of the original requirement, but actually attacks them in a very pragmatic way. This will not appeal to purist BDD folks, but it is an approach we have found to be very effective when analysing requirements from Business. We often find that some of the set up and Administrator stories have been missed from the planning, and that these are required to empower the pure business Story’s.</p>
<p>We can also see here that the motivation for the ACS integration has changed to the Administrator. This would of typically come out of a conversation with a Business Owner over who this Story benefits and which role would be motivated by the security of the system.</p>
<p>The business would typically readjust their Story pallet to include Stories relevant to User profile and data security that arise from discussion with the business owner. This allows us to refine the Stories provided to the developers and better reflect the businesses intentions. The above situation illustrates the cooperative requirement management process with the Agile space. It is a good example of iterative requirement planning as a requirement passes through different stages of planning.</p>
<p>If we execute a dry run of this story -</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image23.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb23.png?w=630&#038;h=189" height="189" width="630" /></a></p>
<p>we see the following output -</p>
<blockquote><p>Story is We are forced to login to ACS when trying to access the site<br />
In order to keep the web site secure =&#62; (#001)<br />
As a Administrator<br />
I want users to have to authenticate via ACS prior to entry to the web site</p>
<p>With scenario Happy Path</p></blockquote>
<h4>Step 4 : Write the scenario -</h4>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image24.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb24.png?w=630&#038;h=270" height="270" width="630" /></a></p>
<h4>Step 5 :Generate Step Stubs</h4>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image25.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb25.png?w=630&#038;h=557" height="557" width="630" /></a></p>
<h2>Recap – What we have done so far</h2>
<p>We have taken the following steps –</p>
<ul>
<li>Set up a environment</li>
<li>Built a class library project</li>
<li>Set up a story</li>
<li>Set up a scenario</li>
<li>Stubbed out the steps required by the scenario</li>
</ul>
<p>If we dry run the story now we see the following output -</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image26.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb26.png?w=630&#038;h=236" height="236" width="630" /></a></p>
<p>Lets take a closer look</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image27.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb27.png?w=630&#038;h=194" height="194" width="630" /></a></p>
<p>We can immediately see what we need to do to make this test pass, and in a very human readable output. This is one of the amazing and empowering features of StoryQ; it’s ability to bridge the gap between technical and business, via its clear and precise output formats.</p>
<p>Note – this is still a bit of a technical story, terms such as ACS would probably need to be refactored or added to a product definition dictionary, for the sake of this article we have kept this wording in.</p>
<h2>Implementing the Functionality and making the story pass.</h2>
<p>Next we start to use the test steps defined in the Story to drive out our functional foot print. In the following sections we will start to make formative steps to construct the application. The ACS bridge being built through the Azure side of the configuration will not be covered, as this has been covered in depth by the links supplied in earlier sections of this article.</p>
<h3>Steps illustration</h3>
<p>Now lets get started with the implementation.</p>
<h4></h4>
<h4>Step 1 : That I am Not Logged In</h4>
<p>This step forces us to use Nuget to bring in the webdriver and selenium implementation we referred to earlier. The main reason we are driven to do this now is because we want to be sure we have no ACS cookies registered with the browser. To delete any cookies that are present we need to make a call to the browser. This also gives us our perfect motivation to bring down a browser automation tool kit.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtml5dd5c70.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTML5dd5c70" alt="SNAGHTML5dd5c70" src="http://azurecoder.files.wordpress.com/2012/09/snaghtml5dd5c70_thumb.png?w=630&#038;h=421" height="421" width="630" /></a></p>
<p>With the Webdriver in place we can now instantiate it and make sure we have cleared down any cookies and are working with a fresh profile. There are drivers available for Firefox, Internet Explorer and Chrome. In our case we have used Firefox.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image28.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb28.png?w=630&#038;h=223" height="223" width="630" /></a></p>
<p>With the Driver in place and instantiated we can now make sure it is clear of cookies.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image29.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb29.png?w=630&#038;h=124" height="124" width="630" /></a></p>
<p>We are being explicit here despite the fact we have just created a new Profile. This is because the step cannot be dependant upon the set code, the driver or profile to remain unchanging.  We therefor include a deliberate step to delete all cookies and make sure we are working with a clean browser.</p>
<h4>Step 2 : I Try To Go To The Home Page</h4>
<p>In this step we will see a browser window open up and try to browse to the site. To enable this we are driven to add the following elements -</p>
<ul>
<li>App.Config</li>
<li>ASP MVC Application</li>
<li>Home Controller</li>
<li>Index Action</li>
</ul>
<ul>When we can see that the browser launched by the framework automatically navigates to the home page then we know this step is complete.</ul>
<h5>The code to drive the browser -</h5>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image30.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb30.png?w=630&#038;h=87" height="87" width="630" /></a></p>
<ul>The settings for the test runner, held in a app.config file for convenience.</ul>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image31.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb31.png?w=630&#038;h=174" height="174" width="630" /></a></p>
<p>We now add a ASP MVC 4 project</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtml98cdf96.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTML98cdf96" alt="SNAGHTML98cdf96" src="http://azurecoder.files.wordpress.com/2012/09/snaghtml98cdf96_thumb.png?w=630&#038;h=437" height="437" width="630" /></a></p>
<p>When we run the story we can see Firefox open and try to navigate to the Home URL, which fails.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image32.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb32.png?w=630&#038;h=463" height="463" width="630" /></a></p>
<p>We will now add a Unit test to drive out the Home controller and index action.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image33.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb33.png?w=630&#038;h=440" height="440" width="630" /></a></p>
<p>From this test we drive out the view and the controller, we have added them below for completeness.</p>
<h5>Controller</h5>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image34.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb34.png?w=630&#038;h=257" height="257" width="630" /></a></p>
<h5>View</h5>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image35.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb35.png?w=630&#038;h=296" height="296" width="630" /></a></p>
<p>The controller and view are skeletal objects, we only implement what we are driven to add by our tests.</p>
<p>We now rerun our test and find that we are green. We are ready to continue our journey.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image36.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb36.png?w=630&#038;h=364" height="364" width="630" /></a></p>
<p>With the new controller and view in place we will re-run our Step and see if we can reach the site. Unfortunately we find we still fail – this is because the default is for visual studio to use the development server. We can work with this, but when working on the types of sites that we will be running via the Azure Emulator, we prefer to work directly with a IIS or IIS express. Eventually, as mentioned above, we would more than likely be driven by our none functional requirements to implement the Azure emulator. However as we have not been driven there yet, we will configure visual studio to run this site via IIS.</p>
<p>The links below will explain how to configure your choice of web server for your project to run under.</p>
<p><a title="http://msdn.microsoft.com/en-us/library/ms178108%28v=vs.100%29.aspx" href="http://msdn.microsoft.com/en-us/library/ms178108%28v=vs.100%29.aspx">[ http://msdn.microsoft.com/en-us/library/ms178108%28v=vs.100%29.aspx</a> ]</p>
<p>[ <a title="http://ukchill.com/technology/setting-up-a-web-project-environment-in-visual-studio-2010-to-allow-debugging-using-both-iis7-and-the-development-web-server/" href="http://ukchill.com/technology/setting-up-a-web-project-environment-in-visual-studio-2010-to-allow-debugging-using-both-iis7-and-the-development-web-server/">http://ukchill.com/technology/setting-up-a-web-project-environment-in-visual-studio-2010-to-allow-debugging-using-both-iis7-and-the-development-web-server/</a> ]</p>
<p>With IIS configured we have proved the potential for this step to succeed. We can see below that without ACS implemented we are successfully able to Test Drive to the Home action of the site.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image37.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb37.png?w=630&#038;h=367" height="367" width="630" /></a></p>
<p>StoryQ guides our efforts by showing a textual map of what we have done and what we have left to achieve.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image38.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb38.png?w=630&#038;h=247" height="247" width="630" /></a></p>
<h4>Step 3 : I Am Taken To The ACS Provider Chooser Page</h4>
<p>To Achieve this step we need to add some acceptance criteria and then we need to configure ACS. First let us set our expectations for this step.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image39.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb39.png?w=630&#038;h=85" height="85" width="630" /></a></p>
<p>In the code above we have a search to retrieve all div elements on page, followed by a Query to make sure the ACS sign on text can be found in the collection. Note that there are many elements that we could have checked on the page, including a fragment of the URL. As there was a choice, we have chosen to select just enough to get the job done and fix the Query and Criteria if it proves to be problematic.</p>
<p>Note: the selection criteria above will vary dependent upon the Identity providers you have configured. The above criteria works when we have selected multiple identity providers, in this case google and Windows Live.</p>
<p>The next step is to configure the pathways to ACS. For this to succeed you need to have configured an ACS namespace as per the directions supplied on the links earlier in this article.</p>
<h5>Identity And Access Tool</h5>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtml9dadae7.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTML9dadae7" alt="SNAGHTML9dadae7" src="http://azurecoder.files.wordpress.com/2012/09/snaghtml9dadae7_thumb.png?w=630&#038;h=437" height="437" width="630" /></a></p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtmla23f413.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTMLa23f413" alt="SNAGHTMLa23f413" src="http://azurecoder.files.wordpress.com/2012/09/snaghtmla23f413_thumb.png?w=630&#038;h=573" height="573" width="630" /></a></p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtmla26430d.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTMLa26430d" alt="SNAGHTMLa26430d" src="http://azurecoder.files.wordpress.com/2012/09/snaghtmla26430d_thumb.png?w=630&#038;h=573" height="573" width="630" /></a></p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtmla4eb6d6.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTMLa4eb6d6" alt="SNAGHTMLa4eb6d6" src="http://azurecoder.files.wordpress.com/2012/09/snaghtmla4eb6d6_thumb.png?w=630&#038;h=573" height="573" width="630" /></a></p>
<p>The Identity and Access Tool can be used to bypass a lot of manual configuration and pain. It is a substantial improvement on the WIF tool kit. Below is a link which provides details of how to configure the tool .</p>
<p><a href="http://visualstudiogallery.msdn.microsoft.com/e21bf653-dfe1-4d81-b3d3-795cb104066e">http://visualstudiogallery.msdn.microsoft.com/e21bf653-dfe1-4d81-b3d3-795cb104066e</a></p>
<p><a href="http://blogs.iqcloud.net/2012/09/federated-authentication-with-azure-acs.html">http://blogs.iqcloud.net/2012/09/federated-authentication-with-azure-acs.html</a></p>
<p>Note: We have, on occasions, found that we have needed to restart Visual Studio 2012 multiple times when installing this tool, before the Identity and Access option has been available on the context menu.</p>
<p>Note: We have found with our ASP MVC projects when using this tool, that we then need to add some namespaces as reference. You can check what these are by taking a quick peek at the web.config file.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image40.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb40.png?w=630&#038;h=340" height="340" width="630" /></a></p>
<p>We found we needed to add System.IdentityModel.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtmla380227.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTMLa380227" alt="SNAGHTMLa380227" src="http://azurecoder.files.wordpress.com/2012/09/snaghtmla380227_thumb.png?w=630&#038;h=434" height="434" width="630" /></a></p>
<p>If you want to check your configuration , set the ASP MVC project as the start up project and press f5 to run the project. Depending on the identity providers you configured, you should be presented with a challenge page.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image41.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb41.png?w=630&#038;h=630" height="630" width="630" /></a></p>
<p>Once you have logged in you , you should be presented with your Home page for your ASP MVC Application</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image42.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb42.png?w=630&#038;h=356" height="356" width="630" /></a></p>
<p>With the ACS bridge in place and properly configured, we will now head back to our Story and the step we were completing. We need to rerun the test to check the expectation.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image43.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb43.png?w=335&#038;h=254" height="254" width="335" /></a></p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image44.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb44.png?w=630&#038;h=244" height="244" width="630" /></a></p>
<p>After running the test Firefox starts up and goes to the ACS page. The text inside the div is found and we have another passing step in our story as well as a configured ACS bridge.</p>
<p>Next we will pick an identify provider. We will then login to the ACS page using the web driver and authenticate.</p>
<h4>Step 4 : I Have To Pick A Identity Provider</h4>
<p>We will use the web driver to login to Windows Live as the Identity Provider.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image45.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb45.png?w=630&#038;h=129" height="129" width="630" /></a></p>
<p>We can now execute this step</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image46.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb46.png?w=630&#038;h=382" height="382" width="630" /></a></p>
<p>Success –  The test now executes the step to take the driver to the Windows Live login page</p>
<h4>Step 5 : I Have To Login To My Identity Provider</h4>
<p>To provide this functionality we have written a few extension methods. There is no magic here, the secret of this technique is in its simplicity.  We need only do the following :</p>
<ul>
<li>Find the relevant elements on the page</li>
<li>Enter the expected Text</li>
<li>Click a button</li>
<li>Capture a confirmation dialog and accept it</li>
</ul>
<h5>Step implementation</h5>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image47.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb47.png?w=630&#038;h=158" height="158" width="630" /></a></p>
<h5>Extension Methods</h5>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image48.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb48.png?w=630&#038;h=515" height="515" width="630" /></a></p>
<h6>The ACS provider after the Email address and Password have been filled in</h6>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/snaghtmlb95f208.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="SNAGHTMLb95f208" alt="SNAGHTMLb95f208" src="http://azurecoder.files.wordpress.com/2012/09/snaghtmlb95f208_thumb.png?w=629&#038;h=746" height="746" width="629" /></a></p>
<h6>Success – The Home screen, post click of submit button and acceptance of Confirmation Dialog</h6>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image49.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb49.png?w=630&#038;h=406" height="406" width="630" /></a></p>
<h6>Test output showing passing step</h6>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image50.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb50.png?w=630&#038;h=234" height="234" width="630" /></a></p>
<h4>Step 6 : I am Taken To The Site</h4>
<p>The final step asserts that we are in fact on the home page and we are done</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image51.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb51.png?w=630&#038;h=108" height="108" width="630" /></a></p>
<p>Let us now execute this test and hopefully we should have a green passing story.</p>
<p><a href="http://azurecoder.files.wordpress.com/2012/09/image52.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;" title="image" alt="image" src="http://azurecoder.files.wordpress.com/2012/09/image_thumb52.png?w=630&#038;h=387" height="387" width="630" /></a></p>
<p>&#160;</p>
<h2>Recap &#8211; What have we just done</h2>
<p>Let us just take a moment to take a breath and look back at what we have achieved.</p>
<ul>
<li>We now have a ASP MVC 4 application shell</li>
<li>The ASP MVC 4 application shell is integrated with ACS</li>
<li>We have security test coverage across the homepage. We can add other scenarios to our Stories if we want to make them implement ACS security.</li>
<li>We have introduced the the concepts of Black Box Browser based BDD.</li>
<li>We have had a short discussion about the need to reinterprete and reframe requirements</li>
</ul>
<h2>Conclusion</h2>
<div>
<ul>In this short article we have introduced a lot of new material ,and supplied a number of links to in-depth discussions and tutorials on the  relevant subject areas. It is our hope that this acts as a spring board to deeper learning and fun with Azure, ACS and BDD.</ul>
<ul>
<ul>Author Beth</ul>
<ul>Follow @Martindotnet</ul>
</ul>
</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Building a virus scanning gateway in Windows Azure with Endpoint Protection]]></title>
<link>http://blog.elastacloud.com/2012/08/12/building-a-virus-scanning-gateway-in-windows-azure-with-endpoint-protection/</link>
<pubDate>Sun, 12 Aug 2012 11:49:46 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/08/12/building-a-virus-scanning-gateway-in-windows-azure-with-endpoint-protection/</guid>
<description><![CDATA[I remember being on a project some 9 years ago and having to build one of these. To build a realtime]]></description>
<content:encoded><![CDATA[<p>I remember being on a project some 9 years ago and having to build one of these. To build a realtime gateway is not as easy as you would think. In my project there were accountants uploading invoices of various types and formats that we had to translate into text using an OCR software package. We built a workflow using a TIBCO workflow designer solution (which I wouldn&#8217;t hesitate now to replace with WF!)</p>
<p>At a certain point people from outside the organisation had the ability to upload a file and this file had to be intercepted by a gateway before being persisted and operated on the through the workflow. You would think that this was an easy and common solution to implement. However, at the time it wasn&#8217;t. We used a Symantec gateway product and its C API which allowed us to use the ICAP protocol and thus do real time scanning.</p>
<div id="attachment_1097" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker1.jpg"><img class="size-full wp-image-1097" title="Begin everything with a web role" src="http://azurecoder.files.wordpress.com/2012/08/filechecker1.jpg?w=575&#038;h=359" alt="Begin everything with a web role" width="575" height="359" /></a><p class="wp-caption-text">Begin everything with a web role</p></div>
<p>For the last 6 months I&#8217;ve wanted to talk about Microsoft Endpoint Protection (<a title="http://www.microsoft.com/en-us/download/details.aspx?id=29209" href="http://www.microsoft.com/en-us/download/details.aspx?id=29209">http://www.microsoft.com/en-us/download/details.aspx?id=29209</a>) which is still in CTP as a I write this. It&#8217;s a lesser known plugin which exists for Windows Azure. For anybody that receives uploaded content, this should be a commonplace part of the design. In this piece I want to look at a pattern for rolling your gateway with Endpoint Protection. It&#8217;s not ideal because it literally is a virus scanner, enabling real time protection and certain other aspects but uses Diagnostics to show issues that have taken place.</p>
<div id="attachment_1098" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker2.jpg"><img class="size-full wp-image-1098" title="The files which are part of the endpoint protection plugin" src="http://azurecoder.files.wordpress.com/2012/08/filechecker2.jpg?w=575&#038;h=209" alt="The files which are part of the endpoint protection plugin" width="575" height="209" /></a><p class="wp-caption-text">The files which are part of the endpoint protection plugin</p></div>
<p>So initially we&#8217;ll enable the imports:</p>
<pre class="brush: xml; title: ; notranslate" title="">
&#60;Imports&#62;
&#60;Import moduleName=&#34;Diagnostics&#34; /&#62;
&#60;Import moduleName=&#34;Antimalware&#34; /&#62;
&#60;Import moduleName=&#34;RemoteAccess&#34; /&#62;
&#60;Import moduleName=&#34;RemoteForwarder&#34; /&#62;
&#60;/Imports&#62;
</pre>
<p>You can see the addition of Antimalware here.</p>
<p>Correspondingly, our service configuration gives us the following new settings:</p>
<pre class="brush: xml; title: ; notranslate" title="">
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString&#34; value=&#34;&#60;my connection string&#62;&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.ServiceLocation&#34; value=&#34;North Europe&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.EnableAntimalware&#34; value=&#34;true&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.EnableRealtimeProtection&#34; value=&#34;true&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.EnableWeeklyScheduledScans&#34; value=&#34;false&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.DayForWeeklyScheduledScans&#34; value=&#34;7&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.TimeForWeeklyScheduledScans&#34; value=&#34;120&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.ExcludedExtensions&#34; value=&#34;txt&#124;rtf&#124;jpg&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.ExcludedPaths&#34; value=&#34;&#34; /&#62;
&#60;Setting name=&#34;Microsoft.WindowsAzure.Plugins.Antimalware.ExcludedProcesses&#34; value=&#34;&#34; /&#62;
</pre>
<p>The settings are using Endpoint Protection for real time protection and scheduled scan. It&#8217;s obviously highly configurable like most virus scanners and in the background will update all malware defitions securely from a Microsoft source.</p>
<div id="attachment_1101" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker3.jpg"><img class="size-full wp-image-1101" title="Endpoint protection installed on our webrole" src="http://azurecoder.files.wordpress.com/2012/08/filechecker3.jpg?w=575&#038;h=402" alt="Endpoint protection installed on our webrole" width="575" height="402" /></a><p class="wp-caption-text">Endpoint protection installed on our webrole</p></div>
<p>First thing we&#8217;ll do is download a free virus test file from <a title="http://www.eicar.org/85-0-Download.html" href="http://www.eicar.org/85-0-Download.html">http://www.eicar.org/85-0-Download.html</a>. Eicar has ensured that this definition is picked by most of the common virus scanning so Endpoint Protection should recognise this immediately. I&#8217;ve tested this with the .zip file but any of them are fine.</p>
<p>The first port of call is setting up diagnostics to proliferate the event log entries. We can do this within our RoleEntryPoint.OnStart method for our web role.</p>
<pre class="brush: csharp; title: ; notranslate" title="">
var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
//exclude informational and verbose event log entries
config.WindowsEventLog.DataSources.Add(&#34;System!*[System[Provider[@Name='Microsoft Antimalware'] and (Level=1 or Level=2 or Level=3 or Level=4)]]&#34;);
//write to persisted storage every 1 minute
config.WindowsEventLog.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1.0);
DiagnosticMonitor.Start(&#34;Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString&#34;, config);
</pre>
<div id="attachment_1104" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker5.jpg"><img class="size-full wp-image-1104" title="Diagnostics info in Azure Management Studio " src="http://azurecoder.files.wordpress.com/2012/08/filechecker5.jpg?w=575&#038;h=341" alt="Diagnostics info in Azure Management Studio " width="575" height="341" /></a><p class="wp-caption-text">Diagnostics info in Azure Management Studio</p></div>
<p>Okay, so in testing it looks like the whole process of cutting and pasting the file onto the desktop or another location takes about 10 seconds for the Endpoint Protection to pick this up and quarante the file. Given this we&#8217;ll set the bar at 20 seconds.</p>
<div id="attachment_1103" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker4.jpg"><img class="size-full wp-image-1103" title="Endpoint protection discovers malware" src="http://azurecoder.files.wordpress.com/2012/08/filechecker4.jpg?w=575&#038;h=402" alt="Endpoint protection discovers malware" width="575" height="402" /></a><p class="wp-caption-text">Endpoint protection discovers malware</p></div>
<p>I created a very simple ASP.NET web forms application with a file upload control. There are two ways to detect whether the file has been flagged as malware:</p>
<ol>
<li>Check to see whether the file is still around or has been removed and placed in quarantine</li>
<li>Check the eventlog entry to see whether this has been flagged as malware.</li>
</ol>
<p>We&#8217;re going to focus on No.2 so I&#8217;ve created a simple button click event which will persist the file. Endpoint protection will kick in within the short period so we&#8217;ll write the file to disk and then pause for 20 seconds. After our wait we&#8217;ll then check the eventlog and in the message string we&#8217;ll have a wealth of information about the file which has been quarantined.</p>
<pre class="brush: csharp; title: ; notranslate" title="">
bool hasFile = fuEndpointProtection.HasFile;
string path = &#34;&#34;;
if(hasFile)
{
	path = Path.Combine(Server.MapPath(&#34;.&#34;), fuEndpointProtection.FileName);
	fuEndpointProtection.SaveAs(path);
}
// block here until we check endpoint protection to see whether the file has been delivered okay!
Thread.Sleep(20000);
var log = new EventLog(&#34;System&#34;, Environment.MachineName, &#34;Microsoft Antimalware&#34;);
foreach(EventLogEntry entry in log.Entries)
{
	if(entry.InstanceId == 1116 &#38;&#38; entry.TimeWritten &#62; DateTime.Now.Subtract(new TimeSpan(0, 2, 0)))
        {
        	if(entry.Message.Contains(value: fuEndpointProtection.FileName.ToLower()))
                {
			Label1.Text = &#34;File has been found to be malware and quarantined!&#34;;
                        return;
                }
        }
}
Label1.Text = path;
</pre>
<div id="attachment_1105" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker6.jpg"><img class="size-full wp-image-1105" title="When I upload a normal file" src="http://azurecoder.files.wordpress.com/2012/08/filechecker6.jpg?w=575&#038;h=43" alt="When I upload a normal file" width="575" height="43" /></a><p class="wp-caption-text">When I upload a normal file</p></div>
<div id="attachment_1106" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/08/filechecker7.jpg"><img class="size-full wp-image-1106" title="When I upload the Eicar test file" src="http://azurecoder.files.wordpress.com/2012/08/filechecker7.jpg?w=575&#038;h=46" alt="When I upload the Eicar test file" width="575" height="46" /></a><p class="wp-caption-text">When I upload the Eicar test file</p></div>
<pre>The eventlog entry should look like this, which contains details on the affected process, the fact that it is a virus and also some indication on where to get some more information by providing a threat URL.
<pre class="brush: xml; title: ; notranslate" title="">
   %%860
   4.0.1521.0
   {872DA7D0-383A-4A18-A447-DC4C7E71785F}
   2012-08-12T09:31:18.362Z

   2147519003
   Virus:DOS/EICAR_Test_File
   5
   Severe
   42
   Virus

http://go.microsoft.com/fwlink/?linkid=37020&#38;name=Virus:DOS/EICAR_Test_File&#38;threatid=2147519003

   3

   2
   3
   %%818
   D:\Windows\System32\inetsrv\w3wp.exe
   NT AUTHORITY\NETWORK SERVICE

   containerfile:_F:\sitesroot&#092;&#048;\eicar_com.zip;file:_F:\sitesroot&#092;&#048;\eicar_com.zip-&#62;(Zip);file:_F:\sitesroot&#092;&#048;\eicar_com.zip-&#62;eicar.com
   1
   %%845
   1
   %%813
   0
   %%822
   0
   2
   %%809

   0x00000000
   The operation completed successfully.

   0
   0
   No additional actions required
   NT AUTHORITY\SYSTEM

   AV: 1.131.1864.0, AS: 1.131.1864.0, NIS: 0.0.0.0
   AM: 1.1.8601.0, NIS: 0.0.0.0
</pre>
<p>Okay, so this is very tamed example but it does prove the concept. In the real world you may even want to have a proper gateway which acts as a proxy and then forwards the file onto a "checked" store if it succeeds. We looked at the two ways you can check to see whether the file has been treated as malware. The first, checking to see whether the file has been deleted from it's location is too non-deterministic because although "real time" means real time we don't want to block and wait and timeout on this. The second is better because we will get a report if it's detected. This being the case, a more hardened version of this example will entail building a class which may treat the file write as a task and asynchronously ping back the user if the file has been treated as malware - something like this could be written as an HttpModule or ISASPI filter pursue the test and either continue with the request or end the request and return an HTTP error code to the user with a description of the problems with the file.</p>
<p>Happy trails etc.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Tricks with IaaS and SQL: Part 2 - Scripting simple powershell activities and consuming the Service Management API in C# with Fluent Management]]></title>
<link>http://blog.elastacloud.com/2012/07/06/tricks-with-iaas-and-sql-part-2-scripting-simple-powershell-activities-and-consuming-the-service-management-api-in-c-with-fluent-management/</link>
<pubDate>Fri, 06 Jul 2012 07:38:50 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/07/06/tricks-with-iaas-and-sql-part-2-scripting-simple-powershell-activities-and-consuming-the-service-management-api-in-c-with-fluent-management/</guid>
<description><![CDATA[In the last blogpost we looked at how we could use powershell to build an IaaS deployment for SQL Se]]></description>
<content:encoded><![CDATA[<p>In the last blogpost we looked at how we could use powershell to build an IaaS deployment for SQL Server 2012. The usage was pretty seamless and it really lends itself well to scripted and unattended deployments of VMs. The process we went through showed itself wanting a little in that we had to build in some unwanted manual tasks to get a connection to the SQL Server. We looked at the provision of firewall rules, moving from Windows Authentication to Mixed Mode authentication and then adding a database user in an admin role.</p>
<p>The unfortunate fact is that this process can never be seamless (unlike PaaS) with the default gallery images since you cannot control the running of a startup script (nor would you want to). So to dive in we&#8217;ll look into building a powershell script that can do all of the above which can just be copied via remote desktop and executed.</p>
<p>The first part of the script will update the registry key so that we can test our SQL Server connection locally.</p>
<pre class="brush: powershell; title: ; notranslate" title="">

#Check and set the LoginMode reg key to 2 so that we can have mixed authentication
 Set-Location HKLM:\
 $registry_key = &#34;SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer&#34;
 var $item = (Get-ItemProperty -path $registry_Key -name LoginMode).loginmode
 If($item -eq 1) {
 # This is Windows Authentication we need to update
 Set-ItemProperty -path $registry_key -name &#34;LoginMode&#34; -value 2
 }

</pre>
<p>When this is done we&#8217;ll want to open up the firewall port on the machine. Whether we our goal is to use Windows Authentication or Mixed Mode, or only expose the SQL Server to a Windows network that we create as part of an application &#8211; so only available internally we&#8217;ll still need to open up that firewall port. We do this through the use of a COM object which will allow us to set various parameters such as a port number, range and protocol.</p>
<pre class="brush: powershell; title: ; notranslate" title="">

# Add a new firewall rule - courtesy Tom Hollander
 $fw = New-Object -ComObject hnetcfg.fwpolicy2
 $rule = New-Object -ComObject HNetCfg.FWRule
 $rule.Name = &#34;SQL Server Inbound Rule&#34;
 $rule.Protocol = 6 #NET_FW_IP_PROTOCOL_TCP
 $rule.LocalPorts = 1433
 $rule.Enabled = $true
 $rule.Grouping = &#34;@firewallapi.dll,-23255&#34;
 $rule.Profiles = 7 # all
 $rule.Action = 1 # NET_FW_ACTION_ALLOW
 $rule.EdgeTraversal = $false
 $fw.Rules.Add($rule)

</pre>
<p>Lastly, we will need to add a user that we can test our SQL Server with. This is done through SQL statements and stored procedures. You can see the use of sqlcmd here. This is by far the easiest way although we could have used SMO to do the same thing.</p>
<pre class="brush: powershell; title: ; notranslate" title="">

# add the new database user
 sqlcmd -d 'master' -Q &#34;CREATE LOGIN richard1 WITH PASSWORD='icanconnect900'&#34;
 sqlcmd -d 'master' -Q &#34;EXEC sys.sp_addsrvrolemember @loginame = N'richard1', @rolename = N'sysadmin'&#34;

</pre>
<p>Take all of this and wrap it into a powershell file &#8220;.ps1&#8243;.</p>
<p>The point of this second post was to show that you could do exactly what we did in the first post programmatically as well. This is what we&#8217;ve done through a branch of our Fluent Management library which will now support IaaS. One of the reasons we&#8217;ve been very keen to integrate IaaS programmatically is because we feel that the hybrid scenarios of PaaS and IaaS are a great mix so to be able to inevitably this mixture transactional in the same way is a good goal for us.</p>
<pre class="brush: csharp; title: ; notranslate" title="">

var manager = new SubscriptionManager(TestConstants.InsidersSubscriptionId);
 manager.GetVirtualMachinesManager()
 .AddCertificateFromStore(TestConstants.ManagementThumbprintIaaS)
 .CreateVirtualMachineDeployment()
 .AddToExistingCloudServiceWithName(TestConstants.CloudServiceNameIaaS)
 .WithDeploymentType(VirtualMachineTemplates.SqlServer2012)
 .WithStorageAccountForVhds(TestConstants.StorageServiceNameIaaS)
 .WithVmOfSize(VmSize.Small)
 .Deploy();

</pre>
<p>So in one line of code we now have the equivalent of the powershell script in the first part. Note that this is a blocking call. When this returns initially a 202 Accepted response is retuned and then we continue to poll in the background using the x-ms-request-id header as we previously did with PaaS deployments. On success Fluent Management will return unblock.</p>
<p>From the code there are key messages to take away.</p>
<ol>
<li>we continue to use our management certificate with the subscription activity</li>
<li>we need to provide a storage account for the VHD datadisks</li>
<li>we can control the size of VM which is new thing for us to be able to do in code (normally the VmSize is set in .csdef but in this case we don&#8217;t have one or a package)</li>
<li>we have to have a cloud service already existing with which to add the deployment to</li>
</ol>
<p>In many of the previous posts on this blog we&#8217;ve looked at the Service Management API in the context of our wrapper Fluent Management. The new rich set of APIs that have been released for Virtual Machines make for a good set of possibilities to do everything that is easy within the CLI and Powershell right now enabled within an application.</p>
<p>Happy 4th July to all of our US friends (for yesterday!)</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Azure Fluent Management v 0.4 Released]]></title>
<link>http://blog.elastacloud.com/2012/06/02/azure-fluent-management-v-0-4-released/</link>
<pubDate>Sat, 02 Jun 2012 12:50:58 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/06/02/azure-fluent-management-v-0-4-released/</guid>
<description><![CDATA[If you haven&#8217;t tried Fluent Management yet try it now! It&#8217;s beginning to shape up into q]]></description>
<content:encoded><![CDATA[<p>If you haven&#8217;t tried Fluent Management yet try it now! It&#8217;s beginning to shape up into quite a powerful library. There are several features which are on cards for the lib between v0.4 and v0.5 most of which revolve around ServiceSystemWatchers and Upgrades but the deployment side of things is done now. We&#8217;re also going to update the Service Bus side of things to create multiple service identities with new queue creation. There are a few updates which need to be done to support rdp, ssl enablements across multiple roles instead of a single one as well as an error router which will deal with common web exceptions through a notification interface but on the whole it can do some pretty good things in a very easy to understand manner. We&#8217;ve had 187 downloads so hopefully people are using it even though we haven&#8217;t had that much feedback.</p>
<p>A common scenario we&#8217;re using it for now are as follows:</p>
<ul>
<li>Upload a package to Blob storage</li>
<li>Auto-update the configs (.cscfg, .csdef on the fly using business rules)</li>
<li>Deploy the package with 3 roles, rdp support and an autgenerated self-signed SSL/RD certificate in the name of the role</li>
<li>Create a SQL Azure instance, logins, firewall rules, single database, new admin user and populate the database</li>
<li>Add a storage account and return the keys</li>
</ul>
<p>Of course the beauty around these scenarios is that this is an all or nothing thing so we&#8217;ll have a rollback occur if there is a failure at any point. The logging support is okay at the moment to help determine the failure scenarios but it will be much better by the next v0.5 release.</p>
<p>Hope you enjoy using this. Remember this is beta and it was released to try and get feedback from the community so if you have any comments or suggestions let us know.</p>
<p>UPDATE: Added the framework this morning for watching things. It should be really easy now to drop in a watcher to keep an eye on whether someone deletes your database, database server, storage account, hosted service, deployment in staging or production etc. can lead to some very useful scenarios.</p>
<p>The only one I&#8217;ve implemented is the one that Michael Collier from Neudesic requested since I think it may be useful for a number of people but when I get time I&#8217;ll add the others because it would be nice to have a simple monitoring and supporting reference service off the back of the lib.</p>
<p>Anyway, the code from my test looks like this (it will poll every 15 seconds by default) &#8211; if you haven&#8217;t got it Azure Fluent Management from nuget:</p>
<pre class="brush: csharp; title: ; notranslate" title="">

var man = new ManualResetEvent(false);

var subscriptionManager = new SubscriptionManager(TestConstants.LwaugSubscriptionId); var manager = subscriptionManager.GetRoleStatusChangedWatcher(TestConstants.LwaugServiceName, TestConstants.LwaugRoleName,                  DeploymentSlot.Staging, TestConstants.LwaugThumbprint);

manager.RoleStatusChangeHandler += (status, oldStatus) =&#62;  {

Assert.AreNotEqual(oldStatus, status);

man.Set();

};

man.WaitOne(10000);

</pre>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Service Bus, ACS and multiple service identities]]></title>
<link>http://blog.elastacloud.com/2012/04/21/service-bus-acs-and-multiple-service-identities/</link>
<pubDate>Sat, 21 Apr 2012 11:20:58 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/04/21/service-bus-acs-and-multiple-service-identities/</guid>
<description><![CDATA[As windows Azure becomes more prolific and people begin to use key features we&#8217;ve had several]]></description>
<content:encoded><![CDATA[<p>As windows Azure becomes more prolific and people begin to use key features we&#8217;ve had several users of the service bus come to us at the user group showing us reasonably good implementations. They all have one key design flaw on production release which I wanted to write about here.</p>
<p>Good security for a website entails that you don&#8217;t send messages back to the client when they get their password wrong that tell that it was their password that was at fault. Whilst the lack of pintpoint feedback like this is not ideal one of the key considerations is not to give an attacker more information then they need to crack an account. Without precise feedback any random attack bot (is there such a term or is my star wars head just inventing stuff this morning?!) can learn details on credentials.</p>
<p>&#160;</p>
<div>
<dl>
<dt><a href="http://azurecoder.files.wordpress.com/2012/04/sb1.png"><img title="Service Bus management details" src="http://azurecoder.files.wordpress.com/2012/04/sb1.png?w=285&#038;h=220" alt="Service Bus management details" width="285" height="220" /></a></dt>
<dd>Service Bus management details</dd>
</dl>
</div>
<p>&#160;</p>
<p>One of the problem with the Service Bus is that many people begin to use it without understanding how ACS is used to protect access to it. They key idea here is that ACS is like a lockbox. As part of the setup process it creates a single &#8220;identity&#8221; which contains the information needed for any client to participate in the service bus and send and receive messages. So this identity then becomes your most important asset.</p>
<p>The problem here is that most users still don&#8217;t effectively understand the coupling mechanism between the service bus and ACS so they keep the default identity with the name &#8220;owner&#8221;. So now we&#8217;re left with breaking our pattern of good security because 50% of the information we need to know is known to an attacker &#8211; it would still be pretty hard to guess the default 256-bit symettric key though!</p>
<div id="attachment_975" class="wp-caption aligncenter" style="width: 502px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb2.png"><img class="size-full wp-image-975" title="Showing the default and owner and key" src="http://azurecoder.files.wordpress.com/2012/04/sb2.png?w=492&#038;h=180" alt="Showing the default and owner and key" width="492" height="180" /></a><p class="wp-caption-text">Showing the default and owner and key</p></div>
<p>&#160;</p>
<p>As such you may want to predicate access on groups or corporations or something that would beget a good access policy and create at least one new or multiple identities so that at least you could track usage effectively as well as revoke access to a particular messaging client.</p>
<p>In order to do this you need to follow the link to the Management Endpoint in your browser which takes you straight to the ACS for the Service Bus. Then select Service Identities. You can add another identity very easily and choose either symettric key, password or certificate-based authentication.</p>
<p>&#160;</p>
<div id="attachment_976" class="wp-caption aligncenter" style="width: 209px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb3.png"><img class="size-full wp-image-976" title="Select Service Identities from the Menu" src="http://azurecoder.files.wordpress.com/2012/04/sb3.png?w=199&#038;h=384" alt="Select Service Identities from the Menu" width="199" height="384" /></a><p class="wp-caption-text">Select Service Identities from the Menu</p></div>
<div id="attachment_978" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb5.png"><img class="size-full wp-image-978" title="Creating and editing a service identity" src="http://azurecoder.files.wordpress.com/2012/04/sb5.png?w=575&#038;h=330" alt="Creating and editing a service identity" width="575" height="330" /></a><p class="wp-caption-text">Creating and editing a service identity</p></div>
<p>&#160;</p>
<p>I&#8217;ve now removed the owner, which is the default identity and set up a new identity which can be used with clients. Of course it&#8217;s possible to automate this process through the management REST layer. Maybe this is something we can look at doing in the fluent management API.</p>
<p>&#160;</p>
<div id="attachment_977" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb4.png"><img class="size-full wp-image-977" title="Managing Multiple Identities" src="http://azurecoder.files.wordpress.com/2012/04/sb4.png?w=575&#038;h=210" alt="Managing Multiple Identities" width="575" height="210" /></a><p class="wp-caption-text">Managing Multiple Identities</p></div>
<p>&#160;</p>
<p>Anyway, should you now try and use these credentials you&#8217;ll get an UnauthorizedAccessException! The Service Bus uses a particular action to generate output claims for access to specific things you can do with the bus. These claims are Send, Listen and Manage. By default, the &#8220;owner&#8221;, has all 3 enabled. The first two are fine but the third could cause major disruption to your project which is all the more reason to change your management access &#8211; or disable programmatic access if you choose to and use the portal instead.</p>
<p>&#160;</p>
<div id="attachment_979" class="wp-caption aligncenter" style="width: 504px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb6.png"><img class="size-full wp-image-979" title="Bye-bye owner!" src="http://azurecoder.files.wordpress.com/2012/04/sb6.png?w=494&#038;h=178" alt="Bye-bye owner!" width="494" height="178" /></a><p class="wp-caption-text">Bye-bye owner!</p></div>
<div id="attachment_984" class="wp-caption aligncenter" style="width: 463px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb71.png"><img class="size-full wp-image-984" title="UnauthorizedAccessException" src="http://azurecoder.files.wordpress.com/2012/04/sb71.png?w=453&#038;h=345" alt="UnauthorizedAccessException" width="453" height="345" /></a><p class="wp-caption-text">UnauthorizedAccessException</p></div>
<p>&#160;</p>
<p>Send and Listen output claims should be sufficient for pretty much everything as long as you don&#8217;t ask the Service Bus to divulge any information (e.g. if you use QueueExists to check the validity of a queue or try and get metainformation about anything on the service bus then it will fail if you don&#8217;t have the Manage output claim).</p>
<p>Here is a screenshot showing the claims:</p>
<p>&#160;</p>
<div id="attachment_981" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb8.png"><img class="size-full wp-image-981" title="Editing and completing input -&#62; output claims" src="http://azurecoder.files.wordpress.com/2012/04/sb8.png?w=575&#038;h=394" alt="Editing and completing input -&#62; output claims" width="575" height="394" /></a><p class="wp-caption-text">Editing and completing input -&#62; output claims</p></div>
<p>&#160;</p>
<p>To add standard rule you would use the following format:</p>
<ul>
<li>Input Claim Issuer: Access Control Service</li>
<li>Input Claim Type: (Select Type) namesidentifier</li>
<li>Input Claim Value: &#60;your new identity name&#62;</li>
<li>Output Claim Type: net.windows.servicebus.action</li>
<li>Output Claim Value: Send/Listen/Manage</li>
</ul>
<p>Once you&#8217;ve created 1-3 rules depending on the rights of the identity, if you&#8217;ve created a new rule group and not added rules to the existing one then you&#8217;ll need to add this to the Relying Party Application as in the screenshot.</p>
<p>&#160;</p>
<div id="attachment_982" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/sb9.png"><img class="size-full wp-image-982" title="Adding a second rule group to a relying party application" src="http://azurecoder.files.wordpress.com/2012/04/sb9.png?w=575&#038;h=80" alt="Adding a second rule group to a relying party application" width="575" height="80" /></a><p class="wp-caption-text">Adding a second rule group to a relying party application</p></div>
<p>&#160;</p>
<p>So the moral of the story here is that ACS offers a rich model of managing identities and claims. Use this and ensure that you adhere to good application design principles, get rid of default users and don&#8217;t send these credentials to clients. Ensure that each user of the service bus subscribes to the principle of least privilege so unless they need management access don&#8217;t give it to them. It means writing your applications in a certain way to ensure that no management checks are done prior to sending and/or receiving messages but better safe than sorry!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[And v0.3.7 Fluent Management was born!]]></title>
<link>http://blog.elastacloud.com/2012/04/19/961/</link>
<pubDate>Thu, 19 Apr 2012 23:13:52 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/04/19/961/</guid>
<description><![CDATA[Okay, so I know the naming convention is pretty pants but I wanted to make another release. Version]]></description>
<content:encoded><![CDATA[<p>Okay, so I know the naming convention is pretty pants but I wanted to make another release. Version 0.4 will include a hosted service delete feature, automatic checks of hosted lists and blob container existance checks, propogation of exceptions from WebExceptions (which are currently suppressed) and enablement of Remote Desktop.</p>
<p>The roadmap for v 0.5 is about a month away but will include an orchestration engine and addition of plugins and new config settings. Remember, this library is still in beta so don&#8217;t use this in a production release until we say so!</p>
<p>Firstly we&#8217;ll review the new read infosets. This will get the current subscription information:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
 var subscriptionManager = new SubscriptionManager(TestConstants.SubscriptionId);
 var subscriptionInformation = subscriptionManager.GetSubscriptionDetailsManager()
                .AddCertificateFromStore(TestConstants.ManagementThumbprint)
                .GetSubscriptionInformation();
</pre>
<p>This will return the locations available under your subscription. Useful if your subscription is free and is pinned to a particular territory.</p>
<pre class="brush: csharp; title: ; notranslate" title="">
 var subscriptionInformation = subscriptionManager.GetSubscriptionDetailsManager()
                .AddCertificateFromStore(TestConstants.ManagementThumbprint)
                .GetSubscriberLocations();
</pre>
<p>To get a list of hosted services you can use the following:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
 var hostedService = subscriptionManager.GetDeploymentManager()
                .ForServiceInformationQuery()
                .UseExistingBuild()
                .AddCertificateFromStore(TestConstants.ManagementThumbprint)
                .GetHostedServiceList();
</pre>
<p>However, by far the most useful feature is the automatic addition of SSL to package and config. I&#8217;m a little tired now but this was not an easy thing to do and required several steps some of which I&#8217;ll share over the next few months.</p>
<pre class="brush: csharp; title: ; notranslate" title="">
var subscriptionManager = new SubscriptionManager(TestConstants.SubscriptionId);

            var deploymentManager = subscriptionManager.GetDeploymentManager();
            ((DeploymentManager)deploymentManager).AzureTaskComplete += TestConstants.TaskComplete;

            deploymentManager.ForNewDeployment(TestConstants.DeploymentName)
                .SetBuildDirectoryRoot(TestConstants.ProjectBuildRoot)
                .Rebuild()
                .EnableSslForRole(TestConstants.RoleNameHellocloudWeb)
                .UploadExistingServiceCertificate(TestConstants.ManagementThumbprint, &#34;xxxxxxx&#34;)
                .AddCertificateFromStore(TestConstants.ManagementThumbprint)
                .WithNewHostedService(TestConstants.HostedServiceName)
                .WithStorageConnectionStringName(TestConstants.ConnectionStringName)
                .AddDescription(&#34;My new hosted services&#34;)
                .AddEnvironment(DeploymentSlot.Production)
                .AddLocation(Constants.LocationNorthEurope)
                .AddParams(DeploymentParams.StartImmediately)
                .ForRole(TestConstants.RoleNameHellocloudWeb)
                .WithInstanceCount(2)
                .Go();
</pre>
<p>The above example would create a hosted service and deployment and add SSL to it. It would allow the uploading of a Service Certificate. In many ways, however, when testing the certificate might not be available so you can replace the UploadExistingServiceCertificate with this:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
.GenerateAndAddServiceCertificate(&#34;helloelastacloud.cloudapp.net&#34;)
 </pre>
<p>And this will generate the appropriate certificate. In order to actually do this the library needs to rebuild the package from source with new build definitions and cloud config. A lot of refactoring has gone on with the lib so I hope you enjoy the updates. It&#8217;s getting that time of night now where I&#8217;m sort of slumped over the keyboard and mistyping every third letter. Leave it another 10 minutes and my keyboard will be full of drool so just to say I&#8217;m happy that this is a semi-stable release and I&#8217;ll upload the new package to nuget tomorrow morning.</p>
<p>Lastly, there is some licensing information in the library which explains the terms of use. Contact us if there are any problems but it&#8217;s fairly open, commercial reditribution usage should get in touch as per the terms etc. etc.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Automating the generation of service certificates in Windows Azure]]></title>
<link>http://blog.elastacloud.com/2012/04/13/automating-the-generation-of-service-certificates-in-windows-azure/</link>
<pubDate>Fri, 13 Apr 2012 20:32:22 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/04/13/automating-the-generation-of-service-certificates-in-windows-azure/</guid>
<description><![CDATA[I was prompted to write this having seen some of the implementations of the generation of service ce]]></description>
<content:encoded><![CDATA[<p>I was prompted to write this having seen some of the implementations of the generation of service certificates online. Some poor explanations so I though I&#8217;d plug the gap. First let us cover some definitions. We interact with our subscription through a management certificate.</p>
<p>The management certificate needs to be uploaded to the subscription through the portal. This is the only function that we can&#8217;t automate. Obvious why, everybody has probably seen the chicken and the egg here already. Anyway, Microsoft have provided a .publishsettings file and Uri which eases the pain of automating this process because the fabric will instamagically update your subscription when you use your live id to login and download a publishsettings file. Y voila you have management access.</p>
<p>A service certificate is something different though. Service certificates are bound to an individual hosted service and don&#8217;t entail management of anything. They actually allow you to perform any operation which involves a certificate for that particular hosted service. Under the seams that certificate is being added to the Personal store on each of the role instances within that service.</p>
<p>Service certificates are immensely important for two essential functions:  SSL and Remote Desktop.</p>
<div id="attachment_954" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/management-portal-e28093-windows-azure-platform-windows-internet-explorer-provided-_2012-04-13_18-46-42.png"><img class="size-full wp-image-954" title="Management Portal Showing Service Certificates" src="http://azurecoder.files.wordpress.com/2012/04/management-portal-e28093-windows-azure-platform-windows-internet-explorer-provided-_2012-04-13_18-46-42.png?w=575&#038;h=211" alt="Management Portal Showing Service Certificates" width="575" height="211" /></a><p class="wp-caption-text">Management Portal Showing Service Certificates</p></div>
<p>SSL is intrinsic to the role instance since it is part of IIS which is present on each of the web roles. Remote Desktop requires a plugin but equally uses the service certificate for authentication purposes.</p>
<p>I wanted to highlight one great way of generating service certificates. There are several ways to do this but we&#8217;ll focus on a single one although we can use makecert, powershell and Microsoft provide a test app called CertificateGenerator (essentially a COM Callable Wrapper) amongst others. This way uses Bouncy Castle, a great library which is available through nuget. Simply:</p>
<div id="attachment_953" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/bouncy-castle.png"><img class="size-full wp-image-953" title="Bouncy Castle from Nuget" src="http://azurecoder.files.wordpress.com/2012/04/bouncy-castle.png?w=575&#038;h=125" alt="Bouncy Castle from Nuget" width="575" height="125" /></a><p class="wp-caption-text">Bouncy Castle from Nuget</p></div>
<p><em>&#62; Install-Package BouncyCastle</em></p>
<p>at the Package Manager Console prompt and it is installed.</p>
<p>Let&#8217;s start by determining all of our using statements:</p>
<pre class="brush: plain; title: ; notranslate" title="">
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Prng;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
</pre>
<p>And then our method signature:</p>
<pre class="brush: plain; title: ; notranslate" title="">
public static X509Certificate2 Create(string name, DateTime start, DateTime end, string userPassword, bool addtoStore = false)
</pre>
<p>In order to create our certificate as a minimum we need a name, a validity period and as we are protecting a private key we need a private key password (more on this later!). Additionally we may want to add this to a local certificate store which the System.Cryptography assembly allows us to do fairly easily.</p>
<p>We always start any asymmetric cryptographic operation with the a private-public key pair. To generate keys we can use the following:</p>
<pre class="brush: plain; title: ; notranslate" title="">
// generate a key pair using RSA
var generator = new RsaKeyPairGenerator();
// keys have to be a minimum of 2048 bits for Azure
generator.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 2048));
var cerKp = generator.GenerateKeyPair();
</pre>
<p>Two properties that an X509v3 certificate has are a serial number and a subject name (and issuer name). The representation of what this looks like is canonical so we use terms such as &#8220;Common Name&#8221; (CN) or &#8220;Organisational Unit&#8221; (OU) to define details about the party the certificate represents and who the authority is that is vouching for them.</p>
<p>To create a subject name we use the X509Name as below and to generate a serial number which is a unique reference to our certificate we generate a large random prime:</p>
<pre class="brush: plain; title: ; notranslate" title="">
// create the CN using the name passed in and create a unique serial number for the cert
var certName = new X509Name(&#34;CN=&#34; + name);
var serialNo = BigInteger.ProbablePrime(120, new Random());
</pre>
<p>After doing this we can create an X509v3CertificateGenerator object which will encapsulate and create the certificate for us:</p>
<pre class="brush: plain; title: ; notranslate" title="">
// start the generator and set CN/DN and serial number and valid period
var x509Generator = new X509V3CertificateGenerator();
x509Generator.SetSerialNumber(serialNo);
x509Generator.SetSubjectDN(certName);
x509Generator.SetIssuerDN(certName);
x509Generator.SetNotBefore(start);
x509Generator.SetNotAfter(end);
</pre>
<p>Once we&#8217;ve set the basic and essential properties we can focus on what the cert actually does:</p>
<pre class="brush: plain; title: ; notranslate" title="">
// add the server authentication key usage
var keyUsage = new KeyUsage(KeyUsage.KeyEncipherment);
x509Generator.AddExtension(X509Extensions.KeyUsage, false, keyUsage.ToAsn1Object());
var extendedKeyUsage = new ExtendedKeyUsage(new[] {KeyPurposeID.IdKPServerAuth});
x509Generator.AddExtension(X509Extensions.ExtendedKeyUsage, true, extendedKeyUsage.ToAsn1Object());
</pre>
<p>Two types of property that the certificate has are Key Usage and Extended Key Usage which tell us all about its purpose to life. It&#8217;s rasion D&#8217;etre (it&#8217;s getting that time of night where I think I can actually speak French!)</p>
<p>In this case the certificate we create will need to be able to do two things.</p>
<ol>
<li>Prove to a client that it has authority to verify the server and</li>
<li>Encrypt a key during a key exchange process</li>
</ol>
<div id="attachment_959" class="wp-caption aligncenter" style="width: 585px"><a href="http://azurecoder.files.wordpress.com/2012/04/cert.jpg"><img class="size-full wp-image-959" title="X509 Certificate with KU/EKU properties" src="http://azurecoder.files.wordpress.com/2012/04/cert.jpg?w=575&#038;h=365" alt="X509 Certificate with KU/EKU properties" width="575" height="365" /></a><p class="wp-caption-text">X509 Certificate with KU/EKU properties</p></div>
<p>Both of these are common to SSL (TLS).</p>
<p>The rest is fairly straightforward. We can set a signature algorithm. Note the use of Sha1 which by extension is the thumbprint algorithm in our certificate which is an integrity check to prove that the cert hasn&#8217;t been tampered with. It&#8217;s important to be aware that Azure will only support this thumbprint algorithm.</p>
<pre class="brush: plain; title: ; notranslate" title="">
// algorithm can only be SHA1 ??
x509Generator.SetSignatureAlgorithm(&#34;sha1WithRSA&#34;);
// Set the key pair
x509Generator.SetPublicKey(cerKp.Public);
Org.BouncyCastle.X509.X509Certificate certificate = x509Generator.Generate(cerKp.Private);
</pre>
<p>When this is done we will want to do common tasks with this and generally end up with our familiar X509Certificate2 exposed by the System.Cryptography.X509Certificates namespace and used in all common crypto tasks. Well the means to do this are fairly easy and provided by Bouncy Castle.</p>
<pre class="brush: plain; title: ; notranslate" title="">
// export the certificate bytes
byte[] certStream = DotNetUtilities.ToX509Certificate(certificate).Export(X509ContentType.Pkcs12, userPassword);
</pre>
<p>Also not the use of PKCS#12 (Public Key Cryptographic Standard) which defines the private and uses a form of password-based encryption (PBE) to ensure that only with the password can I access the private key. As we can just use our password and now treat the X509Certificate2 class as a container for our cert with private key.</p>
<pre class="brush: plain; title: ; notranslate" title="">
var cert = new X509Certificate2(certStream, userPassword);
</pre>
<p>Adding the certificate to the store is fairly easy. You would first start by opening the store you want to engage:</p>
<pre class="brush: plain; title: ; notranslate" title="">
///
&#60;summary&#62; /// Returns the My LocalMachine store
/// &#60;/summary&#62;
private static X509Store ReturnStore()
{
  var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
  store.Open(OpenFlags.OpenExistingOnly &#124; OpenFlags.ReadWrite);
  return store;
}
</pre>
<p>After that all it takes is a bit addition using your X509Certificate2 object and then closing the store to release the handle.</p>
<p>One thing to note is that this certificate is self-signed. This doesn&#8217;t have to be the case; I could easily build a PKI here using this simple technique. Of course the code would like slightly differently (maybe we&#8217;ll cover this in a follow-up post) as would the issuer name.</p>
<p>I thought I&#8217;d write this post to offer readers another way to generate certificates. Six years ago when I was involved as the CTO in a startup that produced epassport software I would get immersed into the underlying details of these standards. Most of the time we would use OpenSSL which is an absolute gem of a library but Bouncy Castle comes a pretty close second in terms of functionality and upkeep. Have a play and enjoy!</p>
<p>The next generation of the Azure Fluent Management library uses the above code in order to automate the setup of SSL for a webrole and remote desktop. There has been a lot of refactoring on this recently to help us streamline deployments and we hope to release this in the coming week.</p>
<p>Happy trails!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Agile, Continuous Integration and Windows Azure]]></title>
<link>http://blog.elastacloud.com/2012/04/11/agile-continuous-integration-and-windows-azure/</link>
<pubDate>Wed, 11 Apr 2012 11:23:37 +0000</pubDate>
<dc:creator>azurecoder</dc:creator>
<guid>http://blog.elastacloud.com/2012/04/11/agile-continuous-integration-and-windows-azure/</guid>
<description><![CDATA[Recently our friends at Blush Packages raised the bar with a great implementation of TeamCity build]]></description>
<content:encoded><![CDATA[<p>Recently our friends at Blush Packages raised the bar with a great implementation of TeamCity build for an Azure project they&#8217;re consulting on. We will be running an intermediate day course on Azure for the Enterprise which will comprise of how to make an enterprise ready application. The course will be delivered at the behest of Microsoft who are sponsors. It will probably take place within the next four weeks and we will have the following agenda:</p>
<ul>
<li>Introduction to TFS Preview: Using TFS Preview to build an agile project in Azure</li>
<li>Development of a sample application using web/worker roles</li>
<li>Adding security using SQL Azure and Membership</li>
<li>Integration of Diagnostics capture for trace, exceptions and logs</li>
<li>Resilience and autoscaling with Enterprise Application Blocks</li>
<li>Automating common deployment tasks with Cerebrata Powershell CmdLets</li>
<li>Using mstest, msbuild and TFS to make a CI server</li>
</ul>
<p>Remember this is not an advanced course; it&#8217;s simply addressing the problem of how to build and deploy a windows azure application and use enterprise methodologies and deployment and build processes to deliver cloud ready projects in the same way as you would traditional server projects.</p>
<p>Feel free to leave a comment here if you&#8217;re interested in attending. For updates on this follow @ukwaug or @azurecoder</p>
]]></content:encoded>
</item>

</channel>
</rss>
