123456789_123456789_123456789_123456789_123456789_

Class: OpenSSL::Timestamp::TokenInfo

Relationships & Source Files
Inherits: Object
Defined in: ext/openssl/ossl_ts.c

Overview

Immutable and read-only representation of a timestamp token info from a Response.

Class Method Summary

  • .new(file) ⇒ token-info constructor

    Creates a TokenInfo from a File or string parameter, the corresponding File or string must be DER-encoded.

Instance Method Summary

Constructor Details

.new(file) ⇒ token-info .new(string) ⇒ token-info

Creates a TokenInfo from a File or string parameter, the corresponding File or string must be DER-encoded. Please note that TokenInfo is an immutable read-only class. If you’d like to create timestamps please refer to Factory instead.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 871

static VALUE
ossl_ts_token_info_initialize(VALUE self, VALUE der)
{
    TS_TST_INFO *info = DATA_PTR(self);
    BIO *in;

    der = ossl_to_der_if_possible(der);
    in  = ossl_obj2bio(&der);
    info = d2i_TS_TST_INFO_bio(in, &info);
    BIO_free(in);
    if (!info) {
        DATA_PTR(self) = NULL;
        ossl_raise(eTimestampError, "Error when decoding the timestamp token info");
    }
    DATA_PTR(self) = info;

    return self;
}

Instance Method Details

#algorithmString?

Returns the ‘short name’ of the object identifier representing the algorithm that was used to derive the message imprint digest. For valid timestamps, this is the same value that was already given in the Request. If status is GRANTED or GRANTED_WITH_MODS, this is never nil.

Example:

algo = token_info.algorithm
puts algo                -> "SHA1"
[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 941

static VALUE
ossl_ts_token_info_get_algorithm(VALUE self)
{
    TS_TST_INFO *info;
    TS_MSG_IMPRINT *mi;
    X509_ALGOR *algo;

    GetTSTokenInfo(self, info);
    mi = TS_TST_INFO_get_msg_imprint(info);
    algo = TS_MSG_IMPRINT_get_algo(mi);
    return get_asn1obj(algo->algorithm);
}

#gen_timeTime

Returns time when this timestamp token was created. If status is GRANTED or GRANTED_WITH_MODS, this is never nil.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 1006

static VALUE
ossl_ts_token_info_get_gen_time(VALUE self)
{
    TS_TST_INFO *info;

    GetTSTokenInfo(self, info);
    return asn1time_to_time(TS_TST_INFO_get_time(info));
}

#msg_imprintstring.

Returns the message imprint digest. For valid timestamps, this is the same value that was already given in the Request. If status is GRANTED or GRANTED_WITH_MODS, this is never nil.

Example:

mi = token_info.msg_imprint
puts mi                -> "DEADBEEF"
[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 966

static VALUE
ossl_ts_token_info_get_msg_imprint(VALUE self)
{
    TS_TST_INFO *info;
    TS_MSG_IMPRINT *mi;
    ASN1_OCTET_STRING *hashed_msg;
    VALUE ret;

    GetTSTokenInfo(self, info);
    mi = TS_TST_INFO_get_msg_imprint(info);
    hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
    ret = rb_str_new((const char *)hashed_msg->data, hashed_msg->length);

    return ret;
}

#nonceBN?

If the timestamp token is valid then this field contains the same nonce that was passed to the timestamp server in the initial Request.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 1048

static VALUE
ossl_ts_token_info_get_nonce(VALUE self)
{
    TS_TST_INFO *info;
    const ASN1_INTEGER *nonce;

    GetTSTokenInfo(self, info);
    if (!(nonce = TS_TST_INFO_get_nonce(info)))
        return Qnil;

    return asn1integer_to_num(nonce);
}

#orderingtrue, ...

If the ordering field is missing, or if the ordering field is present and set to false, then the genTime field only indicates the time at which the time-stamp token has been created by the TSA. In such a case, the ordering of time-stamp tokens issued by the same TSA or different TSAs is only possible when the difference between the genTime of the first time-stamp token and the genTime of the second time-stamp token is greater than the sum of the accuracies of the genTime for each time-stamp token.

If the ordering field is present and set to true, every time-stamp token from the same TSA can always be ordered based on the genTime field, regardless of the genTime accuracy.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 1032

static VALUE
ossl_ts_token_info_get_ordering(VALUE self)
{
    TS_TST_INFO *info;

    GetTSTokenInfo(self, info);
    return TS_TST_INFO_get_ordering(info) ? Qtrue : Qfalse;
}

#policy_idString?

Returns the timestamp policy object identifier of the policy this timestamp was created under. If status is GRANTED or GRANTED_WITH_MODS, this is never nil.

Example:

id = token_info.policy_id
puts id                 -> "1.2.3.4.5"
[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 919

static VALUE
ossl_ts_token_info_get_policy_id(VALUE self)
{
    TS_TST_INFO *info;

    GetTSTokenInfo(self, info);
    return get_asn1obj(TS_TST_INFO_get_policy_id(info));
}

#serial_numberBN?

Returns serial number of the timestamp token. This value shall never be the same for two timestamp tokens issued by a dedicated timestamp authority. If status is GRANTED or GRANTED_WITH_MODS, this is never nil.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 990

static VALUE
ossl_ts_token_info_get_serial_number(VALUE self)
{
    TS_TST_INFO *info;

    GetTSTokenInfo(self, info);
    return asn1integer_to_num(TS_TST_INFO_get_serial(info));
}

#to_derString

Returns the TokenInfo in DER-encoded form.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 1067

static VALUE
ossl_ts_token_info_to_der(VALUE self)
{
    TS_TST_INFO *info;

    GetTSTokenInfo(self, info);
    return asn1_to_der((void *)info, (int (*)(void *, unsigned char **))i2d_TS_TST_INFO);
}

#versionInteger?

Returns the version number of the token info. With compliant servers, this value should be 1 if present. If status is GRANTED or GRANTED_WITH_MODS.

[ GitHub ]

  
# File 'ext/openssl/ossl_ts.c', line 898

static VALUE
ossl_ts_token_info_get_version(VALUE self)
{
    TS_TST_INFO *info;

    GetTSTokenInfo(self, info);
    return LONG2NUM(TS_TST_INFO_get_version(info));
}