-
-
Notifications
You must be signed in to change notification settings - Fork 479
[Community] WFCORE-5744 - improve keystore certificate health check #6420
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5bf7d47
[WFCORE-5744] Add CertificavteValidity type
baranowb 3b92603
[WFCORE-5744] Augment read-alias(s) OP output with additional attribu…
baranowb 6f9035d
[WFCORE-5744] Improve KeyStore certificate expiration warning on startup
baranowb e15ac58
[WFCORE-5744] Add expiration-check to keystore for certificate period…
baranowb 82ae443
[WFCORE-5744] add configurable expiration-watermark to control validi…
baranowb 7445a58
[WFCORE05744] Bump eltyron schema to 19 and 19 community
baranowb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
elytron/src/main/java/org/wildfly/extension/elytron/CertificateValidity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright The WildFly Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.wildfly.extension.elytron; | ||
|
|
||
| import java.util.Calendar; | ||
| import java.util.Date; | ||
|
|
||
| enum CertificateValidity { | ||
| NOT_YET("not yet"), VALID("valid"), ABOUT_TO_EXPIRE("about to expire"), EXPIRED("EXPIRED"); | ||
|
|
||
| private String token; | ||
|
|
||
| CertificateValidity(String string) { | ||
| this.token = string; | ||
| } | ||
|
|
||
| /* | ||
| * (non-Javadoc) | ||
| * | ||
| * @see java.lang.Enum#toString() | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return token; | ||
| } | ||
|
|
||
| /** | ||
| * Fetch representation of health based on provided factors. | ||
| * @param notBefore - certificate start date | ||
| * @param notAfter - certificate expiration date | ||
| * @param expirationWaterMark - watermark expressed in minutes. | ||
| * @return | ||
| * <ul> | ||
| * <li>{@linkplain #NOT_YET} - if currentDate.before(notBefore)</li> | ||
| * <li>{@linkplain #EXPIRE} - if currentDate.after(notAfter)</li> | ||
| * <li>{@linkplain #ABOUT_TO_EXPIRE} - if (currentDate+waterMark).after(notAfter)</li> | ||
| * <li>{@linkplain #VALID} - otherwise</li> | ||
| * </ul> | ||
| */ | ||
| static CertificateValidity getValidity(final Date notBefore, final Date notAfter, final long expirationWaterMark) { | ||
| final Date currentDate = Calendar.getInstance().getTime(); | ||
| if (currentDate.before(notBefore)) { | ||
| return NOT_YET; | ||
| } else if(currentDate.after(notBefore) && currentDate.before(notAfter)) { | ||
| if (expirationWaterMark > 0) { | ||
| //if current_date+watermark>expiration_date | ||
| final Date interimBoundryDate = new Date(currentDate.getTime() + expirationWaterMark*60L*1000L); | ||
| if(interimBoundryDate.after(notAfter)) { | ||
| return ABOUT_TO_EXPIRE; | ||
| } else { | ||
| return VALID; | ||
| } | ||
| } else { | ||
| //watermark should be n+, but just in case someone abuse it lets have some fallback | ||
| final long WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000; | ||
| final long DAY_IN_MS = 4 * 60 * 60 * 1000; | ||
| long diff = (notAfter.getTime() - notBefore.getTime()); | ||
| if (diff < WEEK_IN_MS) { | ||
| // cert is very short lived, lets settle for 1 day or just mark is as about to expire | ||
| if (diff < DAY_IN_MS) { | ||
| return ABOUT_TO_EXPIRE; | ||
| } else { | ||
| diff = DAY_IN_MS; | ||
| } | ||
| } else { | ||
| diff = WEEK_IN_MS; | ||
| } | ||
| final Date interimBoundryDate = new Date(notAfter.getTime() - diff); | ||
| if (currentDate.after(interimBoundryDate)) { | ||
| return ABOUT_TO_EXPIRE; | ||
| } else { | ||
| return VALID; | ||
| } | ||
| } | ||
| } else /*if(currentDate.after(notAfter))*/ { | ||
| return EXPIRED; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.