| 1 |
Index: usr/click/bin/backend/Makefile |
| 2 |
=================================================================== |
| 3 |
--- usr/click/bin/backend/Makefile (revision 38360) |
| 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 38360) |
| 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 38360) |
| 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 38360) |
| 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,175 @@ |
| 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].insecureSkipVerify) { |
| 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 |
+ return EXT_AUTH_FAILED; |
| 201 |
+ } |
| 202 |
+ msgid = ldap_simple_bind_s(ld, username, password); |
| 203 |
+ |
| 204 |
+ if ( msgid != LDAP_SUCCESS ) { |
| 205 |
+ exau_log("LDAPS login failed for user %s password %s.\n", username, password); |
| 206 |
+ ldap_unbind_ext_s(ld, NULL, NULL); |
| 207 |
+ return EXT_AUTH_FAILED; |
| 208 |
+ } else { |
| 209 |
+ exau_log("LDAPS login successful for user %s.\n", username); |
| 210 |
+ ret_value = EXT_AUTH_PASS_CONFIG; |
| 211 |
+ } |
| 212 |
+ |
| 213 |
+ // authorization off then will not do authorization only authentication |
| 214 |
+ if (g_exauth_conf.external_authorize_on == EXT_AUTHORIZE_OFF){ |
| 215 |
+ exau_log("LDAPS authorization off for user %s.\n", username); |
| 216 |
+ ret_value = EXT_AUTH_PASS_CONFIG; |
| 217 |
+ ldap_unbind(ld); |
| 218 |
+ return ret_value; |
| 219 |
+ } |
| 220 |
+ //authorization block |
| 221 |
+ char search_string[1024]; |
| 222 |
+ if (strstr(username, "@")) { |
| 223 |
+ sprintf(search_string,"\(\&\(userPrincipalName\=%s\)\(memberOf=%s\)\)", username, g_exauth_conf.exauth_servers[i].memberOf); |
| 224 |
+ } else { |
| 225 |
+ sprintf(search_string,"\(\&\(sAMAccountName\=%s\)\(memberOf=%s\)\)", username, g_exauth_conf.exauth_servers[i].memberOf); |
| 226 |
+ } |
| 227 |
+ msgid = ldap_search_s(ld, g_exauth_conf.exauth_servers[i].dn, LDAP_SCOPE_SUBTREE, search_string, |
| 228 |
+ attrs, attrsonly, &answer); |
| 229 |
+ if ( msgid != LDAP_SUCCESS ) { |
| 230 |
+ exau_log("LDAPS search failed for user %s.\n", username); |
| 231 |
+ ldap_unbind_ext_s(ld, NULL, NULL); |
| 232 |
+ return EXT_AUTH_FAILED; |
| 233 |
+ } else { |
| 234 |
+ exau_log("LDAPS search successful for user %s.\n", username); |
| 235 |
+ } |
| 236 |
+ |
| 237 |
+ /* Return the number of objects found during the search */ |
| 238 |
+ entries_found = ldap_count_entries(ld, answer); |
| 239 |
+ if ( entries_found == 0 ) { |
| 240 |
+ exau_log("LDAPS authorization failed for user %s.\n", username); |
| 241 |
+ ret_value = EXT_AUTH_PASS_ENABLE; // if authorization failed then not allow to do any change |
| 242 |
+ } else { |
| 243 |
+ ret_value = EXT_AUTH_PASS_CONFIG; |
| 244 |
+ exau_log("LDAPS authorization success for user %s.\n", username); |
| 245 |
+ } |
| 246 |
+ if (ret_value != EXT_AUTH_PASS_CONFIG) { |
| 247 |
+ ret_value = EXT_AUTH_PASS_ENABLE; |
| 248 |
+ } |
| 249 |
+ ldap_msgfree(answer); |
| 250 |
+ ldap_unbind(ld); |
| 251 |
+ ERR_free_strings(); |
| 252 |
+ EVP_cleanup(); |
| 253 |
+ CRYPTO_cleanup_all_ex_data(); |
| 254 |
+ return ret_value; |
| 255 |
+} |
| 256 |
+ |
| 257 |
+int |
| 258 |
external_auth_ldap(char *username, char *password) |
| 259 |
{ |
| 260 |
/*the return value of ldap response type*/ |
| 261 |
Index: usr/click/lib/libexauth/auth_ext_cli.c |
| 262 |
=================================================================== |
| 263 |
--- usr/click/lib/libexauth/auth_ext_cli.c (revision 38360) |
| 264 |
+++ usr/click/lib/libexauth/auth_ext_cli.c (working copy) |
| 265 |
@@ -22,6 +22,7 @@ |
| 266 |
#include <unistd.h> |
| 267 |
#include <string.h> |
| 268 |
#include <sys/time.h> |
| 269 |
+#include <sys/stat.h> |
| 270 |
#include <errno.h> |
| 271 |
#include <netdb.h> /*for gethostbyname()*/ |
| 272 |
#include <sys/socket.h> /*for inet_addr() and inet_ntop()*/ |
| 273 |
@@ -153,9 +154,13 @@ |
| 274 |
{ |
| 275 |
g_exauth_conf.exau_method = METHOD_LDAP; |
| 276 |
} |
| 277 |
+ else if (strcasecmp(method, EXAUTH_METHOD_STRING_LDAPS) == 0) |
| 278 |
+ { |
| 279 |
+ g_exauth_conf.exau_method = METHOD_LDAPS; |
| 280 |
+ } |
| 281 |
else |
| 282 |
{ |
| 283 |
- printf ("%s | %s | %s \n",EXAUTH_METHOD_STRING_RADIUS, EXAUTH_METHOD_STRING_TAC_X, EXAUTH_METHOD_STRING_LDAP); |
| 284 |
+ printf ("%s | %s | %s | %S \n",EXAUTH_METHOD_STRING_RADIUS, EXAUTH_METHOD_STRING_TAC_X, EXAUTH_METHOD_STRING_LDAP, EXAUTH_METHOD_STRING_LDAPS); |
| 285 |
} |
| 286 |
|
| 287 |
/*update conf to shared mem*/ |
| 288 |
@@ -164,6 +169,64 @@ |
| 289 |
return 0; |
| 290 |
} |
| 291 |
|
| 292 |
+/*configure an exauth ldaps server*/ |
| 293 |
+int |
| 294 |
+exauth_ldaps_server(char *id, char *host, uint16_t port, char *dn, char *memberOf) |
| 295 |
+{ |
| 296 |
+ int id_num = -1; |
| 297 |
+ char *str_num = NULL, *ep = NULL; |
| 298 |
+ |
| 299 |
+ |
| 300 |
+ if (id == NULL || host == NULL || dn == NULL || memberOf == NULL) |
| 301 |
+ { |
| 302 |
+ return -1; |
| 303 |
+ } |
| 304 |
+ |
| 305 |
+ get_auth_conf(&shm_p, &g_exauth_conf); |
| 306 |
+ /*invalid server id, should be "es01" or "es02"*/ |
| 307 |
+ if (strcmp(id, EXAUTH_SERVER_ID4)) |
| 308 |
+ { |
| 309 |
+ printf ("%s \n", EXAUTH_SERVER_ID4); |
| 310 |
+ return 0; |
| 311 |
+ } |
| 312 |
+ |
| 313 |
+ /*assign id*/ |
| 314 |
+ str_num = id + 3; |
| 315 |
+ id_num = (int)strtol(str_num, &ep,10) - 1; |
| 316 |
+ |
| 317 |
+ if (id_num == 3) |
| 318 |
+ { |
| 319 |
+ strcpy(g_exauth_conf.exauth_servers[id_num].id, EXAUTH_SERVER_ID4); |
| 320 |
+ } |
| 321 |
+ |
| 322 |
+ /*assign host*/ |
| 323 |
+ strncpy(g_exauth_conf.exauth_servers[id_num].host, host, HOST_LEN); |
| 324 |
+ |
| 325 |
+ /*assign port*/ |
| 326 |
+ g_exauth_conf.exauth_servers[id_num].port = port; |
| 327 |
+ /*assign dn*/ |
| 328 |
+ strncpy(g_exauth_conf.exauth_servers[id_num].dn, dn, DN_LEN); |
| 329 |
+ |
| 330 |
+ /*assign memberOf*/ |
| 331 |
+ strncpy(g_exauth_conf.exauth_servers[id_num].memberOf, memberOf, MEMBEROF_LEN); |
| 332 |
+ |
| 333 |
+ g_exauth_conf.exauth_servers[id_num].max_retry = LDAP_DEF_RETRIES; |
| 334 |
+ /*update conf to shared mem*/ |
| 335 |
+ set_auth_conf(&shm_p, &g_exauth_conf); |
| 336 |
+ return 0; |
| 337 |
+} |
| 338 |
+ |
| 339 |
+/*configure disble certificate verification for ldaps*/ |
| 340 |
+int |
| 341 |
+ldaps_certificate_skipverify(int flag) |
| 342 |
+{ |
| 343 |
+ get_auth_conf(&shm_p, &g_exauth_conf); |
| 344 |
+ g_exauth_conf.exauth_servers[3].insecureSkipVerify = flag; |
| 345 |
+ set_auth_conf(&shm_p, &g_exauth_conf); |
| 346 |
+ |
| 347 |
+ return 0; |
| 348 |
+} |
| 349 |
+ |
| 350 |
/*configure an exauth ldap server*/ |
| 351 |
int |
| 352 |
exauth_ldap_server(char *id, char *host, uint16_t port, char *dn, char *memberOf) |
| 353 |
@@ -305,9 +368,9 @@ |
| 354 |
return -1; |
| 355 |
} |
| 356 |
|
| 357 |
- if (strcmp(id, EXAUTH_SERVER_ID1) && strcmp(id, EXAUTH_SERVER_ID2) && strcmp(id, EXAUTH_SERVER_ID3)) |
| 358 |
+ if (strcmp(id, EXAUTH_SERVER_ID1) && strcmp(id, EXAUTH_SERVER_ID2) && strcmp(id, EXAUTH_SERVER_ID3), strcmp(id, EXAUTH_SERVER_ID4)) |
| 359 |
{ |
| 360 |
- printf ("%s | %s | %s\n",EXAUTH_SERVER_ID1, EXAUTH_SERVER_ID2, EXAUTH_SERVER_ID3); |
| 361 |
+ printf ("%s | %s | %s | %s\n",EXAUTH_SERVER_ID1, EXAUTH_SERVER_ID2, EXAUTH_SERVER_ID3, EXAUTH_SERVER_ID4); |
| 362 |
return 0; |
| 363 |
} |
| 364 |
|
| 365 |
@@ -329,10 +392,96 @@ |
| 366 |
return 0; |
| 367 |
} |
| 368 |
|
| 369 |
+int show_ldaps_cert(char *filename) { |
| 370 |
+ FILE *fp; |
| 371 |
+ char *buffer; |
| 372 |
+ long file_size; |
| 373 |
+ size_t bytesRead; |
| 374 |
+ char *begin_tag = "-----BEGIN CERTIFICATE-----"; |
| 375 |
+ char *end_tag = "-----END CERTIFICATE-----"; |
| 376 |
+ int in_certificate = 0; |
| 377 |
+ |
| 378 |
+ // Open the certificate file |
| 379 |
+ fp = fopen(filename, "r"); |
| 380 |
+ if (fp == NULL) { |
| 381 |
+ perror("Error opening file"); |
| 382 |
+ return 1; |
| 383 |
+ } |
| 384 |
+ |
| 385 |
+ // Calculate file size |
| 386 |
+ fseek(fp, 0, SEEK_END); // Move file pointer to the end |
| 387 |
+ file_size = ftell(fp); // Get current position (which is file size) |
| 388 |
+ rewind(fp); // Rewind file pointer to the beginning |
| 389 |
+ |
| 390 |
+ // Allocate memory to store file contents |
| 391 |
+ buffer = (char *)malloc(file_size + 1); // +1 for null terminator |
| 392 |
+ if (buffer == NULL) { |
| 393 |
+ perror("Memory allocation failed"); |
| 394 |
+ fclose(fp); |
| 395 |
+ return 1; |
| 396 |
+ } |
| 397 |
+ |
| 398 |
+ // Read the entire file into the buffer |
| 399 |
+ bytesRead = fread(buffer, 1, file_size, fp); |
| 400 |
+ buffer[bytesRead] = '\0'; // Null-terminate the buffer |
| 401 |
+ |
| 402 |
+ // Find and print the certificate content |
| 403 |
+ char *begin_pos = strstr(buffer, begin_tag); |
| 404 |
+ char *end_pos = strstr(buffer, end_tag); |
| 405 |
+ |
| 406 |
+ if (begin_pos != NULL && end_pos != NULL && end_pos > begin_pos) { |
| 407 |
+ // Calculate the length of the certificate content including tags |
| 408 |
+ size_t cert_length = end_pos + strlen(end_tag) - begin_pos; |
| 409 |
+ |
| 410 |
+ // Allocate memory for certificate content |
| 411 |
+ char *certificate_content = (char *)malloc(cert_length + 1); |
| 412 |
+ if (certificate_content == NULL) { |
| 413 |
+ perror("Memory allocation failed"); |
| 414 |
+ fclose(fp); |
| 415 |
+ free(buffer); |
| 416 |
+ return 1; |
| 417 |
+ } |
| 418 |
+ |
| 419 |
+ // Copy the certificate content with tags |
| 420 |
+ strncpy(certificate_content, begin_pos, cert_length); |
| 421 |
+ certificate_content[cert_length] = '\0'; // Null-terminate the certificate content |
| 422 |
+ |
| 423 |
+ // Print the contents of the certificate file |
| 424 |
+ printf("%s\n", certificate_content); |
| 425 |
+ |
| 426 |
+ // Clean up: close file and free allocated memory |
| 427 |
+ fclose(fp); |
| 428 |
+ free(buffer); |
| 429 |
+ free(certificate_content); |
| 430 |
+ |
| 431 |
+ return 0; |
| 432 |
+ } else { |
| 433 |
+ printf("Certificate section not found in the file.\n"); |
| 434 |
+ |
| 435 |
+ fclose(fp); |
| 436 |
+ free(buffer); |
| 437 |
+ |
| 438 |
+ return 1; |
| 439 |
+ } |
| 440 |
+} |
| 441 |
+ |
| 442 |
+static __inline int |
| 443 |
+ssl_certfile_exists(char *crtfile) |
| 444 |
+{ |
| 445 |
+ struct stat cstat; |
| 446 |
+ |
| 447 |
+ bzero(&cstat, sizeof(cstat)); |
| 448 |
+ if(stat(crtfile, &cstat) == 0 && S_ISREG(cstat.st_mode) && cstat.st_size > 0) { |
| 449 |
+ return 1; |
| 450 |
+ } |
| 451 |
+ return 0; |
| 452 |
+} |
| 453 |
+ |
| 454 |
/*display exauth configurations*/ |
| 455 |
int |
| 456 |
show_exauth_all(void) |
| 457 |
{ |
| 458 |
+ |
| 459 |
int i; |
| 460 |
|
| 461 |
get_auth_conf(&shm_p, &g_exauth_conf); |
| 462 |
@@ -367,6 +516,9 @@ |
| 463 |
case METHOD_LDAP: |
| 464 |
printf("%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAP); |
| 465 |
break; |
| 466 |
+ case METHOD_LDAPS: |
| 467 |
+ printf("%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAPS); |
| 468 |
+ break; |
| 469 |
|
| 470 |
default: |
| 471 |
printf ("show %s faild\n", CLI_EXAUTH_METHOD); |
| 472 |
@@ -387,6 +539,16 @@ |
| 473 |
g_exauth_conf.exauth_servers[i].dn, |
| 474 |
g_exauth_conf.exauth_servers[i].memberOf |
| 475 |
); |
| 476 |
+ } else if (g_exauth_conf.exau_method == METHOD_LDAPS) { |
| 477 |
+ printf ("%s ldaps settings %s \"%s\" %d \"%s\" \"%s\"\n", |
| 478 |
+ CLI_EXAUTH_SERVER, |
| 479 |
+ g_exauth_conf.exauth_servers[i].id, |
| 480 |
+ g_exauth_conf.exauth_servers[i].host, |
| 481 |
+ g_exauth_conf.exauth_servers[i].port, |
| 482 |
+ g_exauth_conf.exauth_servers[i].dn, |
| 483 |
+ g_exauth_conf.exauth_servers[i].memberOf |
| 484 |
+ ); |
| 485 |
+ printf("%s %d\n", CLI_LDAPS_SKIPVERIFY, g_exauth_conf.exauth_servers[i].insecureSkipVerify); |
| 486 |
} else { |
| 487 |
printf ("%s radius %s \"%s\" %d \"%s\"\n", |
| 488 |
CLI_EXAUTH_SERVER, |
| 489 |
@@ -399,6 +561,24 @@ |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
+ |
| 494 |
+ |
| 495 |
+ char file[1024]; |
| 496 |
+ snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_cert.pem"); |
| 497 |
+ if (ssl_certfile_exists(file)) { |
| 498 |
+ printf("----- Client Certificate -----\n"); |
| 499 |
+ show_ldaps_cert(file); // calling certificate print |
| 500 |
+ } |
| 501 |
+ //snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_key.pem"); |
| 502 |
+ //if (ssl_certfile_exists(file)) { |
| 503 |
+ // printf("----- Client Key -----\n"); |
| 504 |
+ // show_ldaps_cert(file); // calling certificate print |
| 505 |
+ //} |
| 506 |
+ snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_root_cert.pem"); |
| 507 |
+ if (ssl_certfile_exists(file)) { |
| 508 |
+ printf("----- Root CA -----\n"); |
| 509 |
+ show_ldaps_cert(file); // calling certificate print |
| 510 |
+ } |
| 511 |
return 0; |
| 512 |
} |
| 513 |
|
| 514 |
@@ -407,7 +587,21 @@ |
| 515 |
clear_exauth_all(void) |
| 516 |
{ |
| 517 |
get_auth_conf(&shm_p, &g_exauth_conf); |
| 518 |
- |
| 519 |
+ if (g_exauth_conf.exau_method == METHOD_LDAPS) { |
| 520 |
+ char file[1024]; |
| 521 |
+ snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_cert.pem"); |
| 522 |
+ if (ssl_certfile_exists(file)) { |
| 523 |
+ unlink(file); |
| 524 |
+ } |
| 525 |
+ snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_client_key.pem"); |
| 526 |
+ if (ssl_certfile_exists(file)) { |
| 527 |
+ unlink(file); |
| 528 |
+ } |
| 529 |
+ snprintf(file, sizeof(file), "%s", "/ca/ssl/vhost/ldaps_root_cert.pem"); |
| 530 |
+ if (ssl_certfile_exists(file)) { |
| 531 |
+ unlink(file); |
| 532 |
+ } |
| 533 |
+ } |
| 534 |
init_exau_conf(); |
| 535 |
|
| 536 |
/*update conf to shared mem*/ |
| 537 |
@@ -423,7 +617,6 @@ |
| 538 |
{ |
| 539 |
/*write buffer*/ |
| 540 |
char *conf_buf = NULL; |
| 541 |
- |
| 542 |
/*buffer offset*/ |
| 543 |
int buf_offset = 0; |
| 544 |
int i; |
| 545 |
@@ -443,14 +636,14 @@ |
| 546 |
* |
| 547 |
* each cmd line can have maximum LINE_LEN characters |
| 548 |
*/ |
| 549 |
- conf_buf = (char *)malloc(LINE_LEN * 5); |
| 550 |
+ conf_buf = (char *)malloc(LINE_LEN * 6); |
| 551 |
if (conf_buf == NULL) |
| 552 |
{ |
| 553 |
printf("Could not save the admin aaa configuration.\n"); |
| 554 |
return NULL; |
| 555 |
} |
| 556 |
|
| 557 |
- memset (conf_buf, 0, LINE_LEN * 4); |
| 558 |
+ memset (conf_buf, 0, LINE_LEN * 6); |
| 559 |
|
| 560 |
/*show admin aaa on |off*/ |
| 561 |
if (g_exauth_conf.external_auth_on == EXT_AUTH_ON) |
| 562 |
@@ -482,12 +675,16 @@ |
| 563 |
case METHOD_LDAP: |
| 564 |
buf_offset += sprintf(conf_buf + buf_offset, "%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAP); |
| 565 |
break; |
| 566 |
+ case METHOD_LDAPS: |
| 567 |
+ buf_offset += sprintf(conf_buf + buf_offset, "%s %s\n", CLI_EXAUTH_METHOD, EXAUTH_METHOD_STRING_LDAPS); |
| 568 |
+ break; |
| 569 |
|
| 570 |
default: |
| 571 |
printf ("show %s faild\n", CLI_EXAUTH_METHOD); |
| 572 |
return NULL; |
| 573 |
} |
| 574 |
|
| 575 |
+ |
| 576 |
/*show admin aaa server*/ |
| 577 |
for (i = 0; i < MAX_EXAU_SERVER_NUM; i++) |
| 578 |
{ |
| 579 |
@@ -502,6 +699,17 @@ |
| 580 |
g_exauth_conf.exauth_servers[i].dn, |
| 581 |
g_exauth_conf.exauth_servers[i].memberOf |
| 582 |
); |
| 583 |
+ } else if (g_exauth_conf.exau_method == METHOD_LDAPS) { |
| 584 |
+ buf_offset += sprintf (conf_buf + buf_offset, "%s ldaps settings %s \"%s\" %d \"%s\" \"%s\"\n", |
| 585 |
+ CLI_EXAUTH_SERVER, |
| 586 |
+ g_exauth_conf.exauth_servers[i].id, |
| 587 |
+ g_exauth_conf.exauth_servers[i].host, |
| 588 |
+ g_exauth_conf.exauth_servers[i].port, |
| 589 |
+ g_exauth_conf.exauth_servers[i].dn, |
| 590 |
+ g_exauth_conf.exauth_servers[i].memberOf |
| 591 |
+ ); |
| 592 |
+ buf_offset += sprintf(conf_buf + buf_offset,"%s %d\n", CLI_LDAPS_SKIPVERIFY, |
| 593 |
+ g_exauth_conf.exauth_servers[i].insecureSkipVerify); |
| 594 |
} else { |
| 595 |
encrypt_secret((unsigned char *)(g_exauth_conf.exauth_servers[i].secret), encrypted_secret); |
| 596 |
buf_offset += sprintf (conf_buf + buf_offset, "%s radius %s \"%s\" %d \"%s\" \"%s\"\n", |
| 597 |
Index: usr/click/lib/libexauth/auth_ext_cli.h |
| 598 |
=================================================================== |
| 599 |
--- usr/click/lib/libexauth/auth_ext_cli.h (revision 38360) |
| 600 |
+++ usr/click/lib/libexauth/auth_ext_cli.h (working copy) |
| 601 |
@@ -25,7 +25,7 @@ |
| 602 |
#define MEMBEROF_LEN 256 |
| 603 |
#define SECRET_LEN 129 |
| 604 |
#define EXAUTH_DEF_METHOD "RADIUS" |
| 605 |
-#define MAX_EXAU_SERVER_NUM 3 |
| 606 |
+#define MAX_EXAU_SERVER_NUM 4 |
| 607 |
#define IP_PRESENTATION_LEN 100 /*ip presentation length*/ |
| 608 |
|
| 609 |
#define CLI_EXAUTH_ON "admin aaa on" |
| 610 |
@@ -34,6 +34,7 @@ |
| 611 |
#define CLI_EXAUTH_SERVER "admin aaa server" |
| 612 |
#define CLI_EXAUTHORIZE_ON "admin aaa authorize on" |
| 613 |
#define CLI_EXAUTHORIZE_OFF "admin aaa authorize off" |
| 614 |
+#define CLI_LDAPS_SKIPVERIFY "admin aaa server ldaps verifycert" |
| 615 |
#define CLI_SHOW_EXAUTH_ALL "show admin aaa all" |
| 616 |
#define CLI_NO_EXAUTH_SERVER "no admin aaa server" |
| 617 |
#define CLI_CLEAR_EXAUTH_ALL "clear admin aaa all" |
| 618 |
@@ -41,9 +42,11 @@ |
| 619 |
#define EXAUTH_SERVER_ID1 "es01" |
| 620 |
#define EXAUTH_SERVER_ID2 "es02" |
| 621 |
#define EXAUTH_SERVER_ID3 "es03" |
| 622 |
+#define EXAUTH_SERVER_ID4 "es04" |
| 623 |
#define EXAUTH_METHOD_STRING_RADIUS "RADIUS" |
| 624 |
#define EXAUTH_METHOD_STRING_TAC_X "TAC_X" |
| 625 |
#define EXAUTH_METHOD_STRING_LDAP "LDAP" |
| 626 |
+#define EXAUTH_METHOD_STRING_LDAPS "LDAPS" |
| 627 |
#define EXAUTH_METHOD_STRING_UNKONWN "UNKONWN METHOD" |
| 628 |
|
| 629 |
#define EXAUTH_PRIORITY_HIGH 1 |
| 630 |
@@ -53,10 +56,15 @@ |
| 631 |
typedef enum exau_method { |
| 632 |
METHOD_RADIUS, |
| 633 |
METHOD_TAC_X, |
| 634 |
- METHOD_LDAP |
| 635 |
+ METHOD_LDAP, |
| 636 |
+ METHOD_LDAPS |
| 637 |
} enum_exau_method; |
| 638 |
|
| 639 |
-/*the structure for radius server*/ |
| 640 |
+#define false 0 |
| 641 |
+#define true 1 |
| 642 |
+typedef int bool; |
| 643 |
+ |
| 644 |
+/*the structure for servenl authentication server*/ |
| 645 |
typedef struct exauth_server { |
| 646 |
char id[5]; |
| 647 |
char host[HOST_LEN]; |
| 648 |
@@ -66,6 +74,7 @@ |
| 649 |
unsigned short max_retry; |
| 650 |
char dn[DN_LEN]; |
| 651 |
char memberOf[MEMBEROF_LEN]; |
| 652 |
+ bool insecureSkipVerify; |
| 653 |
} exauth_server_t; |
| 654 |
|
| 655 |
/*the structure wrapper*/ |
| 656 |
@@ -74,7 +83,7 @@ |
| 657 |
int external_authorize_on; |
| 658 |
int ext_auth_priority; |
| 659 |
enum_exau_method exau_method; |
| 660 |
- exauth_server_t exauth_servers[3]; |
| 661 |
+ exauth_server_t exauth_servers[4]; |
| 662 |
} exauth_conf_t; |
| 663 |
|
| 664 |
/*turn on external authentication*/ |
| 665 |
Index: usr/click/lib/libparser/commands.pm |
| 666 |
=================================================================== |
| 667 |
--- usr/click/lib/libparser/commands.pm (revision 38360) |
| 668 |
+++ usr/click/lib/libparser/commands.pm (working copy) |
| 669 |
@@ -48705,7 +48705,7 @@ |
| 670 |
function_name => "exauth_method", |
| 671 |
function_args => [{ |
| 672 |
type => "STRING", |
| 673 |
- help_string => "method name(RADIUS or TAC_X or LDAP, default is RADIUS)", |
| 674 |
+ help_string => "method name(RADIUS or TAC_X or LDAP or LDAPS , default is RADIUS)", |
| 675 |
optional => "YES", |
| 676 |
default_value => "\"RADIUS\"", |
| 677 |
},], |
| 678 |
@@ -48793,6 +48793,123 @@ |
| 679 |
}, |
| 680 |
], |
| 681 |
}, |
| 682 |
+ { |
| 683 |
+ obj_type => "MENU", |
| 684 |
+ name => "ldaps", |
| 685 |
+ parent_menu => "root_admin_server_aaa", |
| 686 |
+ uniq_name => "root_admin_ldaps_server_aaa", |
| 687 |
+ cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL", |
| 688 |
+ user_level => "CLI_LEVEL_CONFIG", |
| 689 |
+ help_string => "Configure external authentication server", |
| 690 |
+ }, |
| 691 |
+ { |
| 692 |
+ obj_type => "ITEM", |
| 693 |
+ name => "settings", |
| 694 |
+ menu => "root_admin_ldaps_server_aaa", |
| 695 |
+ help_string => "Configure external authentication server settings", |
| 696 |
+ cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_SPECIAL_LOG", |
| 697 |
+ user_level => "CLI_LEVEL_CONFIG", |
| 698 |
+ function_name => "exauth_ldaps_server", |
| 699 |
+ function_args => [{ |
| 700 |
+ type => "STRING", |
| 701 |
+ help_string => "id, es04(request will be sent to server es04)", |
| 702 |
+ optional => "NO", |
| 703 |
+ }, |
| 704 |
+ { |
| 705 |
+ type => "STRING", |
| 706 |
+ help_string => "Host name or ip address", |
| 707 |
+ optional => "NO", |
| 708 |
+ }, |
| 709 |
+ { |
| 710 |
+ type => "U16", |
| 711 |
+ help_string => "Port", |
| 712 |
+ optional => "NO", |
| 713 |
+ }, |
| 714 |
+ { |
| 715 |
+ type => "STRING", |
| 716 |
+ help_string => "dn (Ex. OU=Eng,dc=example,dc=in)", |
| 717 |
+ optional => "YES", |
| 718 |
+ default_value => "\"\"", |
| 719 |
+ }, |
| 720 |
+ { |
| 721 |
+ type => "STRING", |
| 722 |
+ help_string => "memberOf (Ex. CN=Engineering,DC=example,DC=in)", |
| 723 |
+ optional => "YES", |
| 724 |
+ default_value => "\"\"", |
| 725 |
+ }, |
| 726 |
+ ], |
| 727 |
+ }, |
| 728 |
+ { |
| 729 |
+ obj_type => "ITEM", |
| 730 |
+ name => "verifycert", |
| 731 |
+ menu => "root_admin_ldaps_server_aaa", |
| 732 |
+ help_string => "Turn off certificate verification", |
| 733 |
+ cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL", |
| 734 |
+ user_level => "CLI_LEVEL_CONFIG", |
| 735 |
+ function_name => "ldaps_certificate_skipverify", |
| 736 |
+ function_args => [ |
| 737 |
+ { |
| 738 |
+ type => "U32", |
| 739 |
+ help_string => "Set 1 to enable certificate verification.(Default = 0)", |
| 740 |
+ optional => "YES", |
| 741 |
+ default_value => 0, |
| 742 |
+ }, |
| 743 |
+ ], |
| 744 |
+ }, |
| 745 |
+ { |
| 746 |
+ obj_type => "ITEM", |
| 747 |
+ name => "clientcert", |
| 748 |
+ menu => "root_admin_ldaps_server_aaa", |
| 749 |
+ cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL", |
| 750 |
+ user_level => "CLI_LEVEL_CONFIG", |
| 751 |
+ help_string => "Import PEM client certificate", |
| 752 |
+ function_name => "exauth_ldaps_server_client_cert", |
| 753 |
+ function_args => [ |
| 754 |
+ { |
| 755 |
+ type => "STRING", |
| 756 |
+ name => "url", |
| 757 |
+ help_string => "FTP, TFTP or HTTP URL", |
| 758 |
+ optional => "YES", |
| 759 |
+ default_value => "\"\"", |
| 760 |
+ }, |
| 761 |
+ ], |
| 762 |
+ }, |
| 763 |
+ { |
| 764 |
+ obj_type => "ITEM", |
| 765 |
+ name => "clientkey", |
| 766 |
+ menu => "root_admin_ldaps_server_aaa", |
| 767 |
+ cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL", |
| 768 |
+ user_level => "CLI_LEVEL_CONFIG", |
| 769 |
+ help_string => "Import PEM client key", |
| 770 |
+ function_name => "exauth_ldaps_server_client_key", |
| 771 |
+ function_args => [ |
| 772 |
+ { |
| 773 |
+ type => "STRING", |
| 774 |
+ name => "url", |
| 775 |
+ help_string => "FTP, TFTP or HTTP URL", |
| 776 |
+ optional => "YES", |
| 777 |
+ default_value => "\"\"", |
| 778 |
+ }, |
| 779 |
+ ], |
| 780 |
+ }, |
| 781 |
+ { |
| 782 |
+ obj_type => "ITEM", |
| 783 |
+ name => "rootca", |
| 784 |
+ menu => "root_admin_ldaps_server_aaa", |
| 785 |
+ cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL", |
| 786 |
+ user_level => "CLI_LEVEL_CONFIG", |
| 787 |
+ help_string => "Import CA certificate used for client authentication", |
| 788 |
+ function_name => "exauth_ldaps_server_client_rootca", |
| 789 |
+ function_args => [ |
| 790 |
+ { |
| 791 |
+ type => "STRING", |
| 792 |
+ name => "url", |
| 793 |
+ help_string => "FTP, TFTP or HTTP URL", |
| 794 |
+ optional => "YES", |
| 795 |
+ default_value => "\"\"", |
| 796 |
+ }, |
| 797 |
+ ], |
| 798 |
+ }, |
| 799 |
{ |
| 800 |
obj_type => "MENU", |
| 801 |
name => "authorize", |
| 802 |
Index: usr/click/lib/libpyexauth/pyexauth_build.py |
| 803 |
=================================================================== |
| 804 |
--- usr/click/lib/libpyexauth/pyexauth_build.py (revision 38360) |
| 805 |
+++ usr/click/lib/libpyexauth/pyexauth_build.py (working copy) |
| 806 |
@@ -33,7 +33,7 @@ |
| 807 |
""", |
| 808 |
include_dirs=["../libexauth", "../libpyauth"], |
| 809 |
library_dirs=tmp_library_dirs, |
| 810 |
- libraries=["ldap", "exauth", "fastlog", "bsd", "ssl", "pyauth", "crypt", "uinet_sysctl", "uinet_lite", "uinetnv", "rt"]) |
| 811 |
+ libraries=["ldap", "lber", "exauth", "fastlog", "bsd", "ssl", "crypto", "pyauth", "crypt", "uinet_sysctl", "uinet_lite", "uinetnv", "rt"]) |
| 812 |
|
| 813 |
if __name__ == "__main__": |
| 814 |
ffi.compile() |
| 815 |
Index: usr/click/lib/libssl_cli/ssl_cli.c |
| 816 |
=================================================================== |
| 817 |
--- usr/click/lib/libssl_cli/ssl_cli.c (revision 38360) |
| 818 |
+++ usr/click/lib/libssl_cli/ssl_cli.c (working copy) |
| 819 |
@@ -349,7 +349,6 @@ |
| 820 |
int fips_ssl_start_vhost_from_running_cfg(); |
| 821 |
int fips_ssl_start_vhost(int kernelLoginFlag); |
| 822 |
int fips_ssl_file_exist(char* sPath, char* vhost, char* domainname, int* csr_exist, int* sslConf_exist); |
| 823 |
- |
| 824 |
static int fips_init_turn_on_default_policy(Uint32 session_handle, BoardConfiguration *hsmConfig, int defaultLoginPrompt); |
| 825 |
static int fips_remove_ssl_files(void); |
| 826 |
static int fips_remove_name_passwd_files(void); |
| 827 |
@@ -13975,6 +13974,114 @@ |
| 828 |
return SUCCESS; |
| 829 |
} |
| 830 |
|
| 831 |
+int |
| 832 |
+ssl_import_ldaps_cert(char *certname, char *url, char *type) |
| 833 |
+{ |
| 834 |
+ char file[MAXPATHLEN]; |
| 835 |
+ char file_tmp[MAXPATHLEN]; |
| 836 |
+ char keypath[MAXPATHLEN]; |
| 837 |
+ /*Bug 23410, chenhb, 20090824*/ |
| 838 |
+ char agree[5]; |
| 839 |
+ int format = 0; |
| 840 |
+ /*Bug 23410, end*/ |
| 841 |
+ int certfd; |
| 842 |
+ int ret = 0; |
| 843 |
+ |
| 844 |
+ if(ssl_feactl_approved(SHOW_NON_INTEL_MSG) != 1){ |
| 845 |
+ return ERR_SSL_NOT_LICENSED; |
| 846 |
+ } |
| 847 |
+ |
| 848 |
+ snprintf(file, sizeof(file), "%s/%s", SSL_DATA_PATH, certname); |
| 849 |
+ |
| 850 |
+ if(file_exists(file) && cli_need_challenge()) { |
| 851 |
+ printf("You may overwrite an existing client certificate file.\nType YES to continue, NO to abort: "); |
| 852 |
+ fflush(stdout); |
| 853 |
+ bzero(agree, sizeof(agree)); |
| 854 |
+ if (read(STDIN_FILENO, agree, 4) <= 0) { |
| 855 |
+ return ERR_SSL_USER_ABORT; |
| 856 |
+ } |
| 857 |
+ |
| 858 |
+ /* Check if the user agrees to overwrite */ |
| 859 |
+ if (strncasecmp(agree, "YES", 3) != 0) { |
| 860 |
+ printf("Aborted client certificate by user\n"); |
| 861 |
+ do { |
| 862 |
+ } while (strchr(agree, '\n') == NULL && !(getchar() == '\n' && getchar() == '\n')); |
| 863 |
+ return ERR_SSL_USER_ABORT; |
| 864 |
+ } |
| 865 |
+ } |
| 866 |
+ |
| 867 |
+ /* Bug 23370, chenyl, 20090810 */ |
| 868 |
+ create_ssl_tmp_dir(); |
| 869 |
+ snprintf(file_tmp, sizeof(file_tmp), "%s/%s", SSL_TMP_DIR, certname); /*Bug 23410, chenhb, 20090824*/ |
| 870 |
+ /* Bug 23370, end */ |
| 871 |
+#if defined(__linux__) |
| 872 |
+ certfd = open(file_tmp, O_WRONLY|O_CREAT|O_TRUNC, |
| 873 |
+#else |
| 874 |
+ certfd = open(file_tmp, O_WRONLY|O_CREAT|O_TRUNC|O_EXLOCK, |
| 875 |
+#endif |
| 876 |
+ S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); |
| 877 |
+ if ( certfd < 0 ){ |
| 878 |
+ printf ("Error saving certificate file\n"); |
| 879 |
+ englog(ENGLOG_SSL, SSL_CLI_INFO, "could not save %s\n", |
| 880 |
+ file_tmp); |
| 881 |
+ return ERR_SSL_FILE_WRITE_FAILED; |
| 882 |
+ } |
| 883 |
+ |
| 884 |
+ if (url == NULL || *url == 0) { /* Import via stdin */ |
| 885 |
+ printf("Enter the certificate file in PEM format,\n" |
| 886 |
+ " use \"...\" on a single line, without quotes\n" |
| 887 |
+ " to terminate import\n"); |
| 888 |
+ |
| 889 |
+ fflush(stdout); |
| 890 |
+ ssl_import_via_stdin(certfd); |
| 891 |
+ } else { /* Import from remote or local file */ |
| 892 |
+ if (import_file(url, file_tmp) != SUCCESS) { |
| 893 |
+ close(certfd); |
| 894 |
+ return ERR_SSL_FILE_WRITE_FAILED; |
| 895 |
+ } |
| 896 |
+ } |
| 897 |
+ close(certfd); |
| 898 |
+ // Format check |
| 899 |
+ format = find_format(file_tmp); |
| 900 |
+ switch (format) { |
| 901 |
+ case FORMAT_PEM: |
| 902 |
+ ret = 0; |
| 903 |
+ break; |
| 904 |
+ default: |
| 905 |
+ ret = -1; |
| 906 |
+ break; |
| 907 |
+ } |
| 908 |
+ if(ret != 0 ) { |
| 909 |
+ printf("Certificate import failed..try again\n wrong format or wrong password\n"); |
| 910 |
+ unlink(file_tmp); |
| 911 |
+ return ERR_SSL_WRONG_FORMAT; |
| 912 |
+ } |
| 913 |
+ |
| 914 |
+ unlink(file); |
| 915 |
+ rename(file_tmp, file); |
| 916 |
+ |
| 917 |
+ printf("%s import successful\n", type); |
| 918 |
+ extra_file_add(file); |
| 919 |
+ |
| 920 |
+ return ERR_SSL_OK; |
| 921 |
+} |
| 922 |
+ |
| 923 |
+int |
| 924 |
+exauth_ldaps_server_client_cert(char *url) |
| 925 |
+{ |
| 926 |
+ return ssl_import_ldaps_cert("ldaps_client_cert.pem", url, "Client certficate"); |
| 927 |
+} |
| 928 |
+int |
| 929 |
+exauth_ldaps_server_client_rootca(char *url) |
| 930 |
+{ |
| 931 |
+ return ssl_import_ldaps_cert("ldaps_root_cert.pem", url, "Rootca certificate"); |
| 932 |
+} |
| 933 |
+int |
| 934 |
+exauth_ldaps_server_client_key(char *url) |
| 935 |
+{ |
| 936 |
+ return ssl_import_ldaps_cert("ldaps_client_key.pem", url, "Client key"); |
| 937 |
+} |
| 938 |
+ |
| 939 |
/* |
| 940 |
* Import SSL client certificate for SSL virtual host to be used for SSL virtual host. |
| 941 |
*/ |