Ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a25176072e02db9254f0e0c84c805cd)
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 */
34CONF *
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 */
71void
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}
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
Definition: class.c:711
VALUE rb_define_module(const char *)
Definition: class.c:785
VALUE rb_cObject
Object class.
Definition: ruby.h:2012
VALUE rb_eStandardError
Definition: error.c:921
VALUE mOSSL
Definition: ossl.c:231
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:293
VALUE eOSSLError
Definition: ossl.c:236
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:57
BIO * ossl_obj2bio(volatile VALUE *pobj)
Definition: ossl_bio.c:13
VALUE eConfigError
Definition: ossl_config.c:22
void Init_ossl_config(void)
Definition: ossl_config.c:72
VALUE cConfig
Definition: ossl_config.c:16
CONF * DupConfigPtr(VALUE obj)
Definition: ossl_config.c:35
#define rb_str_new2
#define NULL
const VALUE VALUE obj
unsigned long VALUE
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2891
#define rb_funcall(recv, mid, argc,...)
#define rb_intern(str)