OPCFoundation / UA-.NETStandard

OPC Unified Architecture .NET Standard
Other
1.96k stars 946 forks source link

Directory "C:\ProgramData\Microsoft\Crypto\Keys" is full of files #1950

Closed cristiankohlmann closed 10 months ago

cristiankohlmann commented 2 years ago

Type of issue

Current Behavior

Whenever I call the Load method of the ApplicationConfiguration class with StoryType equal to Directory a new file is generated in the directory "C:\ProgramData\Microsoft\Crypto\Keys", that is, whenever a new session is created with the server I have this behavior. Currently thousands of files have been created in this directory. I found a lot of material on the internet about this problem and, in the case of the SDK, it occurs in the LoadPrivateKey function of the DirectoryCertificateStore class every time a certificate is loaded. The code resposable for creating the file is bellow:

image

An explanation I found on the internet... https://snede.net/the-most-dangerous-constructor-in-net/

Expected Behavior

I think that per certificate only one private key file should be created or at least at some point the file should be deleted.

Steps To Reproduce

1) Open UA-Reference.sln 2) Run ConsoleReferenceClient project and connect to any server 3) Verify that everytime you connect to a server a new file is generated to "C:\ProgramData\Microsoft\Crypto\Keys" directory.

Environment

- OS: Windows 10
- Environment: VS 2022
- Runtime: net6.0
- Nuget Version:
- Component: Opc.Ua.Core
- Server: Any
- Client: ConsoleReferenceClient

Anything else?

No response

mregen commented 2 years ago

I can see on windows platforms in various locations keys are created but not deleted. We need to investigate how this can be improved.