Skip to content

Commit

Permalink
Merge pull request #162 from 2fast-team/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
jp-weber authored Sep 4, 2024
2 parents f54cd22 + a282608 commit de277a5
Show file tree
Hide file tree
Showing 39 changed files with 3,770 additions and 4,083 deletions.
2 changes: 1 addition & 1 deletion Project2FA.Core/Project2FA.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions Project2FA.Core/Services/JSON/INewtonsoftJSONService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
public interface INewtonsoftJSONService
{
object Deserialize(string parameter);
T DeserializeDecrypt<T>(string key, byte[] initVector, string value, int encryptionVersion);
//T DeserializeDecrypt<T>(string key, byte[] initVector, string value, int encryptionVersion);

T DeserializeDecrypt<T>(byte[] keyArray, byte[] initVector, string value, int encryptionVersion);
T Deserialize<T>(string parameter);
string Serialize(object parameter);
string SerializeEncrypt(string key, byte[] initVector, object parameter, int encryptionVersion);
//string SerializeEncrypt(string key, byte[] initVector, object parameter, int encryptionVersion);
string SerializeEncrypt(byte[] keyArray, byte[] initVector, object parameter, int encryptionVersion);
bool TrySerialize(object parameter, out string result);
bool TryDeserialize<T>(string parameter, out T result);
Expand Down
134 changes: 67 additions & 67 deletions Project2FA.Core/Services/JSON/NewtonsoftJSONService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,44 @@ public bool TrySerialize(object parameter, out string result)
}
}

public string SerializeEncrypt(string key, byte[] initVectorArray, object value, int encryptionVersion)
{
byte[] byteArrayKey;
if (encryptionVersion == 1 || encryptionVersion == 0)
{
byteArrayKey = CryptoService.CreateByteArrayKeyV1(key);
}
else if (encryptionVersion == 2)
{
byteArrayKey = CryptoService.CreateByteArrayKeyV2(key);
}
else
{
byteArrayKey = CryptoService.CreateByteArrayKeyV2(key, 80000);
}

var serializer = new JsonSerializer
{
ContractResolver = _encryptionFactory.GetContractResolver()
};

string serialized;

// per serialize session
Aes algorithm = Aes.Create();
algorithm.Key = byteArrayKey;
algorithm.IV = initVectorArray;

using (_encryptionFactory.GetEncryptSession(algorithm))
{
StringBuilder builder = new StringBuilder();
using (StringWriter writer = new StringWriter(builder))
{
serializer.Serialize(writer, value);
}
return serialized = builder.ToString();
}
}
//public string SerializeEncrypt(string key, byte[] initVectorArray, object value, int encryptionVersion)
//{
// byte[] byteArrayKey;
// if (encryptionVersion == 1 || encryptionVersion == 0)
// {
// byteArrayKey = CryptoService.CreateByteArrayKeyV1(key);
// }
// else if (encryptionVersion == 2)
// {
// byteArrayKey = CryptoService.CreateByteArrayKeyV2(key);
// }
// else
// {
// byteArrayKey = CryptoService.CreateByteArrayKeyV2(key, 80000);
// }

// var serializer = new JsonSerializer
// {
// ContractResolver = _encryptionFactory.GetContractResolver()
// };

// string serialized;

// // per serialize session
// Aes algorithm = Aes.Create();
// algorithm.Key = byteArrayKey;
// algorithm.IV = initVectorArray;

// using (_encryptionFactory.GetEncryptSession(algorithm))
// {
// StringBuilder builder = new StringBuilder();
// using (StringWriter writer = new StringWriter(builder))
// {
// serializer.Serialize(writer, value);
// }
// return serialized = builder.ToString();
// }
//}

public string SerializeEncrypt(byte[] keyArray, byte[] initVectorArray, object value, int encryptionVersion)
{
Expand Down Expand Up @@ -209,35 +209,35 @@ public bool TryDeserialize<T>(string value, out T result)
}
}

public T DeserializeDecrypt<T>(string key, byte[] initVector, string value, int encryptionVersion)
{
byte[] byteArrayKey;
if (encryptionVersion == 1 || encryptionVersion == 0)
{
byteArrayKey = CryptoService.CreateByteArrayKeyV1(key);
}
else
{
byteArrayKey = CryptoService.CreateByteArrayKeyV2(key);
}


var serializer = new JsonSerializer
{
ContractResolver = _encryptionFactory.GetContractResolver()
};

Aes algorithm = Aes.Create();
algorithm.Key = byteArrayKey;
algorithm.IV = initVector;

using (_encryptionFactory.GetDecryptSession(algorithm))
using (var stringReader = new StringReader(value))
using (var jsonReader = new JsonTextReader(stringReader))
{
return serializer.Deserialize<T>(jsonReader);
}
}
//public T DeserializeDecrypt<T>(string key, byte[] initVector, string value, int encryptionVersion)
//{
// byte[] byteArrayKey;
// if (encryptionVersion == 1 || encryptionVersion == 0)
// {
// byteArrayKey = CryptoService.CreateByteArrayKeyV1(key);
// }
// else
// {
// byteArrayKey = CryptoService.CreateByteArrayKeyV2(key);
// }


// var serializer = new JsonSerializer
// {
// ContractResolver = _encryptionFactory.GetContractResolver()
// };

// Aes algorithm = Aes.Create();
// algorithm.Key = byteArrayKey;
// algorithm.IV = initVector;

// using (_encryptionFactory.GetDecryptSession(algorithm))
// using (var stringReader = new StringReader(value))
// using (var jsonReader = new JsonTextReader(stringReader))
// {
// return serializer.Deserialize<T>(jsonReader);
// }
//}

public T DeserializeDecrypt<T>(byte[] keyArray, byte[] initVector, string value, int encryptionVersion)
{
Expand Down
2 changes: 1 addition & 1 deletion Project2FA.Repository/Database/DBPasswordHashRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public DBPasswordHashRepository(Project2FAContext db)
}
public async Task DeleteAsync()
{
await _db.Password.FirstOrDefaultAsync();
_db.Password.Remove(await _db.Password.FirstOrDefaultAsync());
}

public async Task<DBPasswordHashModel> GetAsync()
Expand Down
2 changes: 1 addition & 1 deletion Project2FA.Repository/Project2FA.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
8 changes: 5 additions & 3 deletions Project2FA.Shared/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
using UNOversal.Services.Serialization;
using System.Web;
using UNOversal.Services.Logging;
using System.Text;




Expand Down Expand Up @@ -441,7 +443,7 @@ await Task.Run(async () => {
else
{
datafile = NewtonsoftJSONService.DeserializeDecrypt<DatafileModel>(
SecretService.Helper.ReadSecret(Constants.ContainerName, passwordHashName),
Encoding.UTF8.GetBytes(SecretService.Helper.ReadSecret(Constants.ContainerName, passwordHashName)),
iv,
datafileStr,
datafile.Version);
Expand Down Expand Up @@ -752,7 +754,7 @@ await Task.Run(async () => {
await FileService.WriteStringAsync(
fileName,
NewtonsoftJSONService.SerializeEncrypt(
SecretService.Helper.ReadSecret(Constants.ContainerName, passwordHashName),
Encoding.UTF8.GetBytes(SecretService.Helper.ReadSecret(Constants.ContainerName, passwordHashName)),
iv,
fileModel,
fileModel.Version),
Expand All @@ -766,7 +768,7 @@ await FileService.WriteStringAsync(
#endif
//var fileStream = await file.OpenStreamForWriteAsync();
string content = NewtonsoftJSONService.SerializeEncrypt(
SecretService.Helper.ReadSecret(Constants.ContainerName, passwordHashName),
Encoding.UTF8.GetBytes(SecretService.Helper.ReadSecret(Constants.ContainerName, passwordHashName)),
iv,
fileModel,
fileModel.Version);
Expand Down
5 changes: 4 additions & 1 deletion Project2FA.Shared/Strings/de/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ Bitte synchronisieren Sie die Uhrzeit in den Einstellungen.</value>
<value>Datei/Bild zum Import verwenden</value>
</data>
<data name="ApplicationName" xml:space="preserve">
<value>2fast - Zwei-Faktor-Authentifikator</value>
<value>[Beta] 2fast - Zwei-Faktor-Authentifikator</value>
</data>
<data name="TutorialPageBackButton.Text" xml:space="preserve">
<value>Zurück</value>
Expand Down Expand Up @@ -1356,4 +1356,7 @@ Für die zentrale Verwaltung der Anwendung im Unternehmen unterstützt die Anwen
<data name="TutorialContentDialogCreateOrLoad.Text" xml:space="preserve">
<value>![Erste Schritte](ms-appx:///Assets/Images/firstSteps_DE.png)</value>
</data>
<data name="ChangeDatafilePasswordContentDialogNewPasswordError" xml:space="preserve">
<value>Das eingegebene, neue Passwort ist nicht korrekt.</value>
</data>
</root>
5 changes: 4 additions & 1 deletion Project2FA.Shared/Strings/en/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<value>Change datafile password</value>
</data>
<data name="ChangeDatafilePasswordContentDialogPasswordError.Text" xml:space="preserve">
<value>The entered password is not correct.</value>
<value>The current password entered is not correct.</value>
</data>
<data name="Confirm" xml:space="preserve">
<value>Confirm</value>
Expand Down Expand Up @@ -1354,4 +1354,7 @@ The application supports an MDM configuration for centralised management of the
<data name="TutorialContentDialogCreateOrLoad.Text" xml:space="preserve">
<value>![First steps](ms-appx:///Assets/Images/firstSteps_EN.png)</value>
</data>
<data name="ChangeDatafilePasswordContentDialogNewPasswordError" xml:space="preserve">
<value>The new password entered is not correct.</value>
</data>
</root>
3 changes: 2 additions & 1 deletion Project2FA.Shared/Strings/es/Resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,5 @@ Categorías y filtros](ms-appx:///Assets/Images/categories_FR.png)
# Gestión de aplicaciones de empresa | Gestión de dispositivos móviles (MDM)
La aplicación toma a cargo una configuración MDM para una gestión centralizada de la aplicación en la empresa; por ejemplo, el bloqueo automático de la aplicación o de la pantalla de conexión puede configurarse de manera centralizada. La lista de configuraciones disponibles puede consultarse en [Wiki](https://github.com/2fast-team/2fast/wiki/Enterprise-app-management-%7C-mobile-device-management-(MDM)). | |
| TutorialContentDialogProFeatureHeader.Text | Pro-Funktions | |
| TutorialContentDialogCreateOrLoad.Text | ![Premiers pas](ms-appx:///Assets/Images/firstSteps_EN.png) | |
| TutorialContentDialogCreateOrLoad.Text | ![Premiers pas](ms-appx:///Assets/Images/firstSteps_EN.png) | |
| ChangeDatafilePasswordContentDialogNewPasswordError | La nueva contraseña introducida no es correcta. | |
Loading

0 comments on commit de277a5

Please sign in to comment.