Friday, October 23, 2015

ADFS : Differences across versions

This is for Active Directory Federation Services / ADFS / "AD FS".



2008 R2 (ADFS v2.0)
2012 (ADFS v2.1)
2012 R2 (ADFS v3.0)
2016 vNext (ADFS v4.0?)





Runs on IIS
Y
Y
N
N





.NET
3.5
Microsoft.Identity
4.5
System.Identity
4.5
System.Identity
4.6?
System.Identity





Authenticate against
AD
AD
AD
AD
LDAP v3
SQL Server





WS-Federation
Y
SAML 1.1 token
Y
Y
Y





SAML 2.0
Y
SAML 2.0 token
Y
Y
Y





OpenID Connect support
N
N
N
Y
Plus OpenIDConnect Discovery





OAuth 2.0 support
N
JWT token
N
JWT token
Y
Authorisation Code Grant only
JWT token
Y
All profiles
JWT token





Device registration
N
N
Y
Y





Password change support
N
N
Y
Y





Application branding with per RP customisation
N
N
N
Y





Enable delegation for service admin.
N
N
N
Y





Act as a certificate authority
N
N
N
Y


 Enjoy!

Wednesday, October 21, 2015

ADFS : Customising ADFS functionality

This post is NOT about customising the look and feel - it's about customising what ADFS actually does.

ADFS 2.0 was built on IIS and was basically a web site so you had the opportunity to adapt the web pages and change some of the flow.

ADFS 3.0 does not use IIS - it's built on top of http.sys so there are no web pages to alter.

Essentially, it's locked down and there's no way in.

So if you need to alter the flow in some way, what can you do?

I've been involved in two projects recently where this was required.

For a WS-Federation project, I added thinktecture's identityserver into the pipeline. This can be both an IDP and a RP. Essentially, it was a proxy.

So RP <--> IdSrv2 <--> ADFS.

It's open source so you can alter the code. It wasn't used for local authentication but rather for pass-through.

You can capture the request on both the up and down stream tracks and alter as required.

For a SAML-P project, I added ComponentSpaces's SAML stack into the pipeline. This can be both an IDP and a SP. Essentially, it was a proxy. (Note this is commercial).

So SP <--> ComponentSpace <--> ADFS.

It's not open source but they provide both IDP and SP examples. You can pretty much merge the two examples together. It wasn't used for local authentication but rather for pass-through.

You can capture the request on both the up and down stream tracks and alter as required.

Enjoy!

Monday, October 19, 2015

ADFS : Metadata signing

ADFS and pretty much all half-decent IDP's use metadata to transfer stuff like endpoints, bindings, certificates etc.

Sometimes you need to change some part of the metadata e.g. ADFS won't accept any endpoints that aren't https.

So to be able to import the metadata, you have to edit it.

However, if the metadata is signed, it will throw an error.

This is because the signature is a hash value of the contents so obviously if you change the contents you change the hash value.

What to do?

Note: Below is at your own risk as there may be security implications.

Metadata stands on its own. There are no other files involved, links to web collateral etc. So it stands to reason that if the metadata is signed, the fact that it is signed must be recorded somewhere within the metadata.

And in fact it is.

It use the "ds:Signature", "ds:SignedInfo", "ds:SignatureValue" etc. constructs.

So to remove the signature protection, simply delete the entire "ds:Signature" construct, Now you can change anything you want. And by extension so can anybody else!

To repeat: Use at your own risk as there may be security implications.

Enjoy!


Friday, October 16, 2015

WIF : Wrappers around protocols

Put together this diagram:




So what does this show:

WIF = WS-Fed
OWIN = WS-Fed, OpenID Connect, OAuth

There is no official Microsoft support for SAML-P (P for protocol). There are open source libraries and commercial stacks - refer : SAML : SAML connectivity / toolkit.

Just to repeat - WIF and OWIN are not protocols - they are wrappers around protocols.

Enjoy!

Tuesday, October 13, 2015

ADFS : Beware IIS and ADFS

Just read this post:

2012R2 AD FS WAP proxy problem

This was to do with installing WAP with Active Directory Federation Service and getting:

"Unable to retrieve proxy configuration data from the Federation Server." 

The interesting part is the piece at the end:

"Turns out certificate binding precedence is the culprit.  While IIS is not required for 2012 R2 ADFS roles anymore, it can actually get in the way if it is on the same machine.  Binding cert to default web site in IIS will place an ip:port entry into sslcert bindings, which has a higher precedence than service:port entries that ADFS sets up.  Since the IIS entry has no Ctl Store Name, the WAP certificate is placed in a store that is filtered out when ADFS checks for its presence.

Type "netsh http show sslcert" in a terminal on your ADFS machines and look for entries higher on the list than your ADFS service name entries.  If those don't have Ctl Store Name of AdfsTrustedDevices and they can resolve to your ADFS service, the install will fail."

The point for me is that sometimes I'm having problems with ADFS in terms of connectivity. The metadata address and the IDPInitiatedSignOn only work when you have a half-decent install. Ping is disabled by default. So I install IIS just so I can check connectivity

e.g. https://server.domain.

and you should get the IIS splash screen.

So this is something to be aware of.

On a 2012 R2 server with no IIS:

PS C:\> netsh http show sslcert

SSL Certificate bindings:
-------------------------

    Hostname:port                :server.domain:443
    Certificate Hash             : e6a5e9d2358f158ae4e98f753a5cd2bcfda12005
    Application ID               : {5d89a20c-beab-4389-9447-324788eb944a}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : AdfsTrustedDevices
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled

    Hostname:port                : localhost:443
    Certificate Hash             : e6a5e9d2358f158ae4e98f753a5cd2bcfda12005
    Application ID               : {5d89a20c-beab-4389-9447-324788eb944a}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : AdfsTrustedDevices
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled

    Hostname:port                : server.domain:49443
    Certificate Hash             : e6a5e9d2358f158ae4e98f753a5cd2bcfda12005
    Application ID               : {5d89a20c-beab-4389-9447-324788eb944a}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : (null)
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Enabled  

On a 2016 server with IIS:

PS C:\> netsh http show sslcert

SSL Certificate bindings:
-------------------------

    IP:port                      : 0.0.0.0:443
    Certificate Hash             : 51b70e988101c789769c9cd9487c29e88ea7225e
    Application ID               : {4dc3e181-e14b-4a21-b022-59fc669b0914}
    Certificate Store Name       : My
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : (null)
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled
    Reject Connections           : Disabled

    IP:port                      : 0.0.0.0:5986
    Certificate Hash             : bf7db9570b805aa6771be18154e60e4decb295db
    Application ID               : {afebb9ad-9b97-4a91-9ab5-daf4d59122f6}
    Certificate Store Name       : (null)
    Verify Client Certificate Revocation : Disabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Disabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : (null)
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled
    Reject Connections           : Disabled

    Hostname:port                : server.domain:443
    Certificate Hash             : 26ea2faabc7764a9bea7f85db6e931b559eff126
    Application ID               : {5d89a20c-beab-4389-9447-324788eb944a}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : AdfsTrustedDevices
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled
    Reject Connections           : Disabled

    Hostname:port                : localhost:443
    Certificate Hash             : 26ea2faabc7764a9bea7f85db6e931b559eff126
    Application ID               : {5d89a20c-beab-4389-9447-324788eb944a}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : AdfsTrustedDevices
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled
    Reject Connections           : Disabled

    Hostname:port                : server.domain:49443
    Certificate Hash             : 26ea2faabc7764a9bea7f85db6e931b559eff126
    Application ID               : {5d89a20c-beab-4389-9447-324788eb944a}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : (null)
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Enabled
    Reject Connections           : Disabled

Note that I didn't have this problem on this installation. I suspect it's because "and they can resolve to your ADFS service." and the IP address 0.0.0.0 ain't going anywhere!

 Enjoy!

Monday, October 12, 2015

ADFS : SAML 2.0 token

This question came up during a discussion with a customer.

They wanted Active Directory Federation Services (AD FS) to deliver a SAML 2.0 token.

Recall that ADFS delivers a SAML 1.1 token for WS-Fed and a SAML 2.0 token for SAML-P 2.0.

The easiest way is simply to configure the connection to use SAML-P 2.0 (P BTW for protocol).

Simply provide ADFS with metadata for a SAML-P connection.

If you can't do that, you can convert the token by using Azure ACS or by using thinktecture's identityserver as an intermediate step. Both allow you to configure the outbound token type.

While on the subject, did you know that ADFS on Server 2012 R2 (ADFS 3) can deliver JWT tokens for WS-Fed?

Refer : JSON Web Token (JWT) support in ADFS.

Enjoy!

AAD : Integrating with a custom SAML application as a SP

Most of the applications you want to integrate with Azure Active Directory (AAD) can be found in the Gallery. At the time of writing there's about 2,500 of them but the number just keeps increasing.

The big guns are there e.g. Salesforce and Workday and good to see Xero (from NZ) is there.

But what if your SAML application is not there?

Then you have to do it manually.

I've used the MvcExampleServiceProvider from ComponentSpace as the SP. This is a really good SAML library and it comes with heaps of examples that you can use OOTB.

In the Azure Portal - Active Directory - Applications - Add (at the bottom).

Select "Add an Application from the Gallery"


Select "Custom".

Give your application a name and then the click the Tick image.

Click "Configure single sign-on".

Select "Microsoft Azure AD Single Sign-On". Next


The Issuer is the URL of your application.

The "Reply URL" is:

http://xxx/MvcExampleServiceProvider/SAML/AssertionConsumerService

where "xxx" is the URL of my test box where the application is deployed (essentially localhost).


Note that my application is called "ComponentSpace".

Now copy these values into the saml.config.

"Issuer URL" goes on the first line and the sign-on / sign-off go into the last two lines.

My saml.config entry: 

&lt;!-- My Azure AD -->
  &lt;PartnerIdentityProvider Name="https://sts.windows.net/00...79/"
            SignLogoutRequest="true"
            WantSAMLResponseSigned="false"
            WantAssertionSigned="true"
            WantLogoutResponseSigned="true"
            UseEmbeddedCertificate="true"
            ClockSkew="00:03:00"
            SingleSignOnServiceUrl="https://login.windows.net/0...2/saml2"
            SingleLogoutServiceUrl="https://login.windows.net/0...2/saml2"/>  
 
Also remember the web.config change:

&lt;add key="PartnerIdP" value="https://sts.windows.net/00...79/"/
/>


Now run the application.

You should see:
Click the SSO link.

That should take you off the the Azure AD login page where you then authenticate and then the list of claims should be displayed.



If you use the SAML Tracer plugin to Firefox, you can see the actual SAML packets.

&lt;samlp:AuthnRequest ID="_95ff361a-61cb-4bf9-a5e7-529239ebdbb9"
  Version="2.0"
  IssueInstant="2015-10-11T19:08:38.045Z"
  Destination="https://login.windows.net/00...79/saml2"
  ForceAuthn="false"
  IsPassive="false"
  ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
  AssertionConsumerServiceURL="http://xxx/MvcExampleServiceProvider/SAML/
            AssertionConsumerService"
            xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
            >
  &lt;saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" 
  >http://localhost/MvcExampleServiceProvider&lt;/saml:Issuer>
  &lt;samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:
            unspecified"
            AllowCreate="true"
            />
&lt;/samlp:AuthnRequest>

Note that the AssertionConsumerServiceURL is what goes into the ReplyURL in the "Configure App Settings" above and the Issuer is what goes into the "Issuer URL" box.

Enjoy!

Thursday, October 08, 2015

AAD : The OpenID Connect / OAuth claims

There seems to be a lot of confusion regarding the claims delivered from Azure AD when you use the OWIN OpenID Connect plumbing.

I used the Github "WebApp-OpenIDConnect-DotNet" sample.

After authentication, I got back:


Notice that the top part of the claims follow the OAuth pattern e.g.

aud = audience
iss   = issuer
iat    = issued at

etc.

The bottom half (and there are others that didn't fit into the image) are the kind of claims that you get with claims-based identity e.g. the kind you get if you use the older WIF wrapper.

This isn't strictly OAuth but it does provide a way to "augment" the somewhat sparse OAuth claims set.

Also note that you do not get Roles OOTB.

To do this you need to change the AAD Application manifest.

Refer:

 Azure Active Directory Part 4: Group Claims

Or you could just use the good, old Azure AD Graph API.

Enjoy!

Wednesday, October 07, 2015

ADFS : OAuth on Server 2016 TP3

Continuing the saga of OpenID Connect / OAuth on TP3. (Refer previous posts for TP2).

Vittorio blogged on:

OpenId Connect Web Sign On with ADFS in Windows Server 2016 TP3

Securing a Web API with ADFS on WS2012 R2 Got Even Easier

and this is a mix and match of both.

I didn't create a VM on my PC - I ran one up on Azure using the pre-configured TP3 sample from the Gallery. The steps are the same as described except that in Azure you need to enable the http and https endpoints. That catches me every time :-)

I used the code from the second blog entry with the new OAuth wizard from the first one.


RP now have an new entry "Edit Access Control Policy" which displays the screen above. Note I have allowed access to everyone.

Problem is - it doesn't work. I kept getting this error.

MSIS9321: Received invalid OAuth request. The client 'GUID' is forbidden to access the resource 

Pulled my hair out over this one. And then I had another look at Vittorio's blog above and noticed that he had done this via PowerShell.

He has this line:

-IssuanceAuthorizationRules ‘=> issue(Type = “http://schemas.microsoft.com/authorization/claims/permit”, Value = “true”);’

OK - so I'll use PowerShell instead of the wizard to create the RP.

Now the wizard shows:


i.e. the "old" way. And suddenly, that part worked.

Now Vittorio's blog talked about generating a secret key - which he doesn't seem to use in the sample?

I tried everything I could think off on this page:


Nothing I did seemed to work.

I kept getting:

MSIS9267: No Client credentials found in the request. Client 'GUID' is configured as a confidential client.

No idea what to do here? And there doesn't seem to be any relevant documentation.

I noted that in Vittorio's first blog post post, he actually just accesses the ADFS Discovery Doc i.e. the address of your ADFS OpenID Connect discovery document – the issuer metadata in OpenId Connect. I got this sample working. However, he didn't actually use the OAuth flow itself.

Also there is a menu item for "Scope Descriptions" but nothing to map these to an OAuth client i.e. I only want this client to accept these scopes.

But having said all that, I really enjoy reading Vittorio's posts. He's the only one blogging on this at the moment.

BTW, looking forward to his new book - Modern Authentication with Active Directory for Web Applications  which I have pre-ordered!

To be continued ...

Enjoy!




Friday, October 02, 2015

Speaking - some interesting ideas

I speak at various software gatherings.

Public speaking is hard - public speaking about technical subjects is even harder

These talks about being a better speaker really resonated with me:

James Whittaker - The Art of Stage Presence

James Whittaker and Michelle Dickinson - How to rock the stage - public speaking and presentation skills you can master 

Enjoy!

Thursday, October 01, 2015

Misc : Invest in yourself

aka "Make yourself more awesome".

I watched this presentation from Ignite NZ 2015:

Career Path Control

There were a number of things here that totally resonated with me.

And then I saw:

How to Be Awesome

OK - you don't have to be as "batshit insane" (watch the video) as this but it's an interesting approach.

And then I started to think about how I approached this.

First of all I started reading blogs. I use FeedDemon as a RSS reader and I currently have about 180 feeds - mainly in the Microsoft / Azure / Identity space.

I flick through them every morning and read the ones I find more interesting.

How do I find them? I'm doing something, run into a problem, Google and then I find a good answer on a blog and then I take a stroll around other articles in the blog. If it's stuff I may find useful, I add it to my feed. Essentially, people who write good blog posts tend to keep on doing this and I want to know about them.

Sadly, I find in interviews that very few people do this. But it's the main reason:
  • I know more than most people around here
  • I'm more informed
  • I'm the one who gets the news first and then tells other people
All of these do wonders for your reputation.

The other thing I do is to be active on Forums.

I'm in the top 2% on stackoverflow and I also help out on some of the MSDN forums.

The first time I attempted to answer a question on stackoverflow I just about wet myself. I imagined a deluge of criticism but actually all I got was two up votes. So then I started answering more and more and my reputation grew and grew. I try and answer at least one question a day. Basically, I have made my own little niche and recently got my adfs badge.

There's a Chinese saying "A journey of a thousand miles starts with the first step".

People ask "How do I get into stackoverflow? All the questions have been answered by people way smarter than me?".

My advice is always the same - there's over 10 million questions there and most have answers. Find a good question where the answers pretty much suck and write a better one.

And keep doing that. And that will give you the confidence to be the one to answer a question first. Don't be despondent if it takes a while to get an up vote. You''l find that you mainly work in a small group of tags. Start checking those tags every day. Each tag has a RSS feed so I get all the new questions in FeedDemon. And then I answer them.

No - I don't know all the answers. Actually, I rarely know the complete answer. But I research the question. And by doing that, I learn more. So it becomes a self-fulfilling prophecy. And if I find something I think others will find useful, I expand it into a blog post on my blog.

Which is a nice segue into my next point. Start writing a blog. Blog about how you solved a problem. Blog about a cool presentation you watched. If there's a stackoverflow question that keeps occurring, write a really comprehensive blog post and then link it plus a summary in your stackoverflow answer.

You also need to cough up some hard cash, Buy some books or e-books around your particular area and read them. Get a Pluralsight subscription. Buy some tools e.g. ReSharper. I work in the Identity area so there's a lot of SAML-P (P for Protocol) and there's no Microsoft client side stack for this. So I bought one (ComponentSpace) just so I could research SAML, do some PoC, write some of these blog entries etc.

Basically, just do it!

So there you have a number of different approaches with the same outcome.

Choose the one that works for you and make yourself more awesome.

Enjoy!