1327952Sdim/* crypto/x509/x509type.c */ 2193323Sed/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3353358Sdim * All rights reserved. 4353358Sdim * 5353358Sdim * This package is an SSL implementation written 6193323Sed * by Eric Young (eay@cryptsoft.com). 7193323Sed * The implementation was written so as to conform with Netscapes SSL. 8193323Sed * 9193323Sed * This library is free for commercial and non-commercial use as long as 10193323Sed * the following conditions are aheared to. The following conditions 11193323Sed * apply to all code found in this distribution, be it the RC4, RSA, 12193323Sed * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13193323Sed * included with this distribution is covered by the same copyright terms 14193323Sed * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15193323Sed * 16193323Sed * Copyright remains Eric Young's, and as such any Copyright notices in 17327952Sdim * the code are not to be removed. 18341825Sdim * If this package is used in a product, Eric Young should be given attribution 19321369Sdim * as the author of the parts of the library used. 20327952Sdim * This can be in the form of a textual message at program startup or 21327952Sdim * in documentation (online or textual) provided with the package. 22296417Sdim * 23353358Sdim * Redistribution and use in source and binary forms, with or without 24341825Sdim * modification, are permitted provided that the following conditions 25327952Sdim * are met: 26327952Sdim * 1. Redistributions of source code must retain the copyright 27249423Sdim * notice, this list of conditions and the following disclaimer. 28288943Sdim * 2. Redistributions in binary form must reproduce the above copyright 29276479Sdim * notice, this list of conditions and the following disclaimer in the 30249423Sdim * documentation and/or other materials provided with the distribution. 31327952Sdim * 3. All advertising materials mentioning features or use of this software 32327952Sdim * must display the following acknowledgement: 33327952Sdim * "This product includes cryptographic software written by 34327952Sdim * Eric Young (eay@cryptsoft.com)" 35327952Sdim * The word 'cryptographic' can be left out if the rouines from the library 36327952Sdim * being used are not cryptographic related :-). 37239462Sdim * 4. If you include any Windows specific code (or a derivative thereof) from 38193323Sed * the apps directory (application code) you must include an acknowledgement: 39193323Sed * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40327952Sdim * 41327952Sdim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43195340Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44309124Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45344779Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46314564Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47327952Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48327952Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49327952Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50327952Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51221345Sdim * SUCH DAMAGE. 52327952Sdim * 53344779Sdim * The licence and distribution terms for any publically available version or 54193323Sed * derivative of this code cannot be changed. i.e. this code cannot simply be 55327952Sdim * copied and put under another distribution licence 56243830Sdim * [including the GNU Public Licence.] 57243830Sdim */ 58193323Sed 59327952Sdim#include <stdio.h> 60327952Sdim#include "cryptlib.h" 61327952Sdim#include <openssl/evp.h> 62327952Sdim#include <openssl/objects.h> 63327952Sdim#include <openssl/x509.h> 64327952Sdim 65327952Sdimint X509_certificate_type(X509 *x, EVP_PKEY *pkey) 66327952Sdim{ 67327952Sdim EVP_PKEY *pk; 68327952Sdim int ret = 0, i; 69327952Sdim 70261991Sdim if (x == NULL) 71327952Sdim return (0); 72327952Sdim 73327952Sdim if (pkey == NULL) 74327952Sdim pk = X509_get_pubkey(x); 75327952Sdim else 76327952Sdim pk = pkey; 77327952Sdim 78327952Sdim if (pk == NULL) 79327952Sdim return (0); 80327952Sdim 81327952Sdim switch (pk->type) { 82327952Sdim case EVP_PKEY_RSA: 83327952Sdim ret = EVP_PK_RSA | EVP_PKT_SIGN; 84327952Sdim/* if (!sign only extension) */ 85327952Sdim ret |= EVP_PKT_ENC; 86327952Sdim break; 87327952Sdim case EVP_PKEY_DSA: 88327952Sdim ret = EVP_PK_DSA | EVP_PKT_SIGN; 89327952Sdim break; 90327952Sdim case EVP_PKEY_EC: 91327952Sdim ret = EVP_PK_EC | EVP_PKT_SIGN | EVP_PKT_EXCH; 92327952Sdim break; 93327952Sdim case EVP_PKEY_DH: 94327952Sdim ret = EVP_PK_DH | EVP_PKT_EXCH; 95327952Sdim break; 96327952Sdim case NID_id_GostR3410_94: 97327952Sdim case NID_id_GostR3410_2001: 98327952Sdim ret = EVP_PKT_EXCH | EVP_PKT_SIGN; 99327952Sdim break; 100327952Sdim default: 101327952Sdim break; 102327952Sdim } 103327952Sdim 104327952Sdim i = OBJ_obj2nid(x->sig_alg->algorithm); 105327952Sdim if (i && OBJ_find_sigid_algs(i, NULL, &i)) { 106327952Sdim 107327952Sdim switch (i) { 108327952Sdim case NID_rsaEncryption: 109327952Sdim case NID_rsa: 110193323Sed ret |= EVP_PKS_RSA; 111193323Sed break; 112193323Sed case NID_dsa: 113193323Sed case NID_dsa_2: 114309124Sdim ret |= EVP_PKS_DSA; 115309124Sdim break; 116309124Sdim case NID_X9_62_id_ecPublicKey: 117309124Sdim ret |= EVP_PKS_EC; 118223017Sdim break; 119223017Sdim default: 120223017Sdim break; 121243830Sdim } 122341825Sdim } 123344779Sdim 124193323Sed if (pkey == NULL) 125193323Sed EVP_PKEY_free(pk); 126193323Sed return (ret); 127193323Sed} 128193323Sed