Class: Gpsoauth::Google

Inherits:
Object
  • Object
show all
Defined in:
lib/gpsoauth/google.rb

Class Method Summary collapse

Class Method Details

.keyFromb64(key) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gpsoauth/google.rb', line 4

def keyFromb64(key)
	binaryKey = Base64.decode64(key)
	i 		  = Utils.bytesToLong(binaryKey[0..3])
	mod 	  = Utils.bytesToLong(binaryKey[4..3+i])

	j   	  = Utils.bytesToLong(binaryKey[i+4..i+7])
	exponent  = Utils.bytesToLong(binaryKey[i+8..i+7+j])

	key   = OpenSSL::PKey::RSA.new
	key.e = OpenSSL::BN.new(exponent)
	key.n =  OpenSSL::BN.new(mod)

	return key
end

.keyToStuct(key) ⇒ Object



19
20
21
22
23
# File 'lib/gpsoauth/google.rb', line 19

def keyToStuct(key)
  modulus = key.n
  exponent = key.e
  return Utils.serialize_number(modulus.num_bytes, 4) + Utils.serialize_number(modulus) + Utils.serialize_number(exponent.num_bytes, 4) + Utils.serialize_number(exponent)
end

.parseAuthResponse(text) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gpsoauth/google.rb', line 25

def parseAuthResponse(text)
	responseData = Hash.new
	text.split("\n").each do |line|
		if line == nil
			next
		end
		key, _, val = line.partition('=')
		responseData[key] = val
	end
	return responseData
end

.signature(email, password, key) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/gpsoauth/google.rb', line 37

def signature(email, password, key)
	signature = "\x00"
	struct = keyToStuct(key).pack('c*')
	signature = signature + OpenSSL::Digest::SHA1.digest(struct)[0...4]
	encryptedLogin = key.public_encrypt(email + "\x00" + password, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
	signature = signature + encryptedLogin
	return Base64.urlsafe_encode64(signature)
end