]> git.saurik.com Git - apple/security.git/blob - libsecurity_ssl/lib/sslDebug.h
Security-55178.0.1.tar.gz
[apple/security.git] / libsecurity_ssl / lib / sslDebug.h
1 /*
2 * Copyright (c) 2000-2001,2005-2007,2010-2012 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * sslDebug.h - Debugging macros.
26 */
27
28 #ifndef _SSL_DEBUG_H_
29 #define _SSL_DEBUG_H_
30
31 #include "sslContext.h"
32 #include <security_utilities/debugging.h>
33 #include <assert.h>
34
35 #ifndef NDEBUG
36 #include <stdio.h>
37 #endif
38
39 /* If SSL_USE_SYSLOG is defined and not 0, use syslog() for debug
40 * logging in addition to invoking the secdebug macro (which, as of
41 * Snow Leopard, emits a static dtrace probe instead of an actual
42 * log message.)
43 */
44 #ifndef SSL_USE_SYSLOG
45 #define SSL_USE_SYSLOG 0
46 #endif
47
48 #if SSL_USE_SYSLOG
49 #include <syslog.h>
50 #define ssl_secdebug(scope, format...) \
51 { \
52 syslog(LOG_NOTICE, format); \
53 secdebug(scope, format); \
54 }
55 #else
56 #define ssl_secdebug(scope, format...) \
57 secdebug(scope, format)
58 #endif
59
60 #ifndef NDEBUG
61
62 /* log changes in handshake state */
63 #define sslHdskStateDebug(args...) ssl_secdebug("sslHdskState", ## args)
64
65 /* log handshake and alert messages */
66 #define sslHdskMsgDebug(args...) ssl_secdebug("sslHdskMsg", ## args)
67
68 /* log negotiated handshake parameters */
69 #define sslLogNegotiateDebug(args...) ssl_secdebug("sslLogNegotiate", ## args)
70
71 /* log received protocol messsages */
72 #define sslLogRxProtocolDebug(msgType) ssl_secdebug("sslLogRxProtocol", \
73 "---received protoMsg %s", msgType)
74
75 /* log resumable session info */
76 #define sslLogResumSessDebug(args...) ssl_secdebug("sslResumSession", ## args)
77
78 /* log low-level session info in appleSession.c */
79 #define sslLogSessCacheDebug(args...) ssl_secdebug("sslSessionCache", ## args)
80
81 /* log record-level I/O (SSLRead, SSLWrite) */
82 #define sslLogRecordIo(args...) ssl_secdebug("sslRecordIo", ## args)
83
84 /* cert-related info */
85 #define sslCertDebug(args...) ssl_secdebug("sslCert", ## args)
86
87 /* Diffie-Hellman */
88 #define sslDhDebug(args...) ssl_secdebug("sslDh", ## args)
89
90 /* EAP-FAST PAC-based session resumption */
91 #define sslEapDebug(args...) ssl_secdebug("sslEap", ## args)
92
93 /* ECDSA */
94 #define sslEcdsaDebug(args...) ssl_secdebug("sslEcdsa", ## args)
95
96 #else /* NDEBUG */
97
98 /* deployment build */
99 #define sslHdskStateDebug(args...)
100 #define sslHdskMsgDebug(args...)
101 #define sslLogNegotiateDebug(args...)
102 #define sslLogRxProtocolDebug(msgType)
103 #define sslLogResumSessDebug(args...)
104 #define sslLogSessCacheDebug(args...)
105 #define sslLogRecordIo(args...)
106 #define sslCertDebug(args...)
107 #define sslDhDebug(args...)
108 #define sslEapDebug(args...)
109 #define sslEcdsaDebug(args...)
110
111 #endif /*
112 NDEBUG */
113
114 #ifdef NDEBUG
115
116 #define SSLChangeHdskState(ctx, newState) { ctx->state=newState; }
117 #define SSLLogHdskMsg(msg, sent)
118
119 /* all errors logged to stdout for DEBUG config only */
120 #define sslErrorLog(args...)
121 #define sslDebugLog(args...)
122 #define sslDump(d, l)
123
124 #else
125
126 #include "sslAlertMessage.h"
127
128 extern void SSLLogHdskMsg(SSLHandshakeType msg, char sent);
129 extern char *hdskStateToStr(SSLHandshakeState state);
130 extern void SSLChangeHdskState(SSLContext *ctx, SSLHandshakeState newState);
131 extern void SSLDump(const unsigned char *data, unsigned long len);
132
133 /* extra debug logging of non-error conditions, if SSL_DEBUG is defined */
134 #if SSL_DEBUG
135 //#define sslDebugLog(args...) printf(args)
136 #define sslDebugLog(args...) ssl_secdebug("sslDebug", ## args)
137 #else
138 #define sslDebugLog(args...)
139 #endif
140 /* all errors logged to stdout for DEBUG config only */
141 //#define sslErrorLog(args...) printf(args)
142 #define sslErrorLog(args...) ssl_secdebug("sslError", ## args)
143 #define sslDump(d, l) SSLDump((d), (l))
144
145 #endif /* NDEBUG */
146
147
148 #ifdef NDEBUG
149 #define ASSERT(s)
150 #else
151 #define ASSERT(s) assert(s)
152 #endif
153
154 #endif /* _SSL_DEBUG_H_ */