"The system cannot find the file specified." exception on an extension

"The system cannot find the file specified." exception on an extension

  
I developed an extension and it simply instances an RSA object to retrieve a keypair.
Locally, i.e., on a console, forms or web application it works without any problem.

When using it on an eSpace the following errors are logged:
-----
Message: The system cannot find the file specified.

at ssInvoiceReady.RssExtensionPseudoCertificates.MssSignString(HeContext heContext, String inParamSymmetricKey, String inParamTextToSign, String inParamCipheredKeyPair, Byte[]& outParamSignature, Byte[]& outParamSignedData)
at ssInvoiceReady.Actions.ActionSignString(HeContext heContext, String inParamSymmetricKey, String inParamTextToSign, String inParamCipheredKeyPair, Byte[]& outParamSignature, Byte[]& outParamSignedData)
at ssInvoiceReady.Flows.FlowInvoiceFlow.ScrnInvoice_List.CommandSignInvoice_Ajax(HeContext heContext, Int32 inParamInvoiceId, String inParamPassword)

at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)
at System.Security.Cryptography.RSA.FromXmlString(String xmlString)
-----

No file is read or written within the extension.

Running platform server on windows 7 professional.

Any ideas?
Hi Miguel,

This is a common issue with reading and writing from the file system, from a web application. The two most common causes are either permissions, or accessing the wrong path in the file system.

One way to check if it is permission-related would be to read our How to regarding file system access.

If it's path related, when you're reading/writing from an extension or eSpace, you should specify the full path - for instance, instead of "temp\miguel", it should be "c:\temp\miguel" .

Have you tried debugging the extension, as well?

Let us know if any of this helps.

Regards,

Paulo Tavares
Hi Paulo,

I'm aware that the read and write of files must be permitted, however, like I posted "No file is read or written within the extension.".
Ah! I thought that was the problematic behavior, not a fact :)

Still, I wouldn't be sure that that doesn't happen. Won't the RSA object's signature method need to read the private key information form somewhere?

It might just be that the current process doesn't have the right permissions to do so. Are you using .Net's native RSA implementation (if it exists)? Have you checked in MSDN where does it read the signing info from, or related to that error?

Regards,

Paulo Tavares
The .Net's RSA implementation generates a keypair when it is created. My goal was to create an RSA object in order to generate a new keypair.
In this case I'm not using the signature method.

I've used this implementation before out of the OutSystems context and everything worked fine... can't understand what is wrong...
Hi Miguel,

I did some Google searches, and this is what I got:

MSDN Article on that problem

StackOverflow question about that problem

I hope this helps. Let us know if you get it to work.

Regards, and have a great weekend!

Paulo Tavares
Hi Paulo!
Hope you had a great weekend like you wished me :P

So, coming back to work... It turns out that the RSA, even not referencing any key store, tries to access the user's keystore. I googled about this and couldn't find any logic explanation... However, I already ran this code on several servers and everything worked ok... Maybe because here we are working with Active Directory ...

So here's a solution (thank you Paulo for your Googling results) if there's is no need to access the keystore:

"3) We may also use machine key stores instead of user's. We just have to pass CRYPT_MACHINE_KEYSET flag to CryptAcquireContext. In order to do that in .NET, we may use a code like this: 

CspParameters RSAParams = new CspParameters();
RSAParams.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider sp = new RSACryptoServiceProvider(1024, RSAParams);"
Now it works like a charm! :)

Thanks for your support Paulo. Much appreciated :)

Have a good week ;)

Cheers!
Hi Miguel,

Yes, I had a great weekend, thankfully - asides from sports results, everything was fine :) I hope yours was great as well.

I'm glad to hear everything is working fine now.

Good work, and keep in touch!

Paulo Tavares