-
Notifications
You must be signed in to change notification settings - Fork 104
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
Can you support ES256? #145
Comments
@nico-WX I didn't investigate this feature for a long time. |
I looked at the AppleMusicKit to create the developer token, and I need to specify the JWT algorithm as ES256, so I would like to know if I can support ES256 😄😄 |
@nico-WX Any help will be appreciated :) Nevertheless, it seems that they added EC support in os 13 and, I suppose, in iOS 11.
|
Hi, |
@JanC Right! |
I think you can simply close it :) |
@JanC could you check latest master? |
I tried using the private key I get directly from Apple's APNS. (I revoked the key so that I can post it here)
I used this code snippet but I'm getting the error
- (void)signWithAppleAPNS
{
NSString *algorithmName = @"ES256";
NSString *privateKey = @"-----BEGIN PRIVATE KEY-----\n"
"MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgpnX9ZXmgLCWQ+Hkpvae2PLU68XEzJdp+NjswuBS9RHWgCgYIKoZIzj0DAQehRANCAARMSO6bkKjLT+9Mx9wJRXoqUx+CbeOhAbVGS+3fgvVNGv3QM3NlMou3uguMrITwVvpWjuocXbSzjTwMstMMjsZg\n"
"-----END PRIVATE KEY-----";
id <JWTAlgorithmDataHolderProtocol> signDataHolder = [JWTAlgorithmRSFamilyDataHolder new]
.keyExtractorType([JWTCryptoKeyExtractor privateKeyWithPEMBase64].type)
.algorithmName(algorithmName)
.secret(privateKey);
// sign
NSDictionary *payloadDictionary = @{ @"hello": @"world" };
JWTCodingBuilder *signBuilder = [JWTEncodingBuilder encodePayload:payloadDictionary].addHolder(signDataHolder);
JWTCodingResultType *signResult = signBuilder.result;
NSString *token = nil;
if (signResult.successResult) {
// success
NSLog(@"%@ success: %@", self.debugDescription, signResult.successResult.encoded);
token = signResult.successResult.encoded;
} else {
// error
NSLog(@"%@ error: %@", self.debugDescription, signResult.errorResult.error);
}
// verify
if (token == nil) {
NSLog(@"something wrong");
}
} |
@JanC
I even drop prefix of key to determine correct header to strip off - no luck. very strange and interesting. |
@JanC Online checker says that this key type is public. ( Or I do not understand it output ) I do not understand what what happens. I try to create public key from your key and it is created! By Apple API :( |
When I use the OpenSSL api
I used this source for testing: https://github.com/matthijs2704/vapor-apns/blob/master/Sources/VaporAPNS/String%2BAPNS.swift |
Hi any luck for ES256? I also get same error. |
@AyeChanPyaeSone /*!
@function SecKeyCreateWithData
@abstract Create a SecKey from a well-defined external representation.
@param keyData CFData representing the key. The format of the data depends on the type of key being created.
@param attributes Dictionary containing attributes describing the key to be imported. The keys in this dictionary
are kSecAttr* constants from SecItem.h. Mandatory attributes are:
* kSecAttrKeyType
* kSecAttrKeyClass
@param error On error, will be populated with an error object describing the failure.
See "Security Error Codes" (SecBase.h).
@result A SecKey object representing the key, or NULL on failure.
@discussion This function does not add keys to any keychain, but the SecKey object it returns can be added
to keychain using the SecItemAdd function.
The requested data format depend on the type of key (kSecAttrKeyType) being created:
* kSecAttrKeyTypeRSA PKCS#1 format, public key can be also in x509 public key format
* kSecAttrKeyTypeECSECPrimeRandom ANSI X9.63 format (04 || X || Y [ || K])
*/
SecKeyRef _Nullable SecKeyCreateWithData(CFDataRef keyData, CFDictionaryRef attributes, CFErrorRef *error)
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0); And we have limitations:
|
@lolgear Did you solve it? I also found this problem, the ES256 algorithm ('kSecAttrKeyTypeECDSA') is unavailable: not available on iOS, deprecated; kSecAttrKeyTypeECDSA (deprecated; use kSecAttrKeyTypeECSECPrimeRandom instead.) I tried to set kSecAttrKeyTypeECSECPrimeRandom and kSecAttrKeyTypeECDSA (originally kSecAttrKeyTypeEC), but no matter what value is set here, the value is always 73. |
Any conclusion? Got the same error. |
New Issue Checklist
Issue Info
Issue Description and Steps
Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.
The text was updated successfully, but these errors were encountered: