Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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 */
16 VALUE cConfig;
17 /* Document-class: OpenSSL::ConfigError
18 *
19 * General error for openssl library configuration files. Including formatting,
20 * parsing errors, etc.
21 */
22 VALUE eConfigError;
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 *
35 DupConfigPtr(VALUE obj)
36 {
37 CONF *conf;
38 VALUE str;
39 BIO *bio;
40 long eline = -1;
41
42 OSSL_Check_Kind(obj, cConfig);
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);
48 ossl_raise(eConfigError, NULL);
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
72 Init_ossl_config(void)
73 {
74 char *default_config_file;
75
76 #if 0
77 mOSSL = rb_define_module("OpenSSL");
78 eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
79 #endif
80
81 eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
82 cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
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
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
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
rb_funcall
#define rb_funcall(recv, mid, argc,...)
Definition: rb_mjit_min_header-2.7.0.h:6585
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2880
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:919