Class: OpenSSL::X509::ExtensionFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/openssl/x509-internal.rb,
ext/rubysl/openssl/ossl_x509ext.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 183

static VALUE 
ossl_x509extfactory_initialize(int argc, VALUE *argv, VALUE self)
{
    /*X509V3_CTX *ctx;*/
    VALUE issuer_cert, subject_cert, subject_req, crl;
	
    /*GetX509ExtFactory(self, ctx);*/

    rb_scan_args(argc, argv, "04",
		 &issuer_cert, &subject_cert, &subject_req, &crl);
    if (!NIL_P(issuer_cert))
	ossl_x509extfactory_set_issuer_cert(self, issuer_cert);
    if (!NIL_P(subject_cert))
	ossl_x509extfactory_set_subject_cert(self, subject_cert);
    if (!NIL_P(subject_req))
	ossl_x509extfactory_set_subject_req(self, subject_req);
    if (!NIL_P(crl))
	ossl_x509extfactory_set_crl(self, crl);
    rb_iv_set(self, "@config", Qnil);

    return self;
}

Instance Method Details

#config=(config) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 165

static VALUE
ossl_x509extfactory_set_config(VALUE self, VALUE config)
{
#ifdef HAVE_X509V3_SET_NCONF
    X509V3_CTX *ctx;
    CONF *conf;

    GetX509ExtFactory(self, ctx);
    rb_iv_set(self, "@config", config);
    conf = GetConfigPtr(config);  /* NO DUP NEEDED */
    X509V3_set_nconf(ctx, conf);

    return config;
#else
    rb_notimplement();
#endif
}

#create_ext(*args) ⇒ Object

Array to X509_EXTENSION Structure:

“ln”, “value”, bool_critical

or

“sn”, “value”, bool_critical

or

“ln”, “critical,value”

or the same for sn

“ln”, “value”

> not critical



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 214

static VALUE 
ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
{
    X509V3_CTX *ctx;
    X509_EXTENSION *ext;
    VALUE oid, value, critical, valstr, obj;
    int nid;
#ifdef HAVE_X509V3_EXT_NCONF_NID
    VALUE rconf;
    CONF *conf;
#else
    static LHASH *empty_lhash;
#endif

    rb_scan_args(argc, argv, "21", &oid, &value, &critical);
    StringValue(oid);
    StringValue(value);
    if(NIL_P(critical)) critical = Qfalse;

    nid = OBJ_ln2nid(RSTRING_PTR(oid));
    if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
    if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING_PTR(oid));
    valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
    rb_str_append(valstr, value);
    GetX509ExtFactory(self, ctx);
#ifdef HAVE_X509V3_EXT_NCONF_NID
    rconf = rb_iv_get(self, "@config");
    conf = NIL_P(rconf) ? NULL : GetConfigPtr(rconf);
    ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
#else
    if (!empty_lhash) empty_lhash = lh_new(NULL, NULL);
    ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING_PTR(valstr));
#endif
    if (!ext){
	ossl_raise(eX509ExtError, "%s = %s",
		   RSTRING_PTR(oid), RSTRING_PTR(value));
    }
    WrapX509Ext(cX509Ext, obj, ext);

    return obj;
}

#create_ext_from_array(ary) ⇒ Object

Raises:



28
29
30
31
# File 'lib/openssl/x509-internal.rb', line 28

def create_ext_from_array(ary)
  raise ExtensionError, "unexpected array form" if ary.size > 3
  create_ext(ary[0], ary[1], ary[2])
end

#create_ext_from_hash(hash) ⇒ Object



40
41
42
# File 'lib/openssl/x509-internal.rb', line 40

def create_ext_from_hash(hash)
  create_ext(hash["oid"], hash["value"], hash["critical"])
end

#create_ext_from_string(str) ⇒ Object

“oid = critical, value”



33
34
35
36
37
38
# File 'lib/openssl/x509-internal.rb', line 33

def create_ext_from_string(str) # "oid = critical, value"
  oid, value = str.split(/=/, 2)
  oid.strip!
  value.strip!
  create_ext(oid, value)
end

#create_extension(*arg) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/openssl/x509-internal.rb', line 20

def create_extension(*arg)
  if arg.size > 1
    create_ext(*arg)
  else
    send("create_ext_from_"+arg[0].class.name.downcase, arg[0])
  end
end

#crl=(crl) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 153

static VALUE 
ossl_x509extfactory_set_crl(VALUE self, VALUE crl)
{
    X509V3_CTX *ctx;

    GetX509ExtFactory(self, ctx);
    rb_iv_set(self, "@crl", crl);
    ctx->crl = GetX509CRLPtr(crl); /* NO DUP NEEDED */

    return crl;
}

#issuer_certificate=(cert) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 117

static VALUE 
ossl_x509extfactory_set_issuer_cert(VALUE self, VALUE cert)
{
    X509V3_CTX *ctx;

    GetX509ExtFactory(self, ctx);
    rb_iv_set(self, "@issuer_certificate", cert);
    ctx->issuer_cert = GetX509CertPtr(cert); /* NO DUP NEEDED */

    return cert;
}

#subject_certificate=(cert) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 129

static VALUE 
ossl_x509extfactory_set_subject_cert(VALUE self, VALUE cert)
{
    X509V3_CTX *ctx;

    GetX509ExtFactory(self, ctx);
    rb_iv_set(self, "@subject_certificate", cert);
    ctx->subject_cert = GetX509CertPtr(cert); /* NO DUP NEEDED */

    return cert;
}

#subject_request=(req) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'ext/rubysl/openssl/ossl_x509ext.c', line 141

static VALUE 
ossl_x509extfactory_set_subject_req(VALUE self, VALUE req)
{
    X509V3_CTX *ctx;

    GetX509ExtFactory(self, ctx);
    rb_iv_set(self, "@subject_request", req);
    ctx->subject_req = GetX509ReqPtr(req); /* NO DUP NEEDED */

    return req;
}