Class: OpenID::Consumer::DiffieHellmanSession

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/consumer/associationmanager.rb

Overview

A superclass for implementing Diffie-Hellman association sessions.

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dh = nil) ⇒ DiffieHellmanSession

Returns a new instance of DiffieHellmanSession.



19
20
21
22
# File 'lib/openid/consumer/associationmanager.rb', line 19

def initialize(dh = nil)
  dh = DiffieHellman.from_defaults if dh.nil?
  @dh = dh
end

Class Attribute Details

.allowed_assoc_typesObject (readonly)

Returns the value of attribute allowed_assoc_types.



13
14
15
# File 'lib/openid/consumer/associationmanager.rb', line 13

def allowed_assoc_types
  @allowed_assoc_types
end

.hashfuncObject (readonly)

Returns the value of attribute hashfunc.



13
14
15
# File 'lib/openid/consumer/associationmanager.rb', line 13

def hashfunc
  @hashfunc
end

.secret_sizeObject (readonly)

Returns the value of attribute secret_size.



13
14
15
# File 'lib/openid/consumer/associationmanager.rb', line 13

def secret_size
  @secret_size
end

.session_typeObject (readonly)

Returns the value of attribute session_type.



13
14
15
# File 'lib/openid/consumer/associationmanager.rb', line 13

def session_type
  @session_type
end

Instance Method Details

#extract_secret(response) ⇒ Object

Process the response from a successful association request and return the shared secret for this association



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/openid/consumer/associationmanager.rb', line 38

def extract_secret(response)
  dh_server_public64 = response.get_arg(
    OPENID_NS,
    "dh_server_public",
    NO_DEFAULT,
  )
  enc_mac_key64 = response.get_arg(OPENID_NS, "enc_mac_key", NO_DEFAULT)
  dh_server_public = CryptUtil.base64_to_num(dh_server_public64)
  enc_mac_key = Util.from_base64(enc_mac_key64)
  @dh.xor_secret(
    self.class.hashfunc,
    dh_server_public,
    enc_mac_key,
  )
end

#get_requestObject

Return the query parameters for requesting an association using this Diffie-Hellman association session



26
27
28
29
30
31
32
33
34
# File 'lib/openid/consumer/associationmanager.rb', line 26

def get_request
  args = {"dh_consumer_public" => CryptUtil.num_to_base64(@dh.public)}
  unless @dh.using_default_values?
    args["dh_modulus"] = CryptUtil.num_to_base64(@dh.modulus)
    args["dh_gen"] = CryptUtil.num_to_base64(@dh.generator)
  end

  args
end