2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.vizio.internal.communication;
15 import java.net.MalformedURLException;
16 import java.security.cert.CertificateException;
18 import javax.net.ssl.X509ExtendedTrustManager;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.core.io.net.http.PEMTrustManager;
22 import org.openhab.core.io.net.http.TlsTrustManagerProvider;
23 import org.openhab.core.io.net.http.TrustAllTrustManager;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Provides a {@link PEMTrustManager} to allow secure connections to a Vizio TV that uses self signed
31 * @author Christoph Weitkamp - Initial Contribution
32 * @author Michael Lobstein - Adapted for Vizio binding
35 public class VizioTlsTrustManagerProvider implements TlsTrustManagerProvider {
36 private final String hostname;
38 private final Logger logger = LoggerFactory.getLogger(VizioTlsTrustManagerProvider.class);
40 public VizioTlsTrustManagerProvider(String hostname) {
41 this.hostname = hostname;
45 public String getHostName() {
50 public X509ExtendedTrustManager getTrustManager() {
52 logger.trace("Use self-signed certificate downloaded from Vizio TV.");
53 return PEMTrustManager.getInstanceFromServer("https://" + getHostName());
54 } catch (CertificateException | MalformedURLException e) {
55 logger.debug("An unexpected exception occurred - returning a TrustAllTrustManager: {}", e.getMessage(), e);
57 return TrustAllTrustManager.getInstance();