Esempio n. 1
0
def gen_encrypted_config(key_path, conf_path):
    sconf = SecureConfig.from_key(read(key_path))
    conf = ConfigParser.ConfigParser()
    conf.read(conf_path)

    for section in conf.sections():
        sconf.add_section(section)
        for item_key, item_value in conf.items(section):
            sconf.set(section, item_key, item_value)

    return sconf
from __future__ import print_function

import os

from secureconfig import SecureConfig

# here we're going to open the file we encrypted in the previous demo
# and make sure we can decrypt and parse it using the same keystring.


CWD = os.path.dirname(os.path.realpath(__file__))
output_path = os.path.join(CWD, 'demo_secureconfig_data.enc')
TEST_KEYSTRING = 'sFbO-GbipIFIpj64S2_AZBIPBvX80Yozszw7PR2dVFg='

thing = SecureConfig.from_key(TEST_KEYSTRING, filepath=output_path)

print("In our last episode, we created an encrypted serialized dictionary using SecureConfig.")
print("Now we're going to use the same key to decrypt and read the data back.")
print()

print("What's in this file? Use .sections() to see top-level dictionary data.")
print(thing.sections())
print()

print("So, who is in the family? Use .options('family') and .get('family', member) to see. ")

for member in thing.options('family'):
    print(  member + ": " + thing.get('family', member))

from __future__ import print_function

import os

from secureconfig import SecureConfig

# here we're going to open the file we encrypted in the previous demo
# and make sure we can decrypt and parse it using the same keystring.

CWD = os.path.dirname(os.path.realpath(__file__))
output_path = os.path.join(CWD, 'demo_secureconfig_data.enc')
TEST_KEYSTRING = 'sFbO-GbipIFIpj64S2_AZBIPBvX80Yozszw7PR2dVFg='

thing = SecureConfig.from_key(TEST_KEYSTRING, filepath=output_path)

print(
    "In our last episode, we created an encrypted serialized dictionary using SecureConfig."
)
print("Now we're going to use the same key to decrypt and read the data back.")
print()

print("What's in this file? Use .sections() to see top-level dictionary data.")
print(thing.sections())
print()

print(
    "So, who is in the family? Use .options('family') and .get('family', member) to see. "
)

for member in thing.options('family'):
    print(member + ": " + thing.get('family', member))
Esempio n. 4
0
 def read(self, path, keypath):
     f = open(keypath, 'r')
     key = f.read()
     f.close()
     self.cfg = SecureConfig.from_key(key, filepath=path)
from __future__ import print_function

import os

from secureconfig import SecureConfig

CWD = os.path.dirname(os.path.realpath(__file__))
output_path = os.path.join(CWD, 'demo_secureconfig_data.enc')
TEST_KEYSTRING = 'sFbO-GbipIFIpj64S2_AZBIPBvX80Yozszw7PR2dVFg='

thing = SecureConfig.from_key(TEST_KEYSTRING)

print("Start with an blank slate: ")
print(thing.cfg)
print()

print("Add a section with add_section: ")
thing.add_section('family')
print(thing.cfg)
print()

print("Stick some values in it: ")
thing.set('family', 'grandma', 'Kay')
thing.set('family', 'granddad', 'John')
print(thing.cfg)
print()

print("Now let's write it to disk (%s)" % output_path)
fh = open(output_path, 'w')
thing.write(fh)
fh.close()