Changeset 5821 for pjproject/trunk/pjlib/src/pjlib-test/ssl_sock.c
- Timestamp:
- Jul 15, 2018 2:09:23 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/ssl_sock.c
r5381 r5821 28 28 #define CERT_PRIVKEY_PASS "" 29 29 30 #define TEST_LOAD_FROM_FILES 1 30 31 31 32 #if INCLUDE_SSLSOCK_TEST … … 493 494 } 494 495 496 #if (TEST_LOAD_FROM_FILE==0) 497 static pj_status_t load_cert_to_buf(pj_pool_t *pool, const pj_str_t *file_name, 498 pj_ssl_cert_buffer *buf) 499 { 500 pj_status_t status; 501 pj_oshandle_t fd = 0; 502 pj_ssize_t size = (pj_ssize_t)pj_file_size(file_name->ptr); 503 504 status = pj_file_open(pool, file_name->ptr, PJ_O_RDONLY, &fd); 505 if (status != PJ_SUCCESS) 506 return status; 507 508 buf->ptr = (char*)pj_pool_zalloc(pool, size+1); 509 status = pj_file_read(fd, buf->ptr, &size); 510 buf->slen = size; 511 512 pj_file_close(fd); 513 fd = NULL; 514 return status; 515 } 516 #endif 495 517 496 518 static int echo_test(pj_ssl_sock_proto srv_proto, pj_ssl_sock_proto cli_proto, … … 550 572 /* Set server cert */ 551 573 { 552 pj_str_t tmp1, tmp2, tmp3, tmp4; 553 554 status = pj_ssl_cert_load_from_files(pool, 555 pj_strset2(&tmp1, (char*)CERT_CA_FILE), 556 pj_strset2(&tmp2, (char*)CERT_FILE), 557 pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE), 558 pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS), 574 pj_str_t ca_file = pj_str(CERT_CA_FILE); 575 pj_str_t cert_file = pj_str(CERT_FILE); 576 pj_str_t privkey_file = pj_str(CERT_PRIVKEY_FILE); 577 pj_str_t privkey_pass = pj_str(CERT_PRIVKEY_PASS); 578 579 #if (defined(TEST_LOAD_FROM_FILES) && TEST_LOAD_FROM_FILES==1) 580 status = pj_ssl_cert_load_from_files(pool, &ca_file, &cert_file, 581 &privkey_file, &privkey_pass, 559 582 &cert); 583 #else 584 pj_ssl_cert_buffer ca_buf, cert_buf, privkey_buf; 585 586 status = load_cert_to_buf(pool, &ca_file, &ca_buf); 587 if (status != PJ_SUCCESS) { 588 goto on_return; 589 } 590 591 status = load_cert_to_buf(pool, &cert_file, &cert_buf); 592 if (status != PJ_SUCCESS) { 593 goto on_return; 594 } 595 596 status = load_cert_to_buf(pool, &privkey_file, &privkey_buf); 597 if (status != PJ_SUCCESS) { 598 goto on_return; 599 } 600 601 status = pj_ssl_cert_load_from_buffer(pool, &ca_buf, &cert_buf, 602 &privkey_buf, &privkey_pass, 603 &cert); 604 #endif 560 605 if (status != PJ_SUCCESS) { 561 606 goto on_return; … … 614 659 615 660 if (!client_provide_cert) { 616 pj_str_t tmp1, tmp2; 617 618 pj_strset2(&tmp1, (char*)CERT_CA_FILE); 619 pj_strset2(&tmp2, NULL); 620 status = pj_ssl_cert_load_from_files(pool, 621 &tmp1, &tmp2, &tmp2, &tmp2, 622 &cert); 661 pj_str_t ca_file = pj_str(CERT_CA_FILE); 662 pj_str_t null_str = pj_str(""); 663 664 #if (defined(TEST_LOAD_FROM_FILES) && TEST_LOAD_FROM_FILES==1) 665 status = pj_ssl_cert_load_from_files(pool, &ca_file, &null_str, 666 &null_str, &null_str, &cert); 667 #else 668 pj_ssl_cert_buffer null_buf, ca_buf; 669 670 null_buf.slen = 0; 671 672 status = load_cert_to_buf(pool, &ca_file, &ca_buf); 623 673 if (status != PJ_SUCCESS) { 624 674 goto on_return; 625 675 } 676 677 status = pj_ssl_cert_load_from_buffer(pool, &ca_buf, &null_buf, 678 &null_buf, &null_str, &cert); 679 #endif 680 if (status != PJ_SUCCESS) { 681 goto on_return; 682 } 683 626 684 } 627 685 … … 825 883 /* Set cert */ 826 884 { 827 pj_str_t tmp1, tmp2, tmp3, tmp4; 828 status = pj_ssl_cert_load_from_files(pool, 829 pj_strset2(&tmp1, (char*)CERT_CA_FILE), 830 pj_strset2(&tmp2, (char*)CERT_FILE), 831 pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE), 832 pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS), 885 pj_str_t ca_file = pj_str(CERT_CA_FILE); 886 pj_str_t cert_file = pj_str(CERT_FILE); 887 pj_str_t privkey_file = pj_str(CERT_PRIVKEY_FILE); 888 pj_str_t privkey_pass = pj_str(CERT_PRIVKEY_PASS); 889 890 #if (defined(TEST_LOAD_FROM_FILES) && TEST_LOAD_FROM_FILES==1) 891 status = pj_ssl_cert_load_from_files(pool, &ca_file, &cert_file, 892 &privkey_file, &privkey_pass, 833 893 &cert); 894 #else 895 pj_ssl_cert_buffer ca_buf, cert_buf, privkey_buf; 896 897 status = load_cert_to_buf(pool, &ca_file, &ca_buf); 898 if (status != PJ_SUCCESS) { 899 goto on_return; 900 } 901 902 status = load_cert_to_buf(pool, &cert_file, &cert_buf); 903 if (status != PJ_SUCCESS) { 904 goto on_return; 905 } 906 907 status = load_cert_to_buf(pool, &privkey_file, &privkey_buf); 908 if (status != PJ_SUCCESS) { 909 goto on_return; 910 } 911 912 status = pj_ssl_cert_load_from_buffer(pool, &ca_buf, &cert_buf, 913 &privkey_buf, &privkey_pass, 914 &cert); 915 #endif 834 916 if (status != PJ_SUCCESS) { 835 917 goto on_return; … … 1132 1214 /* Set cert */ 1133 1215 { 1134 pj_str_t tmp1, tmp2, tmp3, tmp4; 1135 1136 status = pj_ssl_cert_load_from_files(pool, 1137 pj_strset2(&tmp1, (char*)CERT_CA_FILE), 1138 pj_strset2(&tmp2, (char*)CERT_FILE), 1139 pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE), 1140 pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS), 1216 pj_str_t ca_file = pj_str(CERT_CA_FILE); 1217 pj_str_t cert_file = pj_str(CERT_FILE); 1218 pj_str_t privkey_file = pj_str(CERT_PRIVKEY_FILE); 1219 pj_str_t privkey_pass = pj_str(CERT_PRIVKEY_PASS); 1220 1221 #if (defined(TEST_LOAD_FROM_FILES) && TEST_LOAD_FROM_FILES==1) 1222 status = pj_ssl_cert_load_from_files(pool, &ca_file, &cert_file, 1223 &privkey_file, &privkey_pass, 1141 1224 &cert); 1225 #else 1226 pj_ssl_cert_buffer ca_buf, cert_buf, privkey_buf; 1227 1228 status = load_cert_to_buf(pool, &ca_file, &ca_buf); 1229 if (status != PJ_SUCCESS) { 1230 goto on_return; 1231 } 1232 1233 status = load_cert_to_buf(pool, &cert_file, &cert_buf); 1234 if (status != PJ_SUCCESS) { 1235 goto on_return; 1236 } 1237 1238 status = load_cert_to_buf(pool, &privkey_file, &privkey_buf); 1239 if (status != PJ_SUCCESS) { 1240 goto on_return; 1241 } 1242 1243 status = pj_ssl_cert_load_from_buffer(pool, &ca_buf, &cert_buf, 1244 &privkey_buf, &privkey_pass, 1245 &cert); 1246 #endif 1142 1247 if (status != PJ_SUCCESS) { 1143 1248 goto on_return;
Note: See TracChangeset
for help on using the changeset viewer.