x509_set.c revision 59191
169800Stomsoft/* crypto/x509/x509_set.c */ 269800Stomsoft/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 369800Stomsoft * All rights reserved. 469800Stomsoft * 569800Stomsoft * This package is an SSL implementation written 669800Stomsoft * by Eric Young (eay@cryptsoft.com). 769800Stomsoft * The implementation was written so as to conform with Netscapes SSL. 869800Stomsoft * 969800Stomsoft * This library is free for commercial and non-commercial use as long as 1069800Stomsoft * the following conditions are aheared to. The following conditions 1169800Stomsoft * apply to all code found in this distribution, be it the RC4, RSA, 1269800Stomsoft * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1369800Stomsoft * included with this distribution is covered by the same copyright terms 1469800Stomsoft * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1569800Stomsoft * 1669800Stomsoft * Copyright remains Eric Young's, and as such any Copyright notices in 1769800Stomsoft * the code are not to be removed. 1869800Stomsoft * If this package is used in a product, Eric Young should be given attribution 1969800Stomsoft * as the author of the parts of the library used. 2069800Stomsoft * This can be in the form of a textual message at program startup or 2169800Stomsoft * in documentation (online or textual) provided with the package. 2269800Stomsoft * 2369800Stomsoft * Redistribution and use in source and binary forms, with or without 2469800Stomsoft * modification, are permitted provided that the following conditions 2569800Stomsoft * are met: 2669800Stomsoft * 1. Redistributions of source code must retain the copyright 2769800Stomsoft * notice, this list of conditions and the following disclaimer. 2869800Stomsoft * 2. Redistributions in binary form must reproduce the above copyright 2969800Stomsoft * notice, this list of conditions and the following disclaimer in the 3069800Stomsoft * documentation and/or other materials provided with the distribution. 3169800Stomsoft * 3. All advertising materials mentioning features or use of this software 3269800Stomsoft * must display the following acknowledgement: 3369800Stomsoft * "This product includes cryptographic software written by 3469800Stomsoft * Eric Young (eay@cryptsoft.com)" 3569800Stomsoft * The word 'cryptographic' can be left out if the rouines from the library 3669800Stomsoft * being used are not cryptographic related :-). 3769800Stomsoft * 4. If you include any Windows specific code (or a derivative thereof) from 3869926Stomsoft * the apps directory (application code) you must include an acknowledgement: 3969800Stomsoft * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4069800Stomsoft * 4169800Stomsoft * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4269800Stomsoft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4369800Stomsoft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4469926Stomsoft * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4569800Stomsoft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4669800Stomsoft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4769800Stomsoft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4869800Stomsoft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4969800Stomsoft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5069800Stomsoft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5169800Stomsoft * SUCH DAMAGE. 5269800Stomsoft * 5369800Stomsoft * The licence and distribution terms for any publically available version or 5469800Stomsoft * derivative of this code cannot be changed. i.e. this code cannot simply be 5569800Stomsoft * copied and put under another distribution licence 5669800Stomsoft * [including the GNU Public Licence.] 5769800Stomsoft */ 5869800Stomsoft 5969800Stomsoft#include <stdio.h> 6069800Stomsoft#include "cryptlib.h" 6169800Stomsoft#include <openssl/asn1.h> 6269800Stomsoft#include <openssl/objects.h> 6369800Stomsoft#include <openssl/evp.h> 6469800Stomsoft#include <openssl/x509.h> 6569800Stomsoft 6669800Stomsoftint X509_set_version(X509 *x, long version) 6769800Stomsoft { 6869800Stomsoft if (x == NULL) return(0); 6969800Stomsoft if (x->cert_info->version == NULL) 7069800Stomsoft { 7169800Stomsoft if ((x->cert_info->version=M_ASN1_INTEGER_new()) == NULL) 7269800Stomsoft return(0); 7369800Stomsoft } 7492743Srwatson return(ASN1_INTEGER_set(x->cert_info->version,version)); 7592743Srwatson } 7692743Srwatson 7792743Srwatsonint X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial) 7869800Stomsoft { 7969800Stomsoft ASN1_INTEGER *in; 8069800Stomsoft 8169800Stomsoft if (x == NULL) return(0); 8269800Stomsoft in=x->cert_info->serialNumber; 8369800Stomsoft if (in != serial) 8469800Stomsoft { 8569800Stomsoft in=M_ASN1_INTEGER_dup(serial); 8669800Stomsoft if (in != NULL) 8769800Stomsoft { 8869800Stomsoft M_ASN1_INTEGER_free(x->cert_info->serialNumber); 8969800Stomsoft x->cert_info->serialNumber=in; 9069800Stomsoft } 9169800Stomsoft } 9269800Stomsoft return(in != NULL); 9369800Stomsoft } 9469800Stomsoft 9569800Stomsoftint X509_set_issuer_name(X509 *x, X509_NAME *name) 9669800Stomsoft { 9769800Stomsoft if ((x == NULL) || (x->cert_info == NULL)) return(0); 9869800Stomsoft return(X509_NAME_set(&x->cert_info->issuer,name)); 9969800Stomsoft } 10069800Stomsoft 10169800Stomsoftint X509_set_subject_name(X509 *x, X509_NAME *name) 10269800Stomsoft { 10369800Stomsoft if ((x == NULL) || (x->cert_info == NULL)) return(0); 10469800Stomsoft return(X509_NAME_set(&x->cert_info->subject,name)); 10569800Stomsoft } 10669800Stomsoft 10769800Stomsoftint X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm) 10869800Stomsoft { 10969800Stomsoft ASN1_UTCTIME *in; 11069800Stomsoft 11169800Stomsoft if ((x == NULL) || (x->cert_info->validity == NULL)) return(0); 11269800Stomsoft in=x->cert_info->validity->notBefore; 11369800Stomsoft if (in != tm) 11469800Stomsoft { 11569800Stomsoft in=M_ASN1_UTCTIME_dup(tm); 11669800Stomsoft if (in != NULL) 11769800Stomsoft { 11869800Stomsoft M_ASN1_UTCTIME_free(x->cert_info->validity->notBefore); 11969800Stomsoft x->cert_info->validity->notBefore=in; 12069800Stomsoft } 12169800Stomsoft } 12269800Stomsoft return(in != NULL); 12369800Stomsoft } 12469800Stomsoft 12569800Stomsoftint X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm) 12669800Stomsoft { 12769800Stomsoft ASN1_UTCTIME *in; 12869800Stomsoft 12969800Stomsoft if ((x == NULL) || (x->cert_info->validity == NULL)) return(0); 13069800Stomsoft in=x->cert_info->validity->notAfter; 13169800Stomsoft if (in != tm) 13269800Stomsoft { 13369800Stomsoft in=M_ASN1_UTCTIME_dup(tm); 13469800Stomsoft if (in != NULL) 13569800Stomsoft { 13669800Stomsoft M_ASN1_UTCTIME_free(x->cert_info->validity->notAfter); 13769800Stomsoft x->cert_info->validity->notAfter=in; 13869800Stomsoft } 13969800Stomsoft } 14069800Stomsoft return(in != NULL); 14169800Stomsoft } 14269800Stomsoft 14369800Stomsoftint X509_set_pubkey(X509 *x, EVP_PKEY *pkey) 14469800Stomsoft { 14569800Stomsoft if ((x == NULL) || (x->cert_info == NULL)) return(0); 14669800Stomsoft return(X509_PUBKEY_set(&(x->cert_info->key),pkey)); 14769800Stomsoft } 14869800Stomsoft 14969800Stomsoft 15069800Stomsoft 15169800Stomsoft