Skip to content

Commit

Permalink
imporve constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Thumimku committed Nov 15, 2023
1 parent 0e67e40 commit b7ad5dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.APPLE_ATTESTATION_REVOCATION_CHECK_ENABLED;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.APPLE_ATTESTATION_ROOT_CERTIFICATE_PATH;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.CERTIFICATE_EXPIRY_THRESHOLD;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.MILLI_SECOND_IN_DAY;

/**
* OSGi declarative services component which handled registration and un-registration of
Expand Down Expand Up @@ -141,7 +142,7 @@ private boolean isCertificateExpiringSoon(X509Certificate certificate) {
Date expirationDate = certificate.getNotAfter();

// Calculate the difference in days
long differenceInDays = (expirationDate.getTime() - currentDate.getTime()) / (24 * 60 * 60 * 1000);
long differenceInDays = (expirationDate.getTime() - currentDate.getTime()) / MILLI_SECOND_IN_DAY;

// Check if the certificate is expiring within 3 months.
return differenceInDays <= CERTIFICATE_EXPIRY_THRESHOLD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ public enum ClientTypes {
public static final String X_509_CERTIFICATE_TYPE = "X.509";
public static final String PKIX = "PKIX";
public static final int CERTIFICATE_EXPIRY_THRESHOLD = 90;
// Milli seconds in days 24 * 60 * 60 * 1000
public static final int MILLI_SECOND_IN_DAY = 86400000;

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.ATT_STMT;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.AUTH_DATA;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.CERTIFICATE_EXPIRY_THRESHOLD;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.MILLI_SECOND_IN_DAY;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.PKIX;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.SHA_256;
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.X5C;
Expand Down Expand Up @@ -284,7 +285,7 @@ private boolean isCertificateExpiringSoon(X509Certificate certificate) {
Date expirationDate = certificate.getNotAfter();

// Calculate the difference in days
long differenceInDays = (expirationDate.getTime() - currentDate.getTime()) / (24 * 60 * 60 * 1000);
long differenceInDays = (expirationDate.getTime() - currentDate.getTime()) / MILLI_SECOND_IN_DAY;

// Check if the certificate is expiring within 3 months.
return differenceInDays <= CERTIFICATE_EXPIRY_THRESHOLD;
Expand Down

0 comments on commit b7ad5dc

Please sign in to comment.