server_ssl.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. *
  3. * Copyright 2016 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <arpa/inet.h>
  19. #include <string.h>
  20. #include <sys/socket.h>
  21. #include <unistd.h>
  22. #include <openssl/err.h>
  23. #include <openssl/ssl.h>
  24. #include <grpc/grpc.h>
  25. #include <grpc/grpc_security.h>
  26. #include <grpc/support/alloc.h>
  27. #include <grpc/support/log.h>
  28. #include <grpc/support/string_util.h>
  29. #include <grpc/support/sync.h>
  30. #include "src/core/lib/iomgr/load_file.h"
  31. #include "test/core/handshake/server_ssl_common.h"
  32. #include "test/core/util/port.h"
  33. #include "test/core/util/test_config.h"
  34. int main(int argc, char* argv[]) {
  35. grpc::testing::TestEnvironment env(argc, argv);
  36. // Handshake succeeeds when the client supplies the standard ALPN list.
  37. const char* full_alpn_list[] = {"grpc-exp", "h2"};
  38. GPR_ASSERT(server_ssl_test(full_alpn_list, 2, "grpc-exp"));
  39. // Handshake succeeeds when the client supplies only h2 as the ALPN list. This
  40. // covers legacy gRPC clients which don't support grpc-exp.
  41. const char* h2_only_alpn_list[] = {"h2"};
  42. GPR_ASSERT(server_ssl_test(h2_only_alpn_list, 1, "h2"));
  43. // Handshake succeeds when the client supplies superfluous ALPN entries and
  44. // also when h2 precedes gprc-exp.
  45. const char* extra_alpn_list[] = {"foo", "h2", "bar", "grpc-exp"};
  46. GPR_ASSERT(server_ssl_test(extra_alpn_list, 4, "h2"));
  47. // Handshake fails when the client uses a fake protocol as its only ALPN
  48. // preference. This validates the server is correctly validating ALPN
  49. // and sanity checks the server_ssl_test.
  50. const char* fake_alpn_list[] = {"foo"};
  51. GPR_ASSERT(!server_ssl_test(fake_alpn_list, 1, "foo"));
  52. CleanupSslLibrary();
  53. return 0;
  54. }