Esempio n. 1
0
        /// <summary>
        ///     A check to see if
        /// </summary>
        private void PerformStartupCheck()
        {
            var version   = _version.ToString();
            var challenge = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            var signature = Certs.SignData(_email, _licenseKey, version, challenge);

            try
            {
                StartupResponseV1 response;
                using (var client = new LicenseV1Client(new BasicHttpBinding(), new EndpointAddress(_licenseServer)))
                    response = client.Startup(_email, _licenseKey, version, challenge, signature);

                if (!Certs.VerifyData(response.Signature, response.InstanceId, response.Email, response.LicenseKey, response.ActiveInstances, response.SupportInstances, response.Challenge))
                {
                    throw new Exception();
                }

                _instanceId       = response.InstanceId;
                _activeInstances  = response.ActiveInstances;
                _supportInstances = response.SupportInstances;
            }
            catch (FaultException <LicenseFault> exception)
            {
                throw new SecurityException(exception.Detail.Fault);
            }
            catch (Exception)
            {
                throw new SecurityException(_verifyError);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Perform a server call
        /// </summary>
        /// <returns></returns>
        private XElement PerformServerCall(string url, XElement xml)
        {
            try
            {
                if (xml.Element("signature") == null)
                {
                    var signData = xml.Elements().TakeWhile(element => element.Name != "signature").Select(element => (string)element).ToArray();
                    xml.Add(new XElement("signature", Certs.SignData(signData)));
                }


                byte[] buffer;
                using (var ms = new MemoryStream())
                {
                    xml.Save(ms);
                    buffer = ms.ToArray();
                }

                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method        = "POST";
                request.ContentType   = "text/xml";
                request.ContentLength = buffer.Length;

                var stream = request.GetRequestStream();
                stream.Write(buffer, 0, buffer.Length);
                stream.Close();

                XElement result;
                var      response = request.GetResponse();
                using (var sr = new StreamReader(response.GetResponseStream()))
                    result = XElement.Parse(sr.ReadToEnd());

                if (result.Name == "error")
                {
                    throw new SecurityException(result.Value);
                }

                var signature = (string)result.Element("signature");
                if (string.IsNullOrEmpty(signature))
                {
                    return(null);
                }

                var data = result.Elements().TakeWhile(element => element.Name != "signature").Select(element => (string)element).ToArray();
                if (!Certs.VerifyData(signature, data))
                {
                    return(null);
                }

                return(result);
            }
            catch (SecurityException)
            {
                throw;
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     This tells the server the directeve instance has been closed
        /// </summary>
        internal void QuitDirectEve()
        {
            // Fire & forget
            try
            {
                var challenge = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                var signature = Certs.SignData(_email, _licenseKey, _instanceId, challenge);

                using (var client = new LicenseV1Client(new BasicHttpBinding(), new EndpointAddress(_licenseServer)))
                    client.Shutdown(_email, _licenseKey, _instanceId, challenge, signature);
            }
            catch
            {
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     This pulses the server to keep it alive
        /// </summary>
        private void PulseThread()
        {
            try
            {
                var challenge = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                var signature = Certs.SignData(_email, _licenseKey, _instanceId, challenge);

                UpdateResponseV1 response;
                using (var client = new LicenseV1Client(new BasicHttpBinding(), new EndpointAddress(_licenseServer)))
                    response = client.KeepAlive(_email, _licenseKey, _instanceId, challenge, signature);

                _pulseResult = Certs.VerifyData(response.Signature, response.InstanceId, response.Challenge);
            }
            catch (Exception)
            {
                // An exception is not good :)
                _pulseResult = false;
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Load the DirectEve license
        /// </summary>
        private void LoadLicense()
        {
            var path        = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var licensePath = Path.Combine(path, "DirectEve.lic");

            if (!File.Exists(licensePath))
            {
                RetrieveAnonymousLicense(licensePath);
            }

            var license    = XElement.Load(licensePath);
            var email      = (string)license.Element("email");
            var licenseKey = (Guid?)license.Element("licensekey") ?? Guid.Empty;
            var signature  = (string)license.Element("signature");

            if (!Certs.VerifyData(signature, email, licenseKey))
            {
                throw new SecurityException(_invalidSupportLicense);
            }

            _email      = email;
            _licenseKey = licenseKey;
        }