2018-08-22 08:55:17 -05:00
|
|
|
@PYTHONSHEBANG@
|
2016-05-31 17:07:33 -05:00
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2019-06-12 15:02:52 -05:00
|
|
|
import argparse
|
2016-05-31 17:07:33 -05:00
|
|
|
import os
|
|
|
|
|
|
|
|
from ipalib import constants
|
|
|
|
from ipalib.config import Env
|
|
|
|
from ipaplatform.paths import paths
|
2016-11-22 10:55:10 -06:00
|
|
|
from ipaserver.secrets.client import CustodiaClient
|
2016-05-31 17:07:33 -05:00
|
|
|
|
|
|
|
|
2017-08-22 20:22:48 -05:00
|
|
|
def main():
|
|
|
|
env = Env()
|
|
|
|
env._finalize()
|
2016-05-31 17:07:33 -05:00
|
|
|
|
2019-06-12 15:02:52 -05:00
|
|
|
parser = argparse.ArgumentParser("ipa-pki-retrieve-key")
|
|
|
|
parser.add_argument("keyname", type=str)
|
|
|
|
parser.add_argument("servername", type=str)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
keyname = "ca_wrapped/{}".format(args.keyname)
|
2016-05-31 17:07:33 -05:00
|
|
|
|
2017-08-22 20:22:48 -05:00
|
|
|
service = constants.PKI_GSSAPI_SERVICE_NAME
|
|
|
|
client_keyfile = os.path.join(paths.PKI_TOMCAT, service + '.keys')
|
|
|
|
client_keytab = os.path.join(paths.PKI_TOMCAT, service + '.keytab')
|
2016-05-31 17:07:33 -05:00
|
|
|
|
2019-06-12 15:02:52 -05:00
|
|
|
for filename in [client_keyfile, client_keytab]:
|
|
|
|
if not os.access(filename, os.R_OK):
|
|
|
|
parser.error(
|
|
|
|
"File '{}' missing or not readable.\n".format(filename)
|
|
|
|
)
|
|
|
|
|
2017-08-22 20:22:48 -05:00
|
|
|
# pylint: disable=no-member
|
|
|
|
client = CustodiaClient(
|
2019-06-12 15:02:52 -05:00
|
|
|
client_service="{}@{}".format(service, env.host),
|
|
|
|
server=args.servername,
|
|
|
|
realm=env.realm,
|
|
|
|
ldap_uri="ldaps://" + env.host,
|
|
|
|
keyfile=client_keyfile,
|
|
|
|
keytab=client_keytab,
|
|
|
|
)
|
2017-08-22 20:22:48 -05:00
|
|
|
|
|
|
|
# Print the response JSON to stdout; it is already in the format
|
|
|
|
# that Dogtag's ExternalProcessKeyRetriever expects
|
|
|
|
print(client.fetch_key(keyname, store=False))
|
|
|
|
|
|
|
|
|
2019-06-12 15:02:52 -05:00
|
|
|
if __name__ == '__main__':
|
2017-08-22 20:22:48 -05:00
|
|
|
main()
|