Skip to content

JWT Add Support for .PEM Certificates (Lets Encrypt etc...) - #3223

Open
prosgarz35 wants to merge 4 commits into
apache:masterfrom
Hollow-Ataraxia:jwt_cert
Open

prosgarz35 wants to merge 4 commits into
apache:masterfrom
Hollow-Ataraxia:jwt_cert

Conversation

@prosgarz35

Copy link
Copy Markdown
Contributor

Not much to say i think?

@prosgarz35
prosgarz35 marked this pull request as ready for review October 1, 2026 02:48
@prosgarz35

Copy link
Copy Markdown
Contributor Author

@quantranhong1999 hi there! can you force build? :) i dont know why it dont do it

@quantranhong1999

Copy link
Copy Markdown
Member

@quantranhong1999 hi there! can you force build? :) i dont know why it dont do it

I have no idea about the build infra too. cc @Arsnael . Maybe wait a while and see if the CI takes the build.

@prosgarz35

Copy link
Copy Markdown
Contributor Author

@quantranhong1999 hi there! can you force build? :) i dont know why it dont do it

I have no idea about the build infra too. cc @Arsnael . Maybe wait a while and see if the CI takes the build.

well yeah sometimes its instant, sometimes about 1-3 minuts but there pretty long :D

@Arsnael

Arsnael commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Seems the build started. The CI is managed by the Infra team of the apache foundation. not us. Mind that there can be sometimes issues or lags. It's not dependant on us. Reminding you as well that open source projects are usually managed by people during their free time, so patience is needed :)

@Arsnael Arsnael left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's really necessary but not against either, thanks

@prosgarz35

Copy link
Copy Markdown
Contributor Author

Not sure if it's really necessary but not against either, thanks

Not sure if it's really necessary but not against either, thanks

Understood, thank you! I completely respect your time and the volunteer nature of the project. No rush at all on my end. I appreciate you triggering the build and taking a look at this!

@prosgarz35

Copy link
Copy Markdown
Contributor Author

Not sure if it's really necessary but not against either, thanks

i just want in future use ONE certificate for all SMTP/IMAP/POP/JWT/API because... why not? its more comfortable then java keystores

@prosgarz35 prosgarz35 mentioned this pull request Oct 1, 2026
@prosgarz35

Copy link
Copy Markdown
Contributor Author

The CI build failure is unrelated to this PR. All JWT tests passed (PublicKeyReaderTest ran successfully).
The failure occurred in blob-s3 due to a known flaky test / container startup timeout (DockerCephS3ContainerTest: quay.io/ceph/demo failed to start).

@quantranhong1999

Copy link
Copy Markdown
Member

FYI, I just restart the build

@prosgarz35

Copy link
Copy Markdown
Contributor Author

FYI, I just restart the build

alot of thanks!

return Optional.of(new JcaPEMKeyConverter().getPublicKey((SubjectPublicKeyInfo) readPEM));
}
LOGGER.warn("Key is not an instance of SubjectPublicKeyInfo but of {}", readPEM);
if (readPEM instanceof X509CertificateHolder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the principle, yes.

In practice certificate means we likely shall check notBefore/notAfter...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the principle, yes.

In practice certificate means we likely shall check notBefore/notAfter...

i made it check but only WARN not REJECT cuz... you sure dont wanna your server going down when you just forget this certificate...

Comment on lines +63 to +66
if (now.before(certHolder.getNotBefore()) || now.after(certHolder.getNotAfter())) {
LOGGER.warn("Certificate is not valid at {}. Validity: [{} - {}]",
now, certHolder.getNotBefore(), certHolder.getNotAfter());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we throw by default?

and add a bypass option -Djames.pem.certificates.allow.outdated=false by default ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even need a bypass option? Why should using an outdated certificate ever be an option? Clients hopefully reject it anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can say why - example there russian certs which dont counts as safe for all browser and other programmes but under sanctions some companies cant issue lets encryp and other acme certificates - only self sigh or this national certificates... And this option seems needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sometimes certificates are necessary that would not be valid in a normal browser (e.g. for testing).
But the issue there is the certificate chain, not the validity period. If you self-sign, why not just choose a proper validity period?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In first version realization was same as for imap/pop/smtp - just use certificates without even look at correctly or not. I dont sure it is good or not option. Maybe really better do acme in james but as first steps in refactoring its good dont it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not generally against adding some sanity check.
However, I think that java properties should be used sparely. As this validity period check can always be fixed (generate new self-signed certificate / get new certificate from our issuer), I do not understand why it deserves an additional property.
And the property is not documented in any way, so how would I know how to configure it?

@prosgarz35

Copy link
Copy Markdown
Contributor Author

@chibenwa its here!

@Arsnael Arsnael left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @chibenwa suggestions were taken correctly into account, lgtm thank you :)

@prosgarz35

Copy link
Copy Markdown
Contributor Author

Looks like @chibenwa suggestions were taken correctly into account, lgtm thank you :)

yeah i make it :) thanks to you and good morning :) lets make james more friendly for non spec users

private final boolean allowOutdated;

public PublicKeyReader() {
this(Clock.systemUTC(), Boolean.getBoolean(ALLOW_OUTDATED_PROPERTY));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it more explicit that default value is false

@chibenwa

Copy link
Copy Markdown
Contributor

Hello @prosgarz35

Would you find time to address the nitpick ?

Otherwise I'm happy to help.

Best regards,

Benoit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants