1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CONSCRYPT_TRACE_H_ 18 #define CONSCRYPT_TRACE_H_ 19 20 #include <stdio.h> 21 #include <cstddef> 22 #include <conscrypt/logging.h> 23 24 namespace conscrypt { 25 namespace trace { 26 27 extern const bool kWithJniTrace; 28 extern const bool kWithJniTraceMd; 29 extern const bool kWithJniTraceData; 30 31 /* 32 * To print create a pcap-style dump you can take the log output and 33 * pipe it through text2pcap. 34 * 35 * For example, if you were interested in ssl=0x12345678, you would do: 36 * 37 * address=0x12345678 38 * awk "match(\$0,/ssl=$address SSL_DATA: (.*)\$/,a){print a[1]}" | text2pcap -T 443,1337 -t 39 * '%s.' -n -D - $address.pcapng 40 */ 41 extern const bool kWithJniTracePackets; 42 43 /* 44 * How to use this for debugging with Wireshark: 45 * 46 * 1. Pull lines from logcat to a file that have "KEY_LINE:" and remove the 47 * prefix up to and including "KEY_LINE: " so they look like this 48 * (without the quotes): 49 * "RSA 3b8...184 1c5...aa0" <CR> 50 * "CLIENT_RANDOM 82e...f18b 1c5...aa0" <CR> 51 * <etc> 52 * Follows the format defined at 53 * https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format 54 * 2. Start Wireshark 55 * 3. Go to Edit -> Preferences -> SSL -> (Pre-)Master-Key log and fill in 56 * the file you put the lines in above. 57 * 4. Follow the stream that corresponds to the desired "Session-ID" in 58 * the Server Hello. 59 */ 60 extern const bool kWithJniTraceKeys; 61 62 // don't overwhelm logcat 63 extern const std::size_t kWithJniTraceDataChunkSize; 64 65 } // namespace trace 66 } // namespace conscrypt 67 68 #define JNI_TRACE(...) \ 69 if (conscrypt::trace::kWithJniTrace) { \ 70 CONSCRYPT_LOG(LOG_INFO, LOG_TAG "-jni", __VA_ARGS__); \ 71 } 72 #define JNI_TRACE_MD(...) \ 73 if (conscrypt::trace::kWithJniTraceMd) { \ 74 CONSCRYPT_LOG(LOG_INFO, LOG_TAG "-jni", __VA_ARGS__); \ 75 } 76 #define JNI_TRACE_KEYS(...) \ 77 if (conscrypt::trace::kWithJniTraceKeys) { \ 78 CONSCRYPT_LOG(LOG_INFO, LOG_TAG "-jni", __VA_ARGS__); \ 79 } 80 #define JNI_TRACE_PACKET_DATA(ssl, dir, data, len) \ 81 if (conscrypt::trace::kWithJniTracePackets) { \ 82 debug_print_packet_data(ssl, dir, data, len); \ 83 } 84 85 #endif // CONSCRYPT_TRACE_H_ 86