Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BC Idea]: Support of RSACryptoServiceProvider.ImportEncryptedPkcs8PrivateKey Method #309

Open
marekvicar opened this issue Nov 7, 2023 · 7 comments · May be fixed by #409
Open

[BC Idea]: Support of RSACryptoServiceProvider.ImportEncryptedPkcs8PrivateKey Method #309

marekvicar opened this issue Nov 7, 2023 · 7 comments · May be fixed by #409
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Follow Up The issue has an open question and must be followed up on Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item

Comments

@marekvicar
Copy link

marekvicar commented Nov 7, 2023

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=a9ddabfd-ca32-ee11-a81c-6045bdb6c2ac

Description

We need to be able to work with an encrypted private key in "DER-encoded encrypted PKCS8" format.

Specifically, to import and decrypt the key using the provided password, convert and save it to XmlString format.

Furthermore, use the key to sign the data using RSACryptoServiceProvider, SHA512 hash function, PKCS#1 v1.5 padding

In the BC22 System Application, there are appropriate codeunits 1474 "Signature Key" and 1266 "Cryptography Management", but they do not provide these functions.

The idea is to add new procedures to these codeunits to enable the desired functionality.



Internal work item: AB#479951

@aholstrup1 aholstrup1 added the BCIdea Issue related to a BCIdea label Nov 7, 2023
@JesperSchulz
Copy link
Contributor

Just a little more patience. We're currently setting the right automations up between GitHub <-> DevOps <-> BCIdeas. Shortly we'll be ready to triage and approve ideas!

@JesperSchulz JesperSchulz added the Approved The issue is approved label Nov 16, 2023
@JesperSchulz
Copy link
Contributor

Approved! Please create your PR.

@bcbuild-github-agent bcbuild-github-agent added Linked Issue is linked to a Azure Boards work item and removed BCIdea Issue related to a BCIdea Approved The issue is approved labels Nov 16, 2023
@mazhelez mazhelez added BCIdea Issue related to a BCIdea Approved The issue is approved labels Nov 20, 2023
@marekvicar
Copy link
Author

@JesperSchulz
Hi, I created a draft pull request #409
But the code as we propose cannot be compiled successfully!
We need your suggestion.

We got stuck using the DotNetRSACryptoServiceProvider.ImportEncryptedPkcs8PrivateKey function which has 2 different overloads and the AL compiler cannot recognize the call.
Compiling fails on error "The call is ambiguous between the method 'ImportEncryptedPkcs8PrivateKey(DotNet "System.ReadOnlySpan<System.Byte>", DotNet "System.ReadOnlySpan<System.Byte>", DotNet "System.Int32&")' defined in DotNet ' System.Security.Cryptography.RSACryptoServiceProvider' by the extension 'System Application by Microsoft (24.0.0.0)' and the method 'ImportEncryptedPkcs8PrivateKey(DotNet "System.ReadOnlySpan<System.Char>", DotNet "System.ReadOnlySpan<System.Byte> ", DotNet "System.Int32&")' defined in DotNet 'System.Security.Cryptography.RSACryptoServiceProvider' by the extension 'System Application by Microsoft (24.0.0.0)"

It's a problem of the ReadOnlySpan generic datatype, which AL language cannot handle properly.
Is this somehow solvable using the standard AL language and BusinessCentral application?

If not, we may have to look for a completely different solution outside of standard System application.

@JesperSchulz
Copy link
Contributor

Let me loop in someone from the compiler team! Stay tuned!

@SBalslev
Copy link
Contributor

SBalslev commented Dec 8, 2023

It may not be possible to be specific enough with AL. So, you'll need a .NET wrapper to disambiguate:
ImportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<System.Byte>, System.ReadOnlySpan<System.Byte>System.Int32) ImportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<System.Char>, System.ReadOnlySpan<System.Byte>,System.Int32)

Byte vs. Char

https://learn.microsoft.com/en-us/previous-versions/dynamicsnav-2018-developer/Using-Generics

@marekvicar
Copy link
Author

Yes, that's the point.
We can't do this with the standard AL features available to developers.
Microsoft would have to support this by a .NET wrapper provided, or somehow.

@JesperSchulz JesperSchulz added the Follow Up The issue has an open question and must be followed up on label Dec 15, 2023
@domingosbarreto
Copy link
Contributor

domingosbarreto commented Jul 25, 2024

We have a similar situation where we are trying to use ImportFromPem, but our issue here is that the code compiles, but when executing we get an error stating that BC cannot load System.Private.CoreLib.

Cannot create an instance of the following .NET Framework object: assembly System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, type System.ReadOnlySpan1.`

Can you please help with this?

@JesperSchulz JesperSchulz added the Integration GitHub request for Integration area label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Follow Up The issue has an open question and must be followed up on Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants