Merge pull request #3 from intellivoid/aliwoto-dev

Implementation of `CreateSession` and `AuthenticateUser` methods
This commit is contained in:
ALi.w 2021-10-02 09:47:09 +00:00 committed by GitHub
commit 68ecb47e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
84 changed files with 4156 additions and 145 deletions

View File

@ -1,5 +1,5 @@
# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
# Copyright (c) 2021 SocialVoid.NET Authors.
# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
# Copyright (c) 2021 Socialvoid.NET Authors.
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -17,7 +17,7 @@
version: 2
updates:
- package-ecosystem: nuget
directory: "/SocialVoid"
directory: "/Socialvoid"
schedule:
interval: daily
time: "15:00"

4
.github/stale.yml vendored
View File

@ -1,5 +1,5 @@
# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
# Copyright (c) 2021 SocialVoid.NET Authors.
# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
# Copyright (c) 2021 Socialvoid.NET Authors.
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
# Copyright (c) 2021 SocialVoid.NET Authors.
# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
# Copyright (c) 2021 Socialvoid.NET Authors.
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
# Copyright (c) 2021 SocialVoid.NET Authors.
# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
# Copyright (c) 2021 Socialvoid.NET Authors.
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ woto_files/
woto_docs/
woto_tests/
woto_objects/
/.vs/

View File

@ -1,6 +1,6 @@
<!--
This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
Copyright (c) 2021 SocialVoid.NET Authors.
This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
Copyright (c) 2021 Socialvoid.NET Authors.
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
-->
> #### NOTE: This code style standard for SocialVoid.NET is a work in progress and much of the code does not currently conform to these rules. This is something that will be addressed by the core team.
> #### NOTE: This code style standard for Socialvoid.NET is a work in progress and much of the code does not currently conform to these rules. This is something that will be addressed by the core team.
# Introduction
As the SocialVoid.NET project gains more traction and becomes more widely used, we aim to provide a more professional and consistent look to the large amount of source now in the project. It was a broadly supported decision by the core development team to follow the Microsoft coding guidelines (the default provided in Visual Studio's C# editor). These coding guidelines listed below are based on a [MSDN blog post](http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx) from 2005 by Brad Abrams describing the internal coding guidelines at Microsoft, with some changes to suit our project.
As the Socialvoid.NET project gains more traction and becomes more widely used, we aim to provide a more professional and consistent look to the large amount of source now in the project. It was a broadly supported decision by the core development team to follow the Microsoft coding guidelines (the default provided in Visual Studio's C# editor). These coding guidelines listed below are based on a [MSDN blog post](http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx) from 2005 by Brad Abrams describing the internal coding guidelines at Microsoft, with some changes to suit our project.
# Coding Guidelines
## Tabs & Indenting
@ -117,8 +117,8 @@ Comments must provide added value or explanation to the code. Simply describing
Each file **should** start with a copyright notice. This is a short statement declaring the project name and copyright notice, and directing the reader to the license document elsewhere in the project. To avoid errors in doc comment builds, avoid using triple-slash doc comments.
```csharp
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -254,7 +254,7 @@ In addition, the goal is to have clean, readable source. Code legibility should
## File Organization
* Source files should contain only one public type, although multiple internal types are permitted if required.
* Source files should be given the name of the public type in the file.
* Directory names should follow the namespace for the class after `SocialVoid`. For example, one would expect to find the public class `SocialVoid.Constants.WotoTools` in **SocialVoid\Constants\WotoTools.cs**.
* Directory names should follow the namespace for the class after `Socialvoid`. For example, one would expect to find the public class `Socialvoid.Constants.WotoTools` in **Socialvoid\Constants\WotoTools.cs**.
* Class members should be grouped logically, and encapsulated into regions:
```csharp

View File

@ -1 +1 @@
# SocialVoid.NET
# Socialvoid.NET

View File

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

View File

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialVoid", "SocialVoid\SocialVoid.csproj", "{6CB5C21A-EB16-48D6-B98A-F18D7CE46785}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Socialvoid", "Socialvoid\Socialvoid.csproj", "{6CB5C21A-EB16-48D6-B98A-F18D7CE46785}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBD}") = "Tests", "Tests\Tests.csproj", "{2EFF7FAB-7794-4BFA-AB48-998ADADC45A9}"
EndProject

View File

@ -0,0 +1,603 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Text;
using System.Net.Http;
using System.IO;
using Socialvoid.Security;
using Socialvoid.Security.Otp;
using Socialvoid.JObjects;
using Socialvoid.Errors.ServerErrors;
using Socialvoid.Errors.AuthenticationErrors;
using Socialvoid.Errors.ValidationErrors;
using MType = System.Net.Http.Headers.MediaTypeHeaderValue;
namespace Socialvoid.Client
{
/// <summary>
/// Socialvoid client.
/// <code> since: v0.0.0 </code>
/// </summary>
public abstract class SocialvoidClient
{
//-------------------------------------------------
#region Constant's Region
/// <summary>
/// the content type of all of our http requests.
/// <code> since: v0.0.0 </code>
/// </summary>
protected internal const string ContentType = "application/json-rpc";
/// <summary>
/// the username key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string UsernameKey = "username";
/// <summary>
/// the password key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string PasswordKey = "password";
/// <summary>
/// the otp key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string OtpKey = "otp";
/// <summary>
/// the public hash key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string PublicHashKey = "public_hash";
/// <summary>
/// the private hash key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string PrivateHashKey = "private_hash";
/// <summary>
/// the platform key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string PlatformKey = "platform";
/// <summary>
/// the name key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string NameKey = "name";
/// <summary>
/// the version key in jsonrpc request params.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string VersionKey = "version";
/// <summary>
/// <c>authenticate_user</c> method value.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string AuthenticateUserMethod = "session.authenticate_user";
/// <summary>
/// <c>authenticate_user</c> method value.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string CreateSessionMethod = "session.create";
/// <summary>
/// <c>authenticate_user</c> method value.
/// <code> since: v0.0.0 </code>
/// </summary>
protected const string SessionIDKey = "session_identification";
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The public hash of the client.
/// <code> since: v0.0.0 </code>
/// </summary>
public string PublicHash { get; protected set; }
/// <summary>
/// The private hash of the client.
/// <code> since: v0.0.0 </code>
/// </summary>
public string PrivateHash { get; protected set; }
/// <summary>
/// The platform of the client.
/// <code> since: v0.0.0 </code>
/// </summary>
public string Platform { get; protected set; }
/// <summary>
/// The name of the client.
/// <code> since: v0.0.0 </code>
/// </summary>
public string ClientName { get; protected set; }
/// <summary>
/// The version of the client.
/// <code> since: v0.0.0 </code>
/// </summary>
public string Version { get; protected set; }
/// <summary>
///
/// <code> since: v0.0.0 </code>
/// </summary>
public HttpClient HttpClient { get; protected set; }
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
/// <summary>
/// the endpoint url of socialvoid servers.
/// <code> since: v0.0.0 </code>
/// </summary>
protected internal string _endpoint = "http://socialvoid.qlg1.com:5601/";
/// <summary>
/// Session object of this client.
/// <code> since: v0.0.0 </code>
/// </summary>
protected internal SessionEstablished _session;
/// <summary>
/// if the client should send an otp answer in the next request,
/// this field should be set to <c>true</c>.
/// <code> since: v0.0.0 </code>
/// </summary>
protected bool _should_otp;
/// <summary>
/// the last otp value of the client which should be sent in the
/// next jsonrpc request.
/// <code> since: v0.0.0 </code>
/// </summary>
protected string _otp;
/// <summary>
/// <code> since: v0.0.0 </code>
/// </summary>
protected readonly MType _contentTypeValue = MType.Parse(ContentType);
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of the <see cref="SocialvoidClient"/> class.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="publicHash">
/// the public hash of the client.
/// </param>
/// <param name="privateHash">
/// the private hash of the client.
/// </param>
/// <param name="platform">
/// the platform of the client.
/// </param>
/// <param name="name">
/// the client name.
/// </param>
/// <param name="version">
/// the version of the client.
/// </param>
protected SocialvoidClient(string publicHash, string privateHash,
string platform, string name, string version)
{
PublicHash = publicHash;
PrivateHash = privateHash;
Platform = platform;
ClientName = name;
Version = version;
HttpClient = new();
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
/// <summary>
/// CreateSession method (session.create), establishes a new session
/// to the network.
/// Please do notice that new and unauthenticated sessions
/// expires after 10 minutes of inactivity, authenticating to the session
/// will increase the expiration time to 72 hours of inactivity. This timer
/// is reset whenever the session is used in one way or another.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <exception cref="InternalServerErrorException">
/// Thrown if the server encounters an internal error.
/// </exception>
/// <exception cref="InvalidClientNameException">
/// Thrown if the parameter passed as client name is not valid.
/// </exception>
/// <exception cref="InvalidClientPublicHashException">
/// Thrown if the parameter passed as public hash is not valid.
/// </exception>
/// <exception cref="InvalidClientPrivateHashException">
/// Thrown if the parameter passed as private hash is not valid.
/// </exception>
/// <exception cref="InvalidPlatformException">
/// Thrown if the parameter passed as platform is not valid.
/// </exception>
/// <exception cref="InvalidVersionException">
/// Thrown if the parameter passed as version is not valid.
/// </exception>
public virtual SessionEstablished CreateSession()
{
JArgs args = new(){
{PublicHashKey, PublicHash},
{PrivateHashKey, PrivateHash},
{PlatformKey, Platform},
{NameKey, ClientName},
{VersionKey, Version},
};
var request = GetRpcRequest(CreateSessionMethod, args);
var message = new HttpRequestMessage(HttpMethod.Post, _endpoint);
message.Content = SerializeContent(request);
message.Content.Headers.ContentType = _contentTypeValue;
var jresp = ParseContent<SessionEstablished>(message);
if (!string.IsNullOrEmpty(jresp.Result.ChallengeSecret))
{
_should_otp = true;
_otp = GetChallengeAnswer(jresp.Result.ChallengeSecret);
// set challenege secret to null to avoid sending it again.
// this will avoid future conflicts in using old challenge secret.
jresp.Result.ChallengeSecret = null;
}
_session = jresp.Result;
return _session;
}
/// <summary>
/// AuthenticateUser method (session.authenticate_user),
/// Authenticates a user via a Username and Password combination.
/// Optionally two-factor authentication if the account has enabled it.
/// Once authenticated, the session will be able to access methods that
/// requires authentication and preform operations as the authenticated
/// user.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="sessionID">
/// The Session Identification object.
/// </param>
/// <param name="username">
/// The username of the user to authenticate to.
/// </param>
/// <param name="password">
/// The password used to authenticate to this account.
/// </param>
/// <param name="otp">
/// The optional one-time password used to authenticate to this account.
/// It will be ignored by server if empty or larger than 64 characters.
/// </param>
/// <exception cref="InternalServerErrorException">
/// Thrown if the server encounters an internal error.
/// </exception>
/// <exception cref="AuthenticationFailureException">
/// Thrown if the authentication fails.
/// </exception>
/// <exception cref="AlreadyAuthenticatedException">
/// Thrown if the user is already authenticated.
/// </exception>
/// <exception cref="AuthenticationNotApplicableException">
/// Thrown if the user is not able to authenticate.
/// </exception>
/// <exception cref="BadSessionChallengeAnswerException">
/// Thrown if the session challenge answer is invalid.
/// </exception>
/// <exception cref="IncorrectLoginCredentialsException">
/// Thrown if the username or password is incorrect.
/// </exception>
/// <exception cref="IncorrectTwoFactorAuthenticationCodeException">
/// Thrown if the two-factor authentication code is incorrect.
/// </exception>
/// <exception cref="PrivateAccessTokenRequiredException">
/// Thrown if the user is not authenticated and the private access token is required.
/// </exception>
/// <exception cref="SessionExpiredException">
/// Thrown if the session has expired.
/// </exception>
/// <exception cref="TwoFactorAuthenticationRequiredException">
/// Thrown if two-factor authentication is required.
/// </exception>
public virtual void AuthenticateUser(string username, string password,
string otp = null, SessionIdentification sessionID = null)
{
if (sessionID == null && _session != null)
{
sessionID = new()
{
SessionID = _session.SessionID,
ClientPublicHash = PublicHash
};
}
JArgs args = new(){
{UsernameKey, username},
{PasswordKey, password},
{SessionIDKey, sessionID},
};
// check if the passed-by otp argument is valid or not.
// if yes, ignore _otp field and use user's specified otp value.
// otherwise check for _should_otp and see if we should send an
// otp answer or not.
if (IsOtpValid(otp))
{
args.Add(OtpKey, otp);
sessionID.ChallengeAnswer = otp;
}
else if (_should_otp && IsOtpValid(_otp))
{
// after adding otp answer to args, don't forget to set
// _should_otp to false (and _otp to null).
args.Add(OtpKey, _otp);
sessionID.ChallengeAnswer = _otp;
_should_otp = false;
_otp = null;
}
var request = GetRpcRequest(AuthenticateUserMethod, args);
var message = new HttpRequestMessage(HttpMethod.Post, _endpoint);
message.Content = SerializeContent(request);
message.Content.Headers.ContentType = _contentTypeValue;
var resp = HttpClient.Send(message);
var contentStr = ReadFromContent(resp.Content);
Console.WriteLine(contentStr);
}
/// <summary>
/// returns a challenge's answer using the session's challenge secret.
/// <code> since: v0.0.0 </code>
/// </summary>
protected internal virtual string GetChallengeAnswer(string secret)
{
var otp = new Totp(Encoding.UTF8.GetBytes(secret));
return KeyGeneration.GetSha1(otp.ComputeTotp() + PrivateHash);;
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Gets the session of this <see cref="SocialvoidClient"/> if and only
/// if you have already established a session (or has loaded it from a file);
/// oterwise it will just return a null object instead of throwing an exception.
/// <code> since: v0.0.0 </code>
/// </summary>
public virtual SessionEstablished GetSession()
{
return _session;
}
/// <summary>
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="method">
/// the method.
/// </param>
/// <param name="args">
/// the arguments.
/// </param>
/// <param name="id">
/// the request ID.
/// </param>
/// <param name="useID">
/// set it to `true` if you want this request to have requestID parameter
/// set. (if the passed-by id paramater is null, this method will generate
/// a new id itself.)
/// </param>
protected internal JRequest GetRpcRequest(string method,
JArgs args = null,
Nullable<long> id = null,
bool useID = true)
{
if (string.IsNullOrWhiteSpace(method))
{
throw new ArgumentException(
"method name in a rpc request cannot be null or empty",
nameof(method));
}
if (useID && (id == null))
{
id = DateTime.Now.Ticks;
}
return useID && id != null && id.HasValue ?
new()
{
Method = method,
Arguments = args,
ID = id.Value,
} :
new()
{
Method = method,
Arguments = args,
};
}
/// <summary>
/// <code> since: v0.0.0 </code>
/// </summary>
protected StringContent SerializeContent(JRequest request)
{
return new(request.Serialize());
}
/// <summary>
/// Parses the content of a <see cref="HttpContent"/> as a
/// <see cref="JResponse{T}"/>.
/// </summary>
/// <exception cref="OutOfMemoryException" />
/// <exception cref="IOException" />
protected internal JResponse<VType> ParseContent<VType>(
HttpRequestMessage message,
bool ex = true)
where VType : class
{
if (HttpClient == null)
{
throw new InvalidOperationException("HttpClient wasn't initialized");
}
var resp = HttpClient.Send(message);
if (resp == null)
{
throw new InvalidOperationException("HttpClient.Send returned null");
}
return ParseContent<VType>(resp.Content, ex);
}
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Creates a new instance of the <see cref="SocialvoidClient"/> class.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="publicHash">
/// the public hash of the client.
/// </param>
/// <param name="privateHash">
/// the private hash of the client.
/// </param>
/// <param name="platform">
/// the platform of the client.
/// </param>
/// <param name="name">
/// the client name.
/// </param>
/// <param name="version">
/// the version of the client.
/// </param>
public static SocialvoidClient GetClient(string publicHash, string privateHash,
string platform, string name, string version)
{
if (string.IsNullOrWhiteSpace(publicHash) || publicHash.Length != 64)
{
throw new ArgumentException(
"publicHash parameter is invalid",
nameof(publicHash));
}
if (string.IsNullOrWhiteSpace(privateHash) || privateHash.Length != 64)
{
throw new ArgumentException(
"privateHash parameter is invalid",
nameof(privateHash));
}
if (string.IsNullOrWhiteSpace(platform))
{
throw new ArgumentException(
"platform cannot be null or empty",
nameof(platform));
}
if (string.IsNullOrWhiteSpace(version))
{
throw new ArgumentException(
"version cannot be null or empty",
nameof(version));
}
return new SvClient(publicHash, privateHash, platform, name, version);
}
/// <summary>
/// Checks if a string can be sent as a TOTOP answer or not.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="otp">
/// the otp string to check.
/// </param>
/// <returns>
/// <c>true</c> if the otp string is valid; otherwise <c>false</c>.
/// </returns>
protected internal static bool IsOtpValid(string otp)
{
return !(string.IsNullOrWhiteSpace(otp) || otp.Length > 64);
}
/// <summary>
/// reads the content of a <see cref="HttpContent"/> as a string.
/// returns <c>null</c> if the stream cannot be read.
/// </summary>
/// <exception cref="OutOfMemoryException" />
/// <exception cref="IOException" />
protected internal static string ReadFromContent(HttpContent content)
{
var stream = content.ReadAsStream();
if (stream == null || !stream.CanRead)
{
return null;
}
return new StreamReader(stream).ReadToEnd();
}
/// <summary>
/// Parses the content of a <see cref="HttpContent"/> as a
/// <see cref="JResponse{T}"/>.
/// </summary>
/// <exception cref="OutOfMemoryException" />
/// <exception cref="IOException" />
protected internal static JResponse<VType> ParseContent<VType>(
HttpContent content,
bool ex = true)
where VType : class
{
var jresp = JResponse<VType>.Deserialize(ReadFromContent(content));
if (ex && jresp.HasError())
{
throw jresp.GetException();
}
return jresp;
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,100 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Client
{
internal sealed class SvClient : SocialvoidClient
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
// some members here
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
public SvClient(string publicHash, string privateHash,
string platform, string name, string version) :
base(publicHash, privateHash, platform, name, version)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Get Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
// some methods here
#endregion
//-------------------------------------------------
}
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the client is attempting

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the authentication process failed

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the user does not support

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the given session challenge answer

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the given login credentials

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the given two-factor

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the client attempts to

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the user/entity uses a

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the client tried to use a session

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the requested session can

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.AuthenticationErrors
{
/// <summary>
/// This exception will be raised when the Two-Factor Authentication

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,10 +16,10 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors
namespace Socialvoid.Errors
{
/// <summary>
/// All error codes received from the SocialVoid servers.
/// All error codes received from the Socialvoid servers.
/// <code> Since: v0.0.0 </code>
/// </summary>
public enum ErrorCodes
@ -268,6 +268,61 @@ namespace SocialVoid.Errors
InternalServerError = 16384,
#endregion
//-------------------------------------------------
#region RPC Errors
/// <summary>
/// Execution of the server method was aborted due to a cancellation request from
/// the client.
/// <code> Since: v0.0.0 </code>
/// </summary>
RequestCanceled = -32800,
/// <summary>
/// Invalid JSON was received by the server. An error occurred on the server while
/// parsing the JSON text.
/// <code> Since: v0.0.0 </code>
/// </summary>
ParseError = -32700,
/// <summary>
/// Internal JSON-RPC error.
/// <code> Since: v0.0.0 </code>
/// </summary>
InternalError = -32603,
/// <summary>
/// Invalid method parameter(s).
/// <code> Since: v0.0.0 </code>
/// </summary>
InvalidParams = -32602,
/// <summary>
/// The method does not exist / is not available.
/// <code> Since: v0.0.0 </code>
/// </summary>
MethodNotFound = -32601,
/// <summary>
/// The JSON object sent is not a valid Request object.
/// <code> Since: v0.0.0 </code>
/// </summary>
InvalidRequest = -32600,
/// <summary>
/// Indicates the RPC call was made but the target threw an exception.
/// <code> Since: v0.0.0 </code>
/// </summary>
InvocationErrorWithException = -32004,
/// <summary>
/// Indicates a response could not be serialized as the application intended.
/// <code> Since: v0.0.0 </code>
/// </summary>
ResponseSerializationFailure = -32003,
/// <summary>
/// Indicates a request was made to a remotely marshaled object that never existed
/// or has already been disposed of.
/// <code> Since: v0.0.0 </code>
/// </summary>
NoMarshaledObjectFound = -32001,
/// <summary>
/// Indicates the RPC call was made but the target threw an exception.
/// <code> Since: v0.0.0 </code>
/// </summary>
InvocationError = -32000
#endregion
}
}

View File

@ -1,14 +1,17 @@
using System;
using SocialVoid.Errors.ServerErrors;
using SocialVoid.Errors.NetworkErrors;
using SocialVoid.Errors.ValidationErrors;
using Socialvoid.Errors.RPCErrors;
using Socialvoid.Errors.ServerErrors;
using Socialvoid.Errors.NetworkErrors;
using Socialvoid.Errors.ValidationErrors;
using Socialvoid.Errors.AuthenticationErrors;
namespace SocialVoid.Errors
namespace Socialvoid.Errors
{
/// <summary>
///
/// <code> Since: v0.0.0 </code>
/// </summary>
[Serializable]
public class GeneralException : Exception
{
//-------------------------------------------------
@ -192,6 +195,27 @@ namespace SocialVoid.Errors
// Server Errors
ErrorCodes.InternalServerError =>
new InternalServerErrorException(m),
// RPC Errors
ErrorCodes.RequestCanceled =>
new RequestCanceledException(m),
ErrorCodes.ParseError =>
new ParseErrorException(m),
ErrorCodes.InternalError =>
new InternalErrorException(m),
ErrorCodes.InvalidParams =>
new InvalidParamsException(m),
ErrorCodes.MethodNotFound =>
new MethodNotFoundException(m),
ErrorCodes.InvalidRequest =>
new InvalidRequestException(m),
ErrorCodes.InvocationErrorWithException =>
new InvocationErrorWithExException(m),
ErrorCodes.ResponseSerializationFailure =>
new ResponseSerializationFailureException(m),
ErrorCodes.NoMarshaledObjectFound =>
new NoMarshaledObjectFound(m),
ErrorCodes.InvocationError =>
new InvocationErrorException(m),
// an unknown error code?
_ => new(m, err)

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.NetworkErrors
{
/// <summary>
/// This exception will be raised when the client attempts to repost a

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.NetworkErrors
{
/// <summary>
/// This exception will be raised when there was an error while trying to

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.NetworkErrors
{
/// <summary>
/// This exception will be raised when the requested user entity

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.NetworkErrors
{
/// <summary>
/// This exception will be raised when the client requests a post that

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.NetworkErrors
namespace Socialvoid.Errors.NetworkErrors
{
/// <summary>
/// This exception will be raised when the client requests a post that

View File

@ -0,0 +1,84 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when an internal JSON-RPC error
/// happens at the server-side.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class InternalErrorException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.InternalError"/> error code
/// will be returned because of an internal JSON-RPC error.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.InternalError;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="InternalErrorException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal InternalErrorException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when invalid method parameter(s) is
/// received by socialvoid's servers.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class InvalidParamsException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.InvalidParams"/> error code
/// will be returned because invalid method parameter(s) is
/// received by socialvoid's servers.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.InvalidParams;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="InvalidParamsException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal InvalidParamsException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when the JSON object sent to
/// the socialvoid's server is not a valid Request object.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class InvalidRequestException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.InvalidRequest"/> error code
/// will be returned because the JSON object sent is not a
/// valid Request object.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.InvalidRequest;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="InvalidRequestException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal InvalidRequestException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when the RPC call was made but the target
/// threw an exception.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class InvocationErrorException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.InvocationError"/> error code
/// will be returned because the RPC call was made but the target
/// threw an exception.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.InvocationError;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="InvocationErrorException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal InvocationErrorException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when the RPC call was made but
/// the target threw an exception.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class InvocationErrorWithExException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.AlreadyReposted"/> error code
/// will be returned because the RPC call was made but
/// the target threw an exception.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.InvocationErrorWithException;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="InvocationErrorWithExException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal InvocationErrorWithExException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when the method does not exist / is
/// not available.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class MethodNotFoundException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.MethodNotFound"/> error code
/// will be returned because the method does not exist / is
/// not available.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.MethodNotFound;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="MethodNotFoundException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal MethodNotFoundException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when a request is made to a remotely
/// marshaled object that never existed or has already been disposed of.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class NoMarshaledObjectFound : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.NoMarshaledObjectFound"/> error code
/// will be returned because a request was made to a remotely marshaled object
/// that never existed or has already been disposed of.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.NoMarshaledObjectFound;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="NoMarshaledObjectFound"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal NoMarshaledObjectFound(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when invalid JSON is received by the server.
/// An error occurred on the server while parsing the JSON text.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class ParseErrorException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.ParseError"/> error code
/// will be returned because invalid JSON was received by the server.
/// An error occurred on the server while parsing the JSON text.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.ParseError;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="ParseErrorException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal ParseErrorException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when execution of the server method is
/// aborted due to a cancellation request from the client.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class RequestCanceledException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.RequestCanceled"/> error code
/// will be returned because execution of the server method was aborted
/// due to a cancellation request from the client.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.RequestCanceled;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="RequestCanceledException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal RequestCanceledException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace Socialvoid.Errors.RPCErrors
{
/// <summary>
/// This exception will be raised when a response cannot not be serialized
/// as the application intended.
/// <code> Since: v0.0.0 </code>
/// </summary>
public sealed class ResponseSerializationFailureException : GeneralException
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The <see cref="ErrorCodes.ResponseSerializationFailure"/> error code
/// will be returned because a response could not be serialized
/// as the application intended.
/// <code> Since: v0.0.0 </code>
/// </summary>
public override ErrorCodes ErrorCode
{
get
{
return ErrorCodes.ResponseSerializationFailure;
}
}
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a new instance of <see cref="ResponseSerializationFailureException"/>.
/// <code> Since: v0.0.0 </code>
/// </summary>
internal ResponseSerializationFailureException(string message) : base(message)
{
;
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
}
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ServerErrors
namespace Socialvoid.Errors.ServerErrors
{
/// <summary>
/// This exception will be raised when there is an unexpected error

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the Biography is too long

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the client name contains invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the client's private hash is invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the client's public hash is invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the First Name provided contains

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the Last Name provided contains

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the given password is invalid and/or

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the client provide an invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the platform name contains invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the post contains invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the session identification

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the given username is invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the given username is invalid

View File

@ -1,6 +1,6 @@
/*
* This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
* Copyright (c) 2021 SocialVoid.NET Authors.
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace SocialVoid.Errors.ValidationErrors
namespace Socialvoid.Errors.ValidationErrors
{
/// <summary>
/// This exception will be raised when the given username is invalid

View File

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View File

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

View File

@ -0,0 +1,81 @@
using System;
using System.Text.Json.Serialization;
using System.Collections.Generic;
namespace Socialvoid.JObjects
{
/// <summary>
/// A simple <see cref="Dictionary{TKey, TValue}"/> object.
/// <code> since: v0.0.0 </code>
/// </summary>
[Serializable]
public class JArgs: Dictionary<string, object>
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Get Method's Region
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Text.Json.Serialization;
namespace Socialvoid.JObjects
{
/// <summary>
/// A <see cref="JError"/> object which contains basic information
/// about an error returned by the server.
/// <code> since: v0.0.0 </code>
/// </summary>
[Serializable]
public sealed class JError
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The response error code.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("code")]
public int Code { get; set; }
/// <summary>
/// The error message.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("message")]
public string Message { get; set; }
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Get Method's Region
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,122 @@
using System;
using System.Text.Json.Serialization;
using System.Text.Json;
namespace Socialvoid.JObjects
{
/// <summary>
/// A <see cref="JRequest"/> object which contains basic information
/// about an error returned by the server.
/// <code> since: v0.0.0 </code>
/// </summary>
[Serializable]
public sealed class JRequest
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The JSON-RPC version. Should be equal to "2.0".
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("jsonrpc")]
public string JsonRPC { get; set; } = "2.0";
/// <summary>
/// The error message.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("method")]
public string Method { get; set; }
/// <summary>
/// The error message.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("id")]
public long ID { get; set; }
/// <summary>
/// The error message.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("params")]
public JArgs Arguments { get; set; }
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
/// <summary>
/// Changes the ID property of this value to <c>DateTime.Now.Ticks</c>.
/// <code> since: v0.0.0 </code>
/// </summary>
public void ChangeID()
{
ID = DateTime.Now.Ticks;
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Serializes this request as a string.
/// <code> since: v0.0.0 </code>
/// </summary>
public string Serialize()
{
return JsonSerializer.Serialize(this);
}
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,145 @@
using System;
using System.Text.Json.Serialization;
using Socialvoid.Errors;
using System.Text.Json;
namespace Socialvoid.JObjects
{
/// <summary>
/// A <see cref="JResponse{T}"/> with a specified result type.
/// <code> since: v0.0.0 </code>
/// </summary>
[Serializable]
public sealed class JResponse<T> where T: class
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The Json-rpc version.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("jsonrpc")]
public string RPCVersion { get; set; }
/// <summary>
/// The Json-rpc request id.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("id")]
public long ID { get; set; }
/// <summary>
/// The results.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("result")]
public T Result { get; set; }
/// <summary>
/// The results.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("error")]
public JError Error { get; set; }
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Checks if the current response has error or not.
/// <code> since: v0.0.0 </code>
/// </summary>
public bool HasError()
{
return Error != null;
}
/// <summary>
/// Will convert the current <see cref="Error"/> property of this value
/// to a <see cref="GeneralException"/>.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <returns>
/// returns a <see cref="GeneralException"/> if and only if the
/// <see cref="Error"/> property is not null; otherwise returns null.
/// </returns>
public GeneralException GetException()
{
if (!HasError())
{
return null;
}
return GeneralException.GetException(Error.Message,
(ErrorCodes)Error.Code);
}
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Will convert a json string to a <see cref="JResponse{T}"/>.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <returns>
/// returns a <see cref="JResponse{T}"/> value.
/// </returns>
public static JResponse<T> Deserialize(string text)
{
return JsonSerializer.Deserialize<JResponse<T>>(text);
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,184 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
/*
* Credits to "Shane" from SO answer here:
* http://stackoverflow.com/a/7135008/1090359
*/
using System;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Base32 encoding/decoding helper class.
/// <code> since: v0.0.0 </code>
/// </summary>
public static class Base32Encoding
{
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Converts a string to a byte array using the specified encoding.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentException"/>
public static byte[] ToBytes(string input)
{
if (string.IsNullOrEmpty(input))
{
throw new ArgumentNullException("input");
}
input = input.TrimEnd('='); //remove padding characters
int byteCount = input.Length * 5 / 8; //this must be TRUNCATED
byte[] returnArray = new byte[byteCount];
byte curByte = 0, bitsRemaining = 8;
int mask = 0, arrayIndex = 0;
foreach(char c in input)
{
int cValue = CharToValue(c);
if (bitsRemaining > 5)
{
mask = cValue << (bitsRemaining - 5);
curByte = (byte)(curByte | mask);
bitsRemaining -= 5;
}
else
{
mask = cValue >> (5 - bitsRemaining);
curByte = (byte)(curByte | mask);
returnArray[arrayIndex++] = curByte;
curByte = (byte)(cValue << (3 + bitsRemaining));
bitsRemaining += 3;
}
}
// in the case we didn't end with a full byte
if (arrayIndex != byteCount)
{
returnArray[arrayIndex] = curByte;
}
return returnArray;
}
/// <summary>
/// Converts an array of byte to a Base32-encoded string.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentException"/>
public static string ToString(byte[] input)
{
if (input == null || input.Length == 0)
{
throw new ArgumentNullException("input");
}
int charCount = (int)Math.Ceiling(input.Length / 5d) * 8;
char[] returnArray = new char[charCount];
byte nextChar = 0, bitsRemaining = 5;
int arrayIndex = 0;
foreach(byte b in input)
{
nextChar = (byte)(nextChar | (b >> (8 - bitsRemaining)));
returnArray[arrayIndex++] = ValueToChar(nextChar);
if (bitsRemaining < 4)
{
nextChar = (byte)((b >> (3 - bitsRemaining)) & 31);
returnArray[arrayIndex++] = ValueToChar(nextChar);
bitsRemaining += 5;
}
bitsRemaining -= 3;
nextChar = (byte)((b << bitsRemaining) & 31);
}
// in the case we didn't end with a full char
if (arrayIndex != charCount)
{
returnArray[arrayIndex++] = ValueToChar(nextChar);
while(arrayIndex != charCount) returnArray[arrayIndex++] = '='; //padding
}
return new string(returnArray);
}
/// <summary>
/// Converts a valid base32 character to it's corresponding value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <exception cref="ArgumentException"/>
private static int CharToValue(char c)
{
// 65 - 90 == uppercase letters
if (c < 91 && c > 64)
{
return c - 65;
}
// 50 - 55 == numbers 2-7
if (c < 56 && c > 49)
{
return c - 24;
}
// 97 - 122 == lowercase letters
if (c < 123 && c > 96)
{
return c - 97;
}
// isn't in any of these chars range?
throw new ArgumentException(
"Character is not a valid Base32 character.",
nameof(c));
}
/// <summary>
/// Converts a valid base32 byte value to its corresponding char.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <exception cref="ArgumentException"/>
private static char ValueToChar(byte b)
{
if (b < 26)
{
return (char)(b + 65);
}
if (b < 32)
{
return (char)(b + 24);
}
throw new ArgumentException("Byte is not a Base32 value", nameof(b));
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,153 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Calculate HMAC-Based One-Time-Passwords (HOTP) from a secret key.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// The specifications for the methods of this class can be found in RFC 4226:
/// http://tools.ietf.org/html/rfc4226
/// </remarks>
public sealed class Hotp : Otp
{
//-------------------------------------------------
#region field's Region
/// <summary>
/// The HOTP size.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly int _hotpSize;
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates an HOTP instance.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="secretKey">
/// The secret key to use in HOTP calculations.
/// </param>
/// <param name="mode">
/// The hash mode to use.
/// </param>
/// <param name="hotpSize">The number of digits that the returning HOTP should have. The default is 6.</param>
public Hotp(byte[] secretKey, OtpHashMode mode = OtpHashMode.Sha1, int hotpSize = 6)
: base(secretKey, mode)
{
if (hotpSize < 6 || hotpSize > 8)
{
throw new ArgumentOutOfRangeException(nameof(hotpSize),
"The hotpSize must be between 6 and 8");
}
_hotpSize = hotpSize;
}
/// <summary>
/// Create a HOTP instance.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="key">
/// The key to use in HOTP calculations.
/// </param>
/// <param name="mode">
/// The hash mode to use.
/// </param>
/// <param name="hotpSize">
/// The number of digits that the returning HOTP should have.
/// The default value is 6.
/// </param>
public Hotp(IKeyProvider key,
OtpHashMode mode = OtpHashMode.Sha1,
int hotpSize = 6)
: base(key, mode)
{
if (hotpSize < 6 || hotpSize > 8)
{
throw new ArgumentOutOfRangeException(nameof(hotpSize),
"The hotpSize must be between 6 and 8");
}
_hotpSize = hotpSize;
}
#endregion
//-------------------------------------------------
#region overrided Method's Region
/// <summary>
/// Takes a time step and computes a HOTP code.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="counter">
/// the counter. This is the number of time steps that have passed.
/// </param>
/// <param name="mode">
/// The hash mode to use.
/// </param>
/// <returns>
/// HOTP calculated code.
/// </returns>
protected override string Compute(long counter, OtpHashMode mode)
{
var data = KeyUtilities.GetBigEndianBytes(counter);
var otp = this.CalculateOtp(data, mode);
return Digits(otp, _hotpSize);
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Takes a counter and then computes a HOTP value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="counter">
/// The timestamp to use for the HOTP calculation.
/// </param>
/// <returns>a HOTP value</returns>
public string ComputeHOTP(long counter)
{
return this.Compute(counter, _hashMode);
}
/// <summary>
/// Verify a value that has been provided with the calculated value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="hotp">the trial HOTP value.
/// </param>
/// <param name="counter">
/// The counter value to verify
/// </param>
/// <returns>
/// <c>true</c> if there is a match; otherwise <c>false</c>.
/// </returns>
public bool VerifyHotp(string hotp, long counter) =>
hotp == ComputeHOTP(counter);
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,57 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Interface used to interact with a key.
/// <code> since: v0.0.0 </code>
/// </summary>
public interface IKeyProvider
{
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Uses the key to get an HMAC using the specified algorithm and data.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// This is a much better API than the previous API which would briefly
/// expose the key for all derived types.
///
/// Now a derived type could be bound to an HSM/smart card/etc if
/// required and a lot of the security limitations of in app/memory
/// exposure of the key can be eliminated.
/// </remarks>
/// <param name="mode">
/// The HMAC algorithm to use.
/// </param>
/// <param name="data">
/// The data used to compute the HMAC.
/// </param>
/// <returns>HMAC of the key and data</returns>
byte[] ComputeHmac(OtpHashMode mode, byte[] data);
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,169 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
using System.Security.Cryptography;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Represents a key in memory.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// This will attempt to use the Windows data protection api to
/// encrypt the key in memory.
/// However, this type favors working over memory protection.
/// This is an attempt to minimize exposure in memory, nothing more.
/// This protection is flawed in many ways and is limited to Windows.
///
/// In order to use the key to compute an hmac it must be temporarily
/// decrypted, used, then re-encrypted.
/// This does expose the key in memory for a time.
/// If a memory dump occurs in this time the plaintext key will be part
/// of it. Furthermore, there are potentially artifacts from the hmac
/// computation, GC compaction, or any number of other leaks even after
/// the key is re-encrypted.
///
/// This type favors working over memory protection. If the particular
/// platform isn't supported then, unless forced by modifying the
/// <c>IsPlatformSupported</c> method, it will just store the key in a standard
/// byte array.
/// </remarks>
public class InMemoryKey : IKeyProvider
{
//-------------------------------------------------
#region field's Region
/// <summary>
/// The key data in memory.
/// <code> since: v0.0.0 </code>
/// </summary>
internal readonly byte[] _KeyData;
/// <summary>
/// The key length representing the length of the <see cref="_KeyData"/>.
/// <code> since: v0.0.0 </code>
/// </summary>
internal readonly int _keyLength;
/// <summary>
/// Used for locking.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly object _stateSync = new();
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates an instance of a key.
/// </summary>
/// <param name="key">Plaintext key data</param>
public InMemoryKey(byte[] key)
{
if (key == null || key.Length == 0)
{
throw new ArgumentException("Key cannot be empty or null",
nameof(key));
}
_keyLength = key.Length;
int paddedKeyLength = (int)Math.Ceiling((decimal)key.Length / (decimal)16) * 16;
_KeyData = new byte[paddedKeyLength];
Array.Copy(key, _KeyData, key.Length);
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Gets a copy of the plaintext key.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// This is internal rather than protected so that the tests can
/// use this method.
/// </remarks>
/// <returns>
/// Plaintext Key
/// </returns>
internal byte[] GetCopyOfKey()
{
var plainKey = new byte[_keyLength];
lock(_stateSync)
{
Array.Copy(_KeyData, plainKey, _keyLength);
}
return plainKey;
}
/// <summary>
/// Uses the key to get an HMAC using the specified algorithm and data.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="mode">
/// The HMAC algorithm to use
/// </param>
/// <param name="data">
/// The data used to compute the HMAC
/// </param>
/// <returns>
/// HMAC of the key and data
/// </returns>
public byte[] ComputeHmac(OtpHashMode mode, byte[] data)
{
byte[] hashedValue = null;
using(HMAC hmac = CreateHmacHash(mode))
{
byte[] key = this.GetCopyOfKey();
try
{
hmac.Key = key;
hashedValue = hmac.ComputeHash(data);
}
finally
{
KeyUtilities.Destroy(key);
}
}
return hashedValue;
}
#endregion
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Create an HMAC object for the specified algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
private static HMAC CreateHmacHash(OtpHashMode otpHashMode)
{
return otpHashMode switch
{
OtpHashMode.Sha256 => new HMACSHA256(),
OtpHashMode.Sha512 => new HMACSHA512(),
_ => new HMACSHA1() //OtpHashMode.Sha1
};
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,143 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
using System.Text;
using System.Security.Cryptography;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Helpers to work with key generations.
/// <code> since: v0.0.0 </code>
/// </summary>
public static class KeyGeneration
{
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Generates a random key in accordance with the RFC recommened
/// length for each algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="length">the key length</param>
/// <returns>The generated key</returns>
public static byte[] GenerateRandomKey(int length)
{
byte[] key = new byte[length];
using(var rnd = RandomNumberGenerator.Create())
{
rnd.GetBytes(key);
return key;
}
}
/// <summary>
/// Generates a random key in accordance with the RFC recommened
/// length for each algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="mode">HashMode</param>
/// <returns>Key</returns>
public static byte[] GenerateRandomKey(OtpHashMode mode = OtpHashMode.Sha1) =>
GenerateRandomKey(LengthForMode(mode));
/// <summary>
/// Uses the procedure defined in RFC 4226 section 7.5 to derive a key
/// from the master key.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="masterKey">
/// The master key from which to derive a device specific key.
/// </param>
/// <param name="publicIdentifier">
/// The public identifier that is unique to the authenticating device.
/// </param>
/// <param name="mode">
/// The hash mode to use. This will determine the resulting key lenght.
/// The default value is sha-1 (as per the RFC) which is 20 bytes
/// </param>
/// <returns>Derived key</returns>
public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey,
byte[] publicIdentifier, OtpHashMode mode = OtpHashMode.Sha1)
{
if(masterKey == null)
{
throw new ArgumentNullException(nameof(masterKey),
"The master key cannot be null");
}
return masterKey.ComputeHmac(mode, publicIdentifier);
}
/// <summary>
/// Uses the procedure defined in RFC 4226 section 7.5 to derive a key
/// from the master key.
/// </summary>
/// <param name="masterKey">The master key from which to derive a device specific key</param>
/// <param name="serialNumber">A serial number that is unique to the authenticating device</param>
/// <param name="mode">The hash mode to use. This will determine the resulting key lenght. The default is sha-1 (as per the RFC) which is 20 bytes</param>
/// <returns>Derived key</returns>
public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey,
int serialNumber,
OtpHashMode mode = OtpHashMode.Sha1) =>
DeriveKeyFromMaster(masterKey,
KeyUtilities.GetBigEndianBytes(serialNumber), mode);
internal static HashAlgorithm GetHashAlgorithmForMode(OtpHashMode mode)
{
switch(mode)
{
case OtpHashMode.Sha256:
return SHA256.Create();
case OtpHashMode.Sha512:
return SHA512.Create();
default: //case OtpHashMode.Sha1:
return SHA1.Create();
}
}
internal static int LengthForMode(OtpHashMode mode)
{
switch(mode)
{
case OtpHashMode.Sha256:
return 32;
case OtpHashMode.Sha512:
return 64;
default: //case OtpHashMode.Sha1:
return 20;
}
}
internal static string GetSha1(string value)
{
var data = Encoding.ASCII.GetBytes(value);
var hashData = new SHA1Managed().ComputeHash(data);
var hash = string.Empty;
foreach (var b in hashData)
{
hash += b.ToString("X2");
}
return hash;
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,96 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Some helper methods to perform common key functions.
/// <code> since: v0.0.0 </code>
/// </summary>
internal static class KeyUtilities
{
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Overwrite potentially sensitive data with random junk.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// Warning!
///
/// This isn't foolproof by any means.
/// The garbage collector could have moved the actual location in memory
/// to another location during a collection cycle and left the old data
/// in place simply marking it as available.
/// We can't control this or even detect it.
/// This method is simply a good faith effort to limit the exposure of
/// sensitive data in memory as much as possible.
/// </remarks>
internal static void Destroy(byte[] sensitiveData)
{
if(sensitiveData == null || sensitiveData.Length == 0)
{
// if there is no data, there is nothing to destroy;
// don't throw an exception, just return.
return;
}
new Random().NextBytes(sensitiveData);
}
/// <summary>
/// converts a long into a big endian byte array.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// RFC 4226 specifies big endian as the method for converting the counter
/// to data and then to hash.
/// </remarks>
static internal byte[] GetBigEndianBytes(long input)
{
// Since .net uses little endian numbers, we need to reverse the byte order to get big endian.
var data = BitConverter.GetBytes(input);
Array.Reverse(data);
return data;
}
/// <summary>
/// converts an int into a big endian byte array.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// RFC 4226 specifies big endian as the method for converting
/// the counter to data and then to hash.
/// </remarks>
static internal byte[] GetBigEndianBytes(int input)
{
// Since .net uses little endian numbers, we need to reverse the byte order to get big endian.
var data = BitConverter.GetBytes(input);
Array.Reverse(data);
return data;
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,194 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// An abstract class that contains common OTP calculations.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// https://tools.ietf.org/html/rfc4226
/// </remarks>
public abstract class Otp
{
//-------------------------------------------------
#region field's Region
/// <summary>
/// the secret key.
/// <code> since: v0.0.0 </code>
/// </summary>
protected readonly IKeyProvider _secretKey;
/// <summary>
/// The hash mode to use.
/// <code> since: v0.0.0 </code>
/// </summary>
protected readonly OtpHashMode _hashMode;
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Constructor for the abstract class using an explicit secret key.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="secretKey">
/// The secret key.
/// </param>
/// <param name="mode">
/// The hash mode to use.
/// </param>
public Otp(byte[] secretKey, OtpHashMode mode)
{
if(secretKey == null || secretKey.Length == 0)
{
throw new ArgumentNullException(nameof(secretKey),
"Secret key cannot be null or empty");
}
// when passing a key into the constructor the caller may depend on
// the reference to the key remaining intact.
_secretKey = new InMemoryKey(secretKey);
_hashMode = mode;
}
/// <summary>
/// Constructor for the abstract class using a generic key provider.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="key"></param>
/// <param name="mode">The hash mode to use</param>
public Otp(IKeyProvider key, OtpHashMode mode)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key), "key cannot be null");
}
_hashMode = mode;
_secretKey = key;
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// An abstract definition of a compute method.
/// Takes a counter and runs it through the derived algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="counter">Counter or step</param>
/// <param name="mode">The hash mode to use</param>
/// <returns>OTP calculated code</returns>
protected abstract string Compute(long counter, OtpHashMode mode);
/// <summary>
/// Helper method that calculates OTPs.
/// <code> since: v0.0.0 </code>
/// </summary>
protected internal long CalculateOtp(byte[] data, OtpHashMode mode)
{
byte[] hmacComputedHash = _secretKey.ComputeHmac(mode, data);
// The RFC has a hard coded index 19 in this value.
// This is the same thing but also accomodates SHA256 and SHA512
// hmacComputedHash[19] => hmacComputedHash[hmacComputedHash.Length - 1]
int offset = hmacComputedHash[hmacComputedHash.Length - 1] & 0x0F;
return (hmacComputedHash[offset] & 0x7f) << 24
| (hmacComputedHash[offset + 1] & 0xff) << 16
| (hmacComputedHash[offset + 2] & 0xff) << 8
| (hmacComputedHash[offset + 3] & 0xff) % 1000000;
}
/// <summary>
/// truncates a number down to the specified number of digits.
/// <code> since: v0.0.0 </code>
/// </summary>
protected internal static string Digits(long input, int digitCount)
{
var truncatedValue = ((int)input % (int)Math.Pow(10, digitCount));
return truncatedValue.ToString().PadLeft(digitCount, '0');
}
/// <summary>
/// Verify an OTP value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="initialStep">
/// The initial step to try.
/// </param>
/// <param name="valueToVerify">
/// The value to verify
/// </param>
/// <param name="matchedStep">
/// Output parameter that provides the step
/// where the match was found. If no match was found it will be 0
/// </param>
/// <param name="window">
/// The window to verify.
/// </param>
/// <returns>
/// <c>true</c> if a match is found; otherwise <c>false</c>.
/// </returns>
protected bool Verify(long initialStep, string valueToVerify, out long matchedStep, VerificationWindow window)
{
window ??= new();
foreach(var frame in window.ValidationCandidates(initialStep))
{
var comparisonValue = this.Compute(frame, _hashMode);
if(ValuesEqual(comparisonValue, valueToVerify))
{
matchedStep = frame;
return true;
}
}
matchedStep = 0;
return false;
}
/// <summary>
/// Constant time comparison of two values.
/// <code> since: v0.0.0 </code>
/// </summary>
private bool ValuesEqual(string a, string b)
{
if (string.IsNullOrWhiteSpace(a) && string.IsNullOrWhiteSpace(b))
{
return true;
}
if(a.Length != b.Length)
{
return false;
}
var result = 0;
for(int i = 0; i < a.Length; i++)
{
result |= a[i] ^ b[i];
}
return result == 0;
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,52 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Indicates which HMAC hashing algorithm should be used.
/// <code> since: v0.0.0 </code>
/// </summary>
public enum OtpHashMode
{
//-------------------------------------------------
#region SHA region
/// <summary>
/// Sha1 is used as the HMAC hashing algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
Sha1,
/// <summary>
/// Sha256 is used as the HMAC hashing algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
Sha256,
/// <summary>
/// Sha512 is used as the HMAC hashing algorithm.
/// <code> since: v0.0.0 </code>
/// </summary>
Sha512,
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,144 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Class to apply a correction factor to the system time.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// In cases where the local system time is incorrect it is preferable to simply correct the system time.
/// This class is provided to handle cases where it isn't possible for the client, the server, or both, to be on the correct time.
///
/// This library provides limited facilities to to ping NIST for a correct network time. This class can be used manually however in cases where a server's time is off
/// and the consumer of this library can't control it. In that case create an instance of this class and provide the current server time as the correct time parameter
///
/// This class is immutable and therefore threadsafe.
/// </remarks>
public class TimeCorrection
{
//-------------------------------------------------
#region Properties Region
/// <summary>
/// Applies the correction factor to the current system UTC time and
/// returns a corrected time.
/// <code> since: v0.0.0 </code>
/// </summary>
public DateTime CorrectedUtcNow
{
get => GetCorrectedTime(DateTime.UtcNow);
}
/// <summary>
/// The timespan that is used to calculate a corrected time.
/// <code> since: v0.0.0 </code>
/// </summary>
public TimeSpan CorrectionFactor
{
get => _timeCorrectionFactor;
}
#endregion
//-------------------------------------------------
#region static field's Region
/// <summary>
/// An instance that provides no correction factor.
/// <code> since: v0.0.0 </code>
/// </summary>
public static readonly TimeCorrection UncorrectedInstance = new();
#endregion
//-------------------------------------------------
#region field's Region
/// <summary>
/// The timespan that is used as a correction factor.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly TimeSpan _timeCorrectionFactor;
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Constructor used solely for the <see cref="UncorrectedInstance"/> static
/// field to provide an instance without a correction factor.
/// <code> since: v0.0.0 </code>
/// </summary>
private TimeCorrection()
{
_timeCorrectionFactor = TimeSpan.FromSeconds(0);
}
/// <summary>
/// Creates a corrected time object by providing the known correct
/// current UTC time.
/// The current system UTC time will be used as the reference.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// This overload assumes UTC.
/// If a base and reference time other than UTC are required then use the
/// other overlaod.
/// </remarks>
/// <param name="correctUtc">The current correct UTC time</param>
public TimeCorrection(DateTime correctUtc)
{
_timeCorrectionFactor = DateTime.UtcNow - correctUtc;
}
/// <summary>
/// Creates a corrected time object by providing the known correct current time
/// and the current reference time that needs correction.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="correctTime">
/// The current correct time.
/// </param>
/// <param name="referenceTime">
/// The current reference time (time that will have the correction factor
/// applied in subsequent calls).
/// </param>
public TimeCorrection(DateTime correctTime, DateTime referenceTime)
{
_timeCorrectionFactor = referenceTime - correctTime;
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Applies the correction factor to the reference time and returns a
/// corrected time.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="referenceTime">
/// The reference time.
/// </param>
/// <returns>
/// The reference time with the correction factor applied.
/// </returns>
public DateTime GetCorrectedTime(DateTime referenceTime) =>
referenceTime - _timeCorrectionFactor;
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,326 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// Calculate Timed-One-Time-Passwords (TOTP) from a secret key.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// The specifications for the methods of this class can be found in RFC 6238:
/// http://tools.ietf.org/html/rfc6238
/// </remarks>
public sealed class Totp : Otp
{
//-------------------------------------------------
#region Constant's Region
/// <summary>
/// The number of ticks as Measured at Midnight Jan 1st 1970.
/// <code> since: v0.0.0 </code>
/// </summary>
internal const long unixEpochTicks = 621355968000000000L;
/// <summary>
/// A divisor for converting ticks to seconds.
/// <code> since: v0.0.0 </code>
/// </summary>
internal const long ticksToSeconds = 10000000L;
#endregion
//-------------------------------------------------
#region field's Region
/// <summary>
/// the step value.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly int _step;
/// <summary>
/// the TOTP length.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly int _totpSize;
/// <summary>
/// the TOTP corrected time.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly TimeCorrection correctedTime;
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates a TOTP instance.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="secretKey">
/// The secret key to use in TOTP calculations
/// </param>
/// <param name="step">
/// The time window step amount to use in calculating time windows.
/// The default is 30 as recommended in the RFC
/// </param>
/// <param name="mode">
/// The hash mode to use
/// </param>
/// <param name="totpSize">
/// The number of digits that the returning TOTP should have.
/// The default value of this argument is 6.
/// </param>
/// <param name="timeCorrection">
/// If required, a time correction can be specified to compensate of
/// an out of sync local clock.
/// </param>
public Totp(byte[] secretKey,
int step = 30,
OtpHashMode mode = OtpHashMode.Sha1,
int totpSize = 6,
TimeCorrection timeCorrection = null)
: base(secretKey, mode)
{
if (step < 0)
{
throw new ArgumentOutOfRangeException(nameof(step),
"Step must be greater than 0");
}
if (totpSize < 0 || totpSize > 10)
{
throw new ArgumentOutOfRangeException(nameof(totpSize),
"TOTP size must be greater than 0 and less than 10");
}
_step = step;
_totpSize = totpSize;
// we never null check the corrected time object.
// Since it's readonly, we'll ensure that it isn't null here
// and provide neatral functionality in this case.
correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance;
}
/// <summary>
/// Creates a TOTP instance.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="key">
/// The secret key to use in TOTP calculations.
/// </param>
/// <param name="step">
/// The time window step amount to use in calculating time windows.
/// The default is 30 as recommended in the RFC
/// </param>
/// <param name="mode">
/// The hash mode to use.
/// </param>
/// <param name="totpSize">
/// The number of digits that the returning TOTP should have.
/// The default is 6.</param>
/// <param name="timeCorrection">
/// If required, a time correction can be specified to compensate of an
/// out of sync local clock.</param>
public Totp(IKeyProvider key,
int step = 30,
OtpHashMode mode = OtpHashMode.Sha1,
int totpSize = 6,
TimeCorrection timeCorrection = null)
: base(key, mode)
{
if (step < 0)
{
throw new ArgumentOutOfRangeException(nameof(step),
"Step must be greater than 0");
}
if (totpSize < 0 || totpSize > 10)
{
throw new ArgumentOutOfRangeException(nameof(totpSize),
"TOTP size must be greater than 0 and less than 10");
}
_step = step;
_totpSize = totpSize;
// we never null check the corrected time object.
// Since it's readonly, we'll ensure that it isn't null here and
// provide neatral functionality in this case.
correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance;
}
#endregion
//-------------------------------------------------
#region overrided Method's Region
/// <summary>
/// Takes a time step and computes a TOTP code.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="counter">time step</param>
/// <param name="mode">The hash mode to use</param>
/// <returns>TOTP calculated code</returns>
protected override string Compute(long counter, OtpHashMode mode)
{
var data = KeyUtilities.GetBigEndianBytes(counter);
var otp = this.CalculateOtp(data, mode);
return Digits(otp, _totpSize);
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Takes a timestamp and applies correction (if provided) and then computes
/// a TOTP value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="timestamp">The timestamp to use for the TOTP calculation</param>
/// <returns>a TOTP value</returns>
public string ComputeTotp(DateTime timestamp) =>
ComputeTotpFromSpecificTime(correctedTime.GetCorrectedTime(timestamp));
/// <summary>
/// Takes a timestamp and computes a TOTP value for corrected UTC now.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// It will be corrected against a corrected UTC time using the provided time correction. If none was provided then simply the current UTC will be used.
/// </remarks>
/// <returns>a TOTP value</returns>
public string ComputeTotp() =>
ComputeTotpFromSpecificTime(this.correctedTime.CorrectedUtcNow);
/// <summary>
/// Verify a value that has been provided with the calculated value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// It will be corrected against a corrected UTC time using the provided time correction. If none was provided then simply the current UTC will be used.
/// </remarks>
/// <param name="totp">
/// the trial TOTP value
/// </param>
/// <param name="timeStepMatched">
/// This is an output parameter that gives that time step that was used to find a match.
/// This is useful in cases where a TOTP value should only be used once. This value is a unique identifier of the
/// time step (not the value) that can be used to prevent the same step from being used multiple times
/// </param>
/// <param name="window">
/// The window of steps to verify.
/// </param>
/// <returns>True if there is a match.</returns>
public bool VerifyTotp(string totp,
out long timeStepMatched,
VerificationWindow window = null)
{
return this.VerifyTotpForSpecificTime(correctedTime.CorrectedUtcNow,
totp, window, out timeStepMatched);
}
/// <summary>
/// Verify a value that has been provided with the calculated value.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="timestamp">
/// The timestamp to use.
/// </param>
/// <param name="totp">
/// The trial TOTP value.
/// </param>
/// <param name="timeStepMatched">
/// This is an output parameter that gives that time step that was
/// used to find a match. This is usefule in cases where a TOTP value
/// should only be used once. This value is a unique identifier of the
/// time step (not the value) that can be used to prevent the same step
/// from being used multiple times.
/// </param>
/// <param name="window">The window of steps to verify</param>
/// <returns>True if there is a match.</returns>
public bool VerifyTotp(DateTime timestamp,
string totp,
out long timeStepMatched, VerificationWindow window = null)
{
return this.VerifyTotpForSpecificTime(
this.correctedTime.GetCorrectedTime(timestamp),
totp, window, out timeStepMatched);
}
/// <summary>
/// Remaining seconds in current window based on UtcNow.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <remarks>
/// It will be corrected against a corrected UTC time using the provided time correction. If none was provided then simply the current UTC will be used.
/// </remarks>
/// <returns>Number of remaining seconds</returns>
public int GetRemainingSeconds() =>
RemainingSecondsForSpecificTime(correctedTime.CorrectedUtcNow);
/// <summary>
/// Remaining seconds in current window.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="timestamp">The timestamp</param>
/// <returns>Number of remaining seconds</returns>
public int GetRemainingSeconds(DateTime timestamp) =>
RemainingSecondsForSpecificTime(correctedTime.GetCorrectedTime(timestamp));
/// <summary>
/// The Remaining seconds in the current window based on
/// the provided timestamp using <see cref="_step"/> value.
/// <code> since: v0.0.0 </code>
/// </summary>
private int RemainingSecondsForSpecificTime(DateTime timestamp)
{
return _step -
(int)(((timestamp.Ticks - unixEpochTicks) / ticksToSeconds) % _step);
}
/// <summary>
/// Verify a value that has been provided with the calculated value.
/// <code> since: v0.0.0 </code>
/// </summary>
private bool VerifyTotpForSpecificTime(DateTime timestamp,
string totp, VerificationWindow window, out long timeStepMatched)
{
var initialStep = CalculateTimeStepFromTimestamp(timestamp);
return this.Verify(initialStep, totp, out timeStepMatched, window);
}
/// <summary>
/// Takes a timestamp and calculates a time step.
/// <code> since: v0.0.0 </code>
/// </summary>
private long CalculateTimeStepFromTimestamp(DateTime timestamp)
{
var unixTimestamp = (timestamp.Ticks - unixEpochTicks) / ticksToSeconds;
var window = unixTimestamp / (long)_step;
return window;
}
/// <summary>
/// Takes a timestamp and computes a TOTP value for corrected UTC value.
/// <code> since: v0.0.0 </code>
/// </summary>
private string ComputeTotpFromSpecificTime(DateTime timestamp)
{
var window = CalculateTimeStepFromTimestamp(timestamp);
return this.Compute(window, _hashMode);
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,100 @@
/*
* This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
* Copyright (c) 2021 Socialvoid.NET Authors.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code of library.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Credits to Devin Martin and the original OtpSharp library:
* https://github.com/kspearrin/Otp.NET
*/
using System.Collections.Generic;
namespace Socialvoid.Security.Otp
{
/// <summary>
/// A verification window.
/// <code> since: v0.0.0 </code>
/// </summary>
public sealed class VerificationWindow
{
//-------------------------------------------------
#region static field's Region
/// <summary>
/// The verification window that accomodates network delay that is
/// recommended in the RFC.
/// <code> since: v0.0.0 </code>
/// </summary>
public static readonly VerificationWindow RfcSpecifiedNetworkDelay = new(1, 1);
#endregion
//-------------------------------------------------
#region field's Region
/// <summary>
/// the previous value in the window.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly int _previous;
/// <summary>
/// the future value in the window.
/// <code> since: v0.0.0 </code>
/// </summary>
private readonly int _future;
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
/// Creates an instance of a verification window.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="previous">The number of previous frames to accept</param>
/// <param name="future">The number of future frames to accept</param>
public VerificationWindow(int previous = 0, int future = 0)
{
_previous = previous;
_future = future;
}
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// Gets an enumberable of all the possible validation candidates.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="initialFrame">
/// The initial frame to validate.
/// </param>
/// <returns>
/// Enumberable of all possible frames that need to be validated.
/// </returns>
public IEnumerable<long> ValidationCandidates(long initialFrame)
{
yield return initialFrame;
for(int i = 1; i <= _previous; i++)
{
var val = initialFrame - i;
if(val < 0)
break;
yield return val;
}
for(int i = 1; i <= _future; i++)
yield return initialFrame + i;
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,136 @@
using System.Text.Json.Serialization;
namespace Socialvoid.Security
{
/// <summary>
/// A <see cref="SessionEstablished"/> object contains basic information
/// about the session that the server has created for us.
/// <code> since: v0.0.0 </code>
/// </summary>
public sealed class SessionEstablished
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The ID of the session obtained when establishing a session.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("id")]
public string SessionID { get; set; }
/// <summary>
/// The Public Hash of the client used when establishing the session.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("challenge")]
public string ChallengeSecret { get; set; }
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
///
/// </summary>
public SessionEstablished()
{
;// make is private, so user use `EstablishNew` static method.
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Get Method's Region
/// <summary>
/// This method will return the challenge secret received from the
/// server.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <returns>
/// <c>null</c> if this object doesn't have any challenge secret;
/// otherwise a valid challenge secret.
/// </returns>
public string GetChallengeSecret()
{
return string.IsNullOrWhiteSpace(ChallengeSecret) ?
null : ChallengeSecret;
}
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
/// <summary>
/// Establishes a new session.
/// <code> since: v0.0.0 </code>
/// </summary>
/// <param name="id">
/// the session id returned from the server or being stored in
/// a file.
/// </param>
/// <param name="challenge">
/// The challenge secret returned from the server.
/// it can be <c>null</c>.
/// please do notice that when you are going to load an already
/// existing session from a file, this parameter should remain <c>null</c>.
/// </param>
/// <returns>
/// A new instance of <see cref="SessionEstablished"/> class.
/// </returns>
public static SessionEstablished EstablishNew(string id, string challenge = null)
{
return new()
{
SessionID = id,
ChallengeSecret = challenge,
};
}
#endregion
//-------------------------------------------------
}
}

View File

@ -0,0 +1,111 @@
using System.Text.Json.Serialization;
namespace Socialvoid.Security
{
/// <summary>
/// A SessionIdentification object allows the client to identify the
/// session it's using and prove that it is the owner of the session;
/// it proves as a identification effort and security effort.
/// Most methods that requires authentication or some sort of identity
/// will require you to pass on this object as a parameter under
/// `session_identification`; missing parameters or invalid security values
/// will cause the request to fail as it's validated upon request.
/// <code> since: v0.0.0 </code>
/// </summary>
public sealed class SessionIdentification
{
//-------------------------------------------------
#region Constant's Region
// some members here
#endregion
//-------------------------------------------------
#region static Properties Region
// some members here
#endregion
//-------------------------------------------------
#region Properties Region
/// <summary>
/// The ID of the session obtained when establishing a session.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("session_id")]
public string SessionID { get; set; }
/// <summary>
/// The Public Hash of the client used when establishing the session.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("client_public_hash")]
public string ClientPublicHash { get; set; }
/// <summary>
/// The session challenge answer revolving around the client's
/// private hash, the same client used to establish the session.
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("challenge_answer")]
public string ChallengeAnswer { get; internal set; }
#endregion
//-------------------------------------------------
#region static field's Region
// some members here
#endregion
//-------------------------------------------------
#region field's Region
// some members here
#endregion
//-------------------------------------------------
#region static event field's Region
// some members here
#endregion
//-------------------------------------------------
#region event field's Region
// some members here
#endregion
//-------------------------------------------------
#region Constructor's Region
/// <summary>
///
/// </summary>
public SessionIdentification()
{
}
#endregion
//-------------------------------------------------
#region Destructor's Region
// some members here
#endregion
//-------------------------------------------------
#region Initialize Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Graphical Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region event Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region overrided Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region ordinary Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Get Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region Set Method's Region
// some methods here
#endregion
//-------------------------------------------------
#region static Method's Region
// some methods here
#endregion
//-------------------------------------------------
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
Copyright (c) 2021 SocialVoid.NET Authors.
This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
Copyright (c) 2021 Socialvoid.NET Authors.
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -23,8 +23,8 @@
<RuntimeIdentifier Condition="'$(OS)' == 'unix'">linux-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(OS)' == 'Windows_NT'">win-x64</RuntimeIdentifier>
-->
<AssemblyName>SocialVoid</AssemblyName>
<RootNamespace>SocialVoid</RootNamespace>
<AssemblyName>Socialvoid</AssemblyName>
<RootNamespace>Socialvoid</RootNamespace>
<description>The official Socialvoid RPC Library written for C#</description>
<NeutralLanguage>en-US</NeutralLanguage>
<!--
@ -34,10 +34,10 @@
<TargetFramework>net5.0</TargetFramework>
<PackageId>SovialVoid</PackageId>
<Version>0.0.1</Version>
<Authors>SocialVoid Team</Authors>
<Authors>Socialvoid Team</Authors>
<PackageProjectUrl>https://github.com/intellivoid/Socialvoid.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/intellivoid/Socialvoid.NET</RepositoryUrl>
<PackageIconUrl>https://github.com/intellivoid/Socialvoid.NET/raw/master/SocialVoid/Icon.ico</PackageIconUrl>
<PackageIconUrl>https://github.com/intellivoid/Socialvoid.NET/raw/master/Socialvoid/Icon.ico</PackageIconUrl>
<PackageIcon>Icon.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
@ -83,17 +83,9 @@
<!--
All package references must be added here.
example:
<PackageReference Include="SharpDX" Version="4.2.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="SharpDX.Direct3D9" Version="4.2.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="SharpDX.DXGI" Version="4.2.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="SharpDX.MediaFoundation" Version="4.2.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="SharpDX.XAudio2" Version="4.2.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="TextCopy" Version="4.3.1" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.5" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
<PackageReference Include="StreamJsonRpc" Version="2.8.21" />
-->
</ItemGroup>
<!--===================================================-->
<!--
@ -154,7 +146,7 @@
<!--===================================================-->
</Project>
<!--End of the SocialVoid.NET Project File.-->
<!--End of the Socialvoid.NET Project File.-->
<!--2021 (C) Intellivoid Inc. -->
<!--2021 (C) SocialVoid Team -->
<!--2021 (C) Socialvoid Team -->

View File

@ -0,0 +1,71 @@
using System;
using Socialvoid.Errors;
using Socialvoid.Client;
using Socialvoid.Errors.ServerErrors;
using Socialvoid.Errors.NetworkErrors;
using Socialvoid.Errors.ValidationErrors;
using NUnit.Framework;
namespace Tests.Client
{
[TestFixture]
public class ClientTest
{
[TestCase("test1: the given login credentials are incorrect.", 8704)]
[TestCase("test2: the given two-factor authentication code is incorrect.", 8705)]
[TestCase("test3: the user 'aliwoto' does not support this method of authentication", 8706)]
[TestCase("test4: the requested session was not found in the database on server-side.", 8707)]
public void AuthenticationErrorsTest(string message, int errorCode)
{
try
{
CreateException(message, errorCode);
}
catch (GeneralException ex)
{
Log("got exception of type", ex.GetType(), "with error code of", ex.ErrorCode);
if (ex.Message != message || (int)ex.ErrorCode != errorCode)
{
throw;
}
}
}
[TestCase(
"4c7148caff498d24deee6c8325f1c15773d637ed76c3a4056e00b77b2beb3097", // public hash
"866d3218b239d39c174fa2b16f54e0fa58f9c69fce8c2d941c12a47a7bc75229", // private hash
"Linux", // platform
"Test .NET RCP Client", // the name
"1.0.0.0" // version
)]
public void AuthenticateUserTest(string publicHash, string privateHash,
string platform, string name, string version)
{
var myClient =
SocialvoidClient.GetClient(publicHash,
privateHash, platform, name, version);
myClient.CreateSession();
myClient.AuthenticateUser("aliwoto", "12345678");
}
private void CreateException(string message, int code)
{
throw GeneralException.GetException(message, (ErrorCodes)code);
}
private void Log(params object[] objs)
{
foreach (var obj in objs)
{
Console.Write(obj);
Console.Write(" ");
}
Console.Write("\n");
}
}
}

View File

@ -0,0 +1,8 @@
{
"endpoint": "http://127.0.0.1:5001/",
"public_hash": "4c7148caff498d24deee6c8325f1c15773d637ed76c3a4056e00b77b2beb3097",
"private_hash": "866d3218b239d39c174fa2b16f54e0fa58f9c69fce8c2d941c12a47a7bc75229",
"platform": "Linux",
"name": "Test Python RCP Client",
"version": "1.0.0.0"
}

View File

@ -1,8 +1,8 @@
using System;
using SocialVoid.Errors;
using SocialVoid.Errors.ServerErrors;
using SocialVoid.Errors.NetworkErrors;
using SocialVoid.Errors.ValidationErrors;
using Socialvoid.Errors;
using Socialvoid.Errors.ServerErrors;
using Socialvoid.Errors.NetworkErrors;
using Socialvoid.Errors.ValidationErrors;
using NUnit.Framework;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET).
Copyright (c) 2021 SocialVoid.NET Authors.
This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET).
Copyright (c) 2021 Socialvoid.NET Authors.
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -63,6 +63,7 @@
<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="StreamJsonRpc" Version="2.8.21" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
</ItemGroup>
<!--===================================================-->
@ -76,8 +77,8 @@
<!--
-->
<ProjectReference Include="..\SocialVoid\SocialVoid.csproj" />
<!--SocialVoid/SocialVoid.csproj-->
<ProjectReference Include="..\Socialvoid\Socialvoid.csproj" />
<!--Socialvoid/Socialvoid.csproj-->
</ItemGroup>
<!--