DiffFIle (revision 6)
1
Index: usr/click/bin/backend/Makefile
2
===================================================================
3
--- usr/click/bin/backend/Makefile	(revision 38370)
4
+++ usr/click/bin/backend/Makefile	(working copy)
5
@@ -165,7 +165,7 @@
6
 	-lnfnetlink -lnetfilter_conntrack \
7
 	-lpciaccess \
8
 	-lpam -lpam_misc \
9
-	-lcrypt -lldap -llber -lkvm -lfetch -lmemstat -lutil -lradius -ltacplus -lgeom -lstdc++ -rdynamic
10
+	-lcrypt -lldap -llber -lssl -lcrypto -lkvm -lfetch -lmemstat -lutil -lradius -ltacplus -lgeom -lstdc++ -rdynamic
11
 
12
 BINMODE=4555
13
 
14
Index: usr/click/bin/openssh/array_patch
15
===================================================================
16
--- usr/click/bin/openssh/array_patch	(revision 38370)
17
+++ usr/click/bin/openssh/array_patch	(working copy)
18
@@ -796,7 +796,7 @@
19
  
20
  sshd$(EXEEXT): libssh.a	$(LIBCOMPAT) $(SSHDOBJS)
21
 -	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS)
22
-+	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lldap -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS) -L ../../objdir/ -L../../../lib/libexauth -lexauth -L../../../lib/libuinet-atcp/lib/libuinet -luinet_lite -L../../../lib/libuinet-atcp/lib/libuinet_sysctl -luinet_sysctl -L../../../lib/libuinet-atcp/lib/libuinetnv -luinetnv -lrt -lcrypto -L../../../lib/libfastlog -lfastlog
23
++	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lldap -lssl -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS) -L ../../objdir/ -L../../../lib/libexauth -lexauth -L../../../lib/libuinet-atcp/lib/libuinet -luinet_lite -L../../../lib/libuinet-atcp/lib/libuinet_sysctl -luinet_sysctl -L../../../lib/libuinet-atcp/lib/libuinetnv -luinetnv -lrt -lcrypto -L../../../lib/libfastlog -lfastlog
24
 +
25
 +synconfigd$(EXEEXT): sshd$(EXEEXT)
26
 +	/bin/cp sshd$(EXEEXT) $@
27
Index: usr/click/lib/libexauth/Makefile
28
===================================================================
29
--- usr/click/lib/libexauth/Makefile	(revision 38370)
30
+++ usr/click/lib/libexauth/Makefile	(working copy)
31
@@ -13,6 +13,6 @@
32
 .endif
33
 
34
 LDADD=-L${.OBJDIR}/../../lib/libbsd -lbsd \
35
-      -lmd -lcrypt -lcrypto -lpthread -lldap -llber -lhiredis -lutil
36
+      -lmd -lcrypt -lcrypto -lpthread -lldap -llber -lssl -lcrypto -lhiredis -lutil
37
 
38
 .include <bsd.libauth.mk>
39
Index: usr/click/lib/libexauth/auth_ext.c
40
===================================================================
41
--- usr/click/lib/libexauth/auth_ext.c	(revision 38370)
42
+++ usr/click/lib/libexauth/auth_ext.c	(working copy)
43
@@ -33,6 +33,9 @@
44
 #include <fastlog.h>
45
 #include <sys/shm.h>
46
 #include <ldap.h>
47
+#include <openssl/ssl.h>
48
+#include <openssl/err.h>
49
+
50
 #include "auth_ext.h"
51
 #include "auth_ext_cli.h"
52
 #include "auth_ext_ipc.h"
53
@@ -43,6 +46,9 @@
54
 
55
 #define ARRAY_RADIUS_ID 7564
56
 
57
+#define LDAPS_CLIENT_CERT_FILE        "/ca/ssl/vhost/ldaps_client_cert.pem"
58
+#define LDAPS_CLIENT_KEY_FILE         "/ca/ssl/vhost/ldaps_client_key.pem"
59
+#define LDAPS_ROOTCA_FILE             "/ca/ssl/vhost/ldaps_root_cert.pem"
60
 /*if really do external authentication*/
61
 int do_exauth = 0;
62
 
63
@@ -85,6 +91,10 @@
64
                 sprintf(buf, "%s", EXAUTH_METHOD_STRING_LDAP);
65
         }
66
 
67
+        if (g_exauth_conf.exau_method == METHOD_LDAPS) {
68
+                sprintf(buf, "%s", EXAUTH_METHOD_STRING_LDAPS);
69
+        }
70
+
71
 	return 0;
72
 }
73
 
74
@@ -179,6 +189,10 @@
75
                         return external_auth_ldap(username, password);
76
                         break;
77
 
78
+                case METHOD_LDAPS:
79
+                        return external_auth_ldaps(username, password);
80
+                        break;
81
+
82
 		default:
83
 			exau_log("external_auth: no authenticaion method found");
84
 			return EXT_AUTH_FAILED;
85
@@ -190,6 +204,176 @@
86
 }
87
 
88
 int
89
+external_auth_ldaps(char *username, char *password)
90
+{
91
+    /*the return value of ldap response type*/
92
+    int ret_value = EXT_AUTH_FAILED;
93
+    int i;
94
+    if (username == NULL || password == NULL) {
95
+        return EXT_AUTH_FAILED;
96
+    }
97
+    /*authenticate ldaps servers*/
98
+    for (i = 0; i < MAX_EXAU_SERVER_NUM; i++) {
99
+        if (g_exauth_conf.exauth_servers[i].id &&
100
+            g_exauth_conf.exauth_servers[i].id[0] != '\0') {
101
+            ret_value = external_auth_one_ldaps(i, username, password);
102
+            if ((ret_value == EXT_AUTH_PASS_CONFIG) ||
103
+                (ret_value == EXT_AUTH_PASS_ENABLE)) {
104
+                break;
105
+            }
106
+        }
107
+    }
108
+    return ret_value;
109
+}
110
+
111
+int
112
+external_auth_one_ldaps(int server_num, char *username, char *password)
113
+{
114
+    LDAP *ld;
115
+    struct timeval to;
116
+    int msgid = 0;
117
+    to.tv_sec = 600;
118
+    to.tv_usec = 0;
119
+    int ret_value = EXT_AUTH_FAILED;
120
+    int i = server_num;
121
+    LDAPMessage *answer, *entry;
122
+    char *attrs[]       = {"memberOf", NULL};
123
+    int  attrsonly      = 0;
124
+    int  entries_found  = 0;
125
+    int rc;
126
+
127
+    if (username == NULL || password == NULL) {
128
+            return EXT_AUTH_FAILED;
129
+    }
130
+    // Add certificate verification part here
131
+
132
+    char ldap_uri[1024];
133
+
134
+    sprintf(ldap_uri,"ldaps://%s:%d",g_exauth_conf.exauth_servers[i].host,
135
+                                   g_exauth_conf.exauth_servers[i].port);
136
+    // Initialize OpenSSL
137
+    SSL_library_init();
138
+    ERR_load_BIO_strings();
139
+    OpenSSL_add_all_algorithms();
140
+    SSL_load_error_strings();
141
+    exau_log("ldap_uri %s\n", ldap_uri);
142
+    // Initialize LDAP connection
143
+    rc = ldap_initialize(&ld, ldap_uri);
144
+    if (rc != LDAP_SUCCESS) {
145
+        exau_log("ldap_initialize failed: %s\n", ldap_err2string(rc));
146
+        ldap_unbind_ext_s(ld, NULL, NULL);
147
+        return EXT_AUTH_FAILED;
148
+    }
149
+
150
+    // Set LDAP options
151
+    int version = LDAP_VERSION3;
152
+    ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version);
153
+
154
+    if (!g_exauth_conf.exauth_servers[i].verifyCert) {
155
+        exau_log("Skip certificate verification\n");
156
+        // Skip certificate verification
157
+        int opt = LDAP_OPT_X_TLS_NEVER;
158
+        ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &opt);
159
+    } else {
160
+        exau_log("Enable certificate verification\n");
161
+
162
+        // Set up TLS context
163
+        SSL_CTX *ssl_ctx = SSL_CTX_new(TLSv1_2_client_method());
164
+        if (!ssl_ctx) {
165
+            exau_log( "SSL_CTX_new error\n");
166
+            ldap_unbind_ext_s(ld, NULL, NULL);
167
+            return EXT_AUTH_FAILED;
168
+        }
169
+
170
+        // Load client certificate and key
171
+        if (SSL_CTX_use_certificate_file(ssl_ctx, LDAPS_CLIENT_CERT_FILE, SSL_FILETYPE_PEM) <= 0) {
172
+            exau_log( "SSL_CTX_use_certificate_file error\n");
173
+            SSL_CTX_free(ssl_ctx);
174
+            ldap_unbind_ext_s(ld, NULL, NULL);
175
+            return EXT_AUTH_FAILED;
176
+        }
177
+
178
+        if (SSL_CTX_use_PrivateKey_file(ssl_ctx, LDAPS_CLIENT_KEY_FILE, SSL_FILETYPE_PEM) <= 0) {
179
+            exau_log( "SSL_CTX_use_PrivateKey_file error\n");
180
+            SSL_CTX_free(ssl_ctx);
181
+            ldap_unbind_ext_s(ld, NULL, NULL);
182
+            return EXT_AUTH_FAILED;
183
+        }
184
+
185
+        // Load trusted Root CA certificates
186
+        if (!SSL_CTX_load_verify_locations(ssl_ctx, LDAPS_ROOTCA_FILE, NULL)) {
187
+            exau_log( "SSL_CTX_load_verify_locations error\n");
188
+            SSL_CTX_free(ssl_ctx);
189
+            ldap_unbind_ext_s(ld, NULL, NULL);
190
+            return EXT_AUTH_FAILED;
191
+        }
192
+        SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, NULL);
193
+        // Set TLS context
194
+        ldap_set_option(ld, LDAP_OPT_X_TLS_CTX, ssl_ctx);
195
+
196
+    }
197
+
198
+    // This is AD bug, if password is blank it allows to login
199
+    if (strlen(password) == 0) {
200
+        ldap_unbind_ext_s(ld, NULL, NULL);
201
+        return EXT_AUTH_FAILED;
202
+    }
203
+    msgid = ldap_simple_bind_s(ld, username, password);
204
+
205
+    if ( msgid != LDAP_SUCCESS ) {
206
+        exau_log("LDAPS login failed: %s for user %s.\n", ldap_err2string(msgid), username);
207
+        ldap_unbind_ext_s(ld, NULL, NULL);
208
+        return EXT_AUTH_FAILED;
209
+    } else {
210
+        exau_log("LDAPS bind successful for user %s.\n", username);
211
+        ret_value = EXT_AUTH_PASS_CONFIG;
212
+    }
213
+
214
+    // authorization off then will not do authorization only authentication
215
+    if (g_exauth_conf.external_authorize_on == EXT_AUTHORIZE_OFF){
216
+        exau_log("LDAPS authorization off for user %s.\n", username);
217
+        ret_value = EXT_AUTH_PASS_CONFIG;
218
+        ldap_unbind(ld);
219
+        return ret_value;
220
+    }
221
+    //authorization block
222
+    char search_string[1024];
223
+    if (strstr(username, "@")) {
224
+        sprintf(search_string,"\(\&\(userPrincipalName\=%s\)\(memberOf=%s\)\)", username, g_exauth_conf.exauth_servers[i].memberOf);
225
+    } else {
226
+        sprintf(search_string,"\(\&\(sAMAccountName\=%s\)\(memberOf=%s\)\)", username, g_exauth_conf.exauth_servers[i].memberOf);
227
+    }
228
+    msgid = ldap_search_s(ld, g_exauth_conf.exauth_servers[i].dn, LDAP_SCOPE_SUBTREE, search_string,
229
+                         attrs, attrsonly, &answer);
230
+    if ( msgid != LDAP_SUCCESS ) {
231
+        exau_log("LDAPS search failed: %s for user %s.\n", ldap_err2string(msgid), username);
232
+        ldap_unbind_ext_s(ld, NULL, NULL);
233
+        return EXT_AUTH_FAILED;
234
+    } else {
235
+        exau_log("LDAPS search successful for user %s.\n", username);
236
+    }
237
+
238
+    /* Return the number of objects found during the search */
239
+    entries_found = ldap_count_entries(ld, answer);
240
+    if ( entries_found == 0 ) {
241
+        exau_log("LDAPS authorization failed for user %s.\n", username);
242
+        ret_value = EXT_AUTH_PASS_ENABLE; // if authorization failed then not allow to do any change
243
+    } else {
244
+        ret_value = EXT_AUTH_PASS_CONFIG;
245
+        exau_log("LDAPS authorization success for user %s.\n", username);
246
+    }
247
+    if (ret_value != EXT_AUTH_PASS_CONFIG) {
248
+        ret_value = EXT_AUTH_PASS_ENABLE;
249
+    }
250
+    ldap_msgfree(answer);
251
+    ldap_unbind(ld);
252
+    ERR_free_strings();
253
+    EVP_cleanup();
254
+    CRYPTO_cleanup_all_ex_data();
255
+    return ret_value;
256
+}
257
+
258
+int
259
 external_auth_ldap(char *username, char *password)
260
 {
261
     /*the return value of ldap response type*/
262
Index: usr/click/lib/libexauth/auth_ext_cli.c
263
===================================================================
264
--- usr/click/lib/libexauth/auth_ext_cli.c	(revision 38370)
265
+++ usr/click/lib/libexauth/auth_ext_cli.c	(working copy)
266
@@ -22,6 +22,7 @@
267
 #include <unistd.h>
268
 #include <string.h>
269
 #include <sys/time.h>
270
+#include <sys/stat.h>
271
 #include <errno.h>
272
 #include <netdb.h> 	/*for gethostbyname()*/
273
 #include <sys/socket.h>		/*for inet_addr() and inet_ntop()*/
274
@@ -153,9 +154,13 @@
275
         {
276
                 g_exauth_conf.exau_method = METHOD_LDAP;
277
         }
278
+        else if (strcasecmp(method, EXAUTH_METHOD_STRING_LDAPS) == 0)
279
+        {
280
+                g_exauth_conf.exau_method = METHOD_LDAPS;
281
+        }
282
 	else
283
 	{
284
-		printf ("%s | %s | %s \n",EXAUTH_METHOD_STRING_RADIUS, EXAUTH_METHOD_STRING_TAC_X, EXAUTH_METHOD_STRING_LDAP);
285
+		printf ("%s | %s | %s | %S \n",EXAUTH_METHOD_STRING_RADIUS, EXAUTH_METHOD_STRING_TAC_X, EXAUTH_METHOD_STRING_LDAP, EXAUTH_METHOD_STRING_LDAPS);
286
 	}
287
 
288
 	/*update conf to shared mem*/
289
@@ -164,6 +169,64 @@
290
 	return 0;
291
 }
292
 
293
+/*configure an exauth ldaps server*/
294
+int
295
+exauth_ldaps_server(char *id, char *host, uint16_t port, char *dn, char *memberOf)
296
+{
297
+        int id_num = -1;
298
+        char *str_num = NULL, *ep = NULL;
299
+
300
+
301
+        if (id == NULL || host == NULL || dn == NULL || memberOf == NULL)
302
+        {
303
+                return -1;
304
+        }
305
+
306
+        get_auth_conf(&shm_p, &g_exauth_conf);
307
+        /*invalid server id, should be "es01" or "es02"*/
308
+        if (strcmp(id, EXAUTH_SERVER_ID4))
309
+        {
310
+                printf ("%s \n", EXAUTH_SERVER_ID4);
311
+                return 0;
312
+        }
313
+
314
+        /*assign id*/
315
+        str_num = id + 3;
316
+        id_num = (int)strtol(str_num, &ep,10) - 1;
317
+
318
+        if (id_num == 3)
319
+        {
320
+                strcpy(g_exauth_conf.exauth_servers[id_num].id, EXAUTH_SERVER_ID4);
321
+        }
322
+
323
+        /*assign host*/
324
+        strncpy(g_exauth_conf.exauth_servers[id_num].host, host, HOST_LEN);
325
+
326
+        /*assign port*/
327
+        g_exauth_conf.exauth_servers[id_num].port = port;
328
+        /*assign dn*/
329
+        strncpy(g_exauth_conf.exauth_servers[id_num].dn, dn, DN_LEN);
330
+
331
+        /*assign memberOf*/
332
+        strncpy(g_exauth_conf.exauth_servers[id_num].memberOf, memberOf, MEMBEROF_LEN);
333
+
334
+        g_exauth_conf.exauth_servers[id_num].max_retry  = LDAP_DEF_RETRIES;
335
+        /*update conf to shared mem*/
336
+        set_auth_conf(&shm_p, &g_exauth_conf);
337
+        return 0;
338
+}
339
+
340
+/*configure disble certificate verification for ldaps*/
341
+int
342
+ldaps_certificate_verifycert(int flag)
343
+{
344
+        get_auth_conf(&shm_p, &g_exauth_conf);
345
+        g_exauth_conf.exauth_servers[3].verifyCert = flag;
346
+        set_auth_conf(&shm_p, &g_exauth_conf);
347
+
348
+        return 0;
349
+}
350
+
351
 /*configure an exauth ldap server*/
352
 int
353
 exauth_ldap_server(char *id, char *host, uint16_t port, char *dn, char *memberOf)
354
@@ -305,9 +368,9 @@
355
 		return -1;
356
 	}
357
 
358
-	if (strcmp(id, EXAUTH_SERVER_ID1) && strcmp(id, EXAUTH_SERVER_ID2) && strcmp(id, EXAUTH_SERVER_ID3))
359
+	if (strcmp(id, EXAUTH_SERVER_ID1) && strcmp(id, EXAUTH_SERVER_ID2) && strcmp(id, EXAUTH_SERVER_ID3), strcmp(id, EXAUTH_SERVER_ID4))
360
 	{
361
-		printf ("%s | %s | %s\n",EXAUTH_SERVER_ID1, EXAUTH_SERVER_ID2, EXAUTH_SERVER_ID3);
362
+		printf ("%s | %s | %s | %s\n",EXAUTH_SERVER_ID1, EXAUTH_SERVER_ID2, EXAUTH_SERVER_ID3, EXAUTH_SERVER_ID4);
363
 		return 0;
364
 	}
365
 
366
@@ -329,10 +392,101 @@
367
 	return 0;
368
 }
369
 
370
+int show_ldaps_cert(char *filename) {
371
+    struct stat file_stat;
372
+    FILE *fp;
373
+    char *buffer;
374
+    long file_size;
375
+    size_t bytesRead;
376
+    char *begin_tag = "-----BEGIN CERTIFICATE-----";
377
+    char *end_tag = "-----END CERTIFICATE-----";
378
+
379
+    // Use stat to check existence and access of the file
380
+    if (stat(filename, &file_stat) == -1) {
381
+        fprintf(stderr, "Error accessing file '%s': %s\n", filename, strerror(errno));
382
+        return 1;
383
+    }
384
+
385
+    // Open the certificate file
386
+    fp = fopen(filename, "r");
387
+    if (fp == NULL) {
388
+        perror("Error opening file");
389
+        return 1;
390
+    }
391
+
392
+    // Calculate file size
393
+    file_size = file_stat.st_size;
394
+
395
+    // Allocate memory to store file contents
396
+    buffer = (char *)malloc(file_size + 1);  // +1 for null terminator
397
+    if (buffer == NULL) {
398
+        perror("Memory allocation failed");
399
+        fclose(fp);
400
+        return 1;
401
+    }
402
+
403
+    // Read the entire file into the buffer
404
+    bytesRead = fread(buffer, 1, file_size, fp);
405
+    buffer[bytesRead] = '\0';  // Null-terminate the buffer
406
+
407
+    // Find and print the certificate content
408
+    char *begin_pos = strstr(buffer, begin_tag);
409
+    char *end_pos = strstr(buffer, end_tag);
410
+
411
+    if (begin_pos != NULL && end_pos != NULL && end_pos > begin_pos) {
412
+        // Calculate the length of the certificate content including tags
413
+        size_t cert_length = end_pos + strlen(end_tag) - begin_pos;
414
+
415
+        // Allocate memory for certificate content
416
+        char *certificate_content = (char *)malloc(cert_length + 1);
417
+        if (certificate_content == NULL) {
418
+            perror("Memory allocation failed");
419
+            fclose(fp);
420
+            free(buffer);
421
+            return 1;
422
+        }
423
+
424
+        // Copy the certificate content with tags
425
+        strncpy(certificate_content, begin_pos, cert_length);
426
+        certificate_content[cert_length] = '\0';  // Null-terminate the certificate content
427
+
428
+        // Print the contents of the certificate file
429
+        printf("%s\n", certificate_content);
430
+
431
+        // Clean up: close file and free allocated memory
432
+        fclose(fp);
433
+        free(buffer);
434
+        free(certificate_content);
435
+
436
+        return 0;
437
+    } else {
438
+        printf("Certificate section not found in the file.\n");
439
+
440
+        // Clean up: close file and free allocated memory
441
+        fclose(fp);
442
+        free(buffer);
443
+
444
+        return 1;
445
+    }
446
+}
447
+
448
+static __inline int
449
+ssl_certfile_exists(char *crtfile)
450
+{
451
+        struct stat cstat;
452
+
453
+        bzero(&cstat, sizeof(cstat));
454
+        if(stat(crtfile, &cstat) == 0 && S_ISREG(cstat.st_mode) && cstat.st_size > 0) {
455
+                return 1;
456
+        }
457
+        return 0;
458
+}
459
+
460
 /*display exauth configurations*/
461
 int 
462
 show_exauth_all(void)
463
 {
464
+
465
 	int i;
466
 	
467
 	get_auth_conf(&shm_p, &g_exauth_conf);
468
@@ -367,6 +521,9 @@
469
                 case METHOD_LDAP:
470
                         printf("%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAP);
471
                         break;
472
+                case METHOD_LDAPS:
473
+                        printf("%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAPS);
474
+                        break;
475
 
476
 		default:
477
 			printf ("show %s faild\n", CLI_EXAUTH_METHOD);
478
@@ -387,6 +544,16 @@
479
                                         g_exauth_conf.exauth_servers[i].dn,
480
                                         g_exauth_conf.exauth_servers[i].memberOf
481
                                         );
482
+                    } else if (g_exauth_conf.exau_method == METHOD_LDAPS) {
483
+                        printf ("%s ldaps settings %s \"%s\" %d \"%s\" \"%s\"\n",
484
+                                    CLI_EXAUTH_SERVER,
485
+                                    g_exauth_conf.exauth_servers[i].id,
486
+                                        g_exauth_conf.exauth_servers[i].host,
487
+                                        g_exauth_conf.exauth_servers[i].port,
488
+                                        g_exauth_conf.exauth_servers[i].dn,
489
+                                        g_exauth_conf.exauth_servers[i].memberOf
490
+                                        );
491
+                        printf("%s %d\n", VERIFYCERT, g_exauth_conf.exauth_servers[i].verifyCert);
492
                     } else {
493
                         printf ("%s radius %s \"%s\" %d \"%s\"\n",
494
                                     CLI_EXAUTH_SERVER,
495
@@ -399,6 +566,19 @@
496
 		}
497
 	}
498
 
499
+        char file[1024];
500
+        // read client certificate
501
+        snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_cert.pem");
502
+        if (ssl_certfile_exists(file)) {
503
+            printf("----- Client Certificate -----\n");
504
+            show_ldaps_cert(file); // calling certificate print
505
+        }
506
+        // read root certificate
507
+        snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_root_cert.pem");
508
+        if (ssl_certfile_exists(file)) {
509
+            printf("----- Root CA -----\n");
510
+            show_ldaps_cert(file); // calling certificate print
511
+        }
512
 	return 0;
513
 }
514
 
515
@@ -407,7 +587,21 @@
516
 clear_exauth_all(void)
517
 {
518
 	get_auth_conf(&shm_p, &g_exauth_conf);
519
-
520
+        if (g_exauth_conf.exau_method == METHOD_LDAPS) {
521
+            char file[1024];
522
+            snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_cert.pem");
523
+            if (ssl_certfile_exists(file)) {
524
+                unlink(file);
525
+            }
526
+            snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_key.pem");
527
+            if (ssl_certfile_exists(file)) {
528
+                unlink(file);
529
+            }
530
+            snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_root_cert.pem");
531
+            if (ssl_certfile_exists(file)) {
532
+                unlink(file);
533
+            }
534
+        }
535
 	init_exau_conf();
536
 
537
 	/*update conf to shared mem*/
538
@@ -423,7 +617,6 @@
539
 {
540
 	/*write buffer*/
541
 	char *conf_buf = NULL;
542
-
543
 	/*buffer offset*/
544
 	int buf_offset = 0;
545
 	int i;
546
@@ -443,14 +636,14 @@
547
 	 *
548
 	 * each cmd line can have maximum LINE_LEN characters
549
 	 */
550
-	conf_buf = (char *)malloc(LINE_LEN * 5);
551
+	conf_buf = (char *)malloc(LINE_LEN * 6);
552
 	if (conf_buf == NULL) 
553
 	{
554
        printf("Could not save the admin aaa configuration.\n");
555
        return NULL;
556
 	}
557
 
558
-	memset (conf_buf, 0, LINE_LEN * 4);
559
+	memset (conf_buf, 0, LINE_LEN * 6);
560
 
561
 	/*show admin aaa on |off*/
562
 	if (g_exauth_conf.external_auth_on == EXT_AUTH_ON)
563
@@ -482,12 +675,16 @@
564
                 case METHOD_LDAP:
565
                         buf_offset += sprintf(conf_buf + buf_offset, "%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAP);
566
                         break;
567
+                case METHOD_LDAPS:
568
+                        buf_offset += sprintf(conf_buf + buf_offset, "%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAPS);
569
+                        break;
570
 
571
 		default:
572
 			printf ("show %s faild\n", CLI_EXAUTH_METHOD);
573
 			return NULL;
574
 	}
575
 
576
+
577
 	/*show admin aaa server*/
578
 	for (i = 0; i < MAX_EXAU_SERVER_NUM; i++)
579
 	{
580
@@ -502,6 +699,17 @@
581
                                         g_exauth_conf.exauth_servers[i].dn,
582
                                         g_exauth_conf.exauth_servers[i].memberOf
583
                                         );
584
+                    } else if (g_exauth_conf.exau_method == METHOD_LDAPS) {
585
+                        buf_offset += sprintf (conf_buf + buf_offset, "%s ldaps settings %s \"%s\" %d \"%s\" \"%s\"\n",
586
+                                    CLI_EXAUTH_SERVER,
587
+                                    g_exauth_conf.exauth_servers[i].id,
588
+                                        g_exauth_conf.exauth_servers[i].host,
589
+                                        g_exauth_conf.exauth_servers[i].port,
590
+                                        g_exauth_conf.exauth_servers[i].dn,
591
+                                        g_exauth_conf.exauth_servers[i].memberOf
592
+                                        );
593
+                        buf_offset += sprintf(conf_buf + buf_offset,"%s %d\n", VERIFYCERT,
594
+                                    g_exauth_conf.exauth_servers[i].verifyCert);
595
                     } else {
596
                         encrypt_secret((unsigned char *)(g_exauth_conf.exauth_servers[i].secret), encrypted_secret);
597
                         buf_offset += sprintf (conf_buf + buf_offset, "%s radius %s \"%s\" %d \"%s\" \"%s\"\n",
598
Index: usr/click/lib/libexauth/auth_ext_cli.h
599
===================================================================
600
--- usr/click/lib/libexauth/auth_ext_cli.h	(revision 38370)
601
+++ usr/click/lib/libexauth/auth_ext_cli.h	(working copy)
602
@@ -25,7 +25,7 @@
603
 #define MEMBEROF_LEN 256
604
 #define SECRET_LEN 129
605
 #define EXAUTH_DEF_METHOD		"RADIUS"
606
-#define MAX_EXAU_SERVER_NUM	        3	
607
+#define MAX_EXAU_SERVER_NUM	        4 
608
 #define IP_PRESENTATION_LEN		100	/*ip presentation length*/
609
 
610
 #define CLI_EXAUTH_ON				"admin aaa on"
611
@@ -34,6 +34,7 @@
612
 #define CLI_EXAUTH_SERVER			"admin aaa server"
613
 #define CLI_EXAUTHORIZE_ON				"admin aaa authorize on"
614
 #define CLI_EXAUTHORIZE_OFF				"admin aaa authorize off"
615
+#define VERIFYCERT				"admin aaa server ldaps verifycert"
616
 #define CLI_SHOW_EXAUTH_ALL			"show admin aaa all"
617
 #define CLI_NO_EXAUTH_SERVER		"no admin aaa server"
618
 #define CLI_CLEAR_EXAUTH_ALL		"clear admin aaa all"
619
@@ -41,9 +42,11 @@
620
 #define EXAUTH_SERVER_ID1			"es01"
621
 #define EXAUTH_SERVER_ID2			"es02"
622
 #define EXAUTH_SERVER_ID3                       "es03"
623
+#define EXAUTH_SERVER_ID4                       "es04"
624
 #define EXAUTH_METHOD_STRING_RADIUS		"RADIUS"
625
 #define EXAUTH_METHOD_STRING_TAC_X		"TAC_X"
626
 #define EXAUTH_METHOD_STRING_LDAP               "LDAP"
627
+#define EXAUTH_METHOD_STRING_LDAPS              "LDAPS"
628
 #define EXAUTH_METHOD_STRING_UNKONWN	"UNKONWN METHOD"
629
 
630
 #define EXAUTH_PRIORITY_HIGH		1
631
@@ -53,10 +56,15 @@
632
 typedef enum exau_method {
633
 	METHOD_RADIUS,
634
 	METHOD_TAC_X,
635
-        METHOD_LDAP
636
+        METHOD_LDAP,
637
+        METHOD_LDAPS
638
 } enum_exau_method;
639
 
640
-/*the structure for radius server*/
641
+#define false 0
642
+#define true 1
643
+typedef int bool;
644
+
645
+/*the structure for servenl authentication server*/
646
 typedef struct exauth_server {
647
 	char id[5];
648
 	char host[HOST_LEN];
649
@@ -66,6 +74,7 @@
650
 	unsigned short max_retry;
651
         char dn[DN_LEN];
652
         char memberOf[MEMBEROF_LEN];
653
+        bool verifyCert;
654
 } exauth_server_t;
655
 
656
 /*the structure wrapper*/
657
@@ -74,7 +83,7 @@
658
 	int external_authorize_on;
659
 	int ext_auth_priority;
660
 	enum_exau_method exau_method;
661
-	exauth_server_t exauth_servers[3];
662
+	exauth_server_t exauth_servers[4];
663
 } exauth_conf_t;
664
 
665
 /*turn on external authentication*/
666
Index: usr/click/lib/libparser/commands.pm
667
===================================================================
668
--- usr/click/lib/libparser/commands.pm	(revision 38370)
669
+++ usr/click/lib/libparser/commands.pm	(working copy)
670
@@ -48705,7 +48705,7 @@
671
 		function_name => "exauth_method",
672
 		function_args => [{
673
 								type => "STRING",
674
-								help_string => "method name(RADIUS or TAC_X or LDAP, default is RADIUS)",
675
+								help_string => "method name(RADIUS or TAC_X or LDAP or LDAPS , default is RADIUS)",
676
 								optional => "YES",
677
 								default_value => "\"RADIUS\"",
678
 		},],
679
@@ -48793,6 +48793,123 @@
680
                                                         },
681
                                                  ],
682
         },
683
+        {
684
+                obj_type => "MENU",
685
+                name => "ldaps",
686
+                parent_menu => "root_admin_server_aaa",
687
+                uniq_name => "root_admin_ldaps_server_aaa",
688
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL",
689
+                user_level => "CLI_LEVEL_CONFIG",
690
+                help_string => "Configure external authentication server",
691
+        },
692
+        {
693
+                obj_type => "ITEM",
694
+                name => "settings",
695
+                menu => "root_admin_ldaps_server_aaa",
696
+                help_string => "Configure external authentication server settings",
697
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_SPECIAL_LOG",
698
+                user_level => "CLI_LEVEL_CONFIG",
699
+                function_name => "exauth_ldaps_server",
700
+                function_args => [{
701
+                                                                type => "STRING",
702
+                                                                help_string => "id, es04(request will be sent to server es04)",
703
+                                                                optional => "NO",
704
+                                                   },
705
+                                                   {
706
+                                                                type => "STRING",
707
+                                                                help_string => "Host name or ip address",
708
+                                                                optional => "NO",
709
+                                                        },
710
+                                                        {
711
+                                                                type => "U16",
712
+                                                                help_string => "Port",
713
+                                                                optional => "NO",
714
+                                                        },
715
+                                                        {
716
+                                                                type => "STRING",
717
+                                                                help_string => "dn (Ex. OU=Eng,dc=example,dc=in)",
718
+                                                                optional => "YES",
719
+                                                                default_value => "\"\"",
720
+                                                        },
721
+                                                        {
722
+                                                                type => "STRING",
723
+                                                                help_string => "memberOf (Ex. CN=Engineering,DC=example,DC=in)",
724
+                                                                optional => "YES",
725
+                                                                default_value => "\"\"",
726
+                                                        },
727
+                                                 ],
728
+        },
729
+        {
730
+                obj_type => "ITEM",
731
+                name => "verifycert",
732
+                menu => "root_admin_ldaps_server_aaa",
733
+                help_string => "Enable/Disable certificate verification",
734
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL",
735
+                user_level => "CLI_LEVEL_CONFIG",
736
+                function_name => "ldaps_certificate_verifycert",
737
+                function_args => [
738
+                                                        {
739
+                                                                type => "U32",
740
+                                                                help_string => "Set 1 to enable certificate verification. (Default = 0)",
741
+                                                                optional => "YES",
742
+                                                                default_value => 0,
743
+                                                        },
744
+                                                ],
745
+        },
746
+        {
747
+                obj_type => "ITEM",
748
+                name => "clientcert",
749
+                menu => "root_admin_ldaps_server_aaa",
750
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL",
751
+                user_level => "CLI_LEVEL_CONFIG",
752
+                help_string => "Import PEM client certificate",
753
+                function_name => "exauth_ldaps_server_client_cert",
754
+                function_args => [
755
+                        {
756
+                                type => "STRING",
757
+                                name => "url",
758
+                                help_string => "FTP, TFTP or HTTP URL",
759
+                                optional => "YES",
760
+                                default_value => "\"\"",
761
+                        },
762
+                ],
763
+        },
764
+        {
765
+                obj_type => "ITEM",
766
+                name => "clientkey",
767
+                menu => "root_admin_ldaps_server_aaa",
768
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL",
769
+                user_level => "CLI_LEVEL_CONFIG",
770
+                help_string => "Import PEM client key",
771
+                function_name => "exauth_ldaps_server_client_key",
772
+                function_args => [
773
+                        {
774
+                                type => "STRING",
775
+                                name => "url",
776
+                                help_string => "FTP, TFTP or HTTP URL",
777
+                                optional => "YES",
778
+                                default_value => "\"\"",
779
+                        },
780
+                ],
781
+        },
782
+        {
783
+                obj_type => "ITEM",
784
+                name => "rootca",
785
+                menu => "root_admin_ldaps_server_aaa",
786
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL",
787
+                user_level => "CLI_LEVEL_CONFIG",
788
+                help_string => "Import CA certificate used for client authentication",
789
+                function_name => "exauth_ldaps_server_client_rootca",
790
+                function_args => [
791
+                        {
792
+                                type => "STRING",
793
+                                name => "url",
794
+                                help_string => "FTP, TFTP or HTTP URL",
795
+                                optional => "YES",
796
+                                default_value => "\"\"",
797
+                        },
798
+                ],
799
+        },
800
 	{
801
 		obj_type => "MENU",
802
 		name => "authorize",
803
Index: usr/click/lib/libpyexauth/pyexauth_build.py
804
===================================================================
805
--- usr/click/lib/libpyexauth/pyexauth_build.py	(revision 38370)
806
+++ usr/click/lib/libpyexauth/pyexauth_build.py	(working copy)
807
@@ -33,7 +33,7 @@
808
 """,
809
 	include_dirs=["../libexauth", "../libpyauth"],
810
 	library_dirs=tmp_library_dirs,
811
-	libraries=["ldap", "exauth", "fastlog", "bsd", "ssl", "pyauth", "crypt", "uinet_sysctl", "uinet_lite", "uinetnv", "rt"])
812
+	libraries=["ldap", "lber", "exauth", "fastlog", "bsd", "ssl", "crypto", "pyauth", "crypt", "uinet_sysctl", "uinet_lite", "uinetnv", "rt"])
813
 
814
 if __name__ == "__main__":
815
     ffi.compile()
816
Index: usr/click/lib/libssl_cli/ssl_cli.c
817
===================================================================
818
--- usr/click/lib/libssl_cli/ssl_cli.c	(revision 38370)
819
+++ usr/click/lib/libssl_cli/ssl_cli.c	(working copy)
820
@@ -349,7 +349,6 @@
821
 int fips_ssl_start_vhost_from_running_cfg();
822
 int fips_ssl_start_vhost(int kernelLoginFlag);
823
 int fips_ssl_file_exist(char* sPath, char* vhost, char* domainname, int* csr_exist, int* sslConf_exist);
824
-
825
 static int fips_init_turn_on_default_policy(Uint32 session_handle, BoardConfiguration *hsmConfig, int defaultLoginPrompt);
826
 static int fips_remove_ssl_files(void);
827
 static int fips_remove_name_passwd_files(void);
828
@@ -13975,6 +13974,114 @@
829
 	return SUCCESS;
830
 }
831
 
832
+int
833
+ssl_import_ldaps_cert(char *certname, char *url, char *type)
834
+{
835
+	char file[MAXPATHLEN];
836
+	char file_tmp[MAXPATHLEN];
837
+	char keypath[MAXPATHLEN];
838
+	/*Bug 23410, chenhb, 20090824*/
839
+	char agree[5];
840
+	int format = 0;
841
+	/*Bug 23410, end*/
842
+	int certfd;
843
+	int ret = 0;
844
+
845
+	if (ssl_feactl_approved(SHOW_NON_INTEL_MSG) != 1){
846
+		return ERR_SSL_NOT_LICENSED;
847
+	}
848
+
849
+        snprintf(file, sizeof(file), "%s/%s", SSL_DATA_PATH, certname);
850
+
851
+        if (file_exists(file) && cli_need_challenge()) {
852
+                printf("You may overwrite an existing client certificate file.\nType YES to continue, NO to abort: ");
853
+                fflush(stdout);
854
+                bzero(agree, sizeof(agree));
855
+                if (read(STDIN_FILENO, agree, 4) <= 0) {
856
+                        return ERR_SSL_USER_ABORT;
857
+                }
858
+
859
+                /* Check if the user agrees to overwrite */
860
+                if (strncasecmp(agree, "YES", 3) != 0) {
861
+                        printf("Aborted client certificate by user\n");
862
+                        do {
863
+                        } while (strchr(agree, '\n') == NULL && !(getchar() == '\n' && getchar() == '\n'));
864
+                        return ERR_SSL_USER_ABORT;
865
+                }
866
+        }
867
+
868
+	/* Bug 23370, chenyl, 20090810 */
869
+	create_ssl_tmp_dir();
870
+	snprintf(file_tmp, sizeof(file_tmp), "%s/%s", SSL_TMP_DIR, certname); /*Bug 23410, chenhb, 20090824*/
871
+	/* Bug 23370, end */
872
+#if defined(__linux__)
873
+	certfd = open(file_tmp, O_WRONLY|O_CREAT|O_TRUNC,
874
+#else
875
+	certfd = open(file_tmp, O_WRONLY|O_CREAT|O_TRUNC|O_EXLOCK,
876
+#endif
877
+	              S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
878
+	if ( certfd < 0 ){
879
+		printf ("Error saving certificate file\n");
880
+		englog(ENGLOG_SSL, SSL_CLI_INFO, "could not save %s\n", 
881
+		       file_tmp);
882
+		return ERR_SSL_FILE_WRITE_FAILED;
883
+	}
884
+
885
+	if (url == NULL || *url == 0) {	/* Import via stdin */
886
+		printf("Enter the certificate file in PEM format,\n"
887
+		       " use \"...\" on a single line, without quotes\n"
888
+		       " to terminate import\n");
889
+
890
+		fflush(stdout);
891
+		ssl_import_via_stdin(certfd);
892
+	} else {		/* Import from remote or local file */
893
+		if (import_file(url, file_tmp) != SUCCESS) {
894
+			close(certfd);
895
+			return ERR_SSL_FILE_WRITE_FAILED;
896
+		}
897
+	}
898
+	close(certfd);
899
+        // Format check
900
+        format = find_format(file_tmp);
901
+        switch (format) {
902
+        case FORMAT_PEM:
903
+                ret = 0;
904
+                break;
905
+        default:
906
+                ret = -1;
907
+                break;
908
+        }
909
+        if(ret != 0 ) {
910
+                printf("%s import failed..try again\n wrong format or wrong password\n", type);
911
+                unlink(file_tmp);
912
+                return ERR_SSL_WRONG_FORMAT;
913
+        }
914
+
915
+	unlink(file);
916
+	rename(file_tmp, file);
917
+
918
+	printf("%s import successful\n", type);
919
+	extra_file_add(file);
920
+
921
+	return ERR_SSL_OK;
922
+}
923
+
924
+int
925
+exauth_ldaps_server_client_cert(char *url)
926
+{
927
+    return ssl_import_ldaps_cert("ldaps_client_cert.pem", url, "Client certificate");
928
+}
929
+int
930
+exauth_ldaps_server_client_rootca(char *url)
931
+{
932
+    return ssl_import_ldaps_cert("ldaps_root_cert.pem", url, "Rootca certificate");
933
+}
934
+int
935
+exauth_ldaps_server_client_key(char *url)
936
+{
937
+    return ssl_import_ldaps_cert("ldaps_client_key.pem", url, "Client key");
938
+}
939
+
940
 /* 
941
  * Import SSL client certificate for SSL virtual host to be used for SSL virtual host.
942
  */
Loading...