Certificate References in Configuration

When you are doing STS work (that goes beyond the hardcoded SDK samples), you need programmatic access to certificates from the store. To make this easier I hacked together a configuration section for certificate references, e.g.

<certificateReferences>

  <add name=Sts

       findValue=CN=STS

       x509FindType=FindBySubjectDistinguishedName

       storeLocation=LocalMachine

       storeName=My />

 

  <add name=http://localhost:9000/IssuedToken

       findValue=CN=Service

       x509FindType=FindBySubjectDistinguishedName

       storeLocation=LocalMachine

       storeName=AddressBook />

</certificateReferences>

…and a static class that gives you easy access to the certificate information (e.g. in your STS):

// get the encryption certificate for the requested service

private void SetTargetToken(string appliesTo)

{

  CertificateReferenceElement config =

    CertificateReference.GetReference(appliesTo);

 

  ProofKeyEncryptionToken = FederationUtilities.GetX509TokenFromCert(

    config.StoreName,

    config.StoreLocation,

    config.FindValue);

}

CertificateReference.zip (14.95 KB)

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s