1 // Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <openssl/asn1.h>
16 #include <openssl/bio.h>
17 #include <openssl/mem.h>
18 #include <openssl/obj.h>
19 #include <openssl/x509.h>
20 
21 #include "internal.h"
22 
23 
24 // X509_CERT_AUX and string set routines
25 
X509_CERT_AUX_print(BIO * out,X509_CERT_AUX * aux,int indent)26 int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) {
27   char oidstr[80], first;
28   size_t i;
29   int j;
30   if (!aux) {
31     return 1;
32   }
33   if (aux->trust) {
34     first = 1;
35     BIO_printf(out, "%*sTrusted Uses:\n%*s", indent, "", indent + 2, "");
36     for (i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
37       if (!first) {
38         BIO_puts(out, ", ");
39       } else {
40         first = 0;
41       }
42       OBJ_obj2txt(oidstr, sizeof oidstr, sk_ASN1_OBJECT_value(aux->trust, i),
43                   0);
44       BIO_puts(out, oidstr);
45     }
46     BIO_puts(out, "\n");
47   } else {
48     BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
49   }
50   if (aux->reject) {
51     first = 1;
52     BIO_printf(out, "%*sRejected Uses:\n%*s", indent, "", indent + 2, "");
53     for (i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
54       if (!first) {
55         BIO_puts(out, ", ");
56       } else {
57         first = 0;
58       }
59       OBJ_obj2txt(oidstr, sizeof oidstr, sk_ASN1_OBJECT_value(aux->reject, i),
60                   0);
61       BIO_puts(out, oidstr);
62     }
63     BIO_puts(out, "\n");
64   } else {
65     BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
66   }
67   if (aux->alias) {
68     BIO_printf(out, "%*sAlias: %.*s\n", indent, "", aux->alias->length,
69                aux->alias->data);
70   }
71   if (aux->keyid) {
72     BIO_printf(out, "%*sKey Id: ", indent, "");
73     for (j = 0; j < aux->keyid->length; j++) {
74       BIO_printf(out, "%s%02X", j ? ":" : "", aux->keyid->data[j]);
75     }
76     BIO_write(out, "\n", 1);
77   }
78   return 1;
79 }
80