Ruby  2.5.0dev(2017-10-22revision60238)
ossl_config.c
Go to the documentation of this file.
1 /*
2  * 'OpenSSL for Ruby' project
3  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4  * All rights reserved.
5  */
6 /*
7  * This program is licensed under the same licence as Ruby.
8  * (See the file 'LICENCE'.)
9  */
10 #include "ossl.h"
11 
12 
13 /*
14  * Classes
15  */
17 /* Document-class: OpenSSL::ConfigError
18  *
19  * General error for openssl library configuration files. Including formatting,
20  * parsing errors, etc.
21  */
23 
24 /*
25  * Public
26  */
27 
28 /*
29  * DupConfigPtr is a public C-level function for getting OpenSSL CONF struct
30  * from an OpenSSL::Config(eConfig) instance. We decided to implement
31  * OpenSSL::Config in Ruby level but we need to pass native CONF struct for
32  * some OpenSSL features such as X509V3_EXT_*.
33  */
34 CONF *
36 {
37  CONF *conf;
38  VALUE str;
39  BIO *bio;
40  long eline = -1;
41 
43  str = rb_funcall(obj, rb_intern("to_s"), 0);
44  bio = ossl_obj2bio(&str);
45  conf = NCONF_new(NULL);
46  if(!conf){
47  BIO_free(bio);
49  }
50  if(!NCONF_load_bio(conf, bio, &eline)){
51  BIO_free(bio);
52  NCONF_free(conf);
53  if (eline <= 0)
54  ossl_raise(eConfigError, "wrong config format");
55  else
56  ossl_raise(eConfigError, "error in line %d", eline);
57  }
58  BIO_free(bio);
59 
60  return conf;
61 }
62 
63 /* Document-const: DEFAULT_CONFIG_FILE
64  *
65  * The default system configuration file for openssl
66  */
67 
68 /*
69  * INIT
70  */
71 void
73 {
74  char *default_config_file;
75 
76 #if 0
77  mOSSL = rb_define_module("OpenSSL");
79 #endif
80 
83 
84  default_config_file = CONF_get1_default_config_file();
85  rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
86  rb_str_new2(default_config_file));
87  OPENSSL_free(default_config_file);
88  /* methods are defined by openssl/config.rb */
89 }
VALUE mOSSL
Definition: ossl.c:231
void Init_ossl_config(void)
Definition: ossl_config.c:72
BIO * ossl_obj2bio(volatile VALUE *pobj)
Definition: ossl_bio.c:13
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:774
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:693
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1893
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2691
VALUE eOSSLError
Definition: ossl.c:236
#define rb_str_new2
Definition: intern.h:835
VALUE eConfigError
Definition: ossl_config.c:22
CONF * DupConfigPtr(VALUE obj)
Definition: ossl_config.c:35
VALUE rb_eStandardError
Definition: error.c:799
unsigned long VALUE
Definition: ruby.h:85
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:52
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:293
VALUE rb_define_module(const char *name)
Definition: class.c:768
#define rb_intern(str)
#define NULL
Definition: _sdbm.c:102
VALUE cConfig
Definition: ossl_config.c:16