Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (c) 2015, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <string>
  15. #include <vector>
  16. #include <stdint.h>
  17. #include <stdlib.h>
  18. #include <openssl/ssl.h>
  19. #include "internal.h"
  20. bool Ciphers(const std::vector<std::string> &args) {
  21. if (args.size() != 1) {
  22. fprintf(stderr, "Usage: bssl ciphers <cipher suite string>\n");
  23. return false;
  24. }
  25. const std::string &ciphers_string = args.back();
  26. bssl::UniquePtr<SSL_CTX> ctx(SSL_CTX_new(SSLv23_client_method()));
  27. if (!SSL_CTX_set_strict_cipher_list(ctx.get(), ciphers_string.c_str())) {
  28. fprintf(stderr, "Failed to parse cipher suite config.\n");
  29. ERR_print_errors_fp(stderr);
  30. return false;
  31. }
  32. const struct ssl_cipher_preference_list_st *pref_list = ctx->cipher_list;
  33. STACK_OF(SSL_CIPHER) *ciphers = pref_list->ciphers;
  34. bool last_in_group = false;
  35. for (size_t i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
  36. bool in_group = pref_list->in_group_flags[i];
  37. const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
  38. if (in_group && !last_in_group) {
  39. printf("[\n ");
  40. } else if (last_in_group) {
  41. printf(" ");
  42. }
  43. printf("%s\n", SSL_CIPHER_get_name(cipher));
  44. if (!in_group && last_in_group) {
  45. printf("]\n");
  46. }
  47. last_in_group = in_group;
  48. }
  49. return true;
  50. }