Project

General

Profile

6084.diff

Igor Skornyakov, 06/24/2022 05:44 AM

Download (9.88 KB)

View differences:

src/com/goldencode/p2j/main/ServerDriver.java 2022-06-24 09:34:43 +0000
2 2
** Module   : ServerDriver.java
3 3
** Abstract : command line driver for the server
4 4
**
5
** Copyright (c) 2005-2021, Golden Code Development Corporation.
5
** Copyright (c) 2005-2022, Golden Code Development Corporation.
6 6
**
7 7
** -#- -I- --Date-- --JPRM-- ----------------------------------Description-----------------------------------
8 8
** 001 NVS 20050418   @20786 Repackaging net package. This file has been created as a
......
54 54
**     IAS 20210827          Added BouncyCastle JCE/JSSE support
55 55
**     GES 20210827          Added driver name initialization and diagnostics output.
56 56
**     OM  20210923          Added -profile command line option for specifying the configuration profile.
57
**     IAS 20220624          Added support for the Conscript JCE/JSSE provider
57 58
*/
58 59

  
59 60
/*
......
460 461
   protected void start(BootstrapConfig bc)
461 462
   throws Exception
462 463
   {
463
      if (bc.getBoolean("security", "bouncycastle", "use", false) && BCProbe.bcFound)
464
      String provider = bc.getConfigItem("security", "provider", "name");
465
      if (provider == null)
466
      {
467
      }
468
      else if ("bouncycastle".equals(provider) && BCProbe.bcFound)
464 469
      {
465 470
         Security.insertProviderAt(BCHolder.JCE, 1);
466 471
         Security.insertProviderAt(BCHolder.JSSE, 2);
......
475 480
            e.printStackTrace();
476 481
         }
477 482
      }
483
      else if ("conscrypt".equals(provider) && CSProbe.csFound)
484
      {
485
         Security.insertProviderAt(CSHolder.SSL, 1);
486
      }
487
      else
488
      {
489
         throw new IllegalStateException("Unknown security provider name: [" + provider + "]");
490
      }
478 491
      
479 492
      boolean single = bc.getBoolean("process", "arch", "single", false);
480 493
      
src/com/goldencode/p2j/net/SSL.java 2022-06-24 09:33:41 +0000
2 2
** Module   : SSL.java
3 3
** Abstract : Implements abstract SSL FSM on the top of SSLEngine. 
4 4
**
5
** Copyright (c) 2016-2021, Golden Code Development Corporation.
5
** Copyright (c) 2016-2022, Golden Code Development Corporation.
6 6
**
7 7
** -#- -I- --Date--  ---------------------------------------Description---------------------------------------
8 8
** 001 IAS 20160805  Initial version
......
11 11
**     IAS 20210323  Re-worked synchronization logic and added logging.
12 12
**     IAS 20210608  Provide more details on the unwrap() failure.
13 13
**     IAS 20210827  Fixed sporadic SSL failures
14
**     IAS 20220624  Added support for the Conscript JCE/JSSE provider
14 15
*/
15 16
/*
16 17
** This program is free software: you can redistribute it and/or modify
......
164 165
    */
165 166
   public SSL(SSLEngine engine, ExecutorService fsmWorkers)
166 167
   {
168
      int delta = engine.getClass().getName().startsWith("org.conscrypt") ? 0 : 50;
167 169
      SSLSession session = engine.getSession();
168 170
      this.appBufferMax = session.getApplicationBufferSize();
169 171
      this.netBufferMax = session.getPacketBufferSize();
170 172
      LOG.log(Level.FINE, String.format("appBufferMax: %d, netBufferMax: %d \n", appBufferMax, netBufferMax));
171
      this.outWrap = ByteBuffer.allocate(appBufferMax + 50);
173
      this.outWrap = ByteBuffer.allocate(appBufferMax + delta);
172 174
      this.inpWrap = ByteBuffer.allocateDirect(appBufferMax + 50);
173 175
      this.outUnwrap = ByteBuffer.allocate(2 * netBufferMax);
174 176
      this.inpUnwrap = ByteBuffer.allocate(2 * netBufferMax);
175 177
      this.outUnwrap.limit(0);
176 178
      this.outUnwrap.limit(0);
177 179

  
178
      this.maxMessageSize = appBufferMax;
180
      this.maxMessageSize = appBufferMax - 50 + delta;
179 181

  
180 182
      this.engine = engine;
181 183
      this.fsmWorkers = fsmWorkers;
......
578 580
            break;
579 581

  
580 582
         case BUFFER_OVERFLOW:
581
            throw new IllegalStateException("failed to wrap");
583
            throw new IllegalStateException("failed to wrap - buffer overflow");
582 584

  
583 585
         case CLOSED:
584 586
            this.onClosed();
......
691 693
            return false;
692 694

  
693 695
         case BUFFER_OVERFLOW:
694
            throw new IllegalStateException("failed to unwrap");
696
            throw new IllegalStateException("failed to unwrap - buffer overflow");
695 697

  
696 698
         case BUFFER_UNDERFLOW:
697 699
            return false;
src/com/goldencode/p2j/net/SessionManager.java 2022-06-24 09:35:27 +0000
2 2
** Module   : SessionManager.java
3 3
** Abstract : Abstract base class for session management
4 4
**
5
** Copyright (c) 2007-2021, Golden Code Development Corporation.
5
** Copyright (c) 2007-2022, Golden Code Development Corporation.
6 6
**
7 7
** -#- -I- --Date-- --JPRM-- ---------------------------Description-------------------------------
8 8
** 001 ECF 20071101   @35865 Created initial version. Abstract base class
......
88 88
**     IAS 20210325          Added NIO configuration via BootstrapConfig
89 89
**     IAS 20210505          Changed exception thrown on failed shutdown. 
90 90
**     IAS 20210827          Added allowed ciphers' filtering
91
**     IAS 20220624          Added support for the configurable JCE/JSSE provider
91 92
*/
92 93

  
93 94
/*
......
1194 1195
          KeyStoreException, 
1195 1196
          UnrecoverableKeyException,
1196 1197
          KeyManagementException,
1197
          ConfigurationException
1198
          ConfigurationException,
1199
          NoSuchProviderException
1198 1200
   {
1199 1201
      // detect if we must use TLS (by default we don't use TLS)
1200 1202
      boolean secure = bc.getBoolean("net", "connection", "secure", false);
src/com/goldencode/p2j/security/SecurityManager.java 2022-06-24 09:34:06 +0000
434 434
**     CA  20220405          Added authentication and authorization for web requests.  When this is enabled, 
435 435
**                           the target API call will be executed under the authenticated FWD context, and not 
436 436
**                           the agent's context.
437
**     IAS 20220624          Added support for the Conscript JCE/JSSE provider
437 438
*/
438 439

  
439 440
/*
......
508 509

  
509 510
import org.bouncycastle.jce.provider.*;
510 511
import org.bouncycastle.jsse.provider.*;
512
import org.conscrypt.*;
511 513

  
512 514
import com.goldencode.expr.*;
513 515
import com.goldencode.p2j.admin.*;
......
786 788
         getSecureSocketContext();
787 789
      } 
788 790
      catch (UnrecoverableKeyException | KeyManagementException | NoSuchAlgorithmException 
789
            | KeyStoreException | ConfigurationException e)
791
            | KeyStoreException | ConfigurationException | NoSuchProviderException e)
790 792
      {
791 793
         throw new ConfigurationException("getSecureSocketContext()", e);
792 794
      }
......
2252 2254
          KeyStoreException, 
2253 2255
          UnrecoverableKeyException,
2254 2256
          KeyManagementException,
2255
          ConfigurationException
2257
          ConfigurationException,
2258
          NoSuchProviderException
2256 2259
   {
2257 2260
      return getSecureSocketContext(cfg);
2258 2261
   }
......
2272 2275
          KeyStoreException, 
2273 2276
          UnrecoverableKeyException,
2274 2277
          KeyManagementException,
2275
          ConfigurationException
2278
          ConfigurationException, 
2279
          NoSuchProviderException
2276 2280
   {
2277 2281
      SSLContext ctx;
2278
      if (config.getBoolean("security", "bouncycastle", "use", false) && BCProbe.bcFound)
2282
      String provider = config.getConfigItem("security", "provider", "name");
2283
      if (provider == null)
2284
      {
2285
         ctx = SSLContext.getInstance("TLS");
2286
      }
2287
      else if ("bouncycastle".equals(provider) && BCProbe.bcFound)
2279 2288
      {
2280 2289
         Security.insertProviderAt(BCHolder.JCE, 1);
2281 2290
         Security.insertProviderAt(BCHolder.JSSE, 2);
2282 2291
         ctx = SSLContext.getInstance("TLS", BCHolder.JSSE);
2283 2292
      }
2293
      else if ("conscrypt".equals(provider) && CSProbe.csFound)
2294
      {
2295
         Security.insertProviderAt(CSHolder.SSL, 1);
2296
         ctx = SSLContext.getInstance("TLS", "Conscrypt");
2297
      }
2284 2298
      else
2285 2299
      {
2286
         ctx = SSLContext.getInstance("TLS");
2300
         throw new IllegalStateException("Unknown security provider name: [" + provider + "]");
2287 2301
      }
2288 2302
      // configure the SSL environment with our custom keys/certs
2289 2303
      TransportSecurity ts = getTransportSecurity(config);
......
9745 9759
   }
9746 9760

  
9747 9761
   /**
9762
    * Conscrypt provider holder. Will be initialized only when referenced.
9763
    */
9764
   public static class CSHolder 
9765
   {
9766
      /** provider */
9767
      public static final Provider SSL = new OpenSSLProvider(); 
9768
   }
9769

  
9770
   /**
9748 9771
    * BouncyCastle presence flag holder holder. Will be initialized only when referenced.
9749 9772
    */
9750 9773
   public static class BCProbe 
......
9776 9799
   }
9777 9800
   
9778 9801
   /**
9802
    * Conscrypt presence flag holder holder. Will be initialized only when referenced.
9803
    */
9804
   public static class CSProbe 
9805
   {
9806
      /** Logger */
9807
      private static final Logger LOG = LogHelper.getLogger(BCProbe.class.getName());
9808
      /** BouncyCastle presence flag */
9809
      public static final boolean csFound = isCSFound();
9810
      
9811
      /**
9812
       * Check if BouncyCastle JCE/JSSE present in the classpath
9813
       * 
9814
       * @return <code>true</code> if BouncyCastle JCE/JSSE found in the classpath 
9815
       */
9816
      private static boolean isCSFound()
9817
      {
9818
         try
9819
         {
9820
            Class.forName("org.conscrypt.OpenSSLProvider");
9821
            return true;
9822
         }
9823
         catch (ClassNotFoundException e)
9824
         {
9825
            LOG.warning("Conscrypt SSL provider not found. Default one will be used");
9826
            return false;
9827
         }
9828
     }
9829
   }
9830

  
9831
   /**
9779 9832
    * A thread inheriting the FWD server context, used to perform authentication and authorization work for
9780 9833
    * web requests.
9781 9834
    */