Skip to content

Commit bbbc12b

Browse files
Merge pull request #26 from TrustedComputingGroup/ext_cleanup
Clean up unnecessary headers and handle BIO errors
2 parents 4f4c8cd + 2cdf020 commit bbbc12b

21 files changed

Lines changed: 456 additions & 340 deletions

crypto/x509/v3_aaa.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10-
#include <stdio.h>
11-
#include "internal/cryptlib.h"
1210
#include <openssl/asn1t.h>
1311
#include <openssl/x509v3.h>
14-
#include "ext_dat.h"
1512

1613
IMPLEMENT_ASN1_FUNCTIONS(ALLOWED_ATTRIBUTES_SYNTAX)
1714

@@ -41,24 +38,37 @@ static int i2r_ALLOWED_ATTRIBUTES_CHOICE(X509V3_EXT_METHOD *method,
4138

4239
switch (a->type) {
4340
case (AAA_ATTRIBUTE_TYPE):
44-
BIO_printf(out, "%*sAttribute Type: ", indent, "");
45-
i2a_ASN1_OBJECT(out, a->choice.attributeType);
46-
BIO_puts(out, "\n");
47-
break;
41+
if (BIO_printf(out, "%*sAttribute Type: ", indent, "") <= 0) {
42+
return 0;
43+
}
44+
if (i2a_ASN1_OBJECT(out, a->choice.attributeType) <= 0) {
45+
return 0;
46+
}
47+
return BIO_puts(out, "\n");
4848
case (AAA_ATTRIBUTE_VALUES):
4949
attr = a->choice.attributeTypeandValues;
5050
attr_obj = X509_ATTRIBUTE_get0_object(attr);
5151
attr_nid = OBJ_obj2nid(attr_obj);
52-
BIO_printf(out, "%*sAttribute Values: ", indent, "");
53-
i2a_ASN1_OBJECT(out, attr_obj);
54-
BIO_puts(out, "\n");
52+
if (BIO_printf(out, "%*sAttribute Values: ", indent, "") <= 0) {
53+
return 0;
54+
}
55+
if (i2a_ASN1_OBJECT(out, attr_obj) <= 0) {
56+
return 0;
57+
}
58+
if (BIO_puts(out, "\n") <= 0) {
59+
return 0;
60+
}
5561
for (j = 0; j < X509_ATTRIBUTE_count(attr); j++)
5662
{
5763
av = X509_ATTRIBUTE_get0_type(attr, j);
5864
if (BIO_printf(out, "%*s", indent + 4, "") <= 0)
5965
return 0;
60-
print_attribute_value(out, attr_nid, av);
61-
BIO_puts(out, "\n");
66+
if (print_attribute_value(out, attr_nid, av) <= 0) {
67+
return 0;
68+
}
69+
if (BIO_puts(out, "\n") <= 0) {
70+
return 0;
71+
}
6272
}
6373
// BIO_puts(out, "\n");
6474
break;
@@ -74,13 +84,23 @@ static int i2r_ALLOWED_ATTRIBUTES_ITEM(X509V3_EXT_METHOD *method,
7484
int i;
7585
ALLOWED_ATTRIBUTES_CHOICE *a;
7686
for (i = 0; i < sk_ALLOWED_ATTRIBUTES_CHOICE_num(aai->attributes); i++) {
77-
BIO_printf(out, "%*sAllowed Attribute Type or Values:\n", indent, "");
87+
if (BIO_printf(out, "%*sAllowed Attribute Type or Values:\n", indent, "") <= 0) {
88+
return 0;
89+
}
7890
a = sk_ALLOWED_ATTRIBUTES_CHOICE_value(aai->attributes, i);
79-
i2r_ALLOWED_ATTRIBUTES_CHOICE(method, a, out, indent + 4);
91+
if (i2r_ALLOWED_ATTRIBUTES_CHOICE(method, a, out, indent + 4) <= 0) {
92+
return 0;
93+
}
94+
}
95+
if (BIO_printf(out, "%*sHolder Domain: ", indent, "") <= 0) {
96+
return 0;
97+
}
98+
if (GENERAL_NAME_print(out, aai->holderDomain) <= 0) {
99+
return 0;
100+
}
101+
if (BIO_puts(out, "\n") <= 0) {
102+
return 0;
80103
}
81-
BIO_printf(out, "%*sHolder Domain: ", indent, "");
82-
GENERAL_NAME_print(out, aai->holderDomain);
83-
BIO_puts(out, "\n");
84104
return 1;
85105
}
86106

@@ -91,9 +111,13 @@ static int i2r_ALLOWED_ATTRIBUTES_SYNTAX(X509V3_EXT_METHOD *method,
91111
int i;
92112
ALLOWED_ATTRIBUTES_ITEM *aai;
93113
for (i = 0; i < sk_ALLOWED_ATTRIBUTES_ITEM_num(aaa); i++) {
94-
BIO_printf(out, "%*sAllowed Attributes:\n", indent, "");
114+
if (BIO_printf(out, "%*sAllowed Attributes:\n", indent, "") <= 0) {
115+
return 0;
116+
}
95117
aai = sk_ALLOWED_ATTRIBUTES_ITEM_value(aaa, i);
96-
i2r_ALLOWED_ATTRIBUTES_ITEM(method, aai, out, indent + 4);
118+
if (i2r_ALLOWED_ATTRIBUTES_ITEM(method, aai, out, indent + 4) <= 0) {
119+
return 0;
120+
}
97121
}
98122
return 1;
99123
}

crypto/x509/v3_ac_tgt.c

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10-
#include <stdio.h>
1110
#include "internal/cryptlib.h"
12-
#include <openssl/asn1.h>
1311
#include <openssl/asn1t.h>
14-
#include <openssl/conf.h>
1512
#include <openssl/x509v3.h>
16-
#include "ext_dat.h"
17-
#include "x509_local.h"
18-
#include "crypto/asn1.h"
1913

20-
static int i2r_OBJECT_DIGEST_INFO(X509V3_EXT_METHOD *method,
21-
OBJECT_DIGEST_INFO *odi,
22-
BIO *out, int indent);
2314
static int i2r_TARGET_CERT(X509V3_EXT_METHOD *method,
2415
TARGET_CERT *tc,
2516
BIO *out, int indent);
@@ -93,26 +84,40 @@ static int i2r_OBJECT_DIGEST_INFO(X509V3_EXT_METHOD *method,
9384
}
9485
switch (dot) {
9586
case (ODI_TYPE_PUBLIC_KEY):
96-
BIO_printf(out, "%*sDigest Type: Public Key\n", indent, "");
87+
if (BIO_printf(out, "%*sDigest Type: Public Key\n", indent, "") <= 0) {
88+
return 0;
89+
}
9790
break;
9891
case (ODI_TYPE_PUBLIC_KEY_CERT):
99-
BIO_printf(out, "%*sDigest Type: Public Key Certificate\n", indent, "");
92+
if (BIO_printf(out, "%*sDigest Type: Public Key Certificate\n", indent, "") <= 0) {
93+
return 0;
94+
}
10095
break;
10196
case (ODI_TYPE_OTHER): {
102-
BIO_printf(out, "%*sDigest Type: Other\n", indent, "");
97+
if (BIO_printf(out, "%*sDigest Type: Other\n", indent, "") <= 0) {
98+
return 0;
99+
}
103100
break;
104101
}
105102
}
106103
if (odi->otherObjectTypeID != NULL) {
107-
BIO_printf(out, "%*sDigest Type Identifier: ", indent, "");
108-
i2a_ASN1_OBJECT(out, odi->otherObjectTypeID);
109-
BIO_puts(out, "\n");
104+
if (BIO_printf(out, "%*sDigest Type Identifier: ", indent, "") <= 0) {
105+
return 0;
106+
}
107+
if (i2a_ASN1_OBJECT(out, odi->otherObjectTypeID) <= 0) {
108+
return 0;
109+
}
110+
if (BIO_puts(out, "\n") <= 0) {
111+
return 0;
112+
}
110113
}
111114
if (BIO_printf(out, "%*sSignature Algorithm: ", indent, "") <= 0)
112115
return 0;
113116
if (i2a_ASN1_OBJECT(out, odi->digestAlgorithm->algorithm) <= 0)
114117
return 0;
115-
BIO_puts(out, "\n");
118+
if (BIO_puts(out, "\n") <= 0) {
119+
return 0;
120+
}
116121
if (BIO_printf(out, "\n%*sSignature Value: ", indent, "") <= 0)
117122
return 0;
118123
sig_nid = OBJ_obj2nid(odi->digestAlgorithm->algorithm);
@@ -125,7 +130,7 @@ static int i2r_OBJECT_DIGEST_INFO(X509V3_EXT_METHOD *method,
125130
return ameth->sig_print(out, digalg, sig, indent + 4, 0);
126131
}
127132
}
128-
if (BIO_write(out, "\n", 1) != 1)
133+
if (BIO_write(out, "\n", 1) <= 0)
129134
return 0;
130135
if (sig)
131136
return X509_signature_dump(out, sig, indent + 4);
@@ -136,23 +141,38 @@ static int i2r_TARGET_CERT(X509V3_EXT_METHOD *method,
136141
TARGET_CERT *tc,
137142
BIO *out, int indent)
138143
{
139-
BIO_printf(out, "%*s", indent, "");
144+
if (BIO_printf(out, "%*s", indent, "") <= 0) {
145+
return 0;
146+
}
140147
if (tc->targetCertificate != NULL) {
141-
BIO_puts(out, "Target Certificate:\n");
142-
i2r_ISSUER_SERIAL(method, tc->targetCertificate, out, indent + 2);
148+
if (BIO_puts(out, "Target Certificate:\n") <= 0) {
149+
return 0;
150+
}
151+
if (i2r_ISSUER_SERIAL(method, tc->targetCertificate, out, indent + 2) <= 0) {
152+
return 0;
153+
}
143154
}
144155
if (tc->targetName != NULL) {
145156
// BIO_puts(out, "Target Name: ");
146-
BIO_printf(out, "%*sTarget Name: ", indent, "");
147-
GENERAL_NAME_print(out, tc->targetName);
148-
BIO_puts(out, "\n");
157+
if (BIO_printf(out, "%*sTarget Name: ", indent, "") <= 0) {
158+
return 0;
159+
}
160+
if (GENERAL_NAME_print(out, tc->targetName) <= 0) {
161+
return 0;
162+
}
163+
if (BIO_puts(out, "\n") <= 0) {
164+
return 0;
165+
}
149166
}
150167
if (tc->certDigestInfo != NULL) {
151-
BIO_printf(out, "%*sCertificate Digest Info:\n", indent, "");
152-
i2r_OBJECT_DIGEST_INFO(method, tc->certDigestInfo, out, indent + 2);
168+
if (BIO_printf(out, "%*sCertificate Digest Info:\n", indent, "") <= 0) {
169+
return 0;
170+
}
171+
if (i2r_OBJECT_DIGEST_INFO(method, tc->certDigestInfo, out, indent + 2) <= 0) {
172+
return 0;
173+
}
153174
}
154-
BIO_puts(out, "\n");
155-
return 1;
175+
return BIO_puts(out, "\n");
156176
}
157177

158178
static int i2r_TARGET(X509V3_EXT_METHOD *method,
@@ -161,19 +181,26 @@ static int i2r_TARGET(X509V3_EXT_METHOD *method,
161181
{
162182
switch (target->type) {
163183
case (TGT_TARGET_NAME):
164-
BIO_printf(out, "%*sTarget Name: ", indent, "");
165-
GENERAL_NAME_print(out, target->choice.targetName);
166-
BIO_puts(out, "\n");
167-
break;
184+
if (BIO_printf(out, "%*sTarget Name: ", indent, "") <= 0) {
185+
return 0;
186+
}
187+
if (GENERAL_NAME_print(out, target->choice.targetName) <= 0) {
188+
return 0;
189+
}
190+
return BIO_puts(out, "\n");
168191
case (TGT_TARGET_GROUP):
169-
BIO_printf(out, "%*sTarget Group: ", indent, "");
170-
GENERAL_NAME_print(out, target->choice.targetGroup);
171-
BIO_puts(out, "\n");
172-
break;
192+
if (BIO_printf(out, "%*sTarget Group: ", indent, "") <= 0) {
193+
return 0;
194+
}
195+
if (GENERAL_NAME_print(out, target->choice.targetGroup) <= 0) {
196+
return 0;
197+
}
198+
return BIO_puts(out, "\n");
173199
case (TGT_TARGET_CERT):
174-
BIO_printf(out, "%*sTarget Cert:\n", indent, "");
175-
i2r_TARGET_CERT(method, target->choice.targetCert, out, indent + 2);
176-
break;
200+
if (BIO_printf(out, "%*sTarget Cert:\n", indent, "") <= 0) {
201+
return 0;
202+
}
203+
return i2r_TARGET_CERT(method, target->choice.targetCert, out, indent + 2);
177204
}
178205
return 1;
179206
}
@@ -185,9 +212,13 @@ static int i2r_TARGETS(X509V3_EXT_METHOD *method,
185212
int i;
186213
TARGET *target;
187214
for (i = 0; i < sk_TARGET_num(targets); i++) {
188-
BIO_printf(out, "%*sTarget:\n", indent, "");
215+
if (BIO_printf(out, "%*sTarget:\n", indent, "") <= 0) {
216+
return 0;
217+
}
189218
target = sk_TARGET_value(targets, i);
190-
i2r_TARGET(method, target, out, indent + 2);
219+
if (i2r_TARGET(method, target, out, indent + 2) <= 0) {
220+
return 0;
221+
}
191222
}
192223
return 1;
193224
}
@@ -199,9 +230,13 @@ static int i2r_TARGETING_INFORMATION(X509V3_EXT_METHOD *method,
199230
int i;
200231
TARGETS *targets;
201232
for (i = 0; i < sk_TARGETS_num(tinfo); i++) {
202-
BIO_printf(out, "%*sTargets:\n", indent, "");
233+
if (BIO_printf(out, "%*sTargets:\n", indent, "") <= 0) {
234+
return 0;
235+
}
203236
targets = sk_TARGETS_value(tinfo, i);
204-
i2r_TARGETS(method, targets, out, indent + 2);
237+
if (i2r_TARGETS(method, targets, out, indent + 2) <= 0) {
238+
return 0;
239+
}
205240
}
206241
return 1;
207242
}

0 commit comments

Comments
 (0)