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

RS256 failed when private key has passphrase #224

Open
3 tasks done
oyljerry opened this issue Sep 2, 2020 · 4 comments
Open
3 tasks done

RS256 failed when private key has passphrase #224

oyljerry opened this issue Sep 2, 2020 · 4 comments

Comments

@oyljerry
Copy link

oyljerry commented Sep 2, 2020

New Issue Checklist

Issue Info

Info Value
Platform Name osx
Platform Version 10.14.6
CocoaLumberjack Version e.g. 2.3.0
Integration Method carthage
Xcode Version Xcode 11.3
Repro rate all the time (100%)
Demo project link

Issue Description and Steps

I am use RS256 to encode token, when the private key generated without password, it works fine, however, when I set password, the code is not worked. It always failed with error: error Domain=NSOSStatusErrorDomain Code=-50 "RSA private key creation from data failed" (paramErr: error in user parameter list) UserInfo={NSDescription=RSA private key creation from data failed}

id <JWTAlgorithmDataHolderProtocol> signDataHolder = [JWTAlgorithmRSFamilyDataHolder new]
        .keyExtractorType([JWTCryptoKeyExtractor privateKeyWithPEMBase64].type)
        .privateKeyCertificatePassphrase(passPhrase)
        .algorithmName(algName).secret(privateKey);

    JWTCodingResultType *result = [JWTEncodingBuilder encodePayload:payload]
        .addHolder(signDataHolder)
        .result;

The privateKey is as below. and passPhrase is "123456"

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,98F34D835B49818EA9C013E1F8A5D87D

MBsKuDXTLnW7mE3/vH9LQIx1vm3+/eGvs6Uzqv4MRRH4RHVJA8Y/AnW6x2UH7ye0
GToIjlBl+RoGfdU5uWKTpqYmTgqB3aG6P7gJebC+minxohQLByUQ+IDylP/+t96H
t0BXN0/Ic/IEjummGPW/bkO39b1mxm7LoW409UjvrPg6NtsvLtQvn9xraRUvcO06
j4WL9YWy1lGCPmXkFp6/7xHJivVBQgdDlmcFiJkIawLzi1xtbe0omadbb+JP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xH5h4qz0d1i2IQs12X8jgDKzeuoC/BQeSiIu1
cyhFTY2mnzaRvAZgj1qjgpDxCSsOgvbRrwxnQa7OvEVBXJMQO/H329NENuJbfTHz
+OyRUuH0Zjc3elr1BEtcAP/kRUH29AtflBOhQ5vLHoGG+2QGvBOxL0AWV1TkugWQ
TNt/PmKTxD4PJm95vXffopVgStnKm/8tnYV8P8FQeUoLogy+rY5zE7gaBN347Wmm
8CjW5+O1K27/LM6JarC/G+a0Zjlt2v2pWgGbxhScVicVc6S8dVLtHdhJlhhqu54+
-----END RSA PRIVATE KEY-----
@lolgear
Copy link
Collaborator

lolgear commented Sep 3, 2020

@oyljerry oh no!
You have external parameters in private key and parser doesn't parse this well...
We need an update for a parser.

@oyljerry
Copy link
Author

oyljerry commented Sep 4, 2020

@oyljerry oh no!
You have external parameters in private key and parser doesn't parse this well...
We need an update for a parser.

@lolgear Thanks for your response.
What do you mean "external parameters", you mean private key's password?
If so, I used .privateKeyCertificatePassphrase(passPhrase) to pass "123456" which is not valid?

@lolgear
Copy link
Collaborator

lolgear commented Sep 4, 2020

@oyljerry
Sorry, my bad.
I mean "extra" parameters.
You have correct key, but also key section contains

Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,98F34D835B49818EA9C013E1F8A5D87D

I assume that if you remove these parameters, JWT will work well.
Could you check it?

@oyljerry
Copy link
Author

oyljerry commented Sep 6, 2020

@lolgear
I have tried as your suggestion. It seems not work.

I generate private key with password 123456, Then, I remove encrypt section Proc-Type: 4,ENCRYPTED..., which will be looks like below. Then I use JWTAlgorithmRSFamilyDataHolder to encode it. however, it still failed as Code=-50 "RSA private key creation from data failed".
When I go back to readme for RS256 usage (https://github.com/yourkarma/JWT#rs256-usage), I think here privateKeyCertificatePassphrase is the passphrase of p12 file, however, in my testing, The password 123456 is the passphrase when generate private key. I think it can NOT work.
Once more, I think remove Proc-Type:... can NOT work, because, there is encryption information (DEK-Info: AES-256-CBC) in it, If remove it, parser should not know how to decrypt it.

DiA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hH/V3hnXbDb70YUQHX
sPTqoh6E2FlCietetnH65ZgoFIm/jYeQ+fdLG2g487p6qdpBrmQWuUkbEAsj/wVt
g/VmszlOH9C7+OJ9F7mv6CySZumyHC7puKG0L8hNptrHcFhIu7fLuepcyTMq4l3m
WpOsjXzARLRVy4VulzzK1hBdqeU2d2HgiFvoJjvCJS4j84W5Q7nAYdo533LcW0Eg
RxV9yckH3rf51iPz6ZfCbMzARbrvIsC1BuY1ibNtK+UFuikOsmpRFzRmGmzWlmsD
Ud1n4XirDtSbcFIZGLFhmXpeNb3g5v6uV7AW27Eh5n+kvWiipW9G/KOsMZgvOoL9
/SJq3B/oXfvGyyIuyuKBO8zRIL8iIsr9s/TjpFW2EAI32Dn3OLgiB/P5HwZy+Jrh
tdvwc/jwnzQv3uQv1tjIVKil+tWKz8zomPw/IFGR9Eghp8ZDJoW58pZh2IwwvnUi
N4LICdtAQk1MAEPGsoLeCQ3ThtCB8lxmXqHqMJaD7pn3Qb4PUT5fwY1KN6UnwgFp

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

2 participants