public void GetSSHPublicKeyStringFromGitHubAccount_HTTPError_Test()
        {
            var nousername    = Guid.NewGuid().ToString("N");
            var pubKeysString = CertificateValidater.GetSSHPubKeyStrFromGitHubAccount(nousername);

            pubKeysString.IsNull();
        }
Exemplo n.º 2
0
        private byte[] UpdateCertificateInfo(ClickOnceAppInfo appInfo)
        {
            appInfo.SignedByPublisher = false;

            var certBin = default(byte[]);
            var tmpPath = default(string);

            try
            {
                tmpPath = ExtractEntryPointCommandFile(appInfo.Name);
                var cert = X509Certificate.CreateFromSignedFile(tmpPath);
                if (cert != null)
                {
                    certBin = cert.GetRawCertData();
                    this.ClickOnceFileRepository.SaveFileContent(appInfo.Name, ".cer", certBin);

                    if (appInfo.PublisherName != null)
                    {
                        var sshPubKeyStr = CertificateValidater.GetSSHPubKeyStrFromGitHubAccount(appInfo.PublisherName);
                        appInfo.SignedByPublisher = CertificateValidater.EqualsPublicKey(sshPubKeyStr, cert);
                    }
                }
            }
            catch (CryptographicException) { }
            finally { if (tmpPath != null)
                      {
                          System.IO.File.Delete(tmpPath);
                      }
            }

            appInfo.HasCodeSigning = certBin != null;
            return(certBin);
        }
        public void GetSSHPublicKeyStringFromGitHubAccount_Test()
        {
            var pubKeysString = CertificateValidater.GetSSHPubKeyStrFromGitHubAccount("Haacked");

            var _1stPubKeyStr = pubKeysString.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).First();
            var pubKeyParts   = _1stPubKeyStr.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            pubKeyParts.First().Is("ssh-rsa");

            var pubKeyBin = Convert.FromBase64String(pubKeyParts.Last());

            string.Join("", pubKeyBin
                        .Skip(4) // byte size of algorithm identifier
                        .Take(7) // "ssh-rsa"
                        .Select(n => (char)n))
            .Is("ssh-rsa");
        }
Exemplo n.º 4
0
        public ActionResult Edit(string id, ClickOnceAppInfo model, bool disclosePublisher)
        {
            var result = GetMyAppInfo(id);

            if (result is ActionResult)
            {
                return(result as ActionResult);
            }

            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

            var appInfo = result as ClickOnceAppInfo;

            appInfo.Title       = model.Title;
            appInfo.Description = model.Description;
            appInfo.ProjectURL  = model.ProjectURL;
            SetupPublisherInformtion(disclosePublisher, appInfo);

            appInfo.SignedByPublisher = false;
            if (appInfo.HasCodeSigning == null)
            {
                UpdateCertificateInfo(appInfo);
            }
            else if (appInfo.HasCodeSigning == true && appInfo.PublisherName != null)
            {
                var tmpPath = Server.MapPath($"~/App_Data/{Guid.NewGuid():N}.cer");
                try
                {
                    var certBin = this.ClickOnceFileRepository.GetFileContent(id, ".cer");
                    System.IO.File.WriteAllBytes(tmpPath, certBin);
                    var sshPubKeyStr = CertificateValidater.GetSSHPubKeyStrFromGitHubAccount(appInfo.PublisherName);
                    appInfo.SignedByPublisher = CertificateValidater.EqualsPublicKey(sshPubKeyStr, tmpPath);
                }
                finally { System.IO.File.Delete(tmpPath); }
            }

            this.ClickOnceFileRepository.SaveAppInfo(id, appInfo);

            var from = Request.QueryString["from"];

            return(from == "detail" ? RedirectToRoute("Detail", new { appId = appInfo.Name }) : RedirectToAction("MyApps", "Home"));
        }