Skip to content

Create verify_peer_options when creating ssl credentials to support a peer verification callback#15274

Merged
markdroth merged 1 commit intogrpc:masterfrom
JackOfMostTrades:verify-callback-core
Jun 19, 2018
Merged

Create verify_peer_options when creating ssl credentials to support a peer verification callback#15274
markdroth merged 1 commit intogrpc:masterfrom
JackOfMostTrades:verify-callback-core

Conversation

@JackOfMostTrades
Copy link
Copy Markdown
Contributor

This PR is split from #12656 to include just the updates to core components.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                                                      FILE SIZE
 ++++++++++++++ GROWING                                                        ++++++++++++++
  +0.0%    +160 [None]                                                         +1.73Ki  +0.0%
      +0.0%    +160 [Unmapped]                                                     +1.73Ki  +0.0%
      [NEW]     +16 CSWTCH.81                                                          +16  [NEW]
  +3.5%    +344 src/core/lib/security/security_connector/security_connector.cc    +344  +3.5%
      +282%    +336 ssl_channel_check_peer                                            +336  +282%
      +1.3%      +8 grpc_ssl_channel_security_connector_create                          +8  +1.3%
  +1.9%     +48 src/core/lib/security/credentials/ssl/ssl_credentials.cc           +48  +1.9%
      +6.0%     +24 grpc_ssl_credentials_create                                        +24  +6.0%
       +79%     +22 ssl_destruct                                                       +22   +79%
      +1.5%      +2 [Unmapped]                                                          +2  +1.5%

  +0.0%    +552 TOTAL                                                          +2.12Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.2%     +16 src/cpp/client/secure_credentials.cc     +16  +0.2%
      +4.9%     +16 grpc::SslCredentials                     +16  +4.9%

 -------------- SHRINKING                            --------------
  -0.0%     -16 [None]                                    -8  -0.0%

  [ = ]       0 TOTAL                                     +8  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please give proper comments about this struct. Instead of int (*verify_peer_callback)(const char*, const char*, void*), use e.g.,
int (*verify_peer_callback)(const char* target_name, const char* peer_pem, void* userdata)
and explain each parameter and return value.

Also I assume this callback is blocking, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the callback is blocking. I added that clarification (along with a bunch of other detail) to comments.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You probably can make const verify_peer_options* verify_options

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also add a comment about this new parameter.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why add stdbool.h here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leftover from a prior iteration of this changeset. Removed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

s/NULL/nullptr

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

add const to verify_peer_options*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In the case verify_options is nullptr, config->verify_options is uninitialized, it is safer to set memset config->verify_options to nullptr.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You need to run clang-format.
tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You probably want to also include callback_status code in the error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: you need to format this line.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use static_cast<char*>gpr_malloc(p->value.length + 1)

@jiangtaoli2016
Copy link
Copy Markdown

Thanks much @JackOfMostTrades for contribution, a few comments first.

@JackOfMostTrades
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @jiangtaoli2016 ! I've done a first pass at cleanup based on your comments.

Copy link
Copy Markdown

@jiangtaoli2016 jiangtaoli2016 left a comment

Choose a reason for hiding this comment

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

Thanks much for revision. This looks much better. LGTM

@jiangtaoli2016
Copy link
Copy Markdown

@markdroth Please take a look when you have time.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                                                      FILE SIZE
 ++++++++++++++ GROWING                                                        ++++++++++++++
  +0.0%    +224 [None]                                                         +6.45Ki  +0.1%
      +0.0%    +224 [Unmapped]                                                     +6.45Ki  +0.1%
      [NEW]     +16 CSWTCH.82                                                          +16  [NEW]
  +3.8%    +376 src/core/lib/security/security_connector/security_connector.cc    +376  +3.9%
      +309%    +368 ssl_channel_check_peer                                            +368  +309%
      +1.3%      +8 grpc_ssl_channel_security_connector_create                          +8  +1.3%
  +3.8%     +96 src/core/lib/security/credentials/ssl/ssl_credentials.cc           +96  +3.8%
       +16%     +64 grpc_ssl_credentials_create                                        +64   +16%
       +79%     +22 ssl_destruct                                                       +22   +79%
      +7.3%     +10 [Unmapped]                                                         +10  +7.3%

  +0.0%    +696 TOTAL                                                          +6.91Ki  +0.1%


****************************************************************

libgrpc++.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.2%     +16 src/cpp/client/secure_credentials.cc     +16  +0.2%
      +4.9%     +16 grpc::SslCredentials                     +16  +4.9%

 -------------- SHRINKING                            --------------
  -0.0%     -16 [None]                                     0  [ = ]

  [ = ]       0 TOTAL                                    +16  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@markdroth
Copy link
Copy Markdown
Member

Please add a test for this new API.


Reviewed 15 of 22 files at r1, 7 of 7 files at r2.
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@JackOfMostTrades
Copy link
Copy Markdown
Contributor Author

@markdroth I've added a new test verify_peer_options.cc which covers this API, including checking that the expected values get passed through and that the callback return value is respected. Let me know if you have any comments on it.

@markdroth
Copy link
Copy Markdown
Member

Thanks. The test looks pretty good. I have just a couple of minor comments.


Reviewed 8 of 8 files at r3.
Review status: all files reviewed at latest revision, all discussions resolved.


build.yaml, line 2756 at r3 (raw file):

  - linux
  secure: true
- name: handshake_verify_peer_options

Please also add this target to test/core/handshake/BUILD.


test/core/handshake/verify_peer_options.cc, line 203 at r3 (raw file):

                           void* userdata) {
  if (target_host != nullptr) {
    GPR_ASSERT((callback_target_host = static_cast<char*>(

Can use gpr_strdup() here.


test/core/handshake/verify_peer_options.cc, line 208 at r3 (raw file):

  }
  if (target_pem != nullptr) {
    GPR_ASSERT((callback_target_pem = static_cast<char*>(

Same here.


Comments from Reviewable

@JackOfMostTrades
Copy link
Copy Markdown
Contributor Author

Good feedback, thanks. Added a commit with the cleanup.

@markdroth
Copy link
Copy Markdown
Member

This looks great! Please squash your commits, and then we can run the tests and make sure everything is happy.


Reviewed 2 of 2 files at r4.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@JackOfMostTrades
Copy link
Copy Markdown
Contributor Author

Cool, commits squashed and pushed.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                                                      FILE SIZE
 ++++++++++++++ GROWING                                                        ++++++++++++++
  +0.0%    +224 [None]                                                         +6.45Ki  +0.1%
      +0.0%    +224 [Unmapped]                                                     +6.45Ki  +0.1%
      [NEW]     +16 CSWTCH.82                                                          +16  [NEW]
  +3.8%    +376 src/core/lib/security/security_connector/security_connector.cc    +376  +3.9%
      +309%    +368 ssl_channel_check_peer                                            +368  +309%
      +1.3%      +8 grpc_ssl_channel_security_connector_create                          +8  +1.3%
  +3.8%     +96 src/core/lib/security/credentials/ssl/ssl_credentials.cc           +96  +3.8%
       +16%     +64 grpc_ssl_credentials_create                                        +64   +16%
       +79%     +22 ssl_destruct                                                       +22   +79%
      +7.3%     +10 [Unmapped]                                                         +10  +7.3%

  +0.0%    +696 TOTAL                                                          +6.91Ki  +0.1%


****************************************************************

libgrpc++.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.2%     +16 src/cpp/client/secure_credentials.cc     +16  +0.2%
      +4.9%     +16 grpc::SslCredentials                     +16  +4.9%

 -------------- SHRINKING                            --------------
  -0.0%     -16 [None]                                     0  [ = ]

  [ = ]       0 TOTAL                                    +16  +0.0%



@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                                                      FILE SIZE
 ++++++++++++++ GROWING                                                        ++++++++++++++
  +0.0%    +192 [None]                                                         +2.41Ki  +0.0%
      +0.0%    +192 [Unmapped]                                                     +2.41Ki  +0.0%
      [NEW]     +16 CSWTCH.82                                                          +16  [NEW]
  +3.9%    +376 src/core/lib/security/security_connector/security_connector.cc    +376  +3.9%
      +309%    +368 ssl_channel_check_peer                                            +368  +309%
      +1.3%      +8 grpc_ssl_channel_security_connector_create                          +8  +1.3%
  +3.8%     +96 src/core/lib/security/credentials/ssl/ssl_credentials.cc           +96  +3.8%
       +16%     +64 grpc_ssl_credentials_create                                        +64   +16%
       +79%     +22 ssl_destruct                                                       +22   +79%
      +7.3%     +10 [Unmapped]                                                         +10  +7.3%

  +0.0%    +664 TOTAL                                                          +2.88Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.0%     +16 [None]                                     0  [ = ]
  +0.2%     +16 src/cpp/client/secure_credentials.cc     +16  +0.2%
      +4.9%     +16 grpc::SslCredentials                     +16  +4.9%

  +0.0%     +32 TOTAL                                    +16  +0.0%



@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@JackOfMostTrades JackOfMostTrades force-pushed the verify-callback-core branch 2 times, most recently from 9dea026 to 75a36de Compare June 12, 2018 01:26
@JackOfMostTrades
Copy link
Copy Markdown
Contributor Author

The new test looks like it's behaving now, so I've rebased, resolved conflicts, and squashed.

@markdroth
Copy link
Copy Markdown
Member

It looks like your commit is accidentally changing the subproject commit for boringssl and boringssl-with-bazel. Can you please fix that?

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                                                      FILE SIZE
 ++++++++++++++ GROWING                                                        ++++++++++++++
  +0.0%    +192 [None]                                                         +2.41Ki  +0.0%
      +0.0%    +192 [Unmapped]                                                     +2.41Ki  +0.0%
      [NEW]     +16 CSWTCH.82                                                          +16  [NEW]
  +3.9%    +376 src/core/lib/security/security_connector/security_connector.cc    +376  +3.9%
      +309%    +368 ssl_channel_check_peer                                            +368  +309%
      +1.3%      +8 grpc_ssl_channel_security_connector_create                          +8  +1.3%
  +3.8%     +96 src/core/lib/security/credentials/ssl/ssl_credentials.cc           +96  +3.8%
       +16%     +64 grpc_ssl_credentials_create                                        +64   +16%
       +79%     +22 ssl_destruct                                                       +22   +79%
      +7.3%     +10 [Unmapped]                                                         +10  +7.3%

  +0.0%    +664 TOTAL                                                          +2.87Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.2%     +16 src/cpp/client/secure_credentials.cc     +16  +0.2%
      +4.9%     +16 grpc::SslCredentials                     +16  +4.9%

 -------------- SHRINKING                            --------------
  -0.0%     -16 [None]                                     0  [ = ]

  [ = ]       0 TOTAL                                    +16  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

…expose a verification callback option.

These options are not yet exposed to languages outside of core.
@JackOfMostTrades
Copy link
Copy Markdown
Contributor Author

It looks like your commit is accidentally changing the subproject commit for boringssl and boringssl-with-bazel. Can you please fix that?

Oops, fixed that.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                                                      FILE SIZE
 ++++++++++++++ GROWING                                                        ++++++++++++++
  +0.0%    +192 [None]                                                         +2.41Ki  +0.0%
      +0.0%    +192 [Unmapped]                                                     +2.41Ki  +0.0%
      [NEW]     +16 CSWTCH.82                                                          +16  [NEW]
  +3.9%    +376 src/core/lib/security/security_connector/security_connector.cc    +376  +3.9%
      +309%    +368 ssl_channel_check_peer                                            +368  +309%
      +1.3%      +8 grpc_ssl_channel_security_connector_create                          +8  +1.3%
  +3.8%     +96 src/core/lib/security/credentials/ssl/ssl_credentials.cc           +96  +3.8%
       +16%     +64 grpc_ssl_credentials_create                                        +64   +16%
       +79%     +22 ssl_destruct                                                       +22   +79%
      +7.3%     +10 [Unmapped]                                                         +10  +7.3%

  +0.0%    +664 TOTAL                                                          +2.87Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.2%     +16 src/cpp/client/secure_credentials.cc     +16  +0.2%
      +4.9%     +16 grpc::SslCredentials                     +16  +4.9%

 -------------- SHRINKING                            --------------
  -0.0%     -16 [None]                                     0  [ = ]

  [ = ]       0 TOTAL                                    +16  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@markdroth
Copy link
Copy Markdown
Member

Known issues: #15710 #14240

This looks to me, but I'll let @jiangtaoli2016 give final approval.

@jiangtaoli2016
Copy link
Copy Markdown

Looks good to me. Thanks @JackOfMostTrades for contribution.

@jiangtaoli2016
Copy link
Copy Markdown

@markdroth Could you merge?

@markdroth markdroth merged commit 9e3e646 into grpc:master Jun 19, 2018
@srini100 srini100 mentioned this pull request Jun 28, 2018
@markdroth markdroth added the release notes: no Indicates if PR should not be in release notes label Jul 19, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Oct 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants