Code signing support - #130
Open
banister wants to merge 43 commits into
Open
Conversation
… previous EOF of the executable) But seems to be around 4 bytes of null buffer between end of file and the start of sig
Still struggling with ocraSignatureLocation
unfortunately the digital sig does not appear immediately after the ocra sig. There appears to be a random number of null bytes between them. This code skips over those null bytes until it finds the ocra sig, then returns the start of the sig
* foo -> searchPtr * introduce SECURITY_ENTRY macro
* C style comments (/* */) * Moved some code around
may not -> cannot
banister
force-pushed
the
code-signing-support
branch
from
December 14, 2017 03:50
e0375d1 to
d9f208b
Compare
banister
force-pushed
the
code-signing-support
branch
from
December 14, 2017 04:56
cd6df81 to
ebc6d1e
Compare
banister
force-pushed
the
code-signing-support
branch
from
December 14, 2017 04:57
ebc6d1e to
43590f5
Compare
as it now does more than just manages the header, it also appends data
|
While I have a Github account, I have not figured out how to merge this pull request into my own Github fork of Ocra, so I have my own fork here: https://www.codebykevin.com/fossil.cgi/stringscan/dir?ci=72deeb91ec0fb17e&name=ocra-master I simply took your stub.c file and replaced the one in the current gem of Ocra, and rebuilt stub.exe. Code-signing works perfectly and I plan to deploy it in the next Windows release of my Ruby-Tk app, Stringscan: https://www.codebykevin.com/stringscan.html Thanks for contributing this! Hopefully the Ocra developer will merge this pull request in a future release. |
Largo
added a commit
to Largo/ocran
that referenced
this pull request
Mar 13, 2026
Adapted from larsch#130
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First I want to say that Ocra is a great tool, it solves a real problem in a very clever way 😄.
However, at work we've come across a limitation - currently an executable built by Ocra cannot be digitally signed using the Windows Authenticode code signing system
I looked into it, and think I got my head around the issue, so I thought I'd open up a PR to add code-signing support.
Ocra expects the executable to look like this:
But, after Code Signing they look like this instead:
This breaks Ocra's expectations and prevents the signed executables from working.
The proposed fix is to update
stub.cto use the executable headers (specifically theDataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]header) to retrieve the size and location of the embedded Digital Signature.Using this information we can tell the Ocra generated executable where to look for its own signature and opcodes. This allows an executable to continue to work whether it's been signed or not.
Tests:
I wrote tests for this using a custom fake code signing object (
test/fake_code_signer.rb) as i thought the requirement for code signing tools was too much.This
FakeCodeSignercorrectly updates the headers and appends a "digital signature" to the file, however the signature that gets appended is just jibberish. But this is enough to test the Ocra code, which is also indifferent to the actual signature content.To perform a real code sign, do the following:
First install the code signing tools (I forget the link for this now, but googling will help you find
makecert,signtooletc)Then create a self-signed cert using:
Generate the
pfxfile using:Then sign an Ocra binary using:
Finally test if
helloworld.exeworks using the updated code.EDIT: Also happy to rebase if you would prefer I pruned some of the commits