BYOKMapProperties.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.pdd.core.byok;

  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import java.util.Properties;

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.utils.UtilsException;
  26. import org.openspcoop2.utils.UtilsRuntimeException;
  27. import org.openspcoop2.utils.certificate.byok.BYOKInstance;
  28. import org.openspcoop2.utils.certificate.byok.BYOKManager;
  29. import org.openspcoop2.utils.certificate.byok.BYOKMode;
  30. import org.openspcoop2.utils.certificate.byok.BYOKRequestParams;
  31. import org.openspcoop2.utils.properties.MapProperties;
  32. import org.slf4j.Logger;

  33. /**
  34.  * BYOKMapProperties
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */

  40. public class BYOKMapProperties extends MapProperties {

  41.     public static final String FILE_NAME = "govway.secrets.properties";
  42.    
  43.     private static final String PROP_KMS_PREFIX = "kms.";
  44.     private static final String ENV_KMS_PREFIX = MapProperties.ENV_PREFIX+PROP_KMS_PREFIX;
  45.     private static final String JAVA_KMS_PREFIX = MapProperties.JAVA_PREFIX+PROP_KMS_PREFIX;
  46.    
  47.     private static final String PROP_KSM_PREFIX_DEPRECATED = "ksm.";
  48.     private static final String ENV_KSM_PREFIX_DEPRECATED = MapProperties.ENV_PREFIX+PROP_KSM_PREFIX_DEPRECATED;
  49.     private static final String JAVA_KSM_PREFIX_DEPRECATED = MapProperties.JAVA_PREFIX+PROP_KSM_PREFIX_DEPRECATED;
  50.        
  51.     private static final String PROP_SECURITY_PREFIX = "security.";
  52.     private static final String ENV_SECURITY_PREFIX = MapProperties.ENV_PREFIX+PROP_SECURITY_PREFIX;
  53.     private static final String JAVA_SECURITY_PREFIX = MapProperties.JAVA_PREFIX+PROP_SECURITY_PREFIX;
  54.    
  55.     // default true
  56.     private static final String PROP_WRAPPED_PREFIX = "wrapped.";
  57.     private static final String ENV_WRAPPED_PREFIX = MapProperties.ENV_PREFIX+PROP_WRAPPED_PREFIX;
  58.     private static final String JAVA_WRAPPED_PREFIX = MapProperties.JAVA_PREFIX+PROP_WRAPPED_PREFIX;
  59.    
  60.     // default false
  61.     private static final String PROP_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX = "govway-run-only.unwrap-after-startup.";
  62.     private static final String ENV_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX = MapProperties.ENV_PREFIX+PROP_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX;
  63.     private static final String JAVA_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX = MapProperties.JAVA_PREFIX+PROP_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX;
  64.    
  65.     private static final String UNWRAP_DEFAULT_MODE = "unwrap.default.mode";
  66.     private static final String UNWRAP_DEFAULT_ID = "unwrap.default.id";
  67.     private static final String UNWRAP_MODE_SECURITY = "security";
  68.     private static final String UNWRAP_MODE_KMS = "kms";
  69.     private static final String UNWRAP_MODE_KSM_DEPRECATED = "ksm";
  70.    
  71.     // kms.<id>.param.<paramName>=<paramValue>
  72.     private static final String KMS_PREFIX = "kms.";
  73.     private static final String KMS_PARAM_PREFIX = ".param.";
  74.     private static String getKmsParamPrefixPropertyName(String kmsId) {
  75.         return KMS_PREFIX+kmsId+KMS_PARAM_PREFIX;
  76.     }
  77.    
  78.     private static final String KSM_PREFIX_DEPRECATED = "ksm.";
  79.     private static final String KSM_PARAM_PREFIX_DEPRECATED = ".param.";
  80.     private static String getKsmParamPrefixPropertyNameDeprecated(String ksmId) {
  81.         return KSM_PREFIX_DEPRECATED+ksmId+KSM_PARAM_PREFIX_DEPRECATED;
  82.     }
  83.        
  84.     private static final String ERROR_SUFFIX_UNKNOW = "' unknown";
  85.    
  86.     private static final String ERROR_DEFAULT_MODE_NOT_FOUND = ") an unwrap mode has not been defined (security/kms); specifying the mode is mandatory if a default unwrap mode is not defined.";
  87.    
  88.     private String defaultUnwrapId = null;
  89.     private Boolean defaultUnwrapModeSecurity = null;
  90.    
  91.     private boolean useSecurityEngine = false;
  92.     private String securityPolicy;
  93.     private String securityRemotePolicy;
  94.    
  95.     private Map<String, DriverBYOK> mapDriverSecurity = new HashMap<>();
  96.    
  97.     private Map<String, Map<String, String>> mapKmsInput = new HashMap<>();
  98.    
  99.     private Map<String, Object> dynamicMap = null;
  100.     private boolean checkJmxPrefixOperazioneNonRiuscita = false;
  101.    
  102.     private boolean existsUnwrapPropertiesAfterGovWayStartup = false;
  103.     public boolean isExistsUnwrapPropertiesAfterGovWayStartup() {
  104.         return this.existsUnwrapPropertiesAfterGovWayStartup;
  105.     }
  106.     private boolean isGovWayStarted = false; // usato per caricare variabili che devono essere trattate solo sui nodi run
  107.     public boolean isGovWayStarted() {
  108.         return this.isGovWayStarted;
  109.     }
  110.     public void setGovWayStarted(boolean isGovWayStarted) {
  111.         this.isGovWayStarted = isGovWayStarted;
  112.     }

  113.     /** Copia Statica */
  114.     private static BYOKMapProperties secretsProperties = null;
  115.    
  116.     /**private BYOKMapProperties(Logger log, boolean throwNotFound,
  117.             boolean useSecurityEngine,
  118.             Map<String, Object> dynamicMapParam, boolean checkJmxPrefixOperazioneNonRiuscita) throws UtilsException {
  119.         super(log, FILE_NAME, throwNotFound);
  120.         init(useSecurityEngine,
  121.                 dynamicMapParam, checkJmxPrefixOperazioneNonRiuscita);
  122.     }*/
  123.     private BYOKMapProperties(Logger log, String fileName, boolean throwNotFound,
  124.             boolean useSecurityEngine,
  125.             Map<String, Object> dynamicMapParam, boolean checkJmxPrefixOperazioneNonRiuscita) throws UtilsException {
  126.         super(log, fileName, throwNotFound);
  127.         init(useSecurityEngine,
  128.                 dynamicMapParam, checkJmxPrefixOperazioneNonRiuscita);
  129.     }
  130.     private void init(boolean useSecurityEngine,
  131.             Map<String, Object> dynamicMapParam, boolean checkJmxPrefixOperazioneNonRiuscita) {
  132.         String securityPolicyB = BYOKManager.getSecurityEngineGovWayPolicy();
  133.         String securityRemotePolicyB = BYOKManager.getSecurityRemoteEngineGovWayPolicy();
  134.         if(securityPolicyB!=null && StringUtils.isNotEmpty(securityPolicyB)) {
  135.             this.securityPolicy = securityPolicyB;
  136.         }
  137.         if(securityRemotePolicyB!=null && StringUtils.isNotEmpty(securityRemotePolicyB)) {
  138.             this.securityRemotePolicy = securityRemotePolicyB;
  139.         }
  140.         this.useSecurityEngine = useSecurityEngine;
  141.         this.dynamicMap = dynamicMapParam;
  142.         this.checkJmxPrefixOperazioneNonRiuscita = checkJmxPrefixOperazioneNonRiuscita;
  143.     }
  144.    
  145.     /**
  146.      * Il Metodo si occupa di inizializzare il propertiesReader
  147.      *
  148.      *
  149.      */
  150.     public static boolean initialize(Logger log, String fileName, boolean throwNotFound,  
  151.             boolean useSecurityEngine,
  152.             Map<String, Object> dynamicMapParam, boolean checkJmxPrefixOperazioneNonRiuscita){

  153.         try {
  154.             BYOKMapProperties.secretsProperties = new BYOKMapProperties(log, fileName, throwNotFound,
  155.                     useSecurityEngine,
  156.                     dynamicMapParam, checkJmxPrefixOperazioneNonRiuscita);  
  157.             return true;
  158.         }
  159.         catch(Exception e) {
  160.             return false;
  161.         }
  162.     }
  163.    
  164.     /**
  165.      * Ritorna l'istanza di questa classe
  166.      *
  167.      * @return Istanza di BYOKMapProperties
  168.      *
  169.      */
  170.     public static BYOKMapProperties getInstance(){
  171.         // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  172.         if (BYOKMapProperties.secretsProperties == null) {
  173.             synchronized (BYOKMapProperties.class) {
  174.                 if (BYOKMapProperties.secretsProperties == null) {
  175.                     return null;
  176.                 }
  177.             }
  178.         }
  179.         return BYOKMapProperties.secretsProperties;
  180.     }

  181.     @Override
  182.     public void loadPropertyInEnvironment(String key) throws UtilsException {
  183.        
  184.         this.loadDefaultUnwrap();
  185.        
  186.         if(key.startsWith(ENV_PREFIX) && key.length()>ENV_PREFIX.length() &&
  187.                 !key.startsWith(ENV_KSM_PREFIX_DEPRECATED) &&
  188.                 !key.startsWith(ENV_KMS_PREFIX) &&
  189.                 !key.startsWith(ENV_SECURITY_PREFIX) &&
  190.                 !key.startsWith(ENV_WRAPPED_PREFIX) &&
  191.                 !key.startsWith(ENV_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX)) {
  192.             loadEnvPropertyInEnvironment(key);
  193.         }
  194.         else if(key.startsWith(JAVA_PREFIX) && key.length()>JAVA_PREFIX.length() &&
  195.                 !key.startsWith(JAVA_KSM_PREFIX_DEPRECATED) &&
  196.                 !key.startsWith(JAVA_KMS_PREFIX) &&
  197.                 !key.startsWith(JAVA_SECURITY_PREFIX) &&
  198.                 !key.startsWith(JAVA_WRAPPED_PREFIX) &&
  199.                 !key.startsWith(JAVA_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX)) {
  200.             loadJavaPropertyInEnvironment(key);
  201.         }
  202.     }
  203.     public void loadEnvPropertyInEnvironment(String key) throws UtilsException {
  204.         String envKey = key.substring(ENV_PREFIX.length());
  205.         String value = this.reader.getValue_convertEnvProperties(key);
  206.        
  207.         if(this.isUnwrapAfterGovWayStartup(false,envKey)){
  208.             this.existsUnwrapPropertiesAfterGovWayStartup = true;
  209.             if(!this.isGovWayStarted) {
  210.                 return; // verrĂ  effettuato l'unwrap dopo che GovWay ha completato lo startup
  211.             }
  212.         }
  213.        
  214.         if(this.isWrapped(false,envKey)) {
  215.             processWrappedValue(key, envKey, value,
  216.                     false); // envProperty
  217.         }
  218.         else {
  219.             setEnvProperty(envKey, value);
  220.         }
  221.     }
  222.     public void loadJavaPropertyInEnvironment(String key) throws UtilsException {
  223.         String envKey = key.substring(JAVA_PREFIX.length());
  224.         String value = this.reader.getValue_convertEnvProperties(key);
  225.        
  226.         if(this.isUnwrapAfterGovWayStartup(true,envKey)) {
  227.             this.existsUnwrapPropertiesAfterGovWayStartup = true;
  228.             if(!this.isGovWayStarted) {
  229.                 return; // verrĂ  effettuato l'unwrap dopo che GovWay ha completato lo startup
  230.             }
  231.         }
  232.        
  233.         if(this.isWrapped(true,envKey)) {
  234.             processWrappedValue(key, envKey, value,
  235.                     true); // envProperty
  236.         }
  237.         else {
  238.             setJavaProperty(envKey, value);
  239.         }
  240.     }
  241.     private void processWrappedValue(String key, String envKey, String value, boolean javaProperty) throws UtilsException {
  242.         String plainValue = null;
  243.         String securityId = this.getUnwrapId(javaProperty, envKey);
  244.         try {
  245.             if(this.isWrappedBySecurity(javaProperty, envKey)) {
  246.                 String p = this.securityRemotePolicy!=null ? this.securityRemotePolicy : this.securityPolicy;
  247.                 if(!this.useSecurityEngine && securityId!=null && securityId.equals(p)) {
  248.                     // securityNonInizializzato, skip
  249.                     return;
  250.                 }
  251.                 plainValue = getDriverBYOK(securityId).unwrapAsString(value, securityId, true);
  252.             }
  253.             else {
  254.                 plainValue = unwrapByKmsId(value, securityId);
  255.             }
  256.         }catch(Exception e) {
  257.             throw new UtilsException("["+key+"] "+e.getMessage(),e);
  258.         }
  259.         if(plainValue==null) {
  260.             throw new UtilsException("("+key+") unwrapped value null");
  261.         }
  262.         else {
  263.             if(javaProperty) {
  264.                 setJavaProperty(envKey, plainValue);
  265.             }
  266.             else{
  267.                 setEnvProperty(envKey, plainValue);
  268.             }
  269.         }
  270.     }
  271.    
  272.     private void loadDefaultUnwrap() throws UtilsException {
  273.         String tmp = this.reader.getValue_convertEnvProperties(UNWRAP_DEFAULT_ID);
  274.         if(tmp!=null) {
  275.             this.defaultUnwrapId = tmp.trim();
  276.             if(StringUtils.isEmpty(this.defaultUnwrapId)) {
  277.                 this.defaultUnwrapId = null;
  278.             }
  279.         }
  280.        
  281.         if(this.defaultUnwrapId!=null) {
  282.             tmp = this.reader.getValue_convertEnvProperties(UNWRAP_DEFAULT_MODE);
  283.             if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  284.                 if(UNWRAP_MODE_SECURITY.equals(tmp.trim())) {
  285.                     this.defaultUnwrapModeSecurity = true;
  286.                 }
  287.                 else if(UNWRAP_MODE_KMS.equals(tmp.trim()) || UNWRAP_MODE_KSM_DEPRECATED.equals(tmp.trim())) {
  288.                     this.defaultUnwrapModeSecurity = false;
  289.                 }
  290.                 else {
  291.                     throw new UtilsException(UNWRAP_DEFAULT_MODE +" '"+tmp.trim()+ERROR_SUFFIX_UNKNOW);
  292.                 }
  293.             }
  294.             else {
  295.                 this.defaultUnwrapModeSecurity = true; // default by security id
  296.             }
  297.         }
  298.     }
  299.    
  300.     private boolean isWrapped(boolean javaProperty, String key) throws UtilsException {
  301.         if(this.reader==null) {
  302.             return false; // non inizializzato
  303.         }
  304.         String prefix = javaProperty ? JAVA_WRAPPED_PREFIX : ENV_WRAPPED_PREFIX;
  305.         String tmp = this.reader.getValue_convertEnvProperties(prefix+key);
  306.         if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  307.             if("true".equals(tmp.trim())) {
  308.                 return true;
  309.             }
  310.             else if("false".equals(tmp.trim())) {
  311.                 return false;
  312.             }
  313.             else {
  314.                 throw new UtilsException(prefix+key+" with value '"+tmp.trim()+ERROR_SUFFIX_UNKNOW);
  315.             }
  316.         }
  317.         else {
  318.             return true; // default
  319.         }
  320.     }
  321.    
  322.     private boolean isUnwrapAfterGovWayStartup(boolean javaProperty, String key) throws UtilsException {
  323.         if(this.reader==null) {
  324.             return false; // non inizializzato
  325.         }
  326.         String prefix = javaProperty ? JAVA_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX : ENV_UNWRAP_AFTER_GOVWAY_STARTUP_PREFIX;
  327.         String tmp = this.reader.getValue_convertEnvProperties(prefix+key);
  328.         if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  329.             if("true".equals(tmp.trim())) {
  330.                 return true;
  331.             }
  332.             else if("false".equals(tmp.trim())) {
  333.                 return false;
  334.             }
  335.             else {
  336.                 throw new UtilsException(prefix+key+" with value '"+tmp.trim()+ERROR_SUFFIX_UNKNOW);
  337.             }
  338.         }
  339.         else {
  340.             return false; // default
  341.         }
  342.     }
  343.    
  344.     @Override
  345.     protected boolean obfuscate(boolean java, String key) {
  346.         try {
  347.             return isWrapped(java, key);
  348.         }catch(Exception e) {
  349.             return true;
  350.         }
  351.     }
  352.    
  353.     private boolean isWrappedBySecurity(boolean javaProperty, String key) throws UtilsException {
  354.         if(this.reader==null) {
  355.             return false; // non inizializzato
  356.         }
  357.         String pSecurityName = javaProperty ? JAVA_SECURITY_PREFIX : ENV_SECURITY_PREFIX;
  358.         String tmp = this.reader.getValue_convertEnvProperties(pSecurityName+key);
  359.         if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  360.             return true;
  361.         }
  362.         else {
  363.             return isWrappedBySecurityKms(javaProperty, key);
  364.         }
  365.     }
  366.     private boolean isWrappedBySecurityKms(boolean javaProperty, String key) throws UtilsException {
  367.         String pKmsName = javaProperty ? JAVA_KMS_PREFIX : ENV_KMS_PREFIX;
  368.         String tmp = this.reader.getValue_convertEnvProperties(pKmsName+key);
  369.         if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  370.             return false;
  371.         }
  372.         else {
  373.             pKmsName = javaProperty ? JAVA_KSM_PREFIX_DEPRECATED : ENV_KSM_PREFIX_DEPRECATED;
  374.             tmp = this.reader.getValue_convertEnvProperties(pKmsName+key);
  375.             if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  376.                 return false;
  377.             }
  378.         }
  379.        
  380.         if(this.defaultUnwrapModeSecurity!=null) {
  381.             return this.defaultUnwrapModeSecurity.booleanValue();
  382.         }
  383.         else {
  384.             String prefix = javaProperty ? JAVA_PREFIX : ENV_PREFIX;
  385.             throw new UtilsException("("+prefix+key+ERROR_DEFAULT_MODE_NOT_FOUND);
  386.         }
  387.     }
  388.    
  389.     private String getUnwrapId(boolean javaProperty, String key) throws UtilsException {
  390.         if(this.reader==null) {
  391.             return null; // non inizializzato
  392.         }
  393.         String pSecurityName = javaProperty ? JAVA_SECURITY_PREFIX : ENV_SECURITY_PREFIX;
  394.         String tmp = this.reader.getValue_convertEnvProperties(pSecurityName+key);
  395.         if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  396.             return tmp.trim();
  397.         }
  398.         else {
  399.             return getUnwrapIdByKms(javaProperty, key);
  400.         }
  401.     }
  402.     private String getUnwrapIdByKms(boolean javaProperty, String key) throws UtilsException {
  403.         String pKmsName = javaProperty ? JAVA_KMS_PREFIX : ENV_KMS_PREFIX;
  404.         String tmp = this.reader.getValue_convertEnvProperties(pKmsName+key);
  405.         if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  406.             return tmp.trim();
  407.         }
  408.         else {
  409.             pKmsName = javaProperty ? JAVA_KSM_PREFIX_DEPRECATED : ENV_KSM_PREFIX_DEPRECATED;
  410.             tmp = this.reader.getValue_convertEnvProperties(pKmsName+key);
  411.             if(tmp!=null && StringUtils.isNotEmpty(tmp.trim())) {
  412.                 return tmp.trim();
  413.             }
  414.         }
  415.        
  416.         if(this.defaultUnwrapId!=null) {
  417.             return this.defaultUnwrapId;
  418.         }
  419.         else {
  420.             String prefix = javaProperty ? JAVA_PREFIX : ENV_PREFIX;
  421.             throw new UtilsException("("+prefix+key+ERROR_DEFAULT_MODE_NOT_FOUND);
  422.         }
  423.     }
  424.    
  425.     private DriverBYOK getDriverBYOK(String securityId) {
  426.         if(!this.mapDriverSecurity.containsKey(securityId)) {
  427.             initDriverBYOK(securityId);
  428.         }
  429.         return this.mapDriverSecurity.get(securityId);
  430.     }
  431.     private synchronized void initDriverBYOK(String securityId) {
  432.         this.mapDriverSecurity.computeIfAbsent(securityId, k -> new DriverBYOK(this.log, this.securityPolicy, this.securityRemotePolicy,
  433.                 newDynamicMap(), this.checkJmxPrefixOperazioneNonRiuscita));
  434.     }

  435.     private Map<String, Object> newDynamicMap(){
  436.         if(this.dynamicMap==null) {
  437.             initDynamicMap();
  438.         }
  439.         // cro una nuova mappa per non sovrascrivere le varie variabili di input
  440.         Map<String, Object> map = new HashMap<>();
  441.         if(this.dynamicMap!=null && !this.dynamicMap.isEmpty()) {
  442.             map.putAll(this.dynamicMap);
  443.         }
  444.         return map;
  445.     }
  446.     private synchronized void initDynamicMap() {
  447.         if(this.dynamicMap==null) {
  448.             this.dynamicMap = DriverBYOK.buildDynamicMap(this.log);
  449.         }
  450.     }
  451.    
  452.     private Map<String, String> readKmsInputMap(String kmsId) throws UtilsException{
  453.         Map<String, String> map = new HashMap<>();
  454.         Properties p = this.reader.readProperties_convertEnvProperties(getKmsParamPrefixPropertyName(kmsId));
  455.         if(p==null || p.isEmpty()) {
  456.             p = this.reader.readProperties_convertEnvProperties(getKsmParamPrefixPropertyNameDeprecated(kmsId));
  457.         }
  458.         if(p!=null && !p.isEmpty()) {
  459.             for (Map.Entry<Object,Object> entry : p.entrySet()) {
  460.                 if(entry.getKey() instanceof String && entry.getValue() instanceof String) {
  461.                     map.put((String)entry.getKey(), (String)entry.getValue());
  462.                 }
  463.             }
  464.         }
  465.         return map;
  466.     }
  467.     private Map<String, String> getKmsInputMap(String kmsId) {
  468.         if(!this.mapKmsInput.containsKey(kmsId)) {
  469.             initKmsInputMap(kmsId);
  470.         }
  471.         return this.mapKmsInput.get(kmsId);
  472.     }
  473.     private synchronized void initKmsInputMap(String kmsId) {
  474.         this.mapKmsInput.computeIfAbsent(kmsId, k -> {
  475.             try {
  476.                 return readKmsInputMap(kmsId);
  477.             } catch (UtilsException e) {
  478.                 throw new UtilsRuntimeException(e.getMessage(),e);
  479.             }
  480.         });
  481.     }
  482.    
  483.     private String unwrapByKmsId(String value, String kmsId) throws UtilsException {
  484.        
  485.         Map<String, String> inputMap = getKmsInputMap(kmsId);
  486.         BYOKRequestParams params = DriverBYOK.getBYOKRequestParamsByKmsId(kmsId, inputMap, newDynamicMap());
  487.         if(!BYOKMode.UNWRAP.equals(params.getConfig().getMode())) {
  488.             throw new UtilsException("Kms '"+kmsId+"' unusable in unwrap operation");
  489.         }
  490.         BYOKInstance instance = BYOKInstance.newInstance(this.log, params, value.getBytes());
  491.         byte[] unwrappedValue = DriverBYOK.processInstance(instance, this.checkJmxPrefixOperazioneNonRiuscita);
  492.         return new String(unwrappedValue);

  493.     }
  494. }