Skip to content

dadu0699/signature-generator

Repository files navigation

Signature Generator

Digital signature generator in Go, designed to expose a secure HTTP service for signing documents using digital certificates and the PKCS#7 standard.

Features

  • RESTful API based on Gin
  • PKCS#7 document signing
  • Support for custom certificates and private keys
  • Configurable CORS
  • Structured logging with zap
  • Production-ready (Docker, Kubernetes)

Prerequisites

  • Go 1.25+
  • air (live reload for Go, optional for development)

Installation

Install dependencies

go mod download

Install air (optional, for development)

go install github.com/cosmtrek/air@latest

On Windows:

go install github.com/cosmtrek/air@latest
set PATH=%PATH%;%USERPROFILE%\go\bin

Quick Start

Build locally

go build -o main.exe ./cmd/signsvc

Run

set PORT=8080
set GIN_MODE=release
set LOG_LEVEL=info
set ALLOWED_ORIGIN=*
main.exe

Use Docker

docker build -t signature-generator .
docker run --rm -p 4321:8080 -e PORT=8080 -e GIN_MODE=release -e LOG_LEVEL=info -e ALLOWED_ORIGIN="*" signature-generator

Development

To start the development server with live reload:

air

This will watch for file changes and automatically rebuild and restart the server using the configuration in .air.toml.

Project Structure

.
├── cmd/signsvc/main.go         # Service entry point
├── internal/
│   ├── app/usecase/            # Application use cases
│   ├── domain/                 # Domain entities
│   ├── infra/                  # Infrastructure (crypto, logging)
│   └── ports/http/gin/         # HTTP adapters (handlers, router)
├── pkg/httpx/cors.go           # HTTP utilities
├── certs/                      # (Optional) Certificates and keys
├── Dockerfile                  # Multi-stage Docker image
├── kubernetes.yml              # Kubernetes deployment example
├── http.rest                   # HTTP request examples
└── .env                        # Environment variables (not versioned)

Environment Variables

  • PORT: Service listening port (default: 5000)
  • GIN_MODE: Gin execution mode (release, debug)
  • LOG_LEVEL: Log level (info, debug, etc.)
  • ALLOWED_ORIGIN: Allowed origin for CORS (e.g., *)

HTTP Request Example

See the http.rest file for usage examples with REST Client or try with curl:

curl -X POST http://localhost:8080/sign \
    -H "Content-Type: application/json" \
    -d '{
        "payload": "Hello world, this is a test message",
        "privateKeyPem": "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----",
        "certificatePem": "-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----",
        "signerCertChainPem": []
    }'

Check the http.rest file for complete usage examples.

Generate test certificates with OpenSSL

openssl genrsa -out key.pem 2048
openssl req -x509 -new -key key.pem -out cert.pem -days 365 -subj "/CN=Test User/O=Example Inc/C=US"

Kubernetes Deployment

See the kubernetes.yml file for a deployment example.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published