6890234cd49055219077b2836c8b27697dfdb9ce
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / SslTrustManagerFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core;
10
11 import javax.net.ssl.ManagerFactoryParameters;
12 import javax.net.ssl.TrustManager;
13 import javax.net.ssl.TrustManagerFactorySpi;
14 import javax.net.ssl.X509TrustManager;
15 import java.security.InvalidAlgorithmParameterException;
16 import java.security.KeyStore;
17 import java.security.KeyStoreException;
18 import java.security.cert.X509Certificate;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  *
24  * @author michal.polkorab
25  */
26 public class SslTrustManagerFactory extends TrustManagerFactorySpi {
27
28     /**
29      * Logger for SslTrustManagerFactory
30      */
31     public static final Logger LOGGER = LoggerFactory.getLogger(SslTrustManagerFactory.class);
32     private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
33         @Override
34         public X509Certificate[] getAcceptedIssuers() {
35             return new X509Certificate[0];
36         }
37
38         @Override
39         public void checkClientTrusted(X509Certificate[] chain, String authType) {
40             LOGGER.error("UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
41         }
42
43         @Override
44         public void checkServerTrusted(X509Certificate[] chain, String authType) {
45             LOGGER.error("UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
46         }
47     };
48
49     /**
50      * Getter for TrustManagers
51      *
52      * @return TrustManager[]
53      */
54     public static TrustManager[] getTrustManagers() {
55         return new TrustManager[]{DUMMY_TRUST_MANAGER};
56     }
57
58     @Override
59     protected TrustManager[] engineGetTrustManagers() {
60         return getTrustManagers();
61     }
62
63     @Override
64     protected void engineInit(KeyStore ks) throws KeyStoreException {
65         throw new UnsupportedOperationException("Not supported yet.");
66     }
67
68     @Override
69     protected void engineInit(ManagerFactoryParameters mfp) throws InvalidAlgorithmParameterException {
70         throw new UnsupportedOperationException("Not supported yet.");
71     }
72 }