Skip to content
/ kmip-go Public

A golang KMIP client and server library, supporting KMIP v1.0 to v1.4.

License

Notifications You must be signed in to change notification settings

ovh/kmip-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

kmip-go

Go Reference license test Go Report Card

A go implementation of the KMIP protocol and client, supporting KMIP v1.0 to v1.4. See KMIP v1.4 protocole specification

This library is developped for and tested against OVHcloud KMS.

NOTE: THIS PROJECT IS CURRENTLY UNDER DEVELOPMENT AND SUBJECT TO BREAKING CHANGES.

Usage

Add it to your project by running

go get github.com/ovh/kmip-go@latest

and import required packages

import (
	"github.com/ovh/kmip-go"
	"github.com/ovh/kmip-go/kmipclient"
	"github.com/ovh/kmip-go/payloads"
	"github.com/ovh/kmip-go/ttlv"
)

Then you can connect to your KMS service:

const (
	ADDR = "eu-west-rbx.okms.ovh.net:5696"
	CA   = "ca.pem"
	CERT = "cert.pem"
	KEY  = "key.pem"
)

client, err := kmipclient.Dial(
	ADDR,
	// Optional if server's CA is known by the system
	// kmipclient.WithRootCAFile(CA),
	kmipclient.WithClientCertFiles(CERT, KEY),
	kmipclient.WithMiddlewares(
		kmipclient.CorrelationValueMiddleware(uuid.NewString),
		kmipclient.DebugMiddleware(os.Stdout, ttlv.MarshalXML),
	),
	// kmipclient.EnforceVersion(kmip.V1_4),
)
if err != nil {
	panic(err)
}
defer client.Close()
fmt.Println("Connected using KMIP version", client.Version())

You can then use the high level client helper methods to create and send requests to the server:

resp := client.Create().
	AES(256, kmip.Encrypt|kmip.Decrypt).
	WithName("my-key").
	MustExec()
fmt.Println("Created AES key with ID", resp.UniqueIdentifier)

Or alternatively if more flexibility is required, craft your kmip requests payloads:

request := payloads.CreateRequestPayload{
	ObjectType: kmip.ObjectTypeSymmetricKey,
	TemplateAttribute: kmip.TemplateAttribute{
		Attribute: []kmip.Attribute{
			{
				AttributeName:  kmip.AttributeNameCryptographicAlgorithm,
				AttributeValue: kmip.AES,
			}, {
				AttributeName:  kmip.AttributeNameCryptographicLength,
				AttributeValue: int32(256),
			}, {
				AttributeName: kmip.AttributeNameName,
				AttributeValue: kmip.Name{
					NameType:  kmip.UninterpretedTextString,
					NameValue: "another-key",
				},
			}, {
				AttributeName:  kmip.AttributeNameCryptographicUsageMask,
				AttributeValue: kmip.Encrypt | kmip.Decrypt,
			},
		},
	},
}

response, err := client.Request(context.Background(), &request)
if err != nil {
	panic(err)
}
id := response.(*payloads.CreateResponsePayload).UniqueIdentifier
fmt.Println("Created an AES key with ID", id)

You can also send batches of requests:

batchResponse, err := client.Batch(context.Background(), &request, &request)
if err != nil {
	panic(err)
}
id1 := batchResponse[0].ResponsePayload.(*payloads.CreateResponsePayload).UniqueIdentifier
id2 := batchResponse[1].ResponsePayload.(*payloads.CreateResponsePayload).UniqueIdentifier
fmt.Println("Created 2 AES keys with IDs", id1, id2)

And directly craft your request message with one or more payloads batched together:

msg := kmip.NewRequestMessage(client.Version(), &request, &request)
rMsg, err := client.Roundtrip(context.Background(), &msg)
if err != nil {
	panic(err)
}
id1 := rMsg.BatchItem[0].ResponsePayload.(*payloads.CreateResponsePayload).UniqueIdentifier
id2 := rMsg.BatchItem[1].ResponsePayload.(*payloads.CreateResponsePayload).UniqueIdentifier
fmt.Println("Created a 5th and 6th AES keys with IDs", id1, id2)

}

See examples for more possibilities.

Implementation status

Legend:

  • N/A : Not Applicable
  • βœ… : Fully compatible
  • ❌ : Not implemented or reviewed
  • 🚧 : Work in progress / Partially compatible
  • πŸ’€ : Deprecated

Messages

v1.0 v1.1 v1.2 v1.3 v1.4
Request Message βœ… βœ… βœ… βœ… βœ…
Response Message βœ… βœ… βœ… βœ… βœ…

Operations

Operation v1.0 v1.1 v1.2 v1.3 v1.4
Create βœ… βœ… βœ… βœ… βœ…
Create Key Pair βœ… βœ… βœ… βœ… βœ…
Register βœ… βœ… βœ… βœ… βœ…
Re-key βœ… βœ… βœ… βœ… βœ…
DeriveKey ❌ ❌ ❌ ❌ ❌
Certify ❌ ❌ ❌ ❌ ❌
Re-certify ❌ ❌ ❌ ❌ ❌
Locate βœ… βœ… βœ… βœ… βœ…
Check ❌ ❌ ❌ ❌ ❌
Get βœ… βœ… βœ… βœ… βœ…
Get Attributes βœ… βœ… βœ… βœ… βœ…
Get Attribute List βœ… βœ… βœ… βœ… βœ…
Add Attribute βœ… βœ… βœ… βœ… βœ…
Modify Attribute βœ… βœ… βœ… βœ… βœ…
Delete Attribute βœ… βœ… βœ… βœ… βœ…
Obtain Lease βœ… βœ… βœ… βœ… βœ…
Get Usage Allocation βœ… βœ… βœ… βœ… βœ…
Activate βœ… βœ… βœ… βœ… βœ…
Revoke βœ… βœ… βœ… βœ… βœ…
Destroy βœ… βœ… βœ… βœ… βœ…
Archive βœ… βœ… βœ… βœ… βœ…
Recover βœ… βœ… βœ… βœ… βœ…
Validate ❌ ❌ ❌ ❌ ❌
Query βœ… βœ… βœ… βœ… βœ…
Cancel ❌ ❌ ❌ ❌ ❌
Poll ❌ ❌ ❌ ❌ ❌
Notify ❌ ❌ ❌ ❌ ❌
Put ❌ ❌ ❌ ❌ ❌
Discover N/A βœ… βœ… βœ… βœ…
Re-key Key Pair N/A ❌ ❌ ❌ ❌
Encrypt N/A N/A βœ… βœ… βœ…
Decrypt N/A N/A βœ… βœ… βœ…
Sign N/A N/A ❌ ❌ ❌
Signature Verify N/A N/A ❌ ❌ ❌
MAC N/A N/A ❌ ❌ ❌
MAC Verify N/A N/A ❌ ❌ ❌
RNG Retrieve N/A N/A ❌ ❌ ❌
RNG Seed N/A N/A ❌ ❌ ❌
Hash N/A N/A ❌ ❌ ❌
Create Split Key N/A N/A ❌ ❌ ❌
Join Split Key N/A N/A ❌ ❌ ❌
Export N/A N/A N/A N/A ❌
Import N/A N/A N/A N/A ❌

Managed Objects

Object v1.0 v1.1 v1.2 v1.3 v1.4
Certificate βœ… βœ… βœ… βœ… βœ…
Symmetric Key βœ… βœ… βœ… βœ… βœ…
Public Key βœ… βœ… βœ… βœ… βœ…
Private Key βœ… βœ… βœ… βœ… βœ…
Split Key βœ… βœ… βœ… βœ… βœ…
Template βœ… βœ… βœ… πŸ’€ πŸ’€
Secret Data βœ… βœ… βœ… βœ… βœ…
Opaque Object βœ… βœ… βœ… βœ… βœ…
PGP Key N/A N/A βœ… βœ… βœ…

Base Objects

Object v1.0 v1.1 v1.2 v1.3 v1.4
Attribute βœ… βœ… βœ… βœ… βœ…
Β Credential βœ… βœ… βœ… βœ… βœ…
Β Key Block βœ… βœ… βœ… βœ… βœ…
Key Value βœ… βœ… βœ… βœ… βœ…
Key Wrapping Data βœ… βœ… βœ… βœ… βœ…
Key Wrapping Specification βœ… βœ… βœ… βœ… βœ…
Transparent Key Structures 🚧 🚧 🚧 🚧 🚧
Template-Attribute Structures βœ… βœ… βœ… βœ… βœ…
Extension Information N/A βœ… βœ… βœ… βœ…
Data N/A N/A ❌ ❌ ❌
Data Length N/A N/A ❌ ❌ ❌
Signature Data N/A N/A ❌ ❌ ❌
MAC Data N/A N/A ❌ ❌ ❌
Nonce N/A N/A βœ… βœ… βœ…
Correlation Value N/A N/A N/A ❌ ❌
Init Indicator N/A N/A N/A ❌ ❌
Final Indicator N/A N/A N/A ❌ ❌
RNG Parameter N/A N/A N/A βœ… βœ…
Profile Information N/A N/A N/A βœ… βœ…
Validation Information N/A N/A N/A βœ… βœ…
Capability Information N/A N/A N/A βœ… βœ…
Authenticated Encryption Additional Data N/A N/A N/A N/A ❌
Authenticated Encryption Tag N/A N/A N/A N/A ❌

Transparent Key Structures

Object v1.0 v1.1 v1.2 v1.3 v1.4
Symmetric Key βœ… βœ… βœ… βœ… βœ…
DSA Private/Public Key ❌ ❌ ❌ ❌ ❌
RSA Private/Public Key βœ… βœ… βœ… βœ… βœ…
DH Private/Public Key ❌ ❌ ❌ ❌ ❌
ECDSA Private/Public Key βœ… βœ… βœ… πŸ’€ πŸ’€
ECDH Private/Public Key ❌ ❌ ❌ πŸ’€ πŸ’€
ECMQV Private/Public ❌ ❌ ❌ πŸ’€ πŸ’€
EC Private/Public N/A N/A N/A βœ… βœ…

Attributes

Attribute v1.0 v1.1 v1.2 v1.3 v1.4
Unique Identifier βœ… βœ… βœ… βœ… βœ…
Name βœ… βœ… βœ… βœ… βœ…
Object Type βœ… βœ… βœ… βœ… βœ…
Cryptographic Algorithm βœ… βœ… βœ… βœ… βœ…
Cryptographic Length βœ… βœ… βœ… βœ… βœ…
Cryptographic Parameters βœ… βœ… βœ… βœ… βœ…
Cryptographic Domain Parameters βœ… βœ… βœ… βœ… βœ…
Certificate Type βœ… βœ… βœ… βœ… βœ…
Certificate Identifier βœ… πŸ’€ πŸ’€ πŸ’€ πŸ’€
Certificate Subject βœ… πŸ’€ πŸ’€ πŸ’€ πŸ’€
Certificate Issuer βœ… πŸ’€ πŸ’€ πŸ’€ πŸ’€
Digest βœ… βœ… βœ… βœ… βœ…
Operation Policy Name βœ… βœ… βœ… πŸ’€ πŸ’€
Cryptographic Usage Mask βœ… βœ… βœ… βœ… βœ…
Lease Time βœ… βœ… βœ… βœ… βœ…
Usage Limits βœ… βœ… βœ… βœ… βœ…
State βœ… βœ… βœ… βœ… βœ…
Initial Date βœ… βœ… βœ… βœ… βœ…
Activation Date βœ… βœ… βœ… βœ… βœ…
Process Start Date βœ… βœ… βœ… βœ… βœ…
Protect Stop Date βœ… βœ… βœ… βœ… βœ…
Deactivation Date βœ… βœ… βœ… βœ… βœ…
Destroy Date βœ… βœ… βœ… βœ… βœ…
Compromise Occurrence Date βœ… βœ… βœ… βœ… βœ…
Compromise Date βœ… βœ… βœ… βœ… βœ…
Revocation Reason βœ… βœ… βœ… βœ… βœ…
Archive Date βœ… βœ… βœ… βœ… βœ…
Object Group βœ… βœ… βœ… βœ… βœ…
Link βœ… βœ… βœ… βœ… βœ…
Application Specific Information βœ… βœ… βœ… βœ… βœ…
Contact Information βœ… βœ… βœ… βœ… βœ…
Last Change Date βœ… βœ… βœ… βœ… βœ…
Custom Attribute βœ… βœ… βœ… βœ… βœ…
Certificate Length N/A βœ… βœ… βœ… βœ…
X.509 Certificate Identifier N/A βœ… βœ… βœ… βœ…
X.509 Certificate Subject N/A βœ… βœ… βœ… βœ…
X.509 Certificate Issuer N/A βœ… βœ… βœ… βœ…
Digital Signature Algorithm N/A βœ… βœ… βœ… βœ…
Fresh N/A βœ… βœ… βœ… βœ…
Alternative Name N/A N/A βœ… βœ… βœ…
Key Value Present N/A N/A βœ… βœ… βœ…
Key Value Location N/A N/A βœ… βœ… βœ…
Original Creation Date N/A N/A βœ… βœ… βœ…
Random Number Generator N/A N/A N/A βœ… βœ…
PKCS#12 Friendly Name N/A N/A N/A N/A βœ…
Description N/A N/A N/A N/A βœ…
Comment N/A N/A N/A N/A βœ…
Sensitive N/A N/A N/A N/A βœ…
Always Sensitive N/A N/A N/A N/A βœ…
Extractable N/A N/A N/A N/A βœ…
Never Extractable N/A N/A N/A N/A βœ…

About

A golang KMIP client and server library, supporting KMIP v1.0 to v1.4.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages