├── Gemfile ├── LICENSE.md ├── README.md ├── bin └── forgiva ├── forgiva.gemspec └── lib ├── constants.rb ├── forgiva.rb ├── forgiva_commands.rb ├── forgiva_test.rb └── testvectors.rb /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2016 Sceptive 3 | 4 | ## Creative Commons 5 | 6 | # Attribution-NonCommercial-ShareAlike 4.0 International 7 | 8 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 9 | 10 | ### Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 13 | 14 | * __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 15 | 16 | * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 17 | 18 | ## Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License 19 | 20 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 21 | 22 | ### Section 1 – Definitions. 23 | 24 | a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 25 | 26 | b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 27 | 28 | c. __BY-NC-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. 29 | 30 | d. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 31 | 32 | e. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 33 | 34 | f. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 35 | 36 | g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. 37 | 38 | h. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 39 | 40 | i. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 41 | 42 | h. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. 43 | 44 | i. __NonCommercial__ means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 45 | 46 | j. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 47 | 48 | k. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 49 | 50 | l. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 51 | 52 | ### Section 2 – Scope. 53 | 54 | a. ___License grant.___ 55 | 56 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 57 | 58 | A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 59 | 60 | B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. 61 | 62 | 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 63 | 64 | 3. __Term.__ The term of this Public License is specified in Section 6(a). 65 | 66 | 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 67 | 68 | 5. __Downstream recipients.__ 69 | 70 | A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 71 | 72 | B. __Additional offer from the Licensor – Adapted Material.__ Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 73 | 74 | C. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 75 | 76 | 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 77 | 78 | b. ___Other rights.___ 79 | 80 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 81 | 82 | 2. Patent and trademark rights are not licensed under this Public License. 83 | 84 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 85 | 86 | ### Section 3 – License Conditions. 87 | 88 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 89 | 90 | a. ___Attribution.___ 91 | 92 | 1. If You Share the Licensed Material (including in modified form), You must: 93 | 94 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 95 | 96 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 97 | 98 | ii. a copyright notice; 99 | 100 | iii. a notice that refers to this Public License; 101 | 102 | iv. a notice that refers to the disclaimer of warranties; 103 | 104 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 105 | 106 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 107 | 108 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 109 | 110 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 111 | 112 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 113 | 114 | b. ___ShareAlike.___ 115 | 116 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 117 | 118 | 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. 119 | 120 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 121 | 122 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 123 | 124 | ### Section 4 – Sui Generis Database Rights. 125 | 126 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 127 | 128 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; 129 | 130 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 131 | 132 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 133 | 134 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 135 | 136 | ### Section 5 – Disclaimer of Warranties and Limitation of Liability. 137 | 138 | a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ 139 | 140 | b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ 141 | 142 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 143 | 144 | ### Section 6 – Term and Termination. 145 | 146 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 147 | 148 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 149 | 150 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 151 | 152 | 2. upon express reinstatement by the Licensor. 153 | 154 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 155 | 156 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 157 | 158 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 159 | 160 | ### Section 7 – Other Terms and Conditions. 161 | 162 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 163 | 164 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 165 | 166 | ### Section 8 – Interpretation. 167 | 168 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 169 | 170 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 171 | 172 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 173 | 174 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 175 | 176 | ``` 177 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 178 | 179 | Creative Commons may be contacted at creativecommons.org 180 | ``` 181 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Important 2 | 3 | **Please note that this repository is hold for the references purposes. 4 | Forgiva evolved into Forgiva Enterprise and became fully open-source. Please 5 | refer to [Forgiva Integrator](https://github.com/Sceptive/forgiva-integrator) repository 6 | for more information.** 7 | 8 | 9 | ## Overview 10 | 11 | Forgiva is a brand new password managing idea. It's developed by security 12 | professionals to maintain and protect passwords far more better than any 13 | other commercial solution available on the market. 14 | 15 | * It never stores your passwords anywhere! There is nothing to crack. 16 | * Resistant to key-loggers. 17 | * Combines various hashing and encryption algorithms depending on your 18 | master-key. Thus makes very difficult to estimate an effective 19 | brute-force and/or dictionary attack. 20 | * You can choose complexity depending on your paranoia level. 21 | 22 | ## Installation 23 | 24 | ```bash 25 | $ gem install forgiva 26 | ``` 27 | 28 | ## Usage 29 | 30 | Just type `forgiva` on the command line to run, and pick any password depending 31 | on your favourite animal. 32 | 33 | ``` 34 | 35 | $ forgiva 36 | 37 | .-" L_ FORGIVA (Open Source Edition) 38 | ;', / ( o\ The new-age password manager 39 | \ ; `' / 40 | ;_/"'.__.-" 41 | 42 | Hostname: abc.com 43 | Account: superuser 44 | Master password: 45 | Master password (again): 46 | Generating... 47 | 48 | Ape 0en8*qxxbTopbKD_ 49 | Bat OJJ6+wv6*bx2wscf 50 | Bear tFOAx/@aYd@a8zDG 51 | Whale l/RiCiHlKz_c3+Xt 52 | Crow 0d4nXlk7mx,6g16H 53 | Dog xdYhK.Tr,O,wSXBb 54 | Duck tTGbDlVWdDJv!3Pj 55 | Cat +kEWip3mU_6DhWkz 56 | Wasp SGAl789+hsdoM_qD 57 | Fox X0wxIXc_KdGC1z9t 58 | Gull vnkEml-27mJJ1DmC 59 | Hyena scpcqlNhTdpjbn.7 60 | Lion TiMrSkoCjOj5wQ-+ 61 | Panda iDJ+fkJDiv,8y+-h 62 | Rat map_sqAjAucsDsPh 63 | Shark n1*-a4.BzPbAugUP 64 | Spider Iuw6T%4qDVQyRiZh 65 | Turtle PndQxbYFm0%HsCNf 66 | Wolf Q%eLIONHqscny7on 67 | Zebra VQRD!27jVnVSpC.E 68 | ``` 69 | 70 | Command line options: 71 | 72 | ``` 73 | forgiva [-h HOST] [-a ACCOUNT-ID] [-l LENGTH] [-s] [-c [1-3]] [-e] [OPTION...] 74 | 75 | Help Options: 76 | -?, --help Show help options 77 | 78 | Application Options: 79 | -h, --host-name=HOST Host/Web Site/Domain name (e.g.: facebook.com) 80 | -a, --account=ACCOUNT-ID Account id to log-in to host such as such as e-mail address or nick-name etc. 81 | -r, --renewal-date=DATE Date for passwords to generate 82 | -l, --length=LENGTH Password length (Default: 16) 83 | -s, --save-credentials Save host name and account to local database to remember next time 84 | -c, --complexity=C_LEVEL 0-3 complexity level of password generation. (Default: 0) 85 | -e, --select-credentials Select host and account info from saved list of credentials. If just host or account specified then you get filtered credentials. 86 | -t, --test Runs core tests for the algorithm 87 | -p, --scrypt Use scrypt algorithm to strengthen algorithm 88 | ``` 89 | 90 | ## Release notes 91 | 92 | - 1.0.1.3 and 1.0.1.4 93 | - Added scrypt support with -p/--scrypt option 94 | - Fixed various parameter parsing bugs 95 | 96 | ## Algorithm 97 | 98 | (Note: After 1.0.1.4 version, SCrypt support added) 99 | 100 | Forgiva uses following digest and encryption algorithm to complex password 101 | generation phases: 102 | 103 | for encryption; 104 | 105 | [des-ede3-cbc](https://en.wikipedia.org/wiki/Triple_DES) c[amellia-128-cbc camellia-192-cbc camellia-256-cbc](https://en.wikipedia.org/wiki/Camellia_(cipher)) [cast5-cbc](https://en.wikipedia.org/wiki/CAST-128) 106 | [bf-cbc](https://en.wikipedia.org/wiki/Blowfish_(cipher)) [aes-128-cbc aes-192-cbc aes-256-cbc](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) 107 | 108 | for hashing; 109 | 110 | [sha512 sha384 sha256 sha224](https://en.wikipedia.org/wiki/SHA-2) [sha1](https://en.wikipedia.org/wiki/SHA-1) [sha](https://en.wikipedia.org/wiki/SHA-1#SHA-0) [md5](https://en.wikipedia.org/wiki/MD5) [md4](https://en.wikipedia.org/wiki/MD4) [ripemd160](https://en.wikipedia.org/wiki/RIPEMD) 111 | 112 | Depending on data provided by the user Forgiva may or may not use all the encryption and hashing algorithms in an password re-generation process. 113 | 114 | Algorithm uses 4 key data to generate password(s); 115 | 116 | * Host (ex. google.com/facebook.com/192.168.0.1 etc.) 117 | * Account (ex. root/abc@mail.com etc.) 118 | * Renewal date 119 | * Master key (SHA512 hash value of user entered key) 120 | 121 | 122 | ### Basic Algorithms 123 | 124 | ##### A. Hashing 125 | 126 | Forgiva generates hashes by keeping key-space stable. n-bits of data gets hashed to n-bits of data by dividing data into hash-size. 127 | 128 | ``` 129 | algorithm forgiva-hashing 130 | Input: Value to get hashed as DATA, Hashing algorithm HALG 131 | Output: Hashed input data 132 | if HALG.hash-size < data-size 133 | start_index = 0 134 | end_index = HALG.hash-size 135 | while start_index < DATA size 136 | input_block = DATA content from start_index to end_index 137 | output_block = HALG.hash(input_block) 138 | result = result appended output_block 139 | start_index = end_index 140 | end_index = start_index + HALG.hash-size 141 | return result with the same size of DATA 142 | else 143 | return ALG.hash(DATA) 144 | ``` 145 | ##### B. Iterative Hashing 146 | 147 | Resembles hashing a value with various algorithms which are chosen by the characters of the value. Before getting into algorithm it must be understood that hashing algorithms are contained in an array and gets chosen by index number of it. 148 | 149 | ``` 150 | algorithm forgiva-iterative-hashing 151 | Input: Value to hashed as DATA, Algorithm array AARRAY 152 | Ouput: Hashed input data 153 | final_value = DATA 154 | for each character C in DATA 155 | algorithm = AARRAY index of (C code num modulus AARRAY) 156 | final_value = forgiva-hash(final_value, algorithm) 157 | return final_value 158 | ``` 159 | 160 | ##### C. Encrypting 161 | 162 | Encryption process with Forgiva is totally same with the algorithms except; 163 | 164 | * Data block sizes gets fit into algorithm block sizes by padding zeroes or shortening. 165 | * Encryption key gets put into PBKDF2_HMAC_SHA1 algorithm with 10_000 iteration and initialization vector (IV) is set as 'SHA512' value of encryption key. 166 | 167 | 168 | ##### D. Iterative Encryption 169 | 170 | It's totaly same iteration-method used iterative hashing by using encryption algorithm array. As a different approach there is two input data and one will be used data to get encrypted and the other one will be used as key. 171 | 172 | 173 | ``` 174 | algorithm forgiva-iterative-encryption 175 | Input: Value to get encrypted as DATA, Value to used in encryption as DATA2, Algorithm array AARRAY 176 | Ouput: Encrypted input data 177 | final_value = DATA 178 | for each character C in DATA 179 | algorithm = AARRAY index of (C code num modulus AARRAY size) 180 | final_value = forgiva-encrypt(algorithm,final_value,DATA2) 181 | return final_value 182 | ``` 183 | ### Password generation process 184 | 185 | 186 | #### 1. Iterative hashing 187 | 188 | Host, Account, Renewal Date and Master key gets into **forgiva-iterative-hashing** algorithm twice. 189 | 190 | ``` 191 | Output: Hashed Host -> HHOST 192 | Hashed Account -> HACCOUNT 193 | Hashed Renewal Date -> HRDATE 194 | Hashed Master Key -> HMKEY 195 | ``` 196 | 197 | #### 2. Iterative encryption 198 | 199 | Hashed datas gets into **forgiva-iterative-encryption** process as pairs and finally whole encryption phase reduces into one result. 200 | 201 | ``` 202 | algorithm forgiva-encrypted-inputs 203 | Input: Hashed Host as HHOST, Hashed Account HACCOUNT, Hashed Renewal Date HRDATE, Hashed Master Key as HMKEY 204 | Output: Encrypted result as DATA 205 | first_pair_pre = forgiva-iterative-encryption(HHOST, HACCOUNT) 206 | first_pair = forgiva-iterative-encryption(first_pair_pre, HMKEY) 207 | second_pair = forgiva-iterative-encryption(HRDATE,HMKEY) 208 | return forgiva-iterative-encryption(first_pair,second_pair) 209 | ``` 210 | 211 | #### 3. Password derivation 212 | 213 | Forgiva uses PBKDF2-HMAC as base of the key-derivation family and uses **forgiva-encypted-inputs** as salt mechanism. 214 | 215 | Depending on choices of the complexity it uses SHA1 (Normal),SHA256 (Intermediate) and SHA512 (Advanced) hashing algorithms. 216 | 217 | Note: After 1.0.1.4 Algorithm; SCrypt support added 218 | 219 | ``` 220 | algorithm key-derivation 221 | Input: forgiva-encrypted-inputs as SALT, SHA512 value of master key as KEY 222 | Output: Array of password sized of animal count 223 | hash = KEY 224 | if scrypt_required 225 | hash = scrypt(hash,SALT,131072,8,1) // n = 2^7 , p=8, r=1 226 | for each Animal 227 | hash = PBKDF2_HMAC_SHA1(hash,SALT, 10.000 iterationg with 32 bit key expectation) 228 | password = forgiva-hash-to-password(hash) 229 | push password to return animal array 230 | ``` 231 | 232 | 233 | #### 3.1. Hash to password conversion 234 | 235 | Due to choice of complexity Forgiva uses different character-ranges to generate a good password by using hashes. 236 | 237 | 238 | ``` 239 | algorithm hash-to-password 240 | Input: Hashed value as DATA, characters which will be used in password as CHARACTER_ARRAY 241 | Output: 512 bit of data as KEY 242 | temporary_hash = SHA512(DATA) 243 | for each character C in temporary_hash 244 | password += CHARACTER_ARRAY index of (C code num modulus CHARACTER_ARRAY size) 245 | return password 246 | 247 | ``` 248 | 249 | ## Intellectual Property 250 | 251 | Except for the components mentioned within their own copyright restrictions, the Forgiva code in this repository is copyright (c) 2016 Sceptive and under [CC BY-NC-SA 4.0 license.](https://creativecommons.org/licenses/by-nc-sa/4.0/) 252 | 253 | ## References 254 | 255 | [1] [PKCS #5: Password-Based Cryptography Specification Version 2.0](https://tools.ietf.org/html/rfc2898) 256 | 257 | [2] [US Secure Hash Algorithms (SHA and HMAC-SHA)](https://tools.ietf.org/html/rfc4634) 258 | 259 | [3] [HMAC: Keyed-Hashing for Message Authentication](https://tools.ietf.org/html/rfc2104) 260 | -------------------------------------------------------------------------------- /bin/forgiva: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'forgiva_test' 4 | require 'forgiva_commands' 5 | require 'constants' 6 | require 'openssl' 7 | 8 | 9 | BANNER = Constants::COLOR_CYA + "\n .-\" L_ " + 10 | Constants::COLOR_CYA + " FORGIVA (" + Constants::COLOR_MGN + "Open Source Edition" + Constants::COLOR_CYA + ")\n " + 11 | Constants::COLOR_CYA + ";`, / ( o\\ " + 12 | Constants::COLOR_CYA + " The new-age password manager\n" + 13 | Constants::COLOR_CYA + " \\ ; `, / \n" + 14 | " ;_/\"`.__.-\" \n\n" + Constants::COLOR_RST 15 | 16 | USAGE = < 1.6', '>= 1.6.20' 19 | gem.add_runtime_dependency 'scrypt' 20 | 21 | 22 | gem.add_development_dependency 'rubocop', '~> 0.52' 23 | end 24 | -------------------------------------------------------------------------------- /lib/constants.rb: -------------------------------------------------------------------------------- 1 | # Algorithms, password characters, animals 2 | module Constants 3 | 4 | ENC_ALGS = %w(des-ede3-cbc camellia-128-cbc camellia-192-cbc camellia-256-cbc cast5-cbc bf-cbc aes-128-cbc aes-192-cbc aes-256-cbc).freeze 5 | HASH_ALGS = %w(sha512 sha384 sha256 sha224 sha1 sha md5 md4 ripemd160).freeze 6 | 7 | LETTERS = %w(q w e r t y u i o p a s d f g h j k l z x c v b n m).freeze 8 | BIG_LETTERS = %w(Q W E R T Y U I O P A S D F G H J K L Z X C V B N M).freeze 9 | NUMBERS = %w(0 1 2 3 4 5 6 7 8 9).freeze 10 | SPECIAL_CHARS = %w(. @ + - * / % _ ! ,).freeze 11 | 12 | INTERMEDIATE_CHARS = %w(| # $ ; \\ ( ) > < " =).freeze 13 | 14 | ADVANCED_CHARS = %w(´ ~ £ ¢ § ^ & ± { }).freeze 15 | 16 | PASSWORD_CHARS = (LETTERS + BIG_LETTERS + NUMBERS + SPECIAL_CHARS).freeze 17 | 18 | PASSWORD_CHARS_INTERMEDIATE = (PASSWORD_CHARS + INTERMEDIATE_CHARS).freeze 19 | 20 | PASSWORD_CHARS_ADVANCED = (PASSWORD_CHARS_INTERMEDIATE + ADVANCED_CHARS).freeze 21 | 22 | ANIMALS = %w(Ape Bat Bear Whale Crow Dog Duck Cat Wasp Fox Gull Hyena Lion Panda 23 | Rat Shark Spider Turtle Wolf Zebra).freeze 24 | 25 | FORGIVA_PG_SIMPLE = 1 26 | FORGIVA_PG_INTERMEDIATE = 2 27 | FORGIVA_PG_ADVANCED = 3 28 | 29 | COLOR_BLK = Gem.win_platform? ? "" : "\x1b[0;30m" 30 | COLOR_RED = Gem.win_platform? ? "" : "\x1b[0;31m" 31 | COLOR_GRN = Gem.win_platform? ? "" : "\x1b[0;32m" 32 | COLOR_BRN = Gem.win_platform? ? "" : "\x1b[0;33m" 33 | COLOR_BLU = Gem.win_platform? ? "" : "\x1b[0;34m" 34 | COLOR_MGN = Gem.win_platform? ? "" : "\x1b[0;35m" 35 | COLOR_CYA = Gem.win_platform? ? "" : "\x1b[0;36m" 36 | COLOR_LGR = Gem.win_platform? ? "" : "\x1b[0;37m" 37 | COLOR_GRA = Gem.win_platform? ? "" : "\x1b[1;90m" 38 | COLOR_LRD = Gem.win_platform? ? "" : "\x1b[1;91m" 39 | COLOR_LGN = Gem.win_platform? ? "" : "\x1b[1;92m" 40 | COLOR_YEL = Gem.win_platform? ? "" : "\x1b[1;93m" 41 | COLOR_LBL = Gem.win_platform? ? "" : "\x1b[1;94m" 42 | COLOR_PIN = Gem.win_platform? ? "" : "\x1b[1;95m" 43 | COLOR_LCY = Gem.win_platform? ? "" : "\x1b[1;96m" 44 | COLOR_BRI = Gem.win_platform? ? "" : "\x1b[1;97m" 45 | COLOR_RST = Gem.win_platform? ? "" : "\x1b[0m" 46 | 47 | # Set true to dump password generation details 48 | DEBUG_OUTPUT = false 49 | 50 | 51 | 52 | 53 | end 54 | -------------------------------------------------------------------------------- /lib/forgiva.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | require 'openssl' 3 | require 'highline/import' 4 | require 'constants' 5 | require 'scrypt' 6 | 7 | # Password generation from 4 inputs 8 | class Forgiva 9 | attr_accessor :hostname, :account, :renewal_date, :master_password, :complexity, :length, :use_scrypt 10 | 11 | def initialize(hostname, account, renewal_date, master_password, complexity, length, use_scrypt) 12 | @hostname = hostname 13 | @account = account 14 | @renewal_date = renewal_date 15 | @master_password = master_password 16 | @complexity = complexity 17 | @length = length 18 | @use_scrypt = use_scrypt 19 | end 20 | 21 | def passwords 22 | @passwords ||= generate 23 | end 24 | 25 | 26 | 27 | def generate 28 | passwords = {} 29 | 30 | # Getting input data as encrypted as salt 31 | salt = encrypted_inputs 32 | 33 | puts "SALT: #{salt.unpack('H*')}" if Constants::DEBUG_OUTPUT 34 | 35 | # Getting master password as already hashed SHA512 36 | key = master_password 37 | 38 | puts "CLEAR KEY: #{key.unpack('H*')}" if Constants::DEBUG_OUTPUT 39 | 40 | # If we have complexity options, then we overrun key 41 | # with the pbkdf2 hmac sha256 or sha512 algorithms 42 | if (@complexity == 2 || @complexity == 3) then 43 | key = Forgiva.pbkdf2_hmac_sha(key,salt,@complexity) 44 | end 45 | 46 | puts "ENC KEY: #{key.unpack('H*')}" if Constants::DEBUG_OUTPUT 47 | 48 | if (@use_scrypt) then 49 | key = SCrypt::Engine.scrypt(key,salt,131072,8,1,32) 50 | end 51 | 52 | 53 | Constants::ANIMALS.each do |a| 54 | # For every other animal we re-run pbkdf2 hmac with sha1 over key 55 | key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 10_000, 32) 56 | 57 | puts "GEN_KEY: #{key.unpack('H*')}" if Constants::DEBUG_OUTPUT 58 | 59 | passwords[a] = Forgiva.hash_to_password(key,@complexity, @length) 60 | end 61 | 62 | passwords 63 | end 64 | 65 | def hashed_hostname 66 | Forgiva.hash_twice(hostname) 67 | end 68 | 69 | def hashed_account 70 | Forgiva.hash_twice(account) 71 | end 72 | 73 | def hashed_renewal_date 74 | Forgiva.hash_twice(renewal_date) 75 | end 76 | 77 | def hashed_master_password 78 | Forgiva.hash_twice(master_password) 79 | end 80 | 81 | def encrypted_inputs 82 | 83 | 84 | puts "hashed_hostname: #{hashed_hostname.unpack('H*')}" if Constants::DEBUG_OUTPUT 85 | puts "hashed_account: #{hashed_account.unpack('H*')}" if Constants::DEBUG_OUTPUT 86 | 87 | # Encrypt iteratively hostname and account and master_password 88 | encrypt01 = Forgiva.iterative_encrypt(Forgiva.iterative_encrypt(hashed_hostname, hashed_account), 89 | hashed_master_password) 90 | 91 | puts "encrypt01: #{encrypt01.unpack('H*')}" if Constants::DEBUG_OUTPUT 92 | 93 | puts "hashed_renewal_date: #{hashed_renewal_date.unpack('H*')}" if Constants::DEBUG_OUTPUT 94 | puts "hashed_master_password: #{hashed_master_password.unpack('H*')}" if Constants::DEBUG_OUTPUT 95 | 96 | # Encrypt iteratively renewal date and master key 97 | encrypt02 = Forgiva.iterative_encrypt(hashed_renewal_date, hashed_master_password) 98 | 99 | puts "encrypt02: #{encrypt02.unpack('H*')}" if Constants::DEBUG_OUTPUT 100 | 101 | # Encrypt iteratively prior generated values 102 | ret = Forgiva.iterative_encrypt( 103 | encrypt01, 104 | encrypt02) 105 | 106 | puts "forgiva_encrypted_inputs: #{ret.unpack('H*')}" if Constants::DEBUG_OUTPUT 107 | 108 | return ret 109 | end 110 | 111 | 112 | 113 | ################# 114 | # Class methods # 115 | ################# 116 | def self.pbkdf2_hmac_sha(key,salt,type) 117 | 118 | rkey = nil 119 | 120 | if (type == Constants::FORGIVA_PG_SIMPLE) then 121 | rkey = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 10_000, 32) 122 | elsif (type == Constants::FORGIVA_PG_INTERMEDIATE) then 123 | digest = OpenSSL::Digest::SHA256.new 124 | rkey = OpenSSL::PKCS5.pbkdf2_hmac(key,salt,10_000 * 1000, 32,digest); 125 | elsif (type == Constants::FORGIVA_PG_ADVANCED) then 126 | digest = OpenSSL::Digest::SHA512.new 127 | rkey = OpenSSL::PKCS5.pbkdf2_hmac(key,salt,10_000 * 10000, 32,digest); 128 | end 129 | 130 | return rkey 131 | end 132 | 133 | def self.pad_with_zeroes(data,block_size) 134 | 135 | if (data.length % block_size != 0) then 136 | 137 | tot = block_size + data.length 138 | 139 | toadd = (tot - (tot % block_size) - data.length) 140 | 141 | for i in (1..toadd) do 142 | data = data + "\x00" 143 | end 144 | 145 | end 146 | 147 | data 148 | end 149 | 150 | def self.shorten_if_long(data,block_size) 151 | 152 | data = data[0..block_size] if data.length > block_size 153 | 154 | data 155 | end 156 | 157 | def self.encrypt_ex(alg, data, key,iv) 158 | 159 | cipher = OpenSSL::Cipher::Cipher.new(alg) 160 | cipher.encrypt 161 | 162 | key_ = shorten_if_long(pad_with_zeroes(key,cipher.key_len),cipher.key_len) 163 | iv_ = shorten_if_long(pad_with_zeroes(iv,cipher.iv_len),cipher.iv_len) 164 | 165 | cipher.key = key_ 166 | cipher.iv = iv_ 167 | 168 | ## Padding if length is not multiple of block size of cipher 169 | data = pad_with_zeroes(data,cipher.block_size) 170 | 171 | puts "self.encrypt: #{alg} - #{data.unpack('H*')} Key: #{cipher.key_len} #{key_.unpack('H*')} IV: #{cipher.iv_len} #{iv_.unpack('H*')}" if Constants::DEBUG_OUTPUT 172 | 173 | 174 | ret = cipher.update(data) 175 | 176 | #+ cipher.final 177 | 178 | puts "self.encrypt: (ret) #{ret.unpack('H*')}" if Constants::DEBUG_OUTPUT 179 | 180 | return ret 181 | 182 | 183 | rescue OpenSSL::Cipher::CipherError => e 184 | puts "Error: #{e.message} data_len #{data.length} key_len #{key.length} iv_len #{iv.length}" 185 | end 186 | 187 | def self.encrypt(alg, data, extension) 188 | 189 | return self.encrypt_ex(alg, 190 | data, 191 | self.pbkdf2_hmac_sha(extension,'forgiva', Constants::FORGIVA_PG_SIMPLE), 192 | sha512ize(extension)) 193 | end 194 | 195 | def self.iterative_encrypt(val1, val2) 196 | ret = val1 197 | 198 | val1.each_byte do |c| 199 | alg = Constants::ENC_ALGS[c % Constants::ENC_ALGS.length] 200 | ret = encrypt(alg, ret, val2) 201 | end 202 | 203 | 204 | puts "#{ret.unpack('H*')}" if Constants::DEBUG_OUTPUT 205 | 206 | ret 207 | end 208 | 209 | def self.hash(alg, val) 210 | dig = OpenSSL::Digest.new(alg) 211 | nval =val 212 | puts "alg: #{alg}" if (val == nil) 213 | 214 | 215 | ret = "" 216 | puts "HASH IN: #{nval.unpack('H*')}:#{nval.length} alg: #{alg} dl: #{dig.digest_length}" if Constants::DEBUG_OUTPUT 217 | 218 | if (dig.digest_length < val.length) then 219 | 220 | st = 0 221 | en = dig.digest_length 222 | while (true) do 223 | 224 | inblock = val[st..en-1] 225 | puts "INBLOCK: #{inblock.unpack('H*')}:#{inblock.length}" if Constants::DEBUG_OUTPUT 226 | outblock = OpenSSL::Digest.digest(alg,inblock) 227 | puts "OUTBLOCK: #{outblock.unpack('H*')}:#{outblock.length}" if Constants::DEBUG_OUTPUT 228 | ret = ret + outblock 229 | puts "NRET: #{ret.unpack('H*')}:#{ret.length}" if Constants::DEBUG_OUTPUT 230 | 231 | st = en 232 | break if (st >= val.length) 233 | 234 | en = st + dig.digest_length 235 | en = val.length if (en > val.length) 236 | end 237 | 238 | ret = ret[0...val.length] 239 | 240 | else 241 | ret = dig.digest(nval) 242 | end 243 | 244 | 245 | puts "HASH OUT: #{ret.unpack('H*')}:#{ret.length}" if Constants::DEBUG_OUTPUT 246 | return ret 247 | end 248 | 249 | def self.iterative_hash(val) 250 | ret = val 251 | 252 | val.each_byte do |c| 253 | alg = Constants::HASH_ALGS[c % Constants::HASH_ALGS.length] 254 | ret = hash(alg, ret) 255 | end 256 | 257 | ret 258 | end 259 | 260 | def self.sha512ize(val) 261 | hash('sha512', val) 262 | end 263 | 264 | def self.hash_twice(val) 265 | iterative_hash(iterative_hash(val)) 266 | end 267 | 268 | def self.hash_to_password(val,complexity,length) 269 | ret = '' 270 | 271 | # to be sure it is long enough 272 | hashed = sha512ize(val) 273 | 274 | 275 | pchars = (complexity == 2 ? Constants::PASSWORD_CHARS_INTERMEDIATE : 276 | (complexity == 3 ? Constants::PASSWORD_CHARS_ADVANCED : Constants::PASSWORD_CHARS)) 277 | 278 | 279 | hashed.each_byte do |c| 280 | ret += pchars[c % pchars.length] 281 | break if ret.length >= length 282 | end 283 | 284 | ret = ret[0..length-1] 285 | 286 | puts "HASH_TO_PASSWORD (IN): #{val.unpack('H*')}" if Constants::DEBUG_OUTPUT 287 | puts "HASH_TO_PASSWORD (HASHED): #{hashed.unpack('H*')}" if Constants::DEBUG_OUTPUT 288 | puts "HASH_TO_PASSWORD (OUT): #{ret.unpack('H*')}" if Constants::DEBUG_OUTPUT 289 | 290 | return ret 291 | 292 | end 293 | end 294 | -------------------------------------------------------------------------------- /lib/forgiva_commands.rb: -------------------------------------------------------------------------------- 1 | require 'forgiva' 2 | require 'date' 3 | 4 | # Command line access to Forgiva 5 | class ForgivaCommands 6 | attr_accessor :hash_args 7 | 8 | def initialize(hash_args = {}) 9 | @hash_args = hash_args 10 | end 11 | 12 | def run 13 | 14 | single_generate_choose if single_by_choose? 15 | single_generate if !single_by_choose? 16 | end 17 | 18 | def ask_for_master_password 19 | 20 | master_password = 'a' 21 | master_password_check = 'b' 22 | 23 | while master_password != master_password_check 24 | master_password = ask(Constants::COLOR_CYA + "Master password: " + Constants::COLOR_RST ) { |q| q.echo = false } 25 | master_password_check = ask(Constants::COLOR_CYA + "Master password (again): " + Constants::COLOR_RST ) { |q| q.echo = false } 26 | 27 | puts 'Master passwords do not match!' unless master_password == master_password_check 28 | end 29 | 30 | 31 | 32 | digest = OpenSSL::Digest.digest("sha512",master_password) 33 | 34 | puts "digest: #{digest.unpack('H*')}" if Constants::DEBUG_OUTPUT 35 | return digest 36 | end 37 | 38 | 39 | def forgiva_r_path 40 | File.join(Dir.home, '.forgivacr') 41 | end 42 | 43 | def record 44 | line_to_add = "#{@hostname};#{@account};#{@renewal_date}" 45 | 46 | File.open(forgiva_r_path, 'a') do |file| 47 | file.puts line_to_add 48 | end 49 | end 50 | 51 | def saved_records 52 | recs = [] 53 | i_a = 1 54 | File.open(forgiva_r_path).each do |line| 55 | 56 | begin 57 | recs << line.rstrip 58 | hostname, account, renewal_date = line.rstrip.split(';') 59 | 60 | puts "#{Constants::COLOR_BRI}#{i_a} - #{Constants::COLOR_BLU}#{hostname} #{Constants::COLOR_CYA} #{account} : #{Constants::COLOR_RST} #{renewal_date}" 61 | i_a += 1 62 | rescue 63 | puts "Invalid line in credentials file (#{forgiva_r_path}) - #{line} " 64 | exit(1) 65 | end 66 | end 67 | 68 | recs 69 | end 70 | 71 | def single_generate_choose 72 | recs = saved_records 73 | 74 | puts('') 75 | idx = ask("#{Constants::COLOR_GRN}Selection: #{Constants::COLOR_RST}") 76 | 77 | r = recs[idx.to_i-1].split(';') 78 | 79 | @hostname = r[0] 80 | @account = r[1] 81 | @renewal_date = r[2] 82 | 83 | single_generate 84 | end 85 | 86 | def single_generate 87 | 88 | init_hostname 89 | init_account 90 | init_renewal_date 91 | init_length 92 | init_master_password 93 | init_complexity 94 | init_scrypt 95 | 96 | puts Constants::COLOR_GRN + "Generating..." + Constants::COLOR_RST 97 | puts "" 98 | 99 | record if record? 100 | 101 | passwords = make_passwords(@hostname, @account, @renewal_date, @master_password, @complexity, @length, @use_scrypt) 102 | 103 | if animals.length > 1 104 | Constants::ANIMALS.each { |a| puts "#{Constants::COLOR_YEL}#{a}#{Constants::COLOR_RST}\t#{Constants::COLOR_BRI}#{passwords[a]}#{Constants::COLOR_RST}" } 105 | else 106 | puts passwords[animals[0]] 107 | end 108 | end 109 | 110 | def record? 111 | hash_args.key? 's' || hash_args.key?('save-credentials') 112 | end 113 | 114 | def single_by_choose? 115 | hash_args.key?('e') || hash_args.key?('select-credentials') 116 | end 117 | 118 | def init_scrypt 119 | @use_scrypt = (hash_args['p'] != nil || hash_args['scrypt'] != nil) 120 | end 121 | 122 | def init_length 123 | @length = 16 124 | @length = hash_args['l'].to_i if hash_args['l'] != nil 125 | @length = hash_args['length'].to_i if @length == nil && hash_args['length'] != nil 126 | return @length 127 | end 128 | 129 | def init_master_password 130 | @master_password = ask_for_master_password 131 | return @master_password 132 | end 133 | 134 | 135 | def init_complexity 136 | @complexity = Constants::FORGIVA_PG_SIMPLE 137 | @complexity = hash_args['c'].to_i if hash_args['c'] != nil 138 | @complexity = hash_args['complexity'].to_i if @complexity == nil && hash_args['complexity'] != nil 139 | 140 | if (@complexity == Constants::FORGIVA_PG_INTERMEDIATE) then 141 | puts Constants::COLOR_YEL + "\nINTERMEDIATE COMPLEXITY\n" + Constants::COLOR_RST 142 | elsif (@complexity == Constants::FORGIVA_PG_ADVANCED) then 143 | puts Constants::COLOR_RED + "\nADVANCED COMPLEXITY\n" + Constants::COLOR_RST 144 | end 145 | 146 | return @complexity 147 | end 148 | 149 | 150 | def init_hostname 151 | @hostname = hash_args['h'] if hash_args['h'] != nil 152 | @hostname = hash_args['host'] if @hostname == nil && hash_args['host'] != nil 153 | @hostname = ask(Constants::COLOR_GRN + "Hostname: " + Constants::COLOR_RST ) if @hostname == nil 154 | return @hostname 155 | end 156 | 157 | def init_account 158 | @account = hash_args['a'] if hash_args['a'] != nil 159 | @account = hash_args['account'] if hash_args['account'] != nil 160 | @account = ask(Constants::COLOR_GRN + "Account: " + Constants::COLOR_RST ) if @account == nil 161 | return @account 162 | end 163 | 164 | def init_renewal_date 165 | @renewal_date = "1970-01-01" #Time.now.strftime("%Y-%m-%d") 166 | @renewal_date = hash_args['r'] if hash_args['r'] != nil 167 | @renewal_date = hash_args['renewal-date'] if @hostname == nil && hash_args['renewal-date'] != nil 168 | 169 | begin 170 | Date.strptime(@renewal_date, '%Y-%m-%d') 171 | rescue 172 | puts "WARNING: Renewal date is not valid for YEAR-MONTH-DAY format but still accepted"; 173 | end 174 | 175 | @renewal_date = @renewal_date.gsub(';','') 176 | 177 | return @renewal_date 178 | end 179 | 180 | def animals 181 | 182 | return Constants::ANIMALS 183 | 184 | end 185 | 186 | def make_passwords(hostname, account, renewal_date, master_password, complexity,length,use_scrypt) 187 | Forgiva.new(hostname, account, renewal_date, master_password,complexity,length,use_scrypt).passwords 188 | end 189 | 190 | 191 | 192 | end 193 | -------------------------------------------------------------------------------- /lib/forgiva_test.rb: -------------------------------------------------------------------------------- 1 | require 'forgiva' 2 | require 'testvectors' 3 | require 'openssl' 4 | require 'constants' 5 | 6 | class ForgivaTest 7 | 8 | 9 | def self.run_tests 10 | 11 | 12 | TestVectors::FA_TESTS.each do |test_vec| 13 | 14 | puts "#{Constants::COLOR_GRN} Testing algorithm #{test_vec[:algorithm_name]} ... #{Constants::COLOR_RST}" 15 | 16 | plain_data = [test_vec[:data_hex]].pack('H*') 17 | key = [test_vec[:key_hex]].pack('H*') 18 | iv = [test_vec[:iv_hex]].pack('H*') 19 | expected = [test_vec[:target_hex]].pack('H*') 20 | 21 | if (test_vec[:is_encryption_algorithm]) then 22 | result = Forgiva.encrypt_ex(test_vec[:algorithm_name], plain_data, key, iv) 23 | 24 | else 25 | result = Forgiva.hash(test_vec[:algorithm_name],plain_data) 26 | end 27 | 28 | if (result != expected) then 29 | puts "#{Constants::COLOR_RED} FAILED: (Expected: #{test_vec[:target_hex]}) #{result.unpack('H*') if result != nil} #{Constants::COLOR_RST}" 30 | end 31 | 32 | end 33 | 34 | 35 | TestVectors::FG_TESTS.each do |test_vec| 36 | 37 | for i in 0..1 do 38 | puts "#{Constants::COLOR_GRN} Testing forgiva #{Constants::COLOR_BLU} #{test_vec[:host]} " \ 39 | <<"/ #{test_vec[:account]} / #{test_vec[:renewal_date]} / #{Constants::COLOR_MGN} #{test_vec[:animal_name]} #{Constants::COLOR_GRN} " \ 40 | <<" on complexity #{test_vec[:complexity]} #{Constants::COLOR_RST}" \ 41 | <<"#{Constants::COLOR_YEL}" \ 42 | << (i == 1 ? "+SCRYPT" : "") \ 43 | << "#{Constants::COLOR_RST}" 44 | 45 | p_hash = OpenSSL::Digest.digest("sha512",test_vec[:master_key]) 46 | 47 | passes = Forgiva.new(test_vec[:host], 48 | test_vec[:account], 49 | test_vec[:renewal_date], 50 | p_hash, 51 | test_vec[:complexity], 52 | 16, 53 | i == 1 54 | ).passwords 55 | 56 | g_pass = passes[test_vec[:animal_name]].unpack('H*')[0] 57 | 58 | expected = (i == 0 ? test_vec[:expected_password_hash] : test_vec[:expected_password_hash_scrypt]) 59 | 60 | if (g_pass.downcase != expected) then 61 | puts "#{Constants::COLOR_RED} FAILED: (Expected: #{expected}) #{Constants::COLOR_RST} #{g_pass}" 62 | else 63 | puts "#{Constants::COLOR_GRN}! SUCCESS: (#{g_pass}) #{Constants::COLOR_RST}" 64 | end 65 | end 66 | 67 | 68 | end 69 | 70 | 71 | end 72 | 73 | 74 | end 75 | -------------------------------------------------------------------------------- /lib/testvectors.rb: -------------------------------------------------------------------------------- 1 | require 'constants' 2 | 3 | 4 | module TestVectors 5 | FG_TESTS = [ 6 | {:host => "facebook.com", 7 | :account => "bill.gates@microsoft.com", 8 | :renewal_date => "1970-01-01", 9 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 10 | :complexity => Constants::FORGIVA_PG_SIMPLE, 11 | :animal_name => "Ape", 12 | :expected_password_hash => "797036592a475f78444c6153504d3757", 13 | :expected_password_hash_scrypt => "466b74674d645a4d6939302a6e56797a" 14 | }, 15 | 16 | ## facebook.com - root 17 | {:host => "facebook.com", 18 | :account => "root", 19 | :renewal_date => "1970-01-01", 20 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 21 | :complexity => Constants::FORGIVA_PG_INTERMEDIATE, 22 | :animal_name => "Bat", 23 | :expected_password_hash => "5544245f2b72682e4635765040416a49", 24 | :expected_password_hash_scrypt => "354b223d3b6c246733386c2d6674283d" 25 | 26 | }, 27 | 28 | ## facebook.com - k3ym4k3r 29 | {:host => "facebook.com", 30 | :account => "k3ym4k3r", 31 | :renewal_date => "1970-01-01", 32 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 33 | :complexity => Constants::FORGIVA_PG_ADVANCED, 34 | :animal_name => "Bear", 35 | :expected_password_hash => "4f5c7653513251417a675949284c5539", 36 | :expected_password_hash_scrypt => "587a796a7c40267426637b694d345459" 37 | 38 | }, 39 | 40 | ## facebook.com - scr1ptk1dd1e 41 | {:host => "facebook.com", 42 | :account => "scr1ptk1dd1e", 43 | :renewal_date => "1970-01-01", 44 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 45 | :complexity => Constants::FORGIVA_PG_SIMPLE, 46 | :animal_name => "Whale", 47 | :expected_password_hash => "6465635a675374322f47695051464157", 48 | :expected_password_hash_scrypt => "496375392e63486a59434473334d6169" 49 | }, 50 | 51 | 52 | 53 | ## microsoft.com - toor 54 | {:host => "microsoft.com", 55 | :account => "toor", 56 | :renewal_date => "1970-01-01", 57 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 58 | :complexity => Constants::FORGIVA_PG_INTERMEDIATE, 59 | :animal_name => "Crow", 60 | :expected_password_hash => "4d314573586d403649672970786d7133", 61 | :expected_password_hash_scrypt => "3e51542a4d364d31657673467c6d4728" 62 | }, 63 | 64 | 65 | ## 192.168.0.1 - root 66 | {:host => "192.168.0.1", 67 | :account => "root", 68 | :renewal_date => "1970-01-01", 69 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 70 | :complexity => Constants::FORGIVA_PG_ADVANCED, 71 | :animal_name => "Dog", 72 | :expected_password_hash => "2c376d234a7a6c4d6f785c34494a672a", 73 | :expected_password_hash_scrypt => "4939c2a232217c5c405a6c714e76552566" 74 | }, 75 | 76 | 77 | 78 | ## 10.0.0.2:22 - root 79 | {:host => "10.0.0.2:22", 80 | :account => "root", 81 | :renewal_date => "1970-01-01", 82 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 83 | :complexity => Constants::FORGIVA_PG_SIMPLE, 84 | :animal_name => "Duck", 85 | :expected_password_hash => "6440562a36375065693646396e312c4b", 86 | :expected_password_hash_scrypt => "345057425a5133756c5965745f7a7054" 87 | 88 | }, 89 | 90 | 91 | 92 | ## 10.0.0.2:22 - k3ym4k3r 93 | {:host => "10.0.0.2:22", 94 | :account => "k3ym4k3r", 95 | :renewal_date => "1970-01-01", 96 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 97 | :complexity => Constants::FORGIVA_PG_INTERMEDIATE, 98 | :animal_name => "Cat", 99 | :expected_password_hash => "78435f57566e2f53535f2e617738293b", 100 | :expected_password_hash_scrypt => "5c624f23723e704673452530773e3144" 101 | 102 | }, 103 | 104 | ## 10.0.0.2:22 - toor 105 | {:host => "10.0.0.2:22", 106 | :account => "toor", 107 | :renewal_date => "1970-01-01", 108 | :master_key => "forgiva_rockz_all_the_fuck1ng_t1m3", 109 | :complexity => Constants::FORGIVA_PG_ADVANCED, 110 | :animal_name => "Wasp", 111 | :expected_password_hash => "54534a582b265f337e2e43403b536861", 112 | :expected_password_hash_scrypt => "332b2541364e306537704e4551763938" 113 | }].freeze 114 | 115 | FA_TESTS = [{:is_encryption_algorithm => true, 116 | :algorithm_name => "camellia-128-cbc", 117 | :data_hex => 118 | "b9717e084ce3a6bb30af116bc811df7cbfdd618c005c92c90076162daba5a849", 119 | :key_hex => "d40d6d81d931ecc30a534c3f9d5dfe01", 120 | :iv_hex => "cd5464cf4236b8a53ad5b42cbc27f0a8", 121 | :target_hex => "5a2e35425a955265856300246eca4e65a4a428935c80e59dffed50852b8430d0"}, 122 | 123 | {:is_encryption_algorithm => true, 124 | :algorithm_name => "camellia-192-cbc", 125 | :data_hex => 126 | "404e8c8b37e91d052ffd70573ed257a9677811cfa73458ba0607dc9e8def97b4", 127 | :key_hex => "edb8557b39e7e656148f850530950d8c", 128 | :iv_hex => "a8708092b77bd94c6b1f0b8cf6b0afd8", 129 | :target_hex => "9b297587c3291ddc538ca02cdcd46476f60d45dcf655ebb4d1f7f072d1c514f7"}, 130 | 131 | {:is_encryption_algorithm => true, 132 | :algorithm_name => "camellia-256-cbc", 133 | :data_hex => 134 | "f266dad6764640de2e13902fb7c04fcd7f1c2e950ceb1b6559d1e620ea2cf39b", 135 | :key_hex => "4200c4cad8b47814a5ed84ab0141aaeb", 136 | :iv_hex => "e0a054f34133aa2602db257fee1e7db1", 137 | :target_hex => "be84b266be13e13fc78a27c4ec86c4d7b70ecb26d8d1f6bbe247744f029eed19"}, 138 | 139 | {:is_encryption_algorithm => true, 140 | :algorithm_name => "cast5-cbc", 141 | :data_hex => 142 | "777de3b277bda18f668e3d152e820c1780355e3acd3c840b21f012dd5746c033", 143 | :key_hex => "896f94494198b4867715bfe43a85678a", 144 | :iv_hex => "164cc12f57553024cf070a9bfe6e9d2e", 145 | :target_hex => "a302710f9e7baf1ce2b77a341db04ce1defb1ef60b3e0cf77b265f877f4acbe8"}, 146 | 147 | {:is_encryption_algorithm => true, 148 | :algorithm_name => "bf-cbc", 149 | :data_hex => 150 | "d487857248f982686da2f4f2089ed190e682e0e9121f60ed5e8e5be9ac5ef899", 151 | :key_hex => "bfb9ed5fb23e17e59d930d25eb530a2c", 152 | :iv_hex => "5a112824d6ae4d9fef511706ec5c68eb", 153 | :target_hex => "8544fe775bd28d691ae13c4083ab43b0c0b84062cade9b166b516dbd65685263"}, 154 | 155 | {:is_encryption_algorithm => true, 156 | :algorithm_name => "aes-128-cbc", 157 | :data_hex => 158 | "63e319d3fb7f655479be7b4a1ef03853c590bda498514ce2a4810fe77bb85aa8aa", 159 | :key_hex => "117063a80532b561a8e9a5fc8d850365", 160 | :iv_hex => "13b6cd9b3c664b0d573fbced0c331040", 161 | :target_hex => "f8102b04449eb1ce0048c67496cce3e3a8f1cdb8238d661caddd7ad7d0af2aa920b7d5f224ae50a492e2534a729ca1eb"}, 162 | 163 | {:is_encryption_algorithm => true, 164 | :algorithm_name => "aes-192-cbc", 165 | :data_hex => 166 | "ad67bfaeadab3c6500cbb59a3995a489b131c371bd20c4a55bfe3d7408d6d84b", 167 | :key_hex => "dbab5fe55cd0f37e33e4b875d861ceb3", 168 | :iv_hex => "98044a639fcec92837b300394a709f2c", 169 | :target_hex => "5e439780e5f56b92911e6e60e7ce74b6c5a71cb197d77d99c0e931600c918c03"}, 170 | 171 | {:is_encryption_algorithm => true, 172 | :algorithm_name => "aes-256-cbc", 173 | :data_hex => 174 | "344e7b462a97d48431d68d315dea1a8b8fcfbe3d73a819471309597127aef5da", 175 | :key_hex => "24545749f13f8fb477c7d5046f490dcc", 176 | :iv_hex => "a5276092d0645616bf8999d744580515", 177 | :target_hex => "c60682324e2b83886e17432c212d6690d44afb465a201055af151b44a3448068"}, 178 | 179 | {:is_encryption_algorithm => false, 180 | :algorithm_name => "sha512", 181 | :data_hex => 182 | "695904cb6bf6b74ab18852f70750139d78dbf7d46dda70ce67afac1de89fd2dd", 183 | :key_hex => "", 184 | :iv_hex => "", 185 | :target_hex => "390e9d9c2a5483695a3707b509cd5a5948dea7221e5c3293b0a4eb4dc3c068811b27eef66adf569e268b2779cb77e35ee030918b7f3364e1882b2d524a96846c"}, 186 | 187 | {:is_encryption_algorithm => false, 188 | :algorithm_name => "sha384", 189 | :data_hex => 190 | "de9beb10c8d4208fc23eaeeda614fa6ecf8811e36d61fca957546c7649e561c1", 191 | :key_hex => "", 192 | :iv_hex => "", 193 | :target_hex => "dbab1b89b069043585eeb67fdae2683ec1f5a2d4e721400a3b2335228f49444fb4a0e0509a55d28ffdc608db0bf8866e"}, 194 | 195 | {:is_encryption_algorithm => false, 196 | :algorithm_name => "sha256", 197 | :data_hex => 198 | "46142ed7236f2420f4bdac45192ba954da0ea56235c03886e4a2b528d60044da", 199 | :key_hex => "", 200 | :iv_hex => "", 201 | :target_hex => "dccec513ea5995846df778bed02468e80ffcac06bd07d20eedbed3d367634492"}, 202 | 203 | {:is_encryption_algorithm => false, 204 | :algorithm_name => "sha224", 205 | :data_hex => 206 | "72f159ef70dee2db9e4ce0df16e19231bbacf4127ec97f430b546f838d82d173", 207 | :key_hex => "", 208 | :iv_hex => "", 209 | :target_hex => "0673d0dd51f915d37baf9767dc24325ab9c2317a73a9ef022aa7911c561efd65"}, 210 | 211 | {:is_encryption_algorithm => false, 212 | :algorithm_name => "sha1", 213 | :data_hex => 214 | "5bb6f36326d34827a14df430bf809a14da00c27583bd33aee91edfe58b24708a", 215 | :key_hex => "", 216 | :iv_hex => "", 217 | :target_hex => "f0ceb2b738be458cc0519e7a8b02c6c5cdc1c773687e1f6fb36642e2b87bfeca"}, 218 | 219 | {:is_encryption_algorithm => false, 220 | :algorithm_name => "sha", 221 | :data_hex => 222 | "a8f11175865f3f4dc543f558c282ec9b7b439bf818a77000adc9dee2199d43f5", 223 | :key_hex => "", 224 | :iv_hex => "", 225 | :target_hex => "47e73858d52f91a9f5a3c798d8903a759834fb955544d01deaf55e1fc380e861"}, 226 | 227 | {:is_encryption_algorithm => false, 228 | :algorithm_name => "md5", 229 | :data_hex => 230 | "1b6bc2af8a57ccf15339f023863d35e5f35d13127622e2d03e008eb78188f772", 231 | :key_hex => "", 232 | :iv_hex => "", 233 | :target_hex => "38806990d2b77c96d5776e3ec43cf2082d05d1de3285443444a67f984d3c2288"}, 234 | 235 | {:is_encryption_algorithm => false, 236 | :algorithm_name => "md4", 237 | :data_hex => 238 | "a64d8b2bbee2a8c820c16a14cfaea65d417decc309b3621e1bd5dc4769bb7c61", 239 | :key_hex => "", 240 | :iv_hex => "", 241 | :target_hex => "354fde36aeadd1816b506956985eb7b05a5f9490ae96d88c7a1b3100a8a8d2bc"}, 242 | 243 | {:is_encryption_algorithm => false, 244 | :algorithm_name => "ripemd160", 245 | :data_hex => 246 | "7c2d9f56b35109f7cfdf554f70fdbf2bbff97a2244c0677820be6b38983c90ea", 247 | :key_hex => "", 248 | :iv_hex => "", 249 | :target_hex => "aec3c24f17677cbeffdf1081af591aaa20e51d04e69da384bb65f1eefebbb1f5"}].freeze 250 | 251 | end 252 | --------------------------------------------------------------------------------