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

Error to convert RsaPrivateCrtKeyParameters to ECPrivateKeyParameters with .Net core 2.1 #83

Closed
kisjay opened this issue May 22, 2021 · 4 comments
Labels
question Further information is requested stale Stale issue that will be closed soon wontfix This will not be worked on

Comments

@kisjay
Copy link

kisjay commented May 22, 2021

I am using this package from solution targeting .Net core 2.1 with p12 certificate. It is throwing error: Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters'
to type 'Org.BouncyCastle.Crypto.Parameters.ECPrivateKeyParameters'.

It is throwing error from below lines of codes in ApnsClient, since target framework is not NET46 it's going into this, does it have something to do with p12( as it is with RSA signed)?:

#if !NET46 certContent = $"-----BEGIN PRIVATE KEY-----\n{certContent}\n-----END PRIVATE KEY-----"; var ecPrivateKeyParameters = (ECPrivateKeyParameters)new PemReader(new StringReader(certContent)).ReadObject(); // See https://github.com/dotnet/core/issues/2037#issuecomment-436340605 as to why we calculate q ourselves // TL;DR: we don't have Q coords in ecPrivateKeyParameters, only G ones. They won't work.

@alexalok
Copy link
Owner

dotAPNS supports certificate-based connection only on .NET Core 3.0 and above. Full .NET Framework and .NET Core 2.2 and below are not supported. #6

@alexalok alexalok added the wontfix This will not be worked on label May 23, 2021
@kisjay
Copy link
Author

kisjay commented May 23, 2021

Thank you Alex for responding but I really need to get it work. I am passing the certcontent(cert Private key) instead of certpath , will that also won't work? What is the alternative in this case then (how APNS will establish the connection)? Please guide.

var options = new ApnsJwtOptions()
{
BundleId = "com.kisjay.XXXX",
CertContent = @"-----BEGIN PRIVATE KEY-----\r\n\XXXX\r\n-----END PRIVATE KEY-----",
KeyId = "XXXXXXXXXX",
TeamId = "YYYYYYYYYY"
};
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
var push = new ApplePush(ApplePushType.Background)
.AddContentAvailable()
.AddToken("dbcde31aXXXXXXXXXXXXXXXXXXXXXXXX.....d6d");
var response = _apnsService.SendPush(push, options);

@alexalok
Copy link
Owner

It seems that you're trying to use p12 certificate for token-based authorization. This will not work. p12 is used for certificate-based authorization.
For token-based authorization please use p8 certificate. You may follow this manual to get one.

@alexalok alexalok added the question Further information is requested label May 23, 2021
@stale
Copy link

stale bot commented Jun 22, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale issue that will be closed soon label Jun 22, 2021
@stale stale bot closed this as completed Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale Stale issue that will be closed soon wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants