﻿using System.Net.Http;
using System.Security.Cryptography.X509Certificates;

namespace Docker.DotNet.X509
{
    public class CertificateCredentials : Credentials
    {
        private readonly WebRequestHandler _handler;

        public CertificateCredentials(X509Certificate2 clientCertificate)
        {
            _handler = new WebRequestHandler()
            {
                ClientCertificateOptions = ClientCertificateOption.Manual,
                UseDefaultCredentials = false
            };

            _handler.ClientCertificates.Add(clientCertificate);
        }

        public override HttpMessageHandler Handler
        {
            get
            {
                return _handler;
            }
        }

        public override bool IsTlsCredentials()
        {
            return true;
        }

        public override void Dispose()
        {
            _handler.Dispose();
        }
    }
}
﻿using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Net.Http.Client;

namespace Docker.DotNet.X509
{
    public class CertificateCredentials : Credentials
    {
        private X509Certificate2 _certificate;

        public CertificateCredentials(X509Certificate2 clientCertificate)
        {
            _certificate = clientCertificate;
        }

        public override HttpMessageHandler GetHandler(HttpMessageHandler innerHandler)
        {
            var handler = (ManagedHandler)innerHandler;
            handler.ClientCertificates = new X509CertificateCollection
            {
                _certificate
            };

            handler.ServerCertificateValidationCallback = ServicePointManager.ServerCertificateValidationCallback;
            return handler;
        }

        public override bool IsTlsCredentials()
        {
            return true;
        }

        public override void Dispose()
        {
        }
    }
}
Make X509 work with ManagedHandler
Make X509 work with ManagedHandler

This eliminates the full-framework dependency. A follow-up change should
start building this fore CoreCLR.
