/// <summary> /// Initialize method implementation /// </summary> public override void Initialize(BaseProviderParams externalsystem) { try { if (!_isinitialized) { if (externalsystem is ExternalProviderParams) { ExternalProviderParams param = externalsystem as ExternalProviderParams; Data = param.Data; Enabled = param.Enabled; IsRequired = param.IsRequired; WizardEnabled = param.EnrollWizard; ForceEnrollment = param.ForceWizard; PinRequired = param.PinRequired; _isinitialized = true; return; } else { throw new InvalidCastException("Invalid SMS/External Provider !"); } } } catch (Exception ex) { this.Enabled = false; throw ex; } }
/// <summary> /// GetUserCodeWithExternalSystem method implementation for Azure MFA /// </summary> private int GetUserCodeWithExternalSystem(AuthenticationContext ctx, ExternalOTPProvider externalsys, CultureInfo culture) { ResourcesLocale Resources = new ResourcesLocale(ctx.Lcid); String NumberStr = ctx.PhoneNumber; int CountryCode = 0; ulong NationalNumber = 0; string extension = string.Empty; PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance(); PhoneNumber NumberProto = phoneUtil.Parse(NumberStr, culture.TwoLetterISOLanguageName.ToUpper()); CountryCode = NumberProto.CountryCode; NationalNumber = NumberProto.NationalNumber; if (NumberProto.HasExtension) { extension = NumberProto.Extension; } PhoneFactor.Initialize(externalsys); PhoneFactorParams Params = new PhoneFactorParams(); Params.Username = ctx.UPN; Params.CountryCode = CountryCode.ToString(); Params.Phone = NationalNumber.ToString(); Params.Extension = extension; Params.ApplicationName = "IdentityServer"; Params.Sha1Salt = externalsys.Sha1Salt; if (ctx.IsTwoWay) { Params.SmsText = string.Format(Resources.GetString(ResourcesLocaleKind.Azure, "SMSTwoWayMessage"), externalsys.Company); Params.Mode = PhoneFactor.MODE_SMS_TWO_WAY_OTP; } else { Params.SmsText = string.Format(Resources.GetString(ResourcesLocaleKind.Azure, "SMSMessage"), externalsys.Company); Params.Mode = PhoneFactor.MODE_SMS_ONE_WAY_OTP; } int callStatus; int errorId; string otp = string.Empty; if (PhoneFactor.Authenticate(Params, out otp, out callStatus, out errorId, externalsys.Timeout)) { if (ctx.IsTwoWay) { return((int)AuthenticationResponseKind.SmsTwoWayOTP); } else { return(Convert.ToInt32(otp)); } } else { return((int)AuthenticationResponseKind.Error); } }
/// <summary> /// GetCodeWithExternalSystem method implmentation /// </summary> public NotificationStatus GetCodeWithExternalSystem(Registration reg, ExternalOTPProvider externalsys, CultureInfo culture, out int otp) { SMS_strings.Culture = culture; SMSRuntime.Initialize(externalsys); SMSParams Params = new SMSParams(); try { int zotp = GetRandomOTP(); Params.IPhost = SMSRuntime.IPhost; Params.Password = SMSRuntime.Password; Params.SMSText = string.Format(SMS_strings.SMSMessage, externalsys.Company, zotp); Params.PhoneNumber = reg.PhoneNumber; int errorId; if (SMSRuntime.Authenticate(Params, out errorId, externalsys.Timeout)) { otp = zotp; return(NotificationStatus.ResponseSMSOTP); } else { otp = 0; return(NotificationStatus.Error); } } catch (Exception ex) { Log.WriteEntry("SMS SendMessage : \r" + ex.Message, EventLogEntryType.Error, 10000); otp = 0; return(NotificationStatus.Error); } }
/// <summary> /// GetCodeWithExternalSystem method implementation for Azure MFA /// </summary> public AuthenticationResponseKind GetCodeWithExternalSystem(MFAUser reg, ExternalOTPProvider externalsys, CultureInfo culture, out int otp) { // Compute and send your TOTP code and return his value if everything goes right if (true) { otp = 1230; return(AuthenticationResponseKind.SmsOTP); } else { return(AuthenticationResponseKind.Error); // return error } }
/// <summary> /// GetCodeWithExternalSystem demo method /// </summary> public NotificationStatus GetCodeWithExternalSystem(Registration reg, ExternalOTPProvider externalsys, CultureInfo culture, out int otp) { if (externalsys.IsTwoWay) { otp = Convert.ToInt32(NotificationStatus.ResponseSMSReply); return(NotificationStatus.ResponseSMSReply); } else { otp = Convert.ToInt32("1230"); return(NotificationStatus.ResponseSMSOTP); } }
/// <summary> /// Update method implmentation /// </summary> public void Load(PSHost host) { ManagementAdminService.Initialize(host, true); MFAConfig cfg = ManagementAdminService.ADFSManager.ReadConfiguration(host); ExternalOTPProvider otp = cfg.ExternalOTPProvider; this.IsDirty = cfg.IsDirty; this.Company = otp.Company; this.FullQualifiedImplementation = otp.FullQualifiedImplementation; this.IsTwoWay = otp.IsTwoWay; this.Sha1Salt = otp.Sha1Salt; this.Timeout = otp.Timeout; this.Parameters = otp.Parameters; }
/// <summary> /// Initialize method implementation /// Loads your Phone-Factor attributes for authentication /// </summary> public static void Initialize(ExternalOTPProvider sms) { try { string data = sms.Parameters.Data; Dictionary <string, string> Values = data.Split(',').Select(value => value.Split('=')).ToDictionary(s => s[0].Trim(), s => s[1].Trim()); LICENSE_KEY = Values["LICENSE_KEY"]; GROUP_KEY = Values["GROUP_KEY"]; CERT_THUMBPRINT = Values["CERT_THUMBPRINT"]; return; } catch (Exception ex) { throw ex; } }
/// <summary> /// Initialize method implementation /// Loads your SMS attributes /// </summary> public static void Initialize(ExternalOTPProvider sms) { try { string data = sms.Parameters.Data; Dictionary <string, string> Values = data.Split(',').Select(value => value.Split('=')).ToDictionary(s => s[0].Trim(), s => s[1].Trim()); try { IPhost = Values[IPHOST_KEY]; } catch { IPhost = "sms.yourdomain.com:8000"; } try { Password = Values[PWD_KEY]; } catch { Password = "******"; } return; } catch (Exception ex) { Log.WriteEntry("SMS Initialize : \r" + ex.Message, EventLogEntryType.Error, 10000); throw ex; } }
/// <summary> /// Update method implmentation /// </summary> public void Update(PSHost host) { ManagementService.Initialize(host, true); // MFAConfig cfg = ManagementService.ADFSManager.Config; MFAConfig cfg = ManagementService.Config; ExternalOTPProvider otp = cfg.ExternalOTPProvider; cfg.IsDirty = true; otp.Company = this.Company; otp.FullQualifiedImplementation = this.FullQualifiedImplementation; otp.IsTwoWay = this.IsTwoWay; otp.Sha1Salt = this.Sha1Salt; otp.Timeout = this.Timeout; otp.Parameters = this.Parameters; ManagementService.ADFSManager.WriteConfiguration(host); }
/// <summary> /// Update method implmentation /// </summary> public override void Load(PSHost host) { ManagementService.Initialize(host, true); MFAConfig cfg = ManagementService.Config; ExternalOTPProvider otp = cfg.ExternalProvider; this.IsDirty = cfg.IsDirty; this.Enabled = otp.Enabled; this.EnrollWizard = otp.EnrollWizard; this.ForceWizard = otp.ForceWizard; this.Company = otp.Company; this.FullQualifiedImplementation = otp.FullQualifiedImplementation; this.IsTwoWay = otp.IsTwoWay; this.Sha1Salt = otp.Sha1Salt; this.Timeout = otp.Timeout; this.PinRequired = otp.PinRequired; this.Parameters = otp.Parameters.Data; }
/// <summary> /// Update method implmentation /// </summary> public void Update(PSHost host) { ManagementAdminService.Initialize(true); MFAConfig cfg = ManagementAdminService.ADFSManager.Config; ExternalOTPProvider otp = cfg.ExternalOTPProvider; cfg.IsDirty = true; otp.Company = this.Company; otp.FullQualifiedImplementation = this.FullQualifiedImplementation; otp.IsTwoWay = this.IsTwoWay; otp.Sha1Salt = this.Sha1Salt; otp.Timeout = this.Timeout; otp.Parameters = this.Parameters; ManagementAdminService.ADFSManager.WriteConfiguration(host); using (MailSlotClient mailslot = new MailSlotClient()) { mailslot.SendNotification(0xAA); } }
/// <summary> /// Update method implmentation /// </summary> public override void Update(PSHost host) { ManagementService.Initialize(host, true); MFAConfig cfg = ManagementService.Config; ExternalOTPProvider otp = cfg.ExternalProvider; cfg.IsDirty = true; CheckUpdates(host); otp.Enabled = this.Enabled; otp.EnrollWizard = this.EnrollWizard; otp.ForceWizard = this.ForceWizard; otp.Company = this.Company; otp.FullQualifiedImplementation = this.FullQualifiedImplementation; otp.IsTwoWay = this.IsTwoWay; otp.Sha1Salt = this.Sha1Salt; otp.Timeout = this.Timeout; otp.Parameters.Data = this.Parameters; otp.PinRequired = this.PinRequired; ManagementService.ADFSManager.WriteConfiguration(host); }
/// <summary> /// GetCodeWithExternalSystem method implementation for Azure MFA /// </summary> public AuthenticationResponseKind GetCodeWithExternalSystem(Registration reg, ExternalOTPProvider externalsys, CultureInfo culture, out int otp) { throw new NotImplementedException(); }
/// <summary> /// GetUserCodeWithExternalSystem method implementation for Azure MFA /// </summary> public int GetUserCodeWithExternalSystem(string upn, string phonenumber, string smstext, ExternalOTPProvider externalsys, CultureInfo culture) { SMS_strings.Culture = culture; SMSRuntime.Initialize(externalsys); SMSParams Params = new SMSParams(); try { int otp = GetRandomOTP(); Params.IPhost = SMSRuntime.IPhost; Params.Password = SMSRuntime.Password; Params.SMSText = string.Format(SMS_strings.SMSMessage, externalsys.Company, otp); Params.PhoneNumber = phonenumber; int errorId; if (SMSRuntime.Authenticate(Params, out errorId, externalsys.Timeout)) { return(Convert.ToInt32(otp)); } else { return((int)NotificationStatus.Error); } } catch (Exception ex) { Log.WriteEntry("SMS SendMessage : \r" + ex.Message, EventLogEntryType.Error, 10000); return((int)NotificationStatus.Error); } }
/// <summary> /// GetCodeWithExternalSystem method implmentation /// </summary> public NotificationStatus GetCodeWithExternalSystem(Registration reg, ExternalOTPProvider externalsys, CultureInfo culture, out int otp) { azure_strings.Culture = culture; String NumberStr = reg.PhoneNumber; int CountryCode = 0; ulong NationalNumber = 0; string extension = string.Empty; PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance(); PhoneNumber NumberProto = phoneUtil.Parse(NumberStr, culture.TwoLetterISOLanguageName.ToUpper()); CountryCode = NumberProto.CountryCode; NationalNumber = NumberProto.NationalNumber; if (NumberProto.HasExtension) { extension = NumberProto.Extension; } PhoneFactor.Initialize(externalsys); PhoneFactorParams Params = new PhoneFactorParams(); Params.Username = reg.UPN; Params.CountryCode = CountryCode.ToString(); Params.Phone = NationalNumber.ToString(); Params.Extension = extension; Params.ApplicationName = "IdentityServer"; Params.Sha1Salt = externalsys.Sha1Salt; if (externalsys.IsTwoWay) { Params.SmsText = string.Format(azure_strings.SMSTwoWayMessage, externalsys.Company); Params.Mode = PhoneFactor.MODE_SMS_TWO_WAY_OTP; } else { Params.SmsText = string.Format(azure_strings.SMSMessage, externalsys.Company); Params.Mode = PhoneFactor.MODE_SMS_ONE_WAY_OTP; } int callStatus; int errorId; string xotp = string.Empty; if (PhoneFactor.Authenticate(Params, out xotp, out callStatus, out errorId, externalsys.Timeout)) { if (externalsys.IsTwoWay) { otp = Convert.ToInt32(NotificationStatus.ResponseSMSReply); return(NotificationStatus.ResponseSMSReply); } else { otp = Convert.ToInt32(xotp); return(NotificationStatus.ResponseSMSOTP); } } else { otp = 0; return(NotificationStatus.Error); } }
/// <summary> /// GetUserCodeWithExternalSystem demo method /// </summary> #pragma warning disable 162 public int GetUserCodeWithExternalSystem(string upn, string phonenumber, string email, ExternalOTPProvider externalsys, CultureInfo culture) { // Compute and send your TOTP code and return his value if everything goes right if (true) { return(1230); } else { return((int)AuthenticationResponseKind.Error); // return error } }
/// <summary> /// GetUserCodeWithExternalSystem method implementation for Azure MFA /// </summary> public int GetUserCodeWithExternalSystem(string upn, string phonenumber, string smstext, ExternalOTPProvider externalsys, CultureInfo culture) { azure_strings.Culture = culture; String NumberStr = phonenumber; int CountryCode = 0; ulong NationalNumber = 0; string extension = string.Empty; PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance(); PhoneNumber NumberProto = phoneUtil.Parse(NumberStr, culture.TwoLetterISOLanguageName.ToUpper()); CountryCode = NumberProto.CountryCode; NationalNumber = NumberProto.NationalNumber; if (NumberProto.HasExtension) { extension = NumberProto.Extension; } PhoneFactor.Initialize(externalsys); PhoneFactorParams Params = new PhoneFactorParams(); Params.Username = upn; Params.CountryCode = CountryCode.ToString(); Params.Phone = NationalNumber.ToString(); Params.Extension = extension; Params.ApplicationName = "IdentityServer"; Params.Sha1Salt = externalsys.Sha1Salt; /* Params.SmsText = string.Format(azure_strings.SMSTwoWayMessage, externalsys.Company); * Params.Mode = PhoneFactor.MODE_PHONE_APP_STANDARD; */ if (externalsys.IsTwoWay) { Params.SmsText = string.Format(azure_strings.SMSTwoWayMessage, externalsys.Company); Params.Mode = PhoneFactor.MODE_SMS_TWO_WAY_OTP; } else { Params.SmsText = string.Format(azure_strings.SMSMessage, externalsys.Company); Params.Mode = PhoneFactor.MODE_SMS_ONE_WAY_OTP; } int callStatus; int errorId; string otp = string.Empty; if (PhoneFactor.Authenticate(Params, out otp, out callStatus, out errorId, externalsys.Timeout)) { if (externalsys.IsTwoWay) { return(NotificationStatus.Bypass); } else { return(Convert.ToInt32(otp)); } } else { return(NotificationStatus.Error); } }