Embedded host key and private key in referenced project

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Embedded host key and private key in referenced project

Post by KW » Mon 09 Aug 2010 22:33

I have a website project in asp.net that references a project that has the private key and host key embeded as a resource, how do I reference the private key and host key correctly in the website project?

In other words, the referenced project is called ClientCerts. It contains host key: mykey.text and privatekey.ppk both as embeeded resource.

Now if Im adding a connection string in the website project I am unaware how to refernce the files...

I have tried the Data Connections in the server explorer, but when I click on add advanced properties, and select the private key from storage. The pop up box asks Key Type: File, Resource, Storage. I click resource it opens a dialogue I select the key it says: "Unable to add certificate file. No project selected."

Any help appreciated.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Embedded host key and private key in referenced project

Post by Shalex » Tue 10 Aug 2010 15:50

KW wrote:I have a website project in asp.net that references a project that has the private key and host key embeded as a resource, how do I reference the private key and host key correctly in the website project?

In other words, the referenced project is called ClientCerts. It contains host key: mykey.text and privatekey.ppk both as embeeded resource.

Now if Im adding a connection string in the website project I am unaware how to refernce the files...
If you want to access these files at design time, please find them on your file system via the Select menu of MySqlConnection Editor (if you add them to your ClientCerts project, the mykey.text and privatekey.ppk files should be available in the root folder of ClientCerts).
If you want to access mykey.text and privatekey.ppk as embedded resources of ClientCerts.exe (or ClientCerts.dll), you can do it at run-time. Please refer to MSDN: http://support.microsoft.com/kb/319292.
KW wrote:I have tried the Data Connections in the server explorer, but when I click on add advanced properties, and select the private key from storage. The pop up box asks Key Type: File, Resource, Storage. I click resource it opens a dialogue I select the key it says: "Unable to add certificate file. No project selected."
This is a designed behaviour. The embedded resource should be embedded to the assembly of your project. Server Explorer doesn't have an assembly to embed the resource files in.

KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Re: Embedded host key and private key in referenced project

Post by KW » Tue 10 Aug 2010 18:26

Basically, this works:



However, this won't work if I upload my website to a hosting provider. Because the hosting provider in a shared hosting environment doesn't let you fool around in the c drive, ie, browse, read write execute etc. No permissions.

So, what is the syntax for the embedded resource? I have tried:


Where the files are located as a embedded resource using the resx file.

Of course this doesn't work. But I thought this was roughly the idea.
Last edited by KW on Tue 10 Aug 2010 18:27, edited 1 time in total.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 11 Aug 2010 15:49

The correct format of the resource identifier is

Code: Select all

resource://MyAssembly,%ResourcePath%
where MyAssembly stands for the assembly into which the resource is embedded, and ResourcePath is the complete path to the resource in the project. To determine the assembly name you can, e.g., check the "Assembly Name" field in the properties of the project containing the resource.

Please refer to http://www.devart.com/forums/viewtopic.php?t=16923.

KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Post by KW » Wed 11 Aug 2010 18:08

hmmm.

Still can't get this work:

here is my syntax, the project that is referencing the assembly is a website project and I'm not sure if that matters.

ssh private key=resource://ClientCertificate,DsaPrivateKey.ppk;
ssh host key=resource://ClientCertificate,ssh_host_dsa_key.pub;

I get the error, can't find resource. The assembly name I believe is correct.

The assembly .dll is located in the bin directory of the website.

Getting error:
Resource ID ssh_host_dsa_key.pub: resource not found.

The two files located in the ClientCertificate project have build action as Embedded Resource.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 13 Aug 2010 12:32

1. Is ClientCertificate.dll loaded to the process of your web application? For this, please set a break point in your project, run it in the Debug mode of Visual Studio, navigate to the Debug > Windows > Modules window of Visual Studio. Is ClientCertificate.dll there? Also determine the location of the loaded ClientCertificate.dll in this window, and open this loaded assembly in some tool that enables resource viewing (e.g., .NET Reflector) to find out if it really contains the necessary embedded resources.

2. Can you access the keys that are embedded into ClientCertificate.dll in the code from ClientCertificate.dll itself?

3. Tell us the version of your dotConnect for MySQL. You can find it via the Tools > MySQL > About menu of Visual Studio.

KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Post by KW » Fri 13 Aug 2010 17:44

I executed the following code in a windows forms project

var ass = Assembly.Load("ClientCertificate");

var strings = ass.GetManifestResourceNames();

I noticed that my files were correctly showing. I then executed the same code in the website project and noticed they were not in there. The .dll file didn't get updated, I removed the .dll from the website project and readded it. My files then showed up using the previous code and it now works correctly.

Post Reply