mirror of
https://github.com/Pro/dkim-exchange.git
synced 2026-04-25 08:55:52 +03:00
[GH-ISSUE #120] Support private key files from OpenSSL #96
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @matbech on GitHub (Jan 3, 2016).
Original GitHub issue: https://github.com/Pro/dkim-exchange/issues/120
Currently it seems that DKIM agent fails to read private key files (.pem) which contain line breaks at position 65. When creating private keys with openssl, it creates .pem with line breaks at position 65:
openssl genrsa -out private.pem
I believe the DKIM signer should support .pem key files with line breaks.
@Pro commented on GitHub (Jan 3, 2016):
I tested with a key from
openssl genrsa -out private.pemand it works for me now.@matbech commented on GitHub (Jan 3, 2016):
Thank you. I get the following error now with my key:
Couldn't load private key for domain abcd.com from C:\Program Files\Exchange DkimSigner\keys\abcd.com.pem: Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair'.
I think the AsymmetricKeyParameters you used before was correct:
github.com/Pro/dkim-exchange@d8fa12dee2 (diff-80fbe89954)@Pro commented on GitHub (Jan 3, 2016):
Unfortunately, the MimeKit DKIM signer expects the key to be of type
AsymmetricCipherKeyPairthus I had it to change fromAsymmetricKeyParameters.If the key is of type
AsymmetricKeyParametersit means that it is in the PKCS#8 format (and does only contain the private key, not the public key).Which command did you use to generate your key? Because
openssl genrsa -out private.pemgenerates a key pair.@matbech commented on GitHub (Jan 3, 2016):
I have extracted the private key from PKCS12 .pfx using this command:
openssl pkcs12 -in abcd.com.pfx -nocerts -out abcd.com.pem -nodes
@Pro commented on GitHub (Jan 3, 2016):
What happens, if you take the PKCS12
abcd.com.pfxinstead of the extracted key? Just to see what happens...@matbech commented on GitHub (Jan 3, 2016):
I removed the password from the .pfx and verified the output. Then tried to select it in the configurator:
"The selected key is not a valid private key"
@matbech commented on GitHub (Jan 3, 2016):
Maybe if you get a RSAPrivateCrtKeyParameters object you could build a AsymmetricCipherKeyPair as following:
@Pro commented on GitHub (Jan 3, 2016):
And another try. The configurator and signer now supports default RSA private keys and the ones exported from PKCS12 files.
@matbech please try the newly compiled .dll (and configurator) in https://github.com/Pro/dkim-exchange/tree/master/Src/Exchange.DkimSigner/bin
@matbech commented on GitHub (Jan 3, 2016):
The configurator is able to load the private key now. However I get this message from the agent:
"Could not initialize MimeKit DkimSigner for domain abcd.com: Private key not found."
Looking at the MimeKit source:
It tells me that you cannot use this constructor because it always expects a AsymmetricCipherKeyPair. Instead read the private key into an AsymmetricKeyParameter object, and use the DkimSigner ctor which takes the AsymmetricKeyParameter argument.
Please also note the extra whitespace in front of the domain name in the error message. PR: https://github.com/Pro/dkim-exchange/pull/124
@matbech commented on GitHub (Jan 3, 2016):
In an earlier comment you mentioned that the DKIM signer requires a AsymmetricCipherKeyPair. However when I look at the documentation it says it expects a AsymmetricKeyParameter:
http://www.mimekit.net/docs/html/M_MimeKit_Cryptography_DkimSigner__ctor.htm
So I would rewrite the KeyHelper.ParseKeyPair
https://github.com/Pro/dkim-exchange/blob/master/Src/Exchange.DkimSigner/Helper/KeyHelper.cs#L19
and something similar in the agent.
@matbech commented on GitHub (Jan 3, 2016):
MimeKit just merged a related patch I have submitted:
https://github.com/jstedfast/MimeKit/pull/216
It should simplify the required changes now.
@Pro commented on GitHub (Jan 3, 2016):
@matbech thanks again! Totally missed that constructor. Recompiled sources are in the repo. Lets see if this fixes it
@matbech commented on GitHub (Jan 3, 2016):
Thank you. It is working now :-)