1 # Debuggin SSL on Linux
3 To help anyone looking at the SSL code, here are a few tips I've found handy.
7 ## Building your own NSS
9 In order to use a debugger with the NSS library, it helps to build NSS yourself.
13 [Network Security Services](http://www.mozilla.org/projects/security/pki/nss/nss-3.11.4/nss-3.11.4-build.html)
15 [Build instructions](https://developer.mozilla.org/En/NSS_reference/Building_and_installing_NSS/Build_instructions).
17 Then, to build the most recent source tarball:
21 wget ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_RTM/src/nss-3.12-with-nspr-4.7.tar.gz
22 tar -xzvf nss-3.12-with-nspr-4.7.tar.gz
24 cd mozilla/security/nss/
28 Sadly, the latest release, 3.12.2, isn't available as a tarball, so you have to
35 export CVSROOT=:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
37 cvs co -r NSPR_4_7_RTM NSPR
38 cvs co -r NSS_3_12_2_RTM NSS
39 cd mozilla/security/nss/
43 ## Linking against your own NSS
45 Sadly, I don't know of a nice way to do this; I always do
47 hammer --verbose net > log 2>&1
49 then grab the line that links my app and put it into a shell script link.sh,
50 and edit it to include the line
52 DIR=$HOME/nss-3.12.2/mozilla/dist/Linux2.6_x86_glibc_PTH_DBG.OBJ/lib
54 and insert a `-L$DIR` right before the `-lnss3`.
56 Note that hammer often builds the app in one, deeply buried, place, then copies
57 it into Hammer for ease of use. You'll probably want to make your `link.sh` do
60 Then, after a source code change, do the usual `hammer net` followed by
63 Then, to run the resulting app, use a script like
65 ## Running against your own NSS
67 Create a script named `run.sh` like this:
72 DIR=$HOME/nss-3.12.2/mozilla/dist/Linux2.6_x86_glibc_PTH_DBG.OBJ/lib
73 export LD_LIBRARY_PATH=$DIR
77 Then run your app with
83 sh run.sh gdb Hammer/foo
87 There are several flavors of logging you can turn on.
89 * `SSLClientSocketNSS` can log its state transitions and function calls using
90 `base/logging.cc`. To enable this, edit `net/base/ssl_client_socket_nss.cc`
91 and change `#if 1` to `#if 0`. See `base/logging.cc` for where the output
92 goes (on Linux, it's usually stderr).
94 * `HttpNetworkTransaction` and friends can log its state transitions using
95 `base/trace_event.cc`. To enable this, arrange for your app to call
96 `base::TraceLog::StartTracing()`. The output goes to a file named
97 `trace...pid.log` in the same directory as the executable (e.g.
98 `Hammer/trace_15323.log`).
100 * `NSS` itself can log some events. To enable this, set the environment
101 variables `SSLDEBUGFILE=foo.log SSLTRACE=99 SSLDEBUG=99` before running
106 http://wiki.wireshark.org/SSL describes how to decode SSL traffic. Chromium SSL
107 unit tests that use `net/base/ssl_test_util.cc` to set up their servers always
108 use port 9443 with `net/data/ssl/certificates/ok_cert.pem`, and port 9666 with
109 `net/data/ssl/certificates/expired_cert.pem` This makes it easy to configure
110 Wireshark to decode the traffic: do
112 Edit / Preferences / Protocols / SSL, and in the "RSA Keys List" box, enter
114 127.0.0.1,9443,http,<path to ok_cert.pem>;127.0.0.1,9666,http,<path to expired_cert.pem>
118 127.0.0.1,9443,http,/home/dank/chromium/src/net/data/ssl/certificates/ok_cert.pem;127.0.0.1,9666,http,/home/dank/chromium/src/net/data/ssl/certificates/expired_cert.pem
120 Then capture all tcp traffic on interface lo, and run your test.
124 Read https://developer.mozilla.org/en/NSS_Memory_allocation and do
126 export NSS_DISABLE_ARENA_FREE_LIST=1
128 before valgrinding if you want to find where a block was originally allocated.
130 If you get unsymbolized entries in NSS backtraces, try setting:
132 export NSS_DISABLE_UNLOAD=1
134 (Note that if you use the Chromium valgrind scripts like
135 `tools/valgrind/chrome_tests.sh` or `tools/valgrind/valgrind.sh` these will both
136 be set automatically.)
140 If you have nonconfidential questions about NSS, check
141 [the newsgroup](http://groups.google.com/group/mozilla.dev.tech.crypto).
142 The NSS maintainer monitors that group and gives good answers.