Class: Firefox::Login

Inherits:
Object
  • Object
show all
Defined in:
lib/firefox/login.rb

Constant Summary collapse

JSON_SCHEMA =
{
  'type' => 'object',
  'required' => ['id', 'hostname',
                 'encryptedUsername', 'encryptedPassword'],
  'properties' => {
    'id' => {'type': 'integer'},
    'hostname' => {'type': 'string'},
    'httpRealm' => {'type': ['string', 'null']},
    'formSubmitURL' => {'type': ['string', 'null']},
    'usernameField' => {'type': ['string', 'null']},
    'passwordField' => {'type': ['string', 'null']},
    'encryptedUsername' => {'type': 'string'},
    'encryptedPassword' => {'type': 'string'},
    'guid' => {'type': ['string', 'null']},
    'encType' => {'type': 'integer'},
    'timeCreated' => {'type': 'integer'},
    'timeLastUsed' => {'type': 'integer'},
    'timePasswordChanged' => {'type': 'integer'},
    'timesUsed' => {'type': 'integer'},
  },
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogin

Returns a new instance of Login.



56
57
# File 'lib/firefox/login.rb', line 56

def initialize()
end

Instance Attribute Details

#enc_typeObject

Returns the value of attribute enc_type.



48
49
50
# File 'lib/firefox/login.rb', line 48

def enc_type
  @enc_type
end

#encrypted_passwordObject

Returns the value of attribute encrypted_password.



48
49
50
# File 'lib/firefox/login.rb', line 48

def encrypted_password
  @encrypted_password
end

#encrypted_usernameObject

Returns the value of attribute encrypted_username.



48
49
50
# File 'lib/firefox/login.rb', line 48

def encrypted_username
  @encrypted_username
end

#form_submit_urlObject

Returns the value of attribute form_submit_url.



48
49
50
# File 'lib/firefox/login.rb', line 48

def form_submit_url
  @form_submit_url
end

#guidObject

Returns the value of attribute guid.



48
49
50
# File 'lib/firefox/login.rb', line 48

def guid
  @guid
end

#hostnameObject

Returns the value of attribute hostname.



48
49
50
# File 'lib/firefox/login.rb', line 48

def hostname
  @hostname
end

#http_realmObject

Returns the value of attribute http_realm.



48
49
50
# File 'lib/firefox/login.rb', line 48

def http_realm
  @http_realm
end

#idObject

Returns the value of attribute id.



48
49
50
# File 'lib/firefox/login.rb', line 48

def id
  @id
end

#passwordObject

Returns the value of attribute password.



48
49
50
# File 'lib/firefox/login.rb', line 48

def password
  @password
end

#password_fieldObject

Returns the value of attribute password_field.



48
49
50
# File 'lib/firefox/login.rb', line 48

def password_field
  @password_field
end

#time_createdObject

Returns the value of attribute time_created.



48
49
50
# File 'lib/firefox/login.rb', line 48

def time_created
  @time_created
end

#time_last_usedObject

Returns the value of attribute time_last_used.



48
49
50
# File 'lib/firefox/login.rb', line 48

def time_last_used
  @time_last_used
end

#time_password_changedObject

Returns the value of attribute time_password_changed.



48
49
50
# File 'lib/firefox/login.rb', line 48

def time_password_changed
  @time_password_changed
end

#times_usedObject

Returns the value of attribute times_used.



48
49
50
# File 'lib/firefox/login.rb', line 48

def times_used
  @times_used
end

#usernameObject

Returns the value of attribute username.



48
49
50
# File 'lib/firefox/login.rb', line 48

def username
  @username
end

#username_fieldObject

Returns the value of attribute username_field.



48
49
50
# File 'lib/firefox/login.rb', line 48

def username_field
  @username_field
end

Class Method Details

.from_json(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/firefox/login.rb', line 67

def self.from_json(data)
  # In firefox (checked in the mercurial repository on 2017-02-11),
  # logins.json is updated in
  # toolkit/components/passwordmgr/storage-json.js

  begin
    JSON::Validator.validate!(JSON_SCHEMA, data)
  rescue JSON::Schema::ValidationError => err
    raise InvalidLogin, "invalid login data: #{err.message}"
  end

   = Login.new()

  to_date = lambda do |timestamp|
    seconds = timestamp / 1000
    milliseconds = timestamp % 1000
    Time.at(seconds, milliseconds).utc()
  end

  .id = data['id']
  .hostname = data['hostname']
  .http_realm = data['httpRealm']
  .form_submit_url = data['formSubmitURL']
  .username_field = data['usernameField']
  .password_field = data['passwordField']
  .encrypted_username = data['encryptedUsername']
  .encrypted_password = data['encryptedPassword']
  .enc_type = data['encType']
  .guid = data['guid']
  .time_created = to_date.(data['timeCreated'])
  .time_last_used = to_date.(data['timeLastUsed'])
  .time_password_changed = to_date.(data['timePasswordChanged'])
  .times_used = data['timesUsed']

  
end

Instance Method Details

#decryptObject



104
105
106
107
# File 'lib/firefox/login.rb', line 104

def decrypt()
  @username = NSS.decrypt(@encrypted_username)
  @password = NSS.decrypt(@encrypted_password)
end

#inspectObject



63
64
65
# File 'lib/firefox/login.rb', line 63

def inspect()
  to_s()
end

#to_sObject



59
60
61
# File 'lib/firefox/login.rb', line 59

def to_s()
  "#<Firefox::Login #{@hostname}>"
end