@@ -4685,7 +4685,7 @@ diff -Nur /dev/null BUILD
46854685diff -Nur /dev/null sgx_sdk.bzl
46864686--- /dev/null
46874687+++ sgx_sdk.bzl
4688- @@ -0,0 +1,736 @@
4688+ @@ -0,0 +1,774 @@
46894689+ """Build tools for supporting Intel's SDK."""
46904690+
46914691+ load("@com_google_asylo_backend_provider//:enclave_info.bzl", "backend_tools")
@@ -4827,7 +4827,7 @@ diff -Nur /dev/null sgx_sdk.bzl
48274827+ if not transitions.supported(native.package_name()):
48284828+ sgx_cc_unsigned_enclave(
48294829+ name = name,
4830- + stamp = stamp,
4830+ + stamp = not (not stamp) ,
48314831+ **kwargs
48324832+ )
48334833+ else:
@@ -5133,19 +5133,19 @@ diff -Nur /dev/null sgx_sdk.bzl
51335133+ testonly = testonly,
51345134+ )
51355135+
5136- + def _sgx_generate_sigstruct_impl (ctx):
5136+ + def _sgx_generate_enclave_signing_material_impl (ctx):
51375137+ """Implementation of the sign_tool's gendata command for sigstructs."""
5138- + sigstruct = ctx.outputs.sigstruct
5139- + if not sigstruct :
5140- + sigstruct = ctx.actions.declare_file(ctx.label.name + ".dat")
5138+ + signing_material = ctx.outputs.signing_material
5139+ + if not signing_material :
5140+ + signing_material = ctx.actions.declare_file(ctx.label.name + ".dat")
51415141+ ctx.actions.run_shell(
51425142+ inputs = [
51435143+ ctx.file.unsigned,
51445144+ ctx.file.config,
51455145+ ],
51465146+ tools = [ctx.executable._sign_tool],
5147- + outputs = [sigstruct ],
5148- + progress_message = "Generating SIGSTRUCT material for: //{pkg}:{name}".format(
5147+ + outputs = [signing_material ],
5148+ + progress_message = "Generating enclave signing material for: //{pkg}:{name}".format(
51495149+ pkg = ctx.attr.unsigned.label.package,
51505150+ name = ctx.attr.unsigned.label.name,
51515151+ ),
@@ -5158,19 +5158,21 @@ diff -Nur /dev/null sgx_sdk.bzl
51585158+ "-config",
51595159+ ctx.file.config.path,
51605160+ "-out",
5161- + sigstruct .path,
5161+ + signing_material .path,
51625162+ ],
51635163+ )
51645164+ return [
5165- + DefaultInfo(files = depset([sigstruct ])),
5165+ + DefaultInfo(files = depset([signing_material ])),
51665166+ SGXSigstructInfo(
51675167+ config = ctx.file.config,
51685168+ unsigned = ctx.attr.unsigned,
51695169+ ),
51705170+ ]
51715171+
5172- + sgx_generate_sigstruct = rule(
5173- + implementation = _sgx_generate_sigstruct_impl,
5172+ + sgx_generate_enclave_signing_material = rule(
5173+ + implementation = _sgx_generate_enclave_signing_material_impl,
5174+ + doc = ("Creates a file that contains the parts of the enclave SIGSTRUCT" +
5175+ + " that must be signed."),
51745176+ attrs = {
51755177+ "config": attr.label(
51765178+ mandatory = True,
@@ -5185,7 +5187,7 @@ diff -Nur /dev/null sgx_sdk.bzl
51855187+ doc = ("The label of the unsigned enclave binary to be measured " +
51865188+ "and hashed as a SIGSTRUCT field"),
51875189+ ),
5188- + "sigstruct ": attr.output(
5190+ + "signing_material ": attr.output(
51895191+ doc = "The name of the output file. Default is \"<name>.dat\".",
51905192+ ),
51915193+ "_sign_tool": attr.label(
@@ -5197,37 +5199,54 @@ diff -Nur /dev/null sgx_sdk.bzl
51975199+ },
51985200+ )
51995201+
5200- + def _sign_sigstruct_impl(ctx):
5202+ + def sgx_generate_sigstruct(name, sigstruct = None, **kwargs):
5203+ + """Creates a file that contains parts of the enclave SIGSTRUCT.
5204+ +
5205+ + Args:
5206+ + name: The rule name.
5207+ + sigstruct: The name of the output file. Default is "<name>.dat".
5208+ + **kwargs: The arguments passed to sgx_generate_enclave_signing_material.
5209+ + """
5210+ + sgx_generate_enclave_signing_material(
5211+ + name = name,
5212+ + deprecation = ("Please use sgx_generate_enclave_signing_material " +
5213+ + "because this macro may be removed or change meaning " +
5214+ + "in the future."),
5215+ + signing_material = sigstruct,
5216+ + **kwargs
5217+ + )
5218+ +
5219+ + def _sign_signing_material_impl(ctx):
52015220+ signature = ctx.attr.signature or ctx.actions.declare_file(ctx.label.name + ".sig")
52025221+ ctx.actions.run_shell(
52035222+ outputs = [signature],
5204- + inputs = [ctx.file.private_key, ctx.file.sigstruct ],
5223+ + inputs = [ctx.file.private_key, ctx.file.signing_material ],
52055224+ tools = [ctx.executable._bssl],
5206- + command = "{bssl} {args} < {sigstruct } > {signature}".format(
5225+ + command = "{bssl} {args} < {signing_material } > {signature}".format(
52075226+ bssl = ctx.file._bssl.path,
52085227+ args = " ".join(["sign", "-digest", "sha256", "-key", ctx.file.private_key.path]),
5209- + sigstruct = ctx.file.sigstruct .path,
5228+ + signing_material = ctx.file.signing_material .path,
52105229+ signature = signature.path,
52115230+ ),
52125231+ )
52135232+ return [DefaultInfo(files = depset([signature]))]
52145233+
5215- + boringssl_sign_sigstruct = rule(
5216- + implementation = _sign_sigstruct_impl ,
5217- + doc = ("Signs a sigstruct file with a given private key for use in " +
5218- + "sgx_signed_enclave."),
5234+ + boringssl_sign_enclave_signing_material = rule(
5235+ + implementation = _sign_signing_material_impl ,
5236+ + doc = ("Signs an enclave signing material file with a given private " +
5237+ + "key for use in sgx_signed_enclave."),
52195238+ attrs = {
5220- + "sigstruct ": attr.label(
5239+ + "signing_material ": attr.label(
52215240+ mandatory = True,
52225241+ allow_single_file = True,
52235242+ providers = [SGXSigstructInfo],
5224- + doc = "A target defined by sgx_generate_sigstruct .",
5243+ + doc = "A target defined by sgx_generate_enclave_signing_material .",
52255244+ ),
52265245+ "private_key": attr.label(
52275246+ mandatory = True,
52285247+ allow_single_file = True,
52295248+ doc = ("The RSA-3072 private key with public exponent 3 in PEM " +
5230- + "format used to sign the input sigstruct ."),
5249+ + "format used to sign the input enclave signing material ."),
52315250+ ),
52325251+ "signature": attr.output(
52335252+ doc = "The output signature file name [default: <name>.sig].",
@@ -5241,10 +5260,27 @@ diff -Nur /dev/null sgx_sdk.bzl
52415260+ },
52425261+ )
52435262+
5263+ + def boringssl_sign_sigstruct(name, sigstruct, **kwargs):
5264+ + """Signs enclave signing material with a given private key.
5265+ +
5266+ + Args:
5267+ + name: The rule name.
5268+ + sigstruct: A target defined by sgx_generate_enclave_signing_material.
5269+ + **kwargs: The arguments passed to boringssl_sign_enclave_signing_material.
5270+ + """
5271+ + boringssl_sign_enclave_signing_material(
5272+ + name = name,
5273+ + signing_material = sigstruct,
5274+ + deprecation = ("Please use boringssl_sign_enclave_signing_material " +
5275+ + "as boringssl_sign_sigstruct is deprecated and will " +
5276+ + "be removed in the future."),
5277+ + **kwargs
5278+ + )
5279+ +
52445280+ def _sgx_signed_enclave_impl(ctx):
52455281+ """Implementation of incorporating a signature into an enclave binary."""
5246- + config = ctx.attr.sigstruct [SGXSigstructInfo].config
5247- + unsigned = ctx.attr.sigstruct [SGXSigstructInfo].unsigned
5282+ + config = ctx.attr.signing_material [SGXSigstructInfo].config
5283+ + unsigned = ctx.attr.signing_material [SGXSigstructInfo].unsigned
52485284+ if SGXEnclaveInfo not in unsigned:
52495285+ fail("Unsigned enclave referenced in config does not have SGXEnclaveInfo provider")
52505286+ unsigned_file = unsigned.files.to_list()[0]
@@ -5253,7 +5289,7 @@ diff -Nur /dev/null sgx_sdk.bzl
52535289+ config,
52545290+ ctx.file.public_key,
52555291+ ctx.file.signature,
5256- + ctx.file.sigstruct ,
5292+ + ctx.file.signing_material ,
52575293+ unsigned_file,
52585294+ ],
52595295+ tools = [ctx.executable._sign_tool],
@@ -5275,7 +5311,7 @@ diff -Nur /dev/null sgx_sdk.bzl
52755311+ "-config",
52765312+ config.path,
52775313+ "-unsigned",
5278- + ctx.file.sigstruct .path,
5314+ + ctx.file.signing_material .path,
52795315+ "-out",
52805316+ ctx.outputs.executable.path,
52815317+ ],
@@ -5300,14 +5336,14 @@ diff -Nur /dev/null sgx_sdk.bzl
53005336+ "signature": attr.label(
53015337+ mandatory = True,
53025338+ allow_single_file = True,
5303- + doc = "The sha256 digest of the sigstruct signed by the " +
5304- + "RSA-3072 private key with public exponent 3.",
5339+ + doc = "The sha256 digest of the enclave signing material signed " +
5340+ + "by the RSA-3072 private key with public exponent 3.",
53055341+ ),
5306- + "sigstruct ": attr.label(
5342+ + "signing_material ": attr.label(
53075343+ mandatory = True,
53085344+ allow_single_file = True,
53095345+ providers = [SGXSigstructInfo],
5310- + doc = ("The label of a sgx_generate_sigstruct target that " +
5346+ + doc = ("The label of a sgx_generate_enclave_signing_material target that " +
53115347+ "includes both the unsigned enclave and its config."),
53125348+ ),
53135349+ "_sign_tool": attr.label(
@@ -5414,9 +5450,11 @@ diff -Nur /dev/null sgx_sdk.bzl
54145450+ sgx = struct(
54155451+ backend_labels = SGX_BACKEND_LABELS,
54165452+ boringssl_sign_sigstruct = boringssl_sign_sigstruct,
5453+ + boringssl_sign_enclave_signing_material = boringssl_sign_enclave_signing_material,
54175454+ debug_enclave = sgx_debug_enclave,
54185455+ enclave_configuration = sgx_enclave_configuration,
54195456+ full_enclave_configuration = sgx_full_enclave_configuration,
5457+ + generate_enclave_signing_material = sgx_generate_enclave_signing_material,
54205458+ generate_sigstruct = sgx_generate_sigstruct,
54215459+ signed_enclave = sgx_signed_enclave,
54225460+ tags = sgx_tags,
0 commit comments