GestoreKeystoreCache.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.security.keystore.cache;

  21. import java.security.cert.X509Certificate;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.List;
  25. import java.util.Map;

  26. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  27. import org.openspcoop2.security.SecurityException;
  28. import org.openspcoop2.security.keystore.BYOKStore;
  29. import org.openspcoop2.security.keystore.CRLCertstore;
  30. import org.openspcoop2.security.keystore.ExternalResource;
  31. import org.openspcoop2.security.keystore.HttpStore;
  32. import org.openspcoop2.security.keystore.JWKSetStore;
  33. import org.openspcoop2.security.keystore.KeyPairStore;
  34. import org.openspcoop2.security.keystore.MerlinKeystore;
  35. import org.openspcoop2.security.keystore.MerlinTruststore;
  36. import org.openspcoop2.security.keystore.MultiKeystore;
  37. import org.openspcoop2.security.keystore.OCSPResponse;
  38. import org.openspcoop2.security.keystore.PublicKeyStore;
  39. import org.openspcoop2.security.keystore.RemoteStore;
  40. import org.openspcoop2.security.keystore.SSLConfigProps;
  41. import org.openspcoop2.security.keystore.SSLSocketFactory;
  42. import org.openspcoop2.security.keystore.SecretKeyStore;
  43. import org.openspcoop2.security.keystore.SecretPasswordKeyDerivationConfig;
  44. import org.openspcoop2.security.keystore.SymmetricKeystore;
  45. import org.openspcoop2.utils.cache.Cache;
  46. import org.openspcoop2.utils.certificate.CertificateInfo;
  47. import org.openspcoop2.utils.certificate.byok.BYOKInstance;
  48. import org.openspcoop2.utils.certificate.byok.BYOKRequestParams;
  49. import org.openspcoop2.utils.certificate.remote.IRemoteStoreProvider;
  50. import org.openspcoop2.utils.certificate.remote.RemoteKeyType;
  51. import org.openspcoop2.utils.certificate.remote.RemoteStoreClientInfo;
  52. import org.openspcoop2.utils.certificate.remote.RemoteStoreConfig;
  53. import org.openspcoop2.utils.transport.http.ExternalResourceConfig;
  54. import org.openspcoop2.utils.transport.http.HttpOptions;
  55. import org.openspcoop2.utils.transport.http.IOCSPValidator;
  56. import org.openspcoop2.utils.transport.http.SSLConfig;

  57. /**
  58.  * GestoreKeystoreCache
  59.  *
  60.  * @author Andrea Poli (apoli@link.it)
  61.  * @author $Author$
  62.  * @version $Rev$, $Date$
  63.  */
  64. public class GestoreKeystoreCache {
  65.    
  66.     private GestoreKeystoreCache() {}

  67.     private static final MerlinTruststoreCache merlinTruststoreCache = new MerlinTruststoreCache();
  68.     private static final MerlinKeystoreCache merlinKeystoreCache = new MerlinKeystoreCache();
  69.     private static final SymmetricKeystoreCache symmetricKeystoreCache = new SymmetricKeystoreCache();
  70.     private static final MultiKeystoreCache multiKeystoreCache = new MultiKeystoreCache();
  71.     private static final JWKSetStoreCache jwkSetStoreCache = new JWKSetStoreCache();
  72.     private static final KeyPairStoreCache keyPairStoreCache = new KeyPairStoreCache();
  73.     private static final PublicKeyStoreCache publicKeyStoreCache = new PublicKeyStoreCache();
  74.     private static final SecretKeyStoreCache secretKeyStoreCache = new SecretKeyStoreCache();
  75.     private static final RemoteStoreCache remoteStoreCache = new RemoteStoreCache();
  76.     private static final RemoteStoreClientInfoCache remoteStoreClientInfoCache = new RemoteStoreClientInfoCache();
  77.     private static final HttpStoreCache httpStoreCache = new HttpStoreCache();
  78.     private static final BYOKStoreCache byokStoreCache = new BYOKStoreCache();
  79.     private static final CRLCertstoreCache crlCertstoreCache = new CRLCertstoreCache();
  80.     private static final SSLSocketFactoryCache sslSocketFactoryCache = new SSLSocketFactoryCache();
  81.     private static final SSLConfigPropsCache sslConfigPropsCache = new SSLConfigPropsCache();
  82.     private static final ExternalResourceCache externalResourceCache = new ExternalResourceCache();
  83.     private static final OCSPResponseCache ocspResponseCache = new OCSPResponseCache();
  84.     private static boolean cacheEnabled = false;
  85.    
  86.     public static void setKeystoreCacheParameters(boolean cacheEnabled,int cacheLifeSecond,int cacheSize){
  87.         GestoreKeystoreCache.cacheEnabled = cacheEnabled;
  88.         GestoreKeystoreCache.merlinTruststoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  89.         GestoreKeystoreCache.merlinKeystoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  90.         GestoreKeystoreCache.symmetricKeystoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  91.         GestoreKeystoreCache.multiKeystoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  92.         GestoreKeystoreCache.jwkSetStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  93.         GestoreKeystoreCache.keyPairStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  94.         GestoreKeystoreCache.publicKeyStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  95.         GestoreKeystoreCache.secretKeyStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  96.         GestoreKeystoreCache.remoteStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  97.         GestoreKeystoreCache.remoteStoreClientInfoCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  98.         GestoreKeystoreCache.httpStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  99.         GestoreKeystoreCache.byokStoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  100.         GestoreKeystoreCache.crlCertstoreCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  101.         GestoreKeystoreCache.sslSocketFactoryCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  102.         GestoreKeystoreCache.sslConfigPropsCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  103.         GestoreKeystoreCache.externalResourceCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  104.         GestoreKeystoreCache.ocspResponseCache.setKeystoreCacheParameters(cacheLifeSecond, cacheSize);
  105.     }
  106.     public static void setKeystoreCacheJCS(boolean cacheEnabled,int cacheLifeSecond, Cache cacheJCS){
  107.         GestoreKeystoreCache.cacheEnabled = cacheEnabled;
  108.         GestoreKeystoreCache.merlinTruststoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  109.         GestoreKeystoreCache.merlinKeystoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  110.         GestoreKeystoreCache.symmetricKeystoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  111.         GestoreKeystoreCache.multiKeystoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  112.         GestoreKeystoreCache.jwkSetStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  113.         GestoreKeystoreCache.keyPairStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  114.         GestoreKeystoreCache.publicKeyStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  115.         GestoreKeystoreCache.secretKeyStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  116.         GestoreKeystoreCache.remoteStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  117.         GestoreKeystoreCache.remoteStoreClientInfoCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  118.         GestoreKeystoreCache.httpStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  119.         GestoreKeystoreCache.byokStoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  120.         GestoreKeystoreCache.crlCertstoreCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  121.         GestoreKeystoreCache.sslSocketFactoryCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  122.         GestoreKeystoreCache.sslConfigPropsCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  123.         GestoreKeystoreCache.externalResourceCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  124.         GestoreKeystoreCache.ocspResponseCache.setCacheJCS(cacheLifeSecond, cacheJCS);
  125.     }
  126.     public static void setKeystoreCacheJCSCrlLifeSeconds(int cacheCrlLifeSecond){
  127.         GestoreKeystoreCache.crlCertstoreCache.updateCacheLifeSecond(cacheCrlLifeSecond);
  128.         GestoreKeystoreCache.ocspResponseCache.updateCacheLifeSecond(cacheCrlLifeSecond);
  129.         GestoreKeystoreCache.externalResourceCache.updateCacheLifeSecond(cacheCrlLifeSecond); // Per adesso utilizzo la stessa impostazione che consente di indicare un tempo minore rispetto al resto della cache
  130.     }
  131.    
  132.    
  133.     public static MerlinTruststore getMerlinTruststore(RequestInfo requestInfo, String propertyFilePath) throws SecurityException{
  134.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && propertyFilePath!=null;
  135.         if(useRequestInfo) {
  136.             Object o = requestInfo.getRequestConfig().getMerlinTruststore(propertyFilePath);
  137.             if(o instanceof MerlinTruststore) {
  138.                 return (MerlinTruststore) o;
  139.             }
  140.         }
  141.         MerlinTruststore t = null;
  142.         if(GestoreKeystoreCache.cacheEnabled)
  143.             t = GestoreKeystoreCache.merlinTruststoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath);
  144.         else
  145.             t = new MerlinTruststore(propertyFilePath);
  146.         if(useRequestInfo) {
  147.             requestInfo.getRequestConfig().addMerlinTruststore(propertyFilePath, t, requestInfo.getIdTransazione());
  148.         }
  149.         return t;
  150.     }
  151.     public static MerlinTruststore getMerlinTruststore(RequestInfo requestInfo, String pathStore,String tipoStore,String passwordStore) throws SecurityException{
  152.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && pathStore!=null;
  153.         if(useRequestInfo) {
  154.             Object o = requestInfo.getRequestConfig().getMerlinTruststore(pathStore);
  155.             if(o instanceof MerlinTruststore) {
  156.                 return (MerlinTruststore) o;
  157.             }
  158.         }
  159.         MerlinTruststore t = null;
  160.         if(GestoreKeystoreCache.cacheEnabled)
  161.             t = GestoreKeystoreCache.merlinTruststoreCache.getKeystoreAndCreateIfNotExists(pathStore, tipoStore, passwordStore);
  162.         else
  163.             t = new MerlinTruststore(pathStore, tipoStore, passwordStore);
  164.         if(useRequestInfo) {
  165.             requestInfo.getRequestConfig().addMerlinTruststore(pathStore, t, requestInfo.getIdTransazione());
  166.         }
  167.         return t;
  168.     }
  169.     public static MerlinTruststore getMerlinTruststore(RequestInfo requestInfo, byte[] bytesStore,String tipoStore,String passwordStore) throws SecurityException{
  170.         String keyParam = null;
  171.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && bytesStore!=null;
  172.         if(useRequestInfo) {
  173.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(bytesStore);
  174.             Object o = requestInfo.getRequestConfig().getMerlinTruststore(keyParam);
  175.             if(o instanceof MerlinTruststore) {
  176.                 return (MerlinTruststore) o;
  177.             }
  178.         }
  179.         MerlinTruststore t = null;
  180.         if(GestoreKeystoreCache.cacheEnabled)
  181.             t = GestoreKeystoreCache.merlinTruststoreCache.getKeystoreAndCreateIfNotExists(bytesStore, tipoStore, passwordStore);
  182.         else
  183.             t = new MerlinTruststore(bytesStore, tipoStore, passwordStore);
  184.         if(useRequestInfo) {
  185.             requestInfo.getRequestConfig().addMerlinTruststore(keyParam, t, requestInfo.getIdTransazione());
  186.         }
  187.         return t;
  188.     }
  189.    
  190.    
  191.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String propertyFilePath) throws SecurityException{
  192.         return getMerlinKeystore(requestInfo, propertyFilePath,
  193.                 (BYOKRequestParams) null);
  194.     }
  195.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String propertyFilePath,
  196.             BYOKRequestParams requestParams) throws SecurityException{
  197.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && propertyFilePath!=null;
  198.         if(useRequestInfo) {
  199.             Object o = requestInfo.getRequestConfig().getMerlinKeystore(propertyFilePath);
  200.             if(o instanceof MerlinKeystore) {
  201.                 return (MerlinKeystore) o;
  202.             }
  203.         }
  204.         MerlinKeystore k = null;
  205.         if(requestParams!=null) {
  206.             if(GestoreKeystoreCache.cacheEnabled)
  207.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath, requestParams);
  208.             else
  209.                 k = new MerlinKeystore(propertyFilePath, requestParams);
  210.         }
  211.         else {
  212.             if(GestoreKeystoreCache.cacheEnabled)
  213.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath);
  214.             else
  215.                 k = new MerlinKeystore(propertyFilePath);
  216.         }
  217.         if(useRequestInfo) {
  218.             requestInfo.getRequestConfig().addMerlinKeystore(propertyFilePath, k, requestInfo.getIdTransazione());
  219.         }
  220.         return k;
  221.     }
  222.    
  223.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String propertyFilePath,String passwordPrivateKey) throws SecurityException{
  224.         return getMerlinKeystore(requestInfo, propertyFilePath, passwordPrivateKey,
  225.                 (BYOKRequestParams) null);
  226.     }
  227.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String propertyFilePath,String passwordPrivateKey,
  228.             BYOKRequestParams requestParams) throws SecurityException{
  229.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && propertyFilePath!=null;
  230.         if(useRequestInfo) {
  231.             Object o = requestInfo.getRequestConfig().getMerlinKeystore(propertyFilePath);
  232.             if(o instanceof MerlinKeystore) {
  233.                 return (MerlinKeystore) o;
  234.             }
  235.         }
  236.         MerlinKeystore k = null;
  237.         if(requestParams!=null) {
  238.             if(GestoreKeystoreCache.cacheEnabled)
  239.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath, passwordPrivateKey, requestParams);
  240.             else
  241.                 k = new MerlinKeystore(propertyFilePath, passwordPrivateKey, requestParams);
  242.         }
  243.         else {
  244.             if(GestoreKeystoreCache.cacheEnabled)
  245.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath, passwordPrivateKey);
  246.             else
  247.                 k = new MerlinKeystore(propertyFilePath, passwordPrivateKey);
  248.         }
  249.         if(useRequestInfo) {
  250.             requestInfo.getRequestConfig().addMerlinKeystore(propertyFilePath, k, requestInfo.getIdTransazione());
  251.         }
  252.         return k;
  253.     }
  254.    
  255.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String pathStore,String tipoStore,String passwordStore) throws SecurityException{
  256.         return getMerlinKeystore(requestInfo, pathStore, tipoStore, passwordStore,
  257.                 (BYOKRequestParams) null);
  258.     }
  259.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String pathStore,String tipoStore,String passwordStore,
  260.             BYOKRequestParams requestParams) throws SecurityException{
  261.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && pathStore!=null;
  262.         if(useRequestInfo) {
  263.             Object o = requestInfo.getRequestConfig().getMerlinKeystore(pathStore);
  264.             if(o instanceof MerlinKeystore) {
  265.                 return (MerlinKeystore) o;
  266.             }
  267.         }
  268.         MerlinKeystore k = null;
  269.         if(requestParams!=null) {
  270.             if(GestoreKeystoreCache.cacheEnabled)
  271.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(pathStore, tipoStore, passwordStore, requestParams);
  272.             else
  273.                 k = new MerlinKeystore(pathStore, tipoStore, passwordStore, requestParams);
  274.         }
  275.         else {
  276.             if(GestoreKeystoreCache.cacheEnabled)
  277.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(pathStore, tipoStore, passwordStore);
  278.             else
  279.                 k = new MerlinKeystore(pathStore, tipoStore, passwordStore);
  280.         }
  281.         if(useRequestInfo) {
  282.             requestInfo.getRequestConfig().addMerlinKeystore(pathStore, k, requestInfo.getIdTransazione());
  283.         }
  284.         return k;
  285.     }
  286.    
  287.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String pathStore,String tipoStore,String passwordStore,String passwordPrivateKey) throws SecurityException{
  288.         return getMerlinKeystore(requestInfo, pathStore, tipoStore, passwordStore, passwordPrivateKey,
  289.                 (BYOKRequestParams) null);
  290.     }
  291.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, String pathStore,String tipoStore,String passwordStore,String passwordPrivateKey,
  292.             BYOKRequestParams requestParams) throws SecurityException{
  293.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && pathStore!=null;
  294.         if(useRequestInfo) {
  295.             Object o = requestInfo.getRequestConfig().getMerlinKeystore(pathStore);
  296.             if(o instanceof MerlinKeystore) {
  297.                 return (MerlinKeystore) o;
  298.             }
  299.         }
  300.         MerlinKeystore k = null;
  301.         if(requestParams!=null) {
  302.             if(GestoreKeystoreCache.cacheEnabled)
  303.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(pathStore, tipoStore, passwordStore, passwordPrivateKey, requestParams);
  304.             else
  305.                 k = new MerlinKeystore(pathStore, tipoStore, passwordStore, passwordPrivateKey, requestParams);
  306.         }
  307.         else {
  308.             if(GestoreKeystoreCache.cacheEnabled)
  309.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(pathStore, tipoStore, passwordStore, passwordPrivateKey);
  310.             else
  311.                 k = new MerlinKeystore(pathStore, tipoStore, passwordStore, passwordPrivateKey);
  312.         }
  313.         if(useRequestInfo) {
  314.             requestInfo.getRequestConfig().addMerlinKeystore(pathStore, k, requestInfo.getIdTransazione());
  315.         }
  316.         return k;
  317.     }
  318.    
  319.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, byte[] bytesStore,String tipoStore,String passwordStore) throws SecurityException{
  320.         return getMerlinKeystore(requestInfo, bytesStore, tipoStore, passwordStore,
  321.                 (BYOKRequestParams) null);
  322.     }
  323.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo, byte[] bytesStore,String tipoStore,String passwordStore,
  324.             BYOKRequestParams requestParams) throws SecurityException{
  325.         String keyParam = null;
  326.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && bytesStore!=null;
  327.         if(useRequestInfo) {
  328.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(bytesStore);
  329.             Object o = requestInfo.getRequestConfig().getMerlinKeystore(keyParam);
  330.             if(o instanceof MerlinKeystore) {
  331.                 return (MerlinKeystore) o;
  332.             }
  333.         }
  334.         MerlinKeystore k = null;
  335.         if(requestParams!=null) {
  336.             if(GestoreKeystoreCache.cacheEnabled)
  337.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(bytesStore, tipoStore, passwordStore, requestParams);
  338.             else
  339.                 k = new MerlinKeystore(bytesStore, tipoStore, passwordStore, requestParams);
  340.         }
  341.         else {
  342.             if(GestoreKeystoreCache.cacheEnabled)
  343.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(bytesStore, tipoStore, passwordStore);
  344.             else
  345.                 k = new MerlinKeystore(bytesStore, tipoStore, passwordStore);
  346.         }
  347.         if(useRequestInfo) {
  348.             requestInfo.getRequestConfig().addMerlinKeystore(keyParam, k, requestInfo.getIdTransazione());
  349.         }
  350.         return k;
  351.     }
  352.    
  353.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo,byte[] bytesStore,String tipoStore,String passwordStore,String passwordPrivateKey) throws SecurityException{
  354.         return getMerlinKeystore(requestInfo, bytesStore, tipoStore, passwordStore,passwordPrivateKey,
  355.                 (BYOKRequestParams) null);
  356.     }
  357.     public static MerlinKeystore getMerlinKeystore(RequestInfo requestInfo,byte[] bytesStore,String tipoStore,String passwordStore,String passwordPrivateKey,
  358.             BYOKRequestParams requestParams) throws SecurityException{
  359.         String keyParam = null;
  360.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && bytesStore!=null;
  361.         if(useRequestInfo) {
  362.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(bytesStore);
  363.             Object o = requestInfo.getRequestConfig().getMerlinKeystore(keyParam);
  364.             if(o instanceof MerlinKeystore) {
  365.                 return (MerlinKeystore) o;
  366.             }
  367.         }
  368.         MerlinKeystore k = null;
  369.         if(requestParams!=null) {
  370.             if(GestoreKeystoreCache.cacheEnabled)
  371.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(bytesStore, tipoStore, passwordStore, passwordPrivateKey, requestParams);
  372.             else
  373.                 k = new MerlinKeystore(bytesStore, tipoStore, passwordStore, passwordPrivateKey, requestParams);
  374.         }
  375.         else {
  376.             if(GestoreKeystoreCache.cacheEnabled)
  377.                 k = GestoreKeystoreCache.merlinKeystoreCache.getKeystoreAndCreateIfNotExists(bytesStore, tipoStore, passwordStore, passwordPrivateKey);
  378.             else
  379.                 k = new MerlinKeystore(bytesStore, tipoStore, passwordStore, passwordPrivateKey);
  380.         }
  381.         if(useRequestInfo) {
  382.             requestInfo.getRequestConfig().addMerlinKeystore(keyParam, k, requestInfo.getIdTransazione());
  383.         }
  384.         return k;
  385.     }
  386.    
  387.    
  388.     public static SymmetricKeystore getSymmetricKeystore(RequestInfo requestInfo, String alias,String key,String algoritmo) throws SecurityException{
  389.         return getSymmetricKeystore(requestInfo, alias, key, algoritmo,
  390.                 (BYOKRequestParams) null);
  391.     }
  392.     public static SymmetricKeystore getSymmetricKeystore(RequestInfo requestInfo, String alias,String key,String algoritmo,
  393.             BYOKRequestParams requestParams) throws SecurityException{
  394.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && key!=null;
  395.         if(useRequestInfo) {
  396.             Object o = requestInfo.getRequestConfig().getSymmetricKeystore(key);
  397.             if(o instanceof SymmetricKeystore) {
  398.                 return (SymmetricKeystore) o;
  399.             }
  400.         }
  401.         SymmetricKeystore k = null;
  402.         if(requestParams!=null) {
  403.             if(GestoreKeystoreCache.cacheEnabled)
  404.                 k = GestoreKeystoreCache.symmetricKeystoreCache.getKeystoreAndCreateIfNotExists(key, alias, algoritmo, requestParams);
  405.             else
  406.                 k = new SymmetricKeystore(alias, key, algoritmo, requestParams);
  407.         }
  408.         else {
  409.             if(GestoreKeystoreCache.cacheEnabled)
  410.                 k = GestoreKeystoreCache.symmetricKeystoreCache.getKeystoreAndCreateIfNotExists(key, alias, algoritmo);
  411.             else
  412.                 k = new SymmetricKeystore(alias, key, algoritmo);
  413.         }
  414.         if(useRequestInfo) {
  415.             requestInfo.getRequestConfig().addSymmetricKeystore(key, k, requestInfo.getIdTransazione());
  416.         }
  417.         return k;
  418.     }
  419.    
  420.    
  421.     public static MultiKeystore getMultiKeystore(RequestInfo requestInfo, String propertyFilePath) throws SecurityException{
  422.         return getMultiKeystore(requestInfo, propertyFilePath,
  423.                 (BYOKRequestParams) null);
  424.     }
  425.     public static MultiKeystore getMultiKeystore(RequestInfo requestInfo, String propertyFilePath,
  426.             BYOKRequestParams requestParams) throws SecurityException{
  427.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && propertyFilePath!=null;
  428.         if(useRequestInfo) {
  429.             Object o = requestInfo.getRequestConfig().getMultiKeystore(propertyFilePath);
  430.             if(o instanceof MultiKeystore) {
  431.                 return (MultiKeystore) o;
  432.             }
  433.         }
  434.         MultiKeystore k = null;
  435.         if(requestParams!=null) {
  436.             if(GestoreKeystoreCache.cacheEnabled)
  437.                 k = GestoreKeystoreCache.multiKeystoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath, requestParams);
  438.             else
  439.                 k = new MultiKeystore(propertyFilePath, requestParams);
  440.         }
  441.         else {
  442.             if(GestoreKeystoreCache.cacheEnabled)
  443.                 k = GestoreKeystoreCache.multiKeystoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath);
  444.             else
  445.                 k = new MultiKeystore(propertyFilePath);
  446.         }
  447.         if(useRequestInfo) {
  448.             requestInfo.getRequestConfig().addMultiKeystore(propertyFilePath, k, requestInfo.getIdTransazione());
  449.         }
  450.         return k;
  451.     }
  452.    
  453.    
  454.     public static JWKSetStore getJwkSetStore(RequestInfo requestInfo, String propertyFilePath) throws SecurityException{
  455.         return getJwkSetStore(requestInfo, propertyFilePath,
  456.                 (BYOKRequestParams) null);
  457.     }
  458.     public static JWKSetStore getJwkSetStore(RequestInfo requestInfo, String propertyFilePath,
  459.             BYOKRequestParams requestParams) throws SecurityException{
  460.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && propertyFilePath!=null;
  461.         if(useRequestInfo) {
  462.             Object o = requestInfo.getRequestConfig().getJWKSetStore(propertyFilePath);
  463.             if(o instanceof JWKSetStore) {
  464.                 return (JWKSetStore) o;
  465.             }
  466.         }
  467.         JWKSetStore k = null;
  468.         if(requestParams!=null) {
  469.             if(GestoreKeystoreCache.cacheEnabled)
  470.                 k = GestoreKeystoreCache.jwkSetStoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath, requestParams);
  471.             else
  472.                 k = new JWKSetStore(propertyFilePath, requestParams);
  473.         }
  474.         else {
  475.             if(GestoreKeystoreCache.cacheEnabled)
  476.                 k = GestoreKeystoreCache.jwkSetStoreCache.getKeystoreAndCreateIfNotExists(propertyFilePath);
  477.             else
  478.                 k = new JWKSetStore(propertyFilePath);
  479.         }
  480.         if(useRequestInfo) {
  481.             requestInfo.getRequestConfig().addJWKSetStore(propertyFilePath, k, requestInfo.getIdTransazione());
  482.         }
  483.         return k;
  484.     }
  485.    
  486.     public static JWKSetStore getJwkSetStore(RequestInfo requestInfo, byte[] archive) throws SecurityException{
  487.         return getJwkSetStore(requestInfo, archive,
  488.                 (BYOKRequestParams) null);
  489.     }
  490.     public static JWKSetStore getJwkSetStore(RequestInfo requestInfo, byte[] archive,
  491.             BYOKRequestParams requestParams) throws SecurityException{
  492.         String keyParam = null;
  493.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && archive!=null;
  494.         if(useRequestInfo) {
  495.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(archive);
  496.             Object o = requestInfo.getRequestConfig().getJWKSetStore(keyParam);
  497.             if(o instanceof JWKSetStore) {
  498.                 return (JWKSetStore) o;
  499.             }
  500.         }
  501.         JWKSetStore k = null;
  502.         if(requestParams!=null) {
  503.             if(GestoreKeystoreCache.cacheEnabled)
  504.                 k = GestoreKeystoreCache.jwkSetStoreCache.getKeystoreAndCreateIfNotExists(archive, requestParams);
  505.             else
  506.                 k = new JWKSetStore(archive, requestParams);
  507.         }
  508.         else {
  509.             if(GestoreKeystoreCache.cacheEnabled)
  510.                 k = GestoreKeystoreCache.jwkSetStoreCache.getKeystoreAndCreateIfNotExists(archive);
  511.             else
  512.                 k = new JWKSetStore(archive);
  513.         }
  514.         if(useRequestInfo) {
  515.             requestInfo.getRequestConfig().addJWKSetStore(keyParam, k, requestInfo.getIdTransazione());
  516.         }
  517.         return k;
  518.     }
  519.    
  520.    
  521.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, String privateKeyPath, String publicKeyPath, String privateKeyPassword, String algorithm) throws SecurityException{
  522.         return getKeyPairStore(requestInfo, privateKeyPath, publicKeyPath, privateKeyPassword, algorithm,
  523.                 (BYOKRequestParams) null);
  524.     }
  525.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, String privateKeyPath, String publicKeyPath, String privateKeyPassword, String algorithm,
  526.             BYOKRequestParams requestParams) throws SecurityException{
  527.         // come chiave di cache si usa solo la chiave privata
  528.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && privateKeyPath!=null;
  529.         if(useRequestInfo) {
  530.             Object o = requestInfo.getRequestConfig().getKeyPairStore(privateKeyPath);
  531.             if(o instanceof KeyPairStore) {
  532.                 return (KeyPairStore) o;
  533.             }
  534.         }
  535.         KeyPairStore k = null;
  536.         if(requestParams!=null) {
  537.             if(GestoreKeystoreCache.cacheEnabled)
  538.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKeyPath, publicKeyPath, privateKeyPassword, algorithm, requestParams);
  539.             else
  540.                 k = new KeyPairStore(privateKeyPath, publicKeyPath, privateKeyPassword, algorithm, requestParams);
  541.         }
  542.         else {
  543.             if(GestoreKeystoreCache.cacheEnabled)
  544.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKeyPath, publicKeyPath, privateKeyPassword, algorithm);
  545.             else
  546.                 k = new KeyPairStore(privateKeyPath, publicKeyPath, privateKeyPassword, algorithm);
  547.         }
  548.         if(useRequestInfo) {
  549.             requestInfo.getRequestConfig().addKeyPairStore(privateKeyPath, k, requestInfo.getIdTransazione());
  550.         }
  551.         return k;
  552.     }
  553.    
  554.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, String privateKeyPath, byte[] publicKey, String privateKeyPassword, String algorithm) throws SecurityException{
  555.         return getKeyPairStore(requestInfo, privateKeyPath, publicKey, privateKeyPassword, algorithm,
  556.                 (BYOKRequestParams) null);
  557.     }
  558.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, String privateKeyPath, byte[] publicKey, String privateKeyPassword, String algorithm,
  559.             BYOKRequestParams requestParams) throws SecurityException{
  560.         // come chiave di cache si usa solo la chiave privata
  561.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && privateKeyPath!=null;
  562.         if(useRequestInfo) {
  563.             Object o = requestInfo.getRequestConfig().getKeyPairStore(privateKeyPath);
  564.             if(o instanceof KeyPairStore) {
  565.                 return (KeyPairStore) o;
  566.             }
  567.         }
  568.         KeyPairStore k = null;
  569.         if(requestParams!=null) {
  570.             if(GestoreKeystoreCache.cacheEnabled)
  571.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKeyPath, publicKey, privateKeyPassword, algorithm, requestParams);
  572.             else
  573.                 k = new KeyPairStore(privateKeyPath, publicKey, privateKeyPassword, algorithm, requestParams);
  574.         }
  575.         else {
  576.             if(GestoreKeystoreCache.cacheEnabled)
  577.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKeyPath, publicKey, privateKeyPassword, algorithm);
  578.             else
  579.                 k = new KeyPairStore(privateKeyPath, publicKey, privateKeyPassword, algorithm);
  580.         }
  581.         if(useRequestInfo) {
  582.             requestInfo.getRequestConfig().addKeyPairStore(privateKeyPath, k, requestInfo.getIdTransazione());
  583.         }
  584.         return k;
  585.     }
  586.    
  587.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, byte[] privateKey, byte[] publicKey, String privateKeyPassword, String algorithm) throws SecurityException{
  588.         return getKeyPairStore(requestInfo, privateKey, publicKey, privateKeyPassword, algorithm,
  589.                 (BYOKRequestParams) null);
  590.     }
  591.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, byte[] privateKey, byte[] publicKey, String privateKeyPassword, String algorithm,
  592.             BYOKRequestParams requestParams) throws SecurityException{
  593.         // come chiave di cache si usa solo la chiave privata
  594.         String keyParam = null;
  595.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && privateKey!=null;
  596.         if(useRequestInfo) {
  597.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(privateKey);
  598.             Object o = requestInfo.getRequestConfig().getKeyPairStore(keyParam);
  599.             if(o instanceof KeyPairStore) {
  600.                 return (KeyPairStore) o;
  601.             }
  602.         }
  603.         KeyPairStore k = null;
  604.         if(requestParams!=null) {
  605.             if(GestoreKeystoreCache.cacheEnabled)
  606.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKey, publicKey, privateKeyPassword, algorithm, requestParams);
  607.             else
  608.                 k = new KeyPairStore(privateKey, publicKey, privateKeyPassword, algorithm, requestParams);
  609.         }
  610.         else {
  611.             if(GestoreKeystoreCache.cacheEnabled)
  612.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKey, publicKey, privateKeyPassword, algorithm);
  613.             else
  614.                 k = new KeyPairStore(privateKey, publicKey, privateKeyPassword, algorithm);
  615.         }
  616.         if(useRequestInfo) {
  617.             requestInfo.getRequestConfig().addKeyPairStore(keyParam, k, requestInfo.getIdTransazione());
  618.         }
  619.         return k;
  620.     }
  621.    
  622.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, byte[] privateKey, String publicKeyPath, String privateKeyPassword, String algorithm) throws SecurityException{
  623.         return getKeyPairStore(requestInfo, privateKey, publicKeyPath, privateKeyPassword, algorithm,
  624.                 (BYOKRequestParams) null);
  625.     }
  626.     public static KeyPairStore getKeyPairStore(RequestInfo requestInfo, byte[] privateKey, String publicKeyPath, String privateKeyPassword, String algorithm,
  627.             BYOKRequestParams requestParams) throws SecurityException{
  628.         // come chiave di cache si usa solo la chiave privata
  629.         String keyParam = null;
  630.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && privateKey!=null;
  631.         if(useRequestInfo) {
  632.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(privateKey);
  633.             Object o = requestInfo.getRequestConfig().getKeyPairStore(keyParam);
  634.             if(o instanceof KeyPairStore) {
  635.                 return (KeyPairStore) o;
  636.             }
  637.         }
  638.         KeyPairStore k = null;
  639.         if(requestParams!=null) {
  640.             if(GestoreKeystoreCache.cacheEnabled)
  641.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKey, publicKeyPath, privateKeyPassword, algorithm, requestParams);
  642.             else
  643.                 k = new KeyPairStore(privateKey, publicKeyPath, privateKeyPassword, algorithm, requestParams);
  644.         }
  645.         else {
  646.             if(GestoreKeystoreCache.cacheEnabled)
  647.                 k = GestoreKeystoreCache.keyPairStoreCache.getKeystoreAndCreateIfNotExists(privateKey, publicKeyPath, privateKeyPassword, algorithm);
  648.             else
  649.                 k = new KeyPairStore(privateKey, publicKeyPath, privateKeyPassword, algorithm);
  650.         }
  651.         if(useRequestInfo) {
  652.             requestInfo.getRequestConfig().addKeyPairStore(keyParam, k, requestInfo.getIdTransazione());
  653.         }
  654.         return k;
  655.     }
  656.    
  657.    
  658.    
  659.     public static PublicKeyStore getPublicKeyStore(RequestInfo requestInfo, String publicKeyPath, String algorithm) throws SecurityException{
  660.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && publicKeyPath!=null;
  661.         if(useRequestInfo) {
  662.             Object o = requestInfo.getRequestConfig().getPublicKeyStore(publicKeyPath);
  663.             if(o instanceof PublicKeyStore) {
  664.                 return (PublicKeyStore) o;
  665.             }
  666.         }
  667.         PublicKeyStore k = null;
  668.         if(GestoreKeystoreCache.cacheEnabled)
  669.             k = GestoreKeystoreCache.publicKeyStoreCache.getKeystoreAndCreateIfNotExists(publicKeyPath, algorithm);
  670.         else
  671.             k = new PublicKeyStore(publicKeyPath, algorithm);
  672.         if(useRequestInfo) {
  673.             requestInfo.getRequestConfig().addPublicKeyStore(publicKeyPath, k, requestInfo.getIdTransazione());
  674.         }
  675.         return k;
  676.     }
  677.     public static PublicKeyStore getPublicKeyStore(RequestInfo requestInfo, byte[] publicKey, String algorithm) throws SecurityException{
  678.         String keyParam = null;
  679.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && publicKey!=null;
  680.         if(useRequestInfo) {
  681.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(publicKey);
  682.             Object o = requestInfo.getRequestConfig().getPublicKeyStore(keyParam);
  683.             if(o instanceof PublicKeyStore) {
  684.                 return (PublicKeyStore) o;
  685.             }
  686.         }
  687.         PublicKeyStore k = null;
  688.         if(GestoreKeystoreCache.cacheEnabled)
  689.             k = GestoreKeystoreCache.publicKeyStoreCache.getKeystoreAndCreateIfNotExists(publicKey, algorithm);
  690.         else
  691.             k = new PublicKeyStore(publicKey, algorithm);
  692.         if(useRequestInfo) {
  693.             requestInfo.getRequestConfig().addPublicKeyStore(keyParam, k, requestInfo.getIdTransazione());
  694.         }
  695.         return k;
  696.     }
  697.    
  698.    
  699.    
  700.    
  701.    
  702.     public static SecretKeyStore getSecretKeyStore(RequestInfo requestInfo, String secretKeyPath, String algorithm) throws SecurityException{
  703.         return getSecretKeyStore(requestInfo, secretKeyPath, algorithm,
  704.                 (BYOKRequestParams) null);
  705.     }
  706.     public static SecretKeyStore getSecretKeyStore(RequestInfo requestInfo, String secretKeyPath, String algorithm,
  707.             BYOKRequestParams requestParams) throws SecurityException{
  708.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && secretKeyPath!=null;
  709.         if(useRequestInfo) {
  710.             Object o = requestInfo.getRequestConfig().getSecretKeyStore(secretKeyPath);
  711.             if(o instanceof SecretKeyStore) {
  712.                 return (SecretKeyStore) o;
  713.             }
  714.         }
  715.         SecretKeyStore k = null;
  716.         if(requestParams!=null) {
  717.             if(GestoreKeystoreCache.cacheEnabled)
  718.                 k = GestoreKeystoreCache.secretKeyStoreCache.getKeystoreAndCreateIfNotExists(secretKeyPath, algorithm, requestParams);
  719.             else
  720.                 k = new SecretKeyStore(secretKeyPath, algorithm, requestParams);
  721.         }
  722.         else {
  723.             if(GestoreKeystoreCache.cacheEnabled)
  724.                 k = GestoreKeystoreCache.secretKeyStoreCache.getKeystoreAndCreateIfNotExists(secretKeyPath, algorithm);
  725.             else
  726.                 k = new SecretKeyStore(secretKeyPath, algorithm);
  727.         }
  728.         if(useRequestInfo) {
  729.             requestInfo.getRequestConfig().addSecretKeyStore(secretKeyPath, k, requestInfo.getIdTransazione());
  730.         }
  731.         return k;
  732.     }
  733.    
  734.     public static SecretKeyStore getSecretKeyStore(RequestInfo requestInfo, byte[] secretKey, String algorithm) throws SecurityException{
  735.         return getSecretKeyStore(requestInfo, secretKey, algorithm,
  736.                 (BYOKRequestParams) null);
  737.     }
  738.     public static SecretKeyStore getSecretKeyStore(RequestInfo requestInfo, byte[] secretKey, String algorithm,
  739.             BYOKRequestParams requestParams) throws SecurityException{
  740.         String keyParam = null;
  741.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && secretKey!=null;
  742.         if(useRequestInfo) {
  743.             keyParam = AbstractKeystoreCache.buildKeyCacheFromBytes(secretKey);
  744.             Object o = requestInfo.getRequestConfig().getSecretKeyStore(keyParam);
  745.             if(o instanceof SecretKeyStore) {
  746.                 return (SecretKeyStore) o;
  747.             }
  748.         }
  749.         SecretKeyStore k = null;
  750.         if(requestParams!=null) {
  751.             if(GestoreKeystoreCache.cacheEnabled)
  752.                 k = GestoreKeystoreCache.secretKeyStoreCache.getKeystoreAndCreateIfNotExists(secretKey, algorithm, requestParams);
  753.             else
  754.                 k = new SecretKeyStore(secretKey, algorithm, requestParams);
  755.         }
  756.         else {
  757.             if(GestoreKeystoreCache.cacheEnabled)
  758.                 k = GestoreKeystoreCache.secretKeyStoreCache.getKeystoreAndCreateIfNotExists(secretKey, algorithm);
  759.             else
  760.                 k = new SecretKeyStore(secretKey, algorithm);
  761.         }
  762.         if(useRequestInfo) {
  763.             requestInfo.getRequestConfig().addSecretKeyStore(keyParam, k, requestInfo.getIdTransazione());
  764.         }
  765.         return k;
  766.     }
  767.    
  768.     public static SecretKeyStore getSecretKeyStore(RequestInfo requestInfo, SecretPasswordKeyDerivationConfig config) throws SecurityException{
  769.         return getSecretKeyStore(requestInfo, config,
  770.                 (BYOKRequestParams) null);
  771.     }
  772.     public static SecretKeyStore getSecretKeyStore(RequestInfo requestInfo, SecretPasswordKeyDerivationConfig config,
  773.             BYOKRequestParams requestParams) throws SecurityException{
  774.         if(config==null) {
  775.             throw new SecurityException("SecretPasswordKeyDerivationConfig param undefined");
  776.         }
  777.         String keyParam = config.toKey();
  778.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && config!=null;
  779.         if(useRequestInfo) {
  780.             Object o = requestInfo.getRequestConfig().getSecretKeyStore(keyParam);
  781.             if(o instanceof SecretKeyStore) {
  782.                 return (SecretKeyStore) o;
  783.             }
  784.         }
  785.         SecretKeyStore k = null;
  786.         if(requestParams!=null) {
  787.             if(GestoreKeystoreCache.cacheEnabled)
  788.                 k = GestoreKeystoreCache.secretKeyStoreCache.getKeystoreAndCreateIfNotExists(keyParam, config, requestParams);
  789.             else
  790.                 k = new SecretKeyStore(config, requestParams);
  791.         }
  792.         else {
  793.             if(GestoreKeystoreCache.cacheEnabled)
  794.                 k = GestoreKeystoreCache.secretKeyStoreCache.getKeystoreAndCreateIfNotExists(keyParam, config);
  795.             else
  796.                 k = new SecretKeyStore(config);
  797.         }
  798.         if(useRequestInfo) {
  799.             requestInfo.getRequestConfig().addSecretKeyStore(keyParam, k, requestInfo.getIdTransazione());
  800.         }
  801.         return k;
  802.     }
  803.    
  804.    
  805.    
  806.    
  807.    
  808.    
  809.     public static RemoteStore getRemoteStore(RequestInfo requestInfo, String keyId, RemoteKeyType keyType, RemoteStoreConfig remoteStoreConfig, IRemoteStoreProvider provider) throws SecurityException{
  810.        
  811.         String keyCache = RemoteStoreCache.getKeyCache(remoteStoreConfig, keyId, keyType);
  812.        
  813.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && keyCache!=null;
  814.         if(useRequestInfo) {
  815.             Object o = requestInfo.getRequestConfig().getRemoteStore(keyCache);
  816.             if(o instanceof RemoteStore) {
  817.                 return (RemoteStore) o;
  818.             }
  819.         }
  820.         RemoteStore k = null;
  821.         if(GestoreKeystoreCache.cacheEnabled)
  822.             k = GestoreKeystoreCache.remoteStoreCache.getKeystoreAndCreateIfNotExists(keyCache, keyId, keyType, remoteStoreConfig, provider);
  823.         else
  824.             k = new RemoteStore(keyId, keyType, remoteStoreConfig, provider);
  825.         if(useRequestInfo) {
  826.             requestInfo.getRequestConfig().addRemoteStore(keyCache, k, requestInfo.getIdTransazione());
  827.         }
  828.         return k;
  829.     }
  830.     public static void removeRemoteStore(RequestInfo requestInfo, String keyId, RemoteKeyType keyType, RemoteStoreConfig remoteStoreConfig) throws SecurityException{
  831.         String keyCache = RemoteStoreCache.getKeyCache(remoteStoreConfig, keyId, keyType);
  832.        
  833.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && keyCache!=null;
  834.         if(useRequestInfo) {
  835.             requestInfo.getRequestConfig().removeRemoteStore(keyCache);
  836.         }
  837.         if(GestoreKeystoreCache.cacheEnabled) {
  838.             GestoreKeystoreCache.remoteStoreCache.removeObjectFromCache(keyCache);
  839.         }
  840.     }
  841.     public static List<String> keysRemoteStore() throws SecurityException{
  842.         List<String> l = null;
  843.         if(GestoreKeystoreCache.cacheEnabled) {
  844.             return GestoreKeystoreCache.remoteStoreCache.keys();
  845.         }
  846.         return l;
  847.     }
  848.    
  849.    
  850.    
  851.    
  852.     public static RemoteStoreClientInfo getRemoteStoreClientInfo(RequestInfo requestInfo, String keyId, String clientId, RemoteStoreConfig remoteStoreConfig, IRemoteStoreProvider provider,
  853.             org.openspcoop2.utils.Map<Object> context) throws SecurityException{
  854.        
  855.         String keyCache = RemoteStoreClientInfoCache.getKeyCache(remoteStoreConfig, keyId);
  856.        
  857.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && keyCache!=null;
  858.         if(useRequestInfo) {
  859.             Object o = requestInfo.getRequestConfig().getRemoteStoreClientInfo(keyCache);
  860.             if(o instanceof RemoteStoreClientInfo) {
  861.                 return (RemoteStoreClientInfo) o;
  862.             }
  863.         }
  864.         org.openspcoop2.security.keystore.RemoteStoreClientInfo k = null;
  865.         if(GestoreKeystoreCache.cacheEnabled)
  866.             k = GestoreKeystoreCache.remoteStoreClientInfoCache.getKeystoreAndCreateIfNotExists(keyCache, keyId, clientId, remoteStoreConfig, provider, context);
  867.         else
  868.             k = new org.openspcoop2.security.keystore.RemoteStoreClientInfo(keyId, clientId, remoteStoreConfig, provider, context);
  869.         if(useRequestInfo) {
  870.             requestInfo.getRequestConfig().addRemoteStoreClientInfo(keyCache, k, requestInfo.getIdTransazione());
  871.         }
  872.         return k.getClientInfo();
  873.     }
  874.     public static void removeRemoteStoreClientInfo(RequestInfo requestInfo, String keyId, RemoteStoreConfig remoteStoreConfig) throws SecurityException{
  875.         String keyCache = RemoteStoreClientInfoCache.getKeyCache(remoteStoreConfig, keyId);
  876.        
  877.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && keyCache!=null;
  878.         if(useRequestInfo) {
  879.             requestInfo.getRequestConfig().removeRemoteStoreClientInfo(keyCache);
  880.         }
  881.         if(GestoreKeystoreCache.cacheEnabled) {
  882.             GestoreKeystoreCache.remoteStoreClientInfoCache.removeObjectFromCache(keyCache);
  883.         }
  884.     }
  885.    
  886.    
  887.    
  888.    
  889.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint,
  890.             HttpOptions ... options) throws SecurityException{
  891.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  892.         if(useRequestInfo) {
  893.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  894.             if(o instanceof HttpStore) {
  895.                 return (HttpStore) o;
  896.             }
  897.         }
  898.         HttpStore k = null;
  899.         if(GestoreKeystoreCache.cacheEnabled) {
  900.             if(options!=null && options.length>0) {
  901.                 List<HttpOptions> list = new ArrayList<>();
  902.                 list.addAll(Arrays.asList(options));
  903.                 k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint,
  904.                         list);
  905.             }
  906.             else {
  907.                 k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint);
  908.             }
  909.         }else
  910.             k = new HttpStore(endpoint,
  911.                     options);
  912.         if(useRequestInfo) {
  913.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  914.         }
  915.         return k;
  916.     }
  917.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint, Integer connectionTimeout, Integer readTimeout,
  918.             HttpOptions ... options) throws SecurityException{
  919.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  920.         if(useRequestInfo) {
  921.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  922.             if(o instanceof HttpStore) {
  923.                 return (HttpStore) o;
  924.             }
  925.         }
  926.         HttpStore k = null;
  927.         if(GestoreKeystoreCache.cacheEnabled)
  928.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint, connectionTimeout, readTimeout,
  929.                     options);
  930.         else
  931.             k = new HttpStore(endpoint, connectionTimeout, readTimeout,
  932.                     options);
  933.         if(useRequestInfo) {
  934.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  935.         }
  936.         return k;
  937.     }
  938.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint, MerlinTruststore trustStoreSsl,
  939.             HttpOptions ... options) throws SecurityException{
  940.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  941.         if(useRequestInfo) {
  942.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  943.             if(o instanceof HttpStore) {
  944.                 return (HttpStore) o;
  945.             }
  946.         }
  947.         HttpStore k = null;
  948.         if(GestoreKeystoreCache.cacheEnabled)
  949.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint, trustStoreSsl,
  950.                     options);
  951.         else
  952.             k = new HttpStore(endpoint, trustStoreSsl,
  953.                     options);
  954.         if(useRequestInfo) {
  955.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  956.         }
  957.         return k;
  958.     }
  959.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint, MerlinTruststore trustStoreSsl, CRLCertstore crlTrustStoreSsl,
  960.             HttpOptions ... options) throws SecurityException{
  961.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  962.         if(useRequestInfo) {
  963.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  964.             if(o instanceof HttpStore) {
  965.                 return (HttpStore) o;
  966.             }
  967.         }
  968.         HttpStore k = null;
  969.         if(GestoreKeystoreCache.cacheEnabled)
  970.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint, trustStoreSsl, crlTrustStoreSsl,
  971.                     options);
  972.         else
  973.             k = new HttpStore(endpoint, trustStoreSsl, crlTrustStoreSsl,
  974.                     options);
  975.         if(useRequestInfo) {
  976.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  977.         }
  978.         return k;
  979.     }
  980.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint,
  981.             Integer connectionTimeout, Integer readTimeout,
  982.             MerlinTruststore trustStoreSsl,
  983.             HttpOptions ... options) throws SecurityException{
  984.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  985.         if(useRequestInfo) {
  986.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  987.             if(o instanceof HttpStore) {
  988.                 return (HttpStore) o;
  989.             }
  990.         }
  991.         HttpStore k = null;
  992.         if(GestoreKeystoreCache.cacheEnabled)
  993.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint,
  994.                     connectionTimeout, readTimeout,
  995.                     trustStoreSsl,
  996.                     options);
  997.         else
  998.             k = new HttpStore(endpoint,
  999.                     connectionTimeout, readTimeout,
  1000.                     trustStoreSsl,
  1001.                     options);
  1002.         if(useRequestInfo) {
  1003.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  1004.         }
  1005.         return k;
  1006.     }
  1007.     public static HttpStore getHttpStore(RequestInfo requestInfo,String endpoint,
  1008.             Integer connectionTimeout, Integer readTimeout,
  1009.             MerlinTruststore trustStoreSsl, CRLCertstore crlTrustStoreSsl,
  1010.             HttpOptions ... options) throws SecurityException{
  1011.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  1012.         if(useRequestInfo) {
  1013.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  1014.             if(o instanceof HttpStore) {
  1015.                 return (HttpStore) o;
  1016.             }
  1017.         }
  1018.         HttpStore k = null;
  1019.         if(GestoreKeystoreCache.cacheEnabled)
  1020.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint,
  1021.                     connectionTimeout, readTimeout,
  1022.                     trustStoreSsl, crlTrustStoreSsl,
  1023.                     options);
  1024.         else
  1025.             k = new HttpStore(endpoint,
  1026.                     connectionTimeout, readTimeout,
  1027.                     trustStoreSsl, crlTrustStoreSsl,
  1028.                     options);
  1029.         if(useRequestInfo) {
  1030.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  1031.         }
  1032.         return k;
  1033.     }
  1034.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint, Boolean trustAll,
  1035.             HttpOptions ... options) throws SecurityException{
  1036.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  1037.         if(useRequestInfo) {
  1038.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  1039.             if(o instanceof HttpStore) {
  1040.                 return (HttpStore) o;
  1041.             }
  1042.         }
  1043.         HttpStore k = null;
  1044.         if(GestoreKeystoreCache.cacheEnabled)
  1045.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint, trustAll,
  1046.                     options);
  1047.         else
  1048.             k = new HttpStore(endpoint, trustAll,
  1049.                     options);
  1050.         if(useRequestInfo) {
  1051.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  1052.         }
  1053.         return k;
  1054.     }
  1055.     public static HttpStore getHttpStore(RequestInfo requestInfo, String endpoint,
  1056.             Integer connectionTimeout, Integer readTimeout,
  1057.             Boolean trustAll,
  1058.             HttpOptions ... options) throws SecurityException{
  1059.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && endpoint!=null;
  1060.         if(useRequestInfo) {
  1061.             Object o = requestInfo.getRequestConfig().getHttpStore(endpoint);
  1062.             if(o instanceof HttpStore) {
  1063.                 return (HttpStore) o;
  1064.             }
  1065.         }
  1066.         HttpStore k = null;
  1067.         if(GestoreKeystoreCache.cacheEnabled)
  1068.             k = GestoreKeystoreCache.httpStoreCache.getKeystoreAndCreateIfNotExists(endpoint,
  1069.                     connectionTimeout, readTimeout,
  1070.                     trustAll,
  1071.                     options);
  1072.         else
  1073.             k = new HttpStore(endpoint,
  1074.                     connectionTimeout, readTimeout,
  1075.                     trustAll,
  1076.                     options);
  1077.         if(useRequestInfo) {
  1078.             requestInfo.getRequestConfig().addHttpStore(endpoint, k, requestInfo.getIdTransazione());
  1079.         }
  1080.         return k;
  1081.     }
  1082.    
  1083.    
  1084.    
  1085.     public static BYOKStore getBYOKStore(RequestInfo requestInfo, BYOKInstance instance) throws SecurityException{
  1086.         if(instance==null) {
  1087.             throw new SecurityException("Instance is null");
  1088.         }
  1089.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && instance!=null && instance.getKeyCache()!=null;
  1090.         if(useRequestInfo) {
  1091.             Object o = requestInfo.getRequestConfig().getBYOKStore(instance.getKeyCache());
  1092.             if(o instanceof BYOKStore) {
  1093.                 return (BYOKStore) o;
  1094.             }
  1095.         }
  1096.         BYOKStore k = null;
  1097.         if(GestoreKeystoreCache.cacheEnabled) {
  1098.             k = GestoreKeystoreCache.byokStoreCache.getKeystoreAndCreateIfNotExists(instance.getKeyCache(), instance);
  1099.         }else
  1100.             k = new BYOKStore(instance.getKeyCache(), instance);
  1101.         if(useRequestInfo) {
  1102.             requestInfo.getRequestConfig().addBYOKStore(instance.getKeyCache(), k, requestInfo.getIdTransazione());
  1103.         }
  1104.         return k;
  1105.     }
  1106.    
  1107.    
  1108.    
  1109.     public static CRLCertstore getCRLCertstore(RequestInfo requestInfo,String crlPath) throws SecurityException{
  1110.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && crlPath!=null;
  1111.         if(useRequestInfo) {
  1112.             Object o = requestInfo.getRequestConfig().getCRLCertstore(crlPath);
  1113.             if(o instanceof CRLCertstore) {
  1114.                 return (CRLCertstore) o;
  1115.             }
  1116.         }
  1117.         CRLCertstore k = null;
  1118.         if(GestoreKeystoreCache.cacheEnabled)
  1119.             k = GestoreKeystoreCache.crlCertstoreCache.getKeystoreAndCreateIfNotExists(crlPath);
  1120.         else
  1121.             k = new CRLCertstore(crlPath);
  1122.         if(useRequestInfo) {
  1123.             requestInfo.getRequestConfig().addCRLCertstore(crlPath, k, requestInfo.getIdTransazione());
  1124.         }
  1125.         return k;
  1126.     }
  1127.     public static CRLCertstore getCRLCertstore(RequestInfo requestInfo,String crlPath, Map<String, byte[]> localResources) throws SecurityException{
  1128.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && crlPath!=null;
  1129.         if(useRequestInfo) {
  1130.             Object o = requestInfo.getRequestConfig().getCRLCertstore(crlPath);
  1131.             if(o instanceof CRLCertstore) {
  1132.                 return (CRLCertstore) o;
  1133.             }
  1134.         }
  1135.         CRLCertstore k = null;
  1136.         if(GestoreKeystoreCache.cacheEnabled)
  1137.             k = GestoreKeystoreCache.crlCertstoreCache.getKeystoreAndCreateIfNotExists(crlPath, localResources);
  1138.         else
  1139.             k = new CRLCertstore(crlPath, localResources);
  1140.         if(useRequestInfo) {
  1141.             requestInfo.getRequestConfig().addCRLCertstore(crlPath, k, requestInfo.getIdTransazione());
  1142.         }
  1143.         return k;
  1144.     }
  1145.    
  1146.     public static SSLSocketFactory getSSLSocketFactory(RequestInfo requestInfo,SSLConfig sslConfig) throws SecurityException{
  1147.         String sslConfigKey = sslConfig.toString();
  1148.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && sslConfigKey!=null;
  1149.         if(useRequestInfo) {
  1150.             Object o = requestInfo.getRequestConfig().getSSLSocketFactory(sslConfigKey);
  1151.             if(o instanceof SSLSocketFactory) {
  1152.                 return (SSLSocketFactory) o;
  1153.             }
  1154.         }
  1155.         SSLSocketFactory k = null;
  1156.         if(GestoreKeystoreCache.cacheEnabled)
  1157.             k = GestoreKeystoreCache.sslSocketFactoryCache.getKeystoreAndCreateIfNotExists(sslConfigKey, requestInfo, sslConfig);
  1158.         else
  1159.             k = new SSLSocketFactory(requestInfo, sslConfig);
  1160.         if(useRequestInfo) {
  1161.             requestInfo.getRequestConfig().addSSLSocketFactory(sslConfigKey, k, requestInfo.getIdTransazione());
  1162.         }
  1163.         return k;  
  1164.     }
  1165.    
  1166.     public static ExternalResource getExternalResource(RequestInfo requestInfo,String resource, ExternalResourceConfig externalConfig) throws SecurityException{
  1167.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && resource!=null;
  1168.         if(useRequestInfo) {
  1169.             Object o = requestInfo.getRequestConfig().getExternalResource(resource);
  1170.             if(o instanceof ExternalResource) {
  1171.                 return (ExternalResource) o;
  1172.             }
  1173.         }
  1174.         ExternalResource k = null;
  1175.         if(GestoreKeystoreCache.cacheEnabled)
  1176.             k = GestoreKeystoreCache.externalResourceCache.getKeystoreAndCreateIfNotExists(resource, externalConfig); // gestito nell'oggetto ExternalResourceCache l'utilizzo della risorsa come id
  1177.         else
  1178.             k = new ExternalResource(resource, resource, externalConfig); // l'id della risorsa esterna รจ la url stessa della risorsa, non serve un id aggiuntivo
  1179.         if(useRequestInfo) {
  1180.             requestInfo.getRequestConfig().addExternalResource(resource, k, requestInfo.getIdTransazione());
  1181.         }
  1182.         return k;
  1183.     }
  1184.    
  1185.     public static SSLConfigProps getSSLConfigProps(RequestInfo requestInfo,String resource, boolean sslConfigRequired) throws SecurityException{
  1186.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null && resource!=null;
  1187.         if(useRequestInfo) {
  1188.             Object o = requestInfo.getRequestConfig().getSSLConfigProps(resource);
  1189.             if(o instanceof SSLConfigProps) {
  1190.                 return (SSLConfigProps) o;
  1191.             }
  1192.         }
  1193.         SSLConfigProps k = null;
  1194.         if(GestoreKeystoreCache.cacheEnabled)
  1195.             k = GestoreKeystoreCache.sslConfigPropsCache.getKeystoreAndCreateIfNotExists(resource, sslConfigRequired);
  1196.         else
  1197.             k = new SSLConfigProps(resource, sslConfigRequired);
  1198.         if(useRequestInfo) {
  1199.             requestInfo.getRequestConfig().addSSLConfigProps(resource, k, requestInfo.getIdTransazione());
  1200.         }
  1201.         return k;
  1202.     }
  1203.    
  1204.     public static OCSPResponse getOCSPResponse(RequestInfo requestInfo,IOCSPValidator ocspValidator, X509Certificate cert) throws SecurityException{
  1205.         if(cert==null) {
  1206.             throw new SecurityException("Certificate is null");
  1207.         }
  1208.         CertificateInfo certInfo = new CertificateInfo(cert, "cer");
  1209.         return getOCSPResponse(requestInfo, ocspValidator, certInfo);
  1210.     }
  1211.     public static OCSPResponse getOCSPResponse(RequestInfo requestInfo,IOCSPValidator ocspValidator, CertificateInfo cert) throws SecurityException{
  1212.         if(cert==null) {
  1213.             throw new SecurityException("Certificate is null");
  1214.         }
  1215.         String pem = null;
  1216.         try {
  1217.             pem = cert.getPEMEncoded();
  1218.         }catch(Exception t) {
  1219.             throw new SecurityException(t.getMessage(),t);
  1220.         }
  1221.         if(pem==null) {
  1222.             throw new SecurityException("Certificate PEM Encoding is null");
  1223.         }
  1224.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  1225.         if(useRequestInfo) {
  1226.             Object o = requestInfo.getRequestConfig().getOCSPResponse(pem);
  1227.             if(o instanceof OCSPResponse) {
  1228.                 return (OCSPResponse) o;
  1229.             }
  1230.         }
  1231.         OCSPResponse k = null;
  1232.         if(GestoreKeystoreCache.cacheEnabled)
  1233.             k = GestoreKeystoreCache.ocspResponseCache.getKeystoreAndCreateIfNotExists(pem, ocspValidator, cert.getCertificate());
  1234.         else
  1235.             k = new OCSPResponse(ocspValidator, cert.getCertificate());
  1236.         if(useRequestInfo) {
  1237.             requestInfo.getRequestConfig().addOCSPResponse(pem, k, requestInfo.getIdTransazione());
  1238.         }
  1239.         return k;
  1240.     }
  1241. }