//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.RelyingParty {
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using DotNetOpenAuth.Messaging;
///
/// Security settings that are applicable to relying parties.
///
public sealed class RelyingPartySecuritySettings : SecuritySettings {
///
/// The default value for the property.
///
internal const bool ProtectDownlevelReplayAttacksDefault = true;
///
/// Initializes a new instance of the class.
///
internal RelyingPartySecuritySettings()
: base(false) {
this.PrivateSecretMaximumAge = TimeSpan.FromDays(7);
this.ProtectDownlevelReplayAttacks = ProtectDownlevelReplayAttacksDefault;
this.AllowApproximateIdentifierDiscovery = true;
this.TrustedProviderEndpoints = new HashSet();
}
///
/// Gets or sets a value indicating whether the entire pipeline from Identifier discovery to
/// Provider redirect is guaranteed to be encrypted using HTTPS for authentication to succeed.
///
///
/// Setting this property to true is appropriate for RPs with highly sensitive
/// personal information behind the authentication (money management, health records, etc.)
/// When set to true, some behavioral changes and additional restrictions are placed:
///
/// - User-supplied identifiers lacking a scheme are prepended with
/// HTTPS:// rather than the standard HTTP:// automatically.
/// - User-supplied identifiers are not allowed to use HTTP for the scheme.
/// - All redirects during discovery on the user-supplied identifier must be HTTPS.
/// - Any XRDS file found by discovery on the User-supplied identifier must be protected using HTTPS.
/// - Only Provider endpoints found at HTTPS URLs will be considered.
/// - If the discovered identifier is an OP Identifier (directed identity), the
/// Claimed Identifier eventually asserted by the Provider must be an HTTPS identifier.
/// - In the case of an unsolicited assertion, the asserted Identifier, discovery on it and
/// the asserting provider endpoint must all be secured by HTTPS.
///
/// Although the first redirect from this relying party to the Provider is required
/// to use HTTPS, any additional redirects within the Provider cannot be protected and MAY
/// revert the user's connection to HTTP, based on individual Provider implementation.
/// There is nothing that the RP can do to detect or prevent this.
///
/// A is thrown during discovery or authentication when a secure pipeline cannot be established.
///
///
public bool RequireSsl { get; set; }
///
/// Gets or sets a value indicating whether only OP Identifiers will be discoverable
/// when creating authentication requests.
///
public bool RequireDirectedIdentity { get; set; }
///
/// Gets or sets the oldest version of OpenID the remote party is allowed to implement.
///
/// Defaults to
public ProtocolVersion MinimumRequiredOpenIdVersion { get; set; }
///
/// Gets or sets the maximum allowable age of the secret a Relying Party
/// uses to its return_to URLs and nonces with 1.0 Providers.
///
/// The default value is 7 days.
public TimeSpan PrivateSecretMaximumAge { get; set; }
///
/// Gets or sets a value indicating whether all unsolicited assertions should be ignored.
///
/// The default value is false.
public bool RejectUnsolicitedAssertions { get; set; }
///
/// Gets or sets a value indicating whether delegating identifiers are refused for authentication.
///
/// The default value is false.
///
/// When set to true, login attempts that start at the RP or arrive via unsolicited
/// assertions will be rejected if discovery on the identifier shows that OpenID delegation
/// is used for the identifier. This is useful for an RP that should only accept identifiers
/// directly issued by the Provider that is sending the assertion.
///
public bool RejectDelegatingIdentifiers { get; set; }
///
/// Gets or sets a value indicating whether unsigned extensions in authentication responses should be ignored.
///
/// The default value is false.
///
/// When set to true, the methods
/// will not return any extension that was not signed by the Provider.
///
public bool IgnoreUnsignedExtensions { get; set; }
///
/// Gets or sets a value indicating whether authentication requests will only be
/// sent to Providers with whom we can create a shared association.
///
///
/// true to immediately fail authentication if an association with the Provider cannot be established; otherwise, false.
/// The default value is false.
///
public bool RequireAssociation { get; set; }
///
/// Gets or sets a value indicating whether certain Claimed Identifiers that exploit
/// features that .NET does not have the ability to send exact HTTP requests for will
/// still be allowed by using an approximate HTTP request.
///
///
/// The default value is true.
///
public bool AllowApproximateIdentifierDiscovery { get; set; }
///
/// Gets the set of trusted OpenID Provider Endpoint URIs.
///
public HashSet TrustedProviderEndpoints { get; private set; }
///
/// Gets or sets a value indicating whether any login attempt coming from an OpenID Provider Endpoint that is not on this
/// whitelist of trusted OP Endpoints will be rejected. If the trusted providers list is empty and this value
/// is true, all assertions are rejected.
///
/// Default is false.
public bool RejectAssertionsFromUntrustedProviders { get; set; }
///
/// Gets or sets a value indicating whether special measures are taken to
/// protect users from replay attacks when those users' identities are hosted
/// by OpenID 1.x Providers.
///
/// The default value is true.
///
/// Nonces for protection against replay attacks were not mandated
/// by OpenID 1.x, which leaves users open to replay attacks.
/// This feature works by adding a signed nonce to the authentication request.
/// This might increase the request size beyond what some OpenID 1.1 Providers
/// (such as Blogger) are capable of handling.
///
internal bool ProtectDownlevelReplayAttacks { get; set; }
///
/// Filters out any disallowed endpoints.
///
/// The endpoints discovered on an Identifier.
/// A sequence of endpoints that satisfy all security requirements.
internal IEnumerable FilterEndpoints(IEnumerable endpoints) {
return endpoints
.Where(se => !this.RejectDelegatingIdentifiers || se.ClaimedIdentifier == se.ProviderLocalIdentifier)
.Where(se => !this.RequireDirectedIdentity || se.ClaimedIdentifier == se.Protocol.ClaimedIdentifierForOPIdentifier);
}
}
}