mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-09 21:24:34 +00:00
Closes #1950
This commit is contained in:
@@ -56,6 +56,15 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static string? Encrypt(ArchiCryptoHelper.ECryptoMethod cryptoMethod, string stringToEncrypt) {
|
||||
if (!Enum.IsDefined(typeof(ArchiCryptoHelper.ECryptoMethod), cryptoMethod) || string.IsNullOrEmpty(stringToEncrypt)) {
|
||||
throw new ArgumentNullException(nameof(cryptoMethod) + " || " + nameof(stringToEncrypt));
|
||||
}
|
||||
|
||||
return ArchiCryptoHelper.Encrypt(cryptoMethod, stringToEncrypt);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static (bool Success, string Message) Exit() {
|
||||
// Schedule the task after some time so user can receive response
|
||||
|
||||
@@ -166,6 +166,8 @@ namespace ArchiSteamFarm {
|
||||
return await ResponseBlacklistRemove(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false);
|
||||
case "BLRM":
|
||||
return ResponseBlacklistRemove(steamID, args[1]);
|
||||
case "ENCRYPT" when args.Length > 2:
|
||||
return ResponseEncrypt(steamID, args[1], Utilities.GetArgsAsText(message, 2));
|
||||
case "FARM":
|
||||
return await ResponseFarm(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
|
||||
case "INPUT" when args.Length > 3:
|
||||
@@ -974,6 +976,24 @@ namespace ArchiSteamFarm {
|
||||
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
|
||||
}
|
||||
|
||||
private static string? ResponseEncrypt(ulong steamID, string cryptoMethodText, string stringToEncrypt) {
|
||||
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount || string.IsNullOrEmpty(cryptoMethodText) || string.IsNullOrEmpty(stringToEncrypt)) {
|
||||
throw new ArgumentNullException(nameof(steamID) + " || " + nameof(cryptoMethodText) + " || " + nameof(stringToEncrypt));
|
||||
}
|
||||
|
||||
if (!ASF.IsOwner(steamID)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(cryptoMethodText, true, out ArchiCryptoHelper.ECryptoMethod cryptoMethod)) {
|
||||
return FormatStaticResponse(string.Format(Strings.ErrorIsInvalid, nameof(cryptoMethod)));
|
||||
}
|
||||
|
||||
string? encryptedString = Actions.Encrypt(cryptoMethod, stringToEncrypt);
|
||||
|
||||
return FormatStaticResponse(!string.IsNullOrEmpty(encryptedString) ? string.Format(Strings.Result, encryptedString) : Strings.WarningFailed);
|
||||
}
|
||||
|
||||
private static string? ResponseExit(ulong steamID) {
|
||||
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
||||
throw new ArgumentNullException(nameof(steamID));
|
||||
|
||||
@@ -33,6 +33,27 @@ using Newtonsoft.Json.Linq;
|
||||
namespace ArchiSteamFarm.IPC.Controllers.Api {
|
||||
[Route("Api/ASF")]
|
||||
public sealed class ASFController : ArchiController {
|
||||
/// <summary>
|
||||
/// Encrypts data with ASF encryption mechanisms using provided details.
|
||||
/// </summary>
|
||||
[Consumes("application/json")]
|
||||
[HttpPost("Encrypt")]
|
||||
[ProducesResponseType(typeof(GenericResponse<string>), (int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||
public ActionResult<GenericResponse> ASFEncryptPost([FromBody] ASFEncryptRequest request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(request.StringToEncrypt)) {
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.StringToEncrypt))));
|
||||
}
|
||||
|
||||
string? encryptedString = Actions.Encrypt(request.CryptoMethod, request.StringToEncrypt!);
|
||||
|
||||
return Ok(new GenericResponse<string>(encryptedString));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches common info related to ASF as a whole.
|
||||
/// </summary>
|
||||
|
||||
46
ArchiSteamFarm/IPC/Requests/ASFEncryptRequest.cs
Normal file
46
ArchiSteamFarm/IPC/Requests/ASFEncryptRequest.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// _ _ _ ____ _ _____
|
||||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||
// |
|
||||
// Copyright 2015-2020 Łukasz "JustArchi" Domeradzki
|
||||
// Contact: JustArchi@JustArchi.net
|
||||
// |
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// |
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// |
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ArchiSteamFarm.IPC.Requests {
|
||||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
public sealed class ASFEncryptRequest {
|
||||
/// <summary>
|
||||
/// Encryption method used for encrypting this string.
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
[Required]
|
||||
public readonly ArchiCryptoHelper.ECryptoMethod CryptoMethod;
|
||||
|
||||
/// <summary>
|
||||
/// String to encrypt with provided <see cref="CryptoMethod" />.
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
[Required]
|
||||
public readonly string? StringToEncrypt;
|
||||
|
||||
[JsonConstructor]
|
||||
private ASFEncryptRequest() { }
|
||||
}
|
||||
}
|
||||
9
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
9
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
@@ -1333,6 +1333,15 @@ namespace ArchiSteamFarm.Localization {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Result: {0}.
|
||||
/// </summary>
|
||||
public static string Result {
|
||||
get {
|
||||
return ResourceManager.GetString("Result", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Starting....
|
||||
/// </summary>
|
||||
|
||||
@@ -732,4 +732,8 @@ Process uptime: {1}</value>
|
||||
<value>Received InvalidPassword error code {0} times in a row. Your password for this account is most likely wrong, aborting!</value>
|
||||
<comment>{0} will be replaced by maximum allowed number of failed login attempts</comment>
|
||||
</data>
|
||||
<data name="Result" xml:space="preserve">
|
||||
<value>Result: {0}</value>
|
||||
<comment>{0} will be replaced by generic result of various functions that use this string</comment>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user