Exemplo n.º 1
0
        private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
#if DEBUG
            return(true);
#endif
            return(ServerCertificate.Equals(certificate));
        }
        private SenderCertificate CreateCertificateFor(ECKeyPair trustRoot, String sender, int deviceId, ECPublicKey identityKey, long expires)
        {
            ECKeyPair serverKey = Curve.generateKeyPair();

            byte[] serverCertificateBytes = new libsignalmetadata.protobuf.ServerCertificate.Types.Certificate()
            {
                Id  = 1,
                Key = ByteString.CopyFrom(serverKey.getPublicKey().serialize())
            }.ToByteArray();

            byte[] serverCertificateSignature = Curve.calculateSignature(trustRoot.getPrivateKey(), serverCertificateBytes);

            ServerCertificate serverCertificate = new ServerCertificate(new libsignalmetadata.protobuf.ServerCertificate()
            {
                Certificate = ByteString.CopyFrom(serverCertificateBytes),
                Signature   = ByteString.CopyFrom(serverCertificateSignature)
            }.ToByteArray());

            byte[] senderCertificateBytes = new libsignalmetadata.protobuf.SenderCertificate.Types.Certificate
            {
                Sender       = sender,
                SenderDevice = (uint)deviceId,
                IdentityKey  = ByteString.CopyFrom(identityKey.serialize()),
                Expires      = (ulong)expires,
                Signer       = libsignalmetadata.protobuf.ServerCertificate.Parser.ParseFrom(serverCertificate.Serialized)
            }.ToByteArray();

            byte[] senderCertificateSignature = Curve.calculateSignature(serverKey.getPrivateKey(), senderCertificateBytes);

            return(new SenderCertificate(new libsignalmetadata.protobuf.SenderCertificate()
            {
                Certificate = ByteString.CopyFrom(senderCertificateBytes),
                Signature = ByteString.CopyFrom(senderCertificateSignature)
            }.ToByteArray()));
        }
 private void CleanupServerCertificate()
 {
     if (ServerCertificate != null)
     {
         ServerCertificate.Dispose();
         ServerCertificate = null;
     }
 }
Exemplo n.º 4
0
        private void SaveItem()
        {
            bool success = false;

            try {
                if (PassedValidation())
                {
                    ServerCertificate item = new ServerCertificate(int.Parse(hfItemID.Value));
                    SPA.User          user = new SPA.User(Context.User.Identity.Name);
                    item.ServerID      = ServerID;
                    item.CertificateID = int.Parse(ddlCertificate.SelectedValue);

                    item.ModifiedBy = user.UserName;
                    if (item.ID == 0)
                    {
                        item.CreatedBy = item.ModifiedBy;
                        if (item.Insert())
                        {
                            success = true;
                        }
                    }
                    else
                    {
                        if (item.Update())
                        {
                            success = true;
                        }
                    }
                    if (success)
                    {
                        Fill();
                    }
                }
                else
                {
                    // validation failed
                }
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
                if (ShowDebug)
                {
                    lblErrorMessage.Text = ex.ToString();
                }
            }
            Response.Redirect(string.Format("{0}/{1}?View=Edit&ID={2}&ServerID={2}&IsDlg=1Filter={3}", SPContext.Current.Web.Url, Pages.ServerItem.PAGE_URL, ServerID, Filter), false);
        }
Exemplo n.º 5
0
        public Socket(Options options)
        {
            if (options.Host != null)
            {
                var pieces = options.Host.Split(':');
                options.Hostname = pieces[0];
                if (pieces.Length > 1)
                {
                    options.Port = int.Parse(pieces[pieces.Length - 1]);
                }
            }

            _secure       = options.Secure;
            _sslProtocols = options.SslProtocols;
            _hostname     = options.Hostname;
            _port         = options.Port;
            _query        = options.QueryString != null
                ? ParseQS.Decode(options.QueryString)
                : new Dictionary <string, string>();

            if (options.Query != null)
            {
                foreach (var item in options.Query)
                {
                    _query.Add(item.Key, item.Value);
                }
            }


            _upgrade           = options.Upgrade;
            _path              = (options.Path ?? "/engine.io").Replace("/$", "") + "/";
            _timestampParam    = options.TimestampParam ?? "t";
            _timestampRequests = options.TimestampRequests;
            _transports        = options.Transports ?? ImmutableList <string> .Empty.Add(Polling.NAME).Add(WebSocket.NAME);

            _policyPort      = options.PolicyPort != 0 ? options.PolicyPort : 843;
            _rememberUpgrade = options.RememberUpgrade;
            _cookies         = options.Cookies;
            if (options.IgnoreServerCertificateValidation)
            {
                ServerCertificate.IgnoreServerCertificateValidation();
            }
            ExtraHeaders = options.ExtraHeaders;
        }
Exemplo n.º 6
0
        private void FillItem(string Mode, int ID)
        {
            tblList.Visible = false;
            tblItem.Visible = true;
            ddlCertificate.Items.Clear();
            ddlCertificate.DataSource     = SPA.Certificate.Items();
            ddlCertificate.DataTextField  = "Name";
            ddlCertificate.DataValueField = "ID";
            ddlCertificate.DataBind();
            ddlCertificate.Items.Insert(0, new ListItem("Choose", "0"));

            ServerCertificate item = new ServerCertificate(ID);

            try {
                bool isView = (Mode == "View");
                bool isNew  = (ID == 0);
                btnDelete.Visible = !isView && ID != 0;

                ddlCertificate.SelectedIndex = -1;
                try { ddlCertificate.Items.FindByValue(item.CertificateID.ToString()).Selected = true; } catch { }
                ddlCertificate.Visible  = !isView;
                lblNameView.Text        = new Certificate(item.CertificateID).Name;
                lblNameView.Visible     = isView;
                lblNameRequired.Visible = !isView;

                lblCreatedInfo.Text    = string.Format("Created at {0} by {1}", SPA.Common.ConvertUTCToWebLocalTime(SPContext.Current.Web, item.CreatedOn), item.CreatedBy);
                lblCreatedInfo.Visible = (item.ID != 0);
                lblUpdatedInfo.Text    = string.Format("Last modified at {0} by {1}", SPA.Common.ConvertUTCToWebLocalTime(SPContext.Current.Web, item.ModifiedOn), item.ModifiedBy);
                lblUpdatedInfo.Visible = (item.ID != 0);

                btnSave.Visible = !isView;
                btnCancel.Text  = isView ? "Close" : "Cancel";
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
                if (ShowDebug)
                {
                    lblErrorMessage.Text = ex.ToString();
                }
            }
        }
Exemplo n.º 7
0
        public Socket(Socket.Options options)
        {
            if (options.Host != null)
            {
                string[] strArray = options.Host.Split(':');
                options.Hostname = strArray[0];
                if (strArray.Length > 1)
                {
                    options.Port = int.Parse(strArray[strArray.Length - 1]);
                }
            }

            this.Secure   = options.Secure;
            this.Hostname = options.Hostname;
            this.Port     = options.Port;
            this.Query    = options.QueryString != null?ParseQS.Decode(options.QueryString) : new Dictionary <string, string>();

            if (options.Query != null)
            {
                foreach (KeyValuePair <string, string> keyValuePair in options.Query)
                {
                    this.Query.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }

            this.Upgrade           = options.Upgrade;
            this.Path              = (options.Path ?? "/engine.io").Replace("/$", "") + "/";
            this.TimestampParam    = options.TimestampParam ?? "t";
            this.TimestampRequests = options.TimestampRequests;
            this.Transports        = options.Transports ?? ImmutableList <string> .Empty.Add(Polling.NAME).Add(WebSocket.NAME);

            this.PolicyPort      = options.PolicyPort != 0 ? options.PolicyPort : 843;
            this.RememberUpgrade = options.RememberUpgrade;
            this.Cookies         = options.Cookies;
            if (options.IgnoreServerCertificateValidation)
            {
                ServerCertificate.IgnoreServerCertificateValidation();
            }
            this.ExtraHeaders = options.ExtraHeaders;
        }
Exemplo n.º 8
0
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            if (ServerCertificate != null)
            {
                info.AddValue("ServerCertificate", Convert.ToBase64String(ServerCertificate.GetRawCertData()));
            }
            else
            {
                info.AddValue("ServerCertificate", null, typeof(string));
            }

            if (RootCertificateAuthority != null)
            {
                info.AddValue("RootCertificateAuthority", Convert.ToBase64String(RootCertificateAuthority.GetRawCertData()));
            }
            else
            {
                info.AddValue("RootCertificateAuthority", null, typeof(string));
            }
        }
Exemplo n.º 9
0
        public Socket(Options options)
        {
            if (options.Host != null)
            {
                var pieces = options.Host.Split(':');
                options.Hostname = pieces[0];
                if (pieces.Length > 1)
                {
                    options.Port = int.Parse(pieces[pieces.Length - 1]);
                }
            }

            Secure   = options.Secure;
            Hostname = options.Hostname;
            Port     = options.Port;
            Proxy    = options.Proxy;
            Query    = options.QueryString != null?ParseQS.Decode(options.QueryString) : new Dictionary <string, string>();

            Upgrade           = options.Upgrade;
            Path              = (options.Path ?? "/engine.io").Replace("/$", "") + "/";
            TimestampParam    = (options.TimestampParam ?? "t");
            TimestampRequests = options.TimestampRequests;
            var defaultTransport = new List <string>();

            defaultTransport.Add(Polling.NAME);
            defaultTransport.Add(WebSocket.NAME);


            Transports      = options.Transports ?? defaultTransport;
            PolicyPort      = options.PolicyPort != 0 ? options.PolicyPort : 843;
            RememberUpgrade = options.RememberUpgrade;
            Cookies         = options.Cookies;
            if (options.IgnoreServerCertificateValidation)
            {
                ServerCertificate.IgnoreServerCertificateValidation();
            }
        }
Exemplo n.º 10
0
        private void DeleteItem()
        {
            bool success = false;

            try {
                ServerCertificate item = new ServerCertificate(int.Parse(hfItemID.Value));
                if (item.Delete())
                {
                    success        = true;
                    hfItemID.Value = "0";
                }
                if (success)
                {
                    Fill();
                }
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
                if (ShowDebug)
                {
                    lblErrorMessage.Text = ex.ToString();
                }
            }
            Response.Redirect(string.Format("{0}/{1}?View=Edit&ID={2}&ServerID={2}&IsDlg=1Filter={3}", SPContext.Current.Web.Url, Pages.ServerItem.PAGE_URL, ServerID, Filter), false);
        }
 private bool ValidateCertificate(X509Certificate2 cert)
 {
     if (!QueryCertificateTrusted(cert))
     {
         return(false);
     }
     if (cert is null || ServerCertificate is null)
     {
         return(false);
     }
     if (cert.Issuer != ServerCertificate.Issuer)
     {
         return(false);
     }
     if (cert.GetSerialNumberString() != ServerCertificate.GetSerialNumberString())
     {
         return(false);
     }
     if (cert.GetCertHashString() != ServerCertificate.GetCertHashString())
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 12
0
 public MonoServer(ServerFactory factory, IPEndPoint endpoint, ServerCertificate pfx, IServerParameters parameters)
     : base(factory, endpoint, parameters)
 {
     Certificate = pfx;
 }
Exemplo n.º 13
0
 public OpenSslServer(ServerFactory factory, IPEndPoint endpoint, ServerCertificate certificate, IServerParameters parameters)
     : base(factory, endpoint, parameters)
 {
     Certificate = certificate;
 }