Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/ssl/ssl_text.cc

raw
1 // Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
2 // Copyright 2005 Nokia. All rights reserved.
3 //
4 // SPDX-License-Identifier: Apache-2.0
5 //
6 // Modifications Copyright Amazon.com, Inc. or its affiliates.
7 // SPDX-License-Identifier: Apache-2.0 OR ISC
8
9 #include <openssl/ssl.h>
10
11 #include "internal.h"
12
13
14 int SSL_SESSION_print(BIO *bp, const SSL_SESSION *sess) {
15 if (sess == nullptr) {
16 return 0;
17 }
18
19 bool tls13 = (sess->ssl_version == TLS1_3_VERSION);
20 if (BIO_puts(bp, "SSL-Session:\n") <= 0) {
21 return 0;
22 }
23 if (BIO_printf(bp, " Protocol : %s\n", SSL_SESSION_get_version(sess)) <=
24 0) {
25 return 0;
26 }
27
28 if (sess->cipher != nullptr) {
29 if (BIO_printf(bp, " Cipher : %s\n",
30 ((sess->cipher->name == nullptr) ? "unknown"
31 : sess->cipher->name)) <=
32 0) {
33 return 0;
34 }
35 }
36 if (BIO_puts(bp, " Session-ID: ") <= 0) {
37 return 0;
38 }
39 for (size_t i = 0; i < sess->session_id_length; i++) {
40 if (BIO_printf(bp, "%02X", sess->session_id[i]) <= 0) {
41 return 0;
42 }
43 }
44 if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0) {
45 return 0;
46 }
47 for (size_t i = 0; i < sess->sid_ctx_length; i++) {
48 if (BIO_printf(bp, "%02X", sess->sid_ctx[i]) <= 0) {
49 return 0;
50 }
51 }
52 if (tls13) {
53 if (BIO_puts(bp, "\n Resumption PSK: ") <= 0) {
54 return 0;
55 }
56 } else if (BIO_puts(bp, "\n Master-Key: ") <= 0) {
57 return 0;
58 }
59 for (size_t i = 0; i < sess->secret_length; i++) {
60 if (BIO_printf(bp, "%02X", sess->secret[i]) <= 0) {
61 return 0;
62 }
63 }
64 if (BIO_puts(bp, "\n PSK identity: ") <= 0) {
65 return 0;
66 }
67 if (BIO_printf(
68 bp, "%s",
69 sess->psk_identity.get() ? sess->psk_identity.get() : "None") <= 0) {
70 return 0;
71 }
72
73 if (sess->ticket_lifetime_hint) {
74 if (BIO_printf(bp, "\n TLS session ticket lifetime hint: %u (seconds)",
75 sess->ticket_lifetime_hint) <= 0) {
76 return 0;
77 }
78 }
79 if (!sess->ticket.empty()) {
80 if (BIO_puts(bp, "\n TLS session ticket:\n ") <= 0) {
81 return 0;
82 }
83 for (uint8_t i : sess->ticket) {
84 if (BIO_printf(bp, "%02X", i) <= 0) {
85 return 0;
86 }
87 }
88 }
89
90 if (sess->time != 0) {
91 if (BIO_printf(bp, "\n Start Time: %lld", (long long)sess->time) <= 0) {
92 return 0;
93 }
94 }
95 if (sess->timeout != 0) {
96 if (BIO_printf(bp, "\n Timeout : %u (sec)", sess->timeout) <= 0) {
97 return 0;
98 }
99 }
100 if (BIO_puts(bp, "\n") <= 0) {
101 return 0;
102 }
103
104 if (BIO_puts(bp, " Verify return code: ") <= 0) {
105 return 0;
106 }
107 if (BIO_printf(bp, "%ld (%s)\n", sess->verify_result,
108 X509_verify_cert_error_string(sess->verify_result)) <= 0) {
109 return 0;
110 }
111
112 if (BIO_printf(bp, " Extended master secret: %s\n",
113 sess->extended_master_secret ? "yes" : "no") <= 0) {
114 return 0;
115 }
116
117 if (tls13) {
118 if (BIO_printf(bp, " Max Early Data: %u\n",
119 sess->ticket_max_early_data) <= 0) {
120 return 0;
121 }
122 }
123
124 return 1;
125 }
126