Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/t_req.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||
2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
3 | * | - | ||||||||||||
4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||
5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||
6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||
7 | * https://www.openssl.org/source/license.html | - | ||||||||||||
8 | */ | - | ||||||||||||
9 | - | |||||||||||||
10 | #include <stdio.h> | - | ||||||||||||
11 | #include "internal/cryptlib.h" | - | ||||||||||||
12 | #include <openssl/buffer.h> | - | ||||||||||||
13 | #include <openssl/bn.h> | - | ||||||||||||
14 | #include <openssl/objects.h> | - | ||||||||||||
15 | #include <openssl/x509.h> | - | ||||||||||||
16 | #include <openssl/x509v3.h> | - | ||||||||||||
17 | #include <openssl/rsa.h> | - | ||||||||||||
18 | #include <openssl/dsa.h> | - | ||||||||||||
19 | - | |||||||||||||
20 | #ifndef OPENSSL_NO_STDIO | - | ||||||||||||
21 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | - | ||||||||||||
22 | { | - | ||||||||||||
23 | BIO *b; | - | ||||||||||||
24 | int ret; | - | ||||||||||||
25 | - | |||||||||||||
26 | if ((b = BIO_new(BIO_s_file())) == NULL) {
| 0 | ||||||||||||
27 | X509err(X509_F_X509_REQ_PRINT_FP, ERR_R_BUF_LIB); | - | ||||||||||||
28 | return 0; never executed: return 0; | 0 | ||||||||||||
29 | } | - | ||||||||||||
30 | BIO_set_fp(b, fp, BIO_NOCLOSE); | - | ||||||||||||
31 | ret = X509_REQ_print(b, x); | - | ||||||||||||
32 | BIO_free(b); | - | ||||||||||||
33 | return ret; never executed: return ret; | 0 | ||||||||||||
34 | } | - | ||||||||||||
35 | #endif | - | ||||||||||||
36 | - | |||||||||||||
37 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, | - | ||||||||||||
38 | unsigned long cflag) | - | ||||||||||||
39 | { | - | ||||||||||||
40 | long l; | - | ||||||||||||
41 | int i; | - | ||||||||||||
42 | EVP_PKEY *pkey; | - | ||||||||||||
43 | STACK_OF(X509_EXTENSION) *exts; | - | ||||||||||||
44 | char mlch = ' '; | - | ||||||||||||
45 | int nmindent = 0; | - | ||||||||||||
46 | - | |||||||||||||
47 | if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
| 0-3 | ||||||||||||
48 | mlch = '\n'; | - | ||||||||||||
49 | nmindent = 12; | - | ||||||||||||
50 | } never executed: end of block | 0 | ||||||||||||
51 | - | |||||||||||||
52 | if (nmflags == X509_FLAG_COMPAT)
| 0-3 | ||||||||||||
53 | nmindent = 16; never executed: nmindent = 16; | 0 | ||||||||||||
54 | - | |||||||||||||
55 | if (!(cflag & X509_FLAG_NO_HEADER)) {
| 0-3 | ||||||||||||
56 | if (BIO_write(bp, "Certificate Request:\n", 21) <= 0)
| 0-3 | ||||||||||||
57 | goto err; never executed: goto err; | 0 | ||||||||||||
58 | if (BIO_write(bp, " Data:\n", 10) <= 0)
| 0-3 | ||||||||||||
59 | goto err; never executed: goto err; | 0 | ||||||||||||
60 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
61 | if (!(cflag & X509_FLAG_NO_VERSION)) {
| 0-3 | ||||||||||||
62 | l = X509_REQ_get_version(x); | - | ||||||||||||
63 | if (l >= 0 && l <= 2) {
| 0-3 | ||||||||||||
64 | if (BIO_printf(bp, "%8sVersion: %ld (0x%lx)\n", "", l + 1, (unsigned long)l) <= 0)
| 0-3 | ||||||||||||
65 | goto err; never executed: goto err; | 0 | ||||||||||||
66 | } else { executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
67 | if (BIO_printf(bp, "%8sVersion: Unknown (%ld)\n", "", l) <= 0)
| 0 | ||||||||||||
68 | goto err; never executed: goto err; | 0 | ||||||||||||
69 | } never executed: end of block | 0 | ||||||||||||
70 | } | - | ||||||||||||
71 | if (!(cflag & X509_FLAG_NO_SUBJECT)) {
| 0-3 | ||||||||||||
72 | if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
| 0-3 | ||||||||||||
73 | goto err; never executed: goto err; | 0 | ||||||||||||
74 | if (X509_NAME_print_ex(bp, X509_REQ_get_subject_name(x),
| 0-3 | ||||||||||||
75 | nmindent, nmflags) < 0)
| 0-3 | ||||||||||||
76 | goto err; never executed: goto err; | 0 | ||||||||||||
77 | if (BIO_write(bp, "\n", 1) <= 0)
| 0-3 | ||||||||||||
78 | goto err; never executed: goto err; | 0 | ||||||||||||
79 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
80 | if (!(cflag & X509_FLAG_NO_PUBKEY)) {
| 0-3 | ||||||||||||
81 | X509_PUBKEY *xpkey; | - | ||||||||||||
82 | ASN1_OBJECT *koid; | - | ||||||||||||
83 | if (BIO_write(bp, " Subject Public Key Info:\n", 33) <= 0)
| 0-3 | ||||||||||||
84 | goto err; never executed: goto err; | 0 | ||||||||||||
85 | if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
| 0-3 | ||||||||||||
86 | goto err; never executed: goto err; | 0 | ||||||||||||
87 | xpkey = X509_REQ_get_X509_PUBKEY(x); | - | ||||||||||||
88 | X509_PUBKEY_get0_param(&koid, NULL, NULL, NULL, xpkey); | - | ||||||||||||
89 | if (i2a_ASN1_OBJECT(bp, koid) <= 0)
| 0-3 | ||||||||||||
90 | goto err; never executed: goto err; | 0 | ||||||||||||
91 | if (BIO_puts(bp, "\n") <= 0)
| 0-3 | ||||||||||||
92 | goto err; never executed: goto err; | 0 | ||||||||||||
93 | - | |||||||||||||
94 | pkey = X509_REQ_get0_pubkey(x); | - | ||||||||||||
95 | if (pkey == NULL) {
| 0-3 | ||||||||||||
96 | if (BIO_printf(bp, "%12sUnable to load Public Key\n", "") <= 0)
| 0 | ||||||||||||
97 | goto err; never executed: goto err; | 0 | ||||||||||||
98 | ERR_print_errors(bp); | - | ||||||||||||
99 | } else { never executed: end of block | 0 | ||||||||||||
100 | if (EVP_PKEY_print_public(bp, pkey, 16, NULL) <= 0)
| 0-3 | ||||||||||||
101 | goto err; never executed: goto err; | 0 | ||||||||||||
102 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
103 | } | - | ||||||||||||
104 | - | |||||||||||||
105 | if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
| 0-3 | ||||||||||||
106 | /* may not be */ | - | ||||||||||||
107 | if (BIO_printf(bp, "%8sAttributes:\n", "") <= 0)
| 0-3 | ||||||||||||
108 | goto err; never executed: goto err; | 0 | ||||||||||||
109 | - | |||||||||||||
110 | if (X509_REQ_get_attr_count(x) == 0) {
| 1-2 | ||||||||||||
111 | if (BIO_printf(bp, "%12sa0:00\n", "") <= 0)
| 0-2 | ||||||||||||
112 | goto err; never executed: goto err; | 0 | ||||||||||||
113 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
114 | for (i = 0; i < X509_REQ_get_attr_count(x); i++) {
| 1 | ||||||||||||
115 | ASN1_TYPE *at; | - | ||||||||||||
116 | X509_ATTRIBUTE *a; | - | ||||||||||||
117 | ASN1_BIT_STRING *bs = NULL; | - | ||||||||||||
118 | ASN1_OBJECT *aobj; | - | ||||||||||||
119 | int j, type = 0, count = 1, ii = 0; | - | ||||||||||||
120 | - | |||||||||||||
121 | a = X509_REQ_get_attr(x, i); | - | ||||||||||||
122 | aobj = X509_ATTRIBUTE_get0_object(a); | - | ||||||||||||
123 | if (X509_REQ_extension_nid(OBJ_obj2nid(aobj)))
| 0-1 | ||||||||||||
124 | continue; executed 1 time by 1 test: continue; Executed by:
| 1 | ||||||||||||
125 | if (BIO_printf(bp, "%12s", "") <= 0)
| 0 | ||||||||||||
126 | goto err; never executed: goto err; | 0 | ||||||||||||
127 | if ((j = i2a_ASN1_OBJECT(bp, aobj)) > 0) {
| 0 | ||||||||||||
128 | ii = 0; | - | ||||||||||||
129 | count = X509_ATTRIBUTE_count(a); | - | ||||||||||||
130 | get_next: code before this statement never executed: get_next: | 0 | ||||||||||||
131 | at = X509_ATTRIBUTE_get0_type(a, ii); | - | ||||||||||||
132 | type = at->type; | - | ||||||||||||
133 | bs = at->value.asn1_string; | - | ||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||
135 | for (j = 25 - j; j > 0; j--)
| 0 | ||||||||||||
136 | if (BIO_write(bp, " ", 1) != 1)
| 0 | ||||||||||||
137 | goto err; never executed: goto err; | 0 | ||||||||||||
138 | if (BIO_puts(bp, ":") <= 0)
| 0 | ||||||||||||
139 | goto err; never executed: goto err; | 0 | ||||||||||||
140 | switch (type) { | - | ||||||||||||
141 | case V_ASN1_PRINTABLESTRING: never executed: case 19: | 0 | ||||||||||||
142 | case V_ASN1_T61STRING: never executed: case 20: | 0 | ||||||||||||
143 | case V_ASN1_NUMERICSTRING: never executed: case 18: | 0 | ||||||||||||
144 | case V_ASN1_UTF8STRING: never executed: case 12: | 0 | ||||||||||||
145 | case V_ASN1_IA5STRING: never executed: case 22: | 0 | ||||||||||||
146 | if (BIO_write(bp, (char *)bs->data, bs->length)
| 0 | ||||||||||||
147 | != bs->length)
| 0 | ||||||||||||
148 | goto err; never executed: goto err; | 0 | ||||||||||||
149 | if (BIO_puts(bp, "\n") <= 0)
| 0 | ||||||||||||
150 | goto err; never executed: goto err; | 0 | ||||||||||||
151 | break; never executed: break; | 0 | ||||||||||||
152 | default: never executed: default: | 0 | ||||||||||||
153 | if (BIO_puts(bp, "unable to print attribute\n") <= 0)
| 0 | ||||||||||||
154 | goto err; never executed: goto err; | 0 | ||||||||||||
155 | break; never executed: break; | 0 | ||||||||||||
156 | } | - | ||||||||||||
157 | if (++ii < count)
| 0 | ||||||||||||
158 | goto get_next; never executed: goto get_next; | 0 | ||||||||||||
159 | } never executed: end of block | 0 | ||||||||||||
160 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
161 | } | - | ||||||||||||
162 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
| 0-3 | ||||||||||||
163 | exts = X509_REQ_get_extensions(x); | - | ||||||||||||
164 | if (exts) {
| 1-2 | ||||||||||||
165 | if (BIO_printf(bp, "%8sRequested Extensions:\n", "") <= 0)
| 0-1 | ||||||||||||
166 | goto err; never executed: goto err; | 0 | ||||||||||||
167 | for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
| 0-1 | ||||||||||||
168 | ASN1_OBJECT *obj; | - | ||||||||||||
169 | X509_EXTENSION *ex; | - | ||||||||||||
170 | int critical; | - | ||||||||||||
171 | ex = sk_X509_EXTENSION_value(exts, i); | - | ||||||||||||
172 | if (BIO_printf(bp, "%12s", "") <= 0)
| 0 | ||||||||||||
173 | goto err; never executed: goto err; | 0 | ||||||||||||
174 | obj = X509_EXTENSION_get_object(ex); | - | ||||||||||||
175 | if (i2a_ASN1_OBJECT(bp, obj) <= 0)
| 0 | ||||||||||||
176 | goto err; never executed: goto err; | 0 | ||||||||||||
177 | critical = X509_EXTENSION_get_critical(ex); | - | ||||||||||||
178 | if (BIO_printf(bp, ": %s\n", critical ? "critical" : "") <= 0)
| 0 | ||||||||||||
179 | goto err; never executed: goto err; | 0 | ||||||||||||
180 | if (!X509V3_EXT_print(bp, ex, cflag, 16)) {
| 0 | ||||||||||||
181 | if (BIO_printf(bp, "%16s", "") <= 0
| 0 | ||||||||||||
182 | || ASN1_STRING_print(bp,
| 0 | ||||||||||||
183 | X509_EXTENSION_get_data(ex)) <= 0)
| 0 | ||||||||||||
184 | goto err; never executed: goto err; | 0 | ||||||||||||
185 | } never executed: end of block | 0 | ||||||||||||
186 | if (BIO_write(bp, "\n", 1) <= 0)
| 0 | ||||||||||||
187 | goto err; never executed: goto err; | 0 | ||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||
189 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | - | ||||||||||||
190 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
191 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
192 | - | |||||||||||||
193 | if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
| 0-3 | ||||||||||||
194 | const X509_ALGOR *sig_alg; | - | ||||||||||||
195 | const ASN1_BIT_STRING *sig; | - | ||||||||||||
196 | X509_REQ_get0_signature(x, &sig, &sig_alg); | - | ||||||||||||
197 | if (!X509_signature_print(bp, sig_alg, sig))
| 0-3 | ||||||||||||
198 | goto err; never executed: goto err; | 0 | ||||||||||||
199 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
200 | - | |||||||||||||
201 | return 1; executed 3 times by 1 test: return 1; Executed by:
| 3 | ||||||||||||
202 | err: | - | ||||||||||||
203 | X509err(X509_F_X509_REQ_PRINT_EX, ERR_R_BUF_LIB); | - | ||||||||||||
204 | return 0; never executed: return 0; | 0 | ||||||||||||
205 | } | - | ||||||||||||
206 | - | |||||||||||||
207 | int X509_REQ_print(BIO *bp, X509_REQ *x) | - | ||||||||||||
208 | { | - | ||||||||||||
209 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); never executed: return X509_REQ_print_ex(bp, x, 0, 0); | 0 | ||||||||||||
210 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |