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 · 6 comments
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 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
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 Linked Issue is linked to a Azure Boards work item
Projects
None yet
Development

No branches or pull requests

6 participants