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.
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.CryptographicUsageEncrypt|kmip.CryptographicUsageDecrypt).
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.CryptographicAlgorithmAES,
}, {
AttributeName: kmip.AttributeNameCryptographicLength,
AttributeValue: int32(256),
}, {
AttributeName: kmip.AttributeNameName,
AttributeValue: kmip.Name{
NameType: kmip.NameTypeUninterpretedTextString,
NameValue: "another-key",
},
}, {
AttributeName: kmip.AttributeNameCryptographicUsageMask,
AttributeValue: kmip.CryptographicUsageEncrypt | kmip.CryptographicUsageDecrypt,
},
},
},
}
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.
Legend:
- N/A : Not Applicable
- β : Fully compatible
- β : Not implemented
- π§ : Work in progress / Partially compatible
- π : Deprecated
v1.0 | v1.1 | v1.2 | v1.3 | v1.4 | |
---|---|---|---|---|---|
Request Message | β | β | β | β | β |
Response Message | β | β | β | β | β |
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 | β |
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 | β | β | β |
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 | β |
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 | β | β |
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 | β |