hiera-eyaml-gpg_ruby 0.5 → 0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gemfile +2 -2
 - data/lib/hiera/backend/eyaml/encryptors/gpg.rb +6 -56
 - data/lib/hiera/backend/eyaml/encryptors/gpg/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f977e0b374e9acc78af2c238573bf15dc5f30e76
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 757317de188420c1687b61fd5f8b8ae7e503b773
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: dd63716ef95adcf8768b30aaf0ad99215fcde7944a7f54c7c067cbd7285a2e6de77cd3e99fcfa81e1fd22693522a85d9df239268045794f4d055242ad9b82c26
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b417987eb441341f2db218a7767dc6663f430705dbe938964d6080c4ef5397fa56ca7fc9079774a6c68e062a0366ec3cca9912adea433349e1d30d040b85d57f
         
     | 
    
        data/Gemfile
    CHANGED
    
    
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require ' 
     | 
| 
      
 1 
     | 
    
         
            +
            require 'ruby_gpg'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'base64'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'pathname'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'hiera/backend/eyaml/encryptor'
         
     | 
| 
         @@ -94,75 +94,25 @@ class Hiera 
     | 
|
| 
       94 
94 
     | 
    
         | 
| 
       95 
95 
     | 
    
         
             
                      def self.encrypt plaintext
         
     | 
| 
       96 
96 
     | 
    
         
             
                        gnupghome = self.option :gnupghome
         
     | 
| 
       97 
     | 
    
         
            -
                        GPGME::Engine.home_dir = gnupghome
         
     | 
| 
       98 
97 
     | 
    
         
             
                        debug("GNUPGHOME is #{gnupghome}")
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                        ctx = GPGME::Ctx.new
         
     | 
| 
      
 98 
     | 
    
         
            +
                        RubyGpg.config.homedir = gnupghome
         
     | 
| 
       101 
99 
     | 
    
         | 
| 
       102 
100 
     | 
    
         
             
                        recipients = self.find_recipients
         
     | 
| 
       103 
101 
     | 
    
         
             
                        debug("Recipents are #{recipients}")
         
     | 
| 
       104 
102 
     | 
    
         | 
| 
       105 
103 
     | 
    
         
             
                        raise RecoverableError, 'No recipients provided, don\'t know who to encrypt to' if recipients.empty?
         
     | 
| 
       106 
104 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                         
     | 
| 
       108 
     | 
    
         
            -
                          key_to_use = ctx.keys(r).first 
         
     | 
| 
       109 
     | 
    
         
            -
                          if key_to_use.nil? 
         
     | 
| 
       110 
     | 
    
         
            -
                            raise RecoverableError, "No key found on keyring for #{r}"
         
     | 
| 
       111 
     | 
    
         
            -
                          end
         
     | 
| 
       112 
     | 
    
         
            -
                          key_to_use
         
     | 
| 
       113 
     | 
    
         
            -
                        }
         
     | 
| 
       114 
     | 
    
         
            -
                        debug("Keys: #{keys}")
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
                        always_trust = self.option(:always_trust)
         
     | 
| 
       117 
     | 
    
         
            -
                        unless always_trust
         
     | 
| 
       118 
     | 
    
         
            -
                          # check validity of recipients (this is possibly naive, but better than the unhelpful
         
     | 
| 
       119 
     | 
    
         
            -
                          # error that it would spit out otherwise)
         
     | 
| 
       120 
     | 
    
         
            -
                          keys.each do |key|
         
     | 
| 
       121 
     | 
    
         
            -
                            unless key.primary_uid.validity >= GPGME::VALIDITY_FULL
         
     | 
| 
       122 
     | 
    
         
            -
                              raise RecoverableError, "Key #{key.sha} (#{key.email}) not trusted (if key trust is established by another means then specify always-trust)"
         
     | 
| 
       123 
     | 
    
         
            -
                            end
         
     | 
| 
       124 
     | 
    
         
            -
                          end
         
     | 
| 
       125 
     | 
    
         
            -
                        end
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                        data = GPGME::Data.from_str(plaintext)
         
     | 
| 
       128 
     | 
    
         
            -
                        crypto = GPGME::Crypto.new(:always_trust => always_trust)
         
     | 
| 
      
 105 
     | 
    
         
            +
                        # TODO: check that keys are trusted
         
     | 
| 
       129 
106 
     | 
    
         | 
| 
       130 
     | 
    
         
            -
                         
     | 
| 
       131 
     | 
    
         
            -
                        ciphertext.seek 0
         
     | 
| 
       132 
     | 
    
         
            -
                        ciphertext.read
         
     | 
| 
      
 107 
     | 
    
         
            +
                        RubyGpg.encrypt_string(plaintext, recipients)
         
     | 
| 
       133 
108 
     | 
    
         
             
                      end
         
     | 
| 
       134 
109 
     | 
    
         | 
| 
       135 
110 
     | 
    
         
             
                      def self.decrypt ciphertext
         
     | 
| 
       136 
111 
     | 
    
         
             
                        gnupghome = self.option :gnupghome
         
     | 
| 
       137 
     | 
    
         
            -
                        GPGME::Engine.home_dir = gnupghome
         
     | 
| 
       138 
112 
     | 
    
         
             
                        debug("GNUPGHOME is #{gnupghome}")
         
     | 
| 
      
 113 
     | 
    
         
            +
                        RubyGpg.config.homedir = gnupghome
         
     | 
| 
       139 
114 
     | 
    
         | 
| 
       140 
     | 
    
         
            -
                         
     | 
| 
       141 
     | 
    
         
            -
                          GPGME::Ctx.new
         
     | 
| 
       142 
     | 
    
         
            -
                        else
         
     | 
| 
       143 
     | 
    
         
            -
                          GPGME::Ctx.new(:passphrase_callback => method(:passfunc))
         
     | 
| 
       144 
     | 
    
         
            -
                        end
         
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
                        if !ctx.keys.empty?
         
     | 
| 
       147 
     | 
    
         
            -
                          raw = GPGME::Data.new(ciphertext)
         
     | 
| 
       148 
     | 
    
         
            -
                          txt = GPGME::Data.new
         
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
                          begin
         
     | 
| 
       151 
     | 
    
         
            -
                            txt = ctx.decrypt(raw)
         
     | 
| 
       152 
     | 
    
         
            -
                          rescue GPGME::Error::DecryptFailed => e
         
     | 
| 
       153 
     | 
    
         
            -
                            warn("Fatal: Failed to decrypt ciphertext (check settings and that you are a recipient)")
         
     | 
| 
       154 
     | 
    
         
            -
                            raise e
         
     | 
| 
       155 
     | 
    
         
            -
                          rescue Exception => e
         
     | 
| 
       156 
     | 
    
         
            -
                            warn("Warning: General exception decrypting GPG file")
         
     | 
| 
       157 
     | 
    
         
            -
                            raise e
         
     | 
| 
       158 
     | 
    
         
            -
                          end
         
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
                          txt.seek 0
         
     | 
| 
       161 
     | 
    
         
            -
                          txt.read
         
     | 
| 
       162 
     | 
    
         
            -
                        else
         
     | 
| 
       163 
     | 
    
         
            -
                          warn("No usable keys found in #{gnupghome}. Check :gpg_gnupghome value in hiera.yaml is correct")
         
     | 
| 
       164 
     | 
    
         
            -
                          raise ArgumentError, "No usable keys found in #{gnupghome}. Check :gpg_gnupghome value in hiera.yaml is correct"
         
     | 
| 
       165 
     | 
    
         
            -
                        end
         
     | 
| 
      
 115 
     | 
    
         
            +
                        RubyGpg.decrypt_string(ciphertext)
         
     | 
| 
       166 
116 
     | 
    
         
             
                      end
         
     | 
| 
       167 
117 
     | 
    
         | 
| 
       168 
118 
     | 
    
         
             
                      def self.create_keys
         
     |