class NemID::Authentication::Params

Public Class Methods

new(cert:, key:) click to toggle source
# File lib/nemid/authentication/params.rb, line 6
def initialize(cert:, key:)
  @nemid_crypto = NemID::Crypto.new(cert: cert, key: key)
end

Public Instance Methods

client_initialization_parameters() click to toggle source
# File lib/nemid/authentication/params.rb, line 10
def client_initialization_parameters
  params = unsigned_params
  normalized_unsigned_params = normalize(unsigned_params)
  
  params.merge({
    "DIGEST_SIGNATURE": digest_signature(normalized_unsigned_params),
    "PARAMS_DIGEST": params_digest(normalized_unsigned_params),
  })
end

Private Instance Methods

digest_signature(normalized_unsigned_params) click to toggle source
# File lib/nemid/authentication/params.rb, line 21
def digest_signature(normalized_unsigned_params)
  @nemid_crypto.base64_encoded_rsa_signature(normalized_unsigned_params)
end
normalize(params) click to toggle source
# File lib/nemid/authentication/params.rb, line 25
def normalize(params)
  params = params.transform_keys(&:upcase)
  
  str = String.new
  
  params.keys.sort.each { |k| str += "#{k.to_s}#{params[k]}" }
  
  return str
end
params_digest(normalized_unsigned_params) click to toggle source
# File lib/nemid/authentication/params.rb, line 35
def params_digest(normalized_unsigned_params)
  @nemid_crypto.base64_encoded_digest_representation(normalized_unsigned_params)
end
sp_cert() click to toggle source
# File lib/nemid/authentication/params.rb, line 39
def sp_cert
  @nemid_crypto.base64_encoded_der_representation
end
unsigned_params() click to toggle source
# File lib/nemid/authentication/params.rb, line 43
def unsigned_params
  {
    "CLIENTFLOW": "OCESLOGIN2",
    "ENABLE_AWAITING_APP_APPROVAL_EVENT": "TRUE",
    "SP_CERT": sp_cert,
    "TIMESTAMP": DateTime.now.new_offset(0).strftime('%F %T%z'),
  }
end