JanssenProject / jans

An open source enterprise digital identity platform for CIAM or workforce... Janssen is a distribution of standards-based, developer friendly, components that are engineered to work together in any cloud. #OAuth #OpenID #FIDO
https://docs.jans.io
Apache License 2.0
455 stars 73 forks source link

Auth Server: new endpoint for key management #293

Open nynymike opened 3 years ago

nynymike commented 3 years ago

The JWKS for OpenID Connect is published on the jwks_endpoint, which can be found on the OpenID configuration page (i.e. .well-known/openid-configuration. What we need is a way to import an external key, with a certain kid.

yuriyz commented 3 years ago

Import consists of :

  1. import new key to /etc/certs/jans-auth-keys.jks file (alias=kid)
  2. add new key to JWKS stored in jansConfWebKeys of jansAppConf

It will work for single instance. @moabu how cluster is going to propagate modified keystore file between nodes?

pujavs commented 3 years ago

Implemented and tested import locally. PR#24 raised for the same => https://github.com/JanssenProject/jans-config-api/pull/24 1) logs - Refer line#7300 - 11-Mar-2021 23:30:06 DEBUG [io.ja.co.se.KeyStoreService] (executor-thread-2) config-api_3.log 2) karate test result - Refer POST src.test.resources.feature.config.jwks.jwks.pdf

pujavs commented 3 years ago

@yuriyz , following is the request and response details for this request. Please confirm 1) Spec post: tags:

yuriyz commented 3 years ago

@pujavs I guess json web key can be generated our of key. Shouldn't we expect here actual key (not jwk) ? (E.g. in pem or der formats.) @nynymike what is your vision on request/response for it ?

pujavs commented 3 years ago

@yuriyz , I needed help in getting the requirement right. As per your suggestion and going through the OB doc (https://openbanking.atlassian.net/wiki/spaces/DZ/pages/1150124033/Directory+2.0+Technical+Overview+v1.5), I understand that the input to our endpoint will be the content of key in PEM format and i have to;

The issue that i am facing is If i get the public key as pem format it does not have all the required details to create the JWK. So the question is will the pem be of the cert which has all the required details + public key. I assume that it cannot be pair or cert cannot have private key for obvious reasons. However using cert pem gives error "17-Mar-2021 16:55:54 ERROR [io.ja.co.se.KeyStoreService] (executor-thread-2) Failed to parse X.509 certificates from bytes: java.security.cert.CertificateException: Unable to initialize, java.io.IOException: Short read of DER length" Am i on right track.. I am stuck and will e able to proceed base on your response. cert_n_log.zip

yuriyz commented 3 years ago

My understanding is that import endpoint must accept : 1) alias (kid) - it has to be provided outside. 2) PEM should contain both private and public keys. If it doesn't contain pair it must be rejected with appropriate error. (Private key is required, otherwise how would we validate tokens.) JWK has to be generated based on pair and updated : a) keystore file b) jwks in persistence.

pujavs commented 3 years ago

@yuriyz , based on the above the input pem will be something like below -----BEGIN PRIVATE KEY----- (Private Key content) -----END PRIVATE KEY----- -----BEGIN PUBLIC KEY----- (Public Key content) -----END PUBLIC KEY----- -----BEGIN CERTIFICATE----- (Certificate content) -----END CERTIFICATE----

pujavs commented 3 years ago

@yuriyz , combined pem seems error prone and hence think that a custom data object with required details is better Details: Issue23_Details.zip Ley me know if this is ok

yuriyz commented 3 years ago

What exactly does look error prone to you ? We can take as basis bouncy castle PEM parser: https://www.bouncycastle.org/docs/pkixdocs1.5on/org/bouncycastle/openssl/PEMParser.html

I didn't dive into it but it seems to cover all cases. re: custom format, I'm not sure I got the goal. Can you ask for PEM sample, so we have exact example and can make sure we support it?

pujavs commented 3 years ago

Thanks @yuriyz , i have asked for PEM sample. I am not stuck technically ay this point the blocker is the not clarity of the exact input. And as you have rightly suggested have asked for the sample PEM. Also what I meant with error prone is parsing a PEM with multiple things, like cert, public key and private key. PEM with single content can be easily identified and parsed. Based on my search and analysis i understand that the PEM can have anything with appropriate headers & footers. A cert PEM has the public key also but not the private key and if a single PEM has combined data of the cert+public key and the private key then the content will be as below 1) Example # : Cert + Private Key PEM -----BEGIN CERTIFICATE-----

-----END CERTIFICATE----- -----BEGIN PRIVATE KEY----- -----END PRIVATE KEY----- 2) Example # : Private Key + Public Key PEM -----BEGIN PRIVATE KEY----- -----END PRIVATE KEY----- -----BEGIN PUBLIC KEY----- -----END PUBLIC KEY-----
pujavs commented 3 years ago

Endpoint Spec:

Input: format: => PEM/DER/CRT... alias : => to be used as kid keyContent: => private and public key => Example if PER format -----BEGIN PRIVATE KEY----- (Private Key content) -----END PRIVATE KEY----- -----BEGIN PUBLIC KEY----- (Public Key content) -----END PUBLIC KEY-----

Logic: 1) All input details mandatory. If null throw exception 2) Parse and extract Public key 3) Parse and extract Private key 4) Generated JWK based on keys 5) Import JWK to keystore file 6) Persistence JWK to auth severs jansConfWebKeys

pujavs commented 3 years ago

Code checked in https://github.com/JanssenProject/jans-config-api/tree/jans-config-api_23

anishnath commented 7 months ago

There is a useful online version of the PEM parser https://8gwifi.org/PemParserFunctions.jsp with different configuration usefull