You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ciphers.cc 2.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "../crypto/test/scoped_types.h"
  20. #include "../ssl/test/scoped_types.h"
  21. #include "internal.h"
  22. bool Ciphers(const std::vector<std::string> &args) {
  23. if (args.size() != 1) {
  24. fprintf(stderr, "Usage: bssl ciphers <cipher suite string>\n");
  25. return false;
  26. }
  27. const std::string &ciphers_string = args.back();
  28. ScopedSSL_CTX ctx(SSL_CTX_new(SSLv23_client_method()));
  29. if (!SSL_CTX_set_cipher_list(ctx.get(), ciphers_string.c_str())) {
  30. fprintf(stderr, "Failed to parse cipher suite config.\n");
  31. ERR_print_errors_fp(stderr);
  32. return false;
  33. }
  34. const struct ssl_cipher_preference_list_st *pref_list = ctx->cipher_list;
  35. STACK_OF(SSL_CIPHER) *ciphers = pref_list->ciphers;
  36. bool last_in_group = false;
  37. for (size_t i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
  38. bool in_group = pref_list->in_group_flags[i];
  39. const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
  40. if (in_group && !last_in_group) {
  41. printf("[\n ");
  42. } else if (last_in_group) {
  43. printf(" ");
  44. }
  45. printf("%s\n", SSL_CIPHER_get_name(cipher));
  46. if (!in_group && last_in_group) {
  47. printf("]\n");
  48. }
  49. last_in_group = in_group;
  50. }
  51. return true;
  52. }