public WebApiClient(string urlBase = null, string urlController = null) : base(CertValidator.CertHandler) { CertValidator.HandleCertValidation(); var isUrlBaseNull = string.IsNullOrWhiteSpace(urlBase); if (isUrlBaseNull && string.IsNullOrWhiteSpace(urlController)) { if (!string.IsNullOrWhiteSpace(UrlBaseWebApi)) { BaseAddress = new Uri(UrlBaseWebApi); } } else { if (!isUrlBaseNull) { UrlBaseWebApi = urlBase; BaseAddress = new Uri(UrlBaseWebApi); } UrlController = urlController; } InitHeaders(); //Timeout = TimeSpan.FromMinutes(5); }
void client_CertificateReceived(object sender, ComponentPro.Security.CertificateReceivedEventArgs e) { CertValidator dlg = new CertValidator(); CertificateVerificationStatus status = e.Status; CertificateVerificationStatus[] values = (CertificateVerificationStatus[])Enum.GetValues(typeof(CertificateVerificationStatus)); StringBuilder sbIssues = new StringBuilder(); bool showAddTrusted = false; for (int i = 0; i < values.Length; i++) { // Matches the validation status? if ((status & values[i]) == 0) { continue; } // The issue is processed. status ^= values[i]; sbIssues.AppendFormat("{0}\r\n", GetCertProblem(values[i], e.ErrorCode, ref showAddTrusted)); } dlg.Certificate = e.ServerCertificates[0]; dlg.Issues = sbIssues.ToString(); dlg.ShowAddToTrustedList = showAddTrusted; dlg.ShowDialog(); e.AddToTrustedRoot = dlg.AddToTrustedList; e.Accept = dlg.Accepted; }
public async Task <IActionResult> Get() { try { var clientCert = Request.HttpContext.Connection.ClientCertificate; // Validate signature var(msgErrorSign, certOut, type) = await ValidateSignatureAsync(Request); if (!string.IsNullOrEmpty(msgErrorSign)) { return(CreateErrorResponse(msgErrorSign, clientCert == null ? "Client cert emtpy." : "")); } // Return client cert information if (clientCert != null) { var sans = CertValidator.ParseOneRecordIDs(clientCert); return(CreateResultResponse(clientCert, sans)); } // Return signed cert in config, maybe this cert must get from URA return(CreateResultResponse(certOut)); } catch (Exception ex) { return(CreateExceptionResponse(ex)); } }
/// <summary> /// The function base process the return data to client /// </summary> /// <param name="cert">X509Certificate2 data</param> /// <returns></returns> private JsonResult ProcessRequest(X509Certificate2 cert) { return(new JsonResult(new OneRecordDummyResponse { subcriberID = new OneRecordTLSID { desc = Constants.TYPE_USER_CERTIFICATE, subjectDN = cert?.Subject, validFrom = "" + cert?.NotBefore, validTo = "" + cert?.NotAfter, issuerDN = cert?.Issuer, lastAuthenticatedAt = "" + DateTime.UtcNow, oneRecordIDList = CertValidator.ParseOneRecordIDs(cert) }, result = new OneRecordDummyData(), timestamp = DateTime.UtcNow.Ticks, message = Constants.VERIFY_OK, })); }
private async void Save() { try { CertValidator validatorWorkCompenstation = new CertValidator(); var result3 = validatorWorkCompenstation.Validate(CompensationCert); if (!result3.IsValid) { var firstError = result3.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } CertValidator validatorPublicLiability = new CertValidator(); var result = validatorPublicLiability.Validate(PublicLiabilityCert); if (!result.IsValid) { var firstError = result.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } CertValidator validatorProductLiability = new CertValidator(); var result1 = validatorProductLiability.Validate(ProductLiabilityCert); if (!result1.IsValid) { var firstError = result1.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } for (int j = 0; j < LicenceCerts.Count; j++) { CertValidator validatorLicences2 = new CertValidator(); var result2 = validatorLicences2.Validate(LicenceCerts[j]); if (!result2.IsValid) { var firstError = result2.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } } if (IsCheckVerify == false) { mMessageboxService.ShowToast("Please verify this is information is true "); View.ScrollToBottom(); return; } if (IsTickPublicLiability != true) { PublicLiabilityCert.CertItem.Amount = null; PublicLiabilityCert.CertItem.Document = null; PublicLiabilityCert.CertItem.Expiry = null; } if (IsTickProductLiability != true) { ProductLiabilityCert.CertItem.Amount = null; ProductLiabilityCert.CertItem.Document = null; ProductLiabilityCert.CertItem.Expiry = null; } if (IsTickCompensation != true) { CompensationCert.CertItem.Document = null; CompensationCert.CertItem.Expiry = null; } mCompanyProfile.Certs[0] = CompensationCert.CertItem; mCompanyProfile.Certs[1] = PublicLiabilityCert.CertItem; mCompanyProfile.Certs[2] = ProductLiabilityCert.CertItem; mCompanyProfile.Certs[3] = GSTRegisteredCert.CertItem; for (int i = 0; i < LicenceCerts.Count; i++) { mCompanyProfile.Certs.Add(LicenceCerts[i].CertItem); } mCompanyProfile.ProfileCompletionStep = ProfileCompletionStep.CPComplete; mCompanyProfile.StatementAgree = DateTime.Now; mPlatformService.ShowNetworkIndicator(); mProgressDialogService.ShowProgressDialog(); while (!Mvx.Resolve <ITaskManagementService>().IsAllTaskDone()) { int numOfImages = Mvx.Resolve <ITaskManagementService>().NumberOfTasksRunning(); if (numOfImages > 0) { string uploadStr = numOfImages + (numOfImages > 1 ? " images " : " image ") + "processing"; mProgressDialogService.ShowProgressDialog(uploadStr); } else { mProgressDialogService.ShowProgressDialog(""); } await Task.Delay(150); } var response = await mApiService.CreateCompanyProfile(mCompanyProfile); mPlatformService.HideNetworkIndicator(); mProgressDialogService.HideProgressDialog(); if (response.StatusCode == System.Net.HttpStatusCode.OK) { mCacheService.IsShowProfileView = true; mMessageboxService.ShowToast("Company Profile Complete"); Mvx.Resolve <ITrackingService>().SendEvent("Company Profile completed"); ViewModelAction action = new ViewModelAction { ActionType = ViewModelActionType.Reload, ViewModelType = typeof(ProfileViewModel), Data = "COMPLETED_PROFILE" }; Mvx.Resolve <IMvxMessenger>().Publish(new ViewModelActionMessage(this, action)); BackToViewModel <MainViewModel>(); } else { RefreshListLicences(); if (!string.IsNullOrEmpty(response.ErrorData)) { string errorData = response.ErrorData; ErrorLoginResponse err = JsonConvert.DeserializeObject <ErrorLoginResponse>(errorData); mMessageboxService.ShowToast(err.Description); } } } catch (Exception ex) { RefreshListLicences(); mMessageboxService.Show("Error", ex.Message); } }
public bool AsExpected(JwtSecurityTokenRequirement requirement) { bool asExpected = true; JwtSecurityTokenRequirement controlRequirement = new JwtSecurityTokenRequirement(); if (requirement == null) { return(false); } Assert.IsFalse( MaxTokenSizeInBytes != null && MaxTokenSizeInBytes.Value != requirement.MaximumTokenSizeInBytes, string.Format(CultureInfo.InvariantCulture, "MaximumTokenSizeInBytes (expected, config): '{0}'. '{1}'.", MaxTokenSizeInBytes.ToString(), requirement.MaximumTokenSizeInBytes.ToString())); Assert.IsFalse( MaxTokenSizeInBytes == null && requirement.MaximumTokenSizeInBytes != controlRequirement.MaximumTokenSizeInBytes, string.Format(CultureInfo.InvariantCulture, "MaximumTokenSizeInBytes should be default (default, config): '{0}'. '{1}'.", controlRequirement.MaximumTokenSizeInBytes.ToString(), requirement.MaximumTokenSizeInBytes.ToString())); Assert.IsFalse( MaxClockSkew != null && MaxClockSkew.Value != requirement.MaxClockSkew, string.Format(CultureInfo.InvariantCulture, "MaxClockSkew (expected, config): '{0}'. '{1}'.", MaxClockSkew.ToString(), requirement.MaxClockSkew.ToString())); Assert.IsFalse( MaxClockSkew == null && requirement.MaxClockSkew != controlRequirement.MaxClockSkew, string.Format(CultureInfo.InvariantCulture, "MaxClockSkew should be default (default, config): '{0}'. '{1}'.", controlRequirement.MaxClockSkew.ToString(), requirement.MaxClockSkew.ToString())); Assert.IsFalse( DefaultTokenLifetimeInMinutes != null && DefaultTokenLifetimeInMinutes.Value != requirement.DefaultTokenLifetimeInMinutes, string.Format(CultureInfo.InvariantCulture, "DefaultTokenLifetimeInMinutes (expected, config): '{0}'. '{1}'.", DefaultTokenLifetimeInMinutes.ToString(), requirement.DefaultTokenLifetimeInMinutes.ToString())); Assert.IsFalse( DefaultTokenLifetimeInMinutes == null && requirement.DefaultTokenLifetimeInMinutes != controlRequirement.DefaultTokenLifetimeInMinutes, string.Format(CultureInfo.InvariantCulture, "DefaultTokenLifetimeInMinutes should be default (default, config): '{0}'. '{1}'.", controlRequirement.DefaultTokenLifetimeInMinutes.ToString(), requirement.DefaultTokenLifetimeInMinutes.ToString())); // make sure nameclaim and roleclaim are same, or null together. Assert.IsFalse(NameClaimType == null && requirement.NameClaimType != null, "NameClaimType == null && requirement.NameClaimType != null"); Assert.IsFalse(NameClaimType != null && requirement.NameClaimType == null, "NameClaimType != null && requirement.NameClaimType == null"); if ((NameClaimType != null && requirement.NameClaimType != null) && (NameClaimType != requirement.NameClaimType)) { Assert.Fail(string.Format(CultureInfo.InvariantCulture, "NameClaimType (expected, config): '{0}'. '{1}'.", NameClaimType, requirement.NameClaimType)); asExpected = false; } Assert.IsFalse(RoleClaimType == null && requirement.RoleClaimType != null, "RoleClaimType == null && requirement.RoleClaimType != null"); Assert.IsFalse(RoleClaimType != null && requirement.RoleClaimType == null, "RoleClaimType != null && requirement.RoleClaimType == null"); if ((RoleClaimType != null && requirement.RoleClaimType != null) && (RoleClaimType != requirement.RoleClaimType)) { Assert.Fail(string.Format(CultureInfo.InvariantCulture, "RoleClaimType (expected, config): '{0}'. '{1}'.", RoleClaimType, requirement.RoleClaimType)); asExpected = false; } // != null => this variation sets a custom validator. if (CertValidator != null) { if (requirement.CertificateValidator == null) { return(false); } Assert.IsFalse(CertValidator.GetType() != requirement.CertificateValidator.GetType(), string.Format("CertificateValidator.GetType() != requirement.CertificateValidator.GetType(). (expected, config): '{0}'. '{1}'.", CertValidator.GetType(), requirement.CertificateValidator.GetType())); } else { if (CertValidationMode.HasValue || CertRevocationMode.HasValue || CertStoreLocation.HasValue) { Assert.IsFalse(requirement.CertificateValidator == null, string.Format("X509CertificateValidationMode.HasValue || X09RevocationMode.HasValue || StoreLocation.HasValue is true, there should be a validator")); // get and check _certificateValidationMode Type type = requirement.CertificateValidator.GetType(); FieldInfo fi = type.GetField("validator", BindingFlags.NonPublic | BindingFlags.Instance); X509CertificateValidator validator = (X509CertificateValidator)fi.GetValue(requirement.CertificateValidator); // make sure we created the right validator if (CertValidationMode == CertMode.ChainTrust && (validator.GetType() != X509CertificateValidator.ChainTrust.GetType()) || CertValidationMode == CertMode.PeerTrust && (validator.GetType() != X509CertificateValidator.PeerTrust.GetType()) || CertValidationMode == CertMode.PeerOrChainTrust && (validator.GetType() != X509CertificateValidator.PeerOrChainTrust.GetType()) || CertValidationMode == CertMode.None && (validator.GetType() != X509CertificateValidator.None.GetType())) { Assert.Fail(string.Format(CultureInfo.InvariantCulture, "X509CertificateValidator type. expected: '{0}', actual: '{1}'", CertValidationMode.HasValue ? CertValidationMode.Value.ToString() : "null", validator.GetType().ToString())); asExpected = false; } // if these 'Modes' HasValue, then it should be matched, otherwise expect default. fi = type.GetField("certificateValidationMode", BindingFlags.NonPublic | BindingFlags.Instance); CertMode certMode = (CertMode)fi.GetValue(requirement.CertificateValidator); if (CertValidationMode.HasValue) { Assert.IsFalse(CertValidationMode.Value != certMode, string.Format(CultureInfo.InvariantCulture, "X509CertificateValidationMode. expected: '{0}', actual: '{1}'", CertValidationMode.Value.ToString(), certMode.ToString())); // if mode includes chain building, revocation mode Policy s/b null. if (CertValidationMode.Value == X509CertificateValidationMode.ChainTrust || CertValidationMode.Value == X509CertificateValidationMode.PeerOrChainTrust) { // check inner policy if (CertRevocationMode.HasValue) { fi = type.GetField("chainPolicy", BindingFlags.NonPublic | BindingFlags.Instance); X509ChainPolicy chainPolicy = (X509ChainPolicy)fi.GetValue(requirement.CertificateValidator); Assert.IsFalse( chainPolicy.RevocationMode != CertRevocationMode.Value, string.Format( CultureInfo.InvariantCulture, "chainPolicy.RevocationMode. . expected: '{0}', actual: '{1}'", CertRevocationMode.Value.ToString(), chainPolicy.RevocationMode.ToString())); } } } } } return(asExpected); }
public string[] StringParams(string handler = JwtSecurityTokenHandlerType, string requirement = Elements.JwtSecurityTokenRequirement, string attributeEx1 = "", string attributeEx2 = "", string attributeEx3 = "", string attributeEx4 = "", string elementEx1 = comment, string elementEx2 = comment, string elementEx3 = comment, string elementEx4 = comment, string elementEx5 = comment, string elementEx6 = comment, string elementClose = closeRequirement) { return(new string[] { handler, requirement, CertRevocationMode == null ? string.Empty : Attribute(Attributes.RevocationMode, CertRevocationMode.Value.ToString()), attributeEx1, CertValidationMode == null ? string.Empty : Attribute(Attributes.ValidationMode, CertValidationMode.Value.ToString()), attributeEx2, CertValidator == null ? string.Empty : Attribute(Attributes.Validator, CertValidator.GetType().ToString() + ", System.IdentityModel.Tokens.JWT.Test"), attributeEx3, CertStoreLocation == null ? string.Empty : Attribute(Attributes.TrustedStoreLocation, CertStoreLocation.ToString()), attributeEx4, elementEx1, MaxClockSkew == null ? string.Empty : ElementValue(Elements.MaxClockSkewInMinutes, MaxClockSkew.Value.TotalMinutes.ToString()), elementEx2, MaxTokenSizeInBytes == null ? string.Empty : ElementValue(Elements.MaxTokenSizeInBytes, MaxTokenSizeInBytes.Value.ToString()), elementEx3, DefaultTokenLifetimeInMinutes == null ? string.Empty : ElementValue(Elements.DefaultTokenLifetimeInMinutes, DefaultTokenLifetimeInMinutes.Value.ToString()), elementEx4, NameClaimType == null ? string.Empty : ElementValue(Elements.NameClaimType, NameClaimType), elementEx5, RoleClaimType == null ? string.Empty : ElementValue(Elements.RoleClaimType, RoleClaimType), elementEx6, elementClose, }); }
private async void ShowNext() { try { View.HideKeyboard(); if (CurrentPage < 5) { CurrentPage += 1; } var personalProfileTemp = DataHelper.RetrieveFromUserPref <PersonalProfile>("PERSONAL_STEP"); if (personalProfileTemp != null) { mPersonalProfileLocal = personalProfileTemp; } if (CurrentPage == 2) { mPersonalProfileLocal.FirstName = FirstName; mPersonalProfileLocal.LastName = LastName; mPersonalProfileLocal.DOB = DOB; mPersonalProfileLocal.Mobile = MobileNumber; mPersonalProfileLocal.BulidingNo = UnitNumber; mPersonalProfileLocal.Street = StreetName; mPersonalProfileLocal.PostCode = PostCode; mPersonalProfileLocal.State = State; mPersonalProfileLocal.NOK = NOK; mPersonalProfileLocal.NOKPhone = NOKPhone; PersonalProfileValidator validatorPersonalProfile = new PersonalProfileValidator(); var result = validatorPersonalProfile.Validate(mPersonalProfileLocal); if (!result.IsValid) { CurrentPage -= 1; var firstError = result.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } View.PanToPage(CurrentPage); HightlightStep(true, true, false, false); if (personalProfileTemp != null) { mPersonalProfileLocal.ProfileCompletionStep = personalProfileTemp.ProfileCompletionStep; } else { mPersonalProfileLocal.ProfileCompletionStep = ProfileCompletionStep.PPStep1; } } else if (CurrentPage == 3) { CertValidator validatorConstructionCard = new CertValidator(); var result = validatorConstructionCard.Validate(ConstructionCardItem); if (!result.IsValid) { CurrentPage -= 1; var firstError = result.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } View.PanToPage(CurrentPage); HightlightStep(true, true, true, false); if (personalProfileTemp != null) { if (personalProfileTemp.Certs.Count > 0) { mPersonalProfileLocal.ProfileCompletionStep = personalProfileTemp.ProfileCompletionStep; mPersonalProfileLocal.Certs[0] = ConstructionCardItem.CertItem; } else { mPersonalProfileLocal.ProfileCompletionStep = ProfileCompletionStep.PPStep2; mPersonalProfileLocal.Certs.Add(ConstructionCardItem.CertItem); } } else { mPersonalProfileLocal.ProfileCompletionStep = ProfileCompletionStep.PPStep2; mPersonalProfileLocal.Certs.Add(ConstructionCardItem.CertItem); } } else if (CurrentPage == 4) { CertValidator validatorTraceLicense = new CertValidator(); var result = validatorTraceLicense.Validate(TraceLicenseItem); if (!result.IsValid) { CurrentPage -= 1; var firstError = result.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } View.PanToPage(CurrentPage); HightlightStep(true, true, true, true); if (personalProfileTemp != null) { if (personalProfileTemp.Certs.Count > 1) { mPersonalProfileLocal.ProfileCompletionStep = personalProfileTemp.ProfileCompletionStep; mPersonalProfileLocal.Certs[1] = TraceLicenseItem.CertItem; } else { mPersonalProfileLocal.ProfileCompletionStep = ProfileCompletionStep.PPStep3; mPersonalProfileLocal.Certs.Add(TraceLicenseItem.CertItem); } } else { mPersonalProfileLocal.ProfileCompletionStep = ProfileCompletionStep.PPStep3; mPersonalProfileLocal.Certs.Add(TraceLicenseItem.CertItem); } } DataHelper.SaveToUserPref(mPersonalProfileLocal, "PERSONAL_STEP"); if (CurrentPage == 5) // Done button { CertValidator validatorIncomeInsuredCert = new CertValidator(); var result4 = validatorIncomeInsuredCert.Validate(IncomeInsured); if (!result4.IsValid) { var firstError = result4.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } CertValidator validatorFirstAidCert = new CertValidator(); var result5 = validatorFirstAidCert.Validate(FirstAidCertified); if (!result5.IsValid) { var firstError = result5.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } for (int i = 0; i < OperationalCerts.Count; i++) { CertValidator validatorOperationalCert = new CertValidator(); var result3 = validatorOperationalCert.Validate(OperationalCerts[i]); if (!result3.IsValid) { var firstError = result3.Errors.First(); mMessageboxService.ShowToast(firstError.ErrorMessage); return; } } if (IsVerify == false) { mMessageboxService.ShowToast("Please verify this information is true"); View.ScrollToBottom(); return; } mPlatformService.ShowNetworkIndicator(); mProgressDialogService.ShowProgressDialog(); while (!Mvx.Resolve <ITaskManagementService>().IsAllTaskDone()) { int numOfImages = Mvx.Resolve <ITaskManagementService>().NumberOfTasksRunning(); if (numOfImages > 0) { string uploadStr = numOfImages + (numOfImages > 1 ? " images " : " image ") + "processing"; mProgressDialogService.ShowProgressDialog(uploadStr); } else { mProgressDialogService.ShowProgressDialog(""); } await Task.Delay(150); } Debug.WriteLine("upload all image is done"); if (Mvx.Resolve <ITaskManagementService>().IsAllTaskDone()) { UserProfile.PersonalProfile.FirstName = FirstName; UserProfile.PersonalProfile.LastName = LastName; UserProfile.PersonalProfile.DOB = DOB; UserProfile.PersonalProfile.Mobile = MobileNumber; UserProfile.PersonalProfile.BulidingNo = UnitNumber; UserProfile.PersonalProfile.Street = StreetName; UserProfile.PersonalProfile.State = State; UserProfile.PersonalProfile.NOK = NOK; UserProfile.PersonalProfile.NOKPhone = NOKPhone; UserProfile.PersonalProfile.PostCode = PostCode; if (IsTickFirstAid != true) { FirstAidCertified.CertItem.Document = null; FirstAidCertified.CertItem.Expiry = null; } if (IsTickIncomeInsured != true) { IncomeInsured.CertItem.Document = null; IncomeInsured.CertItem.Expiry = null; } UserProfile.PersonalProfile.Certs[0] = ConstructionCardItem.CertItem; UserProfile.PersonalProfile.Certs[1] = TraceLicenseItem.CertItem; UserProfile.PersonalProfile.Certs[2] = IncomeInsured.CertItem; UserProfile.PersonalProfile.Certs[3] = FirstAidCertified.CertItem; UserProfile.PersonalProfile.Certs[4] = GSTRegistered.CertItem; UserProfile.PersonalProfile.Certs[6] = PublicLiablityCert.CertItem; for (int k = 0; k < OperationalCerts.Count; k++) { UserProfile.PersonalProfile.Certs.Add(OperationalCerts[k].CertItem); } UserProfile.PersonalProfile.StatementAgree = DateTime.Now; UserProfile.PersonalProfile.ProfileCompletionStep = ProfileCompletionStep.PPComplete; var response = await mApiService.CreatePersonalProfile(UserProfile.PersonalProfile); mPlatformService.HideNetworkIndicator(); mProgressDialogService.HideProgressDialog(); if (response.StatusCode == System.Net.HttpStatusCode.OK) { mCacheService.IsShowProfileView = true; Mvx.Resolve <ITrackingService>().SendEvent("Personal Profile completed"); View.ShowPopupFinish(); } else { RefreshListOperationalCert(); if (!string.IsNullOrEmpty(response.ErrorData)) { string errorData = response.ErrorData; ErrorLoginResponse err = JsonConvert.DeserializeObject <ErrorLoginResponse>(errorData); mMessageboxService.ShowToast(err.Description); } } } } } catch (Exception ex) { #if DEBUG RefreshListOperationalCert(); mMessageboxService.Show("Error", ex.Message); #endif } }