Module: PkernelJce::Rfc3161::Request
- Included in:
- Pkernel::Rfc3161::Request, PkernelJce::Rfc3161RequestEngine
- Defined in:
- lib/pkernel_jce/rfc3161.rb
Overview
end module response
Class Method Summary collapse
Instance Method Summary collapse
-
#dump(req, opts = { }) ⇒ Object
end find_tsp_algo.
- #generate(opts = { }) ⇒ Object
-
#parse(opts = { }) ⇒ Object
end generate().
Class Method Details
.find_tsp_algo(dgstCal) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/pkernel_jce/rfc3161.rb', line 361 def Request.find_tsp_algo(dgstCal) if dgstCal.nil? raise PkernelJce::Error, "Digest calculator not given to derive tsp algo" end tspHash = nil org.bouncycastle.tsp.TSPAlgorithms.constants.each do |al| tspAlgo = org.bouncycastle.tsp.TSPAlgorithms.send(al) next if not tspAlgo.java_kind_of?(Java::OrgBouncycastleAsn1::ASN1ObjectIdentifier) if tspAlgo.toASN1Object.equals(dgstCal.algorithm_identifier.algorithm) tspHash = tspAlgo break end end tspHash end |
Instance Method Details
#dump(req, opts = { }) ⇒ Object
end find_tsp_algo
380 381 382 383 384 385 386 |
# File 'lib/pkernel_jce/rfc3161.rb', line 380 def dump(req, opts = { }) if req.nil? raise PkernelJce::Error, "RFC3161 request to dump is nil." end req.encode end |
#generate(opts = { }) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/pkernel_jce/rfc3161.rb', line 280 def generate(opts = { }) targetFile = opts[:tbts_file] targetBin = opts[:tbts_bin] reqGen = org.bouncycastle.tsp.TimeStampRequestGenerator.new reqCert = opts[:inc_certs] || true if reqCert reqGen.setCertReq(true) end reqPolicy = opts[:req_policy] if not (reqPolicy.nil? or reqPolicy.empty?) reqGen.setReqPolicy(org.bouncycastle.asn1.x509.AlgorithmIdentifier.new(reqPolicy)) end nonce = Java::byte[16].new java.util.Random.new.nextBytes(nonce) hashAlgo = opts[:hashAlgo] || "SHA256" if not hashAlgo.nil? hashAlgo = hashAlgo.upcase case hashAlgo when "SHA224","SHA256","SHA384","SHA512","RIPEMD128","RIPEMD160","RIPEMD256" dgstCal = PkernelJce::BcHelpers.find_digest_calculator(hashAlgo) if not (targetFile.nil? or targetFile.empty?) b = Java::byte[10240].new fis = java.io.FileInputStream.new(targetFile) while((cont = fis.read(b,0,b.length)) != -1) dgstCal.getOutputStream.write(b,0,cont) end dgstCal.getOutputStream.close elsif not targetBin.nil? bin = PkernelJce::IoUtils.ensure_java_bytes(targetBin) dgstCal.getOutputStream.write(bin) dgstCal.getOutputStream.close else raise PkernelJce::Error, "No to-be-timestamped file or memory input given to timestamp" end else raise PkernelJce::Error, "Unsupported hash algo '#{hashAlgo}'" end end digest = dgstCal.digest tspHash = PkernelJce::Rfc3161::Request.find_tsp_algo(dgstCal) reqGen.generate(tspHash, digest.to_s.to_java_bytes, java.math.BigInteger.new(nonce).abs) end |
#parse(opts = { }) ⇒ Object
end generate()
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/pkernel_jce/rfc3161.rb', line 336 def parse(opts = { }) bin = opts[:bin] file = opts[:file] if not (file.nil? or file.empty?) breq = IoUtils.file_to_memory_byte_array(file) elsif not bin.nil? breq = IoUtils.ensure_java_bytes(bin) else raise PkernelJce::Error, "No request file or memory is given to parse" end result = { } req = org.bouncycastle.tsp.TimeStampRequest.new(breq) result[:cert_req] = req.cert_req? result[:digest_algo] = req.getMessageImprintAlgOID result[:digest] = req.getMessageImprintDigest result[:nonce] = req.getNonce.to_s(16) result[:policy] = req.req_policy result end |