/// <summary> /// Converts a given identifier to its secure equivalent. /// UriIdentifiers originally created with an implied HTTP scheme change to HTTPS. /// Discovery is made to require SSL for the entire resolution process. /// </summary> /// <param name="secureIdentifier">The newly created secure identifier. /// If the conversion fails, <paramref name="secureIdentifier"/> retains /// <i>this</i> identifiers identity, but will never discover any endpoints.</param> /// <returns> /// True if the secure conversion was successful. /// False if the Identifier was originally created with an explicit HTTP scheme. /// </returns> internal override bool TryRequireSsl(out Identifier secureIdentifier) { // If this Identifier is already secure, reuse it. if (IsDiscoverySecureEndToEnd) { secureIdentifier = this; return(true); } // If this identifier already uses SSL for initial discovery, return one // that guarantees it will be used throughout the discovery process. if (string.Equals(Uri.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)) { secureIdentifier = new UriIdentifier(this.Uri, true); return(true); } // Otherwise, try to make this Identifier secure by normalizing to HTTPS instead of HTTP. if (this.SchemeImplicitlyPrepended) { UriBuilder newIdentifierUri = new UriBuilder(this.Uri); newIdentifierUri.Scheme = Uri.UriSchemeHttps; if (newIdentifierUri.Port == 80) { newIdentifierUri.Port = 443; } secureIdentifier = new UriIdentifier(newIdentifierUri.Uri, true); return(true); } // This identifier is explicitly NOT https, so we cannot change it. secureIdentifier = new NoDiscoveryIdentifier(this, true); return(false); }
/// <summary> /// Converts a given identifier to its secure equivalent. /// UriIdentifiers originally created with an implied HTTP scheme change to HTTPS. /// Discovery is made to require SSL for the entire resolution process. /// </summary> /// <param name="secureIdentifier">The newly created secure identifier. /// If the conversion fails, <paramref name="secureIdentifier"/> retains /// <i>this</i> identifiers identity, but will never discover any endpoints.</param> /// <returns> /// True if the secure conversion was successful. /// False if the Identifier was originally created with an explicit HTTP scheme. /// </returns> internal override bool TryRequireSsl(out Identifier secureIdentifier) { // If this Identifier is already secure, reuse it. if (IsDiscoverySecureEndToEnd) { secureIdentifier = this; return true; } // If this identifier already uses SSL for initial discovery, return one // that guarantees it will be used throughout the discovery process. if (string.Equals(Uri.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)) { secureIdentifier = new UriIdentifier(this.Uri, true); return true; } // Otherwise, try to make this Identifier secure by normalizing to HTTPS instead of HTTP. if (this.SchemeImplicitlyPrepended) { UriBuilder newIdentifierUri = new UriBuilder(this.Uri); newIdentifierUri.Scheme = Uri.UriSchemeHttps; if (newIdentifierUri.Port == 80) { newIdentifierUri.Port = 443; } secureIdentifier = new UriIdentifier(newIdentifierUri.Uri, true); return true; } // This identifier is explicitly NOT https, so we cannot change it. secureIdentifier = new NoDiscoveryIdentifier(this, true); return false; }