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

Could not find any signing keys in keyring #289

Open
Phoenix01001010 opened this issue May 14, 2024 · 16 comments
Open

Could not find any signing keys in keyring #289

Phoenix01001010 opened this issue May 14, 2024 · 16 comments

Comments

@Phoenix01001010
Copy link

Hello, I have used the Pgpcore 6.3.1 library in my project to sign and encrypt a string. The code works fine locally, but when deployed as a web app on Azure, I am encountering an error: "Could not find any signing keys in the keyring." I have been reading the keys from the appsettings file for now and passing them as a string (I also tried using a memory stream), but none of these methods are working. Could someone please help me identify the possible root cause?

string? publicKey = Helper.GetAppSettings("KeyConfig:PublicKey");
string? privateKey = Helper.GetAppSettings("KeyConfig:PrivateKey");
EncryptionKeys signingKey = new(publicKey, privateKey, passphrase); -Error line

@mattosaurus
Copy link
Owner

Hi, the issue is likely because the path to your appsettings file will be different on your local machine than in Azure so you won't be loading any values in Azure.

I'd suggest using the inbuilt configuration provider rather than a custom helper class and making it available via DI.

        public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();

@Phoenix01001010
Copy link
Author

Hello @mattosaurus Thank you for your speedy response. I can confirm that it's not an issue with values not being loaded in Azure. With additional logging, I could confirm this.

Full stack trace:

Error: Encryption failed. [Could not find any signing keys in keyring at PgpCore.Utilities.FindBestSigningKey(PgpSecretKeyRingBundle secretKeyRingBundle)
at PgpCore.EncryptionKeys.<>c__DisplayClass48_0.b__8()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy1.get_Value()
at PgpCore.EncryptionKeys.get_SigningSecretKey()
at PgpCore.EncryptionKeys.InitializeKeys(IEnumerable`1 publicKeyRings)
at PgpCore.EncryptionKeys..ctor(String publicKey, String privateKey, String passPhrase)

@ustaalon
Copy link

@mattosaurus
The same issue happens to me as well. Using the same code from the examples. When downgrading to previous version its working fine (5.2.0 - the version I used before upgrading to 6.5.1).

@mattosaurus
Copy link
Owner

Hi, @ustaalon / @Phoenix01001010. Do you have an example project that you can share with me that I can use to investigate further?

@Pd-26
Copy link

Pd-26 commented Oct 28, 2024

Hi @mattosaurus I am also facing the same issue. Any update on this ? I am passing Publickeystream and private keystream from azure keyvault. I am using below code from your repository. My input output files are also in stream format. I would like to use Encyrption and signing using streams.

`public PGPEncryptionKeys2(Stream publicKeyStream, Stream privateKeyStream, string passPhrase)
{
if (publicKeyStream == null)
throw new ArgumentException("PublicKeyStream");
if (privateKeyStream == null)
throw new ArgumentException("PrivateKeyStream");
if (passPhrase == null)
throw new ArgumentNullException(nameof(passPhrase), "Invalid Pass Phrase.");

  var keyRings = Utilities.ReadAllKeyRings(publicKeyStream);

  _secretKeys = new Lazy<PgpSecretKeyRingBundle>(() => Utilities.ReadSecretKeyRingBundle(privateKeyStream));
  _passPhrase = passPhrase;
  InitializeKeys(keyRings);

}`

@mattosaurus
Copy link
Owner

Hi, I've created a basic example here and all works as expected, both locally and when deployed to Azure.

https://github.com/mattosaurus/PgpCore.Api

If someon's able to share a project with me that replicates this issue then I'll take another look.

@ustaalon
Copy link

Hey @mattosaurus sorry for not sharing any more details. I will try to do something over this weekend or the next one. I will try to make simple project to reproduce it, as I can't share the original code.

@mattosaurus
Copy link
Owner

Hi @ustaalon, no worries. Does the above example help you out or can you fork that to demonstrate?

@peterasamoah7
Copy link

peterasamoah7 commented Jan 14, 2025

Experiencing this as well after deploying to Azure Container Job. Works fine locally. Seeing the same error as mentioned above. Downgrading to version 5.2.0 resolves this issue. Seems something changed between version which is affecting this. In my scenario am using the public and secure files as base4 strings. I can not share my code since this is a work project.

@mattosaurus
Copy link
Owner

Hi @peterasamoah7, are you able to provide an example project that can demonstrate this? I've provided a working solution above if the code there is of any help to you.

@ragnarredbeerd
Copy link

ragnarredbeerd commented Jan 29, 2025

Hey @mattosaurus I'm having a similar issue as these folks, created a GitHub repo that details the issue: https://github.com/[ragnarredbeerd/PGPKeyIssue](https://github.com/ragnarredbeerd/PGPKeyIssue)

Unfortunately the code you provided in the API project does not address the issue, since it is still using a file in the project - some of the other commenters and myself are trying to use Azure Key Vault to fetch the private key. Appreciate any help you can give!

@mattosaurus
Copy link
Owner

Hi @ragnarredbeerd, thanks for creating a demo repo. Looks like it's currently private so could you please either make it public or grant me access.

I think I'd missed the part about keys coming from key vault sot hat should help me investigate as well.

@ragnarredbeerd
Copy link

Hi try this address: https://github.com/ragnarredbeerd/PGPKeyIssue

The repo is public, I just signed out of GH and was still able to navigate to it.

@dbockspp
Copy link

dbockspp commented Feb 2, 2025

I am having the same problem when trying to use code in Azure that works locally on my dev machine. Locally I just put the private key string (include newlines, etc) along with the passPhrase into config settings in local secrets.json.

I tried to add the same settings in my Azure App Service app settings. The app service finds the settings (or I would log an error about not getting them) but I cannot decrypt.

"Could not find any signing keys in keyring"

Does something else PGP-related need to be set up in Azure like I would have on my local machine where I generated the public and private keys?

@mattosaurus
Copy link
Owner

@dbockspp if you're loading from a local file then my example above should be able to help you as this works in Azure.

https://github.com/mattosaurus/PgpCore.Api

@peterasamoah7
Copy link

peterasamoah7 commented Feb 2, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants