This is not a very handy idea to generate random keys.
# Key functions.
-def key_init(**pakfire_args):
- pakfire = Pakfire(**pakfire_args)
-
- return pakfire.keyring.init()
-
def key_generate(realname, email, **pakfire_args):
pakfire = Pakfire(**pakfire_args)
def keyring(self):
"""
Shortcut to access the pakfire keyring.
-
- (Makes also sure that it is properly initialized.)
"""
- assert self.pakfire
-
- if not self.pakfire.keyring.initialized:
- self.pakfire.keyring.init()
-
return self.pakfire.keyring
def lock(self):
# Add sub-commands.
self.sub_commands = self.parser.add_subparsers()
- self.parse_command_init()
self.parse_command_generate()
self.parse_command_import()
self.parse_command_export()
self.pakfire = pakfire.Pakfire(**self.pakfire_args)
self.action2func = {
- "init" : self.handle_init,
"generate" : self.handle_generate,
"import" : self.handle_import,
"export" : self.handle_export,
return ret
- def parse_command_init(self):
- # Parse "init" command.
- sub_init = self.sub_commands.add_parser("init",
- help=_("Initialize the local keyring."))
- sub_init.add_argument("action", action="store_const", const="init")
-
def parse_command_generate(self):
# Parse "generate" command.
sub_gen = self.sub_commands.add_parser("generate",
help=_("Package(s) to verify."))
sub_verify.add_argument("action", action="store_const", const="verify")
- def handle_init(self):
- # Initialize the keyring...
- pakfire.key_init(**self.pakfire_args)
-
def handle_generate(self):
realname = self.args.realname[0]
email = self.args.email[0]
return KEYRING_DIR
def create_path(self):
+ if os.path.exists(self.path):
+ os.chmod(self.path, 700)
+ else:
+ os.makedirs(self.path, 700)
+
filename = os.path.join(self.path, "gnupg.conf")
if os.path.exists(filename):
+ os.chmod(filename, 600)
return
- if not os.path.exists(self.path):
- os.makedirs(self.path)
- # XXX chmod 700
-
# Create a default gnupg.conf.
f = open(filename, "w")
f.write("# This is a default gnupg configuration file created by\n")
f.write("# Pakfire %s.\n" % PAKFIRE_VERSION)
f.close()
- # XXX chmod 600
-
- @property
- def initialized(self):
- """
- Returns true if the local keyring was already initialized.
- """
- if self.get_host_key():
- return True
-
- return False
-
- def init(self):
- # If the host key is already present, we break up.
- if self.initialized:
- log.error(_("The local keyring is already initialized. Aborting."))
- return
-
- log.info(_("Initializing local keyring..."))
- hostname, domainname = system.hostname.split(".", 1)
- self.gen_key(system.hostname, "%s@%s" % (hostname, domainname))
+ os.chmod(filename, 600)
def dump_key(self, keyfp):
ret = []