1

I'm relatively new to Java and stumbled upon this snippet of code that's used for CA cert bypass. I'm having trouble understanding the curly braces after new for TrustManager[] and X509TrustManager(). Could someone shed some light? Thanks.

TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }
    };
Mozbi
  • 1,399
  • 1
  • 17
  • 25
  • Look up: anonymous inner class, such the answers to [this question](http://stackoverflow.com/questions/355167/how-are-anonymous-inner-classes-used-in-java). – Hovercraft Full Of Eels Jul 07 '15 at 14:44
  • For the benefit of the OP, this question is compounded by having an array of instances of type TrustManager - `... = new TrustManager[] { ... };` It just so happens your array `{ ... }` contains one object that is an inner class implementing the X509TrustManager interface - `new X509TrustManager() { // implemented methods }` – wmorrison365 Jul 07 '15 at 14:54
  • `new TM { ... }` is an array initialization, here of 1 element, an anonymous child of `new X509TM()` implemented as class { pu.... }. – Joop Eggen Jul 07 '15 at 14:55

0 Answers0