summarylogtreecommitdiffstats
path: root/77.patch
blob: b70fb6da4c32244bf0b2708422e6526ed95fd1e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
From 75da5c38c0f753269d23a30d599da598b5779b86 Mon Sep 17 00:00:00 2001
From: Konstantin Shalygin <k0ste@k0ste.ru>
Date: Tue, 8 Oct 2019 11:25:02 +0700
Subject: [PATCH] Added TLSRequireCert option: when disabled,
 LDAP_OPT_X_TLS_REQUIRE_CERT policy is setted to 'never'.

---
 auth-ldap.conf                            |  3 +++
 src/TRAuthLDAPConfig.h                    |  8 ++++--
 src/TRAuthLDAPConfig.m                    | 23 +++++++++++++++--
 src/TRLDAPConnection.h                    |  7 +++---
 src/TRLDAPConnection.m                    | 30 ++++++++++++++++++-----
 src/auth-ldap.m                           | 11 ++++++---
 tests/TRLDAPConnectionTests.m             |  2 +-
 tests/data/auth-ldap-mismatched.conf      |  3 +++
 tests/data/auth-ldap-missing-newline.conf |  3 +++
 tests/data/auth-ldap-multikey.conf        |  3 +++
 tests/data/auth-ldap-named.conf           |  4 +++
 tests/data/auth-ldap-pf.conf              |  3 +++
 tests/data/auth-ldap-required.conf        |  3 +++
 tests/data/auth-ldap.conf                 |  3 +++
 14 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/auth-ldap.conf b/auth-ldap.conf
index 300f9c4..a04a882 100644
--- a/auth-ldap.conf
+++ b/auth-ldap.conf
@@ -28,6 +28,9 @@
 	TLSCertFile	/usr/local/etc/ssl/client-cert.pem
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+	# Validate Certificate
+	TLSRequireCert yes
+
 	# Cipher Suite
 	# The defaults are usually fine here
 	# TLSCipherSuite	ALL:!ADH:@STRENGTH
diff --git a/src/TRAuthLDAPConfig.h b/src/TRAuthLDAPConfig.h
index 4aa2c88..e38bbbb 100644
--- a/src/TRAuthLDAPConfig.h
+++ b/src/TRAuthLDAPConfig.h
@@ -16,7 +16,7 @@
  * 3. Neither the name of Landon Fuller nor the names of any contributors
  *    may be used to endorse or promote products derived from this
  *    software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -43,6 +43,7 @@
     /* LDAP Settings */
     TRString *_url;
     BOOL _tlsEnabled;
+    BOOL _tlsReqCertEnabled;
     BOOL _referralEnabled;
     int _timeout;
     TRString *_tlsCACertFile;
@@ -60,7 +61,7 @@
     TRString *_pfTable;
     TRArray *_ldapGroups;
     BOOL _pfEnabled;
-	BOOL _passwordISCR;
+    BOOL _passwordISCR;
 
     /* Parser State */
     TRString *_configFileName;
@@ -86,6 +87,9 @@
 - (BOOL) tlsEnabled;
 - (void) setTLSEnabled: (BOOL) newTLSSetting;
 
+- (BOOL) tlsReqCertEnabled;
+- (void) setTLSReqCertEnabled: (BOOL) newTLSReqCertSetting;
+
 - (TRString *) tlsCACertFile;
 - (void) setTLSCACertFile: (TRString *) fileName;
 
diff --git a/src/TRAuthLDAPConfig.m b/src/TRAuthLDAPConfig.m
index ed1a461..4c74214 100644
--- a/src/TRAuthLDAPConfig.m
+++ b/src/TRAuthLDAPConfig.m
@@ -17,7 +17,7 @@
  * 3. Neither the name of Landon Fuller nor the names of any contributors
  *    may be used to endorse or promote products derived from this
  *    software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -65,6 +65,7 @@
     LF_LDAP_PASSWORD,           /* Associated Password */
     LF_LDAP_REFERRAL,           /* Enable Referrals */
     LF_LDAP_TLS,                /* Enable TLS */
+    LF_LDAP_TLS_REQCERT,        /* Enable TLS Require Cert */
     LF_LDAP_TLS_CA_CERTFILE,    /* TLS CA Certificate File */
     LF_LDAP_TLS_CA_CERTDIR,     /* TLS CA Certificate Dir */
     LF_LDAP_TLS_CERTFILE,       /* TLS Client Certificate File */
@@ -137,6 +138,7 @@
     { "Password",           LF_LDAP_PASSWORD,           NO,     NO },
     { "FollowReferrals",    LF_LDAP_REFERRAL,           NO,     NO },
     { "TLSEnable",          LF_LDAP_TLS,                NO,     NO },
+    { "TLSRequireCert",     LF_LDAP_TLS_REQCERT,        NO,     NO },
     { "TLSCACertFile",      LF_LDAP_TLS_CA_CERTFILE,    NO,     NO },
     { "TLSCACertDir",       LF_LDAP_TLS_CA_CERTDIR,     NO,     NO },
     { "TLSCertFile",        LF_LDAP_TLS_CERTFILE,       NO,     NO },
@@ -613,6 +615,7 @@ - (void) setKey: (TRConfigToken *) key value: (TRConfigToken *) value {
             switch (opcodeEntry->opcode) {
                 int timeout;
                 BOOL enableTLS;
+                BOOL enableTLSReqCert;
                 BOOL enableReferral;
 
                 /* LDAP URL */
@@ -657,6 +660,15 @@ - (void) setKey: (TRConfigToken *) key value: (TRConfigToken *) value {
                     [self setTLSEnabled: enableTLS];
                     break;
 
+                /* LDAP TLS Require Cert */
+                case LF_LDAP_TLS_REQCERT:
+                    if (![value boolValue: &enableTLSReqCert]) {
+                        [self errorBoolValue: value];
+                        return;
+                    }
+                    [self setTLSReqCertEnabled: enableTLSReqCert];
+                    break;
+
                 /* LDAP CA Certificate */
                 case LF_LDAP_TLS_CA_CERTFILE:
                     [self setTLSCACertFile: [value string]];
@@ -865,6 +877,14 @@ - (void) setTLSEnabled: (BOOL) newTLSSetting {
     _tlsEnabled = newTLSSetting;
 }
 
+- (BOOL) tlsReqCertEnabled {
+    return (_tlsReqCertEnabled);
+}
+
+- (void) setTLSReqCertEnabled: (BOOL) newTLSReqCertSetting {
+    _tlsReqCertEnabled = newTLSReqCertSetting;
+}
+
 - (TRString *) url {
     return (_url);
 }
@@ -999,7 +1019,6 @@ - (TRString *) pfTable {
     return (_pfTable);
 }
 
-
 - (BOOL) pfEnabled {
     return (_pfEnabled);
 }
diff --git a/src/TRLDAPConnection.h b/src/TRLDAPConnection.h
index 24f0b2f..a0153b0 100644
--- a/src/TRLDAPConnection.h
+++ b/src/TRLDAPConnection.h
@@ -16,14 +16,14 @@
  * 3. Neither the name of Landon Fuller nor the names of any contributors
  *    may be used to endorse or promote products derived from this
  *    software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * SUBSTITUTE GOODS OR SEfRVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
@@ -47,6 +47,8 @@
 
 - (id) initWithURL: (TRString *) url timeout: (int) timeout;
 - (BOOL) startTLS;
+- (BOOL) TLSReqCert;
+
 
 - (BOOL) bindWithDN: (TRString *) bindDN password: (TRString *) password;
 
@@ -64,4 +66,3 @@
 - (BOOL) setTLSCipherSuite: (TRString *) cipherSuite;
 
 @end
-
diff --git a/src/TRLDAPConnection.m b/src/TRLDAPConnection.m
index 42c782f..7785d54 100644
--- a/src/TRLDAPConnection.m
+++ b/src/TRLDAPConnection.m
@@ -16,7 +16,7 @@
  * 3. Neither the name of Landon Fuller nor the names of any contributors
  *    may be used to endorse or promote products derived from this
  *    software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -91,17 +91,18 @@ - (BOOL) setLDAPOption: (int) opt value: (const char *) value connection: (LDAP
     return true;
 }
 
-/** 
- * Always require a valid certificate
- */    
+/**
+ * Always require a valid certificate.
+ */
 - (BOOL) setTLSRequireCert {
     int err;
     int arg;
     arg = LDAP_OPT_X_TLS_HARD;
     if ((err = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &arg)) != LDAP_SUCCESS) {
-        [TRLog debug: "Unable to set LDAP_OPT_X_TLS_HARD to %d: %d: %s", arg, err, ldap_err2string(err)];
+        [TRLog debug: "Unable to set LDAP_OPT_X_TLS_REQUIRE_CERT to %d: %d: %s", arg, err, ldap_err2string(err)];
         return (false);
     }
+
     return (true);
 }
 
@@ -155,6 +156,23 @@ - (void) dealloc {
     [super dealloc];
 }
 
+/**
+ * Do not require a valid certificate.
+ */
+
+- (BOOL) TLSReqCert {
+    int err;
+    int arg;
+    arg = LDAP_OPT_X_TLS_NEVER;
+
+    if ((err = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &arg)) != LDAP_SUCCESS) {
+        [TRLog debug: "Unable to set LDAP_OPT_X_TLS_REQUIRE_CERT to %d: %d: %s", arg, err, ldap_err2string(err)];
+        return (NO);
+    }
+
+    return (YES);
+}
+
 /**
  * Start TLS on the LDAP connection.
  */
@@ -331,7 +349,7 @@ - (BOOL) bindWithDN: (TRString *) bindDN password: (TRString *) password {
         dnCString = ldap_get_dn(ldapConn, entry);
         dn = [[TRString alloc] initWithCString: dnCString];
         ldap_memfree(dnCString);
-        
+
         /* Load all attributes and associated values */
         for (attr = ldap_first_attribute(ldapConn, entry, &ptr); attr != NULL; attr = ldap_next_attribute(ldapConn, entry, ptr)) {
             TRString *attrName;
diff --git a/src/auth-ldap.m b/src/auth-ldap.m
index ca90dee..65ead04 100644
--- a/src/auth-ldap.m
+++ b/src/auth-ldap.m
@@ -17,7 +17,7 @@
  * 3. Neither the name of Landon Fuller nor the names of any contributors
  *    may be used to endorse or promote products derived from this
  *    software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -281,12 +281,12 @@ static BOOL pf_open(struct ldap_ctx *ctx) {
     }
 
     /* Certificate file */
-    if ((value = [config tlsCACertFile])) 
+    if ((value = [config tlsCACertFile]))
         if (![ldap setTLSCACertFile: value])
             goto error;
 
     /* Certificate directory */
-    if ((value = [config tlsCACertDir])) 
+    if ((value = [config tlsCACertDir]))
         if (![ldap setTLSCACertDir: value])
             goto error;
 
@@ -300,6 +300,11 @@ static BOOL pf_open(struct ldap_ctx *ctx) {
         if(![ldap setTLSCipherSuite: value])
             goto error;
 
+    /* Do not require a valid certificate */
+    if (![config tlsReqCertEnabled])
+        if (![ldap TLSReqCert])
+            goto error;
+
     /* Start TLS */
     if ([config tlsEnabled])
         if (![ldap startTLS])
diff --git a/tests/TRLDAPConnectionTests.m b/tests/TRLDAPConnectionTests.m
index adee3ba..c7a9ed0 100644
--- a/tests/TRLDAPConnectionTests.m
+++ b/tests/TRLDAPConnectionTests.m
@@ -18,7 +18,7 @@
  * 3. Neither the name of Landon Fuller nor the names of any contributors
  *    may be used to endorse or promote products derived from this
  *    software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
diff --git a/tests/data/auth-ldap-mismatched.conf b/tests/data/auth-ldap-mismatched.conf
index 96cf003..7992c17 100644
--- a/tests/data/auth-ldap-mismatched.conf
+++ b/tests/data/auth-ldap-mismatched.conf
@@ -20,6 +20,9 @@
 	# Client Key
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+  # Require Valid Cert
+	TLSRequireCert yes
+
 	# Cipher Suite
 	TLSCipherSuite	ALL:!ADH:@STRENGTH
 </Fred>
diff --git a/tests/data/auth-ldap-missing-newline.conf b/tests/data/auth-ldap-missing-newline.conf
index 65f2851..692078b 100644
--- a/tests/data/auth-ldap-missing-newline.conf
+++ b/tests/data/auth-ldap-missing-newline.conf
@@ -28,6 +28,9 @@
 	# Client Key
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+  # Require Valid Cert
+	TLSRequireCert yes
+
 	# Cipher Suite
 	TLSCipherSuite	ALL:!ADH:@STRENGTH
 </LDAP>
diff --git a/tests/data/auth-ldap-multikey.conf b/tests/data/auth-ldap-multikey.conf
index 49d8e2b..db515b1 100644
--- a/tests/data/auth-ldap-multikey.conf
+++ b/tests/data/auth-ldap-multikey.conf
@@ -21,6 +21,9 @@
 	# Client Key
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+  # Require Valid Cert
+	TLSRequireCert yes
+
 	# Cipher Suite
 	TLSCipherSuite	ALL:!ADH:@STRENGTH
 </LDAP>
diff --git a/tests/data/auth-ldap-named.conf b/tests/data/auth-ldap-named.conf
index 384db18..a0a6737 100644
--- a/tests/data/auth-ldap-named.conf
+++ b/tests/data/auth-ldap-named.conf
@@ -19,4 +19,8 @@
 
 	# Client Key
 	#TLSKeyFile	/usr/local/etc/ssl/client-key.pem
+
+  # Require Valid Cert
+	TLSRequireCert no
+
 </LDAP>
diff --git a/tests/data/auth-ldap-pf.conf b/tests/data/auth-ldap-pf.conf
index 3424c07..6ac1820 100644
--- a/tests/data/auth-ldap-pf.conf
+++ b/tests/data/auth-ldap-pf.conf
@@ -26,6 +26,9 @@
 	# Client Key
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+  # Require Valid Cert
+	TLSRequireCert yes
+
 	# Cipher Suite
 	TLSCipherSuite	ALL:!ADH:@STRENGTH
 </LDAP>
diff --git a/tests/data/auth-ldap-required.conf b/tests/data/auth-ldap-required.conf
index 86fd9fe..54c1756 100644
--- a/tests/data/auth-ldap-required.conf
+++ b/tests/data/auth-ldap-required.conf
@@ -21,6 +21,9 @@
 	# Client Key
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+  # Require Valid Cert
+	TLSRequireCert yes
+
 	# Cipher Suite
 	TLSCipherSuite	ALL:!ADH:@STRENGTH
 </LDAP>
diff --git a/tests/data/auth-ldap.conf b/tests/data/auth-ldap.conf
index 1aca64c..186de54 100644
--- a/tests/data/auth-ldap.conf
+++ b/tests/data/auth-ldap.conf
@@ -26,6 +26,9 @@
 	# Client Key
 	TLSKeyFile	/usr/local/etc/ssl/client-key.pem
 
+  # Require Valid Cert
+	TLSRequireCert yes
+
 	# Cipher Suite
 	TLSCipherSuite	ALL:!ADH:@STRENGTH
 </LDAP>