Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[signing] More signing automation #20769

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions rules/signing.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def _presigning_artifacts(ctx, opentitantool, src, manifest, rsa_key, spx_key, b
else:
basename = paths.replace_extension(basename, "")

signing_directives = []
pre = ctx.actions.declare_file("{}.pre-signing".format(basename))
inputs = [
src,
Expand Down Expand Up @@ -152,6 +153,15 @@ def _presigning_artifacts(ctx, opentitantool, src, manifest, rsa_key, spx_key, b
executable = opentitantool,
mnemonic = "PreSigningDigest",
)
signing_directives.append(struct(
command = "rsa-sign",
id = None,
label = rsa_key.name,
format = "Sha256Hash",
little_endian = True,
output = "{}.rsa_sig".format(basename),
input = "{}.digest".format(basename),
))

# Compute message to be signed with SPX+.
spxmsg = None
Expand All @@ -171,7 +181,10 @@ def _presigning_artifacts(ctx, opentitantool, src, manifest, rsa_key, spx_key, b
executable = opentitantool,
mnemonic = "PreSigningSpxMessage",
)
return struct(pre = pre, digest = digest, spxmsg = spxmsg)
# TODO(cfrantz): After adding SPX support to hsmtool, append an appropriate
# signing directive here.

return struct(pre = pre, digest = digest, spxmsg = spxmsg, script = signing_directives)

def _local_sign(ctx, tool, digest, rsa_key, spxmsg = None, spx_key = None, profile = None):
"""Sign a digest with a local on-disk RSA private key.
Expand Down Expand Up @@ -309,6 +322,7 @@ def _offline_presigning_artifacts(ctx):
spx_key = key_from_dict(ctx.attr.spx_key, "spx_key")
digests = []
bins = []
script = []
for src in get_binary_files(ctx.attr.srcs):
artifacts = _presigning_artifacts(
ctx,
Expand All @@ -320,12 +334,20 @@ def _offline_presigning_artifacts(ctx):
)
bins.append(artifacts.pre)
digests.append(artifacts.digest)
script.extend(artifacts.script)
if artifacts.spxmsg:
digests.append(artifacts.spxmsg)

default_files = digests
if script:
script_file = ctx.actions.declare_file("{}.json".format(ctx.attr.name))
ctx.actions.write(script_file, json.encode_indent(script, indent = " ") + "\n")
default_files.append(script_file)

return [
DefaultInfo(files = depset(digests), data_runfiles = ctx.runfiles(files = digests)),
DefaultInfo(files = depset(default_files), data_runfiles = ctx.runfiles(files = default_files)),
PreSigningBinaryInfo(files = depset(bins)),
OutputGroupInfo(digest = depset(digests), binary = depset(bins)),
OutputGroupInfo(digest = depset(digests), binary = depset(bins), script = depset([script_file])),
]

offline_presigning_artifacts = rule(
Expand Down
Loading