Skip to main content

Overview

Crypto engines manage private key lifecycle operations:
  • Key Generation - RSA and ECDSA key pair creation
  • Key Storage - Secure storage with HSM or cloud KMS
  • Signing Operations - Digital signatures via crypto.Signer interface
  • Key Import/Export - Migrate keys between engines
All engines implement the CryptoEngine interface from github.com/lamassuiot/lamassuiot/core/v3/pkg/engines/cryptoengines.

Available Engines

Software Crypto Engine

Pure Go implementation using standard library crypto. Keys stored in memory or filesystem.Import Path:
import "github.com/lamassuiot/lamassuiot/engines/crypto/software/v3"
Key Features:
  • Security Level: SL1
  • RSA: 2048, 3072, 4096 bits
  • ECDSA: P-256, P-384, P-521 curves
  • PKCS#8 private key encoding
  • No external dependencies
Usage:
engine := software.NewSoftwareCryptoEngine(logger)

// Generate RSA key
keyID, signer, err := engine.CreateRSAPrivateKey(ctx, 2048)

// Generate ECDSA key
keyID, signer, err := engine.CreateECDSAPrivateKey(ctx, elliptic.P256())
Configuration: No configuration required. Used as fallback for key encoding operations in other engines.Source: engines/crypto/software/software.go:41

Engine Selection Guide

Use CaseRecommended EngineSecurity Level
Development/TestingSoftwareSL1
Cloud Production (AWS)AWS KMSSL2
On-Premises ProductionPKCS#11 (HSM)SL2
Hybrid CloudVault KV2SL1
Air-Gapped EnvironmentsPKCS#11 (HSM)SL2

Multi-Engine Configuration

You can register multiple crypto engines and select them per CA:
crypto:
  - id: dev-software
    type: software
  
  - id: prod-hsm
    type: pkcs11
    config:
      module_path: /usr/lib/libCryptoki2_64.so
      token: prod-ca-token
      pin: ${PROD_HSM_PIN}
  
  - id: cloud-kms
    type: awskms
    config:
      aws_region: eu-west-1
When creating a CA, specify the engine ID:
lamassuctl ca create \
  --id root-ca \
  --crypto-engine-id prod-hsm \
  --key-type RSA \
  --key-size 4096

Common Operations

Key Generation

package main

import (
    "context"
    "crypto/elliptic"
    "github.com/lamassuiot/lamassuiot/engines/crypto/aws/v3"
)

func main() {
    engine, _ := aws.NewAWSKMSEngine(logger, awsConfig, metadata)
    
    // RSA key
    keyID, signer, err := engine.CreateRSAPrivateKey(context.Background(), 4096)
    
    // ECDSA key
    keyID, signer, err := engine.CreateECDSAPrivateKey(context.Background(), elliptic.P384())
}

Key Import

// Import existing RSA key to AWS KMS
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048)
keyID, signer, err := engine.ImportRSAPrivateKey(privateKey)

// Import ECDSA key
ecdsaKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
keyID, signer, err := engine.ImportECDSAPrivateKey(ecdsaKey)

Signing

// All engines return crypto.Signer
signer, err := engine.GetPrivateKeyByID(keyID)

// Sign digest
digest := sha256.Sum256([]byte("message"))
signature, err := signer.Sign(rand.Reader, digest[:], crypto.SHA256)

Troubleshooting

Cause: Module path incorrect or HSM not initialized.Solution:
# Verify module exists
ls -l /usr/lib/softhsm/libsofthsm2.so

# Check token status
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --list-slots
Cause: IAM policy missing required permissions.Solution:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "kms:CreateKey",
        "kms:Sign",
        "kms:GetPublicKey",
        "kms:DescribeKey",
        "kms:CreateAlias"
      ],
      "Resource": "*"
    }
  ]
}
Cause: Invalid AppRole credentials or role not configured.Solution:
# Verify AppRole
vault read auth/approle/role/lamassu

# Test login
vault write auth/approle/login \
  role_id=$ROLE_ID \
  secret_id=$SECRET_ID

Next Steps

Storage Engines

Configure PostgreSQL for CA and device storage

Event Bus

Set up AMQP or AWS SNS/SQS for events

Build docs developers (and LLMs) love