ext/openssl/ossl_config.c

Go to the documentation of this file.
00001 /*
00002  * $Id: ossl_config.c 43667 2013-11-13 09:34:08Z zzak $
00003  * 'OpenSSL for Ruby' project
00004  * Copyright (C) 2001-2002  Michal Rokos <m.rokos@sh.cvut.cz>
00005  * All rights reserved.
00006  */
00007 /*
00008  * This program is licenced under the same licence as Ruby.
00009  * (See the file 'LICENCE'.)
00010  */
00011 #include "ossl.h"
00012 
00013 
00014 /*
00015  * Classes
00016  */
00017 VALUE cConfig;
00018 /* Document-class: OpenSSL::ConfigError
00019  *
00020  * General error for openssl library configuration files. Including formating,
00021  * parsing errors, etc.
00022  */
00023 VALUE eConfigError;
00024 
00025 /*
00026  * Public
00027  */
00028 
00029 /*
00030  * GetConfigPtr is a public C-level function for getting OpenSSL CONF struct
00031  * from an OpenSSL::Config(eConfig) instance.  We decided to implement
00032  * OpenSSL::Config in Ruby level but we need to pass native CONF struct for
00033  * some OpenSSL features such as X509V3_EXT_*.
00034  */
00035 CONF *
00036 GetConfigPtr(VALUE obj)
00037 {
00038     CONF *conf;
00039     VALUE str;
00040     BIO *bio;
00041     long eline = -1;
00042 
00043     OSSL_Check_Kind(obj, cConfig);
00044     str = rb_funcall(obj, rb_intern("to_s"), 0);
00045     bio = ossl_obj2bio(str);
00046     conf = NCONF_new(NULL);
00047     if(!conf){
00048         BIO_free(bio);
00049         ossl_raise(eConfigError, NULL);
00050     }
00051     if(!NCONF_load_bio(conf, bio, &eline)){
00052         BIO_free(bio);
00053         NCONF_free(conf);
00054         if (eline <= 0) ossl_raise(eConfigError, "wrong config format");
00055         else ossl_raise(eConfigError, "error in line %d", eline);
00056         ossl_raise(eConfigError, NULL);
00057     }
00058     BIO_free(bio);
00059 
00060     return conf;
00061 }
00062 
00063 /* Document-const: DEFAULT_CONFIG_FILE
00064  *
00065  * The default system configuration file for openssl
00066  */
00067 
00068 /*
00069  * INIT
00070  */
00071 void
00072 Init_ossl_config()
00073 {
00074     char *default_config_file;
00075     eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
00076     cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
00077 
00078     default_config_file = CONF_get1_default_config_file();
00079     rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
00080                     rb_str_new2(default_config_file));
00081     OPENSSL_free(default_config_file);
00082     /* methods are defined by openssl/config.rb */
00083 }
00084 

Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7