diff options
author | crupest <crupest@outlook.com> | 2021-04-25 21:37:52 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-25 21:37:52 +0800 |
commit | dc4f255e0fab5f6b39b7add197830591b89103c0 (patch) | |
tree | e919eaa01fda4efe318e48829360eeef7bf6491a /BackEnd/Timeline/Services/User | |
parent | 657fb589137099794e58fbd35beb7d942b376965 (diff) | |
download | timeline-dc4f255e0fab5f6b39b7add197830591b89103c0.tar.gz timeline-dc4f255e0fab5f6b39b7add197830591b89103c0.tar.bz2 timeline-dc4f255e0fab5f6b39b7add197830591b89103c0.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Services/User')
-rw-r--r-- | BackEnd/Timeline/Services/User/PasswordBadFormatException.cs | 26 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/PasswordService.cs | 24 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/Resource.Designer.cs | 63 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/Resource.resx | 21 |
4 files changed, 94 insertions, 40 deletions
diff --git a/BackEnd/Timeline/Services/User/PasswordBadFormatException.cs b/BackEnd/Timeline/Services/User/PasswordBadFormatException.cs deleted file mode 100644 index b9d76017..00000000 --- a/BackEnd/Timeline/Services/User/PasswordBadFormatException.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System;
-
-namespace Timeline.Services.User
-{
- [Serializable]
- public class PasswordBadFormatException : Exception
- {
- public PasswordBadFormatException() : base(Resources.Services.Exception.PasswordBadFormatException) { }
- public PasswordBadFormatException(string message) : base(message) { }
- public PasswordBadFormatException(string message, Exception inner) : base(message, inner) { }
-
- public PasswordBadFormatException(string password, string validationMessage) : this()
- {
- Password = password;
- ValidationMessage = validationMessage;
- }
-
- protected PasswordBadFormatException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
-
- public string Password { get; set; } = "";
-
- public string ValidationMessage { get; set; } = "";
- }
-}
diff --git a/BackEnd/Timeline/Services/User/PasswordService.cs b/BackEnd/Timeline/Services/User/PasswordService.cs index 580471e1..1c14875f 100644 --- a/BackEnd/Timeline/Services/User/PasswordService.cs +++ b/BackEnd/Timeline/Services/User/PasswordService.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using System;
+using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
@@ -12,18 +13,13 @@ namespace Timeline.Services.User [Serializable]
public class HashedPasswordBadFromatException : Exception
{
- private static string MakeMessage(string reason)
- {
- return Resources.Services.Exception.HashedPasswordBadFromatException + " Reason: " + reason;
- }
-
- public HashedPasswordBadFromatException() : base(Resources.Services.Exception.HashedPasswordBadFromatException) { }
+ public HashedPasswordBadFromatException() : base(Resource.ExceptionHashedPasswordBadFormat) { }
public HashedPasswordBadFromatException(string message) : base(message) { }
public HashedPasswordBadFromatException(string message, Exception inner) : base(message, inner) { }
- public HashedPasswordBadFromatException(string hashedPassword, string reason) : base(MakeMessage(reason)) { HashedPassword = hashedPassword; }
- public HashedPasswordBadFromatException(string hashedPassword, string reason, Exception inner) : base(MakeMessage(reason), inner) { HashedPassword = hashedPassword; }
+ public HashedPasswordBadFromatException(string hashedPassword, string reason, Exception? inner = null)
+ : base(string.Format(CultureInfo.InvariantCulture, Resource.ExceptionHashedPasswordBadFormat, reason), inner) { HashedPassword = hashedPassword; }
protected HashedPasswordBadFromatException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
@@ -150,19 +146,19 @@ namespace Timeline.Services.User }
catch (FormatException e)
{
- throw new HashedPasswordBadFromatException(hashedPassword, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotBase64, e);
+ throw new HashedPasswordBadFromatException(hashedPassword, Resource.ExceptionHashedPasswordBadFormatReasonNotBase64, e);
}
// read the format marker from the hashed password
if (decodedHashedPassword.Length == 0)
{
- throw new HashedPasswordBadFromatException(hashedPassword, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotLength0);
+ throw new HashedPasswordBadFromatException(hashedPassword, Resource.ExceptionHashedPasswordBadFormatReasonLength0);
}
return (decodedHashedPassword[0]) switch
{
0x01 => VerifyHashedPasswordV3(decodedHashedPassword, providedPassword, hashedPassword),
- _ => throw new HashedPasswordBadFromatException(hashedPassword, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotUnknownMarker),
+ _ => throw new HashedPasswordBadFromatException(hashedPassword, Resource.ExceptionHashedPasswordBadFormatReasonUnknownMarker),
};
}
@@ -178,7 +174,7 @@ namespace Timeline.Services.User // Read the salt: must be >= 128 bits
if (saltLength < 128 / 8)
{
- throw new HashedPasswordBadFromatException(hashedPasswordString, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotSaltTooShort);
+ throw new HashedPasswordBadFromatException(hashedPasswordString, Resource.ExceptionHashedPasswordBadFormatReasonSaltTooShort);
}
byte[] salt = new byte[saltLength];
Buffer.BlockCopy(hashedPassword, 13, salt, 0, salt.Length);
@@ -187,7 +183,7 @@ namespace Timeline.Services.User int subkeyLength = hashedPassword.Length - 13 - salt.Length;
if (subkeyLength < 128 / 8)
{
- throw new HashedPasswordBadFromatException(hashedPasswordString, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotSubkeyTooShort);
+ throw new HashedPasswordBadFromatException(hashedPasswordString, Resource.ExceptionHashedPasswordBadFormatReasonSubkeyTooShort);
}
byte[] expectedSubkey = new byte[subkeyLength];
Buffer.BlockCopy(hashedPassword, 13 + salt.Length, expectedSubkey, 0, expectedSubkey.Length);
@@ -201,7 +197,7 @@ namespace Timeline.Services.User // This should never occur except in the case of a malformed payload, where
// we might go off the end of the array. Regardless, a malformed payload
// implies verification failed.
- throw new HashedPasswordBadFromatException(hashedPasswordString, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotOthers, e);
+ throw new HashedPasswordBadFromatException(hashedPasswordString, Resource.ExceptionHashedPasswordBadFormatReasonOthers, e);
}
}
diff --git a/BackEnd/Timeline/Services/User/Resource.Designer.cs b/BackEnd/Timeline/Services/User/Resource.Designer.cs index d64a7aab..4f75b055 100644 --- a/BackEnd/Timeline/Services/User/Resource.Designer.cs +++ b/BackEnd/Timeline/Services/User/Resource.Designer.cs @@ -70,6 +70,69 @@ namespace Timeline.Services.User { }
/// <summary>
+ /// Looks up a localized string similar to The hashes password is of bad format. It might not be created by server. Reason: {0}.
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormat {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormat", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Decoded hashed password is of length 0..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonLength0 {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonLength0", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Not of valid base64 format. See inner exception..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonNotBase64 {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonNotBase64", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to See inner exception..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonOthers {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonOthers", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Salt length < 128 bits..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonSaltTooShort {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonSaltTooShort", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Subkey length < 128 bits..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonSubkeyTooShort {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonSubkeyTooShort", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unknown format marker..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonUnknownMarker {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonUnknownMarker", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Nickname is of bad format. {0}.
/// </summary>
internal static string ExceptionNicknameBadFormat {
diff --git a/BackEnd/Timeline/Services/User/Resource.resx b/BackEnd/Timeline/Services/User/Resource.resx index 732cfefd..28e75b19 100644 --- a/BackEnd/Timeline/Services/User/Resource.resx +++ b/BackEnd/Timeline/Services/User/Resource.resx @@ -120,6 +120,27 @@ <data name="ExceptionBadPassword" xml:space="preserve">
<value>Password is wrong.</value>
</data>
+ <data name="ExceptionHashedPasswordBadFormat" xml:space="preserve">
+ <value>The hashes password is of bad format. It might not be created by server. Reason: {0}</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonLength0" xml:space="preserve">
+ <value>Decoded hashed password is of length 0.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonNotBase64" xml:space="preserve">
+ <value>Not of valid base64 format. See inner exception.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonOthers" xml:space="preserve">
+ <value>See inner exception.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonSaltTooShort" xml:space="preserve">
+ <value>Salt length < 128 bits.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonSubkeyTooShort" xml:space="preserve">
+ <value>Subkey length < 128 bits.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonUnknownMarker" xml:space="preserve">
+ <value>Unknown format marker.</value>
+ </data>
<data name="ExceptionNicknameBadFormat" xml:space="preserve">
<value>Nickname is of bad format. {0}</value>
</data>
|