• Stars
    star
    108
  • Rank 310,852 (Top 7 %)
  • Language
    Go
  • License
    Other
  • Created about 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Golang symmetric encryption library

symmecrypt

symmecrypt is a symmetric encryption toolsuite. It provides recommended implementations of crypto algorithms and facilities around configuration management and encryption key lifecycle.

GoDoc Go Report Card

Overview

  • symmecrypt: Symmetrical encryption with MAC. Built-in cipher implementations provided, but extensible. Also provides a keyring mechanism for easy key rollover.
  • symmecrypt/seal: Encryption through a symmetric key split in shards (shamir)
  • symmecrypt/keyloader: Configuration manager that loads symmecrypt compatible keys from configuration, and supports key seal and hot-reloading.

Dependencies

  • configstore: symmecrypt/seal and symmecrypt/keyloader provide configuration management facilities, that rely on the configstore library. It provides file system, in memory sources, as well as data source abstraction (providers), so that any piece of code can easily bridge it with its own configuration management.

Example

    k, err := keyloader.LoadKey("storage")
    if err != nil {
        panic(err)
    }

    encrypted, err := k.Encrypt([]byte("foobar"), []byte("additional"), []byte("mac"), []byte("data"))
    if err != nil {
        panic(err)
    }

    // decryption will fail if you do not provide the same additional data
    // of course, you can also encrypt/decrypt without additional data
    decrypted, err := k.Decrypt(encrypted, []byte("additional"), []byte("mac"), []byte("data"))
    if err != nil {
        panic(err)
    }

    // output: foobar
    fmt.Println(string(decrypted))

Configuration format

Package configstore is used for sourcing and managing key configuration values.

    // before loading a key by its identifier, package `configstore` needs to
    // be configured so it knows about possible configuration sources
    //
    // this would load keys from a file named "key.txt" that contains a key with
    // the identifier "storage":
    configstore.File("key.txt")
    // more options can be found here: https://github.com/ovh/configstore
    k, err := keyloader.LoadKey("storage")

symmecrypt looks for items in the config store that are of key encryption-key, its value is expected to be a JSON string containing the key itself.

If loading from a text file this would look like:

- key: encryption-key
  value: '{"identifier":"storage","cipher":"aes-gcm","timestamp":1559309532,"key":"b6a942c0c0c75cc87f37d9e880c440ac124e040f263611d9d236b8ed92e35521"}'

or when done in code:

  item := configstore.NewItem("encryption-key", `{"identifier":"storage","cipher":"aes-gcm","timestamp":1559309532,"key":"b6a942c0c0c75cc87f37d9e880c440ac124e040f263611d9d236b8ed92e35521"}`, 0)

Key rollover

It is important to be able to easily rollover keys when doing symmetric encryption.

For that, one needs to be able to keep decrypting old ciphertexts using the old key, while encrypting new entries with a new, different key.

Then, the old ciphertexts should all be re-encrypted using the new key.

symmecrypt + symmecrypt/keyloader make that easy, by providing a keyring / composite key implementation that encrypts with the latest key, while decrypting with any key of the keyring.

Encryption keys are fetched from the configuration, and are expected to have the following format:

    encryption-key: {"cipher":"aes-gcm","key":"442fca912da8309613542e7bb29788a44c162cde6ee4f0f5b1322132f65a2ddc","identifier":"storage","timestamp":1522138216}
    encryption-key: {"cipher":"aes-gcm","key":"49a9bc2774e7976c44f4bb6e1e3e6fc70e629be5923a511c8187b72bdc8f848c","identifier":"storage","timestamp":1522138240}
    

With this configuration, the previous example code would automatically instantiate a composite key through keyloader.LoadKey(), and be able to decrypt using either key, while all new encryptions would use the timestamp == 1522138240 key.

Seal

If you do not want to rely on the confidentiality of your configuration to protect your encryption keys, you can seal them.

symmecrypt/seal provides encryption through a symmetric key which is split in several shards (shamir algorithm). The number of existing shards and the minimum threshold needed to unlock the seal can be configured when first generating it.

symmecrypt/keyloader uses symmecrypt/seal to generate and load encryption keys which are themselves encrypted. This is controlled via the sealed boolean property in a key configuration.

When generating a key via symmecrypt/keyloader.GenerateKey, use sealed = true. This will use the singleton global instance of the symmecrypt/seal package to directly seal the key.

When loading a key via symmecrypt/keyloader.LoadKey, the returned key will automatically decrypt itself and become usable as soon as the singleton global instance of symmecrypt/seal becomes unsealed (human operation).

A sealed encryption key is unusable on its own, which makes your configuration less at risk. Additionally, the metadata of the key (identifier, timestamp, cipher...) are passed as additional MAC data when encrypting/decrypting the key, preventing any alteration.

    seal:           {"min": 2, "total": 3, "nonce": "9cce8734c707881b1b00d24c3d9cee13"} // Seal definition
    encryption-key: {"cipher":"aes-gcm","key":"3414e0524c6a52018849b562b74e611748caf842dd653abc53469c986993f79d4406c662a1a7a9bef141ea88e0464e5bd79857f496418df81bb19ec391174af1d956603c7b8c2825a528972610b25483601c3083ef14c62c31e04f69","identifier":"storage","sealed":true,"timestamp":1522138887}
    encryption-key: {"cipher":"aes-gcm","key":"52ef448282bfbdaedcbda970a54b8626ef97a58ffc5489897554c8cba85cf4001d93b23751aaffb5ef2175192bb83ee7c0568634e8d0c7e4ae39f5102402d984220c64d4c6450b034b841844be818a6c5b0ef9016d92b9de1de5408c","identifier":"storage","sealed":true,"timestamp":1522138924}
    

These keys can be generated via symmecrypt/keyloader.GenerateKey(), and are recognized and correctly instantiated by symmecrypt/keyloader.LoadKey().

Supporting your old crypto code

If you want to start using symmecrypt but currently depend on another different implementation, no worries. symmecrypt supports custom types/ciphers. You can register a named factory via symmecrypt.RegisterCipher(), which has to return an object respecting the symmecrypt.Key interface, and will be invoked by symmecrypt/keyloader when this cipher is specified in a key configuration. That way, you can bridge your old code painlessly, and can get rid of the compatibility bridge once you rollover your encrypted data.

Or you can also decide to keep your own Key implementation, and use it through the keyloader that way.

Note: no matter its cipher (built-in or extended), a key can optionally be sealed without additional logic, this is all handled by symmecrypt/keyloader itself.

    seal:           {"min": 2, "total": 3, "nonce": "9cce8734c707881b1b00d24c3d9cee13"} // Seal definition
    encryption-key: {"cipher":"old-aes-algo","key":"3414e0524c6a52018849b562b74e611748caf842dd653abc53469c986993f79d4406c662a1a7a9bef141ea88e0464e5bd79857f496418df81bb19ec391174af1d956603c7b8c2825a528972610b25483601c3083ef14c62c31e04f69","identifier":"storage","sealed":true,"timestamp":1522138887}
    encryption-key: {"cipher":"aes-gcm","key":"52ef448282bfbdaedcbda970a54b8626ef97a58ffc5489897554c8cba85cf4001d93b23751aaffb5ef2175192bb83ee7c0568634e8d0c7e4ae39f5102402d984220c64d4c6450b034b841844be818a6c5b0ef9016d92b9de1de5408c","identifier":"storage","sealed":true,"timestamp":1522138924}

    symmecrypt.RegisterCipher("old-aes-algo", OldAESFactory)

    k, err := keyloader.LoadKey("storage")
    if err != nil {
        panic(err)
    }

    encrypted, err := k.Encrypt([]byte("foobar"), []byte("additional"), []byte("mac"), []byte("data"))
    if err != nil {
        panic(err)
    }

    decrypted, err := k.Decrypt(encrypted, []byte("additional"), []byte("mac"), []byte("data"))
    if err != nil {
        panic(err)
    }

    // output: foobar
    fmt.Println(string(decrypted))

With such a configuration, any of your previous ciphertexts can be read using your old implementation, but any new data will be encrypted using symmecrypt's aes-gcm implementation.

Available ciphers

symmecrypt provides built-in implementations of symmetric authenticated ciphers:

aes-gcm

Robust Fast Proven
โญโญ โญโญโญ โญโญโญ

AES Galois/Counter mode (256bits), with built-in authentication.

โ— Nonces are randomly generated and should not be repeated with aes-gcm, remember to rollover your key on a regular basis. Nonce size is 96 bits, which is not ideal for random generation due to the risk of collision, prefer xchacha20-poly1305.

chacha20-poly1305

Robust Fast Proven
โญโญ โญโญโญ โญโญ

ChaCha20-Poly1305, with built-in authentication.

โ— Nonces are randomly generated and should not be repeated with chacha20-poly1305, remember to rollover your key on a regular basis. Nonce size is 96 bits, which is not ideal for random generation due to the risk of collision, prefer xchacha20-poly1305.

xchacha20-poly1305

Robust Fast Proven
โญโญโญ โญโญโญ โญโญ

Variant of ChaCha20-Poly1305 with extended nonce, with built-in authentication.

โ— Nonces are randomly generated and should not be repeated with xchacha20-poly1305, remember to rollover your key on a regular basis. Nonce size is 192 bits, which is acceptable for random generation.

aes-pmac-siv

Robust Fast Proven
โญโญโญ โญโญ โญ

Parallelized implementation of AES-SIV (256 bits), with built-in authentication.

โ— This cipher is still young, use with caution.

โ— This is one of the rare ciphers which is not weak to nonce reuse.

More information:

hmac

Robust Fast Proven
โญโญโญ โญโญโญ โญโญโญ

โ— DOES NOT GUARANTEE CONFIDENTIALITY.

HMAC-sha512 for authentication only. Note: if the input consists only of printable characters, so will the output.

Command-line tool

A command-line tool is available as a companion to the library (source).

It can be used to generate new random encryption keys for any of the built-in symmecrypt ciphers, and to encrypt/decrypt arbitrary data.

Example (new key)

    $ symmecrypt new aes-gcm --key=storage_key
    {"identifier":"storage_key","cipher":"aes-gcm","timestamp":1538383069,"key":"46ca74bf7a980ffbfdeea5a66593f7a8f12039f872694015e66c44b652165ee4"}

Example (file)

    $ export ENCRYPTION_KEY_BASE64=$(symmecrypt new aes-gcm --base64)
    $ symmecrypt encrypt <<EOF >test.encrypted
    foo
    bar
    baz
    EOF
    $ cat -e test.encrypted
    ^^JDM-1^EM-$M-^K1nX;^WM-^HC6^Xw^?^BM-.M-p^[M-%=^M-^ZM-uM-%M-2^H6M-sM-NM-FM-^H^RM-]g^_&$
    $ symmecrypt decrypt <test.encrypted
    foo
    bar
    baz

Example (script)

    export ENCRYPTION_KEY_BASE64=$(symmecrypt new aes-gcm --base64)
    ENCRYPTED=$(echo foo bar baz | symmecrypt encrypt --base64)
    PLAIN=$(echo $ENCRYPTED | symmecrypt decrypt --base64)

More Repositories

1

cds

Enterprise-Grade Continuous Delivery & DevOps Automation Open Source Platform
Go
4,440
star
2

the-bastion

Authentication, authorization, traceability and auditability for SSH accesses.
Perl
1,429
star
3

utask

ยตTask is an automation engine that models and executes business processes declared in yaml. โœ๏ธ๐Ÿ“‹
Go
1,100
star
4

venom

๐Ÿ Manage and run your integration tests with efficiency - Venom run executors (script, HTTP Request, web, imap, etc... ) and assertions
Go
974
star
5

debian-cis

PCI-DSS compliant Debian 10/11/12 hardening
Shell
667
star
6

celery-director

Simple and rapid framework to build workflows with Celery
Python
512
star
7

svfs

The Swift Virtual File System
Go
373
star
8

php-ovh

Lightweight PHP wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.
PHP
287
star
9

python-ovh

Thin wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.
Python
266
star
10

docs

Official repository containing all docs & guides of OVH Group
HTML
214
star
11

manager

OVHcloud Control Panel
JavaScript
203
star
12

overthebox

OverTheBox - Aggregate and encrypt your multiple internet connections.
Shell
194
star
13

public-cloud-roadmap

Agile roadmap for OVHcloud Public Cloud services. Discover the features our product teams are working on, comment and influence our backlog.
183
star
14

terraform-provider-ovh

Terraform OVH provider
Go
178
star
15

metronome

Metronome is a distributed and fault-tolerant event scheduler
Go
135
star
16

node-ovh

Node.js wrapper for the OVH APIs
JavaScript
125
star
17

go-ovh

Simple go wrapper for the OVH API
Go
124
star
18

ai-training-examples

Jupyter Notebook
121
star
19

overthebox-feeds

OverTheBox - LEDE/OpenWrt feed
HTML
106
star
20

ovh-ttyrec

Enhanced (but compatible) version of the classic ttyrec
C
105
star
21

overthebox-openwrt

OverTheBox - OpenWrt fork
C
98
star
22

sv2chisel

(System)Verilog to Chisel translator
Scala
97
star
23

celery-dyrygent

Celery extension which allows to orchestrate 100/1000/10000 tasks combined into a complex workflow
Python
94
star
24

tat

Tat Engine - Text And Tags
Go
89
star
25

beamium

Prometheus to Warp10 metrics forwarder
Rust
84
star
26

ip-reputation-monitoring

Monitor the reputation of your IP ranges
Python
82
star
27

depc

QoS Measurement & Dependency Graph Platform
Python
80
star
28

configstore

Golang configuration management library
Go
62
star
29

erlenmeyer

Erlenmeyer is a proxy used to parse common Open Source TimeSeries DataBase query endpoints like OpenTSDB, Prometheus/PromQL, InfluxQL or Graphite. Parsed queries are translated into WarpScript to produce native Warp 10 queries.
Go
60
star
30

tsl

TSL is a HTTP proxy which generate WarpScript or a PromQl script based on a TSL query.
Go
56
star
31

noderig

Export OS stats as Sensision Metrics
Go
55
star
32

ovh-ui-kit

OVHcloud UI Kit - Master UI Framework
JavaScript
53
star
33

terraform-ovh-commons

This repo contains commons resources to interact with OVH Public Cloud using Terraform.
HTML
53
star
34

php-ovh-sms

PHP for ovh sms API
PHP
49
star
35

ovh-cli

OVH Command Line Interface
Python
41
star
36

infrastructure-roadmap

34
star
37

summit2016-RankingPredict

Deprecated, No more maintained - Deprecated, no longer maintained
R
34
star
38

ovh-warp10-datasource

Grafana datasource for Warp10 platform
TypeScript
33
star
39

the-bastion-ansible-wrapper

Using Ansible through The Bastion
Python
30
star
40

csharp-ovh

Thin wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing
C#
27
star
41

order-cart-examples

Example code snippets demonstrating how to use new order with cart on api.ovh.com
PHP
25
star
42

ldp-tail

OVH Logs Data Platform - Tail CLI tooling
Go
24
star
43

haproxy-exporter

Export HAProxy stats as Sensision Metrics
Go
21
star
44

fossil

Fossil is a proxy for securing unencrypted Graphite metrics collection
Go
20
star
45

java-ovh

Thin wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing
Java
19
star
46

tatwebui

Tat Web UI - Text And Tags
JavaScript
19
star
47

terraform-ovh-publiccloud-network

HCL
19
star
48

python-apispec-fromfile

APISpec plugin to import OpenAPI specifications from a file
Python
18
star
49

design-system

A collection of assets, guidelines and UI components for building consistent user experiences across OVHcloud products.
TypeScript
18
star
50

public-cloud-examples

Jupyter Notebook
18
star
51

cerberus-ux

HTML
15
star
52

lxd-puppet-module

Ruby
14
star
53

website-evidence-collector-batch

A tool to launch website-evidence-collector on several URLs or Sitemaps and generate a full report.
JavaScript
14
star
54

osarchiver

OpenStack databases archiver
Python
14
star
55

jerem

Jerem is a golang bot that scrap JIRA project to extract Metrics. Those Metrics can then be send to a Warp 10 Backend.
Go
14
star
56

cerberus-core

Cerberus is a toolkit to receive, parse, process and automate abuse reports handling received by ISP or hosting providers.
Python
14
star
57

ovh-ui-kit-bs

A bootstrap theme for the OVH managers, based on ovh-ui-kit
Less
13
star
58

prescience-client

Desktop python client for using OVH Prescience service
Jupyter Notebook
13
star
59

gulp-drupal-stack

OVH Gulp tasks for Drupal themes and modules
JavaScript
12
star
60

public-cloud-databases-examples

OVHcloud Public Cloud Databases Training examples
HCL
12
star
61

distronaut

Find distribution installers all across the web !
Go
12
star
62

serving-runtime

Exposes a serialized machine learning model through a HTTP API.
Java
12
star
63

metronome-ui

User interface for Metronome
JavaScript
11
star
64

private-cloud-roadmap

11
star
65

swift-ovh

This Swift package is a lightweight wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your Swift applications. Apple platforms supported: iOS, OSX, tvOS, watchOS.
Swift
11
star
66

rtm

RTM (OVH Real Time Monitoring)
Perl
11
star
67

pulumi-ovh

Pulumi provider for OVHcloud
Python
11
star
68

telephony-example-cti-dashboard

Shows signaling events provided by OVH France telephony services CTI
CSS
11
star
69

drucker

Drucker is a lightweight Drupal Developer Environment.
Shell
10
star
70

phishing-mitigation

Tilera-based phishing mitigation layer
JavaScript
10
star
71

lhasa

List and map micro-services-based information system and observe how they interact. Track their activities, then gamify their continuous improvement.
Go
10
star
72

overthebox-lede

OverTheBox - LEDE fork
C
8
star
73

owstats-ui

JavaScript
8
star
74

python-logging-gelf

A python logging bundle to send logs using GELF
Python
8
star
75

webpaas-cli

PHP
7
star
76

vbridge

X11 cloud desktop software
C
7
star
77

djehouty

Djehouty intends to be a set of logging formatters and handlers to easily send log entries.
Python
7
star
78

crystal-ovh

Lightweight Crystal wrapper around OVH's APIs.
Crystal
7
star
79

ovhdata-cli

Rust
7
star
80

python-warp10client

Python
7
star
81

data-processing-spark-submit

Spark CLI wrapper to run your jobs on OVHcloud Data Processing
Go
7
star
82

interpretability-engine

Interpret Machine Learning black-box models deployed on Serving Engine
Python
6
star
83

terraform-provider-mimirtool

Terraform provider for Grafana Mimir
Go
6
star
84

webhosting-ssh-bashrc

Shell
6
star
85

tat-contrib

Go
6
star
86

puppet-thebastion

Puppet module for Thebastion management.
Ruby
6
star
87

public-cloud-databases-operator

This operator allow you to automaticaly authorize your Kubernetes cluster IP on your OVHcloud cloud databases service.
Go
6
star
88

docs-developer-env

Easy to deploy developer environment, for writing/testing guides & documentations for docs.ovh.com
Shell
6
star
89

docs-rendering

[DEPRECATED] Official rendering engine for static generation of OVH Docs platform
HTML
6
star
90

terraform-ovh-publiccloud-docker-swarm

HCL
5
star
91

terraform-ovh-publiccloud-spark

HCL
5
star
92

summit2016-webhosting-example-rondcoin

PHP
5
star
93

collectd-write-warp10

Python
5
star
94

fiowebviewer

Python
5
star
95

yubico-piv-checker

Go
4
star
96

puppet-mimir

Ruby
4
star
97

pingdom-to-graphite

A tool for copying metrics from Pingdom to Graphite.
JavaScript
4
star
98

ovh-winston-ldp

A graylog2 TCP/TLS transport for winston library
JavaScript
4
star
99

bringyourownlinux

Shell
4
star
100

.github

Community health files for the @ovh organization
3
star