use of org.signal.libsignal.metadata.certificate.InvalidCertificateException in project Signal-Android by signalapp.
the class PushSendJob method rotateSenderCertificateIfNecessary.
protected void rotateSenderCertificateIfNecessary() throws IOException {
try {
Collection<CertificateType> requiredCertificateTypes = SignalStore.phoneNumberPrivacy().getRequiredCertificateTypes();
Log.i(TAG, "Ensuring we have these certificates " + requiredCertificateTypes);
for (CertificateType certificateType : requiredCertificateTypes) {
byte[] certificateBytes = SignalStore.certificateValues().getUnidentifiedAccessCertificate(certificateType);
if (certificateBytes == null) {
throw new InvalidCertificateException(String.format("No certificate %s was present.", certificateType));
}
SenderCertificate certificate = new SenderCertificate(certificateBytes);
if (System.currentTimeMillis() > (certificate.getExpiration() - CERTIFICATE_EXPIRATION_BUFFER)) {
throw new InvalidCertificateException(String.format(Locale.US, "Certificate %s is expired, or close to it. Expires on: %d, currently: %d", certificateType, certificate.getExpiration(), System.currentTimeMillis()));
}
Log.d(TAG, String.format("Certificate %s is valid", certificateType));
}
Log.d(TAG, "All certificates are valid.");
} catch (InvalidCertificateException e) {
Log.w(TAG, "A certificate was invalid at send time. Fetching new ones.", e);
if (!ApplicationDependencies.getJobManager().runSynchronously(new RotateCertificateJob(), 5000).isPresent()) {
throw new IOException("Timeout rotating certificate");
}
}
}
Aggregations