Class: Capistrano::Password::Manager
- Inherits:
-
Object
- Object
- Capistrano::Password::Manager
- Defined in:
- lib/capistrano_recia/password/manager.rb
Instance Method Summary collapse
-
#corrupt(save_key) ⇒ Object
permet de récupérer un mot de passe si sa clé de sauvegarde est enregistré, sinon retourne nil.
-
#corrupted ⇒ Object
permet de récupérer les mots de passe corrompus.
-
#generate(save_key = "") ⇒ Object
permet de générer un mot de passe.
-
#initialize(file_path, keepass = "[S]{20}") ⇒ Manager
constructor
constructor must determine the path to the save file.
-
#is_corrupted?(save_key) ⇒ Boolean
permet de savoir si le mot de passe est corrompu.
-
#live_uncorrupt(save_key) ⇒ Object
to use only in a secure context (batch, admins who should know the pass).
-
#securize ⇒ Object
regenerate all corrupted password.
Constructor Details
#initialize(file_path, keepass = "[S]{20}") ⇒ Manager
constructor must determine the path to the save file. if we need to change the keepass regexp, the second parameter is used for it (default [S]20)
11 12 13 14 15 |
# File 'lib/capistrano_recia/password/manager.rb', line 11 def initialize(file_path, keepass = "[S]{20}") @file_path = file_path @salt = "recia_password" @keepass_regex = keepass end |
Instance Method Details
#corrupt(save_key) ⇒ Object
permet de récupérer un mot de passe si sa clé de sauvegarde est enregistré, sinon retourne nil
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/capistrano_recia/password/manager.rb', line 68 def corrupt(save_key) # get passwd pass = live_uncorrupt save_key # load yaml file yaml = load_file # if yaml file contains informations if yaml and pass # set password to corrupted yaml[save_key]["corrupt"] = true # save the information of corruption to the file File.open(@file_path, "w") do |io| io.write(yaml.to_yaml) io.close end end # return password return pass end |
#corrupted ⇒ Object
permet de récupérer les mots de passe corrompus
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/capistrano_recia/password/manager.rb', line 53 def corrupted() list = Array.new yaml = load_file yaml.keys.each do |key| if is_corrupted? key list.push key end end list end |
#generate(save_key = "") ⇒ Object
permet de générer un mot de passe. le premier paramètre indique si nous devons sauvegarder ou non le mot de passe (nil ou “” aucune sauvegarde) le deuxième paramètre est celui des options de keepass.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/capistrano_recia/password/manager.rb', line 94 def generate(save_key="") # generate a password without lookalikes (l, I, !, ...) pass = KeePass::Password.generate(@keepass_regex, :remove_lookalikes => true) # crypt the password enc_pass = pass.encrypt(:symmetric, :password => @salt) enc_pass.send :remove_instance_variable, :@cipher # if a save key is passed if save_key and not save_key.empty? # load yaml file yaml = load_file yaml[save_key] = Hash.new if not yaml.has_key? save_key # add password to file yaml[save_key]["password"] = enc_pass yaml[save_key]["corrupt"] = false # save file File.open(@file_path, "w") do |io| io.write(yaml.to_yaml) io.close end end return pass, enc_pass end |
#is_corrupted?(save_key) ⇒ Boolean
permet de savoir si le mot de passe est corrompu
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/capistrano_recia/password/manager.rb', line 38 def is_corrupted?(save_key) # load yaml file yaml = load_file if yaml and yaml.has_key? save_key # check if password is corrupted corrupt = yaml[save_key]["corrupt"] if corrupt.to_s == "true" return true end end return false end |
#live_uncorrupt(save_key) ⇒ Object
to use only in a secure context (batch, admins who should know the pass)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/capistrano_recia/password/manager.rb', line 18 def live_uncorrupt(save_key) pass = nil # load yaml file yaml = load_file # if yaml file contains informations if yaml and yaml.has_key? save_key # get the password pass = yaml[save_key]["password"] end # decrypt the password if pass pass = pass.decrypt(:symmetric, :password => @salt) end # return password return pass end |
#securize ⇒ Object
regenerate all corrupted password. and return all the password which are regenerated by keys
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/capistrano_recia/password/manager.rb', line 123 def securize() securized = Hash.new # for each corrupted passwd corrupted.each do |key| securized[key] = Hash.new securized[key]['old'] = corrupt(key) securized[key]['new'], crypted = generate(key) end securized end |