860 if ((rfp = fopen(path, "r")) == NULL) {
861 goto cleanup;
862 }
863 if ((p12 = d2i_PKCS12_fp(rfp, NULL)) == NULL) {
864 errtype = 1;
865 goto cleanup;
866 }
867 i = sunw_PKCS12_parse(p12, WANBOOT_PASSPHRASE, DO_NONE, NULL, 0, NULL,
868 NULL, NULL, &i_anchors);
869 if (i <= 0) {
870 errtype = 1;
871 goto cleanup;
872 }
873 PKCS12_free(p12);
874 p12 = NULL;
875
876 /*
877 * Merge the two stacks of pkcs12 certs.
878 */
879 for (i = 0; i < sk_X509_num(i_anchors); i++) {
880 /* LINTED */
881 x = sk_X509_delete(i_anchors, i);
882 (void) sk_X509_push(o_anchors, x);
883 }
884
885 /*
886 * Create the pkcs12 structure from the modified input stack and
887 * then write out that structure.
888 */
889 p12 = sunw_PKCS12_create((const char *)WANBOOT_PASSPHRASE, NULL, NULL,
890 o_anchors);
891 if (p12 == NULL) {
892 goto cleanup;
893 }
894 rewind(wfp);
895 if (i2d_PKCS12_fp(wfp, p12) == 0) {
896 goto cleanup;
897 }
898
899 ret = WBCGI_FTW_CBCONT;
900 cleanup:
1073
1074 if ((rfp = fopen(path, "r")) == NULL) {
1075 goto cleanup;
1076 }
1077
1078 if ((p12 = d2i_PKCS12_fp(rfp, NULL)) == NULL) {
1079 errtype = 1;
1080 goto cleanup;
1081 }
1082 i = sunw_PKCS12_parse(p12, WANBOOT_PASSPHRASE, DO_NONE, NULL, 0, NULL,
1083 NULL, NULL, &certs);
1084 if (i <= 0) {
1085 errtype = 1;
1086 goto cleanup;
1087 }
1088
1089 PKCS12_free(p12);
1090 p12 = NULL;
1091
1092 for (i = 0; i < sk_X509_num(certs); i++) {
1093 /* LINTED */
1094 x = sk_X509_value(certs, i);
1095 if (!one_name(sunw_issuer_attrs(x, buf, sizeof (buf) - 1),
1096 nvl)) {
1097 goto cleanup;
1098 }
1099 }
1100
1101 ret = WBCGI_FTW_CBCONT;
1102 cleanup:
1103 if (ret == WBCGI_FTW_CBERR) {
1104 if (errtype == 1) {
1105 chars = snprintf(message, sizeof (message),
1106 "(internal PKCS12 error reading %s)", path);
1107 } else {
1108 chars = snprintf(message, sizeof (message),
1109 "error reading %s", path);
1110 }
1111 if (chars > 0 && chars <= sizeof (message)) {
1112 print_status(500, message);
1113 } else {
|
860 if ((rfp = fopen(path, "r")) == NULL) {
861 goto cleanup;
862 }
863 if ((p12 = d2i_PKCS12_fp(rfp, NULL)) == NULL) {
864 errtype = 1;
865 goto cleanup;
866 }
867 i = sunw_PKCS12_parse(p12, WANBOOT_PASSPHRASE, DO_NONE, NULL, 0, NULL,
868 NULL, NULL, &i_anchors);
869 if (i <= 0) {
870 errtype = 1;
871 goto cleanup;
872 }
873 PKCS12_free(p12);
874 p12 = NULL;
875
876 /*
877 * Merge the two stacks of pkcs12 certs.
878 */
879 for (i = 0; i < sk_X509_num(i_anchors); i++) {
880 x = sk_X509_delete(i_anchors, i);
881 (void) sk_X509_push(o_anchors, x);
882 }
883
884 /*
885 * Create the pkcs12 structure from the modified input stack and
886 * then write out that structure.
887 */
888 p12 = sunw_PKCS12_create((const char *)WANBOOT_PASSPHRASE, NULL, NULL,
889 o_anchors);
890 if (p12 == NULL) {
891 goto cleanup;
892 }
893 rewind(wfp);
894 if (i2d_PKCS12_fp(wfp, p12) == 0) {
895 goto cleanup;
896 }
897
898 ret = WBCGI_FTW_CBCONT;
899 cleanup:
1072
1073 if ((rfp = fopen(path, "r")) == NULL) {
1074 goto cleanup;
1075 }
1076
1077 if ((p12 = d2i_PKCS12_fp(rfp, NULL)) == NULL) {
1078 errtype = 1;
1079 goto cleanup;
1080 }
1081 i = sunw_PKCS12_parse(p12, WANBOOT_PASSPHRASE, DO_NONE, NULL, 0, NULL,
1082 NULL, NULL, &certs);
1083 if (i <= 0) {
1084 errtype = 1;
1085 goto cleanup;
1086 }
1087
1088 PKCS12_free(p12);
1089 p12 = NULL;
1090
1091 for (i = 0; i < sk_X509_num(certs); i++) {
1092 x = sk_X509_value(certs, i);
1093 if (!one_name(sunw_issuer_attrs(x, buf, sizeof (buf) - 1),
1094 nvl)) {
1095 goto cleanup;
1096 }
1097 }
1098
1099 ret = WBCGI_FTW_CBCONT;
1100 cleanup:
1101 if (ret == WBCGI_FTW_CBERR) {
1102 if (errtype == 1) {
1103 chars = snprintf(message, sizeof (message),
1104 "(internal PKCS12 error reading %s)", path);
1105 } else {
1106 chars = snprintf(message, sizeof (message),
1107 "error reading %s", path);
1108 }
1109 if (chars > 0 && chars <= sizeof (message)) {
1110 print_status(500, message);
1111 } else {
|