Method: Tem::Cert.create_tag_from_cert

Defined in:
lib/tem/_cert.rb

.create_tag_from_cert(cert) ⇒ Object

The tag is 527 bytes long. What the bytes encode is as follows:

-Serial number   tag[0..3]
-Not before date tag[4..7]
-Not after date  tag[8..11]
-Modulus         tag[12..267]
-Public key exp  tag[268..270]
-Signature       tag[271..526]

Parameters:

  • cert

    An OpenSSL::X509::Certificate instance



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tem/_cert.rb', line 55

def self.create_tag_from_cert(cert)
  tag_serial_num = Tem::CryptoAbi.to_tem_bignum(OpenSSL::BN.new(cert.serial.to_s))
  while tag_serial_num.length < 4
    tag_serial_num = [0] + tag_serial_num  #make sure array is 4 bytes

  end
  #The dates are encoded as the number of seconds since epoch (Jan 1, 1970 00:00:00 GMT)

  #TODO: check that dates are exactly 4 bytes, else throw an exception

  tag_not_before = Tem::CryptoAbi.to_tem_bignum(OpenSSL::BN.new(cert.not_before.to_i.to_s))
  tag_not_after = Tem::CryptoAbi.to_tem_bignum(OpenSSL::BN.new(cert.not_after.to_i.to_s))
  tag_modulus = Tem::CryptoAbi.to_tem_bignum(OpenSSL::BN.new(cert.public_key.n.to_s))
  #TODO: ensure that exponent is exactly three bytes, or come up with a safer way to encode it

  tag_public_exp = Tem::CryptoAbi.to_tem_bignum(OpenSSL::BN.new(cert.public_key.e.to_s))
  tag = [tag_serial_num, tag_not_before, tag_not_after, tag_modulus, tag_public_exp].flatten
  return tag
end