本文簡要介紹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類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。