t_req.c
Go to the documentation of this file.
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to. The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  * must display the following acknowledgement:
32  * "This product includes cryptographic software written by
33  * Eric Young (eay@cryptsoft.com)"
34  * The word 'cryptographic' can be left out if the rouines from the library
35  * being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  * the apps directory (application code) you must include an acknowledgement:
38  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed. i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #include <stdio.h>
58 
59 #include <openssl/bn.h>
60 #include <openssl/buffer.h>
61 #include <openssl/err.h>
62 #include <openssl/objects.h>
63 #include <openssl/x509.h>
64 #include <openssl/x509v3.h>
65 
66 #include "internal.h"
67 
68 
70  BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
71  if (bio == NULL) {
73  return 0;
74  }
75  int ret = X509_REQ_print(bio, x);
76  BIO_free(bio);
77  return ret;
78 }
79 
80 int X509_REQ_print_ex(BIO *bio, X509_REQ *x, unsigned long nmflags,
81  unsigned long cflag) {
82  long l;
83  EVP_PKEY *pkey;
85  char mlch = ' ';
86 
87  int nmindent = 0;
88 
89  if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
90  mlch = '\n';
91  nmindent = 12;
92  }
93 
94  if (nmflags == X509_FLAG_COMPAT) {
95  nmindent = 16;
96  }
97 
98  X509_REQ_INFO *ri = x->req_info;
99  if (!(cflag & X509_FLAG_NO_HEADER)) {
100  if (BIO_write(bio, "Certificate Request:\n", 21) <= 0 ||
101  BIO_write(bio, " Data:\n", 10) <= 0) {
102  goto err;
103  }
104  }
105  if (!(cflag & X509_FLAG_NO_VERSION)) {
107  if (BIO_printf(bio, "%8sVersion: %ld (0x%lx)\n", "", l + 1, l) <= 0) {
108  goto err;
109  }
110  }
111  if (!(cflag & X509_FLAG_NO_SUBJECT)) {
112  if (BIO_printf(bio, " Subject:%c", mlch) <= 0 ||
113  X509_NAME_print_ex(bio, ri->subject, nmindent, nmflags) < 0 ||
114  BIO_write(bio, "\n", 1) <= 0) {
115  goto err;
116  }
117  }
118  if (!(cflag & X509_FLAG_NO_PUBKEY)) {
119  if (BIO_write(bio, " Subject Public Key Info:\n", 33) <= 0 ||
120  BIO_printf(bio, "%12sPublic Key Algorithm: ", "") <= 0 ||
121  i2a_ASN1_OBJECT(bio, ri->pubkey->algor->algorithm) <= 0 ||
122  BIO_puts(bio, "\n") <= 0) {
123  goto err;
124  }
125 
126  pkey = X509_REQ_get_pubkey(x);
127  if (pkey == NULL) {
128  BIO_printf(bio, "%12sUnable to load Public Key\n", "");
129  ERR_print_errors(bio);
130  } else {
131  EVP_PKEY_print_public(bio, pkey, 16, NULL);
132  EVP_PKEY_free(pkey);
133  }
134  }
135 
136  if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
137  if (BIO_printf(bio, "%8sAttributes:\n", "") <= 0) {
138  goto err;
139  }
140 
141  sk = x->req_info->attributes;
142  if (sk_X509_ATTRIBUTE_num(sk) == 0) {
143  if (BIO_printf(bio, "%12sa0:00\n", "") <= 0) {
144  goto err;
145  }
146  } else {
147  size_t i;
148  for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
149  X509_ATTRIBUTE *a = sk_X509_ATTRIBUTE_value(sk, i);
151 
152  if (X509_REQ_extension_nid(OBJ_obj2nid(aobj))) {
153  continue;
154  }
155 
156  if (BIO_printf(bio, "%12s", "") <= 0) {
157  goto err;
158  }
159 
160  const int num_attrs = X509_ATTRIBUTE_count(a);
161  const int obj_str_len = i2a_ASN1_OBJECT(bio, aobj);
162  if (obj_str_len <= 0) {
163  if (BIO_puts(bio, "(Unable to print attribute ID.)\n") < 0) {
164  goto err;
165  } else {
166  continue;
167  }
168  }
169 
170  int j;
171  for (j = 0; j < num_attrs; j++) {
172  const ASN1_TYPE *at = X509_ATTRIBUTE_get0_type(a, j);
173  const int type = at->type;
175 
176  int k;
177  for (k = 25 - obj_str_len; k > 0; k--) {
178  if (BIO_write(bio, " ", 1) != 1) {
179  goto err;
180  }
181  }
182 
183  if (BIO_puts(bio, ":") <= 0) {
184  goto err;
185  }
186 
187  if (type == V_ASN1_PRINTABLESTRING ||
188  type == V_ASN1_UTF8STRING ||
189  type == V_ASN1_IA5STRING ||
190  type == V_ASN1_T61STRING) {
191  if (BIO_write(bio, (char *)bs->data, bs->length) != bs->length) {
192  goto err;
193  }
194  BIO_puts(bio, "\n");
195  } else {
196  BIO_puts(bio, "unable to print attribute\n");
197  }
198  }
199  }
200  }
201  }
202 
203  if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
205  if (exts) {
206  BIO_printf(bio, "%8sRequested Extensions:\n", "");
207 
208  size_t i;
209  for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
210  X509_EXTENSION *ex = sk_X509_EXTENSION_value(exts, i);
211  if (BIO_printf(bio, "%12s", "") <= 0) {
212  goto err;
213  }
215  i2a_ASN1_OBJECT(bio, obj);
216  const int is_critical = X509_EXTENSION_get_critical(ex);
217  if (BIO_printf(bio, ": %s\n", is_critical ? "critical" : "") <= 0) {
218  goto err;
219  }
220  if (!X509V3_EXT_print(bio, ex, cflag, 16)) {
221  BIO_printf(bio, "%16s", "");
223  }
224  if (BIO_write(bio, "\n", 1) <= 0) {
225  goto err;
226  }
227  }
228  sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
229  }
230  }
231 
232  if (!(cflag & X509_FLAG_NO_SIGDUMP) &&
233  !X509_signature_print(bio, x->sig_alg, x->signature)) {
234  goto err;
235  }
236 
237  return 1;
238 
239 err:
241  return 0;
242 }
243 
246 }
X509_NAME_print_ex
#define X509_NAME_print_ex
Definition: boringssl_prefix_symbols.h:2394
asn1_type_st::asn1_string
ASN1_STRING * asn1_string
Definition: asn1.h:1486
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
bn.h
X509_REQ_get_pubkey
#define X509_REQ_get_pubkey
Definition: boringssl_prefix_symbols.h:2448
BIO_new_fp
#define BIO_new_fp
Definition: boringssl_prefix_symbols.h:819
X509_REQ_get_extensions
#define X509_REQ_get_extensions
Definition: boringssl_prefix_symbols.h:2447
bio_st
Definition: bio.h:822
X509_algor_st::algorithm
ASN1_OBJECT * algorithm
Definition: x509.h:114
X509V3_EXT_print
#define X509V3_EXT_print
Definition: boringssl_prefix_symbols.h:2227
V_ASN1_PRINTABLESTRING
#define V_ASN1_PRINTABLESTRING
Definition: asn1.h:139
X509_FLAG_NO_HEADER
#define X509_FLAG_NO_HEADER
Definition: x509.h:188
OPENSSL_PUT_ERROR
#define OPENSSL_PUT_ERROR(library, reason)
Definition: err.h:423
objects.h
error_ref_leak.err
err
Definition: error_ref_leak.py:35
V_ASN1_UTF8STRING
#define V_ASN1_UTF8STRING
Definition: asn1.h:135
x509v3.h
X509_FLAG_NO_VERSION
#define X509_FLAG_NO_VERSION
Definition: x509.h:189
EVP_PKEY_print_public
#define EVP_PKEY_print_public
Definition: boringssl_prefix_symbols.h:1650
BIO_write
#define BIO_write
Definition: boringssl_prefix_symbols.h:870
X509_FLAG_NO_SIGDUMP
#define X509_FLAG_NO_SIGDUMP
Definition: x509.h:197
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
X509_extension_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:117
setup.k
k
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
ex
OPENSSL_EXPORT X509_EXTENSION * ex
Definition: x509.h:1418
X509_REQ_INFO::subject
X509_NAME * subject
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:167
asn1_string_st::data
unsigned char * data
Definition: asn1.h:546
BIO_printf
#define BIO_printf
Definition: boringssl_prefix_symbols.h:827
asn1_object_st
Definition: third_party/boringssl-with-bazel/src/crypto/asn1/internal.h:102
X509_signature_print
#define X509_signature_print
Definition: boringssl_prefix_symbols.h:2722
OBJ_obj2nid
#define OBJ_obj2nid
Definition: boringssl_prefix_symbols.h:1857
asn1_type_st::type
int type
Definition: asn1.h:1482
evp_pkey_st
Definition: evp.h:1046
STACK_OF
#define STACK_OF(type)
Definition: stack.h:125
asn1_string_st::length
int length
Definition: asn1.h:544
req
static uv_connect_t req
Definition: test-connection-fail.c:30
X509_EXTENSION_get_object
#define X509_EXTENSION_get_object
Definition: boringssl_prefix_symbols.h:2339
XN_FLAG_SEP_MULTILINE
#define XN_FLAG_SEP_MULTILINE
Definition: x509.h:212
X509_REQ_INFO::pubkey
X509_PUBKEY * pubkey
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:168
X509_ATTRIBUTE_get0_type
#define X509_ATTRIBUTE_get0_type
Definition: boringssl_prefix_symbols.h:2268
X509_EXTENSION_get_data
#define X509_EXTENSION_get_data
Definition: boringssl_prefix_symbols.h:2338
EVP_PKEY_free
#define EVP_PKEY_free
Definition: boringssl_prefix_symbols.h:1625
err.h
X509_REQ_INFO
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:164
X509_req_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:175
X509_REQ_get_version
#define X509_REQ_get_version
Definition: boringssl_prefix_symbols.h:2451
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
internal.h
X509_ATTRIBUTE_count
#define X509_ATTRIBUTE_count
Definition: boringssl_prefix_symbols.h:2259
X509_FLAG_NO_EXTENSIONS
#define X509_FLAG_NO_EXTENSIONS
Definition: x509.h:196
X509_EXTENSION_free
#define X509_EXTENSION_free
Definition: boringssl_prefix_symbols.h:2336
ERR_R_BUF_LIB
#define ERR_R_BUF_LIB
Definition: err.h:335
x509_attributes_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:104
V_ASN1_IA5STRING
#define V_ASN1_IA5STRING
Definition: asn1.h:143
buffer.h
V_ASN1_T61STRING
#define V_ASN1_T61STRING
Definition: asn1.h:140
BIO_free
#define BIO_free
Definition: boringssl_prefix_symbols.h:787
X509_FLAG_NO_SUBJECT
#define X509_FLAG_NO_SUBJECT
Definition: x509.h:194
X509_FLAG_NO_ATTRIBUTES
#define X509_FLAG_NO_ATTRIBUTES
Definition: x509.h:199
i2a_ASN1_OBJECT
#define i2a_ASN1_OBJECT
Definition: boringssl_prefix_symbols.h:3172
benchmark.FILE
FILE
Definition: benchmark.py:21
x509_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:139
X509_pubkey_st::algor
X509_ALGOR * algor
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:83
X509_REQ_extension_nid
#define X509_REQ_extension_nid
Definition: boringssl_prefix_symbols.h:2439
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
XN_FLAG_SEP_MASK
#define XN_FLAG_SEP_MASK
Definition: x509.h:206
BIO_puts
#define BIO_puts
Definition: boringssl_prefix_symbols.h:830
X509_FLAG_NO_PUBKEY
#define X509_FLAG_NO_PUBKEY
Definition: x509.h:195
asn1_type_st::value
union asn1_type_st::@361 value
BIO_NOCLOSE
#define BIO_NOCLOSE
Definition: bio.h:373
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
X509_REQ_print
int X509_REQ_print(BIO *bio, X509_REQ *req)
Definition: t_req.c:244
asn1_type_st
Definition: asn1.h:1481
run_grpclb_interop_tests.l
dictionary l
Definition: run_grpclb_interop_tests.py:410
X509_EXTENSION_get_critical
#define X509_EXTENSION_get_critical
Definition: boringssl_prefix_symbols.h:2337
ASN1_STRING_print
#define ASN1_STRING_print
Definition: boringssl_prefix_symbols.h:685
XN_FLAG_COMPAT
#define XN_FLAG_COMPAT
Definition: x509.h:208
X509_REQ_print_ex
int X509_REQ_print_ex(BIO *bio, X509_REQ *x, unsigned long nmflags, unsigned long cflag)
Definition: t_req.c:80
X509_ATTRIBUTE_get0_object
#define X509_ATTRIBUTE_get0_object
Definition: boringssl_prefix_symbols.h:2267
X509_FLAG_COMPAT
#define X509_FLAG_COMPAT
Definition: x509.h:187
X509_REQ_print_fp
int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
Definition: t_req.c:69
asn1_string_st
Definition: asn1.h:543
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
x509.h
ERR_print_errors
#define ERR_print_errors
Definition: boringssl_prefix_symbols.h:1435


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:29