1/* 2 * $Id: ossl_config.c 29359 2010-09-29 03:37:44Z nobu $ 3 * 'OpenSSL for Ruby' project 4 * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz> 5 * All rights reserved. 6 */ 7/* 8 * This program is licenced under the same licence as Ruby. 9 * (See the file 'LICENCE'.) 10 */ 11#include "ossl.h" 12 13 14/* 15 * Classes 16 */ 17VALUE cConfig; 18VALUE eConfigError; 19 20/* 21 * Public 22 */ 23 24/* 25 * GetConfigPtr is a public C-level function for getting OpenSSL CONF struct 26 * from an OpenSSL::Config(eConfig) instance. We decided to implement 27 * OpenSSL::Config in Ruby level but we need to pass native CONF struct for 28 * some OpenSSL features such as X509V3_EXT_*. 29 */ 30CONF * 31GetConfigPtr(VALUE obj) 32{ 33 CONF *conf; 34 VALUE str; 35 BIO *bio; 36 long eline = -1; 37 38 OSSL_Check_Kind(obj, cConfig); 39 str = rb_funcall(obj, rb_intern("to_s"), 0); 40 bio = ossl_obj2bio(str); 41 conf = NCONF_new(NULL); 42 if(!conf){ 43 BIO_free(bio); 44 ossl_raise(eConfigError, NULL); 45 } 46 if(!NCONF_load_bio(conf, bio, &eline)){ 47 BIO_free(bio); 48 NCONF_free(conf); 49 if (eline <= 0) ossl_raise(eConfigError, "wrong config format"); 50 else ossl_raise(eConfigError, "error in line %d", eline); 51 ossl_raise(eConfigError, NULL); 52 } 53 BIO_free(bio); 54 55 return conf; 56} 57 58 59/* 60 * INIT 61 */ 62void 63Init_ossl_config() 64{ 65 char *default_config_file; 66 eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError); 67 cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject); 68 69 default_config_file = CONF_get1_default_config_file(); 70 rb_define_const(cConfig, "DEFAULT_CONFIG_FILE", 71 rb_str_new2(default_config_file)); 72 OPENSSL_free(default_config_file); 73 /* methods are defined by openssl/config.rb */ 74} 75