Ejemplo n.º 1
0
 public void SetBio(MonoBtlsBio bio)
 {
     CheckThrow();
     mono_btls_ssl_set_bio(
         Handle.DangerousGetHandle(),
         bio.Handle.DangerousGetHandle());
 }
Ejemplo n.º 2
0
        public override void Close()
        {
            Debug("Close!");

            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;
            }
        }
Ejemplo n.º 3
0
        public void ExportAsPEM(MonoBtlsBio bio, bool includeHumanReadableForm)
        {
            GetRawData(bio, MonoBtlsX509Format.PEM);

            if (!includeHumanReadableForm)
            {
                return;
            }

            Print(bio);

            var hash   = GetCertHash();
            var output = new StringBuilder();

            output.Append("SHA1 Fingerprint=");
            for (int i = 0; i < hash.Length; i++)
            {
                if (i > 0)
                {
                    output.Append(":");
                }
                output.AppendFormat("{0:X2}", hash [i]);
            }
            output.AppendLine();
            var outputData = Encoding.ASCII.GetBytes(output.ToString());

            bio.Write(outputData, 0, outputData.Length);
        }
Ejemplo n.º 4
0
        public override void StartHandshake()
        {
            InitializeConnection();

            ssl = new MonoBtlsSsl(ctx);

            bio = new MonoBtlsBioMono(this);
            ssl.SetBio(bio);

            if (IsServer)
            {
                if (nativeServerCertificate != null)
                {
                    SetPrivateCertificate(nativeServerCertificate);
                }
            }
            else
            {
                ssl.SetServerName(ServerName);
            }

            if (Options.AllowRenegotiation)
            {
                ssl.SetRenegotiateMode(MonoBtlsSslRenegotiateMode.FREELY);
            }
        }
Ejemplo n.º 5
0
        public void Print(MonoBtlsBio bio)
        {
            var ret = mono_btls_x509_print(
                Handle.DangerousGetHandle(),
                bio.Handle.DangerousGetHandle());

            CheckError(ret);
        }
Ejemplo n.º 6
0
        public void GetRawData(MonoBtlsBio bio, MonoBtlsX509Format format)
        {
            CheckThrow();
            var ret = mono_btls_x509_get_raw_data(
                Handle.DangerousGetHandle(),
                bio.Handle.DangerousGetHandle(),
                format);

            CheckError(ret);
        }
Ejemplo n.º 7
0
        void InitializeConnection()
        {
            ctx = new MonoBtlsSslCtx();

#if MARTIN_DEBUG
            errbio = MonoBtlsBio.CreateMonoStream(Console.OpenStandardError());
            ctx.SetDebugBio(errbio);
#endif

            MonoBtlsProvider.SetupCertificateStore(ctx.CertificateStore, Settings, IsServer);

            if (!IsServer || AskForClientCertificate)
            {
                ctx.SetVerifyCallback(VerifyCallback, false);
            }
            if (!IsServer)
            {
                ctx.SetSelectCallback(SelectCallback);
            }

            if (IsServer && (Options.ServerCertSelectionDelegate != null || Settings.ClientCertificateSelectionCallback != null))
            {
                ctx.SetServerNameCallback(ServerNameCallback);
            }

            ctx.SetVerifyParam(MonoBtlsProvider.GetVerifyParam(Settings, ServerName, IsServer));

            TlsProtocolCode?minProtocol, maxProtocol;
            GetProtocolVersions(out minProtocol, out maxProtocol);

            if (minProtocol != null)
            {
                ctx.SetMinVersion((int)minProtocol.Value);
            }
            if (maxProtocol != null)
            {
                ctx.SetMaxVersion((int)maxProtocol.Value);
            }

            if (Settings != null && Settings.EnabledCiphers != null)
            {
                var ciphers = new short [Settings.EnabledCiphers.Length];
                for (int i = 0; i < ciphers.Length; i++)
                {
                    ciphers [i] = (short)Settings.EnabledCiphers [i];
                }
                ctx.SetCiphers(ciphers, true);
            }

            if (IsServer && Settings?.ClientCertificateIssuers != null)
            {
                ctx.SetClientCertificateIssuers(Settings.ClientCertificateIssuers);
            }
        }
Ejemplo n.º 8
0
        void InitializeConnection()
        {
            ctx = new MonoBtlsSslCtx();

#if MARTIN_DEBUG
            errbio = MonoBtlsBio.CreateMonoStream(Console.OpenStandardError());
            ctx.SetDebugBio(errbio);
#endif

            SetupCertificateStore();

            if (!IsServer || AskForClientCertificate)
            {
                ctx.SetVerifyCallback(VerifyCallback, false);
            }
            if (!IsServer)
            {
                ctx.SetSelectCallback(SelectCallback);
            }

            var host = TargetHost;
            if (!string.IsNullOrEmpty(host))
            {
                var pos = TargetHost.IndexOf(':');
                if (pos > 0)
                {
                    host = host.Substring(0, pos);
                }
            }

            ctx.SetVerifyParam(MonoBtlsProvider.GetVerifyParam(host, IsServer));

            TlsProtocolCode minProtocol, maxProtocol;
            GetProtocolVersions(out minProtocol, out maxProtocol);

            ctx.SetMinVersion((int)minProtocol);
            ctx.SetMaxVersion((int)maxProtocol);

            if (Settings != null && Settings.EnabledCiphers != null)
            {
                var ciphers = new short [Settings.EnabledCiphers.Length];
                for (int i = 0; i < ciphers.Length; i++)
                {
                    ciphers [i] = (short)Settings.EnabledCiphers [i];
                }
                ctx.SetCiphers(ciphers, true);
            }
        }
Ejemplo n.º 9
0
        static void ConvertToNewFormat(string root, MonoBtlsX509 x509)
        {
            long hash = x509.GetSubjectNameHash();

            string newName;
            int    index = 0;

            do
            {
                newName = Path.Combine(root, string.Format("{0:x8}.{1}", hash, index++));
            } while (File.Exists(newName));
            Console.WriteLine("  new name: {0}", newName);

            using (var stream = new FileStream(newName, FileMode.Create))
                using (var bio = MonoBtlsBio.CreateMonoStream(stream))
                    x509.ExportAsPEM(bio, true);
        }
Ejemplo n.º 10
0
        public override void StartHandshake()
        {
            InitializeConnection();

            ssl = new MonoBtlsSsl(ctx);

            bio = new MonoBtlsBioMono(this);
            ssl.SetBio(bio);

            if (IsServer)
            {
                SetPrivateCertificate(nativeServerCertificate);
            }
            else
            {
                ssl.SetServerName(ServerName);
            }
        }
Ejemplo n.º 11
0
		public void SetDebugBio (MonoBtlsBio bio)
		{
			CheckThrow ();
			mono_btls_ssl_ctx_set_debug_bio (Handle.DangerousGetHandle (), bio.Handle.DangerousGetHandle ());
		}
Ejemplo n.º 12
0
		public void ExportAsPEM (MonoBtlsBio bio, bool includeHumanReadableForm)
		{
			GetRawData (bio, MonoBtlsX509Format.PEM);

			if (!includeHumanReadableForm)
				return;

			Print (bio);

			var hash = GetCertHash ();
			var output = new StringBuilder ();
			output.Append ("SHA1 Fingerprint=");
			for (int i = 0; i < hash.Length; i++) {
				if (i > 0)
					output.Append (":");
				output.AppendFormat ("{0:X2}", hash [i]);
			}
			output.AppendLine ();
			var outputData = Encoding.ASCII.GetBytes (output.ToString ());
			bio.Write (outputData, 0, outputData.Length);
		}
Ejemplo n.º 13
0
		public void Print (MonoBtlsBio bio)
		{
			var ret = mono_btls_x509_print (
				Handle.DangerousGetHandle (),
				bio.Handle.DangerousGetHandle ());
			CheckError (ret);
		}
Ejemplo n.º 14
0
		public void GetRawData (MonoBtlsBio bio, MonoBtlsX509Format format)
		{
			CheckThrow ();
			var ret = mono_btls_x509_get_raw_data (
				Handle.DangerousGetHandle (),
				bio.Handle.DangerousGetHandle (),
				format);
			CheckError (ret);
		}