ciphers.cc
Go to the documentation of this file.
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 
15 #include <string>
16 #include <vector>
17 
18 #include <stdint.h>
19 #include <stdlib.h>
20 
21 #include <openssl/ssl.h>
22 
23 #include "internal.h"
24 
25 
26 bool Ciphers(const std::vector<std::string> &args) {
27  bool openssl_name = false;
28  if (args.size() == 2 && args[0] == "-openssl-name") {
29  openssl_name = true;
30  } else if (args.size() != 1) {
31  fprintf(stderr,
32  "Usage: bssl ciphers [-openssl-name] <cipher suite string>\n");
33  return false;
34  }
35 
36  const std::string &ciphers_string = args.back();
37 
38  bssl::UniquePtr<SSL_CTX> ctx(SSL_CTX_new(TLS_method()));
39  if (!SSL_CTX_set_strict_cipher_list(ctx.get(), ciphers_string.c_str())) {
40  fprintf(stderr, "Failed to parse cipher suite config.\n");
42  return false;
43  }
44 
45  STACK_OF(SSL_CIPHER) *ciphers = SSL_CTX_get_ciphers(ctx.get());
46 
47  bool last_in_group = false;
48  for (size_t i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
49  bool in_group = SSL_CTX_cipher_in_group(ctx.get(), i);
50  const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
51 
52  if (in_group && !last_in_group) {
53  printf("[\n ");
54  } else if (last_in_group) {
55  printf(" ");
56  }
57 
58  printf("%s\n", openssl_name ? SSL_CIPHER_get_name(cipher)
59  : SSL_CIPHER_standard_name(cipher));
60 
61  if (!in_group && last_in_group) {
62  printf("]\n");
63  }
64  last_in_group = in_group;
65  }
66 
67  return true;
68 }
SSL_CTX_cipher_in_group
#define SSL_CTX_cipher_in_group
Definition: boringssl_prefix_symbols.h:75
ssl_cipher_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:520
SSL_CIPHER_get_name
#define SSL_CIPHER_get_name
Definition: boringssl_prefix_symbols.h:53
internal.h
ctx
Definition: benchmark-async.c:30
SSL_CTX_set_strict_cipher_list
#define SSL_CTX_set_strict_cipher_list
Definition: boringssl_prefix_symbols.h:201
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
ERR_print_errors_fp
#define ERR_print_errors_fp
Definition: boringssl_prefix_symbols.h:1437
Ciphers
bool Ciphers(const std::vector< std::string > &args)
Definition: ciphers.cc:26
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
sk_SSL_CIPHER_value
#define sk_SSL_CIPHER_value
Definition: boringssl_prefix_symbols.h:572
python_utils.port_server.stderr
stderr
Definition: port_server.py:51
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
SSL_CTX_new
#define SSL_CTX_new
Definition: boringssl_prefix_symbols.h:115
SSL_CIPHER_standard_name
#define SSL_CIPHER_standard_name
Definition: boringssl_prefix_symbols.h:61
STACK_OF
#define STACK_OF(type)
Definition: stack.h:125
stdint.h
ssl.h
TLS_method
#define TLS_method
Definition: boringssl_prefix_symbols.h:538
sk_SSL_CIPHER_num
#define sk_SSL_CIPHER_num
Definition: boringssl_prefix_symbols.h:570
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
SSL_CTX_get_ciphers
#define SSL_CTX_get_ciphers
Definition: boringssl_prefix_symbols.h:91


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:45