It might make sense to reverse the semantics for this local boolean throughout this section:
```java
    boolean isCertificateTrusted = false;
```
then only set the condition to true if the certificate passes all trust validations (not null, properly signed, not expired, etc.).