ConnettoreHTTPSUtils.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.web.ctrlstat.servlet.connettori;

  21. import java.util.List;

  22. import javax.net.ssl.KeyManagerFactory;
  23. import javax.net.ssl.TrustManagerFactory;

  24. import org.openspcoop2.core.constants.CostantiDB;
  25. import org.openspcoop2.core.registry.constants.StatiAccordo;
  26. import org.openspcoop2.pdd.core.dynamic.DynamicHelperCostanti;
  27. import org.openspcoop2.utils.UtilsException;
  28. import org.openspcoop2.utils.certificate.KeystoreType;
  29. import org.openspcoop2.utils.certificate.byok.BYOKProvider;
  30. import org.openspcoop2.utils.certificate.hsm.HSMUtils;
  31. import org.openspcoop2.utils.certificate.ocsp.OCSPProvider;
  32. import org.openspcoop2.utils.transport.http.SSLUtilities;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  35. import org.openspcoop2.web.ctrlstat.servlet.ConsoleHelper;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  37. import org.openspcoop2.web.lib.mvc.DataElement;
  38. import org.openspcoop2.web.lib.mvc.DataElementInfo;
  39. import org.openspcoop2.web.lib.mvc.DataElementType;

  40. /**
  41.  * ConnettoreHTTPSUtils
  42.  *
  43.  * @author Andrea Poli (apoli@link.it)
  44.  * @author $Author$
  45.  * @version $Rev$, $Date$
  46.  */
  47. public class ConnettoreHTTPSUtils {
  48.    
  49.     private ConnettoreHTTPSUtils() {}

  50.     public static void fillConnettoreConfig(org.openspcoop2.core.config.Connettore connettore,
  51.             String httpsurl, String httpstipologia, boolean httpshostverify,
  52.             boolean httpsTrustVerifyCert, String httpspath, String httpstipo, String httpspwd,
  53.             String httpsalgoritmo, boolean httpsstato, String httpskeystore,
  54.             String httpspwdprivatekeytrust, String httpspathkey,
  55.             String httpstipokey, String httpspwdkey,
  56.             String httpspwdprivatekey, String httpsalgoritmokey,
  57.             String httpsKeyAlias, String httpsTrustStoreCRLs, String httpsTrustStoreOCSPPolicy, String httpsKeyStoreBYOKPolicy){
  58.        
  59.         connettore.setCustom(true);
  60.        
  61.         org.openspcoop2.core.config.Property prop = new org.openspcoop2.core.config.Property();
  62.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_LOCATION);
  63.         prop.setValore(httpsurl);
  64.         connettore.addProperty(prop);

  65.         prop = new org.openspcoop2.core.config.Property();
  66.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_SSL_TYPE);
  67.         prop.setValore(httpstipologia);
  68.         connettore.addProperty(prop);

  69.         prop = new org.openspcoop2.core.config.Property();
  70.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_HOSTNAME_VERIFIER);
  71.         prop.setValore(String.valueOf(httpshostverify));
  72.         connettore.addProperty(prop);

  73.         prop = new org.openspcoop2.core.config.Property();
  74.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_ALL_CERTS);
  75.         if(httpsTrustVerifyCert) {
  76.             prop.setValore(String.valueOf(false));
  77.         }
  78.         else {
  79.             prop.setValore(String.valueOf(true));
  80.         }
  81.         connettore.addProperty(prop);
  82.        
  83.         if(httpsTrustVerifyCert) {
  84.        
  85.             prop = new org.openspcoop2.core.config.Property();
  86.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  87.             prop.setValore(httpspath);
  88.             connettore.addProperty(prop);
  89.    
  90.             prop = new org.openspcoop2.core.config.Property();
  91.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  92.             prop.setValore(httpstipo);
  93.             connettore.addProperty(prop);
  94.    
  95.             if(httpspwd!=null && !"".equals(httpspwd)) {
  96.                 prop = new org.openspcoop2.core.config.Property();
  97.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  98.                 prop.setValore(httpspwd);
  99.                 connettore.addProperty(prop);
  100.             }
  101.            
  102.             if(httpsTrustStoreCRLs!=null && !"".equals(httpsTrustStoreCRLs)) {
  103.                 prop = new org.openspcoop2.core.config.Property();
  104.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_CRLS);
  105.                 prop.setValore(httpsTrustStoreCRLs);
  106.                 connettore.addProperty(prop);
  107.             }
  108.            
  109.             prop = new org.openspcoop2.core.config.Property();
  110.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  111.             if (httpsalgoritmo == null || "".equals(httpsalgoritmo))
  112.                 prop.setValore(javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm());
  113.             else
  114.                 prop.setValore(httpsalgoritmo);
  115.             connettore.addProperty(prop);
  116.        
  117.         }
  118.        
  119.         if(httpsTrustStoreOCSPPolicy!=null && !"".equals(httpsTrustStoreOCSPPolicy)) {
  120.             prop = new org.openspcoop2.core.config.Property();
  121.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  122.             prop.setValore(httpsTrustStoreOCSPPolicy);
  123.             connettore.addProperty(prop);
  124.            
  125.             if(!httpsTrustVerifyCert &&
  126.                 httpsTrustStoreCRLs!=null && !"".equals(httpsTrustStoreCRLs)) {
  127.                 prop = new org.openspcoop2.core.config.Property();
  128.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_CRLS);
  129.                 prop.setValore(httpsTrustStoreCRLs);
  130.                 connettore.addProperty(prop);
  131.             }
  132.         }

  133.         if (httpsstato) {

  134.             prop = new org.openspcoop2.core.config.Property();
  135.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  136.             if (httpsalgoritmokey == null || "".equals(httpsalgoritmokey))
  137.                 prop.setValore(javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm());
  138.             else
  139.                 prop.setValore(httpsalgoritmokey);
  140.             connettore.addProperty(prop);


  141.             if (ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_DEFAULT.equals(httpskeystore)) {
  142.                 if(httpspwdprivatekeytrust!=null && !"".equals(httpspwdprivatekeytrust)) {
  143.                     prop = new org.openspcoop2.core.config.Property();
  144.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD);
  145.                     prop.setValore(httpspwdprivatekeytrust);
  146.                     connettore.addProperty(prop);
  147.                 }

  148.                 prop = new org.openspcoop2.core.config.Property();
  149.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  150.                 prop.setValore(httpspath);
  151.                 connettore.addProperty(prop);

  152.                 prop = new org.openspcoop2.core.config.Property();
  153.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_TYPE);
  154.                 prop.setValore(httpstipo);
  155.                 connettore.addProperty(prop);

  156.                 if(httpspwd!=null && !"".equals(httpspwd)) {
  157.                     prop = new org.openspcoop2.core.config.Property();
  158.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  159.                     prop.setValore(httpspwd);
  160.                     connettore.addProperty(prop);
  161.                 }

  162.             } else {
  163.                 prop = new org.openspcoop2.core.config.Property();
  164.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  165.                 prop.setValore(httpspathkey);
  166.                 connettore.addProperty(prop);

  167.                 prop = new org.openspcoop2.core.config.Property();
  168.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_TYPE);
  169.                 prop.setValore(httpstipokey);
  170.                 connettore.addProperty(prop);

  171.                 if(httpspwdkey!=null && !"".equals(httpspwdkey)) {
  172.                     prop = new org.openspcoop2.core.config.Property();
  173.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  174.                     prop.setValore(httpspwdkey);
  175.                     connettore.addProperty(prop);
  176.                 }

  177.                 if(httpspwdprivatekey!=null && !"".equals(httpspwdprivatekey)) {
  178.                     prop = new org.openspcoop2.core.config.Property();
  179.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD);
  180.                     prop.setValore(httpspwdprivatekey);
  181.                     connettore.addProperty(prop);
  182.                 }

  183.             }
  184.            
  185.             if(httpsKeyAlias!=null && !"".equals(httpsKeyAlias)) {
  186.                 prop = new org.openspcoop2.core.config.Property();
  187.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_ALIAS);
  188.                 prop.setValore(httpsKeyAlias);
  189.                 connettore.addProperty(prop);
  190.             }
  191.            
  192.             if(httpsKeyStoreBYOKPolicy!=null && !"".equals(httpsKeyStoreBYOKPolicy)) {
  193.                 prop = new org.openspcoop2.core.config.Property();
  194.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  195.                 prop.setValore(httpsKeyStoreBYOKPolicy);
  196.                 connettore.addProperty(prop);
  197.             }
  198.         }
  199.     }
  200.    
  201.     public static void fillConnettoreRegistry(org.openspcoop2.core.registry.Connettore connettore,
  202.             String httpsurl, String httpstipologia, boolean httpshostverify,
  203.             boolean httpsTrustVerifyCert, String httpspath, String httpstipo, String httpspwd,
  204.             String httpsalgoritmo, boolean httpsstato, String httpskeystore,
  205.             String httpspwdprivatekeytrust, String httpspathkey,
  206.             String httpstipokey, String httpspwdkey,
  207.             String httpspwdprivatekey, String httpsalgoritmokey,
  208.             String httpsKeyAlias, String httpsTrustStoreCRLs, String httpsTrustStoreOCSPPolicy, String httpsKeyStoreBYOKPolicy,
  209.             String user, String pwd){
  210.        
  211.         connettore.setCustom(true);
  212.    
  213.         org.openspcoop2.core.registry.Property prop = new org.openspcoop2.core.registry.Property();
  214.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_LOCATION);
  215.         prop.setValore(httpsurl);
  216.         connettore.addProperty(prop);

  217.         if(user!=null){
  218.             prop = new org.openspcoop2.core.registry.Property();
  219.             prop.setNome(CostantiDB.CONNETTORE_USER);
  220.             prop.setValore(user);
  221.             connettore.addProperty(prop);
  222.         }
  223.        
  224.         if(pwd!=null){
  225.             prop = new org.openspcoop2.core.registry.Property();
  226.             prop.setNome(CostantiDB.CONNETTORE_PWD);
  227.             prop.setValore(pwd);
  228.             connettore.addProperty(prop);
  229.         }
  230.        
  231.         prop = new org.openspcoop2.core.registry.Property();
  232.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_SSL_TYPE);
  233.         prop.setValore(httpstipologia);
  234.         connettore.addProperty(prop);

  235.         prop = new org.openspcoop2.core.registry.Property();
  236.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_HOSTNAME_VERIFIER);
  237.         prop.setValore(String.valueOf(httpshostverify));
  238.         connettore.addProperty(prop);

  239.         prop = new org.openspcoop2.core.registry.Property();
  240.         prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_ALL_CERTS);
  241.         if(httpsTrustVerifyCert) {
  242.             prop.setValore(String.valueOf(false));
  243.         }
  244.         else {
  245.             prop.setValore(String.valueOf(true));
  246.         }
  247.         connettore.addProperty(prop);
  248.        
  249.         if(httpsTrustVerifyCert) {
  250.            
  251.             prop = new org.openspcoop2.core.registry.Property();
  252.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  253.             prop.setValore(httpspath);
  254.             connettore.addProperty(prop);
  255.    
  256.             prop = new org.openspcoop2.core.registry.Property();
  257.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  258.             prop.setValore(httpstipo);
  259.             connettore.addProperty(prop);
  260.    
  261.             if(httpspwd!=null && !"".equals(httpspwd)) {
  262.                 prop = new org.openspcoop2.core.registry.Property();
  263.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  264.                 prop.setValore(httpspwd);
  265.                 connettore.addProperty(prop);
  266.             }
  267.    
  268.             if(httpsTrustStoreCRLs!=null && !"".equals(httpsTrustStoreCRLs)) {
  269.                 prop = new org.openspcoop2.core.registry.Property();
  270.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_CRLS);
  271.                 prop.setValore(httpsTrustStoreCRLs);
  272.                 connettore.addProperty(prop);
  273.             }
  274.        
  275.             prop = new org.openspcoop2.core.registry.Property();
  276.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  277.             if (httpsalgoritmo == null || "".equals(httpsalgoritmo))
  278.                 prop.setValore(javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm());
  279.             else
  280.                 prop.setValore(httpsalgoritmo);
  281.             connettore.addProperty(prop);

  282.         }
  283.        
  284.        
  285.         if(httpsTrustStoreOCSPPolicy!=null && !"".equals(httpsTrustStoreOCSPPolicy)) {
  286.             prop = new org.openspcoop2.core.registry.Property();
  287.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  288.             prop.setValore(httpsTrustStoreOCSPPolicy);
  289.             connettore.addProperty(prop);
  290.            
  291.             if(!httpsTrustVerifyCert &&
  292.                 httpsTrustStoreCRLs!=null && !"".equals(httpsTrustStoreCRLs)) {
  293.                 prop = new org.openspcoop2.core.registry.Property();
  294.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_CRLS);
  295.                 prop.setValore(httpsTrustStoreCRLs);
  296.                 connettore.addProperty(prop);
  297.             }
  298.         }
  299.        
  300.         if (httpsstato) {

  301.             prop = new org.openspcoop2.core.registry.Property();
  302.             prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  303.             if (httpsalgoritmokey == null || "".equals(httpsalgoritmokey))
  304.                 prop.setValore(javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm());
  305.             else
  306.                 prop.setValore(httpsalgoritmokey);
  307.             connettore.addProperty(prop);


  308.             if (ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_DEFAULT.equals(httpskeystore)) {
  309.                 if(httpspwdprivatekeytrust!=null && !"".equals(httpspwdprivatekeytrust)) {
  310.                     prop = new org.openspcoop2.core.registry.Property();
  311.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD);
  312.                     prop.setValore(httpspwdprivatekeytrust);
  313.                     connettore.addProperty(prop);
  314.                 }

  315.                 prop = new org.openspcoop2.core.registry.Property();
  316.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  317.                 prop.setValore(httpspath);
  318.                 connettore.addProperty(prop);

  319.                 prop = new org.openspcoop2.core.registry.Property();
  320.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_TYPE);
  321.                 prop.setValore(httpstipo);
  322.                 connettore.addProperty(prop);

  323.                 if(httpspwd!=null && !"".equals(httpspwd)) {
  324.                     prop = new org.openspcoop2.core.registry.Property();
  325.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  326.                     prop.setValore(httpspwd);
  327.                     connettore.addProperty(prop);
  328.                 }

  329.             } else {
  330.                 prop = new org.openspcoop2.core.registry.Property();
  331.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  332.                 prop.setValore(httpspathkey);
  333.                 connettore.addProperty(prop);

  334.                 prop = new org.openspcoop2.core.registry.Property();
  335.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_TYPE);
  336.                 prop.setValore(httpstipokey);
  337.                 connettore.addProperty(prop);

  338.                 if(httpspwdkey!=null && !"".equals(httpspwdkey)) {
  339.                     prop = new org.openspcoop2.core.registry.Property();
  340.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  341.                     prop.setValore(httpspwdkey);
  342.                     connettore.addProperty(prop);
  343.                 }

  344.                 if(httpspwdprivatekey!=null && !"".equals(httpspwdprivatekey)) {
  345.                     prop = new org.openspcoop2.core.registry.Property();
  346.                     prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD);
  347.                     prop.setValore(httpspwdprivatekey);
  348.                     connettore.addProperty(prop);
  349.                 }

  350.             }
  351.            
  352.             if(httpsKeyAlias!=null && !"".equals(httpsKeyAlias)) {
  353.                 prop = new org.openspcoop2.core.registry.Property();
  354.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_ALIAS);
  355.                 prop.setValore(httpsKeyAlias);
  356.                 connettore.addProperty(prop);
  357.             }
  358.            
  359.             if(httpsKeyStoreBYOKPolicy!=null && !"".equals(httpsKeyStoreBYOKPolicy)) {
  360.                 prop = new org.openspcoop2.core.registry.Property();
  361.                 prop.setNome(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  362.                 prop.setValore(httpsKeyStoreBYOKPolicy);
  363.                 connettore.addProperty(prop);
  364.             }
  365.         }
  366.     }
  367.    
  368.     public static void addHTTPSDati(List<DataElement> dati,
  369.             String httpsurl, String httpstipologia, boolean httpshostverify,
  370.             boolean httpsTrustVerifyCert, String httpspath, String httpstipo, String httpspwd,
  371.             String httpsalgoritmo, boolean httpsstato, String httpskeystore,
  372.             String httpspwdprivatekeytrust, String httpspathkey,
  373.             String httpstipokey, String httpspwdkey,
  374.             String httpspwdprivatekey, String httpsalgoritmokey,
  375.             String httpsKeyAlias, String httpsTrustStoreCRLs, String httpsTrustStoreOCSPPolicy, String httpsKeyStoreBYOKPolicy,
  376.             String stato,
  377.             ControlStationCore core,ConsoleHelper consoleHelper, int pageSize, boolean addUrlParameter,
  378.             String prefix, boolean forceHttpsClient,
  379.             boolean modi, boolean fruizione, boolean forceNoSec,
  380.             boolean postBackViaPost) throws UtilsException {
  381.        
  382.         // default
  383.         if(httpsalgoritmo==null || "".equals(httpsalgoritmo)){
  384.             httpsalgoritmo = TrustManagerFactory.getDefaultAlgorithm();
  385.         }
  386.         if(httpsalgoritmokey==null || "".equals(httpsalgoritmokey)){
  387.             httpsalgoritmokey = KeyManagerFactory.getDefaultAlgorithm();
  388.         }
  389.         if(httpstipologia==null || "".equals(httpstipologia)){
  390.             httpstipologia = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TYPE;
  391.         }
  392.        
  393.         if(addUrlParameter){
  394.             DataElement de = new DataElement();
  395.             de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_URL);
  396.             de.setValue(httpsurl);
  397.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  398.                 de.setType(DataElementType.TEXT_EDIT);
  399.                 de.setRequired(true);  
  400.                
  401.                 DataElementInfo dInfoPatternFileName = new DataElementInfo(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_URL);
  402.                 dInfoPatternFileName.setHeaderBody(DynamicHelperCostanti.LABEL_CONFIGURAZIONE_INFO_TRASPORTO);
  403.                 dInfoPatternFileName.setListBody(DynamicHelperCostanti.getLABEL_CONFIGURAZIONE_INFO_CONNETTORE_VALORI(modi, fruizione, forceNoSec));
  404.                 de.setInfo(dInfoPatternFileName);
  405.             }else{
  406.                 de.setType(DataElementType.TEXT);
  407.             }
  408.             de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_URL);
  409.             de.setSize(pageSize);
  410.             dati.add(de);
  411.         }

  412.         if(prefix==null){
  413.             prefix = "";
  414.         }
  415.        
  416.         DataElement de = new DataElement();
  417.         de.setLabel(prefix+ConnettoriCostanti.LABEL_CONNETTORE_AUTENTICAZIONE);
  418.         de.setType(DataElementType.TITLE);
  419.         dati.add(de);

  420.         de = new DataElement();
  421.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_SSL_TYPE);
  422.         de.setType(DataElementType.SELECT);
  423.         List<String> tipologie = null;
  424.         try{
  425.             tipologie = SSLUtilities.getSSLSupportedProtocols();
  426.         }catch(Exception e){
  427.             ControlStationCore.logError(e.getMessage(), e);
  428.             tipologie = SSLUtilities.getAllSslProtocol();
  429.         }
  430.         if(httpstipologia!=null && !"".equals(httpstipologia) &&
  431.                 !tipologie.contains(httpstipologia)){
  432.             tipologie.add(httpstipologia); // per retrocompatibilità delle configurazioni SSL e TLS
  433.         }
  434.         de.setValues(tipologie);
  435.         de.setSelected(httpstipologia);
  436.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_SSL_TYPE);
  437.         dati.add(de);

  438.         de = new DataElement();
  439.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_HOST_VERIFY);
  440.         de.setValue(httpshostverify ? Costanti.CHECK_BOX_ENABLED : "");
  441.         de.setSelected(httpshostverify);
  442.         de.setType(DataElementType.CHECKBOX);
  443.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_HOST_VERIFY);
  444.         dati.add(de);

  445.         de = new DataElement();
  446.         de.setLabel(prefix+ConnettoriCostanti.LABEL_CONNETTORE_AUTENTICAZIONE_SERVER);
  447.         de.setType(DataElementType.SUBTITLE);
  448.         dati.add(de);

  449.         de = new DataElement();
  450.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS);
  451.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS);
  452.         de.setValue(httpsTrustVerifyCert ? Costanti.CHECK_BOX_ENABLED : "");
  453.         de.setSelected(httpsTrustVerifyCert);
  454.         de.setType(DataElementType.CHECKBOX);
  455.         if(postBackViaPost) {
  456.             de.setPostBack_viaPOST(true);
  457.         }
  458.         else {
  459.             de.setPostBack(true);
  460.         }
  461.         dati.add(de);
  462.        
  463.         boolean truststoreHsm = false;
  464.         String httpstipoDefault = null;
  465.         de = new DataElement();
  466.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  467.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  468.         if(httpsTrustVerifyCert) {
  469.             de.setType(DataElementType.SELECT);
  470.             if(core.isConnettoriAllTypesEnabled()) {
  471.                 de.setValues(ConnettoriCostanti.TIPOLOGIE_KEYSTORE_OLD);
  472.             }
  473.             else {
  474.                 List<String> values = ConnettoriCostanti.getTIPOLOGIE_KEYSTORE(true, false);
  475.                 List<String> labels = ConnettoriCostanti.getTIPOLOGIE_KEYSTORE(true, true);
  476.                 // per retrocompatibilita verifico che esista ancora nelle nuove, altrimenti lo aggiungo
  477.                 if(httpstipo!=null && !"".equals(httpstipo)) {
  478.                     boolean exists = false;
  479.                     for (String v : values) {
  480.                         if(httpstipo.equalsIgnoreCase(v)) {
  481.                             exists = true;
  482.                         }
  483.                     }
  484.                     if(!exists) {
  485.                         values.add(httpstipo);
  486.                     }
  487.                 }
  488.                 de.setValues(values);
  489.                 de.setLabels(labels);
  490.                 if(ConnettoriCostanti.existsTIPOLOGIE_KEYSTORE_HSM(true)) {
  491.                     if(postBackViaPost) {
  492.                         de.setPostBack_viaPOST(true);
  493.                     }
  494.                     else {
  495.                         de.setPostBack(true);
  496.                     }
  497.                 }
  498.             }
  499.             if(httpstipo!=null) {
  500.                 de.setSelected(httpstipo);
  501.                 truststoreHsm = HSMUtils.isKeystoreHSM(httpstipo);
  502.             }
  503.         }
  504.         else {
  505.             de.setType(DataElementType.HIDDEN);
  506.         }
  507.         if( (httpstipo==null || "".equals(httpstipo))
  508.                 && de.getValues()!=null && de.getValues().length>0) {
  509.                 httpstipoDefault = de.getValues()[0];
  510.         }
  511.         dati.add(de);

  512.         de = new DataElement();
  513.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  514.         de.setValue(httpspath);
  515.         if(httpsTrustVerifyCert) {
  516.             if(truststoreHsm) {
  517.                 de.setValue(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_PATH_HSM_PREFIX+httpstipo);
  518.                 de.setType(DataElementType.HIDDEN);
  519.             }
  520.             else {
  521.                 if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  522.                     de.setType(DataElementType.TEXT_AREA);
  523.                     de.setRequired(true);  
  524.                 }else{
  525.                     de.setType(DataElementType.TEXT_AREA_NO_EDIT);
  526.                 }
  527.                 de.setRows(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_LOCATION_SIZE);
  528.                 de.setSize(pageSize);
  529.             }
  530.         }
  531.         else {
  532.             de.setType(DataElementType.HIDDEN);
  533.         }
  534.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  535.         dati.add(de);
  536.        
  537.         de = new DataElement();
  538.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  539.         if(httpsTrustVerifyCert) {
  540.             if(truststoreHsm) {
  541.                 de.setValue(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_HSM_STORE_PASSWORD_UNDEFINED);
  542.                 de.setType(DataElementType.HIDDEN);
  543.             }
  544.             else if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  545.                 de.setRequired(isStorePasswordRequired(httpstipo, httpstipoDefault, false, false, core));
  546.                 core.getLockUtilities().lock(de, httpspwd);
  547.             }else{
  548.                 core.getLockUtilities().lockReadOnly(de, httpspwd);
  549.             }
  550.             de.setSize(pageSize);
  551.         }
  552.         else {
  553.             core.getLockUtilities().lockHidden(de, httpspwd);
  554.         }
  555.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  556.         dati.add(de);

  557.         OCSPProvider ocspProvider = new OCSPProvider();
  558.         boolean ocspEnabled = ocspProvider.isOcspEnabled();
  559.         List<String> ocspTypes = ocspProvider.getValues();
  560.         List<String> ocspLabels = ocspProvider.getLabels();
  561.                
  562.         boolean crlWithOCSPEnabledTrustAllHttpsServer =
  563.                 ocspEnabled &&
  564.                 core.isOCSPPolicyChoiceConnettoreHTTPSVerificaServerDisabilitata() &&
  565.                 httpsTrustStoreOCSPPolicy!=null &&
  566.                 !"".equals(httpsTrustStoreOCSPPolicy);
  567.                
  568.         de = new DataElement();
  569.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  570.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  571.         if(ocspEnabled && (httpsTrustVerifyCert || core.isOCSPPolicyChoiceConnettoreHTTPSVerificaServerDisabilitata())) {
  572.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  573.                 de.setType(DataElementType.SELECT);
  574.                 de.setValues(ocspTypes);
  575.                 de.setLabels(ocspLabels);
  576.                 if(postBackViaPost) {
  577.                     de.setPostBack_viaPOST(core.isOCSPPolicyChoiceConnettoreHTTPSVerificaServerDisabilitata());
  578.                 }
  579.                 else {
  580.                     de.setPostBack(core.isOCSPPolicyChoiceConnettoreHTTPSVerificaServerDisabilitata());
  581.                 }
  582.                 if(httpsTrustStoreOCSPPolicy==null) {
  583.                     httpsTrustStoreOCSPPolicy = "";
  584.                 }  
  585.                 de.setSelected(httpsTrustStoreOCSPPolicy);
  586.             }else{
  587.                 de.setType(DataElementType.HIDDEN);
  588.                
  589.                 if(httpsTrustStoreOCSPPolicy!=null &&
  590.                         !"".equals(httpsTrustStoreOCSPPolicy)){
  591.                    
  592.                     String label = null;
  593.                     for (int i = 0; i < ocspTypes.size(); i++) {
  594.                         String type = ocspTypes.get(i);
  595.                         if(type!=null && type.equals(httpsTrustStoreOCSPPolicy)) {
  596.                             label = ocspLabels.get(i);
  597.                         }
  598.                     }
  599.                     if(label!=null) {
  600.                         DataElement deLABEL = new DataElement();
  601.                         de.setType(DataElementType.TEXT);
  602.                         deLABEL.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  603.                         deLABEL.setValue(label);
  604.                         deLABEL.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY+CostantiControlStation.PARAMETRO_SUFFIX_LABEL);
  605.                         dati.add(deLABEL);
  606.                     }
  607.                 }
  608.             }
  609.             de.setSize(pageSize);
  610.         }
  611.         else {
  612.             de.setType(DataElementType.HIDDEN);
  613.         }
  614.         de.setValue(httpsTrustStoreOCSPPolicy);
  615.         dati.add(de);
  616.        
  617.         de = new DataElement();
  618.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL);
  619.         de.setValue(httpsTrustStoreCRLs);
  620.         if(httpsTrustVerifyCert || crlWithOCSPEnabledTrustAllHttpsServer) {
  621.             de.setNote(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL_NOTE);
  622.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  623.                 de.setType(DataElementType.TEXT_AREA);  
  624.             }else{
  625.                 de.setType(DataElementType.TEXT_AREA_NO_EDIT);
  626.             }
  627.             de.setRows(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL_SIZE);
  628.             de.setSize(pageSize);
  629.         }
  630.         else {
  631.             de.setType(DataElementType.HIDDEN);
  632.         }
  633.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL);
  634.         dati.add(de);
  635.        
  636.         de = new DataElement();
  637.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  638.         de.setValue(httpsalgoritmo);
  639.         if(httpsTrustVerifyCert) {
  640.             if(!consoleHelper.isModalitaStandard()) {
  641.                 if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  642.                     de.setType(DataElementType.TEXT_EDIT);
  643.                     de.setRequired(true);  
  644.                 }else{
  645.                     de.setType(DataElementType.TEXT);
  646.                 }
  647.                 de.setSize(pageSize);
  648.             }
  649.             else {
  650.                 de.setType(DataElementType.HIDDEN);
  651.             }
  652.         }
  653.         else {
  654.             de.setType(DataElementType.HIDDEN);
  655.         }
  656.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  657.         dati.add(de);

  658.         de = new DataElement();
  659.         de.setLabel(prefix+ConnettoriCostanti.LABEL_CONNETTORE_AUTENTICAZIONE_CLIENT);
  660.         de.setType(DataElementType.SUBTITLE);
  661.         dati.add(de);

  662.         de = new DataElement();
  663.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_STATO);
  664.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_STATO);
  665.         if(forceHttpsClient) {
  666.             httpsstato = true;
  667.             de.setValue(Costanti.CHECK_BOX_ENABLED);
  668.             de.setType(DataElementType.HIDDEN);
  669.         }
  670.         else {
  671.             de.setValue(httpsstato ? Costanti.CHECK_BOX_ENABLED : "");
  672.             de.setSelected(httpsstato);
  673.             de.setType(DataElementType.CHECKBOX);
  674.             if(postBackViaPost) {
  675.                 de.setPostBack_viaPOST(true);
  676.             }
  677.             else {
  678.                 de.setPostBack(true);
  679.             }
  680.         }
  681.         dati.add(de);


  682.         de = new DataElement();
  683.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE);
  684.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE);
  685.         if (httpsstato) {
  686.             if(httpsTrustVerifyCert) {
  687.                 de.setType(DataElementType.SELECT);
  688.                 de.setValues(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODES);
  689.                 de.setLabels(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_LABEL_MODES);
  690.                 de.setSelected(httpskeystore);
  691.                 if(postBackViaPost) {
  692.                     de.setPostBack_viaPOST(true);
  693.                 }
  694.                 else {
  695.                     de.setPostBack(true);
  696.                 }
  697.             }
  698.             else {
  699.                 de.setType(DataElementType.HIDDEN);
  700.                 httpskeystore = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI;
  701.                 de.setValue(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI);
  702.             }
  703.         } else {
  704.             de.setType(DataElementType.HIDDEN);
  705.             de.setValue("");
  706.         }
  707.         dati.add(de);

  708.         de = new DataElement();
  709.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_STORE);
  710.         if (httpsstato &&
  711.                 (httpskeystore == null || "".equals(httpskeystore) || httpskeystore.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_DEFAULT))){
  712.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  713.                 de.setRequired(isStorePasswordRequired(httpstipo, httpstipoDefault, true, true, core));
  714.                 core.getLockUtilities().lock(de, httpspwdprivatekeytrust);
  715.             }else{
  716.                 core.getLockUtilities().lockReadOnly(de, httpspwdprivatekeytrust);
  717.             }
  718.         }else {
  719.             core.getLockUtilities().lockHidden(de, httpspwdprivatekeytrust);
  720.         }
  721.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_STORE);
  722.         de.setSize(pageSize);
  723.         dati.add(de);

  724.         boolean keystoreHsm = false;
  725.         de = new DataElement();
  726.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_TYPE);
  727.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_TYPE);
  728.         String httpstipokeyDefault = null;
  729.         if (httpsstato &&
  730.                 (httpskeystore != null && httpskeystore.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI))) {
  731.             de.setType(DataElementType.SELECT);
  732.             if(core.isConnettoriAllTypesEnabled()) {
  733.                 de.setValues(ConnettoriCostanti.TIPOLOGIE_KEYSTORE_OLD);
  734.             }
  735.             else {
  736.                 List<String> values = ConnettoriCostanti.getTIPOLOGIE_KEYSTORE(false, false);
  737.                 List<String> labels = ConnettoriCostanti.getTIPOLOGIE_KEYSTORE(false, true);
  738.                 // per retrocompatibilita verifico che esista ancora nelle nuove, altrimenti lo aggiungo
  739.                 if(httpstipokey!=null && !"".equals(httpstipokey)) {
  740.                     boolean exists = false;
  741.                     for (String v : values) {
  742.                         if(httpstipokey.equalsIgnoreCase(v)) {
  743.                             exists = true;
  744.                             break;
  745.                         }
  746.                     }
  747.                     if(!exists) {
  748.                         values.add(httpstipokey);
  749.                     }
  750.                 }
  751.                 de.setValues(values);
  752.                 de.setLabels(labels);
  753.                 if(ConnettoriCostanti.existsTIPOLOGIE_KEYSTORE_HSM(false)) {
  754.                     if(postBackViaPost) {
  755.                         de.setPostBack_viaPOST(true);
  756.                     }
  757.                     else {
  758.                         de.setPostBack(true);
  759.                     }
  760.                 }
  761.             }
  762.             if(httpstipokey!=null) {
  763.                 de.setSelected(httpstipokey);
  764.                 keystoreHsm = HSMUtils.isKeystoreHSM(httpstipokey);
  765.             }
  766.         } else {
  767.             de.setType(DataElementType.HIDDEN);
  768.             de.setValue("");
  769.         }
  770.         if( (httpstipokey==null || "".equals(httpstipokey))
  771.             && de.getValues()!=null && de.getValues().length>0) {
  772.             httpstipokeyDefault = de.getValues()[0];
  773.         }
  774.         dati.add(de);
  775.        
  776.         de = new DataElement();
  777.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  778.         de.setValue(httpspathkey);
  779.         if (httpsstato &&
  780.                 (httpskeystore != null && httpskeystore.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI))){
  781.             if(keystoreHsm) {
  782.                 de.setValue(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_PATH_HSM_PREFIX+httpstipokey);
  783.                 de.setType(DataElementType.HIDDEN);
  784.             }
  785.             else {
  786.                 if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  787.                     de.setType(DataElementType.TEXT_AREA);
  788.                     de.setRequired(true);  
  789.                 }else{
  790.                     de.setType(DataElementType.TEXT_AREA_NO_EDIT);
  791.                 }
  792.                 de.setRows(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_LOCATION_SIZE);
  793.             }
  794.         }else
  795.             de.setType(DataElementType.HIDDEN);
  796.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  797.         de.setSize(pageSize);
  798.         dati.add(de);

  799.         de = new DataElement();
  800.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  801.         if (httpsstato &&
  802.                 (httpskeystore != null && httpskeystore.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI))){
  803.             if(keystoreHsm) {
  804.                 de.setValue(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_HSM_STORE_PASSWORD_UNDEFINED);
  805.                 de.setType(DataElementType.HIDDEN);
  806.             }
  807.             else if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  808.                 de.setRequired(isStorePasswordRequired(httpstipokey, httpstipokeyDefault, true, false, core));
  809.                 core.getLockUtilities().lock(de, httpspwdkey);
  810.             }else{
  811.                 core.getLockUtilities().lockReadOnly(de, httpspwdkey);
  812.             }
  813.         }else {
  814.             core.getLockUtilities().lockHidden(de, httpspwdkey);
  815.         }
  816.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  817.         de.setSize(pageSize);
  818.         dati.add(de);

  819.         de = new DataElement();
  820.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_KEYSTORE);
  821.         if (httpsstato &&
  822.                 (httpskeystore != null && httpskeystore.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI))){
  823.             if(keystoreHsm && !ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_HSM_CONFIGURABLE_KEY_PASSWORD) {
  824.                 de.setValue(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_HSM_PRIVATE_KEY_PASSWORD_UNDEFINED);
  825.                 de.setType(DataElementType.HIDDEN);
  826.             }
  827.             else if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  828.                 de.setRequired(isStorePasswordRequired(httpstipokey, httpstipokeyDefault, true, true, core));
  829.                 core.getLockUtilities().lock(de, httpspwdprivatekey);
  830.             }else{
  831.                 core.getLockUtilities().lockReadOnly(de, httpspwdprivatekey);
  832.             }
  833.         }else {
  834.             core.getLockUtilities().lockHidden(de, httpspwdprivatekey);
  835.         }
  836.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_KEYSTORE);
  837.         de.setSize(pageSize);
  838.         dati.add(de);

  839.         de = new DataElement();
  840.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_ALIAS_PRIVATE_KEY_KEYSTORE);
  841.         de.setValue(httpsKeyAlias);
  842.         if (httpsstato){
  843.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  844.                 de.setType(DataElementType.TEXT_EDIT);  
  845.             }else{
  846.                 de.setType(DataElementType.TEXT);
  847.             }
  848.         }else
  849.             de.setType(DataElementType.HIDDEN);
  850.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_ALIAS_PRIVATE_KEY_KEYSTORE);
  851.         de.setSize(pageSize);
  852.         dati.add(de);
  853.        
  854.         de = new DataElement();
  855.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  856.         de.setValue(httpsalgoritmokey);
  857.         if (httpsstato && !consoleHelper.isModalitaStandard()){
  858.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  859.                 de.setType(DataElementType.TEXT_EDIT);
  860.                 de.setRequired(true);  
  861.             }else{
  862.                 de.setType(DataElementType.TEXT);
  863.             }
  864.         }else
  865.             de.setType(DataElementType.HIDDEN);
  866.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  867.         de.setSize(pageSize);
  868.         dati.add(de);
  869.        
  870.        
  871.        
  872.        
  873.        
  874.         BYOKProvider byokProvider = BYOKProvider.getUnwrapInstance();
  875.         boolean byokEnabled = byokProvider.isUnwrapByokKeystoreEnabled();
  876.         List<String> byokTypes = byokProvider.getValues();
  877.         List<String> byokLabels = byokProvider.getLabels();
  878.        
  879.         de = new DataElement();
  880.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  881.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  882.         if(byokEnabled && httpsstato && !keystoreHsm) {
  883.             if(!consoleHelper.isShowGestioneWorkflowStatoDocumenti() || !StatiAccordo.finale.toString().equals(stato)){
  884.                 de.setType(DataElementType.SELECT);
  885.                 de.setValues(byokTypes);
  886.                 de.setLabels(byokLabels);
  887.                 if(postBackViaPost) {
  888.                     de.setPostBack_viaPOST(true);
  889.                 }
  890.                 else {
  891.                     de.setPostBack(true);
  892.                 }
  893.                 if(httpsKeyStoreBYOKPolicy==null) {
  894.                     httpsKeyStoreBYOKPolicy = "";
  895.                 }  
  896.                 de.setSelected(httpsKeyStoreBYOKPolicy);
  897.             }else{
  898.                 de.setType(DataElementType.HIDDEN);
  899.                
  900.                 if(httpsKeyStoreBYOKPolicy!=null &&
  901.                         !"".equals(httpsKeyStoreBYOKPolicy)){
  902.                    
  903.                     String label = null;
  904.                     for (int i = 0; i < byokTypes.size(); i++) {
  905.                         String type = byokTypes.get(i);
  906.                         if(type!=null && type.equals(httpsKeyStoreBYOKPolicy)) {
  907.                             label = byokLabels.get(i);
  908.                         }
  909.                     }
  910.                     if(label!=null) {
  911.                         DataElement deLABEL = new DataElement();
  912.                         de.setType(DataElementType.TEXT);
  913.                         deLABEL.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  914.                         deLABEL.setValue(label);
  915.                         deLABEL.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY+CostantiControlStation.PARAMETRO_SUFFIX_LABEL);
  916.                         dati.add(deLABEL);
  917.                     }
  918.                 }
  919.             }
  920.             de.setSize(pageSize);
  921.             de.setValue(httpsKeyStoreBYOKPolicy);
  922.         }
  923.         else {
  924.             de.setType(DataElementType.HIDDEN);
  925.         }
  926.         dati.add(de);
  927.     }
  928.     private static boolean isStorePasswordRequired(String httpstipo, String httpstipoDefault, boolean keystore, boolean key, ControlStationCore core) {
  929.         String check = httpstipo;
  930.         if(httpstipo==null || "".equals(httpstipo)) {
  931.             check = httpstipoDefault;
  932.         }
  933.        
  934.         if(KeystoreType.JKS.isType(check)) {
  935.             return isStoreJksPasswordRequired(keystore, key, core);
  936.         }
  937.         else if(KeystoreType.PKCS12.isType(check)) {
  938.             return isStorePkcs12PasswordRequired(keystore, key, core);
  939.         }
  940.         else {
  941.             return true;
  942.         }
  943.     }
  944.     private static boolean isStoreJksPasswordRequired(boolean keystore, boolean key,
  945.             ControlStationCore core) {
  946.         if(keystore) {
  947.             return key ? core.isKeystoreJksKeyPasswordRequired() : core.isKeystoreJksPasswordRequired();
  948.         }
  949.         else {
  950.             return core.isTruststoreJksPasswordRequired();
  951.         }
  952.     }
  953.     private static boolean isStorePkcs12PasswordRequired(boolean keystore, boolean key,
  954.             ControlStationCore core) {
  955.         if(keystore) {
  956.             return key ? core.isKeystorePkcs12KeyPasswordRequired() : core.isKeystorePkcs12PasswordRequired();
  957.         }
  958.         else {
  959.             return core.isTruststorePkcs12PasswordRequired();
  960.         }
  961.     }
  962.    
  963.     public static void addHTTPSDatiAsHidden(List<DataElement> dati,
  964.             String httpsurl, String httpstipologia, boolean httpshostverify,
  965.             boolean httpsTrustVerifyCert, String httpspath, String httpstipo, String httpspwd,
  966.             String httpsalgoritmo, boolean httpsstato, String httpskeystore,
  967.             String httpspwdprivatekeytrust, String httpspathkey,
  968.             String httpstipokey, String httpspwdkey,
  969.             String httpspwdprivatekey, String httpsalgoritmokey,
  970.             String httpsKeyAlias, String httpsTrustStoreCRLs, String httpsTrustStoreOCSPPolicy, String httpsKeyStoreBYOKPolicy,
  971.             String stato,
  972.             ControlStationCore core,int pageSize){
  973.        
  974.         if(stato!=null && core!=null) {
  975.             // nop
  976.         }
  977.        
  978.         DataElement de = new DataElement();
  979.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_URL);
  980.         de.setValue(httpsurl);
  981.         de.setType(DataElementType.HIDDEN);
  982.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_URL);
  983.         de.setSize(pageSize);
  984.         dati.add(de);


  985.         de = new DataElement();
  986.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_SSL_TYPE);
  987.         de.setType(DataElementType.HIDDEN);
  988.         de.setValue(httpstipologia);
  989.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_SSL_TYPE);
  990.         dati.add(de);

  991.         de = new DataElement();
  992.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_HOST_VERIFY);
  993.         de.setValue(httpshostverify ? Costanti.CHECK_BOX_ENABLED : "");
  994.         de.setType(DataElementType.HIDDEN);
  995.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_HOST_VERIFY);
  996.         dati.add(de);

  997.         de = new DataElement();
  998.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS);
  999.         de.setValue(httpsTrustVerifyCert ? Costanti.CHECK_BOX_ENABLED : "");
  1000.         de.setType(DataElementType.HIDDEN);
  1001.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS);
  1002.         de.setSize(pageSize);
  1003.         dati.add(de);
  1004.        
  1005.         de = new DataElement();
  1006.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  1007.         de.setValue(httpspath);
  1008.         de.setType(DataElementType.HIDDEN);
  1009.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  1010.         de.setSize(pageSize);
  1011.         dati.add(de);

  1012.         de = new DataElement();
  1013.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  1014.         de.setType(DataElementType.HIDDEN);
  1015.         de.setValue(httpstipo);
  1016.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  1017.         dati.add(de);

  1018.         de = new DataElement();
  1019.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  1020.         de.setValue(httpspwd);
  1021.         de.setType(DataElementType.HIDDEN);
  1022.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  1023.         de.setSize(pageSize);
  1024.         dati.add(de);

  1025.         de = new DataElement();
  1026.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL);
  1027.         de.setValue(httpsTrustStoreCRLs);
  1028.         de.setType(DataElementType.HIDDEN);
  1029.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL);
  1030.         de.setSize(pageSize);
  1031.         dati.add(de);
  1032.        
  1033.         de = new DataElement();
  1034.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  1035.         de.setValue(httpsTrustStoreOCSPPolicy);
  1036.         de.setType(DataElementType.HIDDEN);
  1037.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  1038.         de.setSize(pageSize);
  1039.         dati.add(de);
  1040.        
  1041.         de = new DataElement();
  1042.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  1043.         de.setValue(httpsalgoritmo);
  1044.         de.setType(DataElementType.HIDDEN);
  1045.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  1046.         de.setSize(pageSize);
  1047.         dati.add(de);

  1048.         de = new DataElement();
  1049.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_STATO);
  1050.         de.setValue(httpsstato ? Costanti.CHECK_BOX_ENABLED : "");
  1051.         de.setType(DataElementType.HIDDEN);
  1052.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_STATO);
  1053.         dati.add(de);


  1054.         de = new DataElement();
  1055.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE);
  1056.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE);
  1057.         de.setType(DataElementType.HIDDEN);
  1058.         if (httpsstato) {
  1059.             de.setValue(httpskeystore);
  1060.         } else {
  1061.             de.setValue("");
  1062.         }
  1063.         dati.add(de);

  1064.         de = new DataElement();
  1065.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_STORE);
  1066.         de.setValue(httpspwdprivatekeytrust);
  1067.         de.setType(DataElementType.HIDDEN);
  1068.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_STORE);
  1069.         de.setSize(pageSize);
  1070.         dati.add(de);

  1071.         de = new DataElement();
  1072.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  1073.         de.setValue(httpspathkey);
  1074.         de.setType(DataElementType.HIDDEN);
  1075.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  1076.         de.setSize(pageSize);
  1077.         dati.add(de);

  1078.         de = new DataElement();
  1079.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_TYPE);
  1080.         if (httpsstato &&
  1081.                 (httpskeystore != null && httpskeystore.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI))) {
  1082.             de.setType(DataElementType.HIDDEN);
  1083.             de.setValue(httpstipokey);
  1084.         } else {
  1085.             de.setType(DataElementType.HIDDEN);
  1086.             de.setValue("");
  1087.         }
  1088.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_TYPE);
  1089.         dati.add(de);

  1090.         de = new DataElement();
  1091.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  1092.         de.setValue(httpspwdkey);
  1093.         de.setType(DataElementType.HIDDEN);
  1094.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  1095.         de.setSize(pageSize);
  1096.         dati.add(de);

  1097.         de = new DataElement();
  1098.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_KEYSTORE);
  1099.         de.setValue(httpspwdprivatekey);
  1100.         de.setType(DataElementType.HIDDEN);
  1101.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_KEYSTORE);
  1102.         de.setSize(pageSize);
  1103.         dati.add(de);
  1104.        
  1105.         de = new DataElement();
  1106.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_ALIAS_PRIVATE_KEY_KEYSTORE);
  1107.         de.setValue(httpsKeyAlias);
  1108.         de.setType(DataElementType.HIDDEN);
  1109.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_ALIAS_PRIVATE_KEY_KEYSTORE);
  1110.         de.setSize(pageSize);
  1111.         dati.add(de);

  1112.         de = new DataElement();
  1113.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  1114.         de.setValue(httpsalgoritmokey);
  1115.         de.setType(DataElementType.HIDDEN);
  1116.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  1117.         de.setSize(pageSize);
  1118.         dati.add(de);
  1119.                
  1120.         de = new DataElement();
  1121.         de.setLabel(ConnettoriCostanti.LABEL_PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  1122.         de.setValue(httpsKeyStoreBYOKPolicy);
  1123.         de.setType(DataElementType.HIDDEN);
  1124.         de.setName(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  1125.         de.setSize(pageSize);
  1126.         dati.add(de);
  1127.        
  1128.     }
  1129.    
  1130. }