summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-04-09 17:28:52 +0000
committertb <>2023-04-09 17:28:52 +0000
commit1a13fc28a37c78be82ff302230a5b50d3ea03d28 (patch)
tree184e59d041a24e4da0ea9f6223826675a78e818d /src
parent39985ed6a552d770366d2c19d9c5a7cb31a62141 (diff)
downloadopenbsd-1a13fc28a37c78be82ff302230a5b50d3ea03d28.tar.gz
openbsd-1a13fc28a37c78be82ff302230a5b50d3ea03d28.tar.bz2
openbsd-1a13fc28a37c78be82ff302230a5b50d3ea03d28.zip
Minor code cleanup
Unwrap a few awkwardly wrapped lines, drop redundant parentheses and add empty lines after some variable declarations. No change in the generated assembly.
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/openssl/x509.c73
1 files changed, 31 insertions, 42 deletions
diff --git a/src/usr.bin/openssl/x509.c b/src/usr.bin/openssl/x509.c
index 66cad3ab2c..e6d1ee915d 100644
--- a/src/usr.bin/openssl/x509.c
+++ b/src/usr.bin/openssl/x509.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509.c,v 1.31 2023/03/06 14:32:06 tb Exp $ */ 1/* $OpenBSD: x509.c,v 1.32 2023/04/09 17:28:52 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -772,10 +772,9 @@ x509_main(int argc, char **argv)
772 ERR_print_errors(bio_err); 772 ERR_print_errors(bio_err);
773 goto end; 773 goto end;
774 } 774 }
775 if ((cfg.CAkeyfile == NULL) && (cfg.CA_flag) && 775 if (cfg.CAkeyfile == NULL && cfg.CA_flag && cfg.CAformat == FORMAT_PEM) {
776 (cfg.CAformat == FORMAT_PEM)) {
777 cfg.CAkeyfile = cfg.CAfile; 776 cfg.CAkeyfile = cfg.CAfile;
778 } else if ((cfg.CA_flag) && (cfg.CAkeyfile == NULL)) { 777 } else if (cfg.CA_flag && cfg.CAkeyfile == NULL) {
779 BIO_printf(bio_err, 778 BIO_printf(bio_err,
780 "need to specify a CAkey if using the CA command\n"); 779 "need to specify a CAkey if using the CA command\n");
781 goto end; 780 goto end;
@@ -796,8 +795,8 @@ x509_main(int argc, char **argv)
796 goto end; 795 goto end;
797 } 796 }
798 if (cfg.extsect == NULL) { 797 if (cfg.extsect == NULL) {
799 cfg.extsect = NCONF_get_string(extconf, 798 cfg.extsect = NCONF_get_string(extconf, "default",
800 "default", "extensions"); 799 "extensions");
801 if (cfg.extsect == NULL) { 800 if (cfg.extsect == NULL) {
802 ERR_clear_error(); 801 ERR_clear_error();
803 cfg.extsect = "default"; 802 cfg.extsect = "default";
@@ -805,11 +804,9 @@ x509_main(int argc, char **argv)
805 } 804 }
806 X509V3_set_ctx_test(&ctx2); 805 X509V3_set_ctx_test(&ctx2);
807 X509V3_set_nconf(&ctx2, extconf); 806 X509V3_set_nconf(&ctx2, extconf);
808 if (!X509V3_EXT_add_nconf(extconf, &ctx2, cfg.extsect, 807 if (!X509V3_EXT_add_nconf(extconf, &ctx2, cfg.extsect, NULL)) {
809 NULL)) {
810 BIO_printf(bio_err, 808 BIO_printf(bio_err,
811 "Error Loading extension section %s\n", 809 "Error Loading extension section %s\n", cfg.extsect);
812 cfg.extsect);
813 ERR_print_errors(bio_err); 810 ERR_print_errors(bio_err);
814 goto end; 811 goto end;
815 } 812 }
@@ -869,8 +866,7 @@ x509_main(int argc, char **argv)
869 866
870 if (cfg.sno == NULL) { 867 if (cfg.sno == NULL) {
871 cfg.sno = ASN1_INTEGER_new(); 868 cfg.sno = ASN1_INTEGER_new();
872 if (cfg.sno == NULL || 869 if (cfg.sno == NULL || !rand_serial(NULL, cfg.sno))
873 !rand_serial(NULL, cfg.sno))
874 goto end; 870 goto end;
875 if (!X509_set_serialNumber(x, cfg.sno)) 871 if (!X509_set_serialNumber(x, cfg.sno))
876 goto end; 872 goto end;
@@ -897,15 +893,15 @@ x509_main(int argc, char **argv)
897 goto end; 893 goto end;
898 } 894 }
899 } else { 895 } else {
900 x = load_cert(bio_err, cfg.infile, cfg.informat, 896 x = load_cert(bio_err, cfg.infile, cfg.informat, NULL,
901 NULL, "Certificate"); 897 "Certificate");
902 } 898 }
903 if (x == NULL) 899 if (x == NULL)
904 goto end; 900 goto end;
905 901
906 if (cfg.CA_flag) { 902 if (cfg.CA_flag) {
907 xca = load_cert(bio_err, cfg.CAfile, 903 xca = load_cert(bio_err, cfg.CAfile, cfg.CAformat, NULL,
908 cfg.CAformat, NULL, "CA Certificate"); 904 "CA Certificate");
909 if (xca == NULL) 905 if (xca == NULL)
910 goto end; 906 goto end;
911 } 907 }
@@ -938,16 +934,14 @@ x509_main(int argc, char **argv)
938 934
939 if (cfg.trust != NULL) { 935 if (cfg.trust != NULL) {
940 for (i = 0; i < sk_ASN1_OBJECT_num(cfg.trust); i++) { 936 for (i = 0; i < sk_ASN1_OBJECT_num(cfg.trust); i++) {
941 cfg.objtmp = sk_ASN1_OBJECT_value( 937 cfg.objtmp = sk_ASN1_OBJECT_value(cfg.trust, i);
942 cfg.trust, i);
943 if (!X509_add1_trust_object(x, cfg.objtmp)) 938 if (!X509_add1_trust_object(x, cfg.objtmp))
944 goto end; 939 goto end;
945 } 940 }
946 } 941 }
947 if (cfg.reject != NULL) { 942 if (cfg.reject != NULL) {
948 for (i = 0; i < sk_ASN1_OBJECT_num(cfg.reject); i++) { 943 for (i = 0; i < sk_ASN1_OBJECT_num(cfg.reject); i++) {
949 cfg.objtmp = sk_ASN1_OBJECT_value( 944 cfg.objtmp = sk_ASN1_OBJECT_value(cfg.reject, i);
950 cfg.reject, i);
951 if (!X509_add1_reject_object(x, cfg.objtmp)) 945 if (!X509_add1_reject_object(x, cfg.objtmp))
952 goto end; 946 goto end;
953 } 947 }
@@ -956,12 +950,10 @@ x509_main(int argc, char **argv)
956 for (i = 1; i <= cfg.num; i++) { 950 for (i = 1; i <= cfg.num; i++) {
957 if (cfg.issuer == i) { 951 if (cfg.issuer == i) {
958 print_name(STDout, "issuer= ", 952 print_name(STDout, "issuer= ",
959 X509_get_issuer_name(x), 953 X509_get_issuer_name(x), cfg.nmflag);
960 cfg.nmflag);
961 } else if (cfg.subject == i) { 954 } else if (cfg.subject == i) {
962 print_name(STDout, "subject= ", 955 print_name(STDout, "subject= ",
963 X509_get_subject_name(x), 956 X509_get_subject_name(x), cfg.nmflag);
964 cfg.nmflag);
965 } else if (cfg.serial == i) { 957 } else if (cfg.serial == i) {
966 BIO_printf(STDout, "serial="); 958 BIO_printf(STDout, "serial=");
967 i2a_ASN1_INTEGER(STDout, 959 i2a_ASN1_INTEGER(STDout,
@@ -970,6 +962,7 @@ x509_main(int argc, char **argv)
970 } else if (cfg.next_serial == i) { 962 } else if (cfg.next_serial == i) {
971 BIGNUM *bnser; 963 BIGNUM *bnser;
972 ASN1_INTEGER *ser; 964 ASN1_INTEGER *ser;
965
973 ser = X509_get_serialNumber(x); 966 ser = X509_get_serialNumber(x);
974 if (ser == NULL) 967 if (ser == NULL)
975 goto end; 968 goto end;
@@ -989,10 +982,10 @@ x509_main(int argc, char **argv)
989 i2a_ASN1_INTEGER(out, ser); 982 i2a_ASN1_INTEGER(out, ser);
990 ASN1_INTEGER_free(ser); 983 ASN1_INTEGER_free(ser);
991 BIO_puts(out, "\n"); 984 BIO_puts(out, "\n");
992 } else if ((cfg.email == i) || 985 } else if (cfg.email == i || cfg.ocsp_uri == i) {
993 (cfg.ocsp_uri == i)) {
994 int j;
995 STACK_OF(OPENSSL_STRING) *emlst; 986 STACK_OF(OPENSSL_STRING) *emlst;
987 int j;
988
996 if (cfg.email == i) 989 if (cfg.email == i)
997 emlst = X509_get1_email(x); 990 emlst = X509_get1_email(x);
998 else 991 else
@@ -1033,6 +1026,7 @@ x509_main(int argc, char **argv)
1033 else if (cfg.pprint == i) { 1026 else if (cfg.pprint == i) {
1034 X509_PURPOSE *ptmp; 1027 X509_PURPOSE *ptmp;
1035 int j; 1028 int j;
1029
1036 BIO_printf(STDout, "Certificate purposes:\n"); 1030 BIO_printf(STDout, "Certificate purposes:\n");
1037 for (j = 0; j < X509_PURPOSE_get_count(); j++) { 1031 for (j = 0; j < X509_PURPOSE_get_count(); j++) {
1038 ptmp = X509_PURPOSE_get0(j); 1032 ptmp = X509_PURPOSE_get0(j);
@@ -1162,6 +1156,7 @@ x509_main(int argc, char **argv)
1162 goto end; 1156 goto end;
1163 } else if (cfg.startdate == i) { 1157 } else if (cfg.startdate == i) {
1164 ASN1_TIME *nB = X509_get_notBefore(x); 1158 ASN1_TIME *nB = X509_get_notBefore(x);
1159
1165 BIO_puts(STDout, "notBefore="); 1160 BIO_puts(STDout, "notBefore=");
1166 if (ASN1_time_parse(nB->data, nB->length, NULL, 1161 if (ASN1_time_parse(nB->data, nB->length, NULL,
1167 0) == -1) 1162 0) == -1)
@@ -1172,6 +1167,7 @@ x509_main(int argc, char **argv)
1172 BIO_puts(STDout, "\n"); 1167 BIO_puts(STDout, "\n");
1173 } else if (cfg.enddate == i) { 1168 } else if (cfg.enddate == i) {
1174 ASN1_TIME *nA = X509_get_notAfter(x); 1169 ASN1_TIME *nA = X509_get_notAfter(x);
1170
1175 BIO_puts(STDout, "notAfter="); 1171 BIO_puts(STDout, "notAfter=");
1176 if (ASN1_time_parse(nA->data, nA->length, NULL, 1172 if (ASN1_time_parse(nA->data, nA->length, NULL,
1177 0) == -1) 1173 0) == -1)
@@ -1201,12 +1197,10 @@ x509_main(int argc, char **argv)
1201 } 1197 }
1202 1198
1203 /* should be in the library */ 1199 /* should be in the library */
1204 } else if ((cfg.sign_flag == i) && 1200 } else if (cfg.sign_flag == i && cfg.x509req == 0) {
1205 (cfg.x509req == 0)) {
1206 BIO_printf(bio_err, "Getting Private key\n"); 1201 BIO_printf(bio_err, "Getting Private key\n");
1207 if (Upkey == NULL) { 1202 if (Upkey == NULL) {
1208 Upkey = load_key(bio_err, 1203 Upkey = load_key(bio_err, cfg.keyfile,
1209 cfg.keyfile,
1210 cfg.keyformat, 0, passin, 1204 cfg.keyformat, 0, passin,
1211 "Private key"); 1205 "Private key");
1212 if (Upkey == NULL) 1206 if (Upkey == NULL)
@@ -1219,20 +1213,16 @@ x509_main(int argc, char **argv)
1219 } else if (cfg.CA_flag == i) { 1213 } else if (cfg.CA_flag == i) {
1220 BIO_printf(bio_err, "Getting CA Private Key\n"); 1214 BIO_printf(bio_err, "Getting CA Private Key\n");
1221 if (cfg.CAkeyfile != NULL) { 1215 if (cfg.CAkeyfile != NULL) {
1222 CApkey = load_key(bio_err, 1216 CApkey = load_key(bio_err, cfg.CAkeyfile,
1223 cfg.CAkeyfile,
1224 cfg.CAkeyformat, 0, passin, 1217 cfg.CAkeyformat, 0, passin,
1225 "CA Private Key"); 1218 "CA Private Key");
1226 if (CApkey == NULL) 1219 if (CApkey == NULL)
1227 goto end; 1220 goto end;
1228 } 1221 }
1229 if (!x509_certify(ctx, cfg.CAfile, 1222 if (!x509_certify(ctx, cfg.CAfile, cfg.digest,
1230 cfg.digest, x, xca, CApkey, 1223 x, xca, CApkey, cfg.sigopts, cfg.CAserial,
1231 cfg.sigopts, cfg.CAserial, 1224 cfg.CA_createserial, cfg.days, cfg.clrext,
1232 cfg.CA_createserial, 1225 extconf, cfg.extsect, cfg.sno))
1233 cfg.days, cfg.clrext,
1234 extconf, cfg.extsect,
1235 cfg.sno))
1236 goto end; 1226 goto end;
1237 } else if (cfg.x509req == i) { 1227 } else if (cfg.x509req == i) {
1238 EVP_PKEY *pk; 1228 EVP_PKEY *pk;
@@ -1244,8 +1234,7 @@ x509_main(int argc, char **argv)
1244 "no request key file specified\n"); 1234 "no request key file specified\n");
1245 goto end; 1235 goto end;
1246 } else { 1236 } else {
1247 pk = load_key(bio_err, 1237 pk = load_key(bio_err, cfg.keyfile,
1248 cfg.keyfile,
1249 cfg.keyformat, 0, passin, 1238 cfg.keyformat, 0, passin,
1250 "request key"); 1239 "request key");
1251 if (pk == NULL) 1240 if (pk == NULL)