Skip to content

Commit

Permalink
Change signature section to SH_NOTE
Browse files Browse the repository at this point in the history
  • Loading branch information
mafik committed Jul 27, 2023
1 parent 7b9ea4a commit ea29b6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/elf_signer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "elf.hh"
#include "log.hh"
#include "path.hh"
#include "sig.hh"
#include "ssh_key.hh"
#include "virtual_fs.hh"

Expand All @@ -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 &note = *reinterpret_cast<SignatureNote *>(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;
Expand Down
4 changes: 2 additions & 2 deletions src/sig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion src/sig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/sig.x
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OVERWRITE_SECTIONS {
maf.sig.ed25519 : {
KEEP(*(maf.sig.ed25519))
.note.maf.sig.ed25519 : {
KEEP(*(.note.maf.sig.ed25519))
}
};

0 comments on commit ea29b6e

Please sign in to comment.