Ruby  2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
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 }
DupConfigPtr
CONF * DupConfigPtr(VALUE obj)
Definition: ossl_config.c:35
eConfigError
VALUE eConfigError
Definition: ossl_config.c:22
rb_str_new2
#define rb_str_new2
Definition: intern.h:903
VALUE
unsigned long VALUE
Definition: ruby.h:102
ossl_obj2bio
BIO * ossl_obj2bio(volatile VALUE *pobj)
Definition: ossl_bio.c:13
OSSL_Check_Kind
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:56
rb_intern
#define rb_intern(str)
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:772
ossl.h
NULL
#define NULL
Definition: _sdbm.c:101
cConfig
VALUE cConfig
Definition: ossl_config.c:16
mOSSL
VALUE mOSSL
Definition: ossl.c:231
ossl_raise
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:293
Init_ossl_config
void Init_ossl_config(void)
Definition: ossl_config.c:72
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:2010
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.2.h:5777
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_funcall
#define rb_funcall(recv, mid, argc,...)
Definition: rb_mjit_min_header-2.7.2.h:6620
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2891
eOSSLError
VALUE eOSSLError
Definition: ossl.c:236
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:698
rb_eStandardError
VALUE rb_eStandardError
Definition: error.c:921