sl@0: /* crypto/asn1/t_req.c */ sl@0: /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) sl@0: * All rights reserved. sl@0: * sl@0: * This package is an SSL implementation written sl@0: * by Eric Young (eay@cryptsoft.com). sl@0: * The implementation was written so as to conform with Netscapes SSL. sl@0: * sl@0: * This library is free for commercial and non-commercial use as long as sl@0: * the following conditions are aheared to. The following conditions sl@0: * apply to all code found in this distribution, be it the RC4, RSA, sl@0: * lhash, DES, etc., code; not just the SSL code. The SSL documentation sl@0: * included with this distribution is covered by the same copyright terms sl@0: * except that the holder is Tim Hudson (tjh@cryptsoft.com). sl@0: * sl@0: * Copyright remains Eric Young's, and as such any Copyright notices in sl@0: * the code are not to be removed. sl@0: * If this package is used in a product, Eric Young should be given attribution sl@0: * as the author of the parts of the library used. sl@0: * This can be in the form of a textual message at program startup or sl@0: * in documentation (online or textual) provided with the package. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * "This product includes cryptographic software written by sl@0: * Eric Young (eay@cryptsoft.com)" sl@0: * The word 'cryptographic' can be left out if the rouines from the library sl@0: * being used are not cryptographic related :-). sl@0: * 4. If you include any Windows specific code (or a derivative thereof) from sl@0: * the apps directory (application code) you must include an acknowledgement: sl@0: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * The licence and distribution terms for any publically available version or sl@0: * derivative of this code cannot be changed. i.e. this code cannot simply be sl@0: * copied and put under another distribution licence sl@0: * [including the GNU Public Licence.] sl@0: */ sl@0: sl@0: #include sl@0: #include "cryptlib.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #ifndef OPENSSL_NO_RSA sl@0: #include sl@0: #endif sl@0: #ifndef OPENSSL_NO_DSA sl@0: #include sl@0: #endif sl@0: sl@0: #ifndef OPENSSL_NO_FP_API sl@0: EXPORT_C int X509_REQ_print_fp(FILE *fp, X509_REQ *x) sl@0: { sl@0: BIO *b; sl@0: int ret; sl@0: sl@0: if ((b=BIO_new(BIO_s_file())) == NULL) sl@0: { sl@0: X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); sl@0: return(0); sl@0: } sl@0: BIO_set_fp(b,fp,BIO_NOCLOSE); sl@0: ret=X509_REQ_print(b, x); sl@0: BIO_free(b); sl@0: return(ret); sl@0: } sl@0: #endif sl@0: sl@0: EXPORT_C int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) sl@0: { sl@0: unsigned long l; sl@0: int i; sl@0: const char *neg; sl@0: X509_REQ_INFO *ri; sl@0: EVP_PKEY *pkey; sl@0: STACK_OF(X509_ATTRIBUTE) *sk; sl@0: STACK_OF(X509_EXTENSION) *exts; sl@0: char mlch = ' '; sl@0: int nmindent = 0; sl@0: sl@0: if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { sl@0: mlch = '\n'; sl@0: nmindent = 12; sl@0: } sl@0: sl@0: if(nmflags == X509_FLAG_COMPAT) sl@0: nmindent = 16; sl@0: sl@0: sl@0: ri=x->req_info; sl@0: if(!(cflag & X509_FLAG_NO_HEADER)) sl@0: { sl@0: if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; sl@0: if (BIO_write(bp," Data:\n",10) <= 0) goto err; sl@0: } sl@0: if(!(cflag & X509_FLAG_NO_VERSION)) sl@0: { sl@0: neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; sl@0: l=0; sl@0: for (i=0; iversion->length; i++) sl@0: { l<<=8; l+=ri->version->data[i]; } sl@0: if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, sl@0: l) <= 0) sl@0: goto err; sl@0: } sl@0: if(!(cflag & X509_FLAG_NO_SUBJECT)) sl@0: { sl@0: if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; sl@0: if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; sl@0: if (BIO_write(bp,"\n",1) <= 0) goto err; sl@0: } sl@0: if(!(cflag & X509_FLAG_NO_PUBKEY)) sl@0: { sl@0: if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) sl@0: goto err; sl@0: if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) sl@0: goto err; sl@0: if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0) sl@0: goto err; sl@0: if (BIO_puts(bp, "\n") <= 0) sl@0: goto err; sl@0: sl@0: pkey=X509_REQ_get_pubkey(x); sl@0: if (pkey == NULL) sl@0: { sl@0: BIO_printf(bp,"%12sUnable to load Public Key\n",""); sl@0: ERR_print_errors(bp); sl@0: } sl@0: else sl@0: #ifndef OPENSSL_NO_RSA sl@0: if (pkey->type == EVP_PKEY_RSA) sl@0: { sl@0: BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", sl@0: BN_num_bits(pkey->pkey.rsa->n)); sl@0: RSA_print(bp,pkey->pkey.rsa,16); sl@0: } sl@0: else sl@0: #endif sl@0: #ifndef OPENSSL_NO_DSA sl@0: if (pkey->type == EVP_PKEY_DSA) sl@0: { sl@0: BIO_printf(bp,"%12sDSA Public Key:\n",""); sl@0: DSA_print(bp,pkey->pkey.dsa,16); sl@0: } sl@0: else sl@0: #endif sl@0: #ifndef OPENSSL_NO_EC sl@0: if (pkey->type == EVP_PKEY_EC) sl@0: { sl@0: BIO_printf(bp, "%12sEC Public Key: \n",""); sl@0: EC_KEY_print(bp, pkey->pkey.ec, 16); sl@0: } sl@0: else sl@0: #endif sl@0: BIO_printf(bp,"%12sUnknown Public Key:\n",""); sl@0: sl@0: EVP_PKEY_free(pkey); sl@0: } sl@0: sl@0: if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) sl@0: { sl@0: /* may not be */ sl@0: if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) sl@0: goto err; sl@0: sl@0: sk=x->req_info->attributes; sl@0: if (sk_X509_ATTRIBUTE_num(sk) == 0) sl@0: { sl@0: if(BIO_printf(bp,"%12sa0:00\n","") <= 0) sl@0: goto err; sl@0: } sl@0: else sl@0: { sl@0: for (i=0; iobject))) sl@0: continue; sl@0: if(BIO_printf(bp,"%12s","") <= 0) sl@0: goto err; sl@0: if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) sl@0: { sl@0: if (a->single) sl@0: { sl@0: t=a->value.single; sl@0: type=t->type; sl@0: bs=t->value.bit_string; sl@0: } sl@0: else sl@0: { sl@0: ii=0; sl@0: count=sk_ASN1_TYPE_num(a->value.set); sl@0: get_next: sl@0: at=sk_ASN1_TYPE_value(a->value.set,ii); sl@0: type=at->type; sl@0: bs=at->value.asn1_string; sl@0: } sl@0: } sl@0: for (j=25-j; j>0; j--) sl@0: if (BIO_write(bp," ",1) != 1) goto err; sl@0: if (BIO_puts(bp,":") <= 0) goto err; sl@0: if ( (type == V_ASN1_PRINTABLESTRING) || sl@0: (type == V_ASN1_T61STRING) || sl@0: (type == V_ASN1_IA5STRING)) sl@0: { sl@0: if (BIO_write(bp,(char *)bs->data,bs->length) sl@0: != bs->length) sl@0: goto err; sl@0: BIO_puts(bp,"\n"); sl@0: } sl@0: else sl@0: { sl@0: BIO_puts(bp,"unable to print attribute\n"); sl@0: } sl@0: if (++ii < count) goto get_next; sl@0: } sl@0: } sl@0: } sl@0: if(!(cflag & X509_FLAG_NO_EXTENSIONS)) sl@0: { sl@0: exts = X509_REQ_get_extensions(x); sl@0: if(exts) sl@0: { sl@0: BIO_printf(bp,"%8sRequested Extensions:\n",""); sl@0: for (i=0; ivalue); sl@0: } sl@0: if (BIO_write(bp,"\n",1) <= 0) goto err; sl@0: } sl@0: sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); sl@0: } sl@0: } sl@0: sl@0: if(!(cflag & X509_FLAG_NO_SIGDUMP)) sl@0: { sl@0: if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; sl@0: } sl@0: sl@0: return(1); sl@0: err: sl@0: X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); sl@0: return(0); sl@0: } sl@0: sl@0: EXPORT_C int X509_REQ_print(BIO *bp, X509_REQ *x) sl@0: { sl@0: return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); sl@0: }