Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 332248

Summary: Buffer changes for future SSL/TLS support
Product: [Modeling] EMF Reporter: Karel Gardas <karel.gardas>
Component: cdo.net4jAssignee: Eike Stepper <stepper>
Status: ASSIGNED --- QA Contact: Eike Stepper <stepper>
Severity: enhancement    
Priority: P3 CC: erwin, saulius.tvarijonas
Version: 4.13   
Target Milestone: ---   
Hardware: PC   
OS: Solaris   
Whiteboard:
Bug Depends on:    
Bug Blocks: 333947    
Attachments:
Description Flags
Net4j buffer changes for Net4j/TLS support
none
Patch v2
none
Net4j TLS support 1st prototype
none
Net4j TLS support 1st prototype version b
none
Net4j TLS support 2nd prototype
none
TLS patch v3 none

Description Karel Gardas CLA 2010-12-09 15:24:46 EST
Build Identifier: I20100608-0911

Hello,
Net4j buffer/ibuffer requires some changes in order to work well with future Net4j/TLS support. As per Eike request I'll attempt to attach patch which implements required changes to this bugreport.

Reproducible: Always
Comment 1 Karel Gardas CLA 2010-12-09 15:25:41 EST
Created attachment 184897 [details]
Net4j buffer changes for Net4j/TLS support
Comment 2 Eike Stepper CLA 2010-12-10 05:17:27 EST
Created attachment 184933 [details]
Patch v2

The two new methods on Buffer look very similar to existing methods. I've tried to consolidate that for the startGetting case. While doing that I noticed that your if blocks differed slightly and I suspect that this was unintentional. Please correct me if I was wrong.
Comment 3 Eike Stepper CLA 2010-12-10 05:42:09 EST
I also started to find potential for consolidation in the other "almost duplicate" method: write() / getBufferForWrite(). I have the feeling that your method name is not good. write() means "write to channel", i.e. read from buffer. I noticed this when I saw your call to byteBuffer.asReadOnlyBuffer() which implies that the result can not be written to. When we clarified these semantics and you confirmed that my first refactoring is working we can see how to refactor the remaining two methods so that they share the complicated IO logic.

Further I'm renaming this bugzilla so that you can use it for the whole TLS feature. The Buffer changes alone are almost impossible to proof correct, hence I#d like to combine these changes with the coming changes for the overall feature.

For the future please make sure that you create patches as *workspace-relative* (not project-relative). That makes it easier to apply them if I don't know what projects will be affected ;-)
Comment 4 Eike Stepper CLA 2010-12-10 05:43:01 EST
BTW. Buffer.java has not been changed after 3.0 SR1. That will make it trivial to port your changes to 4.0 ;-)
Comment 5 Karel Gardas CLA 2010-12-10 07:12:03 EST
(In reply to comment #2)
> Created an attachment (id=184933) [details]
> Patch v2
> 
> The two new methods on Buffer look very similar to existing methods. I've tried
> to consolidate that for the startGetting case. While doing that I noticed that
> your if blocks differed slightly and I suspect that this was unintentional.
> Please correct me if I was wrong.

I'm not sure, but what was exactly issue with my if block? I cannot find any change except that you have done while loop a more robust by also testing for hasRemaining in source buffer...

Anyway your patch is working so I'm curious what exactly was my mistake for review...Thanks!
Comment 6 Karel Gardas CLA 2010-12-10 07:15:28 EST
(In reply to comment #3)
> I also started to find potential for consolidation in the other "almost
> duplicate" method: write() / getBufferForWrite(). I have the feeling that your
> method name is not good. write() means "write to channel", i.e. read from
> buffer. I noticed this when I saw your call to byteBuffer.asReadOnlyBuffer()
> which implies that the result can not be written to. When we clarified these
> semantics and you confirmed that my first refactoring is working we can see how
> to refactor the remaining two methods so that they share the complicated IO
> logic.

getBufferForWrite means -- get real buffer representation which then is able to be written directly w/o any needed buffer preparation like saving channel id into it and such. When such buffer is available I'm able to encrypt it. Anyway if you find better name for it, I'm accepting what you change it to. :-)

> For the future please make sure that you create patches as *workspace-relative*
> (not project-relative). That makes it easier to apply them if I don't know what
> projects will be affected ;-)

Err, I'm simple minded c++/java/cal/haskell programmer using emacs mainly. I'm using eclipse when I just need to write something for it so I'm not so much eclipse power user. Anyway, I've finally found out what do you mean by this workspace-relative. Thanks for insisting on it.
Comment 7 Eike Stepper CLA 2010-12-10 07:21:45 EST
> getBufferForWrite means -- get real buffer representation which then is able to
> be written directly w/o any needed buffer preparation like saving channel id
> into it and such. When such buffer is available I'm able to encrypt it. Anyway
> if you find better name for it, I'm accepting what you change it to. :-)

That's what I expected first and then the name would be fine. But the ByteBuffer you're returning is created by asReadOnlyBuffer() and I doubt that you'll be able to write to it. In addition there seemd to be an unconditional clear() call on the original buffer. Possibly by a misplaced closing bracket of the preceeding if statement.

> > For the future please make sure that you create patches as *workspace-relative*
> > (not project-relative). That makes it easier to apply them if I don't know what
> > projects will be affected ;-)
> 
> Err, I'm simple minded c++/java/cal/haskell programmer using emacs mainly. I'm
> using eclipse when I just need to write something for it so I'm not so much
> eclipse power user. Anyway, I've finally found out what do you mean by this
> workspace-relative. Thanks for insisting on it.

Np. There are so many things in Eclipse that can make our lifes easier :P
Comment 8 Karel Gardas CLA 2010-12-10 07:24:26 EST
(In reply to comment #7)
> > getBufferForWrite means -- get real buffer representation which then is able to
> > be written directly w/o any needed buffer preparation like saving channel id
> > into it and such. When such buffer is available I'm able to encrypt it. Anyway
> > if you find better name for it, I'm accepting what you change it to. :-)
> 
> That's what I expected first and then the name would be fine. But the
> ByteBuffer you're returning is created by asReadOnlyBuffer() and I doubt that
> you'll be able to write to it. In addition there seemd to be an unconditional
> clear() call on the original buffer. Possibly by a misplaced closing bracket of
> the preceeding if statement.

Err, misunderstanding. By buffer for write I mean buffer which will be applied to socket channel write method, i.e. buffer from which we will just read. So I'm not going to write to it at all! Just read it.
Comment 9 Eike Stepper CLA 2010-12-10 07:32:16 EST
I see ;-)
Comment 10 Karel Gardas CLA 2010-12-10 07:37:44 EST
Eike,
what about if I submit *current* stage of TLS support just to let you know better the usage of buffer functions? If you agree, please let me know exactly what to do for easy your work with it. FYI: I do have org.eclipse.net4j.tls project here which is just org.eclipse.net4j.tcp renamed, and where all the TCP strings/names were renamed to TLS. Also the only part I touched IIRC is TLSConnector.java (i.e. former TCPConnector.java). I'm able to do gtar -cjvf for you, but you surely do have eclipse preferred method for this. :-)
Thanks!
PS: the code is still to be clean up from a lot of debugging messages etc. so it looks horrible, but you will get an idea what's needed for this.
Comment 11 Eike Stepper CLA 2010-12-10 07:57:50 EST
I'd appreciate to have a look at your new code. A ZIP would be fine but the best way would be a patch that transforms TCPConnector into the new TLSConnector. Then I could focus on your changes and later we could copy the result into a new bundle. What do you think?
Comment 12 Karel Gardas CLA 2010-12-10 08:37:26 EST
Although this is more work for me now, I 100% agree with you that this is more clean approach so I did it. See attached bzip2ed patch file.
WARNING: this is really prototype for now! Also for testing you will need to create some keystore...
Comment 13 Karel Gardas CLA 2010-12-10 08:38:07 EST
Created attachment 184953 [details]
Net4j TLS support 1st prototype
Comment 14 Eike Stepper CLA 2010-12-11 03:10:54 EST
Okay, this is the right patch format, but please don#t zip it in the future ;-)
Comment 15 Eike Stepper CLA 2010-12-11 03:21:42 EST
I fear that there is another misunderstanding. In your patch you've renamed everything from tcp to tls (project, packages, classes). This way we certainly can not easily see the code changes. Is it possible that you "un-rename" everything so that I can apply the code changes to the original classes you've changed? Only this way I can get an overview of your changes as opposed to all the new state that is probably mostly a copy. This may also be helpful for the legal department that has to review the changes later on.
Comment 16 Eike Stepper CLA 2010-12-11 03:23:56 EST
I think this will be necessary anyway because we already agreed earlier that we probably don't want to create a big copy of the tcp plugin. When your actual changes are obvious we can decide whether to inherit the existing code or to integrate it directly somehow.
Comment 17 Karel Gardas CLA 2010-12-13 09:34:45 EST
(In reply to comment #15)
> I fear that there is another misunderstanding. In your patch you've renamed
> everything from tcp to tls (project, packages, classes). This way we certainly
> can not easily see the code changes. Is it possible that you "un-rename"
> everything so that I can apply the code changes to the original classes you've
> changed? Only this way I can get an overview of your changes as opposed to all
> the new state that is probably mostly a copy. This may also be helpful for the
> legal department that has to review the changes later on.

Hi Eike,
I'm afraid if I rename everything back, then this will not run at all as this will be over-patched by Net4j provided TCP version which is already on version 3.0. Also I would like to point out that the project's choice of VCS which does not support renames is not my fault unfortunately. Anyway if you let me know how to solve this issue I described above I'll do as you like. In the meantime however I came with my own solution: please grab tcp project and rename everything in file/directory names from tcp to tls (and `TCP' to 'TLS'). And then attempt to apply the patch attached (v1b). This is a patch between straight TCP and my TLS implementation where I ignored renames so you will get exact data as you wanted in your last ask. Well, although this is raw patch and not something directly provided/supported by Eclipse. Please let me know your opinion.
Thansk!
Comment 18 Karel Gardas CLA 2010-12-13 09:39:29 EST
Created attachment 185067 [details]
Net4j TLS support 1st prototype version b
Comment 19 Karel Gardas CLA 2010-12-13 09:40:48 EST
(In reply to comment #18)
> Created an attachment (id=185067) [details]
> Net4j TLS support 1st prototype version b

Ah, I also see there were some changes hapenning on tcp project since I kind of branch it. So they are also marked, but you will see them clearly IMHO.

Please let me know what else shall I provide to you to easy the process of review. Thanks! Karel
Comment 20 Eike Stepper CLA 2010-12-18 04:02:10 EST
(In reply to comment #17)
> I'm afraid if I rename everything back, then this will not run at all as this
> will be over-patched by Net4j provided TCP version which is already on version
> 3.0. Also I would like to point out that the project's choice of VCS which does
> not support renames is not my fault unfortunately. Anyway if you let me know how
> to solve this issue I described above I'll do as you like. In the meantime
> however I came with my own solution: please grab tcp project and rename
> everything in file/directory names from tcp to tls (and `TCP' to 'TLS'). And
> then attempt to apply the patch attached (v1b). This is a patch between straight
> TCP and my TLS implementation where I ignored renames so you will get exact data
> as you wanted in your last ask. Well, although this is raw patch and not
> something directly provided/supported by Eclipse. Please let me know your
> opinion.

I tried again to look at your code, but failed. Your latest patch is not a workspace patch. Please have a look at any of the hundreds of patches attached to other bugzillas to see how they look like. Your "patch" for example contains absolute paths from your particular file system. That can't be good.

Further I don't understand what you mean by "as this will be over-patched by Net4j provided TCP version which is already on version 3.0". Am I right that the original tcp code/functionality is not needed while we work on your new tls functionality?

Maybe I completely miss the point, but if I got you right you took the o.e.net4j.tcp bundle, copied it, renamed everything and applied tls specific changes. Copying and renaming was not a good idea because CVS indeed looses the connection ten (and please let's not discuss whose fault it is that we use CVS, we may switch to git in the near future).

I still think the best way is that you 

1) rename everything back to "tcp"
2) transfer the changes to the original tcp bundle (which is CVS connected and eases future compares/patches)
3) create a *workspace* relative patch from the changes in the original tcp bundle

IMHO the only thing that could prevent us from doing that would be that your tls code requires the unmodified tcp bundle (which I doubt from all I know).

Sorry that this turns out to be a hazzle. The best I can do is offer you to do it together via TeamViewer/Skype...
Comment 21 Eike Stepper CLA 2010-12-18 04:04:06 EST
Or, I could even do it alone. Then I'd need the newest snapshot (zip) of your tls bundle from you...
Comment 22 Karel Gardas CLA 2010-12-18 04:18:41 EST
Hi Eike,
OK, I will do as you like, but I'll first finish rehandshake support and only a bit of cleanup of the debugging messages. I also see I still do have some issue with connection closure. Well, I hope I'll bring you what you request for Christmass. :-) I'll contact you next week in case of any troubles with this. Thanks for review attempt!
Comment 23 Eike Stepper CLA 2010-12-18 04:22:23 EST
(In reply to comment #22)
> Hi Eike,
> OK, I will do as you like, but I'll first finish rehandshake support and only a
> bit of cleanup of the debugging messages. I also see I still do have some issue
> with connection closure. Well, I hope I'll bring you what you request for
> Christmass. :-) I'll contact you next week in case of any troubles with this.

Wonderful ;-)

> Thanks for review attempt!

You're welcome!
Comment 24 Karel Gardas CLA 2011-01-07 14:17:26 EST
Created attachment 186301 [details]
Net4j TLS support 2nd prototype

So later than expected, but at least it's here finally. I've renamed back everything from TLS to TCP. As I claimed in the past this no longer (I mean plugin) work since the classes now mixes with original TCP plugin, but at least might be used for your review. Please let me know any suggestion w.r.t. code you have.
Thanks for review! Karel PS: if you like have it running, then please rename all *TCP*.java to *TLS*.java and this should run...
Comment 25 Eike Stepper CLA 2011-01-08 13:52:23 EST
Hi Karel, I just finished a "mechanic" walk-through to make everything comply with our coding standards. It turned out that your only *important* modifications are to TCPConnector.java. If undone all the other changes (tcp->tls renamings mostly). This makes the patch smaller, but more important, we can run all of our CDO tests with the TLS implementation. I'll attach a new patch in a minute. When you create patches in the future make sure you don't include the .project in your patches.

When everything is in a state we consider final I'll take the task to create a separate bundle for it. For now my biggest problem is that the code depends on your file system:

	java.io.FileNotFoundException: \export\home\karel\tmp\cdo-tls-keystore\keystore
	
How can I deal with it for first tests?

Later we need to decide how to pass the needed "secure things" into the connector. I have many more questions/comments. Is it possible that we have a screen sharing session? We use Skype and TeamViewer for this purpose.

BTW. Is this code:

        KeyStore ksTrust = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream("/export/home/karel/tmp/cdo-tls-keystore/keystore"), passphrase);

okay? Shouldn't it be ksTrust.load... ?
Comment 26 Eike Stepper CLA 2011-01-08 13:53:06 EST
Created attachment 186333 [details]
TLS patch v3
Comment 27 Karel Gardas CLA 2011-01-10 04:50:34 EST
(In reply to comment #25)
> Hi Karel, I just finished a "mechanic" walk-through to make everything comply
> with our coding standards. It turned out that your only *important*
> modifications are to TCPConnector.java. If undone all the other changes
> (tcp->tls renamings mostly).

Yes, you are right!

> This makes the patch smaller, but more important,
> we can run all of our CDO tests with the TLS implementation. I'll attach a new
> patch in a minute. When you create patches in the future make sure you don't
> include the .project in your patches.

I don't know what you are talking about. :-)

> When everything is in a state we consider final I'll take the task to create a
> separate bundle for it.

It would be also nice if you suggest how to add "magic" copyright sentence to the file for our changes. Certainly sponsor of those changes would like to have it there...

> For now my biggest problem is that the code depends on
> your file system:
> 
>     java.io.FileNotFoundException:
> \export\home\karel\tmp\cdo-tls-keystore\keystore
> 
> How can I deal with it for first tests?

That's my testing keystore. What you will need is to create your own testing keystore together with testing trust store. The code is there exactly because of your note below. But certainly this might wait till we resolve our architectural questions from the beginning, i.e. how to integrate the stuff? Directly into TCPConnector, or inheriting all TCP stuff or cloning (like I did) etc.
BTW: For tests you will need to use following properties:
-Djavax.net.ssl.trustStore=/export/home/karel/tmp/cdo-tls-keystore/truststore
-Dsun.security.ssl.allowUnsafeRenegotiation=true

The first is for setting the truststore and the second is for allowing rehandshake which is disable in current JDK due to security issue with it, which is to be solved on Sun's side...

> Later we need to decide how to pass the needed "secure things" into the
> connector.

That's exactly the reason things are hardwired now. I would certainly be happy to not have them in this form...

> I have many more questions/comments. Is it possible that we have a
> screen sharing session? We use Skype and TeamViewer for this purpose.
> 
> BTW. Is this code:
> 
>         KeyStore ksTrust = KeyStore.getInstance("JKS");
>         ks.load(new
> FileInputStream("/export/home/karel/tmp/cdo-tls-keystore/keystore"),
> passphrase);
> 
> okay? Shouldn't it be ksTrust.load... ?

Indeed, good catch, but this code is broken in its current form anyway. I wait for reorganization on fixing it, i.e. to have a framework how to pass secure things down to the connector...

Please let me know if you do have any troubles creating your own working keystore/truststore and making everything run. Remember you need to rename everything back to TLS*...

Thanks! Karel
Comment 28 Karel Gardas CLA 2011-01-10 04:55:30 EST
Hi Eike,
sorry for not addressing your skype/teamviewer question. For skype I'm using dedicated M$ laptop, for development I'm using SunOS workstation hence teamviewer is not an option here...Well, I guess I'm right assuming this works only on M$.
Thanks,
Karel
PS: I mean I'm happy to skype with you if this is enough for you.
Comment 29 Eike Stepper CLA 2011-01-10 04:59:36 EST
(In reply to comment #28)
Is it possible that yousetup a CDO 4.0 development environment on your laptop while we're bringing this to an end? Note that we can not add this in 3.0 maintenance anyway.

BTW. there's a linux version of Teamviewer. Not sure if that would help.
Comment 30 Eike Stepper CLA 2011-01-10 05:04:39 EST
(In reply to comment #27)
> > When you create patches in the future make sure you don't
> > include the .project in your patches.
> 
> I don't know what you are talking about. :-)

In your workspace you seem to have renamed the net4j.tcp project (and/or the contained plugin). That leads to a patch generated  that I can not easily apply to the (unrenamed) project. I should have said "make sure that the .project file is not changed" ;-)

> > When everything is in a state we consider final I'll take the task to create a
> > separate bundle for it.
> 
> It would be also nice if you suggest how to add "magic" copyright sentence to
> the file for our changes. Certainly sponsor of those changes would like to have
> it there...

The copyright text is always the same, something like "... Eike Stepper and others.". This has several reasons. But you may and should change or add your name (if you want with a company) to the contributors list. Just have a look at the other sources.

I'll try to make it run with your other suggestions...
Comment 31 Eike Stepper CLA 2011-01-11 02:13:52 EST
I just seem to realize that we have no own bugzilla for the SSLConnector feature. Karel, Can you please file a separate bugzilla? Then we continue from there...
Comment 32 Karel Gardas CLA 2011-01-11 03:24:02 EST
As you requested, here we go: https://bugs.eclipse.org/bugs/show_bug.cgi?id=333947
Comment 33 Eike Stepper CLA 2011-01-11 03:38:25 EST
(In reply to comment #32)
> As you requested, here we go:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=333947

Thanks! I'll copy the patches over...
Comment 34 Eike Stepper CLA 2011-06-23 04:30:33 EDT
Moving all open enhancement requests to 4.1
Comment 35 Eike Stepper CLA 2012-08-14 22:52:09 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 36 Eike Stepper CLA 2013-06-27 04:07:10 EDT
Moving all outstanding enhancements to 4.3
Comment 37 Eike Stepper CLA 2014-08-19 09:25:21 EDT
Moving all open enhancement requests to 4.4
Comment 38 Eike Stepper CLA 2014-08-19 09:36:09 EDT
Moving all open enhancement requests to 4.4
Comment 39 Eike Stepper CLA 2015-07-14 02:11:49 EDT
Moving all open bugzillas to 4.5.
Comment 40 Eike Stepper CLA 2016-07-31 00:54:27 EDT
Moving all unaddressed bugzillas to 4.6.
Comment 41 Eike Stepper CLA 2017-12-28 01:09:44 EST
Moving all open bugs to 4.7
Comment 42 Eike Stepper CLA 2019-11-08 02:07:35 EST
Moving all unresolved issues to version 4.8-
Comment 43 Eike Stepper CLA 2019-12-13 12:49:32 EST
Moving all unresolved issues to version 4.9
Comment 44 Eike Stepper CLA 2020-12-11 10:47:52 EST
Moving to 4.13.