def _create_account_key(self):
account_key = crypto.PKey()
if self.type == 'RSA':
crypto_type = crypto.TYPE_RSA
else:
crypto_type = crypto.TYPE_DSA
try:
LOG.info('[global] Generating account key: %s \
(type: %s, size: %s)' %
(self.account_key_name, self.type, self.size))
account_key.generate_key(crypto_type, self.size)
except (TypeError, ValueError):
raise
try:
LOG.debug('[global] Writting account key: %s/private/%s' %
(self.path, self.account_key_name))
accountkey_file = os.open('%s/private/%s' %
(self.path, self.account_key_name),
os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
0o600)
os.write(accountkey_file,
crypto.dump_privatekey(crypto.FILETYPE_PEM, account_key))
os.close(accountkey_file)
except IOError:
try:
os.remove('%s/private/%s.key' %
(self.path, self.account_key_name))
except OSError:
pass
raise
评论列表
文章目录