diff --git a/QRBee.Core/Security/ISecurityService.cs b/QRBee.Core/Security/ISecurityService.cs
index 1da7dba..9a0a73b 100644
--- a/QRBee.Core/Security/ISecurityService.cs
+++ b/QRBee.Core/Security/ISecurityService.cs
@@ -7,6 +7,12 @@ namespace QRBee.Core.Security
///
public interface ISecurityService
{
+ ///
+ /// Private key handler
+ ///
+ ///
+ IPrivateKeyHandler PrivateKeyHandler { get; }
+
// -------------------------- encryption --------------------------
///
diff --git a/QRBee.Core/Security/SecurityServiceBase.cs b/QRBee.Core/Security/SecurityServiceBase.cs
index 9f8f74b..440ed58 100644
--- a/QRBee.Core/Security/SecurityServiceBase.cs
+++ b/QRBee.Core/Security/SecurityServiceBase.cs
@@ -7,13 +7,15 @@ namespace QRBee.Core.Security
public abstract class SecurityServiceBase : ISecurityService
{
- protected IPrivateKeyHandler PrivateKeyHandler { get; }
+ private IPrivateKeyHandler _privateKeyHandler;
protected SecurityServiceBase(IPrivateKeyHandler privateKeyHandler)
{
- PrivateKeyHandler = privateKeyHandler;
+ _privateKeyHandler = privateKeyHandler;
}
+ ///
+ public IPrivateKeyHandler PrivateKeyHandler => _privateKeyHandler;
///
public abstract X509Certificate2 CreateCertificate(string subjectName, byte[] rsaPublicKey);
diff --git a/QRBee.Tests/QRBee.Tests.csproj b/QRBee.Tests/QRBee.Tests.csproj
index 10c7f04..84c0089 100644
--- a/QRBee.Tests/QRBee.Tests.csproj
+++ b/QRBee.Tests/QRBee.Tests.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
enable
false
diff --git a/QRBee/QRBee.Android/Resources/Resource.designer.cs b/QRBee/QRBee.Android/Resources/Resource.designer.cs
index 97c8062..89e6ccb 100644
--- a/QRBee/QRBee.Android/Resources/Resource.designer.cs
+++ b/QRBee/QRBee.Android/Resources/Resource.designer.cs
@@ -14,7 +14,7 @@ namespace QRBee.Droid
{
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.1.0.11")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "13.2.0.99")]
public partial class Resource
{
diff --git a/QRBee/QRBee.Android/Services/AndroidSecurityService.cs b/QRBee/QRBee.Android/Services/AndroidSecurityService.cs
index 4d1d9e2..6c3a3cd 100644
--- a/QRBee/QRBee.Android/Services/AndroidSecurityService.cs
+++ b/QRBee/QRBee.Android/Services/AndroidSecurityService.cs
@@ -8,8 +8,10 @@ namespace QRBee.Droid.Services
{
internal class AndroidSecurityService : SecurityServiceBase
{
- private X509Certificate2 _apiServerCertificate;
- private string ApiServerCertificateFileName => $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/ApiServerCertificate.bin";
+#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
+ private X509Certificate2? _apiServerCertificate;
+#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
+ public static string ApiServerCertificateFileName => $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/ApiServerCertificate.bin";
public AndroidSecurityService(IPrivateKeyHandler privateKeyHandler)
: base(privateKeyHandler)
diff --git a/QRBeeApi/DatabaseSettings.cs b/QRBeeApi/DatabaseSettings.cs
index 54d960c..d7cdc3f 100644
--- a/QRBeeApi/DatabaseSettings.cs
+++ b/QRBeeApi/DatabaseSettings.cs
@@ -4,12 +4,12 @@ namespace QRBee.Api
{
public class DatabaseSettings
{
- public string? ConnectionString { get; set;}
+ public string? Connection { get; set;}
public string? DatabaseName { get; set; }
public MongoClientSettings ToMongoDbSettings()
{
- var settings = MongoClientSettings.FromConnectionString(ConnectionString);
+ var settings = MongoClientSettings.FromConnectionString(Connection);
return settings;
diff --git a/QRBeeApi/Program.cs b/QRBeeApi/Program.cs
index 52cfba9..4d80d44 100644
--- a/QRBeeApi/Program.cs
+++ b/QRBeeApi/Program.cs
@@ -1,6 +1,7 @@
using log4net;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
+using OpenTelemetry.Metrics;
using QRBee.Api;
using QRBee.Api.Services;
using QRBee.Api.Services.Database;
@@ -8,14 +9,22 @@ using QRBee.Core.Security;
var builder = WebApplication.CreateBuilder(args);
+builder.Logging.ClearProviders();
+GlobalContext.Properties["LOGS_ROOT"] = Environment.GetEnvironmentVariable("LOGS_ROOT") ?? "";
+System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
+builder.Logging.AddLog4Net("log4net.config");
-builder.Host.ConfigureLogging(logging =>
-{
- logging.ClearProviders();
- GlobalContext.Properties["LOGS_ROOT"] = Environment.GetEnvironmentVariable("LOGS_ROOT") ?? "";
- System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
- logging.AddLog4Net("log4net.config");
-});
+builder.Services.AddOpenTelemetry()
+ .WithMetrics(options =>
+ {
+ options
+ .AddAspNetCoreInstrumentation()
+ .AddHttpClientInstrumentation()
+ .AddRuntimeInstrumentation()
+ .AddProcessInstrumentation()
+ .AddPrometheusExporter()
+ ;
+ });
// Add services to the container.
@@ -24,11 +33,19 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
+builder.Services
+ .Configure(builder.Configuration.GetSection("QRBeeDatabase"))
+ ;
+
builder.Services
.AddSingleton()
.AddSingleton()
- .Configure(builder.Configuration.GetSection("QRBeeDatabase"))
- .AddSingleton( cfg => new MongoClient(cfg.GetRequiredService>().Value.ToMongoDbSettings()))
+ .AddSingleton( cfg =>
+ {
+ var section = cfg.GetRequiredService>().Value
+ ?? throw new ApplicationException("Configuration for DatabaseSettings is not found");
+ return new MongoClient(section.ToMongoDbSettings());
+ })
.AddSingleton()
.AddSingleton()
.AddSingleton()
@@ -44,10 +61,9 @@ var app = builder.Build();
app.UseSwaggerUI();
}
+app.UseOpenTelemetryPrometheusScrapingEndpoint();
app.UseHttpsRedirection();
-
app.UseAuthorization();
-
app.MapControllers();
app.Run();
diff --git a/QRBeeApi/QRBee.Api.csproj b/QRBeeApi/QRBee.Api.csproj
index b5e6d95..becaa94 100644
--- a/QRBeeApi/QRBee.Api.csproj
+++ b/QRBeeApi/QRBee.Api.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
enable
enable
3b7dc7f1-0b82-4746-b99b-73c43c8826e0
@@ -20,7 +20,14 @@
+
+
+
+
+
+
+
diff --git a/QRBeeApi/Services/QRBeeAPIService.cs b/QRBeeApi/Services/QRBeeAPIService.cs
index 1b05918..e4cf55b 100644
--- a/QRBeeApi/Services/QRBeeAPIService.cs
+++ b/QRBeeApi/Services/QRBeeAPIService.cs
@@ -204,6 +204,7 @@ namespace QRBee.Api.Services
}
catch (Exception e)
{
+ _logger.LogError(e, $"Transaction failed. Merchant={value.ClientResponse.MerchantRequest.MerchantId} Client={value.ClientResponse.ClientId}");
var response = MakePaymentResponse(value, "", "", false, e.Message);
return response;
}
@@ -317,10 +318,10 @@ namespace QRBee.Api.Services
throw new ApplicationException($"The valid from date: {validFrom} is wrong");
}
- if (holderName.Any(char.IsDigit))
- {
- throw new ApplicationException($"The card holder name: {holderName} is wrong");
- }
+ //if (holderName.Any(char.IsDigit))
+ //{
+ // throw new ApplicationException($"The card holder name: {holderName} is wrong");
+ //}
}
private static RSA LoadRsaPublicKey(StringRSAParameters stringParameters)
diff --git a/QRBeeApi/Services/ServerPrivateKeyHandler.cs b/QRBeeApi/Services/ServerPrivateKeyHandler.cs
index 50c41a8..25f5517 100644
--- a/QRBeeApi/Services/ServerPrivateKeyHandler.cs
+++ b/QRBeeApi/Services/ServerPrivateKeyHandler.cs
@@ -2,6 +2,8 @@
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Configuration;
namespace QRBee.Api.Services
{
@@ -20,7 +22,7 @@ namespace QRBee.Api.Services
private const string VeryBadNeverUseCertificatePassword = "+ñèbòFëc׎ßRúß¿ãçPN";
- private string PrivateKeyFileName { get; set; } = $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/{FileName}";
+ protected string PrivateKeyFileName { get; set; } = $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/{FileName}";
private string PrivateKeyCertificatePassword { get; set; } = VeryBadNeverUseCertificatePassword;
public ServerPrivateKeyHandler(ILogger logger, IConfiguration config)
diff --git a/QRBeeApi/appsettings.json b/QRBeeApi/appsettings.json
index 16535b6..686e65e 100644
--- a/QRBeeApi/appsettings.json
+++ b/QRBeeApi/appsettings.json
@@ -1,7 +1,7 @@
{
"QRBeeDatabase": {
- "ConnectionString": "mongodb://localhost:27017",
+ "Connection": "mongodb://localhost:27017",
"DatabaseName": "QRBee"
},
diff --git a/QRBeeApi/log4net.config b/QRBeeApi/log4net.config
index 9cdced5..683eed4 100644
--- a/QRBeeApi/log4net.config
+++ b/QRBeeApi/log4net.config
@@ -6,26 +6,28 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+