Thursday, April 29, 2010

How to set a host header on an SSL binding in IIS7

How to set a host header on an SSL binding in IIS7


If you google for this you'll see alot of answers, but none of them seemed production-ready or correct.
Situation: 

  • You have a Windows 2008 web server that is hosting multiple sites on different IP addresses. 
  • You want/need to return the site name rather than the box name in a WSDL call to one of your web services.
  • You may have multiple SSL certs installed on your server, for each site (i.e. VeriSign certs bound to the domain name of the site). 



Every example I looked was for some other situation, typically a developer's PC using self-generated SSL certs, and "*" is the IP address of the site, but we don't roll like that.
Also, they usually added a binding which works if you don't care which SSL cert you're using, but again, we don't roll like that. We want to edit an existing https binding so we know it's using the right SSL cert, not add a new binding. 



  1. Set up a plain-jane https binding on your site with the right ssl cert. Hostheader is probably grayed out, don't worry about it.
  2. Navigate to the C:\Windows\System32\inetsrv folder in a command window. 
  3. Run this command line - replace everything in #'s with your value:
appcmd set site /site.name: #SiteName# /bindings.[protocol='https',bindingInformation='#IPAddress#:443:'].bindingInformation:#IPAddress#:443:#HostHeader.YouWant.com#


example:
appcmd set site /site.name: Intranet /bindings.[protocol='https',bindingInformation='10.12.1.10:443:'].bindingInformation:10.12.1.10:443:Intranet.MyCompany.com


You may need to recycle IIS for the binding to correctly show up or work, but calling your service via https should now correctly return the host header rather than the server name!

Thursday, March 25, 2010

Computer Forensics: The Impact of Electronic Evidence on Modern Corporate Investigations

I attended a 2-hour lunch & learn hosted by the The Business Bank & RJ Ahmann Company at the Golden Valley Country Club, titled “Computer Forensics: The Impact of Electronic Evidence on Modern Corporate Investigations”. We ate while 3 speakers talked. Mark Lanterman was the last and primary speaker - I didn't catch the first two speaker's but they did excellent jobs. Mark is the CTO of a company called "Computer Forensic Services", a pretty high-end firm brought in by plaintiffs, defendants and the court system in general to figure out electronic evidence. His recent most high-profile cases have been Denny Hecker, Tom Petters and Paul McCartney's divorce. 

The initial speaker worked for The Business Bank and talked about banking/e-commerce fraud and what the e-commerce field is doing about it. 

Since you all love write-ups, here's some cleaned up notes and some observations of mine on the talks - some tentative best practices being put into place by the industry. Since we run an e-commerce platform ourselves, it behooves us to take a look at what the trends are, where our gaps are and maybe where we want to go ourselves. 

He primarily spoke regarding people who have admin accounts with their companies financial institution, or people with the role of orderers in an e-commerce platform.
 

1)    When a client’s admin account creates additional accounts, the account is held pending until a separate confirmation is made. They said it’s the hottest source of fraud right now – an admin’s account gets hacked, and the only thing the hackers do is create additional orderer accounts, and do their fraud from the fake orderer accounts. If it’s done properly, you never catch on that an admin’s account has been compromised (or which one), so they can keep doing it and doing it and doing it.
2)    As a result, have admin accounts password expiration be much faster than a normal user. They even referenced daily/every login expiration they have implemented. If the password changes every time the account it used, it makes the account harder to keep compromised and/or resell on the black market. It’s better to have less complex passwords (to keep users OK with 1-day expirations) then to have super-complex passwords that never expire.
3)    When activities of an orderer are outside the norm, insert challenge questions into the web page they have to answer before they can continue. If they can’t answer them, their account is locked until they call in.
4)    Geotracking (IP) restrictions on orderer/admin logins.
5)    Orderers/admins select a background watermark picture when their account is first created/logged into. This background watermark ensures they are in the “real” website when ordering/doing admin tasks.
6)    Issue RSA token fobs for admin & orderer accounts. It’s cheaper than a single fraud investigation. Usually you can charge the fob to the client and they are happy paying for it.

Corporate-wise:
1)    This may sound draconian, but no file attachments in (externally bound) emails. None. Email is not secure. Secure email is still not secure. No file attachments, no documents, period.
2)    If you need to share files, use an external service. They threw out “ShareDefender” as an example, for (casual) secure file transmission between you & clients.

Mark Lanterman gave the longest talk, and he mainly used "warstories" to illustrate where computer forensics have gone, and the role corporations play there.

1)    Deleting evidence highlights what needs to be looked at by investigators. You can’t find a needle in a haystack but you can often see where the needle was by the missing hole, and then you know where to start looking.
2)    In the last couple years, for the first time ever in Minnesota, plaintiffs have been sanctioned for “evidence spoliation”.
3)    Evidence collected for one court case has led to many other cases. I.e. two executives sue each other and the 3rd party court appointed forensic investigators uncover internal fraud from IT purchasing, etc.
4)    Give out rich/smart devices to employees; they are much easier to monitor and collect much richer evidence. They named the iPhone as top of the list as greatest un-intentioned evidence collector on employees.
5)    Even if the corporation didn’t do the theft, if an employee brings IN illegally obtained data/software and uses it, or forwards it on for other departments to use, the corporation can and will be help liable in a court of law. This happened in the Pioneer Press vs Star Tribune court case a couple years ago. You cannot let new employees bring in shady data, shady software or shady devices. You will be held liable for their use. The Star Tribune was fined & sanctioned for this, they also had to pay Pioneer Press’s complete court costs and all expert testimony fees.

That last point is highly relevant to your employee onboarding process. There is absolutely no allowance to bring in home laptops, home software, USB drives from home, nothing. You have to actively prevent it, not just say “hey guys don’t bring in your favorite software from home, or the client list from your last place of work”. They are literally exposing your entire company to successful litigation & sanctions.

-KellyS

Friday, February 5, 2010

Web.config inheritance madness!

We’re slowly migrating to Server 2008/IIS 7, and we hit on a curious issue the other day. We have a marketing "subsite” that’s incredibly basic – think a handful of .html and .asp pages -  in the same domain space as our flagship asp.net application, just taking up an isolated subfolder (and I actually use a virtual directory, because there’s no good reason to physically host one project inside another project, let alone an html/asp project inside a .net 3.5 project where you have two totally disparate groups making changes). Other than in Production nobody makes a habit of hitting the marketing site. So when a break-fix for one of the few pieces of functionality it has showed up, Development wasn’t able to pull up the marketing subsite in Test. They got this instead:


Server Error in '/Child' Application.




Could not load file or assembly 'Super.Awesome.v3.3, Version=3.3.2.0, Culture=neutral, PublicKeyToken=abc123youandme' or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Super.Awesome.v3.3, Version=3.3.2.0, Culture=neutral, PublicKeyToken=abc123youandme' or one of its dependencies. The system cannot find the file specified.


The assembly that whacked us is an http module used by the parent asp.net website, referenced in the parent folder’s web.config in httpModules and system.webServer modules. IIS 7 has some great inheritance features, but they never seem to work when you want them to (MSEntLib database connection strings) and work when you don’t want them to (referenced modules).

Googling around, there are a few solutions, but the one that seems to work best is the one I didn’t like at all, initially. They want you to modify the web.config of the parent application to stop inheritance. I’d rather modify the child application to block inheritance. MS’s method seems backwards to me, more of a security risk and a hinderance than a help. If you’re on a locked down server farm (say, rented web space at a 3rd party co-location facility), anyone with physical rights above your folder can make you inherit whatever you don’t explicitly call out. They could write a http, network or file stream logger that steals logins and passwords, for instance. Securing your site via https wouldn’t help because they would be on the inside of the protection. And you wouldn’t be able to do anything about it; you wouldn’t even know what you were inheriting.

Alright, soap box time over. Here’s the simplest way to block web.config section inheritances downstream:
Insert
<location path="." inheritInChildApplications="false">

and
</location>
Around the section you want to stop child inheritance for.

I used system.web & system.webServer in this example, as that’s where extension mapping modules seem to be loaded most commonly.

<?xml version="1.0"?>
[…]
  <configuration>

    <location path="." inheritInChildApplications="false">
      <system.web>
      […]
        <httpModules>
          <add type="SuperAwesome.HttpHandlerModule, Super.Awesome.v3.3, Version=3.3.2.0, Culture=neutral, PublicKeyToken=abc123youandme" name="SuperAwesomeHttpHandlerModule" />
        </httpModules>
      </system.web>
    </location>

  […]
    <location path="." inheritInChildApplications="false">
      <system.webServer>
        <modules>
          <add type="SuperAwesome.ASPxHttpHandlerModule, Super.Awesome.v3.3, Version=3.3.2.0, Culture=neutral, PublicKeyToken=abc123youandme" name="SuperAwesomeHttpHandlerModule" />
        </modules>
      </system.webServer>

    </location>
  </configuration>

Not the way I would have handled this (to repeat, I would have had the child web.config be able to block inheritance) but it could be worse.

Wednesday, December 23, 2009

WCF endpoint over https = no wsdl response?

We've had a torturous time getting a client connecting to an externally exposed (http) WCF endpoint. The biggest "fix" was enabling rich error reporting which sped up troubleshooting incredibly. To enable the real error to come through to your client consuming your endpoint (this probably isn't a great Production setting, but it's invaluable in Test), add this to your endpoint behavior:

<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>

So we get out of our sandbox environment and get closer to production, and the client starts reporting they can't add our almost-production-but-not-quite endpoint as a service reference. We pick at it and we're seeing errors like this:

The document at the url https://sanitized/sanitized.svc was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'https://sanitized/sanitized.svc' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'DISCO Document' is 'Discovery document at the URL https://sanitized/sanitized.svc?disco could not be found.'.
- The document format is not recognized.

(etc etc)

It turned out if you called https://sanitized/sanitized.svc?wsdl via your browser, you didn't get a wsdl response. You got the regular "You have created a service." front page. That's what the error message from above is actually saying - it was expecting a text wsdl response and it got a nice html Hello World page from your service.

With that clue, our lead dev on this tracked it down quickly - you have to enable https on the endpoint behavior. We had already set the Security from None to Transport at an earlier point when we had the client go over SSL, but it wasn't enough apparently for this service.
I set the endpoint behavior to this:

<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>

and things got much better.

Strong Naming Assemblies in MSBuild

For a few years, it's been requested our core dll's be strongly named so they can be invoked by 3rd party tools. It's always been a bigger effort (we thought) then the payback so we kept putting it off. Now we need them strongly named so they can be used by say, SSIS.

I spent a ton of time on this just going in circles, and when I actually got it working it was pretty simple. You can strong name your assemblies many ways, but two stand out.
First off, I had problem after problem using the pkcs#12 key I generated using OpenSSL for various tasks (such as signing the manifest for a ClickOnce install, another MS technology). Eventually I read that Microsoft’s strong naming algorithm is just too tight on unnamed standards, and it’s pretty common to get stuck in the endless “Import Key” popup during a manual build, which I did. The fallback is to just generate a key using sn.exe, which I ultimately did.

Using sn.exe to generate a strong naming key is simple, if you’re not concerned about key security. We’re not a shrink-wrapped software place and we have tight controls about the migration of compiled code so I wasn’t concerned about that.

On your build server just do the following out of the bin folder of the appropriate Windows SDK you have installed:

sn -k CompanyBuildKey.snk

and now you have a MS-compliant strong naming key.

The first way to strong name assemblies is to do it in the msbuild script, at compile time.
A good practices is to copy the key to the C:\Program Files\MSBuild folder on the build server, and then you can reference it like this in your msbuild scripts:

$(MSBuildExtensionsPath)\CompanyBuildKey.snk

In your msbuild file on your build server change the following sample line from this:

<MSBuild
Projects="@(ProjectList)"
Properties="Configuration=$(Configuration)"
Targets="Build" />

to this:

<MSBuild
Projects="@(ProjectList)"
Properties="Configuration=$(Configuration);SignAssembly=true;DelaySign=false;AssemblyOriginatorKeyFile=$(MSBuildExtensionsPath)\CompanyBuildKey.snk" Targets="Build" />

This worked fairly well, but it started to generate two worlds – the developers are all unsigned but the build server is signing everything. If a developer wants to use compiled dll’s as references in another project, they can run into issues mixing strong (from the build server) and non-strong dll’s – a strongly named dll cannot call a non-strongly named dll.

So the second method is probably for the best, as it puts everyone on the same page.

Second method:

Move the CompanyBuildKey.snk into a neutral reference. If you have a common library folder in source control that the build server & developers all use, this is a good spot for it.

Move your strong name compiling into each project file and out of the msbuild script.
Add this to each project file:

<AssemblyOriginatorKeyFile>\Common\Folder\For\All\CompanyBuildKey.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>

I hate to put this out without a clean followup, but I can’t do the bulk of the strong naming I need to do for another couple weeks. I’ll try to do a follow-up post on how that works out.

Thursday, December 17, 2009

Chained SSL + Java or Smartphone = Not Trusted?

For years we’ve seen our partners that use Java servers, particularly Sun servers, have to manually retrust our VeriSign chained SSL certs every time we had to renew them. The serial number would change (or something) and we’d go from trusted back to untrusted. We’ve also noticed some smartphones also don’t seem to trust our certs either. A year ago I installed an intermediate CA cert to get a clean Mac+Safari machine to trust our site without a popup, but Java servers & smartphones continued to have initial trust issues.

A typical error from a client with Java servers would be something along the lines of this:

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.Validator Exception: PKIX path building failed: sun.security.provider.certpath.SunCertPath BuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1 591)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Clien tHandshaker.java:1035)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHa ndshaker.java:124)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:5 16)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.jav

I put a resolution in place yesterday, it turns out that this is a pretty common problem with consumers of VeriSign chained certs.

VeriSign has a java applet SSL Cert “installation checker” that walks your certification path and looks for gaps in your chain. You can find that applet here:

https://knowledge.verisign.com/support/ssl-certificates-support/index?page=content&id=AR1130

To run the applet you’ll need to install the Java JRE runtime if you don’t already have it, it just takes a min, if can be found here:

http://www.java.com/en/download/manual.jsp

So run the applet, point it at your externally accessible domain, and have it crawl your cert chain. If it finds a gap it will tell you, and if you’re using VeriSign certs above and below the gap it should even give you the public key you’ll need to import.

VeriSign changed their chained cert public key in May of 2009, so if you have a new cert since then you’ll need the latest chained key. The applet correctly identified that for us and pointed me to the newest key automatically.

We have our VeriSign certs loaded on the F5 load balancers, and we’re on version 9 of the OS, which makes chained cert key installation a snap.

  1. Import the public key as an SSL cert on the F5.
  2. Edit your client-facing SSL Cert “Profile”.
  3. Go into Advanced Configuration.
  4. Enable “Chain” and select the chained public key that you installed.

It takes effect immediately on all virtual servers using that Client SSL profile.

And now Java/Sun shops will trust your chained cert automatically, and the non-Windows based smartphones (the majority of them) should now trust your website without question!