Skip to content

Commit

Permalink
3.1.2202.2
Browse files Browse the repository at this point in the history
3.1.2202.2
  • Loading branch information
redhook62 committed Feb 14, 2022
1 parent 8d4ca5c commit 77f1a26
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.1.2202.1")]
[assembly: AssemblyFileVersion("3.1.2202.2")]
[assembly: AssemblyInformationalVersion("3.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ public override bool DoImport()
{
reg.PIN = Convert.ToInt32(Config.DefaultPin);
reg.PreferredMethod = Config.DefaultProviderMethod;

if (!Utilities.ValidateEmail(reg.MailAddress, (Config.MailProvider.Enabled && Config.MailProvider.IsRequired)))
throw new Exception(string.Format("invalid mail address for user : {0}", reg.UPN));
if (!Utilities.ValidatePhoneNumber(reg.PhoneNumber, (Config.ExternalProvider.Enabled && Config.ExternalProvider.IsRequired)))
throw new Exception(string.Format("invalid phone number for user : {0}", reg.UPN));

client2.AddMFAUser(reg, ForceNewKey, false);
Trace.TraceInformation(string.Format("User {0} Imported in MFA", reg.UPN));
if (!string.IsNullOrEmpty(reg.MailAddress))
Expand Down Expand Up @@ -352,20 +358,22 @@ public override bool DoImport()
{
MFAUser reg = new MFAUser();
reg.PIN = Convert.ToInt32(Config.DefaultPin);

if ((ids[0].HasValue) && (!string.IsNullOrEmpty(row[ids[0].Value])))
reg.UPN = row[ids[0].Value];
else
throw new InvalidDataException("upn must be provided !");

if ((ids[1].HasValue) && (!string.IsNullOrEmpty(row[ids[1].Value])))
reg.MailAddress = row[ids[1].Value];
else if (Config.MailProvider.Enabled)
throw new InvalidDataException("email must be provided !");

if ((ids[2].HasValue) && (!string.IsNullOrEmpty(row[ids[2].Value])))
reg.PhoneNumber = row[ids[2].Value];
else if (Config.ExternalProvider.Enabled)
throw new InvalidDataException("mobile must be provided !");

if (!Utilities.ValidateEmail(reg.MailAddress, (Config.MailProvider.Enabled && Config.MailProvider.IsRequired)))
throw new Exception(string.Format("invalid mail address for user : {0}", reg.UPN));
if (!Utilities.ValidatePhoneNumber(reg.PhoneNumber, (Config.ExternalProvider.Enabled && Config.ExternalProvider.IsRequired)))
throw new Exception(string.Format("invalid phone number for user : {0}", reg.UPN));

if ((ids[3].HasValue) && (!string.IsNullOrEmpty(row[ids[3].Value])))
reg.PreferredMethod = (PreferredMethod)Enum.Parse(typeof(PreferredMethod), row[ids[3].Value]);
Expand Down Expand Up @@ -479,13 +487,14 @@ public override bool DoImport()

if (row.Attribute("email") != null)
reg.MailAddress = row.Attribute("email").Value;
else if (Config.MailProvider.Enabled)
throw new InvalidDataException("email must be provided !");

if (row.Attribute("mobile") != null)
reg.PhoneNumber = row.Attribute("mobile").Value;
else if (Config.ExternalProvider.Enabled)
throw new InvalidDataException("mobile must be provided !");

if (!Utilities.ValidateEmail(reg.MailAddress, (Config.MailProvider.Enabled && Config.MailProvider.IsRequired)))
throw new Exception(string.Format("invalid mail address for user : {0}", reg.UPN));
if (!Utilities.ValidatePhoneNumber(reg.PhoneNumber, (Config.ExternalProvider.Enabled && Config.ExternalProvider.IsRequired)))
throw new Exception(string.Format("invalid phone number for user : {0}", reg.UPN));

if (row.Attribute("method") != null)
reg.PreferredMethod = (PreferredMethod)Enum.Parse(typeof(PreferredMethod), row.Attribute("method").Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,10 @@ internal static MFAUser SetMFAUser(MFAConfig cfg, MFAUser reg, bool resetkey = f
reg.PIN = Convert.ToInt32(cfg.DefaultPin);
if (reg.OverrideMethod == null)
reg.OverrideMethod = string.Empty;
if (!Utilities.ValidateEmail(reg.MailAddress, (cfg.MailProvider.Enabled && cfg.MailProvider.IsRequired)))
throw new Exception(string.Format("invalid mail address for user : {0}", reg.UPN));
if (!Utilities.ValidatePhoneNumber(reg.PhoneNumber, (cfg.ExternalProvider.Enabled && cfg.ExternalProvider.IsRequired)))
throw new Exception(string.Format("invalid phone number for user : {0}", reg.UPN));
MFAUser newreg = client.SetMFAUser(reg, resetkey, caninsert);
if (newreg != null)
{
Expand Down Expand Up @@ -1042,6 +1046,10 @@ internal static MFAUser AddMFAUser(MFAConfig cfg, MFAUser reg, bool resetkey = t
reg.PIN = Convert.ToInt32(cfg.DefaultPin);
if (reg.OverrideMethod == null)
reg.OverrideMethod = string.Empty;
if (!Utilities.ValidateEmail(reg.MailAddress, (cfg.MailProvider.Enabled && cfg.MailProvider.IsRequired)))
throw new Exception(string.Format("invalid mail address for user : {0}", reg.UPN));
if (!Utilities.ValidatePhoneNumber(reg.PhoneNumber, (cfg.ExternalProvider.Enabled && cfg.ExternalProvider.IsRequired)))
throw new Exception(string.Format("invalid phone number for user : {0}", reg.UPN));
client.OnKeyDataEvent += KeyDataEvent;
MFAUser newreg = client.AddMFAUser(reg, resetkey, canupdate);
if (newreg != null)
Expand Down Expand Up @@ -2625,7 +2633,7 @@ private static void SendMail(MailMessage Message, MailProvider mail)
Port = mail.Port,
UseDefaultCredentials = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
EnableSsl = mail.UseSSL
EnableSsl = mail.UseSSL
};
if (!mail.Anonymous)
client.Credentials = new NetworkCredential(mail.UserName, mail.Password);
Expand Down Expand Up @@ -2673,11 +2681,13 @@ public static void SendOTPByEmail(string to, string upn, string code, MailProvid
name = upn.Remove(2, upn.IndexOf('@') - 2).Insert(2, "*********");
else
name = upn;
MailMessage Message = new MailMessage(mail.From, to)
MailAddress mailfrom = Utilities.MakeMailAddress(mail.From);
MailAddress mailto = Utilities.MakeMailAddress(to);
MailMessage Message = new MailMessage(mailfrom, mailto)
{
BodyEncoding = UTF8Encoding.UTF8,
IsBodyHtml = true,
Body = string.Format(html, mail.Company, name, code, to)
Body = string.Format(html, mail.Company, name, code, mailto.Address)
};

if (mail.DeliveryNotifications)
Expand All @@ -2689,7 +2699,7 @@ public static void SendOTPByEmail(string to, string upn, string code, MailProvid
{
Group titlegrp = Regex.Match(html, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"];
if (titlegrp != null)
Message.Subject = string.Format(titlegrp.Value, mail.Company, name, code, to);
Message.Subject = string.Format(titlegrp.Value, mail.Company, name, code, mailto.Address);
if (Message.Subject == string.Empty)
{
ResourcesLocale Resources = new ResourcesLocale(culture.LCID);
Expand Down Expand Up @@ -2747,9 +2757,16 @@ public static void SendInscriptionMail(string to, MFAUser user, MailProvider mai
}
string sendermail = GetUserBusinessEmail(user.UPN);
string html = StripEmailContent(htmlres);
MailMessage Message = new MailMessage(mail.From, to);
MailAddress mailfrom = Utilities.MakeMailAddress(mail.From);
MailAddress mailto = Utilities.MakeMailAddress(to);
MailAddress mailuser = Utilities.MakeMailAddress(user.MailAddress);

MailMessage Message = new MailMessage(mailfrom, mailto);
if (!string.IsNullOrEmpty(sendermail))
Message.CC.Add(sendermail);
{
MailAddress mailcc = Utilities.MakeMailAddress(sendermail);
Message.CC.Add(mailcc);
}
Message.BodyEncoding = UTF8Encoding.UTF8;
Message.IsBodyHtml = true;
Message.Body = string.Format(htmlres, mail.Company, user.UPN, user.MailAddress, user.PhoneNumber, user.PreferredMethod);
Expand All @@ -2763,7 +2780,7 @@ public static void SendInscriptionMail(string to, MFAUser user, MailProvider mai
{
Group titlegrp = Regex.Match(html, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"];
if (titlegrp != null)
Message.Subject = string.Format(titlegrp.Value, mail.Company, user.UPN, user.MailAddress, user.PhoneNumber, user.PreferredMethod);
Message.Subject = string.Format(titlegrp.Value, mail.Company, user.UPN, mailuser.Address, user.PhoneNumber, user.PreferredMethod);
if (Message.Subject == string.Empty)
{
ResourcesLocale Resources = new ResourcesLocale(culture.LCID);
Expand Down Expand Up @@ -2832,9 +2849,14 @@ public static void SendKeyByEmail(string to, string upn, string key, MailProvide
ContentId = Guid.NewGuid().ToString()
};

MailMessage Message = new MailMessage(mail.From, to);
MailAddress mailfrom = Utilities.MakeMailAddress(mail.From);
MailAddress mailto = Utilities.MakeMailAddress(to);
MailMessage Message = new MailMessage(mailfrom, mailto);
if (!string.IsNullOrEmpty(sendermail))
Message.CC.Add(sendermail);
{
MailAddress mailcc = Utilities.MakeMailAddress(sendermail);
Message.CC.Add(mailcc);
}
Message.BodyEncoding = UTF8Encoding.UTF8;
Message.IsBodyHtml = true;

Expand Down Expand Up @@ -2916,11 +2938,14 @@ public static void SendNotificationByEmail(MFAConfig config, MFAUser user, MailP
}
}
string html = StripEmailContent(htmlres);
MailMessage Message = new MailMessage(mail.From, user.MailAddress)
MailAddress mailfrom = Utilities.MakeMailAddress(mail.From);
MailAddress mailuser = Utilities.MakeMailAddress(user.MailAddress);

MailMessage Message = new MailMessage(mailfrom, mailuser)
{
BodyEncoding = UTF8Encoding.UTF8,
IsBodyHtml = true,
Body = string.Format(html, user.UPN, mail.Company, user.MailAddress)
Body = string.Format(html, user.UPN, mail.Company, mailuser.Address)
};

if (mail.DeliveryNotifications)
Expand All @@ -2932,7 +2957,7 @@ public static void SendNotificationByEmail(MFAConfig config, MFAUser user, MailP
{
Group titlegrp = Regex.Match(html, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"];
if (titlegrp != null)
Message.Subject = string.Format(titlegrp.Value, user.UPN, mail.Company, user.MailAddress);
Message.Subject = string.Format(titlegrp.Value, user.UPN, mail.Company, mailuser.Address);
if (Message.Subject == string.Empty)
{
ResourcesLocale Resources = new ResourcesLocale(culture.LCID);
Expand Down Expand Up @@ -2983,8 +3008,8 @@ public static string StripEmailDomain(string email)

if (string.IsNullOrEmpty(email))
return string.Empty;
else
return email.Substring(email.IndexOf("@", 0));
var addr = Utilities.MakeMailAddress(email);
return addr.Address.Substring(addr.Address.IndexOf("@", 0));
}
catch
{
Expand Down Expand Up @@ -3725,6 +3750,41 @@ internal static string ParseType(string AssemblyFulldescription)
return type[0].Trim();
}


/// <summary>
/// ValidateEmail method implementation
/// </summary>
public static MailAddress MakeMailAddress(string email)
{
try
{
if (string.IsNullOrEmpty(email))
throw new ArgumentNullException("MailAddress", "Email address not provided !") ;
int f = email.IndexOf('<');
int l = email.IndexOf('>');
int f2 = email.IndexOf('[');
int l2 = email.IndexOf(']');
string trueemail = email;
string displayname = string.Empty;
if ((f >= 0) && (l > f))
{
trueemail = email.Substring(f + 1, (l - f) - 1);
displayname = email.Substring(0, f - 1).Trim();
}
else if ((f2 >= 0) && (l2 > f2))
{
trueemail = email.Substring(f2 + 1, (l2 - f2) - 1);
displayname = email.Substring(0, f2 - 1).Trim();
}
return new System.Net.Mail.MailAddress(trueemail, displayname);
}
catch (Exception ex)
{
Log.WriteEntry(ex.Message, EventLogEntryType.Error, 800);
return null;
}
}

/// <summary>
/// ValidateEmail method implementation
/// </summary>
Expand All @@ -3737,11 +3797,8 @@ public static bool ValidateEmail(string email, bool checkempty = false)
return false;
else
return true;
var addr = new System.Net.Mail.MailAddress(email);
if (addr.Address != email)
return false;
else
return true;
var addr = MakeMailAddress(email);
return true;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -3852,7 +3909,10 @@ internal static string GetEmailDomain(string email)
if (string.IsNullOrEmpty(email))
return string.Empty;
else
return email.Remove(0, email.IndexOf('@') + 1);
{
var addr = MakeMailAddress(email);
return addr.Host;
}
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// en utilisant '*', comme ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.1.2202.1")]
[assembly: AssemblyFileVersion("3.1.2202.2")]
[assembly: AssemblyInformationalVersion("3.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@ public static bool IsSQLEncrypted
/// </summary>
public static bool IsValidEmail(string email)
{
try
{
var addr = new System.Net.Mail.MailAddress(email);
return addr.Address == email;
}
catch
{
return false;
}
return MultiFactor.Utilities.ValidateEmail(email, true);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.1.2202.1")]
[assembly: AssemblyFileVersion("3.1.2202.2")]
[assembly: AssemblyInformationalVersion("3.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UPN;EMAIL;MOBILE;METHOD;ENABLED
[email protected];[email protected];601020304;Choose;true
[email protected];[email protected];601020304;Choose;true
[email protected];Test1 <[email protected]>;601020304;Choose;true
[email protected];Test2 <[email protected]>;601020304;Choose;true
[email protected];;601020304;Code;true
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Root>
<User upn="[email protected]" email="[email protected]" mobile="601020304" method="Choose" enabled="true" />
<User upn="[email protected]" email="[email protected]" mobile="601020304" method="Choose" enabled="true" />
<User upn="[email protected]" email="[email protected]" mobile="601020304" method="Code" enabled="false" />
<User upn="[email protected]" email="Test1 [[email protected]]" mobile="601020304" method="Choose" enabled="true" />
<User upn="[email protected]" email="Test2 [[email protected]]" mobile="601020304" method="Choose" enabled="true" />
<User upn="[email protected]" email="Test3 [[email protected]]" mobile="601020304" method="Code" enabled="false" />
</Root>
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.1.2202.1")]
[assembly: AssemblyFileVersion("3.1.2202.2")]
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.1.2202.1")]
[assembly: AssemblyFileVersion("3.1.2202.2")]
[assembly: AssemblyInformationalVersion("3.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ public string MailAddress
return _mail;
}
set
{
{
_mail = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
// Révision
//
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.1.2202.1")]
[assembly: AssemblyFileVersion("3.1.2202.2")]
[assembly: AssemblyInformationalVersion("3.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

Expand Down
Loading

0 comments on commit 77f1a26

Please sign in to comment.