SSLX509ManagerForcedClientAlias.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.utils.transport.http;

  21. import java.net.Socket;
  22. import java.security.Principal;
  23. import java.security.PrivateKey;
  24. import java.security.cert.X509Certificate;

  25. import javax.net.ssl.X509KeyManager;

  26. /**
  27.  * SSLX509ManagerChooseClientAlias
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class SSLX509ManagerForcedClientAlias implements X509KeyManager {

  34.     /*
  35.      * Il default KeyManager spedisce il primo certificato che trova che ha un match con le condizioni richieste dal server.
  36.      * Questa classe permette di forzare l'utilizzo di uno specifico certificato indirizzato da un alias
  37.      * */
  38.    
  39.     private String alias;
  40.     private X509KeyManager wrapped_x509KeyManager;
  41.    
  42.     public SSLX509ManagerForcedClientAlias(String alias, X509KeyManager x509KeyManager) {
  43.         this.alias = alias;
  44.         this.wrapped_x509KeyManager = x509KeyManager;
  45.     }
  46.    
  47.     @Override
  48.     public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
  49.         // force
  50.         return this.alias;
  51.     }
  52.    
  53.     @Override
  54.     public String[] getClientAliases(String keyType, Principal[] issuers) {
  55.         return this.wrapped_x509KeyManager.getClientAliases(keyType, issuers);
  56.     }
  57.     @Override
  58.     public String[] getServerAliases(String keyType, Principal[] issuers) {
  59.         return this.wrapped_x509KeyManager.getServerAliases(keyType, issuers);
  60.     }
  61.     @Override
  62.     public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
  63.         return this.wrapped_x509KeyManager.chooseServerAlias(keyType, issuers, socket);
  64.     }
  65.     @Override
  66.     public X509Certificate[] getCertificateChain(String alias) {
  67.         return this.wrapped_x509KeyManager.getCertificateChain(alias);
  68.     }
  69.     @Override
  70.     public PrivateKey getPrivateKey(String alias) {
  71.         return this.wrapped_x509KeyManager.getPrivateKey(alias);
  72.     }
  73.    
  74. }