diff --git a/src/elf_signer.cc b/src/elf_signer.cc index 046d172..4e3f95c 100644 --- a/src/elf_signer.cc +++ b/src/elf_signer.cc @@ -8,6 +8,7 @@ #include "elf.hh" #include "log.hh" #include "path.hh" +#include "sig.hh" #include "ssh_key.hh" #include "virtual_fs.hh" @@ -32,14 +33,16 @@ int main(int argc, char *argv[]) { } auto signature = ed25519::Signature(elf_copy, key.private_key, key.public_key); - auto sig_section = elf::FindSection(elf_copy, "maf.sig.ed25519", status); + auto sig_section = + elf::FindSection(elf_copy, ".note.maf.sig.ed25519", status); if (not OK(status)) { FATAL << "Failed to find signature section: " << status; } - if (sig_section.size() != sizeof(signature.bytes)) { + if (sig_section.size() != sizeof(SignatureNote)) { FATAL << "Invalid signature section size: " << sig_section.size(); } - memcpy(sig_section.data(), signature.bytes, sizeof(signature.bytes)); + SignatureNote ¬e = *reinterpret_cast(sig_section.data()); + memcpy(note.desc.bytes, signature.bytes, sizeof(signature.bytes)); WriteFile(argv[3], elf_copy, status, 0775); if (not OK(status)) { FATAL << "Failed to write ELF file: " << status; diff --git a/src/sig.cc b/src/sig.cc index e855547..85fc10f 100644 --- a/src/sig.cc +++ b/src/sig.cc @@ -7,7 +7,7 @@ namespace maf { // Reserve space for signature. Actual signing happens after linking. -__attribute__((section("maf.sig.ed25519"))) __attribute__((used)) -const ed25519::Signature kSignature = {}; +__attribute__((section(".note.maf.sig.ed25519"))) __attribute__((used)) +const SignatureNote kSignatureNote = {}; } // namespace maf \ No newline at end of file diff --git a/src/sig.hh b/src/sig.hh index 3276675..435da95 100644 --- a/src/sig.hh +++ b/src/sig.hh @@ -4,6 +4,14 @@ namespace maf { -extern const ed25519::Signature kSignature; +struct SignatureNote { + int namesz = 4; + int descsz = sizeof(ed25519::Signature); + int type = 3; + char name[4] = "MAF"; + ed25519::Signature desc = {}; +}; + +extern const SignatureNote kSignatureNote; } // namespace maf \ No newline at end of file diff --git a/src/sig.x b/src/sig.x index 5cedb43..3878c8b 100644 --- a/src/sig.x +++ b/src/sig.x @@ -1,5 +1,5 @@ OVERWRITE_SECTIONS { - maf.sig.ed25519 : { - KEEP(*(maf.sig.ed25519)) + .note.maf.sig.ed25519 : { + KEEP(*(.note.maf.sig.ed25519)) } }; \ No newline at end of file