BYOKManager.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.certificate.byok;

  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.util.ArrayList;
  24. import java.util.Collections;
  25. import java.util.Enumeration;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. import java.util.Properties;

  30. import org.apache.commons.lang.StringUtils;
  31. import org.openspcoop2.utils.SortedMap;
  32. import org.openspcoop2.utils.Utilities;
  33. import org.openspcoop2.utils.UtilsException;
  34. import org.openspcoop2.utils.properties.PropertiesReader;
  35. import org.slf4j.Logger;

  36. /**
  37.  * BYOKManager
  38.  *
  39.  * @author Poli Andrea (apoli@link.it)
  40.  * @author $Author$
  41.  * @version $Rev$, $Date$
  42.  */
  43. public class BYOKManager {

  44.     private static BYOKManager staticInstance;
  45.     public static synchronized void init(File f, boolean throwNotExists, Logger log) throws UtilsException {
  46.         if(staticInstance==null) {
  47.             staticInstance = new BYOKManager(f, throwNotExists, log);
  48.         }
  49.     }
  50.     public static BYOKManager getInstance() {
  51.         // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  52.         if (staticInstance == null) {
  53.             synchronized (BYOKManager.class) {
  54.                 if (staticInstance == null) {
  55.                     return null;
  56.                 }
  57.             }
  58.         }
  59.         return staticInstance;
  60.     }
  61.     public static String getSecurityEngineGovWayPolicy() {
  62.         if(staticInstance!=null) {
  63.             return staticInstance.getSecurityEngineGovWay();
  64.         }
  65.         return null;
  66.     }
  67.     public static String getSecurityRemoteEngineGovWayPolicy() {
  68.         if(staticInstance!=null) {
  69.             return staticInstance.getSecurityRemoteEngineGovWay();
  70.         }
  71.         return null;
  72.     }
  73.     public static boolean isEnabledBYOK() {
  74.         String securityManagerPolicy = BYOKManager.getSecurityEngineGovWayPolicy();
  75.         return securityManagerPolicy!=null && StringUtils.isNotEmpty(securityManagerPolicy);
  76.     }
  77.    
  78.     /*
  79.      * Consente di inizializzare una serie di keystore hardware
  80.      *
  81.      * La configurazione di ogni keystore deve essere definita nel file kms.properties fornito come argomento dove la sintassi utilizzabile è la seguente
  82.      *
  83.      * kms.<idKMS>.type: [required] identificativo univoco del kms utilizzato nelle configurazioni di govway
  84.      * kms.<idKMS>.label: [required] etichetta associata al kms e visualizzata nelle maschere di configurazione
  85.      * kms.<idKMS>.mode: [required] indica il tipo di operazione wrap e unwrap
  86.      * kms.<idKMS>.input.<idParam>.name: [optional] se fornito definisce un parametro richiesto alla configurazione della credenziale a cui il kms viene associato
  87.      * kms.<idKMS>.input.<idParam>.label: [optional] definisce l'etichetta associata al parametro di configurazione
  88.      *
  89.      * Le restanti proprietà definiscono come accedere al kms possono essere valorizzate utilizzando anche le seguenti variabili:
  90.      * ${kms-key}: byte[] dell'archivio indicato
  91.      * ${kms-base64-key}: byte[] dell'archivio indicato codificato in base64
  92.      * ${kms-hex-key}: byte[] dell'archivio indicato codificato in base64
  93.      * ${kms:<nomeparametro>}: parametro indicato nella configurazione del kms
  94.      *
  95.      * L'operazione di wrap/unwrap può essere realizzata invocando un kms remoto (via http) o cifrando/decifrando tramite keystore locali.
  96.      *
  97.      * kms.<idKMS>.encryptionMode: [optional; default:remote] indica il tipo di encryption via kms remoto (remote) o locale (local)
  98.      *
  99.      * Configurazioni per kms remoto:
  100.      *
  101.      * kms.<idKMS>.http.endpoint: [required] definisce l'endpoint del kms
  102.      * kms.<idKMS>.http.method: [required] definisce il metodo HTTP utilzzato per connettersi al kms
  103.      * kms.<idKMS>.http.header.<nome>: definisce un header HTTP che possiede il nome indicato nella proprietà stessa
  104.      * kms.<idKMS>.http.payload.inline [optional] definisce il payload da utilizzare nella richiesta http
  105.      * kms.<idKMS>.http.payload.path [optional] alternativa alla precedente proprietà defnisce il path ad un file contenente il payload da utilizzare nella richiesta http
  106.      * kms.<idKMS>.http.username [optional] definisce la credenziale http-basic (username)
  107.      * kms.<idKMS>.http.password [optional] definisce la credenziale http-basic (password)
  108.      * kms.<idKMS>.http.connectionTimeout [optional; int] tempo massimo in millisecondi di attesa per stabilire una connessione con il server kms
  109.      * kms.<idKMS>.http.readTimeout [optional; int] tempo massimo in millisecondi di attesa per la ricezione di una risposta dal server
  110.      *
  111.      * Le seguenti proprietà opzionali consentono invece di utilizzare e configurare un connettore di tipo https
  112.      * kms.<idKMS>.https [optional; boolean] indica se utilizzare o meno un connettore di tipo https
  113.      * kms.<idKMS>.https.hostnameVerifier  [optional; boolean] indica se deve essere verificato l'hostname rispetto al certificato server
  114.      *
  115.      * kms.<idKMS>.https.serverAuth  [optional; boolean] indica se deve essere effettuata l'autenticazione del certificato server
  116.      * kms.<idKMS>.https.serverAuth.trustStore.path: truststore per effettuare l'autenticazione
  117.      * kms.<idKMS>.https.serverAuth.trustStore.type: tipo di truststore
  118.      * kms.<idKMS>.https.serverAuth.trustStore.password password del truststore
  119.      * kms.<idKMS>.https.serverAuth.trustStore.crls: crl
  120.      * kms.<idKMS>.https.serverAuth.trustStore.ocspPolicy: OCSP Policy
  121.      *
  122.      * kms.<idKMS>.https.clientAuth  [optional; boolean] indica se deve essere inviato un certificato client
  123.      * kms.<idKMS>.https.clientAuth.keyStore.path: keystore per effettuare l'autenticazione client
  124.      * kms.<idKMS>.https.clientAuth.keyStore.type: tipo di keystore
  125.      * kms.<idKMS>.https.clientAuth.keyStore.password password del keystore
  126.      * kms.<idKMS>.https.clientAuth.key.alias: identifica la chiave privata
  127.      * kms.<idKMS>.https.clientAuth.key.password: password della chiave privata
  128.      *
  129.      * kms.<idKMS>.http.response.base64Encoded [optional; boolean] indicazione se la risposta è codificata in base64
  130.      * kms.<idKMS>.http.response.hexEncoded [optional; boolean] indicazione se la risposta è codificata tramite una rappresentazione esadecimale
  131.      * kms.<idKMS>.http.response.jsonPath [optional] se la risposta è un json (eventualmente dopo la decodificata base64/hex) consente di indicare un jsonPath per estrarre l'informazione da un singolo elemento
  132.      *
  133.      **/
  134.    

  135.     private HashMap<String, BYOKConfig> kmsKeystoreMapIDtoConfig = new HashMap<>();
  136.    
  137.     private HashMap<String, String> kmsKeystoreMapLabelToID = new HashMap<>();
  138.     private HashMap<String, String> kmsKeystoreMapTypeToID = new HashMap<>();
  139.    
  140.     private List<String> unwrapTypes = new ArrayList<>();
  141.     private List<String> unwrapLabels = new ArrayList<>();
  142.     private List<String> wrapTypes = new ArrayList<>();
  143.     private List<String> wrapLabels = new ArrayList<>();

  144.     private static final String UNKNOWN = "unknown";
  145.    
  146.     private HashMap<String, BYOKSecurityConfig> securityMapIDtoConfig = new HashMap<>();
  147.    
  148.     private String securityEngineGovWay = null;
  149.     private String securityRemoteEngineGovWay = null;
  150.    
  151.     private BYOKManager(File f, boolean throwNotExists, Logger log) throws UtilsException {
  152.         String prefixFile = "File '"+f.getAbsolutePath()+"'";
  153.         if(!f.exists()) {
  154.             if(throwNotExists) {
  155.                 throw new UtilsException(prefixFile+" not exists");
  156.             }
  157.         }
  158.         else {
  159.             if(!f.canRead()) {
  160.                 throw new UtilsException(prefixFile+" cannot read");
  161.             }
  162.             Properties p = new Properties();
  163.             try {
  164.                 try(FileInputStream fin = new FileInputStream(f)){
  165.                     p.load(fin);
  166.                 }
  167.             }catch(Exception t) {
  168.                 throw new UtilsException(prefixFile+"; initialize error: "+t.getMessage(),t);
  169.             }
  170.             init(p, log);
  171.         }
  172.     }
  173.     /**private BYOKManager(Properties p, Logger log, boolean accessKeystore) throws UtilsException {
  174.         init(p, log, accessKeystore);
  175.     }*/
  176.     private void init(Properties p, Logger log) throws UtilsException {
  177.        
  178.         List<String> idKeystore = new ArrayList<>();
  179.         List<String> securityKeystore = new ArrayList<>();
  180.        
  181.         if(p!=null && !p.isEmpty()) {
  182.             init(p, idKeystore, securityKeystore);
  183.         }
  184.        
  185.         if(!idKeystore.isEmpty()) {
  186.             for (String idK : idKeystore) {
  187.                 init(p, log, idK);      
  188.             }
  189.         }
  190.         else {
  191.             log.warn("La configurazione fornita per KMS non contiene alcun keystore");
  192.         }
  193.        
  194.         if(!securityKeystore.isEmpty()) {
  195.             for (String idK : securityKeystore) {
  196.                 initSecurity(p, log, idK);      
  197.             }
  198.         }
  199.         else {
  200.             log.warn("La configurazione fornita per KMS non contiene alcun security manager");
  201.         }
  202.        
  203.         initSecurityGovWay(p);
  204.     }
  205.     private void init(Properties p, List<String> idKeystore, List<String> securityKeystore) {
  206.         Enumeration<?> enKeys = p.keys();
  207.         while (enKeys.hasMoreElements()) {
  208.             Object object = enKeys.nextElement();
  209.             if(object instanceof String) {
  210.                 String key = (String) object;
  211.                 init(key, idKeystore, securityKeystore);    
  212.             }
  213.         }
  214.     }
  215.     private void init(String key, List<String> idKeystore, List<String> securityKeystore) {
  216.         boolean isIdKeystore = initEngine(key, idKeystore, BYOKCostanti.PROPERTY_PREFIX_KMS);
  217.         if(!isIdKeystore) {
  218.             isIdKeystore = initEngine(key, idKeystore, BYOKCostanti.PROPERTY_PREFIX_KSM_DEPRECATED);
  219.         }
  220.         if(!isIdKeystore) {
  221.             initEngine(key, securityKeystore, BYOKCostanti.SECURITY_PROPERTY_PREFIX);
  222.         }
  223.     }
  224.     private boolean initEngine(String key, List<String> list, String prefix) {
  225.         if(key.startsWith(prefix) && key.length()>(prefix.length())) {
  226.             String tmp = key.substring(prefix.length());
  227.             if(tmp!=null && tmp.contains(".")) {
  228.                 int indeoOf = tmp.indexOf(".");
  229.                 if(indeoOf>0) {
  230.                     String idK = tmp.substring(0,indeoOf);
  231.                     if(!list.contains(idK)) {
  232.                         list.add(idK);
  233.                     }
  234.                 }
  235.             }
  236.             return true;
  237.         }
  238.         return false;
  239.     }
  240.    
  241.     private void init(Properties p, Logger log, String idK) throws UtilsException {
  242.         String byokPropertyPrefix = BYOKCostanti.PROPERTY_PREFIX_KMS;
  243.         String prefix = byokPropertyPrefix + idK + ".";
  244.         Properties pKeystore = Utilities.readProperties(prefix, p);
  245.         if(pKeystore==null || pKeystore.isEmpty()) {
  246.             byokPropertyPrefix = BYOKCostanti.PROPERTY_PREFIX_KSM_DEPRECATED;
  247.             prefix = byokPropertyPrefix + idK + ".";
  248.             pKeystore = Utilities.readProperties(prefix, p);
  249.         }
  250.         BYOKConfig kmsKeystore = new BYOKConfig(idK, pKeystore, log, byokPropertyPrefix);
  251.        
  252.         // check label
  253.         boolean alreadyExists = false;
  254.         for (String l : this.kmsKeystoreMapLabelToID.keySet()) {
  255.             if(kmsKeystore.getLabel().equalsIgnoreCase(l)) {
  256.                 alreadyExists = true;
  257.                 break;
  258.             }
  259.         }
  260.         if(alreadyExists) {
  261.             throw new UtilsException("Same label found for kms '"+this.kmsKeystoreMapLabelToID.get(kmsKeystore.getLabel())+"' e '"+idK+"'");
  262.         }
  263.         this.kmsKeystoreMapLabelToID.put(kmsKeystore.getLabel(), idK);
  264.        
  265.         // check type
  266.         alreadyExists = false;
  267.         for (String type : this.kmsKeystoreMapTypeToID.keySet()) {
  268.             if(kmsKeystore.getType().equalsIgnoreCase(type)) {
  269.                 alreadyExists = true;
  270.                 break;
  271.             }
  272.         }
  273.         if(alreadyExists) {
  274.             throw new UtilsException("Same type found for kms '"+this.kmsKeystoreMapTypeToID.get(kmsKeystore.getType())+"' e '"+idK+"'");
  275.         }
  276.         this.kmsKeystoreMapTypeToID.put(kmsKeystore.getType(), idK);
  277.        
  278.         // registro nelle liste
  279.         if(BYOKMode.UNWRAP.equals(kmsKeystore.getMode())) {
  280.             this.unwrapTypes.add(kmsKeystore.getType());
  281.             this.unwrapLabels.add(kmsKeystore.getLabel());
  282.         }
  283.         else {
  284.             this.wrapTypes.add(kmsKeystore.getType());
  285.             this.wrapLabels.add(kmsKeystore.getLabel());
  286.         }
  287.        
  288.         this.kmsKeystoreMapIDtoConfig.put(idK, kmsKeystore);
  289.         String d = "KMS "+idK+" registrato (type:"+kmsKeystore.getType()+") label:"+kmsKeystore.getLabel()+"";
  290.         log.info(d);    
  291.     }
  292.    
  293.     private void initSecurity(Properties p, Logger log, String idK) throws UtilsException {
  294.         String prefix = BYOKCostanti.SECURITY_PROPERTY_PREFIX + idK + ".";
  295.         Properties pKeystore = Utilities.readProperties(prefix, p);
  296.         BYOKSecurityConfig securityConfig = new BYOKSecurityConfig(idK, pKeystore, log);
  297.                
  298.         this.securityMapIDtoConfig.put(idK, securityConfig);
  299.         String d = "Security manager "+idK+" registrato";
  300.         log.info(d);    
  301.     }
  302.    
  303.     private void initSecurityGovWay(Properties p) throws UtilsException {
  304.        
  305.         PropertiesReader pReader = new PropertiesReader(p, true);
  306.        
  307.         this.securityEngineGovWay = pReader.getValue_convertEnvProperties(BYOKCostanti.PROPERTY_GOVWAY_SECURITY);
  308.         if(this.securityEngineGovWay!=null && StringUtils.isEmpty(this.securityEngineGovWay)) {
  309.             this.securityEngineGovWay = null;
  310.         }
  311.        
  312.         this.securityRemoteEngineGovWay = pReader.getValue_convertEnvProperties(BYOKCostanti.PROPERTY_GOVWAY_SECURITY_RUNTIME);
  313.         if(this.securityRemoteEngineGovWay!=null && StringUtils.isEmpty(this.securityRemoteEngineGovWay)) {
  314.             this.securityRemoteEngineGovWay = null;
  315.         }
  316.     }
  317.    
  318.     public BYOKConfig getKMSConfigByType(String type) throws UtilsException {
  319.         if(!this.kmsKeystoreMapTypeToID.containsKey(type)) {
  320.             throw new UtilsException("KMS type '"+type+"' "+UNKNOWN);
  321.         }
  322.         String idK = this.kmsKeystoreMapTypeToID.get(type);
  323.         if(!this.kmsKeystoreMapIDtoConfig.containsKey(idK)) {
  324.             throw new UtilsException("KMS config for type '"+type+"' unknown ? (id:"+idK+")");
  325.         }
  326.         return this.kmsKeystoreMapIDtoConfig.get(idK);
  327.     }
  328.    
  329.     public BYOKConfig getKMSConfigByLabel(String label) throws UtilsException {
  330.         if(!this.kmsKeystoreMapLabelToID.containsKey(label)) {
  331.             throw new UtilsException("KMS label '"+label+"' "+UNKNOWN);
  332.         }
  333.         String idK = this.kmsKeystoreMapLabelToID.get(label);
  334.         if(!this.kmsKeystoreMapIDtoConfig.containsKey(idK)) {
  335.             throw new UtilsException("KMS config for label '"+label+"' unknown ? (id:"+idK+")");
  336.         }
  337.         return this.kmsKeystoreMapIDtoConfig.get(idK);
  338.     }
  339.    
  340.     public List<String> getKeystoreTypes() {
  341.         List<String> l = new ArrayList<>();
  342.         if(!this.kmsKeystoreMapLabelToID.isEmpty()) {
  343.             for (String type : this.kmsKeystoreMapLabelToID.keySet()) {
  344.                 l.add(type);
  345.             }
  346.         }
  347.         return l;
  348.     }
  349.    
  350.     public SortedMap<String> getKeystoreWrapConfigTypesLabels() throws UtilsException {
  351.         return getKeystoreConfigTypesLabels(true);
  352.     }
  353.     public SortedMap<String> getKeystoreUnwrapConfigTypesLabels() throws UtilsException {
  354.         return getKeystoreConfigTypesLabels(false);
  355.     }
  356.     private SortedMap<String> getKeystoreConfigTypesLabels(boolean wrap) throws UtilsException {
  357.        
  358.         SortedMap<String> sMap = new SortedMap<>();
  359.        
  360.         List<String> types = wrap ? this.wrapTypes : this.unwrapTypes;
  361.         List<String> labels = wrap ? this.wrapLabels : this.unwrapLabels;
  362.        
  363.         // SortedMap by label
  364.         if(types!=null && !types.isEmpty()) {
  365.             List<String> labelsDaOrdinare = new ArrayList<>();
  366.             Map<String, String> m = new HashMap<>();
  367.             for (int i = 0; i < types.size(); i++) {
  368.                 String type = types.get(i);
  369.                 String label = labels.get(i);
  370.                 m.put(label, type);
  371.                 labelsDaOrdinare.add(label);
  372.             }
  373.            
  374.             Collections.sort(labelsDaOrdinare);
  375.             for (String l : labelsDaOrdinare) {
  376.                 sMap.add(m.get(l), l);  
  377.             }
  378.         }
  379.        
  380.         return sMap;
  381.     }
  382.    
  383.     public boolean isKMSUsedInSecurityWrapConfig(String id, StringBuilder securityId) {
  384.         return isKMSUsedInSecurityConfig(true, id, securityId);
  385.     }
  386.     public boolean isKMSUsedInSecurityUnwrapConfig(String id, StringBuilder securityId) {
  387.         return isKMSUsedInSecurityConfig(false, id, securityId  );
  388.     }
  389.     private boolean isKMSUsedInSecurityConfig(boolean wrap, String id, StringBuilder securityId) {
  390.         if(!this.securityMapIDtoConfig.isEmpty()) {
  391.             for (Map.Entry<String,BYOKSecurityConfig> entry : this.securityMapIDtoConfig.entrySet()) {
  392.                 String confKmsId = wrap ? entry.getValue().getWrapId() : entry.getValue().getUnwrapId();
  393.                 if(id.equals(confKmsId)){
  394.                     if(securityId!=null) {
  395.                         securityId.append(entry.getKey());
  396.                     }
  397.                     return true;
  398.                 }
  399.             }
  400.         }
  401.         return false;
  402.     }
  403.    
  404.     public boolean existsKMSConfigByType(String type) {
  405.         if(type==null) {
  406.             return false;
  407.         }
  408.         for (String i : this.kmsKeystoreMapTypeToID.keySet()) {
  409.             if(type.equalsIgnoreCase(i)) {
  410.                 return true;
  411.             }
  412.         }
  413.         return false;
  414.     }
  415.    
  416.     public boolean existsKMSConfigByLabel(String label) {
  417.         if(label==null) {
  418.             return false;
  419.         }
  420.         for (String i : this.kmsKeystoreMapLabelToID.keySet()) {
  421.             if(label.equalsIgnoreCase(i)) {
  422.                 return true;
  423.             }
  424.         }
  425.         return false;
  426.     }
  427.    
  428.     public List<String> getUnwrapTypes() {
  429.         return this.unwrapTypes;
  430.     }
  431.     public List<String> getUnwrapLabels() {
  432.         return this.unwrapLabels;
  433.     }
  434.     public List<String> getWrapTypes() {
  435.         return this.wrapTypes;
  436.     }
  437.     public List<String> getWrapLabels() {
  438.         return this.wrapLabels;
  439.     }
  440.    
  441.     public BYOKSecurityConfig getKMSSecurityConfig(String type) throws UtilsException {
  442.         if(!this.securityMapIDtoConfig.containsKey(type)) {
  443.             throw new UtilsException("KMS security config type '"+type+"' "+UNKNOWN);
  444.         }
  445.         BYOKSecurityConfig c = this.securityMapIDtoConfig.get(type);
  446.         if(c==null) {
  447.             throw new UtilsException("KMS security config type '"+type+"' "+UNKNOWN);
  448.         }
  449.         return c;
  450.     }
  451.     public List<String> getSecurityEngineTypes() {
  452.         List<String> l = new ArrayList<>();
  453.         if(!this.securityMapIDtoConfig.isEmpty()) {
  454.             for (String type : this.securityMapIDtoConfig.keySet()) {
  455.                 l.add(type);
  456.             }
  457.         }
  458.         return l;
  459.     }
  460.    
  461.     public boolean existsSecurityEngineByType(String type) {
  462.         if(type==null) {
  463.             return false;
  464.         }
  465.         for (String i : this.securityMapIDtoConfig.keySet()) {
  466.             if(type.equalsIgnoreCase(i)) {
  467.                 return true;
  468.             }
  469.         }
  470.         return false;
  471.     }
  472.    
  473.    
  474.     public boolean isBYOKRemoteGovWayNodeUnwrapConfig() throws UtilsException {
  475.         return isBYOKRemoteGovWayNodeConfig(BYOKManager.getSecurityEngineGovWayPolicy(), false, true);
  476.     }
  477.     public boolean isBYOKRemoteGovWayNodeWrapConfig() throws UtilsException {
  478.         return isBYOKRemoteGovWayNodeConfig(BYOKManager.getSecurityEngineGovWayPolicy(), true, false);
  479.        
  480.     }
  481.    
  482.     public boolean isBYOKRemoteGovWayNodeUnwrapConfig(String securityManagerPolicy) throws UtilsException {
  483.         return isBYOKRemoteGovWayNodeConfig(securityManagerPolicy, false, true);
  484.     }
  485.     public boolean isBYOKRemoteGovWayNodeWrapConfig(String securityManagerPolicy) throws UtilsException {
  486.         return isBYOKRemoteGovWayNodeConfig(securityManagerPolicy, true, false);
  487.        
  488.     }
  489.     public boolean isBYOKRemoteGovWayNodeConfig(String securityManagerPolicy) throws UtilsException {
  490.         return isBYOKRemoteGovWayNodeConfig(securityManagerPolicy, true, true);
  491.     }
  492.     public boolean isBYOKRemoteGovWayNodeConfig(String securityManagerPolicy, boolean wrap, boolean unwrap) throws UtilsException {
  493.        
  494.         if(securityManagerPolicy==null || StringUtils.isEmpty(securityManagerPolicy)) {
  495.             return false;
  496.         }
  497.        
  498.         BYOKSecurityConfig secConfig = this.getKMSSecurityConfig(securityManagerPolicy);
  499.        
  500.         boolean govwayRuntime = false;
  501.         if(secConfig.getInputParameters()!=null && !secConfig.getInputParameters().isEmpty()) {
  502.             for (BYOKSecurityConfigParameter sec : secConfig.getInputParameters()) {
  503.                 if(sec.getValue().contains(("${"+BYOKCostanti.GOVWAY_RUNTIME_CONTEXT+":"))) {
  504.                     govwayRuntime = true;
  505.                     break;
  506.                 }
  507.             }
  508.         }
  509.         if(!govwayRuntime) {
  510.             return false;
  511.         }
  512.        
  513.         return isBYOKRemoteGovWayNodeConfig(secConfig, wrap, unwrap);      
  514.     }
  515.     private boolean isBYOKRemoteGovWayNodeConfig(BYOKSecurityConfig secConfig, boolean wrap, boolean unwrap) throws UtilsException {
  516.         // ne basta uno
  517.        
  518.         if(wrap) {
  519.             BYOKConfig c = this.getKMSConfigByType(secConfig.getWrapId());
  520.             if(BYOKEncryptionMode.REMOTE.equals(c.getEncryptionMode())) {
  521.                 return true;
  522.             }
  523.         }
  524.        
  525.         if(unwrap) {
  526.             BYOKConfig c = this.getKMSConfigByType(secConfig.getUnwrapId());
  527.             if(BYOKEncryptionMode.REMOTE.equals(c.getEncryptionMode())) {
  528.                 return true;
  529.             }
  530.         }
  531.        
  532.         return false;
  533.     }
  534.    
  535.     private String getSecurityEngineGovWay() {
  536.         if(this.securityEngineGovWay==null || StringUtils.isEmpty(this.securityEngineGovWay)) {
  537.             return null;
  538.         }
  539.         return this.securityEngineGovWay;
  540.     }
  541.     private String getSecurityRemoteEngineGovWay() {
  542.         if(this.securityRemoteEngineGovWay==null || StringUtils.isEmpty(this.securityRemoteEngineGovWay)) {
  543.             return null;
  544.         }
  545.         return this.securityRemoteEngineGovWay;
  546.     }
  547.     public String getSecurityEngineGovWayDescription() {
  548.         if(this.securityEngineGovWay==null || StringUtils.isEmpty(this.securityEngineGovWay)) {
  549.             return "unactive";
  550.         }
  551.         else {
  552.             StringBuilder sb = new StringBuilder(this.securityEngineGovWay);
  553.             if(this.securityRemoteEngineGovWay!=null && StringUtils.isNotEmpty(this.securityRemoteEngineGovWay) &&
  554.                     !this.securityEngineGovWay.equals(this.securityRemoteEngineGovWay)) {
  555.                 sb.append(" (remote:").append(this.securityRemoteEngineGovWay).append(")");
  556.             }
  557.             return sb.toString();
  558.         }
  559.     }
  560. }