diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/t_req.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/t_req.c | 260 |
1 files changed, 151 insertions, 109 deletions
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c index 848c29a2dd..739f272ecf 100644 --- a/src/lib/libcrypto/asn1/t_req.c +++ b/src/lib/libcrypto/asn1/t_req.c | |||
| @@ -82,7 +82,7 @@ int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | |||
| 82 | } | 82 | } |
| 83 | #endif | 83 | #endif |
| 84 | 84 | ||
| 85 | int X509_REQ_print(BIO *bp, X509_REQ *x) | 85 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) |
| 86 | { | 86 | { |
| 87 | unsigned long l; | 87 | unsigned long l; |
| 88 | int i; | 88 | int i; |
| @@ -92,143 +92,185 @@ int X509_REQ_print(BIO *bp, X509_REQ *x) | |||
| 92 | STACK_OF(X509_ATTRIBUTE) *sk; | 92 | STACK_OF(X509_ATTRIBUTE) *sk; |
| 93 | STACK_OF(X509_EXTENSION) *exts; | 93 | STACK_OF(X509_EXTENSION) *exts; |
| 94 | char str[128]; | 94 | char str[128]; |
| 95 | char mlch = ' '; | ||
| 96 | int nmindent = 0; | ||
| 97 | |||
| 98 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | ||
| 99 | mlch = '\n'; | ||
| 100 | nmindent = 12; | ||
| 101 | } | ||
| 102 | |||
| 103 | if(nmflags == X509_FLAG_COMPAT) | ||
| 104 | nmindent = 16; | ||
| 105 | |||
| 95 | 106 | ||
| 96 | ri=x->req_info; | 107 | ri=x->req_info; |
| 97 | sprintf(str,"Certificate Request:\n"); | 108 | if(!(cflag & X509_FLAG_NO_HEADER)) |
| 98 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 99 | sprintf(str,"%4sData:\n",""); | ||
| 100 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 101 | |||
| 102 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | ||
| 103 | l=0; | ||
| 104 | for (i=0; i<ri->version->length; i++) | ||
| 105 | { l<<=8; l+=ri->version->data[i]; } | ||
| 106 | sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l); | ||
| 107 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 108 | sprintf(str,"%8sSubject: ",""); | ||
| 109 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 110 | |||
| 111 | X509_NAME_print(bp,ri->subject,16); | ||
| 112 | sprintf(str,"\n%8sSubject Public Key Info:\n",""); | ||
| 113 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 114 | i=OBJ_obj2nid(ri->pubkey->algor->algorithm); | ||
| 115 | sprintf(str,"%12sPublic Key Algorithm: %s\n","", | ||
| 116 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
| 117 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 118 | |||
| 119 | pkey=X509_REQ_get_pubkey(x); | ||
| 120 | #ifndef OPENSSL_NO_RSA | ||
| 121 | if (pkey != NULL && pkey->type == EVP_PKEY_RSA) | ||
| 122 | { | 109 | { |
| 123 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | 110 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; |
| 124 | BN_num_bits(pkey->pkey.rsa->n)); | 111 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
| 125 | RSA_print(bp,pkey->pkey.rsa,16); | ||
| 126 | } | 112 | } |
| 127 | else | 113 | if(!(cflag & X509_FLAG_NO_VERSION)) |
| 128 | #endif | ||
| 129 | #ifndef OPENSSL_NO_DSA | ||
| 130 | if (pkey != NULL && pkey->type == EVP_PKEY_DSA) | ||
| 131 | { | 114 | { |
| 132 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | 115 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; |
| 133 | DSA_print(bp,pkey->pkey.dsa,16); | 116 | l=0; |
| 117 | for (i=0; i<ri->version->length; i++) | ||
| 118 | { l<<=8; l+=ri->version->data[i]; } | ||
| 119 | sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l); | ||
| 120 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 134 | } | 121 | } |
| 135 | else | 122 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
| 136 | #endif | 123 | { |
| 137 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | 124 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
| 125 | if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; | ||
| 126 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 127 | } | ||
| 128 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | ||
| 129 | { | ||
| 130 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | ||
| 131 | goto err; | ||
| 132 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | ||
| 133 | goto err; | ||
| 134 | if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0) | ||
| 135 | goto err; | ||
| 136 | if (BIO_puts(bp, "\n") <= 0) | ||
| 137 | goto err; | ||
| 138 | 138 | ||
| 139 | if (pkey != NULL) | 139 | pkey=X509_REQ_get_pubkey(x); |
| 140 | EVP_PKEY_free(pkey); | 140 | if (pkey == NULL) |
| 141 | { | ||
| 142 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | ||
| 143 | ERR_print_errors(bp); | ||
| 144 | } | ||
| 145 | else | ||
| 146 | #ifndef OPENSSL_NO_RSA | ||
| 147 | if (pkey->type == EVP_PKEY_RSA) | ||
| 148 | { | ||
| 149 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
| 150 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 151 | RSA_print(bp,pkey->pkey.rsa,16); | ||
| 152 | } | ||
| 153 | else | ||
| 154 | #endif | ||
| 155 | #ifndef OPENSSL_NO_DSA | ||
| 156 | if (pkey->type == EVP_PKEY_DSA) | ||
| 157 | { | ||
| 158 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
| 159 | DSA_print(bp,pkey->pkey.dsa,16); | ||
| 160 | } | ||
| 161 | else | ||
| 162 | #endif | ||
| 163 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
| 141 | 164 | ||
| 142 | /* may not be */ | 165 | EVP_PKEY_free(pkey); |
| 143 | sprintf(str,"%8sAttributes:\n",""); | 166 | } |
| 144 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 145 | 167 | ||
| 146 | sk=x->req_info->attributes; | 168 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
| 147 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | ||
| 148 | { | 169 | { |
| 149 | sprintf(str,"%12sa0:00\n",""); | 170 | /* may not be */ |
| 171 | sprintf(str,"%8sAttributes:\n",""); | ||
| 150 | if (BIO_puts(bp,str) <= 0) goto err; | 172 | if (BIO_puts(bp,str) <= 0) goto err; |
| 151 | } | 173 | |
| 152 | else | 174 | sk=x->req_info->attributes; |
| 153 | { | 175 | if (sk_X509_ATTRIBUTE_num(sk) == 0) |
| 154 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
| 155 | { | 176 | { |
| 156 | ASN1_TYPE *at; | 177 | sprintf(str,"%12sa0:00\n",""); |
| 157 | X509_ATTRIBUTE *a; | ||
| 158 | ASN1_BIT_STRING *bs=NULL; | ||
| 159 | ASN1_TYPE *t; | ||
| 160 | int j,type=0,count=1,ii=0; | ||
| 161 | |||
| 162 | a=sk_X509_ATTRIBUTE_value(sk,i); | ||
| 163 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | ||
| 164 | continue; | ||
| 165 | sprintf(str,"%12s",""); | ||
| 166 | if (BIO_puts(bp,str) <= 0) goto err; | 178 | if (BIO_puts(bp,str) <= 0) goto err; |
| 167 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | 179 | } |
| 180 | else | ||
| 168 | { | 181 | { |
| 169 | if (a->single) | 182 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) |
| 170 | { | 183 | { |
| 171 | t=a->value.single; | 184 | ASN1_TYPE *at; |
| 172 | type=t->type; | 185 | X509_ATTRIBUTE *a; |
| 173 | bs=t->value.bit_string; | 186 | ASN1_BIT_STRING *bs=NULL; |
| 174 | } | 187 | ASN1_TYPE *t; |
| 175 | else | 188 | int j,type=0,count=1,ii=0; |
| 189 | |||
| 190 | a=sk_X509_ATTRIBUTE_value(sk,i); | ||
| 191 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | ||
| 192 | continue; | ||
| 193 | sprintf(str,"%12s",""); | ||
| 194 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 195 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | ||
| 176 | { | 196 | { |
| 177 | ii=0; | 197 | if (a->single) |
| 178 | count=sk_ASN1_TYPE_num(a->value.set); | 198 | { |
| 199 | t=a->value.single; | ||
| 200 | type=t->type; | ||
| 201 | bs=t->value.bit_string; | ||
| 202 | } | ||
| 203 | else | ||
| 204 | { | ||
| 205 | ii=0; | ||
| 206 | count=sk_ASN1_TYPE_num(a->value.set); | ||
| 179 | get_next: | 207 | get_next: |
| 180 | at=sk_ASN1_TYPE_value(a->value.set,ii); | 208 | at=sk_ASN1_TYPE_value(a->value.set,ii); |
| 181 | type=at->type; | 209 | type=at->type; |
| 182 | bs=at->value.asn1_string; | 210 | bs=at->value.asn1_string; |
| 211 | } | ||
| 212 | } | ||
| 213 | for (j=25-j; j>0; j--) | ||
| 214 | if (BIO_write(bp," ",1) != 1) goto err; | ||
| 215 | if (BIO_puts(bp,":") <= 0) goto err; | ||
| 216 | if ( (type == V_ASN1_PRINTABLESTRING) || | ||
| 217 | (type == V_ASN1_T61STRING) || | ||
| 218 | (type == V_ASN1_IA5STRING)) | ||
| 219 | { | ||
| 220 | if (BIO_write(bp,(char *)bs->data,bs->length) | ||
| 221 | != bs->length) | ||
| 222 | goto err; | ||
| 223 | BIO_puts(bp,"\n"); | ||
| 224 | } | ||
| 225 | else | ||
| 226 | { | ||
| 227 | BIO_puts(bp,"unable to print attribute\n"); | ||
| 228 | } | ||
| 229 | if (++ii < count) goto get_next; | ||
| 183 | } | 230 | } |
| 184 | } | 231 | } |
| 185 | for (j=25-j; j>0; j--) | 232 | } |
| 186 | if (BIO_write(bp," ",1) != 1) goto err; | 233 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
| 187 | if (BIO_puts(bp,":") <= 0) goto err; | 234 | { |
| 188 | if ( (type == V_ASN1_PRINTABLESTRING) || | 235 | exts = X509_REQ_get_extensions(x); |
| 189 | (type == V_ASN1_T61STRING) || | 236 | if(exts) |
| 190 | (type == V_ASN1_IA5STRING)) | 237 | { |
| 238 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | ||
| 239 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | ||
| 191 | { | 240 | { |
| 192 | if (BIO_write(bp,(char *)bs->data,bs->length) | 241 | ASN1_OBJECT *obj; |
| 193 | != bs->length) | 242 | X509_EXTENSION *ex; |
| 243 | int j; | ||
| 244 | ex=sk_X509_EXTENSION_value(exts, i); | ||
| 245 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
| 246 | obj=X509_EXTENSION_get_object(ex); | ||
| 247 | i2a_ASN1_OBJECT(bp,obj); | ||
| 248 | j=X509_EXTENSION_get_critical(ex); | ||
| 249 | if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0) | ||
| 194 | goto err; | 250 | goto err; |
| 195 | BIO_puts(bp,"\n"); | 251 | if(!X509V3_EXT_print(bp, ex, 0, 16)) |
| 196 | } | 252 | { |
| 197 | else | 253 | BIO_printf(bp, "%16s", ""); |
| 198 | { | 254 | M_ASN1_OCTET_STRING_print(bp,ex->value); |
| 199 | BIO_puts(bp,"unable to print attribute\n"); | 255 | } |
| 256 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 200 | } | 257 | } |
| 201 | if (++ii < count) goto get_next; | 258 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); |
| 202 | } | 259 | } |
| 203 | } | 260 | } |
| 204 | 261 | ||
| 205 | exts = X509_REQ_get_extensions(x); | 262 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) |
| 206 | if(exts) { | 263 | { |
| 207 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | 264 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; |
| 208 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) { | ||
| 209 | ASN1_OBJECT *obj; | ||
| 210 | X509_EXTENSION *ex; | ||
| 211 | int j; | ||
| 212 | ex=sk_X509_EXTENSION_value(exts, i); | ||
| 213 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
| 214 | obj=X509_EXTENSION_get_object(ex); | ||
| 215 | i2a_ASN1_OBJECT(bp,obj); | ||
| 216 | j=X509_EXTENSION_get_critical(ex); | ||
| 217 | if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0) | ||
| 218 | goto err; | ||
| 219 | if(!X509V3_EXT_print(bp, ex, 0, 16)) { | ||
| 220 | BIO_printf(bp, "%16s", ""); | ||
| 221 | M_ASN1_OCTET_STRING_print(bp,ex->value); | ||
| 222 | } | ||
| 223 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 224 | } | 265 | } |
| 225 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | ||
| 226 | } | ||
| 227 | |||
| 228 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | ||
| 229 | 266 | ||
| 230 | return(1); | 267 | return(1); |
| 231 | err: | 268 | err: |
| 232 | X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); | 269 | X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); |
| 233 | return(0); | 270 | return(0); |
| 234 | } | 271 | } |
| 272 | |||
| 273 | int X509_REQ_print(BIO *bp, X509_REQ *x) | ||
| 274 | { | ||
| 275 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
| 276 | } | ||
