本文整理汇总了Python中gnupg.GPG.gen_key_input方法的典型用法代码示例。如果您正苦于以下问题:Python GPG.gen_key_input方法的具体用法?Python GPG.gen_key_input怎么用?Python GPG.gen_key_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnupg.GPG
的用法示例。
在下文中一共展示了GPG.gen_key_input方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reqPGP
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
class reqPGP(object):
def __init__(self, path=None):
self.gpg = GPG(gpgbinary=('../gpg.exe' if osName == 'nt' else 'gpg'))
if not path:
try:
self.path = environ["HOME"] + '/'
except KeyError:
self.path = environ["HOMEPATH"] + '\\'
else:
if path[-1] != '\\' and osName == 'nt':
path += '\\'
elif path[-1] != '/' and osName == 'posix':
path += '/'
self.path = path
def genKey(self, account, passphrase):
input_data = self.gpg.gen_key_input(
name_email=account,
passphrase=passphrase)
self.gpg.gen_key(input_data)
def encryptFile(self, account, data):
encryptedData = str(self.gpg.encrypt(data, account))
with open(self.path + '.' + account + '.req', 'w') as f:
f.write(encryptedData)
def decryptFile(self, account, passphrase):
with open(self.path + '.' + account + '.req', 'rb') as f:
decryptedData = str(self.gpg.decrypt_file(f, passphrase=passphrase))
return decryptedData
def deleteKey(self, keyId):
self.gpg.delete_keys(keyId, True)
self.gpg.delete_keys(keyId)
示例2: _generate_key
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
def _generate_key(username):
gpg = GPG()
key_input = gpg.gen_key_input(key_type="RSA", key_length=1024, name_email=username+"@node.org", name_real=username)
entropy_thread = Process(target=generate_entropy)
entropy_thread.start()
key = gpg.gen_key(key_input)
entropy_thread.terminate()
keys = gpg.list_keys(True)
for k in keys:
if k.get("fingerprint") == key.fingerprint:
return k['keyid']
示例3: Test
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
class Test(unittest.TestCase):
'''Unit test cases for signing envelopes from the Learning Registry'''
def __init__(self, methodName="runTest"):
self.gpgbin="/usr/local/bin/gpg"
self.gnupgHome = os.path.expanduser(os.path.join("~", ".gnupg"))
self.gpg = GPG(gpgbinary=self.gpgbin, gnupghome=self.gnupgHome)
unittest.TestCase.__init__(self, methodName)
self.testDataDir = None
configFile = os.path.join("config.cfg")
if os.path.exists(configFile):
config = json.load(file(configFile))
if config.has_key("global"):
if config["global"].has_key("testdata") and os.path.exists(config["global"]["testdata"]):
self.testDataDir = config["global"]["testdata"]
def setUp(self):
now = time.localtime()
now = calendar.timegm(now)
self.goodEmail = "signTest-{0}@learningregistry.org".format(now)
self.goodRealName = "Autogenerated Sign Test"
self.goodpassphrase = "supersecret"
input = self.gpg.gen_key_input(name_real=self.goodRealName, name_email=self.goodEmail, passphrase=self.goodpassphrase)
self.goodPrivateKey = self.gpg.gen_key(input)
privateKeyAvailable = False
privateKeys = self.gpg.list_keys(secret=True)
for skey in privateKeys:
if skey["keyid"] == self.goodPrivateKey.fingerprint:
privateKeyAvailable = True
self.privateKeyInfo = skey
break
if skey["fingerprint"] == self.goodPrivateKey.fingerprint:
privateKeyAvailable = True
self.privateKeyInfo = skey
break
assert privateKeyAvailable == True, "Could not locate generated Private Key"
self.goodkeyid = self.privateKeyInfo["keyid"]
self.goodowner = self.privateKeyInfo["uids"][0]
self.badkeyid = "XXXXXXXXXXXXXXXX"
self.badpassphrase = "bad passphrase"
self.sampleJSON = '''
{
"_id":"00e3f67232e743b6bc2a079bd98ff55a",
"_rev":"1-8163d32f6cc9996f2b7228d8b5db7962",
"doc_type":"resource_data",
"update_timestamp":"2011-03-14 13:36:04.617999",
"resource_data":"<oai_dc:dc xmlns:oai_dc=\\"http://www.openarchives.org/OAI/2.0/oai_dc/\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xmlns=\\"http://www.openarchives.org/OAI/2.0/\\" xsi:schemaLocation=\\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\\">\\n<dc:title>A chat about America. October and November, 1884.</dc:title>\\n<dc:creator>J. P.</dc:creator>\\n<dc:subject>United States--Description and travel.</dc:subject>\\n<dc:description>\\"Printed for private circulation only.\\"</dc:description>\\n<dc:description>Electronic reproduction. Washington, D.C. : Library of Congress, [2002-2003]</dc:description>\\n<dc:publisher>Manchester, Palmer & Howe</dc:publisher>\\n<dc:date>1885</dc:date>\\n<dc:type>text</dc:type>\\n<dc:identifier>http://hdl.loc.gov/loc.gdc/lhbtn.12281</dc:identifier>\\n<dc:language>eng</dc:language>\\n<dc:coverage>United States</dc:coverage>\\n</oai_dc:dc>\\n ",
"keys":["United States--Description and travel.","eng"],
"submitter_type":"agent",
"resource_data_type":"metadata",
"payload_schema_locator":"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd",
"payload_placement":"inline",
"submitter":"NSDL 2 LR Data Pump",
"payload_schema":["oai_dc"],
"node_timestamp":"2011-03-14 13:36:04.617999",
"doc_version":"0.10.0",
"create_timestamp":"2011-03-14 13:36:04.617999",
"active":true,
"publishing_node":"string",
"resource_locator":"http://hdl.loc.gov/loc.gdc/lhbtn.12281",
"doc_ID":"00e3f67232e743b6bc2a079bd98ff55a",
"TOS": {
"submission_TOS": "http://example.com/tos/unknown",
"submission_attribution": "unidentified"
}
}
'''
self.sampleJSON_strip = '''{"keys": ["United States--Description and travel.", "eng"], "TOS": {"submission_attribution": "unidentified", "submission_TOS": "http://example.com/tos/unknown"}, "payload_placement": "inline", "active": true, "resource_locator": "http://hdl.loc.gov/loc.gdc/lhbtn.12281", "doc_type": "resource_data", "resource_data": "<oai_dc:dc xmlns:oai_dc=\\"http://www.openarchives.org/OAI/2.0/oai_dc/\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xmlns=\\"http://www.openarchives.org/OAI/2.0/\\" xsi:schemaLocation=\\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\\">\\n<dc:title>A chat about America. October and November, 1884.</dc:title>\\n<dc:creator>J. P.</dc:creator>\\n<dc:subject>United States--Description and travel.</dc:subject>\\n<dc:description>\\"Printed for private circulation only.\\"</dc:description>\\n<dc:description>Electronic reproduction. Washington, D.C. : Library of Congress, [2002-2003]</dc:description>\\n<dc:publisher>Manchester, Palmer & Howe</dc:publisher>\\n<dc:date>1885</dc:date>\\n<dc:type>text</dc:type>\\n<dc:identifier>http://hdl.loc.gov/loc.gdc/lhbtn.12281</dc:identifier>\\n<dc:language>eng</dc:language>\\n<dc:coverage>United States</dc:coverage>\\n</oai_dc:dc>\\n ", "submitter_type": "agent", "resource_data_type": "metadata", "payload_schema_locator": "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd", "payload_schema": ["oai_dc"], "doc_version": "0.10.0", "submitter": "NSDL 2 LR Data Pump"}'''
self.sampleJSON_strip_normal = '''{"keys": ["United States--Description and travel.", "eng"], "TOS": {"submission_attribution": "unidentified", "submission_TOS": "http://example.com/tos/unknown"}, "payload_placement": "inline", "active": "true", "resource_locator": "http://hdl.loc.gov/loc.gdc/lhbtn.12281", "doc_type": "resource_data", "resource_data": "<oai_dc:dc xmlns:oai_dc=\\"http://www.openarchives.org/OAI/2.0/oai_dc/\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xmlns=\\"http://www.openarchives.org/OAI/2.0/\\" xsi:schemaLocation=\\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\\">\\n<dc:title>A chat about America. October and November, 1884.</dc:title>\\n<dc:creator>J. P.</dc:creator>\\n<dc:subject>United States--Description and travel.</dc:subject>\\n<dc:description>\\"Printed for private circulation only.\\"</dc:description>\\n<dc:description>Electronic reproduction. Washington, D.C. : Library of Congress, [2002-2003]</dc:description>\\n<dc:publisher>Manchester, Palmer & Howe</dc:publisher>\\n<dc:date>1885</dc:date>\\n<dc:type>text</dc:type>\\n<dc:identifier>http://hdl.loc.gov/loc.gdc/lhbtn.12281</dc:identifier>\\n<dc:language>eng</dc:language>\\n<dc:coverage>United States</dc:coverage>\\n</oai_dc:dc>\\n ", "submitter_type": "agent", "resource_data_type": "metadata", "payload_schema_locator": "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd", "payload_schema": ["oai_dc"], "doc_version": "0.10.0", "submitter": "NSDL 2 LR Data Pump"}'''
self.sampleJSON_strip_normal_bencode = '''d3:TOSd14:submission_TOS30:http://example.com/tos/unknown22:submission_attribution12:unidentifiede6:active4:true8:doc_type13:resource_data11:doc_version6:0.10.04:keysl38:United States--Description and travel.3:enge17:payload_placement6:inline14:payload_schemal6:oai_dce22:payload_schema_locator90:http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd13:resource_data968:<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.openarchives.org/OAI/2.0/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">\n<dc:title>A chat about America. October and November, 1884.</dc:title>\n<dc:creator>J. P.</dc:creator>\n<dc:subject>United States--Description and travel.</dc:subject>\n<dc:description>"Printed for private circulation only."</dc:description>\n<dc:description>Electronic reproduction. Washington, D.C. : Library of Congress, [2002-2003]</dc:description>\n<dc:publisher>Manchester, Palmer & Howe</dc:publisher>\n<dc:date>1885</dc:date>\n<dc:type>text</dc:type>\n<dc:identifier>http://hdl.loc.gov/loc.gdc/lhbtn.12281</dc:identifier>\n<dc:language>eng</dc:language>\n<dc:coverage>United States</dc:coverage>\n</oai_dc:dc>\n 18:resource_data_type8:metadata16:resource_locator38:http://hdl.loc.gov/loc.gdc/lhbtn.122819:submitter19:NSDL 2 LR Data Pump14:submitter_type5:agente'''
self.sampleJSON_sha256 = '''ef1b3b63adc663602c7a3c7595951b2761b34f5f6490ea1acee3df0fd97db03c'''
self.sampleKeyLocations = [
"http://example.com/mykey",
"http://example2.com/mykey"
]
self.signatureTemplate = '{{"key_location": [{0}], "key_owner": "'+self.goodowner+'", "signing_method": "LR-PGP.1.0", "signature": "{1}"}}'
def tearDown(self):
self.gpg.delete_keys([self.goodPrivateKey.fingerprint, ], secret=True)
self.gpg.delete_keys([self.goodPrivateKey.fingerprint, ], secret=False)
pass
def testMissingPrivateKey(self):
#.........这里部分代码省略.........
示例4: Test
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
class Test(unittest.TestCase):
'''Unit tests for validating signed envelopes from the Learning Registry'''
def __init__(self, methodName="runTest"):
self.sampleJSON = '''
{
"_id":"00e3f67232e743b6bc2a079bd98ff55a",
"_rev":"1-8163d32f6cc9996f2b7228d8b5db7962",
"doc_type":"resource_data",
"update_timestamp":"2011-03-14 13:36:04.617999",
"resource_data":"<oai_dc:dc xmlns:oai_dc=\\"http://www.openarchives.org/OAI/2.0/oai_dc/\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xmlns=\\"http://www.openarchives.org/OAI/2.0/\\" xsi:schemaLocation=\\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\\">\\n<dc:title>A chat about America. October and November, 1884.</dc:title>\\n<dc:creator>J. P.</dc:creator>\\n<dc:subject>United States--Description and travel.</dc:subject>\\n<dc:description>\\"Printed for private circulation only.\\"</dc:description>\\n<dc:description>Electronic reproduction. Washington, D.C. : Library of Congress, [2002-2003]</dc:description>\\n<dc:publisher>Manchester, Palmer & Howe</dc:publisher>\\n<dc:date>1885</dc:date>\\n<dc:type>text</dc:type>\\n<dc:identifier>http://hdl.loc.gov/loc.gdc/lhbtn.12281</dc:identifier>\\n<dc:language>eng</dc:language>\\n<dc:coverage>United States</dc:coverage>\\n</oai_dc:dc>\\n ",
"keys":["United States--Description and travel.","eng"],
"submitter_type":"agent",
"resource_data_type":"metadata",
"payload_schema_locator":"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd",
"payload_placement":"inline",
"submitter":"NSDL 2 LR Data Pump",
"payload_schema":["oai_dc"],
"node_timestamp":"2011-03-14 13:36:04.617999",
"doc_version":"0.10.0",
"create_timestamp":"2011-03-14 13:36:04.617999",
"active":true,
"publishing_node":"string",
"resource_locator":"http://hdl.loc.gov/loc.gdc/lhbtn.12281",
"doc_ID":"00e3f67232e743b6bc2a079bd98ff55a",
"TOS": {
"submission_TOS": "http://example.com/tos/unknown",
"submission_attribution": "unidentified"
}
}
'''
self.sampleKeyLocations = [
"http://example.com/mykey",
"http://example2.com/mykey"
]
self.gpgbin="/usr/local/bin/gpg"
self.gnupgHome = os.path.expanduser(os.path.join("~", ".gnupg"))
self.gpg = GPG(gpgbinary=self.gpgbin, gnupghome=self.gnupgHome)
self.testDataDir = None
configFile = os.path.join("config.cfg")
if os.path.exists(configFile):
config = json.load(file(configFile))
if config.has_key("global"):
if config["global"].has_key("testdata") and os.path.exists(config["global"]["testdata"]):
self.testDataDir = config["global"]["testdata"]
unittest.TestCase.__init__(self, methodName)
def setUp(self):
now = time.localtime()
now = calendar.timegm(now)
self.privateEmail = "privateTest-{0}@learningregistry.org".format(now)
self.privateEmail2 = "privateTest2-{0}@learningregistry.org".format(now)
self.genericPassphrase = "supersecret"
input = self.gpg.gen_key_input(name_email=self.privateEmail, passphrase=self.genericPassphrase)
self.privateKey = self.gpg.gen_key(input)
input = self.gpg.gen_key_input(name_email=self.privateEmail2, passphrase=self.genericPassphrase)
self.privateKey2 = self.gpg.gen_key(input)
self.privExport = self.gpg.export_keys([self.privateKey.fingerprint, self.privateKey2.fingerprint], secret=True)
self.pubExport = self.gpg.export_keys([self.privateKey.fingerprint, self.privateKey2.fingerprint], secret=False)
pass
def tearDown(self):
self.gpg.delete_keys([self.privateKey.fingerprint, self.privateKey2.fingerprint], secret=True)
self.gpg.delete_keys([self.privateKey.fingerprint, self.privateKey2.fingerprint], secret=False)
pass
def testGetSignatureBlock(self):
'''Check that signature block validation correctly returns a structurally valid response'''
unsigned = json.loads(self.sampleJSON)
signtool = Sign_0_21(privateKeyID=self.privateKey.fingerprint, passphrase=self.genericPassphrase, gnupgHome=self.gnupgHome, gpgbin=self.gpgbin, publicKeyLocations=self.sampleKeyLocations)
signed = signtool.sign(unsigned)
assert signed != None, "envelope did not sign correctly"
verifytool = Verify_0_21(gpgbin=self.gpgbin, gnupgHome=self.gnupgHome)
sigInfo = verifytool._getSignatureInfo(signed)
assert sigInfo != None, "signature extraction from envelope failed"
assert sigInfo.has_key("signing_method") and sigInfo["signing_method"] == verifytool.signatureMethod, "signing_method is missing from signature block"
assert sigInfo.has_key("signature") and sigInfo["signature"] != None and len(sigInfo["signature"]) > 0, "signature field is missing, null or is empty"
assert sigInfo.has_key("key_location") and sigInfo["key_location"] == self.sampleKeyLocations, "key_location field is not correct"
#.........这里部分代码省略.........
示例5: OpenPgpFactory
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
class OpenPgpFactory(GenericFactory):
"""Provides OpenPGP functionality based on GnuPG."""
implements(ICipherModule)
gpg_binary = Option('crypto', 'gpg_binary', 'gpg',
"""GnuPG binary name, allows for full path too.
Value 'gpg' is same default as in python-gnupg itself.
For usual installations location of the gpg binary is auto-detected.
""")
gpg_home = Option('crypto', 'gpg_home', '.gpg',
"""Directory containing keyring files.
In case of wrong configuration missing keyring files without content
will be created in the configured location, provided necessary
write permssion is granted for the corresponding parent directory.
""")
priv_key = Option('crypto', 'gpg_private_key', '',
"""Key ID of private key (last 8 chars or more).
If unset, a private key will be selected from keyring automagicly.
The password must be available i.e. provided by running gpg-agent
(not yet available) or empty (security trade-off). No private key
operation can happen before the key has been unlocked successfully.
""")
name = 'openpgp'
_supported_keys = ['name_real', 'name_comment', 'name_email',
'key_type', 'key_length',
'subkey_type', 'subkey_length',
'expire_date', 'passphrase']
def __init__(self):
try:
from gnupg import GPG
except ImportError:
raise TracError(_("""Unable to load the python-gnupg module.
Please check and correct your installation."""))
try:
# Initialize the GnuPG instance.
path = os.path.join(os.path.abspath(self.env.path), self.gpg_home)
self.env.log.debug('Using GnuPG home dir: ' + str(path))
self.gpg = GPG(gpgbinary=self.gpg_binary, gnupghome=path)
except ValueError:
raise TracError(_("""Missing the crypto binary. Please check and
set full path with option 'gpg_binary'."""))
# IKeyVault methods
def keys(self, private=False, id_only=False):
"""Returns the list of all available keys."""
# DEVEL: Cache this for performance.
if not id_only:
return self.gpg.list_keys(private) # same as gpg.list_keys(False)
keys = []
for key in self.gpg.list_keys(private):
keys.append(key['fingerprint'])
return keys
def create_key(self, **kwargs):
"""Generate a new OpenPGP key pair."""
# Sanitize input.
for k in kwargs.keys():
if k not in self._supported_keys:
kwargs.pop(k)
input_data = self.gpg.gen_key_input(**kwargs)
try:
return self.gpg.gen_key(input_data)
except ValueError, e:
return False, e
示例6: setUp
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
def setUp(self):
"""
Construct environment.
Here, we adopt the configuration used by the production or development
installation and make the necessary changes before writing it to a new
file in the etc directory. When we're finished, we'll remove it in the
tearDown() function.
"""
if not os.path.exists(self.client_env['CONFDIR']):
# Don't waste time and entropy on keys if we can't write configuration
# files -- that's a very distressing experience.
assert len(sys.argv) == 2
# Prepare two GPG keypairs; one for the agent, one for the client
agent_gpg_dir = os.path.join(self.client_env['CONFDIR'], 'agent_gpg')
agent_gpg = GPG(gnupghome=agent_gpg_dir)
agent_key = agent_gpg.gen_key(agent_gpg.gen_key_input(**self.gpg_params))
client_gpg_dir = os.path.join(self.client_env['CONFDIR'], 'client_gpg')
client_gpg = GPG(gnupghome=client_gpg_dir)
client_key = client_gpg.gen_key(client_gpg.gen_key_input(**self.gpg_params))
# Export both public keys; import them into the opposing side
agent_key_blob = agent_gpg.export_keys(agent_key.fingerprint)
client_gpg.import_keys(agent_key_blob)
client_gpg.sign_key(agent_key.fingerprint)
client_key_blob = client_gpg.export_keys(client_key.fingerprint)
agent_gpg.import_keys(client_key_blob)
agent_gpg.sign_key(client_key.fingerprint)
# Configure the agent to run in a development-safe configuration.
#
# Here, we load the base configuration we ship with the application
# as the default. All other configuration will be ignored for the
# purposes of the test run, since this is outside of our scope.
with open(self.agent_env['CONFDIR'], 'w') as f:
l = os.path.join(self.client_env['CONFDIR'], 'agent_%s.log')
agent_cfg = ConfigurationFactory.get('hypernova.agent',
root_dir=sys.argv[1])
agent_cfg.set('server', 'address', self.agent_addr[0])
agent_cfg.set('server', 'port', self.agent_addr[1])
agent_cfg.set('server', 'daemon', 'false')
agent_cfg.set('gpg', 'key_store', agent_gpg_dir)
agent_cfg.set('gpg', 'fingerprint', agent_key.fingerprint)
agent_cfg.set('logging', 'main_log', l %('main'))
agent_cfg.set('logging', 'request_log', l %('request'))
agent_cfg.set('logging', 'error_log', l %('error'))
agent_cfg.write(f)
# The client has to use two different configuration files, both in
# the same directory.
client_cfg_dir = self.client_env['CONFDIR']
# Configure the client to use its temporary key.
#
# To communicate with the agent (which will be running in a limited
# testing mode), we'll need to reconfigure the client with a keypair
# we've imported into the agent. This keystore manipulation has
# already taken place, so we know the fingerprint of our new private
# key.
client_cfg_file = os.path.join(client_cfg_dir, 'client.ini')
with open(client_cfg_file, 'w') as f:
client_cfg = configparser.SafeConfigParser()
client_cfg.add_section('client')
client_cfg.set('client', 'privkey', client_key.fingerprint)
client_cfg.write(f)
# Pair the client to the agent.
#
# We do this manually, since the importer requires that we write the
# public key to a file before we import it. This would be a
# pointless exercise and an unnecessary complication.
client_srv_file = os.path.join(client_cfg_dir, 'servers.ini')
with open(client_srv_file, 'w') as f:
client_srv_cfg = configparser.SafeConfigParser()
client_srv_cfg.add_section('local')
client_srv_cfg.set('local', 'addr', ':'.join(self.agent_addr))
client_srv_cfg.set('local', 'pubkey', agent_key.fingerprint)
client_srv_cfg.write(f)
# TODO: instead of lazily and unreliably falling asleep on the job,
# we should probably use a regular expression to check the output.
# Time is of the essence, though!
# No, we'll use pexpect instead, since it's now shipped as a py3k
# dependency.
agent_cmd = [
'hn-agent',
self.agent_env['CONFDIR']
]
self.agent_proc = subprocess.Popen(agent_cmd, env=self.agent_env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
time.sleep(self.agent_init_time)
示例7: setUpClass
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
def setUpClass(cls):
super(TestGnuPGMessage, cls).setUpClass()
gpg = GPG(gnupghome=settings.GNUPG_HOMEDIR)
key_input = gpg.gen_key_input()
gpg.gen_key(key_input)
示例8: gen
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import gen_key_input [as 别名]
def gen(this):
gpg=GPG(gnupghome=os.path.join(GNUPG_HOME,user.pk))
input_data = gpg.gen_key_input(key_type="RSA", key_length=1024)
key=gpg.gen_key(input_data)