Revision c5dc6a3c src/cli/one_helper.rb

View differences:

src/cli/one_helper.rb
37 37

  
38 38
    if ONE_LOCATION
39 39
        TABLE_CONF_PATH=ONE_LOCATION+"/etc/cli"
40
        VAR_LOCATION=ONE_LOCATION+"/var" if !defined?(VAR_LOCATION)
40 41
    else
41 42
        TABLE_CONF_PATH="/etc/one/cli"
43
        VAR_LOCATION="/var/lib/one" if !defined?(VAR_LOCATION)
42 44
    end
43 45

  
44 46
    EDITOR_PATH='/usr/bin/vi'
......
489 491
            end
490 492
        end
491 493

  
494

  
495
        # receive a object key => value format
496
        # returns hashed values
497
        def encrypt(opts)
498

  
499
            res = {}
500
            key_one= File.read(VAR_LOCATION+'/.one/one_key')
501

  
502
            opts.each do |key, value|
503
                cipher = OpenSSL::Cipher::AES.new(256,:CBC)
504
                cipher.encrypt.key = key_one
505
                puts "cifrando #{key}"                
506
                encrypted = cipher.update(value) + cipher.final
507
                #res.merge!({key => value})
508
                res[key] = Base64::encode64(encrypted) 
509
                puts "encriptado es: "+encrypted
510
            end
511
            
512
            return res
513
        end
514

  
515
        def decrypt(res)
516
            opts = {}
517
            key_one= File.read(VAR_LOCATION+'/.one/one_key')
518

  
519
            res.each do |key, encrypted_value|
520
                decipher = OpenSSL::Cipher::AES.new(256,:CBC)
521
                decipher.decrypt
522
                decipher.key = key_one
523
                puts "desencriptando #{key}"
524
                plain = decipher.update(Base64::decode64(encrypted_value)) + decipher.final
525
                puts "una vez desencriptado es "+plain
526
                opts[key] = plain
527
            end
528

  
529
            return opts
530

  
531
        end
532

  
533

  
534

  
492 535
        def list_pool(options, top=false, filter_flag=nil)
493 536
            if options[:describe]
494 537
                table = format_pool(options)

Also available in: Unified diff