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 EqualsPublicKey_NullSshPubKeyStr_False_Test() { var sshPubKeyString = default(string); var pathOfCertFile = PathOf("id_rsa.cer"); CertificateValidater.EqualsPublicKey(sshPubKeyString, pathOfCertFile) .IsFalse(); }
public void EqualsPublicKey_False_Test() { var sshPubKeyString = File.ReadAllText(PathOf("id_rsa.pub")); var pathOfCertFile = PathOf("another.cer"); CertificateValidater.EqualsPublicKey(sshPubKeyString, pathOfCertFile) .IsFalse(); }
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")); }