(CORE) CORE (2023)

Rebuilding my ancient API factory on modern way (Cryptor, Windows services, IIS management, Windows Task Scheduler, TcpListener, WCF, gRPC, Port Sharing service)

This is my ancient project from more than 15 years ago ( WebActivator ) - API factory for checking License and remote control of computers. If end-computer break license of my software my software is disappears.

Unfortunately I have no time to full finish this my project and make full refactoring it to NET CORE 8, therefore one intermediate point I have uploaded to git https://github.com/Alex-1557/ApiFactory


1. Why ApiFactory?

Why I named this project "ApiFactory"? Because is based of this simple idea:



   1:  Module ApiFactory
   2:      Public Function GetReference(Of T)(ApiName As String, Shift As Integer, Optional Parameters As Object = Nothing) As T
   3:          Dim RegComObjType = Type.GetTypeFromProgID(Encoding.UTF8.GetString(Convert.FromBase64String(ApiName)).Caesar(-Shift))
   4:          If Parameters Is Nothing Then
   5:              Return Activator.CreateInstance(RegComObjType)
   6:          Else
   7:              Return Activator.CreateInstance(RegComObjType, Parameters)
   8:          End If
   9:      End Function
  10:   
  11:  End Module

And I newer use clear API name as text literal on this project


   1:  <TestClass()>
   2:  Public Class CryptoApiFactory
   3:   
   4:      Dim RootRegistryKey = "XXXXXXXXXXX"
   5:   
   6:      <DataRow("cMKfwqbCncKhwpzCn1t/wpLClA==", 45)>
   7:      <TestMethod>
   8:      Public Sub Reg(ApiName As String, Shift As Integer)
   9:          Dim Reg = ApiFactory.GetReference(Of Registry)(ApiName, Shift, RootRegistryKey)
  10:          Console.WriteLine(Reg.GetValue(Of String)("Otp"))
  11:      End Sub
  12:   
  13:      <DataRow("cMCncKhwpzCn1t/wpLClA==", 45, "dcKkwqvCoCpGDCgcKmwqI=", 50)>
  14:      <TestMethod>
  15:      Public Sub Otp(RegApiName As String, RegShift As Integer, OtpApiName As String, OtpShift As Integer)
  16:          Dim Reg = ApiFactory.GetReference(Of Registry)(RegApiName, RegShift, RootRegistryKey)
  17:          Dim OtpSecureString = Reg.GetValue(Of String)("Otp")
  18:   
  19:          Dim Otp = ApiFactory.GetReference(Of Otp)(OtpApiName, OtpShift)
  20:          Console.WriteLine(Otp.GetTimeBasedCode(OtpSecureString))
  21:      End Sub
  22:   
  23:  End Class

All Api's composed from separate COM-objects and stupid middle level user even never can understand what API I used and where that API really placed on disk. This is my ordinary way, I use COM-object maybe on each my projects, for example - How to expand ancient ASPpage by function in Com-visible dll, this is my liked type of projects.

Of course API for control my software license I deploy to one of the system folder, different from my target software what I will deleted if license is violated. And directly my software can not contains any links to license control software. This is common ideas of this project.

Pay attention how each API need to register:

# C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm /codebase E:\Projects\ApiFactory\Control\Control1\Control1\bin\Debug

Interface library used as reference to API factory and will register automatically when you register library with meaningful class.



So, below I try to quick simple describe of each API.

2. Get equipment list of target computer. (*)

I have a lot of project to collection target system equipment list from this project from 2004 year Управление ресурсами компьютера с помощью Windows WMI to this project from 2014 year Collection and processing information about your system.

(*) But currently I decide simplify this project and decide to use this library - WMIGatherer

Also a couple this functions contains first API library.



3. Helper to read/write windows registry.

This is my ancient helper for windows registry Простий сервіс реестра для зберігання вводу користувача десктопних прог.

4. File control.

This is simple wrapper of My namespace plus my ancient project from 2006 year WinDump - фиксация состояния системы. plus a couple of functions from Kernel32 what allow delete my software only after system reboot.



5. Command line.

Cmd Api - this is also nothing at all, this is just simple command line starter.



6. Config helper

This is my ancient helper to modify app.config - Dispose unmanaged resources (configuration, fonts). GC.SuppressFinalize

7. Object dumper.

I have my own object dumpler - Reflection Object dumper., but in this project I use NewtonJson serializer.



8. Sql helper.

This is helper what allow pass delegate as typed SqlReader and work with Sql Db with the same way:



9. WebRequest helper.

This is my extension of WebClient with noTimeout and Get/Post extension with JWT authentication and anonymous Get/Post request (this look as extension of this my ancient library WCF_CLIENT - клиент Web-сервиса (вторая версия).



And finally this extension allow to ultimate simplifying any WebRequest.



10. Cryptor. (*)

Cryptor library is my ancient project from 2009 year NetStringObfuscatorHelper - OpenSource моей библиотеки симметричного шифрования., I used it on many my projects, for example Encrypt sensitive data in DB by Rijndael symmetric algorithm. and I also included that service to Api factory library.

Also I added OTP (*) opensource library Otp.NET, Caesar string obfuscator and a couple of my ancient random generators Робота з байтами у VB.NET - ChrW, BitConverter.ToInt32, Convert.ToInt32, Byte.Parse, ToString("X2") / AllowHexSpecifier, GetBytes/GetString, New Byte(N) {}, UInt32 = &H33., also I have included to this library my ancient ZIP compressor.



Also I included to project the simplest way to hide string as secureString (*)



With As a result I receive cool library what allow me hide any communication with my software and hide any object. And with JsonConvert.SerializeObject/DeSerializeObject allow me send and restore any objects with time OTP stamp, that can decrypt and not allow reproduce captured stream.



This is my way as alternatives to embedded opportunity to .NET framework - secure communication and make it not reproducible on application layer.

Also Caesar/OTP get me additional way for Authenticate web request instead predefined digital sign what I used in most of my project Protect WCF service by password

11. Windows services. (*)

I like Windows services and make it since 2002 year, when VB.NET was applicable to create Windows services.



And I used Windows service to a lot of my projects, for example - Windows service example.

Also I millions time demonize Linux .NET program to Linux services, for example - this is also my liked project type.

But currently I wan to use new way, new opensource library dasMulli/dotnet-win32-service and I'm happy that is new for me way is working.



Pay attention how this project can strated:

# sc.exe create MyService DisplayName= "My Service" binpath= "C:\Program Files\dotnet\dotnet.exe E:\Projects\ApiFactory\Service\DotNetWin32\Win32ServiceHost\Win32ServiceHost\bin\Debug\Win32Service.dll --run-as-service"

12. IIS management. (*)

Since 2002 years, I used ADSI library to manage IIS - Сценарии ADSI, even I have converted ancient ADSI-control library to VB.NET - Thomas_Eck_ADSI_Lib - OpenSource библиотека ADSI-функций Томаса Еска на VB.NET

But currently I decide to try new MS library Microsoft.Web.Administration.dll. And it working !!!



Pay attention that this library must be installed:

# C:\Windows\System32\Dism.exe /enable-feature /online /featurename:IIS-ManagementConsole

13. Windows Task Scheduler. (*)

I know and use millions way to create periodic task from this my most ancient way Выполнение периодических задач в ASP.NET to new way with Quartz services on Net.Core Asynchronous MultiThreaded SSH engine for Web (Net Core 6, Linux) - Part 7,8 (QuartzService/Jobs and Singleton CacheService). ConcurrentDictionary, Interlocked.Increment, SyncLock, Closure variable for MultiThreading, Cron Configuration. Also I like dynamically create Sql Job like this Реализация таймаута на динамически создаваемых SQL JOB, вызывающих SQL CLR сборку.

But in current project I decide to try new way dahall/TaskScheduler/, and I'm happy, this project also working !!!



This is most interesting project for me in this packages, because I many times used this way to start periodic task, but never with fill future. Therefore I need to create full usable interface for this library. This is what I want to do but have no enough time to finish

Also this project used a lot of windows API and I recommend use this project as C# programmer examples, especially how to create library to any .NET version

Of course, to start, you need delete MS Sign and set use last C# version.



Also project contains concrete example of using 143 Windows Pinvoke API (meaning of parameters you can see only on this project dotnet/pinvoke because site pinvoke.net is currerntly shutdown.



14. Listeners (TcpListener, WCF, gRPC, PortSharing). (*)

We can organize receiving request from another computer by a lot of different ways:

  1. Simplest fastest for working and development and cheapest and always workable way is using IIS with ASHX handler Как сделать простейший Web-handler - формирующий XML или JSON.. This is practical implementation of this service type Proxy-handler for graphhopper.com.

  2. If you have no IIS, you can simple organize Socket TCP Sender/Listener, this is also a cool way to create TcpListener for example, I use this way since 2002 year, look for example to this software - Прокси-сервер для передачи нотификаций об изменениях данных в SQL-сервере из локальной сети вовне., Программирование в сетях - in this case I up notification from MS SQL server to proxy server and than translate notification to desktop client, this my ancient software looks as SqlDependency/SqlServiceBroker plus SignalR hub.

    This API included prototype of simplest Socket TCP Sender/Listener.



  3. Next my liked way is ASMX or SVC services, this is my liked service type, I use it in 90% my project when I need any service SOAP/WSDL vs XML data exchange., this service can work as SOAP/WSDP service, this is some list of my project with this service type Защищенный SOAP/WSDL сервис доступа к данным MS SQL (WCF communications).

    Alternatively WCF service can working as REST services - Start WCF service as REST

  4. .Net core services with DI container - this is example to move from .NET Core 3.1 to .NET Core 6 Asp.Net Core 6 new initialization

    I usually demonize and deploy it as Linux services - this is full example with demonize service with Kestrel Informer - site colaboration with JS and simple NET Core ApiController., Deploy .NET Core on Ubuntu, demonize Kestrel, run Nginx as reversy proxy, separate Backend and Frontend

    Wcf can easy connected to angular frontend - for example I created my own parser of Swagger, what create interface to Angular client Scaffolding Angular Client From Swagger.json


  5. gRPC - I don't use this service in practice, because MS can not support code generation to VB.NET from Protobuf, however in restricted mode (with support only ancient ECMA language C# this project type is workable too:


  6. Benefits of gRPC is reduce communication traffic and just as simple connection to Angular frontend like WCF with smnbbrv/ngx-grpc packages.



  7. Port sharing - this is most interesting type of services, I still never used it in practice (instead simple WCF with SOAP/WSDL or REST), but in current project I want to use exactly the same service.





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: http://www.vb-net.com/ApiFactory/Index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>