2003-07-23 20:12:24 +04:00
|
|
|
/*
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
2015-04-20 06:55:09 +03:00
|
|
|
* This program is licensed under the same licence as Ruby.
|
2003-07-23 20:12:24 +04:00
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#include "ossl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cConfig;
|
2013-11-13 13:34:08 +04:00
|
|
|
/* Document-class: OpenSSL::ConfigError
|
|
|
|
*
|
2013-12-22 22:21:14 +04:00
|
|
|
* General error for openssl library configuration files. Including formatting,
|
2013-11-13 13:34:08 +04:00
|
|
|
* parsing errors, etc.
|
|
|
|
*/
|
2003-07-23 20:12:24 +04:00
|
|
|
VALUE eConfigError;
|
|
|
|
|
2010-04-22 12:04:13 +04:00
|
|
|
/*
|
|
|
|
* Public
|
2003-07-23 20:12:24 +04:00
|
|
|
*/
|
|
|
|
|
2010-08-19 12:22:31 +04:00
|
|
|
/*
|
2016-08-29 08:47:09 +03:00
|
|
|
* DupConfigPtr is a public C-level function for getting OpenSSL CONF struct
|
2010-08-19 12:22:31 +04:00
|
|
|
* from an OpenSSL::Config(eConfig) instance. We decided to implement
|
|
|
|
* OpenSSL::Config in Ruby level but we need to pass native CONF struct for
|
|
|
|
* some OpenSSL features such as X509V3_EXT_*.
|
|
|
|
*/
|
2003-09-08 14:31:38 +04:00
|
|
|
CONF *
|
2016-08-29 08:47:09 +03:00
|
|
|
DupConfigPtr(VALUE obj)
|
2003-09-08 14:31:38 +04:00
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
VALUE str;
|
|
|
|
BIO *bio;
|
|
|
|
long eline = -1;
|
|
|
|
|
2010-08-19 12:22:31 +04:00
|
|
|
OSSL_Check_Kind(obj, cConfig);
|
|
|
|
str = rb_funcall(obj, rb_intern("to_s"), 0);
|
2017-08-10 12:23:45 +03:00
|
|
|
bio = ossl_obj2bio(&str);
|
2010-08-19 12:22:31 +04:00
|
|
|
conf = NCONF_new(NULL);
|
2003-09-08 14:31:38 +04:00
|
|
|
if(!conf){
|
|
|
|
BIO_free(bio);
|
|
|
|
ossl_raise(eConfigError, NULL);
|
|
|
|
}
|
|
|
|
if(!NCONF_load_bio(conf, bio, &eline)){
|
|
|
|
BIO_free(bio);
|
2010-08-19 12:22:31 +04:00
|
|
|
NCONF_free(conf);
|
2016-08-29 08:47:09 +03:00
|
|
|
if (eline <= 0)
|
|
|
|
ossl_raise(eConfigError, "wrong config format");
|
|
|
|
else
|
|
|
|
ossl_raise(eConfigError, "error in line %d", eline);
|
2003-09-08 14:31:38 +04:00
|
|
|
}
|
|
|
|
BIO_free(bio);
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
2013-11-13 13:34:08 +04:00
|
|
|
/* Document-const: DEFAULT_CONFIG_FILE
|
|
|
|
*
|
|
|
|
* The default system configuration file for openssl
|
|
|
|
*/
|
2003-09-08 14:31:38 +04:00
|
|
|
|
2003-07-23 20:12:24 +04:00
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
|
|
|
void
|
2014-09-30 09:25:32 +04:00
|
|
|
Init_ossl_config(void)
|
2003-07-23 20:12:24 +04:00
|
|
|
{
|
2008-08-31 07:36:09 +04:00
|
|
|
char *default_config_file;
|
2016-08-29 08:47:09 +03:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
mOSSL = rb_define_module("OpenSSL");
|
|
|
|
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
|
|
#endif
|
|
|
|
|
2003-07-23 20:12:24 +04:00
|
|
|
eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
|
|
|
|
cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
|
|
|
|
|
2008-08-31 07:36:09 +04:00
|
|
|
default_config_file = CONF_get1_default_config_file();
|
2003-09-08 14:31:38 +04:00
|
|
|
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
|
2008-08-30 10:54:25 +04:00
|
|
|
rb_str_new2(default_config_file));
|
|
|
|
OPENSSL_free(default_config_file);
|
2010-08-19 12:22:31 +04:00
|
|
|
/* methods are defined by openssl/config.rb */
|
2003-07-23 20:12:24 +04:00
|
|
|
}
|