// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#if SECURITY_DEP
+#if SECURITY_DEP && MONO_FEATURE_BTLS
#if MONO_SECURITY_ALIAS
extern alias MonoSecurity;
#endif
if (IsServer) {
SetPrivateCertificate (nativeServerCertificate);
} else {
- ssl.SetServerName (TargetHost);
+ ssl.SetServerName (ServerName);
}
}
}
}
- Exception GetException (MonoBtlsSslError status)
+ static Exception GetException (MonoBtlsSslError status)
{
- var error = MonoBtlsError.GetError ();
+ string file;
+ int line;
+ var error = MonoBtlsError.GetError (out file, out line);
if (error == null)
return new MonoBtlsException (status);
var text = MonoBtlsError.GetErrorString (error);
- return new MonoBtlsException ("{0} {1}", status, text);
+
+ string message;
+ if (file != null)
+ message = string.Format ("{0} {1}\n at {2}:{3}", status, text, file, line);
+ else
+ message = string.Format ("{0} {1}", status, text);
+ return new MonoBtlsException (message);
}
public override bool ProcessHandshake ()
void SetupCertificateStore ()
{
-#if MONODROID
- ctx.CertificateStore.SetDefaultPaths ();
- ctx.CertificateStore.AddAndroidLookup ();
-#else
- var userPath = MonoBtlsX509StoreManager.GetStorePath (MonoBtlsX509StoreType.UserTrustedRoots);
- if (Directory.Exists (userPath))
- ctx.CertificateStore.AddDirectoryLookup (userPath, MonoBtlsX509FileType.PEM);
- var machinePath = MonoBtlsX509StoreManager.GetStorePath (MonoBtlsX509StoreType.MachineTrustedRoots);
- if (Directory.Exists (machinePath))
- ctx.CertificateStore.AddDirectoryLookup (machinePath, MonoBtlsX509FileType.PEM);
-#endif
+ MonoBtlsProvider.SetupCertificateStore (ctx.CertificateStore);
if (Settings != null && Settings.TrustAnchors != null) {
var trust = IsServer ? MonoBtlsX509TrustKind.TRUST_CLIENT : MonoBtlsX509TrustKind.TRUST_SERVER;
if (!IsServer)
ctx.SetSelectCallback (SelectCallback);
- ctx.SetVerifyParam (MonoBtlsProvider.GetVerifyParam (TargetHost, IsServer));
+ ctx.SetVerifyParam (MonoBtlsProvider.GetVerifyParam (ServerName, IsServer));
TlsProtocolCode minProtocol, maxProtocol;
GetProtocolVersions (out minProtocol, out maxProtocol);
var cipher = (CipherSuiteCode)ssl.GetCipher ();
var protocol = (TlsProtocolCode)ssl.GetVersion ();
+ var serverName = ssl.GetServerName ();
Debug ("GET CONNECTION INFO: {0:x}:{0} {1:x}:{1} {2}", cipher, protocol, (TlsProtocolCode)protocol);
connectionInfo = new MonoTlsConnectionInfo {
CipherSuiteCode = cipher,
- ProtocolVersion = GetProtocol (protocol)
+ ProtocolVersion = GetProtocol (protocol),
+ PeerDomainName = serverName
};
}
public override void Close ()
{
Debug ("Close!");
- ssl.Dispose ();
+
+ if (ssl != null) {
+ ssl.Dispose ();
+ ssl = null;
+ }
+ if (ctx != null) {
+ ctx.Dispose ();
+ ctx = null;
+ }
+ if (bio != null) {
+ bio.Dispose ();
+ bio = null;
+ }
+ if (errbio != null) {
+ errbio.Dispose ();
+ errbio = null;
+ }
}
void Dispose<T> (ref T disposable)