本文简要介绍ruby语言中 OpenSSL::Timestamp::Factory类
的用法。
用于从头开始生成 Response
。
请记住,实现将始终应用并优先使用请求中给出的策略对象标识符,而不是 Factory
中指定的默认策略 ID。因此,只有在没有给出 Request#policy_id
的情况下才会应用 default_policy_id
。但这也意味着在创建 Response
之前需要手动检查请求中的策略标识符,例如检查它是否符合一组特定的可接受策略。
如果 Request#cert_requested?
是 true
,除了将包含在生成的时间戳令牌中的时间戳证书之外,还存在添加证书( OpenSSL::X509::Certificate
的实例)的可能性。理想情况下,还应包括任何中间证书(根证书可以省略 - 为了信任它,任何验证方无论如何都必须拥有它)。这简化了时间戳的验证,因为这些中间证书是“already there”,不再需要作为外部参数传递给 Response#verify
,从而最大限度地减少了验证所需的外部资源。
示例:包含(不受信任的)中间证书
假设我们收到一个时间戳请求,将 Request#policy_id
设置为 nil
并将 Request#cert_requested?
设置为 true。原始请求字节存储在一个名为 req_raw
的变量中。我们仍然希望集成必要的中间证书(在 inter1.cer
和 inter2.cer
中)以简化对生成的 Response
的验证。 ts.p12
是一个 PKCS#12 兼容文件,包括私钥和时间戳证书。
req = OpenSSL::Timestamp::Request.new(raw_bytes)
p12 = OpenSSL::PKCS12.new(File.binread('ts.p12'), 'pwd')
inter1 = OpenSSL::X509::Certificate.new(File.binread('inter1.cer'))
inter2 = OpenSSL::X509::Certificate.new(File.binread('inter2.cer'))
fac = OpenSSL::Timestamp::Factory.new
fac.gen_time = Time.now
fac.serial_number = 1
fac.allowed_digests = ["sha256", "sha384", "sha512"]
#needed because the Request contained no policy identifier
fac.default_policy_id = '1.2.3.4.5'
fac.additional_certificates = [ inter1, inter2 ]
timestamp = fac.create_timestamp(p12.key, p12.certificate, req)
属性
default_policy_id
Request#policy_id
如果出现在 Request
中,将始终优先于此,仅当 Request#policy_id
为 nil 时才会使用 default_policy。如果两者都不存在,则在尝试创建 Response
时将引发 TimestampError
。
call-seq:
factory.default_policy_id = "string" -> string factory.default_policy_id -> string or nil
serial_number
设置或检索用于创建时间戳的序列号。必须存在才能创建时间戳。
call-seq:
factory.serial_number = number -> number factory.serial_number -> number or nil
gen_time
设置或检索要在 Response
中使用的 Time
值。必须存在才能创建时间戳。
call-seq:
factory.gen_time = Time -> Time factory.gen_time -> Time or nil
additional_certs
设置或检索除要添加到 Response
的时间戳证书(例如中间证书)之外的其他证书。必须是 Array
的 OpenSSL::X509::Certificate
。
call-seq:
factory.additional_certs = [cert1, cert2] -> [ cert1, cert2 ] factory.additional_certs -> array or nil
allowed_digests
设置或检索允许工厂为其创建时间戳的摘要算法。在可能的情况下,不应允许使用已知的易受攻击或弱算法。必须是 String
或 OpenSSL::Digest
子类实例的 Array
。
call-seq:
factory.allowed_digests = ["sha1", OpenSSL::Digest.new('SHA256').new] -> [ "sha1", OpenSSL::Digest) ] factory.allowed_digests -> array or nil
相关用法
- Ruby Float arg()用法及代码示例
- Ruby File.identical?用法及代码示例
- Ruby Fiber.schedule用法及代码示例
- Ruby Float fdiv()用法及代码示例
- Ruby Float quo()用法及代码示例
- Ruby Float angle()用法及代码示例
- Ruby FileUtils.mkdir用法及代码示例
- Ruby Float divmod()用法及代码示例
- Ruby Float.self - other用法及代码示例
- Ruby Float.rationalize用法及代码示例
- Ruby Float.truncate用法及代码示例
- Ruby FileUtils.compare_file用法及代码示例
- Ruby FileUtils.options_of用法及代码示例
- Ruby File.dirname用法及代码示例
- Ruby Formatter.random_bytes用法及代码示例
- Ruby Float prev_float()用法及代码示例
- Ruby FileUtils.ln_s用法及代码示例
- Ruby Float round()用法及代码示例
- Ruby Float denominator()用法及代码示例
- Ruby Float numerator()用法及代码示例
- Ruby Float absolute()用法及代码示例
- Ruby Float to_i()用法及代码示例
- Ruby Fiddle.dlwrap用法及代码示例
- Ruby Float nan?()用法及代码示例
- Ruby File.directory?用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Factory类。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。