public void ValidateSignicatSignatureOutsideValidityTest()
        {
            var testxml  = EmbeddedResourceExtractor.GetString <NemidSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.nemid_signicat_sample.xml");
            var verifier = new NemidSignatureVerification(testxml);

            Assert.False(verifier.TryValidateSignature(DateTime.Parse("2016-01-01 02:10:31.296761+00"), true));
        }
        public void XmlSignatureVerificationBankIdSeTest()
        {
            var testxml  = EmbeddedResourceExtractor.GetString <BankIdSeSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.bankid-se_signicat_sample.xml");
            var verifier = new XmlSignatureVerification(testxml);

            Assert.True(verifier.ValidReferences.Count > 0);
            Assert.True(verifier.ValidateSignature(SystemTestBankIdSeRootCertificate, DateTime.Parse("2017-02-01 02:10:31.296761+00")));
        }
        public void XmlSignatureVerificationNemIdLoadTest()
        {
            var testxml  = EmbeddedResourceExtractor.GetString <BankIdSeSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.nemid_opensign_pocesII.xml");
            var verifier = new XmlSignatureVerification(testxml);

            Assert.True(verifier.ValidReferences.Count > 0);
            Assert.True(verifier.TryValidateSignature(SystemTestNemIdRootCertificate, DateTime.Parse("2016-01-01 02:10:31.296761+00")));
        }
        public ZklSteamHandler(TasClient tas)
        {
            this.tas = tas;
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libCSteamworks.so", "libCSteamworks.so");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libsteam_api.so", "libsteam_api.so");
            }
            else
            {
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.CSteamworks.dll", "CSteamworks.dll");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_api.dll", "steam_api.dll");
            }
            EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_appid.txt", "steam_appid.txt");

            SteamHelper              = new SteamClientHelper();
            SteamHelper.SteamOnline += () =>
            {
                SteamName = SteamHelper.GetMyName();
                friends   = SteamHelper.GetFriends();
                SteamID   = SteamHelper.GetSteamID();
                if (tas.IsLoggedIn && tas.MyUser != null && tas.MyUser.EffectiveElo != 0)
                {
                    OnLoggedToBothSteamAndTas();
                }
            };


            tas.MyExtensionsChanged += (sender, args) => { if (SteamHelper.IsOnline && SteamID != 0)
                                                           {
                                                               OnLoggedToBothSteamAndTas();
                                                           }
            };
            tas.UserExtensionsChanged += (sender, args) =>
            {
                if (args.Data.SteamID != null)
                {
                    Voice.AddListenerSteamID(args.Data.SteamID.Value);                            // todo only for battle in future
                }
                if (args.Data.SteamID != null && SteamID != 0 && friends.Contains(args.Data.SteamID.Value))
                {
                    AddFriend(args.Data.Name);
                }
            };

            tas.UserRemoved += (sender, args) =>
            {
                User us;
                if (tas.ExistingUsers.TryGetValue(args.Name, out us) && us.SteamID.HasValue)
                {
                    Voice.RemoveListenerSteamID(us.SteamID.Value);
                }
            };
        }
        public void ValidateSignicatSignatureTest()
        {
            var testxml  = EmbeddedResourceExtractor.GetString <BankIdSeSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.bankid-se_signicat_sample.xml");
            var verifier = new BankIdSeSignatureVerification(testxml);

            Assert.True(verifier.ValidateSignature(DateTimeOffset.Parse("2017-02-01 02:10:31.296761+00"), true));
            var jsonBase64Payload = verifier.UserNonVisibleData;
            var payload           = new SignicatPayload(jsonBase64Payload);

            Assert.True(payload.ValidateAttachment(0, EmbeddedResourceExtractor.GetStream <BankIdSeSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.bankid-se_signicat_sample.pdf")));
        }
        public void ValidateSignicatSignatureTest()
        {
            var testxml           = EmbeddedResourceExtractor.GetString <NemidSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.nemid_signicat_sample.xml");
            var verifier          = new NemidSignatureVerification(testxml);
            var jsonBase64Payload = verifier.SignatureProperties
                                    .Where(p => p.Name == "signicat")
                                    .Select(p => p.Value)
                                    .SingleOrDefault();

            Assert.True(verifier.ValidateSignature(DateTimeOffset.Parse("2016-09-01 02:10:31.296761+00"), true));

            var payload = new SignicatPayload(jsonBase64Payload);

            Assert.True(payload.ValidateAttachment(0, EmbeddedResourceExtractor.GetStream <NemidSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.nemid_signicat_sample.pdf")));
        }
Ejemplo n.º 7
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            tcCommandInstances.TabPages.Clear();
            try
            {
                EmbeddedResourceExtractor.Extract(C_FFMpegBinName, C_WorkFolderName);
            }
            catch (Exception eee)
            {
                MessageBox.Show("ffmpeg extraction failure: " + eee.Message);
            }

            if (File.Exists(pathOfLastSession()))
            {
                loadSession(pathOfLastSession());
            }
        }
        public void ExtractNativeSdoTest()
        {
            var testxml   = EmbeddedResourceExtractor.GetString <NemidSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.signicat_bankid-se_sample.xml");
            var ltSdoXDoc = XDocument.Parse(testxml);

            XNamespace nsLtv           = "https://id.signicat.com/definitions/xsd/LtvSdo-1.1";
            var        nativeSdoBase64 = ltSdoXDoc.Root?
                                         .Element(nsLtv + "NativeSignature")?
                                         .Element(nsLtv + "NativeSdo")?
                                         .Value;

            var originalDocumentBase64 = ltSdoXDoc.Root?
                                         .Element(nsLtv + "NativeSignature")?
                                         .Element(nsLtv + "OriginalDocument")?
                                         .Value;

            var nativeSdoBytes = Convert.FromBase64String(nativeSdoBase64);
            //File.WriteAllBytes(@"C:\repos\git\OnboardingCustomers\MobileLife.OBCO.DataTests\Signicat\Samples\bankid-se_signicat_sample.xml", nativeSdoBytes);

            var originalDocument = Convert.FromBase64String(originalDocumentBase64);
            //File.WriteAllBytes(@"C:\repos\git\OnboardingCustomers\MobileLife.OBCO.DataTests\Signicat\Samples\bankid-se_signicat_sample.pdf", originalDocument);
        }
Ejemplo n.º 9
0
 public void BankIdNoTestSignatureVerificationTest()
 {
     var testxml  = EmbeddedResourceExtractor.GetString <BankIdNoSignatureVerificationTests>("MobileLife.OBCO.DataTests.Signicat.Samples.bankid-no_signicat_sample.xml");
     var verifier = new BankIdNoSignatureVerification(testxml);
 }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            try
            {
                //Stopwatch stopWatch = new Stopwatch(); stopWatch.Start();
                Trace.Listeners.Add(new ConsoleTraceListener());


                if (Environment.OSVersion.Platform != PlatformID.Unix)
                {
                    var ver = GetNetVersionFromRegistry();
                    if (ver < 378675)
                    {
                        MessageBox.Show(new Form {
                            TopMost = true
                        },
                                        "Zero-K launcher needs Microsoft .NET framework 4.5.1\nPlease download and install it first",
                                        "Program is unable to run",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }

                Directory.SetCurrentDirectory(StartupPath);

                // extract fonts
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.SM.ttf", "SM.ttf");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.OpenSans-Regular.ttf", "OpenSans-Regular.ttf");

                Conf = new Config();

                IsSteamFolder = File.Exists(Path.Combine(StartupPath, "steamfolder.txt"));

                SelfUpdater = new SelfUpdater("Zero-K");

                StartupArgs = args;

                try
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Failed to set rendering compatibility: {0}", ex);
                }

                if (!Debugger.IsAttached)
                {
                    try
                    {
                        AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                        Thread.GetDomain().UnhandledException += UnhandledException;
                        Application.ThreadException += Application_ThreadException;
                        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceWarning("Failed to set exception handling :{0}", ex);
                    }
                }



                //HttpWebRequest.DefaultCachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                Trace.TraceInformation("Starting with version {0}", SelfUpdater.CurrentVersion);

                WebRequest.DefaultWebProxy = null;
                ThreadPool.SetMaxThreads(500, 2000);
                ServicePointManager.Expect100Continue = false;
                LoadConfig();



                Trace.Listeners.Add(new LogTraceListener());
                if (Environment.OSVersion.Platform != PlatformID.Unix && !Conf.UseExternalBrowser)
                {
                    Utils.SetIeCompatibility();                                                                                //set to current IE version
                }
                var contentDir = !string.IsNullOrEmpty(Conf.DataFolder) ? Conf.DataFolder : StartupPath;
                if (!Directory.Exists(contentDir) || !SpringPaths.IsDirectoryWritable(contentDir))
                {
                    var dc = new SelectWritableFolder {
                        SelectedPath = SpringPaths.GetMySpringDocPath()
                    };
                    if (dc.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    contentDir = dc.SelectedPath;
                }
                if (Conf.DataFolder != StartupPath)
                {
                    Conf.DataFolder = contentDir;
                }
                else
                {
                    Conf.DataFolder = null;
                }

                if (!SpringPaths.IsDirectoryWritable(StartupPath))
                {
                    var newTarget = Path.Combine(contentDir, "Zero-K.exe");
                    if (SelfUpdater.CheckForUpdate(newTarget, true))
                    {
                        Conf.Save(Path.Combine(contentDir, Config.ConfigFileName));
                        Process.Start(newTarget);
                        return;
                    }
                    MessageBox.Show(new Form {
                        TopMost = true
                    }, "Move failed, please copy Zero-K.exe to a writable folder");
                    return;
                }



                SpringPaths = new SpringPaths(contentDir, true, true);

                if (
                    MessageBox.Show(new Form()
                {
                    TopMost = true
                },
                                    "WARNING: Zero-K lobby is now obsolete. Starting Chobby instead, ok? ",
                                    "WARNING: launcher obsolete",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var targetPath = Path.Combine(SpringPaths.WritableDirectory, "Chobby.exe");
                    if (!File.Exists(targetPath))
                    {
                        var wc = new WebClient();
                        wc.DownloadFile(GlobalConst.BaseSiteUrl + "/lobby/Chobby.exe", targetPath);
                    }
                    Process.Start(targetPath);
                    Environment.Exit(0);
                }

                // speed up spring start
                SpringPaths.SpringVersionChanged += (sender, engine) =>
                {
                    ZkData.Utils.StartAsync(
                        () =>
                    {
                        UnitSync unitSync = null;
                        try
                        {
                            unitSync = new UnitSync(SpringPaths, engine);     // initialize unitsync to avoid slowdowns when starting

                            if (unitSync.UnitsyncWritableFolder != SpringPaths.WritableDirectory)
                            {
                                // unitsync created its cache in different folder than is used to start spring -> move it
                                var fi = ArchiveCache.GetCacheFile(unitSync.UnitsyncWritableFolder);
                                if (fi != null)
                                {
                                    File.Copy(fi.FullName, Path.Combine(SpringPaths.WritableDirectory, "cache", fi.Name), true);
                                }
                            }
                        }
                        finally
                        {
                            unitSync?.Dispose();
                        }
                    });
                };

                SaveConfig();


                // write license files
                try
                {
                    var path    = SpringPaths.WritableDirectory;
                    var pathGPL = Utils.MakePath(path, "license_GPLv3");
                    var gpl     = Encoding.UTF8.GetString(License.GPLv3);
                    if (!File.Exists(pathGPL))
                    {
                        File.WriteAllText(pathGPL, gpl);
                    }
                    var pathMIT = Utils.MakePath(path, "license_MIT");
                    var mit     = Encoding.UTF8.GetString(License.MITlicense);
                    if (!File.Exists(pathMIT))
                    {
                        File.WriteAllText(pathMIT, mit);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }



                if (Conf.IsFirstRun)
                {
                    if (!IsSteamFolder)
                    {
                        Utils.CreateDesktopShortcut();
                    }
                    if (Environment.OSVersion.Platform != PlatformID.Unix)
                    {
                        Utils.RegisterProtocol();
                    }
                }

                MetaData           = new MetaDataCache(SpringPaths);
                AutoJoinManager    = new AutoJoinManager();
                EngineConfigurator = new EngineConfigurator(SpringPaths.WritableDirectory);

                SpringScanner = new PlasmaResourceChecker(SpringPaths);
                SpringScanner.LocalResourceAdded   += (s, e) => Trace.TraceInformation("New resource found: {0}", e.Item.InternalName);
                SpringScanner.LocalResourceRemoved += (s, e) => Trace.TraceInformation("Resource removed: {0}", e.Item.InternalName);
                Downloader = new PlasmaDownloader.PlasmaDownloader(SpringScanner, SpringPaths); //rapid
                Downloader.DownloadAdded += (s, e) => Trace.TraceInformation("Download started: {0}", e.Data.Name);
                //Downloader.GetResource(DownloadType.ENGINE, GlobalConst.DefaultEngineOverride);

                var isLinux = Environment.OSVersion.Platform == PlatformID.Unix;
                TasClient = new TasClient(string.Format("ZK {0}{1}", SelfUpdater.CurrentVersion, isLinux ? " linux" : ""));

                SayCommandHandler = new SayCommandHandler(TasClient);

                ServerImages = new ServerImagesHandler(SpringPaths, TasClient);


                // log, for debugging
                TasClient.Connected     += (s, e) => Trace.TraceInformation("TASC connected");
                TasClient.LoginAccepted += (s, e) =>
                {
                    Trace.TraceInformation("TASC login accepted");
                    Trace.TraceInformation("Server is using Spring version {0}", TasClient.ServerSpringVersion);
                    if (Environment.OSVersion.Platform == PlatformID.Unix || Conf.UseExternalBrowser)
                    {
                        if (MainWindow != null)
                        {
                            MainWindow.navigationControl.Path = "battles";
                        }
                    }
                };

                TasClient.LoginDenied     += (s, e) => Trace.TraceInformation("TASC login denied");
                TasClient.ChannelJoined   += (s, e) => { Trace.TraceInformation("TASC channel joined: " + e.Name); };
                TasClient.ConnectionLost  += (s, e) => Trace.TraceInformation("Connection lost");
                TasClient.WelcomeReceived += (s, e) =>
                {
                    Downloader.GetResource(DownloadType.ENGINE, e.Engine);
                    Downloader.GetResource(DownloadType.RAPID, e.Game);
                };

                Program.AreYouReadyDialog = new AreYouReadyDialog(TasClient);

                // special handling
                TasClient.PreviewSaid += (s, e) =>
                {
                    var  tas  = (TasClient)s;
                    User user = null;
                    if (e.Data.UserName != null)
                    {
                        tas.ExistingUsers.TryGetValue(e.Data.UserName, out user);
                        if ((user != null && user.BanMute) || TasClient.Ignores.Contains(e.Data.UserName))
                        {
                            e.Cancel = true;
                        }
                    }
                };

                TasClient.SiteToLobbyCommandReceived += (eventArgs, o) =>
                {
                    if (MainWindow != null)
                    {
                        MainWindow.navigationControl.Path = o.Command;
                        MainWindow.PopupSelf();
                    }
                };

                ModStore = new ModStore();

                ConnectBar        = new ConnectBar(TasClient);
                ToolTip           = new ToolTipHandler();
                BrowserInterop    = new BrowserInterop(TasClient, Conf);
                BattleIconManager = new BattleIconManager();
                Application.AddMessageFilter(ToolTip);

                SteamHandler = new ZklSteamHandler(TasClient);

                MainWindow = new MainWindow();

                Application.AddMessageFilter(new ScrollMessageFilter());

                MainWindow.Size = new Size(
                    Math.Min(SystemInformation.VirtualScreen.Width - 30, MainWindow.Width),
                    Math.Min(SystemInformation.VirtualScreen.Height - 30, MainWindow.Height)); //in case user have less space than 1024x768

                BattleBar     = new BattleBar();
                VoteBar       = new VoteBar();
                PwBar         = new PwBar();
                MatchMakerBar = new MatchMakerBar(TasClient);

                SelfUpdater.ProgramUpdated += s =>
                {
                    Program.MainWindow.InvokeFunc(
                        () => WarningBar.DisplayWarning($"New version of Zero-K launcher downloaded, restart it to apply changes", "Restart", Restart));
                };
                if (!Debugger.IsAttached && !Conf.DisableAutoUpdate && !IsSteamFolder)
                {
                    SelfUpdater.StartChecking();
                }

                if (GlobalConst.Mode != ModeType.Local)
                {
                    SteamHandler.Connect();
                }
                Application.Run(MainWindow);

                ShutDown();
            }
            catch (Exception ex)
            {
                ErrorHandling.HandleException(ex, true);
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            finally
            {
                ShutDown();
            }
            if (ErrorHandling.HasFatalException && !CloseOnNext)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                Application.Restart();
            }
        }
Ejemplo n.º 11
0
        public ZklSteamHandler(TasClient tas)
        {
            this.tas = tas;
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                if (Environment.Is64BitProcess)
                {
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libCSteamworks-x86_64.so", "libCSteamworks.so");
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libsteam_api-x86_64.so", "libsteam_api.so");
                }
                else
                {
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libCSteamworks.so", "libCSteamworks.so");
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libsteam_api.so", "libsteam_api.so");
                }
            }
            else
            {
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.CSteamworks.dll", "CSteamworks.dll");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_api.dll", "steam_api.dll");
            }
            EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_appid.txt", "steam_appid.txt");

            SteamHelper              = new SteamClientHelper();
            SteamHelper.SteamOnline += () =>
            {
                SteamName = SteamHelper.GetMyName();
                friends   = SteamHelper.GetFriends();
                SteamID   = SteamHelper.GetSteamID();
                if (tas.IsLoggedIn && tas.MyUser != null)
                {
                    OnLoggedToBothSteamAndTas();
                }
            };


            tas.MyUserStatusChanged += (sender, args) => { if (SteamHelper.IsOnline && SteamID != 0)
                                                           {
                                                               OnLoggedToBothSteamAndTas();
                                                           }
            };
            tas.UserStatusChanged += (sender, args) =>
            {
                if (args?.New?.SteamID != null && args?.Old?.SteamID != args?.New?.SteamID && !string.IsNullOrEmpty(args?.New?.SteamID))
                {
                    Voice.AddListenerSteamID(ulong.Parse(args.New.SteamID)); // todo only for battle in future
                    if (friends.Contains(ulong.Parse(args.New.SteamID)))
                    {
                        AddFriend(args.New.Name);
                    }
                }
            };

            tas.UserRemoved += (sender, args) =>
            {
                User us;
                if (tas.ExistingUsers.TryGetValue(args.Name, out us) && !string.IsNullOrEmpty(us.SteamID))
                {
                    Voice.RemoveListenerSteamID(ulong.Parse(us.SteamID));
                }
            };
        }