It uses public key cryptography to create a different, and more secure approach to authenticating your identity and rights to access a server or resource. In a nutshell, you will generate a public and private key pair. The public key will be placed on the server by your system administrator, giving you access.
-->Federation servers require token-signing certificates to prevent attackers from altering or counterfeiting security tokens in an attempt to gain unauthorized access to federated resources. The private/public key pairing that is used with token-signing certificates is the most important validation mechanism of any federated partnership because these keys verify that a security token was issued by a valid partner federation server and that the token was not modified during transit.
Token-signing certificate requirements
A token-signing certificate must meet the following requirements to work with AD FS:
- For a token-signing certificate to successfully sign a security token, the token-signing certificate must contain a private key.
- The AD FS service account must have access to the token-signing certificate's private key in the personal store of the local computer. This is taken care of by Setup. You can also use the AD FS Management snap-in to ensure this access if you subsequently change the token-signing certificate.
Note
It is a public key infrastructure (PKI) best practice to not share the private key for multiple purposes. Therefore, do not use the service communication certificate that you installed on the federation server as the token-signing certificate.
How token-signing certificates are used across partners
Every token-signing certificate contains cryptographic private keys and public keys that are used to digitally sign (by means of the private key) a security token. Later, after they are received by a partner federation server, these keys validate the authenticity (by means of the public key) of the encrypted security token.
Because each security token is digitally signed by the account partner, the resource partner can verify that the security token was in fact issued by the account partner and that it was not modified. Digital signatures are verified by the public key portion of a partner's token-signing certificate. After the signature is verified, the resource federation server generates its own security token for its organization and it signs the security token with its own token-signing certificate.
For federation partner environments, when the token-signing certificate has been issued by a CA, ensure that:
- The certificate revocation lists (CRLs) of the certificate are accessible to relying parties and Web servers that trust the federation server.
- The root CA certificate is trusted by the relying parties and Web servers that trust the federation server.
The Web server in the resource partner uses the public key of the token-signing certificate to verify that the security token is signed by the resource federation server. The Web server then allows the appropriate access to the client.
Deployment considerations for token-signing certificates
When you deploy the first federation server in a new AD FS installation, you must obtain a token-signing certificate and install it in the local computer personal certificate store on that federation server. You can obtain a token-signing certificate by requesting one from an enterprise CA or a public CA or by creating a self-signed certificate.
When you deploy an AD FS farm, token-signing certificates are installed differently, depending on how you create the server farm.
There are two server farm options that you can consider when you obtain token-signing certificates for your deployment:
- A private key from one token-signing certificate is shared among all the federation servers in a farm.In a federation server farm environment, we recommend that all federation servers share (or reuse) the same token-signing certificate. You can install a single token-signing certificate from a CA on a federation server and then export the private key, as long as the issued certificate is marked as exportable.As shown in the following illustration, the private key from a single token-signing certificate can be shared to all the federation servers in a farm. This option—compared to the following 'unique token-signing certificate' option—reduces costs if you plan to obtain a token-signing certificate from a public CA.
- There is a unique token-signing certificate for each federation server in a farm.When you use multiple, unique certificates throughout your farm, each server in that farm signs tokens with its own unique private key.As shown in the following illustration, you can obtain a separate token-signing certificate for every single federation server in the farm. This option is more expensive if you plan to obtain your token-signing certificates from a public CA.
For information about installing a certificate when you use Microsoft Certificate Services as your enterprise CA, see IIS 7.0: Create a Domain Server Certificate in IIS 7.0.
For information about installing a certificate from a public CA, see IIS 7.0: Request an Internet Server Certificate.
For information about installing a self-signed certificate, see IIS 7.0: Create a Self-Signed Server Certificate in IIS 7.0.
See Also
-->This topic shows how to create a custom security token using the SecurityToken class, and how to integrate it with a custom security token provider and authenticator. For a complete code example see the Custom Token sample.
A security token is essentially an XML element that is used by the Windows Communication Foundation (WCF) security framework to represent claims about a sender inside the SOAP message. WCF security provides various tokens for system-provided authentication modes. Examples include an X.509 certificate security token represented by the X509SecurityToken class or a Username security token represented by the UserNameSecurityToken class.
Sometimes an authentication mode or credential is not supported by the provided types. In that case, it is necessary to create a custom security token to provide an XML representation of the custom credential inside the SOAP message.
The following procedures show how to create a custom security token and how to integrate it with the WCF security infrastructure. This topic creates a credit card token that is used to pass information about the client's credit card to the server.
For more information about custom credentials and security token manager, see Walkthrough: Creating Custom Client and Service Credentials.
See the System.IdentityModel.Tokens namespace for more classes that represent security tokens.
Procedures
A client application must be provided with a way to specify credit card information for the security infrastructure. This information is made available to the application by a custom client credentials class. The first step is to create a class to represent the credit card information for custom client credentials.
To create a class that represents credit card information inside client credentials
- Define a new class that represents the credit card information for the application. The following example names the class
CreditCardInfo
. - Add appropriate properties to the class to allow an application set the necessary information required for the custom token. In this example, the class has three properties:
CardNumber
,CardIssuer
, andExpirationDate
.
Next, a class that represents the custom security token must be created. This class is used by the security token provider, authenticator, and serializer classes to pass information about the security token to and from the WCF security infrastructure.
To create a custom security token class
- Define a new class derived from the SecurityToken class. This example creates a class named
CreditCardToken
. - Override the Id property. This property is used to get the local identifier of the security token that is used to point to the security token XML representation from other elements inside the SOAP message. In this example, a token identifier can be either passed to it as a constructor parameter or a new random one is generated every time a security token instance is created.
- Implement the SecurityKeys property. This property returns a collection of security keys that the security token instance represents. Such keys can be used by WCF to sign or encrypt parts of the SOAP message. In this example, the credit card security token cannot contain any security keys; therefore, the implementation always returns an empty collection.
- Override the ValidFrom and ValidTo properties. These properties are used by WCF to determine the validity of the security token instance. In this example, the credit card security token has only an expiration date, so the
ValidFrom
property returns a DateTime that represents the date and time of the instance creation.
When a new security token type is created, it requires an implementation of the SecurityTokenParameters class. The implementation is used in the security binding element configuration to represent the new token type. The security token parameters class serves as a template that is used to match the actual security token instance to when a message is processed. The template provides additional properties that an application can use to specify criteria that the security token must match to be used or authenticated. The following example does not add any additional properties, so only the security token type is matched when the WCF infrastructure searches for a security token instance to use or to validate.
To create a custom security token parameters class
- Define a new class derived from the SecurityTokenParameters class.
- Implement the CloneCore method. Copy all internal fields defined in your class, if any. This example does not define any additional fields.
- Implement the SupportsClientAuthentication read-only property. This property returns
true
if the security token type represented by this class can be used to authenticate a client to a service. In this example, the credit card security token can be used to authenticate a client to a service. - Implement the SupportsServerAuthentication read-only property. This property returns
true
if the security token type represented by this class can be used to authenticate a service to a client. In this example, the credit card security token cannot be used to authenticate a service to a client. - Implement the SupportsClientWindowsIdentity read-only property. This property returns
true
if the security token type represented by this class can be mapped to a Windows account. If so, the authentication result is represented by a WindowsIdentity class instance. In this example, the token cannot be mapped to a Windows account. - Implement the CreateKeyIdentifierClause(SecurityToken, SecurityTokenReferenceStyle) method. This method is called by WCF security framework when it requires a reference to the security token instance represented by this security token parameters class. Both the actual security token instance and SecurityTokenReferenceStyle that specifies the type of the reference that is being requested are passed to this method as arguments. In this example, only internal references are supported by the credit card security token. The SecurityToken class has functionality to create internal references; therefore, the implementation does not require additional code.
- Implement the InitializeSecurityTokenRequirement(SecurityTokenRequirement) method. This method is called by WCF to convert the security token parameters class instance into an instance of the SecurityTokenRequirement class. The result is used by security token providers to create the appropriate security token instance.
Security tokens are transmitted inside SOAP messages, which requires a translation mechanism between the in-memory security token representation and the on-the-wire representation. WCF uses a security token serializer to accomplish this task. Every custom token must be accompanied by a custom security token serializer that can serialize and deserialize the custom security token from the SOAP message.
Note
Derived keys are enabled by default. If you create a custom security token and use it as the primary token, WCF derives a key from it. While doing so, it calls the custom security token serializer to write the SecurityKeyIdentifierClause for the custom security token while serializing the
DerivedKeyToken
to the wire. On the receiving end, when deserializing the token off the wire, the DerivedKeyToken
serializer expects a SecurityTokenReference
element as the top-level child under itself. If the custom security token serializer did not add a SecurityTokenReference
element while serializing its clause type, an exception is thrown.To create a custom security token serializer
- Define a new class derived from the WSSecurityTokenSerializer class.
- Override the CanReadTokenCore(XmlReader) method, which relies on an XmlReader to read the XML stream. The method returns
true
if the serializer implementation can deserialize the security token based given its current element. In this example, this method checks whether the XML reader's current XML element has the correct element name and namespace. If it does not, it calls the base class implementation of this method to handle the XML element. - Override the ReadTokenCore(XmlReader, SecurityTokenResolver) method. This method reads the XML content of the security token and constructs the appropriate in-memory representation for it. If it does not recognize the XML element on which the passed-in XML reader is standing, it calls the base class implementation to process the system-provided token types.
- Override the CanWriteTokenCore(SecurityToken) method. This method returns
true
if it can convert the in-memory token representation (passed in as an argument) to the XML representation. If it cannot convert, it calls the base class implementation. - Override the WriteTokenCore(XmlWriter, SecurityToken) method. This method converts an in-memory security token representation into an XML representation. If the method cannot convert, it calls the base class implementation.
After completing the four previous procedures, integrate the custom security token with the security token provider, authenticator, manager, and client and service credentials.
To integrate the custom security token with a security token provider
- The security token provider creates, modifies (if necessary), and returns an instance of the token. To create a custom provider for the custom security token, create a class that inherits from the SecurityTokenProvider class. The following example overrides the GetTokenCore method to return an instance of the
CreditCardToken
. For more information about custom security token providers, see How to: Create a Custom Security Token Provider.
To integrate the custom security token with a security token authenticator
- The security token authenticator validates the content of the security token when it is extracted from the message. To create a custom authenticator for the custom security token, create a class that inherits from the SecurityTokenAuthenticator class. The following example overrides the ValidateTokenCore method. For more information about custom security token authenticators, see How to: Create a Custom Security Token Authenticator.
To integrate the custom security token with a security token manager
- The security token manager creates the appropriate token provider, security authenticator, and token serializer instances. To create a custom token manager, create a class that inherits from the ClientCredentialsSecurityTokenManager class. The primary methods of the class use a SecurityTokenRequirement to create the appropriate provider and client or service credentials. For more information about custom security token managers, see Walkthrough: Creating Custom Client and Service Credentials.
To integrate the custom security token with custom client and service credentials
- The custom client and service credentials must be added to provide an API for the application to allow specifying custom token information that is used by the custom security token infrastructure created previously to provide and authenticate the custom security token content. The following samples show how this can be done. For more information about custom client and service credentials, see Walkthrough: Creating Custom Client and Service Credentials.
Generate Megasol Public Key Token Account
The custom security token parameters class created previously is used to tell the WCF security framework that a custom security token must be used when communicating with a service. The following procedure shows how this can be done.
To integrate the custom security token with the binding
- The custom security token parameters class must be specified in one of the token parameters collections that are exposed on the SecurityBindingElement class. The following example uses the collection returned by
SignedEncrypted
. The code adds the credit card custom token to every message sent from the client to the service with its content automatically signed and encrypted.
This topic shows the various pieces of code necessary to implement and use a custom token. To see a complete example of how all these pieces of code fit together see, Custom Token.