Class: OpenSSL::Timestamp::Request
- Inherits:
-
Object
- Object
- OpenSSL::Timestamp::Request
- Defined in:
- ext/openssl/ossl_ts.c,
ext/openssl/ossl_ts.c
Overview
Allows to create timestamp requests or parse existing ones. A Request is also needed for creating timestamps from scratch with Factory. When created from scratch, some default values are set:
-
version is set to
1 -
cert_requested is set to
true -
algorithm, message_imprint, policy_id, and nonce are set to
false
Instance Method Summary collapse
-
#algorithm ⇒ Object
Returns the ‘short name’ of the object identifier that represents the algorithm that was used to create the message imprint digest.
-
#algorithm=(algo) ⇒ Object
Allows to set the object identifier or the ‘short name’ of the algorithm that was used to create the message imprint digest.
-
#cert_requested=(requested) ⇒ Object
Specify whether the response shall contain the timestamp authority’s certificate or not.
-
#cert_requested? ⇒ Boolean
Indicates whether the response shall contain the timestamp authority’s certificate or not.
-
#initialize(*args) ⇒ Object
constructor
When creating a Request with the
Fileorstringparameter, the correspondingFileorstringmust be DER-encoded. -
#message_imprint ⇒ Object
Returns the message imprint (digest) of the data to be timestamped.
-
#message_imprint=(hash) ⇒ Object
Set the message imprint digest.
-
#nonce ⇒ Object
Returns the nonce (number used once) that the server shall include in its response.
-
#nonce=(num) ⇒ Object
Sets the nonce (number used once) that the server shall include in its response.
-
#policy_id ⇒ Object
Returns the ‘short name’ of the object identifier that represents the timestamp policy under which the server shall create the timestamp.
-
#policy_id=(oid) ⇒ Object
Allows to set the object identifier that represents the timestamp policy under which the server shall create the timestamp.
-
#to_der ⇒ Object
DER-encodes this Request.
- #to_text ⇒ Object
-
#version ⇒ Object
Returns the version of this request.
-
#version=(version) ⇒ Object
Sets the version number for this Request.
Constructor Details
#initialize(*args) ⇒ Object
When creating a Request with the File or string parameter, the corresponding File or string must be DER-encoded.
call-seq:
OpenSSL::Timestamp::Request.new(file) -> request
OpenSSL::Timestamp::Request.new(string) -> request
OpenSSL::Timestamp::Request.new -> empty request
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'ext/openssl/ossl_ts.c', line 168
static VALUE
ossl_ts_req_initialize(int argc, VALUE *argv, VALUE self)
{
TS_REQ *ts_req = DATA_PTR(self);
BIO *in;
VALUE arg;
if(rb_scan_args(argc, argv, "01", &arg) == 0) {
return self;
}
arg = ossl_to_der_if_possible(arg);
in = ossl_obj2bio(&arg);
ts_req = d2i_TS_REQ_bio(in, &ts_req);
BIO_free(in);
if (!ts_req) {
DATA_PTR(self) = NULL;
ossl_raise(eTimestampError, "Error when decoding the timestamp request");
}
DATA_PTR(self) = ts_req;
return self;
}
|
Instance Method Details
#algorithm ⇒ Object
Returns the ‘short name’ of the object identifier that represents the algorithm that was used to create the message imprint digest.
call-seq:
request.algorithm -> string
199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'ext/openssl/ossl_ts.c', line 199
static VALUE
ossl_ts_req_get_algorithm(VALUE self)
{
TS_REQ *req;
TS_MSG_IMPRINT *mi;
X509_ALGOR *algor;
const ASN1_OBJECT *obj;
GetTSRequest(self, req);
mi = TS_REQ_get_msg_imprint(req);
algor = TS_MSG_IMPRINT_get_algo(mi);
X509_ALGOR_get0(&obj, NULL, NULL, algor);
return ossl_asn1obj_to_string(obj);
}
|
#algorithm=(algo) ⇒ Object
Allows to set the object identifier or the ‘short name’ of the algorithm that was used to create the message imprint digest.
Example:
request.algorithm = "SHA1"
call-seq:
request.algorithm = "string" -> string
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'ext/openssl/ossl_ts.c', line 224
static VALUE
ossl_ts_req_set_algorithm(VALUE self, VALUE algo)
{
TS_REQ *req;
TS_MSG_IMPRINT *mi;
ASN1_OBJECT *obj;
X509_ALGOR *algor;
GetTSRequest(self, req);
obj = ossl_to_asn1obj(algo);
mi = TS_REQ_get_msg_imprint(req);
algor = TS_MSG_IMPRINT_get_algo(mi);
if (!X509_ALGOR_set0(algor, obj, V_ASN1_NULL, NULL)) {
ASN1_OBJECT_free(obj);
ossl_raise(eTimestampError, "X509_ALGOR_set0");
}
return algo;
}
|
#cert_requested=(requested) ⇒ Object
Specify whether the response shall contain the timestamp authority’s certificate or not. The default value is true.
call-seq:
request.cert_requested = boolean -> true or false
438 439 440 441 442 443 444 445 446 447 |
# File 'ext/openssl/ossl_ts.c', line 438
static VALUE
ossl_ts_req_set_cert_requested(VALUE self, VALUE requested)
{
TS_REQ *req;
GetTSRequest(self, req);
TS_REQ_set_cert_req(req, RTEST(requested));
return requested;
}
|
#cert_requested? ⇒ Boolean
Indicates whether the response shall contain the timestamp authority’s certificate or not.
call-seq:
request.cert_requested? -> true or false
422 423 424 425 426 427 428 429 |
# File 'ext/openssl/ossl_ts.c', line 422
static VALUE
ossl_ts_req_get_cert_requested(VALUE self)
{
TS_REQ *req;
GetTSRequest(self, req);
return TS_REQ_get_cert_req(req) ? Qtrue: Qfalse;
}
|
#message_imprint ⇒ Object
Returns the message imprint (digest) of the data to be timestamped.
call-seq:
request.message_imprint -> string or nil
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'ext/openssl/ossl_ts.c', line 250
static VALUE
ossl_ts_req_get_msg_imprint(VALUE self)
{
TS_REQ *req;
TS_MSG_IMPRINT *mi;
ASN1_OCTET_STRING *hashed_msg;
VALUE ret;
GetTSRequest(self, req);
mi = TS_REQ_get_msg_imprint(req);
hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
ret = asn1str_to_str(hashed_msg);
return ret;
}
|
#message_imprint=(hash) ⇒ Object
Set the message imprint digest.
call-seq:
request.message_imprint = "string" -> string
273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'ext/openssl/ossl_ts.c', line 273
static VALUE
ossl_ts_req_set_msg_imprint(VALUE self, VALUE hash)
{
TS_REQ *req;
TS_MSG_IMPRINT *mi;
StringValue(hash);
GetTSRequest(self, req);
mi = TS_REQ_get_msg_imprint(req);
if (!TS_MSG_IMPRINT_set_msg(mi, (unsigned char *)RSTRING_PTR(hash), RSTRING_LENINT(hash)))
ossl_raise(eTimestampError, "TS_MSG_IMPRINT_set_msg");
return hash;
}
|
#nonce ⇒ Object
Returns the nonce (number used once) that the server shall include in its response.
call-seq:
request.nonce -> BN or nil
379 380 381 382 383 384 385 386 387 388 389 |
# File 'ext/openssl/ossl_ts.c', line 379
static VALUE
ossl_ts_req_get_nonce(VALUE self)
{
TS_REQ *req;
const ASN1_INTEGER * nonce;
GetTSRequest(self, req);
if (!(nonce = TS_REQ_get_nonce(req)))
return Qnil;
return asn1integer_to_num(nonce);
}
|
#nonce=(num) ⇒ Object
Sets the nonce (number used once) that the server shall include in its response. If the nonce is set, the server must return the same nonce value in a valid Response.
call-seq:
request.nonce = number -> BN
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'ext/openssl/ossl_ts.c', line 399
static VALUE
ossl_ts_req_set_nonce(VALUE self, VALUE num)
{
TS_REQ *req;
ASN1_INTEGER *nonce;
int ok;
GetTSRequest(self, req);
nonce = num_to_asn1integer(num, NULL);
ok = TS_REQ_set_nonce(req, nonce);
ASN1_INTEGER_free(nonce);
if (!ok)
ossl_raise(eTimestampError, NULL);
return num;
}
|
#policy_id ⇒ Object
Returns the ‘short name’ of the object identifier that represents the timestamp policy under which the server shall create the timestamp.
call-seq:
request.policy_id -> string or nil
332 333 334 335 336 337 338 339 340 341 |
# File 'ext/openssl/ossl_ts.c', line 332
static VALUE
ossl_ts_req_get_policy_id(VALUE self)
{
TS_REQ *req;
GetTSRequest(self, req);
if (!TS_REQ_get_policy_id(req))
return Qnil;
return ossl_asn1obj_to_string(TS_REQ_get_policy_id(req));
}
|
#policy_id=(oid) ⇒ Object
Allows to set the object identifier that represents the timestamp policy under which the server shall create the timestamp. This may be left nil, implying that the timestamp server will issue the timestamp using some default policy.
Example:
request.policy_id = "1.2.3.4.5"
call-seq:
request.policy_id = "string" -> string
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'ext/openssl/ossl_ts.c', line 355
static VALUE
ossl_ts_req_set_policy_id(VALUE self, VALUE oid)
{
TS_REQ *req;
ASN1_OBJECT *obj;
int ok;
GetTSRequest(self, req);
obj = ossl_to_asn1obj(oid);
ok = TS_REQ_set_policy_id(req, obj);
ASN1_OBJECT_free(obj);
if (!ok)
ossl_raise(eTimestampError, "TS_REQ_set_policy_id");
return oid;
}
|
#to_der ⇒ Object
DER-encodes this Request.
call-seq:
request.to_der -> DER-encoded string
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'ext/openssl/ossl_ts.c', line 455
static VALUE
ossl_ts_req_to_der(VALUE self)
{
TS_REQ *req;
TS_MSG_IMPRINT *mi;
X509_ALGOR *algo;
const ASN1_OBJECT *obj;
ASN1_OCTET_STRING *hashed_msg;
GetTSRequest(self, req);
mi = TS_REQ_get_msg_imprint(req);
algo = TS_MSG_IMPRINT_get_algo(mi);
X509_ALGOR_get0(&obj, NULL, NULL, algo);
if (OBJ_obj2nid(obj) == NID_undef)
ossl_raise(eTimestampError, "Message imprint missing algorithm");
hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
if (!ASN1_STRING_length(hashed_msg))
ossl_raise(eTimestampError, "Message imprint missing hashed message");
return asn1_to_der((void *)req, (int (*)(void *, unsigned char **))i2d_TS_REQ);
}
|
#to_text ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'ext/openssl/ossl_ts.c', line 479
static VALUE
ossl_ts_req_to_text(VALUE self)
{
TS_REQ *req;
BIO *out;
GetTSRequest(self, req);
out = BIO_new(BIO_s_mem());
if (!out) ossl_raise(eTimestampError, NULL);
if (!TS_REQ_print_bio(out, req)) {
BIO_free(out);
ossl_raise(eTimestampError, NULL);
}
return ossl_membio2str(out);
}
|
#version ⇒ Object
Returns the version of this request. 1 is the default value.
call-seq:
request.version -> Integer
294 295 296 297 298 299 300 301 |
# File 'ext/openssl/ossl_ts.c', line 294
static VALUE
ossl_ts_req_get_version(VALUE self)
{
TS_REQ *req;
GetTSRequest(self, req);
return LONG2NUM(TS_REQ_get_version(req));
}
|
#version=(version) ⇒ Object
Sets the version number for this Request. This should be 1 for compliant servers.
call-seq:
request.version = number -> Integer
310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'ext/openssl/ossl_ts.c', line 310
static VALUE
ossl_ts_req_set_version(VALUE self, VALUE version)
{
TS_REQ *req;
long ver;
if ((ver = NUM2LONG(version)) < 0)
ossl_raise(eTimestampError, "version must be >= 0!");
GetTSRequest(self, req);
if (!TS_REQ_set_version(req, ver))
ossl_raise(eTimestampError, "TS_REQ_set_version");
return version;
}
|