Skip to content

Commit

Permalink
redhat-rpm-sign-ostree: Reimplementation of rpm-ostree compose sign (#9)
Browse files Browse the repository at this point in the history
* redhat-rpm-sign-ostree: Reimplementation of rpm-ostree compose sign

See coreos/rpm-ostree#607

* fixup! redhat-rpm-sign-ostree: Reimplementation of rpm-ostree compose sign
  • Loading branch information
cgwalters committed Mar 30, 2017
1 parent cc38e16 commit a38f71b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions redhat-rpm-sign-ostree
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
#
# This script calls out to a Red Hat internal
# program called `rpm-sign`, and uses it to sign
# a given OSTree commit.
#
# Copyright 2017 Colin Walters <walters@verbum.org>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)

from __future__ import print_function

import os, sys, argparse, gi, tempfile, subprocess
gi.require_version('OSTree', '1.0')
from gi.repository import GLib, Gio, OSTree

def fatal(msg):
print >>sys.stderr, msg
sys.exit(1)

parser = argparse.ArgumentParser()
parser.add_argument("--repo", help="Repo",
action='store', required=True)
parser.add_argument("--key", help="Key",
action='store', required=True)
parser.add_argument("--rev", help="OSTree commit ID",
action='store', required=True)

args = parser.parse_args()

r = OSTree.Repo.new(Gio.File.new_for_path(args.repo))
r.open(None)
[_,rev] = r.resolve_rev(args.rev, False)
[_,v] = r.load_variant(OSTree.ObjectType.COMMIT, rev)
commit_bytes = v.get_data_as_bytes()

with tempfile.NamedTemporaryFile() as commitfd:
commitfd.write(commit_bytes.get_data())
commitfd.flush()
with tempfile.NamedTemporaryFile() as sigfd:
subprocess.check_call(['rpm-sign', '--key', args.key, '--detachsign', commitfd.name,
'--output', sigfd.name])
with open(sigfd.name) as sigfd_in:
sigdata = GLib.Bytes.new(sigfd_in.read())
r.append_gpg_signature(rev, sigdata, None)
print("Successfully signed OSTree commit={} with key={}".format(rev, args.key))

0 comments on commit a38f71b

Please sign in to comment.