Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 206878 - JSSE ssl provider
Summary: JSSE ssl provider
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: TPTP (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Jonathan West CLA
QA Contact:
URL:
Whiteboard: closed460
Keywords:
Depends on: 195644 215346 216611
Blocks:
  Show dependency tree
 
Reported: 2007-10-19 08:29 EDT by Igor Alelekov CLA
Modified: 2016-05-05 10:52 EDT (History)
7 users (show)

See Also:


Attachments
SetConfig JSSE Changes (6.76 KB, patch)
2008-01-22 20:27 EST, Jonathan West CLA
no flags Details | Diff
Java Side JSSE Patch (18.66 KB, patch)
2008-01-22 20:46 EST, Jonathan West CLA
no flags Details | Diff
Native Side AC Patch (40.00 KB, application/octet-stream)
2008-01-22 22:32 EST, Jonathan West CLA
no flags Details
Native AC JSSE Patch (40.00 KB, patch)
2008-01-22 22:40 EST, Jonathan West CLA
no flags Details | Diff
Patch - Race condition fix to execution framework code (2.33 KB, patch)
2008-01-23 15:04 EST, Jonathan West CLA
igor.alelekov: review+
Details | Diff
Java Side JSSE Patch - 2 (19.24 KB, patch)
2008-01-23 15:55 EST, Jonathan West CLA
no flags Details | Diff
Native AC JSSE Patch - 2 (40.57 KB, patch)
2008-01-23 19:41 EST, Jonathan West CLA
no flags Details | Diff
Java Side JSSE Patch - 3 - Post Review (22.22 KB, patch)
2008-01-24 13:31 EST, Jonathan West CLA
no flags Details | Diff
Race condition fix to exec framework code - Patch 2 (2.65 KB, patch)
2008-01-24 13:34 EST, Jonathan West CLA
no flags Details | Diff
Native AC JSSE Patch - 3 - Post Review (38.08 KB, patch)
2008-01-24 14:24 EST, Jonathan West CLA
no flags Details | Diff
Native AC JSSE Patch 3 - Post Review (36.83 KB, patch)
2008-01-24 14:28 EST, Jonathan West CLA
no flags Details | Diff
Native AC JSSE Patch - 4 - Post Review (36.70 KB, patch)
2008-01-25 11:19 EST, Jonathan West CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Alelekov CLA 2007-10-19 08:29:51 EDT
Implementation of pluggable module for JSSE ssl provider.
Pluggable layer should be supported by the bug #195644.
Comment 1 jkubasta CLA 2007-10-19 11:13:18 EDT
Samson, please add FDD
Comment 2 Paul Slauenwhite CLA 2007-10-21 20:39:14 EDT
Approved by the AG for TPTP 4.4.1 with the following comments:

-See meetings from review call
(http://dev.eclipse.org/mhonarc/lists/tptp-platform-dev/msg02106.html).
Comment 3 Samson Wai CLA 2007-10-22 14:01:07 EDT
Igor. How can the location of the JVM library be passed to the pluggable provider? Can we add a "setNVPair(char* name, char* value)" function to the interface? This way we can pass anything before "init()" is called.
Comment 4 Igor Alelekov CLA 2007-10-22 14:59:09 EDT
Samson, I thought all AC modules should use single embedded JVM.
A mechanism to submit an java job should be provided by AC.
Comment 5 Samson Wai CLA 2007-10-22 15:24:23 EDT
Igor, I don't think we can do that if we want to use a common interface for both JSSE and OpenSSL provider. Furthermore the JVM is currently created in the CCTL. By providing the "setNVPair()" option we can isolate this provider with the CCTL. If later the CCTL/ACTL is being removed, the JSSE provider will still be functional.

Is it true that you are concerning about memory usage? If that's true, I would rather trade off memory for ease of maintainance.
Comment 6 Igor Alelekov CLA 2007-10-23 09:09:37 EDT
Samson, sure we can add any functions you need to the interface.
You solution is reasonable.
But this way implies that second embedded jvm will be launched by AC which will rise up total memory consumption.
Another option could be extracting jvm from the CCTL in a separate module.
And provide all other modules with ability to submit an java job.
Comment 7 Jonathan West CLA 2008-01-22 20:27:37 EST
Created attachment 87588 [details]
SetConfig JSSE Changes
Comment 8 Jonathan West CLA 2008-01-22 20:46:01 EST
Created attachment 87589 [details]
Java Side JSSE Patch
Comment 9 Jonathan West CLA 2008-01-22 22:32:39 EST
Created attachment 87594 [details]
Native Side AC Patch
Comment 10 Jonathan West CLA 2008-01-22 22:40:11 EST
Created attachment 87595 [details]
Native AC JSSE Patch

Bugzilla patch flag applied.
Comment 11 Jonathan West CLA 2008-01-23 15:04:16 EST
Created attachment 87692 [details]
Patch - Race condition fix  to execution framework code

Patch for a race condition in the execution framework's ConnectionImpl class in authenticateUser(...) and processControlMessage(...) methods.

The problem is that the AuthenticateCommand is sent to the agent controller and the response is received and processed by processControlMessage(..) BEFORE authenticateUser calls wait on the authLock. This means that the wait(...) call in authenticateUser is waiting for a notification which has already occurred. This causes a ten second delay, which causes the createConnection() method of AgentControllerFactory to time out and throw the connection exception to the user.

Fix is just a patch to properly synchronize the wait and notify statements.

I discovered this bug during testing of my JSSE pluggable layer, so I've posted the patch here rather than opening a new bug against the execution framework code.
Comment 12 Jonathan West CLA 2008-01-23 15:55:19 EST
Created attachment 87695 [details]
Java Side JSSE Patch - 2

Updated Java Side JSSE Patch:
- Minor tweaks to thread synchronization and SSL context initialization.
Comment 13 Jonathan West CLA 2008-01-23 19:41:31 EST
Created attachment 87718 [details]
Native AC JSSE Patch - 2


Minor Updates:
- Updated debug statements.
- Updated classpath calls to Java provider
Comment 14 Jonathan West CLA 2008-01-23 21:49:52 EST
Igor, can you review the patches?
Comment 15 Igor Alelekov CLA 2008-01-24 02:53:55 EST
(In reply to comment #11)
> Created an attachment (id=87692) [details]
> Patch - Race condition fix  to execution framework code
> Patch for a race condition in the execution framework's ConnectionImpl class in
> authenticateUser(...) and processControlMessage(...) methods.
> The problem is that the AuthenticateCommand is sent to the agent controller and
> the response is received and processed by processControlMessage(..) BEFORE
> authenticateUser calls wait on the authLock. This means that the wait(...) call
> in authenticateUser is waiting for a notification which has already occurred.
> This causes a ten second delay, which causes the createConnection() method of
> AgentControllerFactory to time out and throw the connection exception to the
> user.
> Fix is just a patch to properly synchronize the wait and notify statements.
> I discovered this bug during testing of my JSSE pluggable layer, so I've posted
> the patch here rather than opening a new bug against the execution framework
> code.

Hi Jonathan, the patch is good. Please just make the same changes in synchronization for authentication failure.
Comment 16 Igor Alelekov CLA 2008-01-24 08:41:43 EST
(In reply to comment #13)
> Native AC JSSE Patch - 2

Hi Jonathan, the patch is good, please see my comments below.

- You are resolving java methods each time to call. This is especially expensive in the sslRead() and sslWrite(). Please consider to use global references and its single resolving during module initialization.

- I'd suggest to free arrays, allocated with NewByteArray(), using DeleteLocalRef() call. According to JNI spec., these references "will be freed once the native method returns". You are using Invocation API and your methods never "return" control to the JVM and it seems you are responsible to free the memory.

- I'd suggest to use one call AttachCurrentThread() instead of pair tptpCreateJVM(NULL), tptpGetJNIEnv()

- jsse/tptpCommon.h - I'd suggest to remove this file and use definitions for LOAD_LIBRARY from tptp/tptpCommon.h instead of.

- The file Resource.h seems to be unused

- remove/hide <windows.h> to prevent build problems on Linux

Comment 17 Igor Alelekov CLA 2008-01-24 10:11:26 EST
(In reply to comment #12)
> Java Side JSSE Patch - 2

Hi Jonathan, the patch is good.
I'll send you my minor comments by email.

Comment 18 Igor Alelekov CLA 2008-01-24 10:15:51 EST
(In reply to comment #17)
> (In reply to comment #12)
> > Java Side JSSE Patch - 2
> Hi Jonathan, the patch is good.
> I'll send you my minor comments by email.

Sorry, I have one note:
You are opening a server socket to listen. IMHO user should be informed about failures: port might be busy...
Comment 19 Jonathan West CLA 2008-01-24 13:31:11 EST
Created attachment 87791 [details]
Java Side JSSE Patch - 3 - Post Review

Java side JSSE updated based on review comments:
- Joel and I updated build settings for this plugin.
- Java code now prints an error to the user when ServerSocket cannot listen on the port.
Comment 20 Jonathan West CLA 2008-01-24 13:34:54 EST
Created attachment 87793 [details]
Race condition fix to exec framework code - Patch 2

Minor update based on review comments.
Comment 21 Jonathan West CLA 2008-01-24 14:24:08 EST
Created attachment 87796 [details]
Native AC JSSE Patch - 3 - Post Review

Changes based on Igor's review:
- Cached methodIDs for all native methods 
- DeleteLocalRef is called in nativeRead(..) and nativeWrite(..)  (I made the removal of the local reference explicit, even though detaching from the JVM using the detach JNI call has the same effect)
- Call AttachCurrentThread() instead of pair tptpCreateJVM(NULL), tptpGetJNIEnv()
- Removed windows.h reference, and extraneous VS source files.
Comment 22 Jonathan West CLA 2008-01-24 14:28:20 EST
Created attachment 87797 [details]
Native AC JSSE Patch 3 - Post Review
Comment 23 Jonathan West CLA 2008-01-24 18:18:34 EST
My patches are good to go as soon as the JVM provider (bug 215346) is approved by PMC and checked in.
Comment 24 Igor Alelekov CLA 2008-01-25 03:43:56 EST
(In reply to comment #21)
> Created an attachment (id=87796) [details]
> Native AC JSSE Patch - 3 - Post Review
> Changes based on Igor's review:
> - Cached methodIDs for all native methods 
> - DeleteLocalRef is called in nativeRead(..) and nativeWrite(..)  (I made the
> removal of the local reference explicit, even though detaching from the JVM
> using the detach JNI call has the same effect)
> - Call AttachCurrentThread() instead of pair tptpCreateJVM(NULL),
> tptpGetJNIEnv()
> - Removed windows.h reference, and extraneous VS source files.

OK, you are caching methodIDs. Let's go ahead and don't call FindClass() each time sslRead() and sslWrite() used, since this is unnecessary :)
Comment 25 Igor Alelekov CLA 2008-01-25 04:05:00 EST
(In reply to comment #19)
> Created an attachment (id=87791) [details]
> Jave Side JSSE Patch - 3 - Post Review
> Java side JSSE updated based on review comments:
> - Joel and I updated build settings for this plugin.
> - Java code now prints an error to the user when ServerSocket cannot listen on
> the port.

I agree to check the patch in, since it is working.

But users (and we) can have problems to support it.
AC might be launched as daemon (or Windows service) and error messages to console might be invisible. Problems with keystore file and password are not reported at all.
From other hand, AC implies stopping itself if any Transport Layer has initialization problem. To follow this it is enough to return error code (-1 e.g.). void nativeInit() Java method could return error code to block AC launching in the case of busy port or keys problems.
Later, logging to AC log file could be added using SSL layer built-in log service.
Comment 26 Jonathan West CLA 2008-01-25 10:38:53 EST
> OK, you are caching methodIDs. Let's go ahead and don't call FindClass() each
> time sslRead() and sslWrite() used, since this is unnecessary :)
> 

AFAIK you can't directly cache class IDs, as they're local references which disappear when detachThread is called. This was the way Samson had originally written the code, and that code was unstable. I'll see if I can find a workaround ASAP.

> But users (and we) can have problems to support it.
> AC might be launched as daemon (or Windows service) and error messages to
> console might be invisible. Problems with keystore file and password are not
> reported at all.

Although keystore in particular is auto-generated with a password that doesn't change. Can't imagine we'd have a problem with this unless the user directly tampers with the keystore.

> From other hand, AC implies stopping itself if any Transport Layer has
> initialization problem. To follow this it is enough to return error code (-1
> e.g.). void nativeInit() Java method could return error code to block AC
> launching in the case of busy port or keys problems.
> Later, logging to AC log file could be added using SSL layer built-in log
> service.
> 

Agreed.... with more time there is always more we can do ;). And as you note, the error codes are a reasonable indicator. We'll open a new bug to add better logging to JSSE if support for it will extend into and past 4.5.
Comment 27 Jonathan West CLA 2008-01-25 11:19:56 EST
Created attachment 87877 [details]
Native AC JSSE Patch - 4 - Post Review


Minor patch update based on comment #24 and #26:
- Fortunately there is no need to cache class IDs, as we only need them when we grab the method ID, which IS cached. Code updated to reflect this.
Comment 28 Jonathan West CLA 2008-01-25 11:31:49 EST
Hi Kiryl/Igor, in order to support JSSE in the agent controller we will need to add the jsse.jar and it's pluginconfig.xml file, into the appropriate folders of the agent controller build.

New files/folders are:

/(AC_DIR)/plugins/org.eclipse.tptp.jsse
/(AC_DIR)/plugins/org.eclipse.tptp.jsse/jsse.jar

/(AC_DIR)/plugins/org.eclipse.tptp.jsse/config/
/(AC_DIR)/plugins/org.eclipse.tptp.jsse/config/pluginconfig.xml

Jsse.jar is produced by the build changes in Java Side JSSE patch, and the JAR can be found under \org.eclipse.tptp.platform.agentcontroller(*)\jsse.jar when compiled.

pluginconfig.xml can be found under \org.eclipse.tptp.platform.agentcontroller(*)\jsse-config\pluginconfig.xml.

Thanks!
Comment 29 Jonathan West CLA 2008-01-25 11:56:45 EST
Added text from comment #28 into a separate bug w/ dependency on that bug.
Comment 30 Joel Cayne CLA 2008-01-25 14:39:05 EST
Patches SetConfig JSSE Changes, Java Side JSSE Patch - 3 - Post Review, Race condition fix to exec framework code - Patch 2, and Native AC JSSE Patch - 4 - Post Review checked into HEAD and 4.4.1 branch.
Comment 31 jkubasta CLA 2008-01-27 19:10:15 EST
Resolving as fixed.  Test pass will be used to verify.
Comment 32 Igor Alelekov CLA 2008-01-28 01:43:06 EST
(In reply to comment #26)
> AFAIK you can't directly cache class IDs, as they're local references which
> disappear when detachThread is called. This was the way Samson had originally
> written the code, and that code was unstable. 

JNI provides "Global References" to resove this.
You can get them with NewGlobalRef() call.
Please see JNI specification for details.

Actually, it seems you don't need it here;
Comment 33 Igor Alelekov CLA 2008-01-28 01:47:34 EST
(In reply to comment #28)
> Hi Kiryl/Igor, in order to support JSSE in the agent controller we will need to
> add the jsse.jar and it's pluginconfig.xml file, into the appropriate folders
> of the agent controller build.

Hi Jonathan, Kiryl is resolving this, but it seems Win-64 make file should provided as well.
Comment 34 Paul Slauenwhite CLA 2009-06-30 09:58:37 EDT
As of TPTP 4.6.0, TPTP is in maintenance mode and focusing on improving quality by resolving relevant enhancements/defects and increasing test coverage through test creation, automation, Build Verification Tests (BVTs), and expanded run-time execution. As part of the TPTP Bugzilla housecleaning process (see http://wiki.eclipse.org/Bugzilla_Housecleaning_Processes), this enhancement/defect is verified/closed by the Project Lead since the originator of this enhancement/defect has an inactive Bugzilla account and considered to be fixed. If this enhancement/defect is still unresolved and reproducible in the latest TPTP release (http://www.eclipse.org/tptp/home/downloads/), please re-open.