web-dev-qa-db-fra.com

Configuration de SSL sur l'API Web auto-hébergée ASP.NET

Je crée un service API Web auto-hébergé. Pour le sécuriser, j'ai étudié et mis en œuvre this article, généré avec succès un certificat SSL local en utilisant makecert et mon service authentifié et généré des jetons bien, si j'utilise 

http://localhost/webapi/authentication/authenticate

lien, mais lorsque j'essaie d'accéder à mon service à l'aide de HTTPS, je reçois le suivi sur Firefox:

ssl_error_rx_record_too_long

et pour la même demande, Fiddler me montre:

HTTP/1.1 502 Fiddler - Echec de la connexion Date: lun., 26 août 2013 10:44:27 GMT Content-Type: text/html; charset = UTF-8 Connexion: fermez Horodatage: 13: 44: 27.433

[Fiddler] La connexion socket vers localhost a échoué. 
Échec de négociez la connexion HTTPS avec server.fiddler.network.https> Échec de la sécurisation de la connexion existante pour localhost. La poignée de main a échoué à cause d'un format de paquet inattendu.

Ma configuration auto-hôte:

    private HttpSelfHostServer _server;
    private ExtendedHttpsSelfHostConfiguration _config;
    public const string ServiceAddress = "https://localhost/webapi";
    _config = new ExtendedHttpsSelfHostConfiguration(ServiceAddress);
    _server = new HttpSelfHostServer(_config);
    _server.OpenAsync();

où ExtendedHttpSelfHostConfiguration extrait de cet article est:

public class ExtendedHttpSelfHostConfiguration : HttpSelfHostConfiguration
{
    public ExtendedHttpSelfHostConfiguration(string baseAddress) : base(baseAddress) { }
    public ExtendedHttpSelfHostConfiguration(Uri baseAddress) : base(baseAddress) { }

    protected override BindingParameterCollection OnConfigureBinding(HttpBinding httpBinding)
    {
        if (BaseAddress.ToString().ToLower().Contains("https://"))
        {
            httpBinding.Security.Mode = HttpBindingSecurityMode.Transport;
        }

        return base.OnConfigureBinding(httpBinding);
    }
}

Qu'est-ce qui me manque? Merci d'avance!

32
insomnium_

D'après cet article de blog j'ai découvert qu'il me fallait créer un certificat SSL et l'assigner à un port spécifique (: 99 dans mon cas).

J'ai créé un protocole SSL signé localement. Ensuite, c'est Thumbprint et ApplicationId. En utilisant la commande CMD netsh (dans les systèmes antérieurs à Win7, il existe un outil httpcfg), j'ai attribué mon certificat au port

netsh http add sslcert ipport=0.0.0.0:99 certhash=3e49906c01a774c888231e5092077d3d855a6861 appid={2d6059b2-cccb-4a83-ae08-8ce209c2c5c1}, où certhash = SSL Thumbprint et appid = ApplicationId que j'ai copié auparavant.

Ça y est, maintenant je peux faire des requêtes HTTPS!

31
insomnium_