protected void Page_Load(object sender, EventArgs e) { Session.Remove("errorText"); string result = Request["result"]; if (result != null && result.Length % 4 == 0) { result = SignHandler.Base64Decode(result); } if (result != null && "ok" == result.ToLower()) { var loginData = Request["signature"]; var textToBeSigned = (string)Session["signText"]; var signTextTransformation = (string)Session["signTransformation"]; var logonto = ConfigurationManager.AppSettings["logonto"]; var signTextFormat = (String)Session["signTextFormat"]; if (logonto == null || "".Equals(logonto.Trim())) { throw new ConfigurationErrorsException("Fejl: Logonto / friendlyname mangler, eller er tom i konfigurationen"); } SignatureValidationStatus status = null; if ("pdf".Equals(signTextFormat)) { status = SignHandler.validateSignatureAgainstAgreementPDF(loginData, textToBeSigned, Challenge(), logonto); } else { status = SignHandler.ValidateSignatureAgainstAgreement(loginData, textToBeSigned, signTextTransformation, Challenge(), logonto); } if (!(status.Certificate is MocesCertificate)) { Session.Add("errorText", "Det benyttede certifikat er ikke af korrekt type. Forventede medarbejdercertifikat, fik " + ErrorHandler.CertificateType(status)); } else if (status.CertificateStatus != CertificateStatus.Valid) { Session.Add("errorText", "Certifikatet er " + ErrorHandler.GetCertificateStatusText(status.CertificateStatus)); } else if (status.SignatureMatches) { Response.Redirect("signeringskvittering.aspx"); } else { Session.Add("errorText", "Signaturen matcher ikke teksten '" + textToBeSigned + "'."); } } else { Session.Add("errorText", ErrorHandler.GetErrorText(String.IsNullOrEmpty(result) ? "cancelsign" : result)); } }
protected void Page_Load(object sender, EventArgs e) { Session.Remove("errorText"); string result = Request["result"]; if (result != null && result.Length % 4 == 0) { result = SignHandler.Base64Decode(result); } if (result != null && "ok" == result.ToLower()) { var loginData = Request["signature"]; var textToBeSigned = (string)Session["signText"]; var signTextTransformation = (string)Session["signTransformation"]; var signTextFormat = (String)Session["signTextFormat"]; SignatureValidationStatus status = null; if ("pdf".Equals(signTextFormat)) { status = SignHandler.validateSignatureAgainstAgreementPDF(loginData, textToBeSigned, Challenge(), "DanID Test TU"); } else { status = SignHandler.ValidateSignatureAgainstAgreement(loginData, textToBeSigned, signTextTransformation, Challenge(), "DanID Test TU"); } if (!(status.Certificate is PocesCertificate)) { Session.Add("errorText", "Det benyttede certifikat er ikke af korrekt type. Forventede personligt certifikat, fik " + ErrorHandler.CertificateType(status)); } else if (status.CertificateStatus != CertificateStatus.Valid) { Session.Add("errorText", "Certifikatet er " + ErrorHandler.GetCertificateStatusText(status.CertificateStatus)); } else if (status.SignatureMatches) { Response.Redirect("signeringskvittering.aspx"); } else { Session.Add("errorText", "Signaturen matcher ikke teksten '" + textToBeSigned + "'."); } } else { Session.Add("errorText", ErrorHandler.GetErrorText(String.IsNullOrEmpty(result) ? "cancelsign" : result)); } }
protected void Page_Load(object sender, EventArgs e) { var result = Request["result"]; if (result.Length % 4 == 0) { result = SignHandler.Base64Decode(result); } if ("ok" == result.ToLower()) { try { String friendlyName = ConfigurationManager.AppSettings.Get("logonto"); if (friendlyName == null || "".Equals(friendlyName.Trim())) { throw new ConfigurationException("Fejl: Logonto / friendlyname mangler, eller er tom i konfigurationen"); } string signature = SignHandler.Base64Decode(Request["signature"]); CertificateAndStatus certificateAndStatus = LogonHandler.ValidateAndExtractCertificateAndStatus(signature, Challenge(), friendlyName); if (certificateAndStatus.Certificate is PocesCertificate) { CertificateStatus status = certificateAndStatus.CertificateStatus; if (status == CertificateStatus.Valid) { Session.Add(KeyPid, ((PocesCertificate)certificateAndStatus.Certificate).Pid); if (Session[Global.CurrentUser] == null) { var randomUserName = ChallengeGenerator.GenerateChallenge(); Session.Add(Global.CurrentUser, randomUserName); } if (!Roles.IsUserInRole((string)Session[Global.CurrentUser], "poces")) { Roles.AddUserToRole((string)Session[Global.CurrentUser], "poces"); } FormsAuthentication.RedirectFromLoginPage((string)Session[Global.CurrentUser], false); } else { Session.Add("errorText", "Certifikatet er " + ErrorHandler.GetCertificateStatusText(status)); } } else { Session.Add("notPoces", true); } } catch (NonOcesCertificateException) { Session.Add("errorText", "Ikke et OCES-certifikat"); } catch (Exception ex) { Session.Add("errorText", "Ukendt server-fejl: " + ex.Message); } } else { Session.Add("errorText", ErrorHandler.GetErrorText(result)); } }
protected void Page_Load(object sender, EventArgs e) { var result = Request["result"]; if (result.Length % 4 == 0) { result = SignHandler.Base64Decode(result); } if ("ok" == result.ToLower()) { try { String logonto = ConfigurationManager.AppSettings["logonto"]; if (logonto == null || "".Equals(logonto.Trim())) { throw new ConfigurationErrorsException("Error - logonto parameter from configuration is missing or empty"); } string signature = SignHandler.Base64Decode(Request["signature"]); CertificateAndStatus certificateAndStatus = LogonHandler.ValidateAndExtractCertificateAndStatus(signature, Challenge(), logonto); if (certificateAndStatus.Certificate is PocesCertificate || certificateAndStatus.Certificate is MocesCertificate) { CertificateStatus status = certificateAndStatus.CertificateStatus; if (status == CertificateStatus.Valid) { SetAttributesForMocesOrPoces(certificateAndStatus.Certificate); if (Session[Global.CurrentUser] == null) { var randomUserName = ChallengeGenerator.GenerateChallenge(); Session.Add(Global.CurrentUser, randomUserName); } if (!Roles.IsUserInRole((string)Session[Global.CurrentUser], "nemid")) { Roles.AddUserToRole((string)Session[Global.CurrentUser], "nemid"); } FormsAuthentication.RedirectFromLoginPage((string)Session[Global.CurrentUser], false); } else { Session.Add("errorText", "Certifikatet er " + ErrorHandler.GetCertificateStatusText(status)); } } else { Session.Add("notPocesOrMoces", true); } } catch (NonOcesCertificateException) { Session.Add("errorText", "Ikke et OCES-certifikat"); } catch (Exception) { Session.Add("errorText", "Ukendt server-fejl"); } } else { Session.Add("errorText", ErrorHandler.GetErrorText(result)); } }