|
Packit |
d7e8d0 |
#!/usr/bin/env python
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
|
|
Packit |
d7e8d0 |
# Copyright (C) 2016 g10 Code GmbH
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# This file is part of GPGME.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# GPGME is free software; you can redistribute it and/or modify it
|
|
Packit |
d7e8d0 |
# under the terms of the GNU General Public License as published by
|
|
Packit |
d7e8d0 |
# the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
d7e8d0 |
# (at your option) any later version.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# GPGME is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
d7e8d0 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit |
d7e8d0 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
Packit |
d7e8d0 |
# Public License for more details.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
30b792 |
# License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
from __future__ import absolute_import, print_function, unicode_literals
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
import sys
|
|
Packit |
d7e8d0 |
import os
|
|
Packit |
d7e8d0 |
import gpg
|
|
Packit |
d7e8d0 |
import support
|
|
Packit Service |
30b792 |
_ = support # to appease pyflakes.
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
del absolute_import, print_function, unicode_literals
|
|
Packit Service |
30b792 |
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
class KeyEditor(object):
|
|
Packit |
d7e8d0 |
def __init__(self):
|
|
Packit |
d7e8d0 |
self.steps = ["fpr", "expire", "1", "primary", "quit"]
|
|
Packit |
d7e8d0 |
self.step = 0
|
|
Packit |
d7e8d0 |
self.done = False
|
|
Packit |
d7e8d0 |
self.verbose = int(os.environ.get('verbose', 0)) > 1
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
def edit_fnc(self, status, args, out=None):
|
|
Packit |
d7e8d0 |
if args == "keyedit.prompt":
|
|
Packit |
d7e8d0 |
result = self.steps[self.step]
|
|
Packit |
d7e8d0 |
self.step += 1
|
|
Packit |
d7e8d0 |
elif args == "keyedit.save.okay":
|
|
Packit |
d7e8d0 |
result = "Y"
|
|
Packit |
d7e8d0 |
self.done = self.step == len(self.steps)
|
|
Packit |
d7e8d0 |
elif args == "keygen.valid":
|
|
Packit |
d7e8d0 |
result = "0"
|
|
Packit |
d7e8d0 |
else:
|
|
Packit |
d7e8d0 |
result = None
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
if self.verbose:
|
|
Packit Service |
30b792 |
sys.stderr.write("Code: {}, args: {!r}, Returning: {!r}\n".format(
|
|
Packit Service |
30b792 |
status, args, result))
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
return result
|
|
Packit |
d7e8d0 |
|
|
Packit Service |
30b792 |
|
|
Packit |
d7e8d0 |
c = gpg.Context()
|
|
Packit |
d7e8d0 |
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
|
Packit |
d7e8d0 |
c.set_passphrase_cb(lambda *args: "abc")
|
|
Packit |
d7e8d0 |
c.set_armor(True)
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
# The deprecated interface.
|
|
Packit |
d7e8d0 |
editor = KeyEditor()
|
|
Packit Service |
30b792 |
c.interact(
|
|
Packit Service |
30b792 |
c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
|
|
Packit Service |
30b792 |
editor.edit_fnc)
|
|
Packit |
d7e8d0 |
assert editor.done
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
# The deprecated interface.
|
|
Packit |
d7e8d0 |
sink = gpg.Data()
|
|
Packit |
d7e8d0 |
editor = KeyEditor()
|
|
Packit Service |
30b792 |
c.op_edit(
|
|
Packit Service |
30b792 |
c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
|
|
Packit Service |
30b792 |
editor.edit_fnc, sink, sink)
|
|
Packit |
d7e8d0 |
assert editor.done
|