简体   繁体   中英

Add private key file to Pageant from Azure local storage resource

I'm implementing a Cloud Service (worker role) application in Azure which can add private key files to Pageant from an Azure Local Storage. The p variable is a Process which starts cmd.exe as well.

var filename = "pageant.exe";

var workerRoleStorageName = "PrivateKeys";
var privatekeyfilename = "ThePrivateKey.ppk";
var localResource = RoleEnvironment.GetLocalResource(workerRoleStorageName);
var path = Path.Combine(localResource.RootPath, privatekeyfilename);

p.StandardInput.WriteLine(filename + " "+ path);

I'm in local now, so the content of the path variable is something like this:

c:\\Users\\Username\\AppData\\Local\\dftmp\\Resources\\4691e8f6-fdbd-42ad-af67-986b491aca89\\directory\\PrivateKeys\\ThePrivateKey.ppk

But at the last line of code I have got the following error message:

Couldn't load this key (unable to open file).

It's quite interesting, because if I set up a hard coded simple path it works fine:

var path = @"E:\PrivateKeys\ThePrivateKey.ppk";

I know that the Azure Local Storage folder is hidden in this case, so I tried to set the E:\\PrivateKeys folder to hidden, but it still worked with the hard coded path.

What do you think, why I can't add this file to Pageant from that path?

Pageant is unfortunately not very informative when failing to load a private key. It reports "Couldn't load this key (unable to open file)." for any error, including non existence and lack or read permissions.

As is clear from your comments, in this particular instance, it's lack of permissions.

I suppose you need to run your application with higher privileges or with an appropriate role. I would not expect you can run just the cmd.exe with higher privileges from a less privileged process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM