Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'ssl3_get_message()' with 'tls_get_message_body()' #21886

Closed

Conversation

heygauri
Copy link
Contributor

Update commit messages that previously used ssl3_get_message() to now use tls_get_message_body() due to the split into tls_get_message_header and tls_get_message_body in OpenSSL 1.1.0.

Fixes #21582

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Aug 29, 2023
CHANGES.md Outdated
Comment on lines 15565 to 15573
* In ssl3_get_key_exchange (ssl/s3_clnt.c), call ssl3_get_message()
* In ssl3_get_key_exchange (ssl/s3_clnt.c), call tls_get_message_body()
with the same message size as in ssl3_get_certificate_request().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not edit the CHANGES.md as that should reflect the history as of when the concrete change was done and not the current state of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still did not revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry I forgot this one.

ssl/ssl_local.h Outdated Show resolved Hide resolved
@t8m t8m added branch: master Merge to master branch triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly labels Aug 29, 2023
@mattcaswell
Copy link
Member

Note that there are more references that need updating. One in ssl/record/rec_layer_d1.c and one in ssl/record/rec_layer_s3.c

@@ -533,7 +533,7 @@ int ssl_release_record(SSL_CONNECTION *s, TLS_RECORD *rr, size_t length)
* Return up to 'len' payload bytes received in 'type' records.
* 'type' is one of the following:
*
* - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
* - SSL3_RT_HANDSHAKE (when tls_get_message_header calls us)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case its tls_get_message_header or tls_get_message_body (they both make such a call):

int tls_get_message_header(SSL_CONNECTION *s, int *mt)
{
/* s->init_num < SSL3_HM_HEADER_LENGTH */
int skip_message, i;
uint8_t recvd_type;
unsigned char *p;
size_t l, readbytes;
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
p = (unsigned char *)s->init_buf->data;
do {
while (s->init_num < SSL3_HM_HEADER_LENGTH) {
i = ssl->method->ssl_read_bytes(ssl, SSL3_RT_HANDSHAKE, &recvd_type,
&p[s->init_num],
SSL3_HM_HEADER_LENGTH - s->init_num,
0, &readbytes);

and

int tls_get_message_body(SSL_CONNECTION *s, size_t *len)
{
size_t n, readbytes;
unsigned char *p;
int i;
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
if (s->s3.tmp.message_type == SSL3_MT_CHANGE_CIPHER_SPEC) {
/* We've already read everything in */
*len = (unsigned long)s->init_num;
return 1;
}
p = s->init_msg;
n = s->s3.tmp.message_size - s->init_num;
while (n > 0) {
i = ssl->method->ssl_read_bytes(ssl, SSL3_RT_HANDSHAKE, NULL,
&p[s->init_num], n, 0, &readbytes);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah even I was confused at this point. But I thought that since tls_get_message_header is calling the ssl_read_bytes. I can go for it. But honestly I do not see either of them calling "ssl3" to be specific. It might be deep down in the nested calls. I tried looking for it but didnt find much.

sumitra@sumitra:~/opensource/openssl$ git grep 'ssl3_read_bytes' -- .
CHANGES.md: ssl3_read_bytes() found application data while handshake
CHANGES.md: * Fix ssl3_read_bytes (ssl/s3_pkt.c): To ignore messages of unknown
CHANGES.md: A 'peek' parameter has also been added to ssl3_read_bytes, which
doc/man3/ERR_put_error.pod:descriptions. For example, the function ssl3_read_bytes() reports a
ssl/record/rec_layer_s3.c:int ssl3_read_bytes(SSL *ssl, uint8_t type, uint8_t *recvd_type,
ssl/record/record.h:__owur int ssl3_read_bytes(SSL *s, uint8_t type, uint8_t *recvd_type,
ssl/s3_lib.c: * ssl3_read_bytes decided to call s->handshake_func, which called
ssl/s3_lib.c: * ssl3_read_bytes to read handshake data. However, ssl3_read_bytes
ssl/ssl_local.h: ssl3_read_bytes,
ssl/ssl_local.h: ssl3_read_bytes, \

You can see there is no direct call to ssl3_read_bytes anywhere.

PS: I am new to open source. I apologise for the mistakes made.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see there is no direct call to ssl3_read_bytes anywhere.

Ah, yes. That is because the call is made via a function pointer. So, in tls_get_message_header you will see a call to ssl->method->ssl_read_bytes which (in this case) is a function pointer to ssl3_read_bytes.

I apologise for the mistakes made.

There is no need to apologise. We don't expect new contributors to know the details of the source code and I hope our review comments help you learn your way around.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I got it thanks.

I will then mention both the functions tls_get_message_header and tls_get_message_body in the comments.

@@ -170,7 +170,7 @@ static void dtls_unbuffer_record(SSL_CONNECTION *s)
* Return up to 'len' payload bytes received in 'type' records.
* 'type' is one of the following:
*
* - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
* - SSL3_RT_HANDSHAKE (when tls_get_message_header calls us)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I would just delete the text in parens after SSL3_RT_HANDSHAKE. It actually makes no sense any more. This function is called from quite a number of places with the type set to SSL3_RT_HANDSHAKE, and tls_get_message_header isn't one of them (dtsl1_read_bytes is only relevant to DTLS, and tls_get_message_header is only relevant to TLS).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Aug 29, 2023
CHANGES.md Outdated
@@ -4335,7 +4335,7 @@ OpenSSL 1.1.0

*Matt Caswell*

* Excessive allocation of memory in tls_get_message_header() and
* Excessive allocation of memory in ssl3_get_message() and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed back the wrong entry in CHANGES.md to ssl3_get_message....this entry was correctly referring to tls_get_message_header(). You should have changed back the entry on line 15565 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Thanks again!

@@ -533,7 +533,7 @@ int ssl_release_record(SSL_CONNECTION *s, TLS_RECORD *rr, size_t length)
* Return up to 'len' payload bytes received in 'type' records.
* 'type' is one of the following:
*
* - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
* - SSL3_RT_HANDSHAKE (when tls_get_message_header and tls_get_message_body calls us)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please split the line so it is not longer than 80 characters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

CHANGES.md Outdated
@@ -4335,7 +4335,7 @@ OpenSSL 1.1.0

*Matt Caswell*

* Excessive allocation of memory in tls_get_message_header() and
* Excessive allocation of memory in tls_get_message_body() and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahem, this should be kept as is.

Please squash the commits with git rebase -i master and drop all the changes in CHANGES.md. There should not be any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @t8m I've encountered significant issues in the ssl3_to_tls_message_comments branch, leading to a complex situation. Considering this, I'm contemplating creating a new branch and reapplying the changes to ensure a cleaner and more manageable state. Will that be fine?

@@ -533,7 +533,7 @@ int ssl_release_record(SSL_CONNECTION *s, TLS_RECORD *rr, size_t length)
* Return up to 'len' payload bytes received in 'type' records.
* 'type' is one of the following:
*
* - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
* - SSL3_RT_HANDSHAKE (when tls_get_message_header and tls_get_message_body calls us)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a second function makes the subject of the verb "call" plural, so this should be "call us" not "calls us"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Aug 31, 2023
@heygauri heygauri closed this Aug 31, 2023
@heygauri heygauri reopened this Aug 31, 2023
@tom-cosgrove-arm
Copy link
Contributor

@heygauri You need to push your changes to your OpenSSL fork, probably with -f if you've rebased

@heygauri
Copy link
Contributor Author

Hello @tom-cosgrove-arm, I'm considering the idea of creating a new branch and reapplying the changes. Unfortunately, I made quite a mess in the ssl3_to_tls_message_comments branch due to my limited knowledge of the process.

@tom-cosgrove-arm
Copy link
Contributor

Hello @tom-cosgrove-arm, I'm considering the idea of creating a new branch and reapplying the changes. Unfortunately, I made quite a mess in the ssl3_to_tls_message_comments branch due to my limited knowledge of the process.

Yes, that's fine. You can close this PR and create a new one

@tom-cosgrove-arm
Copy link
Contributor

(do note though, that you could delete your local branch with the problems - or rename it to something like ssl3_to_tls_message_comments-bad - then create a new branch with the original name, and git push -f that new branch to your fork)

@heygauri
Copy link
Contributor Author

Hello @tom-cosgrove-arm, I've followed your instructions to delete the local branch and start fresh. I'd like to highlight that I now need to drop or squash some commits based on the feedback from the maintainers. However, I'm encountering an issue: when I perform the rebase using the command "git rebase -i master," my branch seems to change automatically (as shown in the reference below). How can I ensure that the rebase changes are made in the branch "ssl3_to_tls_message_comments"? Your guidance would be appreciated.

sumitra@sumitra:~/opensource/openssl$ git branch

  • (no branch, rebasing ssl3_to_tls_message_comments)
    master
    ssl3_to_tls_message_comments

@tom-cosgrove-arm
Copy link
Contributor

tom-cosgrove-arm commented Aug 31, 2023

Okay, this is what I would do in your situation, including renaming the old branch. There are several ways to do this, some more "git pro user" than this!

I don't know if you need to make more changes, but this should give you something to start afresh from.

First, get onto the master branch

$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Now rename the branch

$ git branch -m ssl3_to_tls_message_comments ssl3_to_tls_message_comments-BAD

Create a new ssl3_to_tls_message_comments branch

$ git checkout -b ssl3_to_tls_message_comments
Switched to a new branch 'ssl3_to_tls_message_comments'

Now, there are four commits in your old branch that I see, with most recent first:

$ git log --oneline -n4 ssl3_to_tls_message_comments-BAD
fa1a5ac595 (ssl3_to_tls_message_comments-BAD) Update accurate function names in CHANGES.md
13b62e2002 Replace ssl3_get_message() with tls_get_message_header() and/or tls_get_message_body()
801621c391 Replace 'ssl3_get_message()' with 'tls_get_message_header()'
f7b2bfbc4f Replace 'ssl3_get_message()' with 'tls_get_message_body()'

Depending what you've done, the commit IDs you have might be different.

We don't want the most recent commit, as it only touches CHANGES.md, but we'll bring the other commits, from oldest to newest (i.e. in the opposite order to that from git log), into our clean branch with cherry-pick. Remember, we changed back to master, then created a new branch, so the code is just what was in master.

$ git cherry-pick f7b2bfbc4f
Auto-merging ssl/ssl_local.h
Auto-merging CHANGES.md
[ssl3_to_tls_message_comments c22ecd3a9e] Replace 'ssl3_get_message()' with 'tls_get_message_body()'
 Author: Sumitra Sharma <sumitraartsy@gmail.com>
 Date: Tue Aug 29 16:02:47 2023 +0530
 2 files changed, 2 insertions(+), 2 deletions(-)

$ git cherry-pick 801621c391
Auto-merging ssl/ssl_local.h
[ssl3_to_tls_message_comments 77115561ba] Replace 'ssl3_get_message()' with 'tls_get_message_header()'
 Author: Sumitra Sharma <sumitraartsy@gmail.com>
 Date: Tue Aug 29 18:16:11 2023 +0530
 3 files changed, 3 insertions(+), 3 deletions(-)

$ git cherry-pick 13b62e2002
Auto-merging CHANGES.md
[ssl3_to_tls_message_comments b1d6539bd0] Replace ssl3_get_message() with tls_get_message_header() and/or tls_get_message_body()
 Author: Sumitra Sharma <sumitraartsy@gmail.com>
 Date: Tue Aug 29 20:37:21 2023 +0530
 3 files changed, 3 insertions(+), 3 deletions(-)

Now, we need the commit message. I'm going to snag it from the most recent commit and put it into a file called /tmp/message, but you might want to rewrite it

$ git show | head -15 | tail -11 | sed 's/^  *//' | tee /tmp/message
Replace ssl3_get_message() with tls_get_message_header() and/or tls_get_message_body()

Update commit messages that previously used ssl3_get_message()
to now use tls_get_message_header() and tls_get_message_body()
due to the split in OpenSSL 1.1.0.

CLA: trivial

Fixes #21582

Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>

Now, use git reset to wind back this branch pointer, but keep the changes that we cherry-picked:

$ git reset HEAD~3
Unstaged changes after reset:
M	CHANGES.md
M	ssl/record/rec_layer_d1.c
M	ssl/record/rec_layer_s3.c
M	ssl/ssl_local.h

We don't want to modify CHANGES.md, so restore it

$ git restore CHANGES.md

$ git status
On branch ssl3_to_tls_message_comments
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
	modified:   ssl/record/rec_layer_d1.c
	modified:   ssl/record/rec_layer_s3.c
	modified:   ssl/ssl_local.h

Now we can commit again

$ git commit -F/tmp/message -a
[ssl3_to_tls_message_comments e4a6f2fe12] Replace ssl3_get_message() with tls_get_message_header() and/or tls_get_message_body()
 3 files changed, 3 insertions(+), 3 deletions(-)

and you can use git show to check that you are happy with what you've got, then

$ git push -f origin ssl3_to_tls_message_comments

will replace the ssl3_to_tls_message_comments branch in your fork with what you've done

@tom-cosgrove-arm
Copy link
Contributor

tom-cosgrove-arm commented Aug 31, 2023

(to get out of "(no branch, rebasing ssl3_to_tls_message_comments)" just use git rebase --abort)

@heygauri
Copy link
Contributor Author

heygauri commented Sep 1, 2023

@tom-cosgrove-arm Thank you for the thorough explanation. I've submitted a pull request (PR). Please review it and let me know if there are any concerns or further adjustments needed. Your feedback is highly appreciated.

@tom-cosgrove-arm
Copy link
Contributor

@heygauri It looks like you have merged master on top of the changes you previously had - if you look at the Commit tab you see your four commits from 29 August, then lots from master, then another commit from you. This should just show the commits from you, which is why I suggested re-creating the branch from master and starting afresh with git cherry-pick to take the changes that you want

@heygauri
Copy link
Contributor Author

heygauri commented Sep 1, 2023

Okay. I will redo this.

…et_message_body()

Update commit messages that previously used ssl3_get_message()
to now use tls_get_message_header() and tls_get_message_body()
due to the split in OpenSSL 1.1.0.

CLA: trivial

Fixes openssl#21582

Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
@mattcaswell mattcaswell added approval: review pending This pull request needs review by a committer tests: exempted The PR is exempt from requirements for testing labels Sep 1, 2023
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tom-cosgrove-arm tom-cosgrove-arm removed the approval: review pending This pull request needs review by a committer label Sep 1, 2023
@tom-cosgrove-arm tom-cosgrove-arm added the approval: done This pull request has the required number of approvals label Sep 1, 2023
@github-actions github-actions bot removed the severity: fips change The pull request changes FIPS provider sources label Sep 1, 2023
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Sep 2, 2023
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@hlandau
Copy link
Member

hlandau commented Sep 2, 2023

Merged to master. Thank you.

@hlandau hlandau closed this Sep 2, 2023
openssl-machine pushed a commit that referenced this pull request Sep 2, 2023
…et_message_body()

Update commit messages that previously used ssl3_get_message()
to now use tls_get_message_header() and tls_get_message_body()
due to the split in OpenSSL 1.1.0.

CLA: trivial

Fixes #21582

Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #21886)
@heygauri heygauri deleted the ssl3_to_tls_message_comments branch September 2, 2023 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch tests: exempted The PR is exempt from requirements for testing triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ssl3_get_message() is mentioned in source code comments, but it does not exist
6 participants