Skip to content

Commit

Permalink
Sign executable using pfx certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoapaes committed Jan 17, 2021
0 parents commit 5a2c144
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
work/
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM debian:10-slim as sign

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
osslsigncode openssl \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /work/

ENV CERT_FILE=certificate.pfx
ENV CERT_PASSWORD=123456
ENV EXE_FILE=app.exe
ENV EXE_SIGNED=app_signed.exe

COPY sign.sh /usr/local/bin/sign
RUN chmod +x /usr/local/bin/sign

ENTRYPOINT [ "sign" ]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Executable Sign

Docker image to sign an executable using osslsigncode.

```docker
docker run -v ${PWD}/work/:/work/ likesistemas/exe-sign:latest
```

## Enviroment Variables

CERT_FILE: Certificate file that should be in the / work / folder. Default: certificate.pfx
CERT_PASSWORD: Certificate password. Default: 123456
EXE_FILE: Executable to be signed. Default: app.exe
EXE_SIGNED: Final signed file name. Default: app_signed.exe
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"

services:

sign-exe:
image: likesistemas/exe-sign:latest
build:
context: .
dockerfile: Dockerfile
volumes:
- ./work/:/work/
43 changes: 43 additions & 0 deletions sign.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
if [ ! -f ${CERT_FILE} ]; then
echo "Certificate ${CERT_FILE} file not found"
exit
fi

if [ ! -f ${EXE_FILE} ]; then
echo "Executable '${EXE_FILE}' not found"
exit
fi

mkdir -p sign

KEY_PEM=sign/key.pem
CERT_PEM=sign/cert.pem
RSA_KEY=sign/authenticode.key
RSA_SPC=sign/authenticode.spc

openssl pkcs12 \
-password pass:${CERT_PASSWORD} \
-in ${CERT_FILE} \
-nocerts -nodes \
-out ${KEY_PEM}

openssl pkcs12 \
-password pass:${CERT_PASSWORD} \
-in ${CERT_FILE} \
-nokeys -nodes \
-out ${CERT_PEM}

openssl rsa \
-in ${KEY_PEM} \
-outform DER \
-out ${RSA_KEY}

openssl crl2pkcs7 -nocrl -certfile ${CERT_PEM} \
-outform DER \
-out ${RSA_SPC}

osslsigncode -spc ${RSA_SPC} -key ${RSA_KEY} \
-in ${EXE_FILE} -out ${EXE_SIGNED}

osslsigncode verify ${EXE_SIGNED}

0 comments on commit 5a2c144

Please sign in to comment.