-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runfix: improve e2ei timers (#17474)
* runfix: renew certificate device details [WPB-9193] (#17451) * Revert "fix: show enrollment modal for existing clients after e2ei activation [WPB-9816] (#17422)" This reverts commit 72c8c63. * runfix: old client can snooze the enrollment * runfix: show the update button during the grace period * runfix: always calculate the next fire date * runfix: don't open the confirmation modal if delay <= 0 * test: fix tests * test: show get cert button * Revert "runfix: always calculate the next fire date" This reverts commit b15d2c7. * runfix: reset timers when updating the cert manually * refactor: use certificate status * runfix: pass 'is current device' flag * runfix: update state after enrollment * runfix: recalculate isSnoozable value when task runs * refactor: improve naming * runfix: get and update buttons visible at once * test: update expired cert test * test: expires soon cert * runfix: reset timer only after user interaction with modal [WPB-9431] (#17469) * runfix: reset timer only after user interaction with modal * test: reset timer on user interaction * docs: add comment
- Loading branch information
1 parent
442c2d3
commit d4397a1
Showing
10 changed files
with
317 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,92 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {useCallback, useEffect, useState} from 'react'; | ||
|
||
import {CredentialType} from '@wireapp/core/lib/messagingProtocols/mls'; | ||
|
||
import {TIME_IN_MILLIS} from 'Util/TimeUtil'; | ||
|
||
import {E2EIHandler, MLSStatuses, WireIdentity} from '../E2EIdentity'; | ||
|
||
const getCertificateStatus = (identity?: WireIdentity, isSelfWithinGracePeriod: boolean = false) => { | ||
if (!identity || identity.credentialType === CredentialType.Basic) { | ||
return MLSStatuses.NOT_ACTIVATED; | ||
} | ||
|
||
const certificate = identity.x509Identity?.certificate; | ||
const hasCertificate = !!certificate && Boolean(certificate.length); | ||
|
||
if (!hasCertificate) { | ||
return MLSStatuses.NOT_ACTIVATED; | ||
} | ||
|
||
if (identity.status === MLSStatuses.VALID && isSelfWithinGracePeriod) { | ||
return MLSStatuses.EXPIRES_SOON; | ||
} | ||
|
||
return identity.status; | ||
}; | ||
|
||
export const useCertificateStatus = ( | ||
identity?: WireIdentity, | ||
isCurrentDevice = false, | ||
): [string | null, MLSStatuses] => { | ||
const [certificateStatus, setCertificateStatus] = useState<[string | null, MLSStatuses]>([ | ||
null, | ||
MLSStatuses.NOT_ACTIVATED, | ||
]); | ||
|
||
const refreshCertificateStatus = useCallback(async () => { | ||
const identityCertificate = identity?.x509Identity?.certificate; | ||
const certificate = !!identityCertificate && Boolean(identityCertificate.length) ? identityCertificate : null; | ||
|
||
const hasGracePeriodStarted = isCurrentDevice | ||
? await E2EIHandler.getInstance().hasGracePeriodStartedForSelfClient() | ||
: false; | ||
const status = getCertificateStatus(identity, hasGracePeriodStarted); | ||
|
||
setCertificateStatus(prev => { | ||
if (prev[0] === certificate && prev[1] === status) { | ||
return prev; | ||
} | ||
|
||
return [certificate, status]; | ||
}); | ||
}, [identity, isCurrentDevice]); | ||
|
||
useEffect(() => { | ||
void refreshCertificateStatus(); | ||
|
||
// Refresh the certificate status every second if the device is the current device | ||
if (isCurrentDevice) { | ||
const tid = setInterval(() => { | ||
void refreshCertificateStatus(); | ||
}, TIME_IN_MILLIS.SECOND); | ||
|
||
return () => { | ||
clearTimeout(tid); | ||
}; | ||
} | ||
|
||
return () => {}; | ||
}, [refreshCertificateStatus, isCurrentDevice]); | ||
|
||
return certificateStatus; | ||
}; |
This file contains 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 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.