godss

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

goxades

First comprehensive solution in Go for creating XAdES-compliant XML signatures using PKCS#11 tokens or keystores. This library enables seamless signing of XML documents, supporting cryptographic devices for secure digital signatures.

Usage

package main

import (
	"fmt"
	"github.com/alapierre/godss/signer"
	"github.com/alapierre/godss/xades"
	"github.com/beevik/etree"
	"os"
	"strings"
)

// Example usage
func main() {

	pin := os.Getenv("PIN")
	if pin == "" {
		panic("PIN envirnoment variable is not set")
	}

	sig, err := signer.NewPkcs11Signer(signer.Pkcs11Config{
		Pkcs11ModulePath: "/opt/proCertumSmartSign/libcryptoCertum3PKCS.so",
		Pin:              pin,
		SlotNumber:       0,
	})

	if err != nil {
		panic(err)
	}

	defer sig.Close()

	x := xades.NewDefault(sig)
	var sampleXml = `<invoice><Number>12345</Number></invoice>`

	doc := etree.NewDocument()
	err = doc.ReadFromString(strings.ReplaceAll(sampleXml, "\n", ""))
	if err != nil {
		panic(err)
	}

	signature, err := x.CreateSignature(doc.Root())
	if err != nil {
		panic(err)
	}

	signedDoc := etree.NewDocument()
	signedDoc.SetRoot(signature)
	signedXML, err := signedDoc.WriteToString()

	if err != nil {
		panic(err)
	}

	fmt.Printf("%s\n", signedXML)

}

Acknowledgments

This project was inspired by and partially based on [goxades], which is licensed under the Apache License, Version 2.0. Some constants and types are copied from [goxmldsig], which is also licensed under the Apache License, Version 2.0.

Significant portions of codebase have been modified or rewritten to better fit the needs of this project.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL