2 // HttpsClientStream.cs: Glue between HttpWebRequest and SslClientStream to
3 // reduce reflection usage.
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2004-2006 Novell, Inc. (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Security.Cryptography.X509Certificates;
35 namespace Mono.Security.Protocol.Tls {
37 // Note: DO NOT REUSE this class - instead use SslClientStream
39 internal class HttpsClientStream : SslClientStream {
41 private HttpWebRequest _request;
44 public HttpsClientStream (Stream stream, X509CertificateCollection clientCertificates,
45 HttpWebRequest request, byte [] buffer)
46 : base (stream, request.RequestUri.Host, false, (Mono.Security.Protocol.Tls.SecurityProtocolType)
47 ServicePointManager.SecurityProtocol, clientCertificates)
49 // this constructor permit access to the WebRequest to call
50 // ICertificatePolicy.CheckValidationResult
54 InputBuffer.Write (buffer, 0, buffer.Length);
56 // also saved from reflection
57 base.CheckCertRevocationStatus = ServicePointManager.CheckCertificateRevocationList;
61 public bool TrustFailure {
64 case -2146762486: // CERT_E_CHAINING 0x800B010A
65 case -2146762487: // CERT_E_UNTRUSTEDROOT 0x800B0109
73 internal override bool RaiseServerCertificateValidation (X509Certificate certificate, int[] certificateErrors)
75 bool failed = (certificateErrors.Length > 0);
76 // only one problem can be reported by this interface
77 _status = ((failed) ? certificateErrors [0] : 0);
79 if (ServicePointManager.CertificatePolicy != null) {
80 ServicePoint sp = _request.ServicePoint;
81 return ServicePointManager.CertificatePolicy.CheckValidationResult (sp, certificate, _request, _status);