Categorygithub.com/Keyfactor/ejbca-go-client-sdk

# README

Go Client SDK for Keyfactor EJBCA

The Go Client SDK for Keyfactor EJBCA enables management of EJBCA resources utilizing the Go programming language.

Support for the Keyfactor EJBCA Go Client SDK

We welcome contributions.

The Keyfactor EJBCA Go Client SDK is open source and community supported, meaning that there is no SLA applicable for these tools.

To report a problem or suggest a new feature, use the Issues tab. If you want to contribute actual bug fixes or proposed enhancements, use the Pull requests tab.

Installation

Install the Go Client SDK for Keyfactor EJBCA using the go get command:

go get github.com/Keyfactor/ejbca-go-client-sdk

Put the package under your project folder and add the following in import:

import "github.com/Keyfactor/ejbca-go-client-sdk/api/ejbca"

Configuration

Communication with the EJBCA REST API is authenticated using mTLS (client certificate) or OAuth 2.0 (token). Authentication is handled via the ejbca.Authenticator interface, and the SDK ships with two default implementations, described below.

Both the mTLS and OAuth authenticators enable configuration of a CA Certificate if the target EJBCA server doesn't serve a certificate signed by a publically trusted root. Your application may elect to source this CA certificate via an appropriate authentication mechanism, or provide the appropriate authenticator builder with a path. Both methods are demonstrated below.

The following code snippets demonstrate how to configure the EJBCA client with an mTLS authenticator:

import (
    "crypto/x509"
    "fmt"
    "crypto/tls"

    "github.com/Keyfactor/ejbca-go-client-sdk/api/ejbca"
)

// Source the CA chain by an appropriate method for your application
caChain := []byte("<ca chain source by your application>")

caCerts, err := x509.ParseCertificates(caChain)
if err != nil {
    panic(err)
}

// Source the client certificate and key by an appropriate method for your application
clientCertificate := []byte("<client certificate source by your application>")
clientKey := []byte("<client key source by your application>")

tlsCert, err := tls.X509KeyPair(clientCertificate, clientKey)
if err != nil {
    panic(err)
}

authenticator, err := ejbca.NewMTLSAuthenticatorBuilder().
    WithClientCertificate(&tlsCert).
    WithCaCertificates(caCerts).
    Build()
if err != nil {
    panic(err)
}

The ejbca.MTLSAuthenticatorBuilder can also source the client certificate, key and CA certificate from a provided path. It's important that the certificates at the specified paths be PEM encoded X.509 certificates, and the private key must be an unencrypted PKCS#8 key.

import "github.com/Keyfactor/ejbca-go-client-sdk/api/ejbca"

authenticator, err := ejbca.NewMTLSAuthenticatorBuilder().
    WithClientCertificatePath("<path to client certificate>").
    WithClientCertificateKeyPath("<path to client key>").
    WithCaCertificatePath("<path to ca certificate>").
    Build()
if err != nil {
    panic(err)
}

OAuth2.0 is configured using the ejbca.OAuthAuthenticatorBuilder. Under the hood, this authenticator uses the golang.org/x/oauth2/clientcredentials package to implement the OAuth2.0 "client credentials" token flow, since the client is acting on its own behalf.

import "github.com/Keyfactor/ejbca-go-client-sdk/api/ejbca"

authenticator, err := ejbca.NewOAuthAuthenticatorBuilder().
    WithCaCertificates(caCerts).
//  WithCaCertificatePath("<path to ca certificate>").
    WithTokenUrl("<url to token endpoint>").
    WithClientId("<client ID>").
    WithClientSecret("<client secret>").
    WithAudience("<optional audience").
    WithScopes("<optional scopes>").
    Build()
if err != nil {
    panic(err)
}

Finally, the EJBCA client is configured with the authenticator and the hostname of the EJBCA server:

import "github.com/Keyfactor/ejbca-go-client-sdk/api/ejbca"

configuration := ejbca.NewConfiguration()
configuration.Host = "<hostname>:<optional port>"
configuration.SetAuthenticator(authenticator)

ejbcaClient, err := ejbca.NewAPIClient(configuration)
if err != nil {
    panic(err)
}

If neither authentication mechanism is suitable for your application, you can implement your own authenticator by implementing the ejbca.Authenticator interface.

Documentation for API Endpoints

All URIs are relative to http://localhost/ejbca/ejbca-rest-api

ClassMethodHTTP requestDescription
V1CaApiCreateCrlPost /v1/ca/{issuer_dn}/createcrlCreate CRL(main, partition and delta) issued by this CA
V1CaApiGetCertificateAsPemGet /v1/ca/{subject_dn}/certificate/downloadGet PEM file with the active CA certificate chain
V1CaApiGetLatestCrlGet /v1/ca/{issuer_dn}/getLatestCrlReturns the latest CRL issued by this CA
V1CaApiImportCrlPost /v1/ca/{issuer_dn}/importcrlImport a certificate revocation list (CRL) for a CA
V1CaApiListCasGet /v1/caReturns the Response containing the list of CAs with general information per CA as Json
V1CaApiStatus1Get /v1/ca/statusGet the status of this REST Resource
V1CaManagementApiActivatePut /v1/ca_management/{ca_name}/activateActivate a CA
V1CaManagementApiDeactivatePut /v1/ca_management/{ca_name}/deactivateDeactivate a CA
V1CaManagementApiStatusGet /v1/ca_management/statusGet the status of this REST Resource
V1CertificateApiCertificateRequestPost /v1/certificate/certificaterequestEnrollment with client generated keys for an existing End Entity
V1CertificateApiEnrollKeystorePost /v1/certificate/enrollkeystoreKeystore enrollment
V1CertificateApiEnrollPkcs10CertificatePost /v1/certificate/pkcs10enrollEnrollment with client generated keys, using CSR subject
V1CertificateApiFinalizeEnrollmentPost /v1/certificate/{request_id}/finalizeFinalize enrollment
V1CertificateApiGetCertificatesAboutToExpireGet /v1/certificate/expireGet a list of certificates that are about to expire
V1CertificateApiRevocationStatusGet /v1/certificate/{issuer_dn}/{certificate_serial_number}/revocationstatusChecks revocation status of the specified certificate
V1CertificateApiRevokeCertificatePut /v1/certificate/{issuer_dn}/{certificate_serial_number}/revokeRevokes the specified certificate
V1CertificateApiSearchCertificatesPost /v1/certificate/searchSearches for certificates confirming given criteria.
V1CertificateApiStatus2Get /v1/certificate/statusGet the status of this REST Resource
V1ConfigdumpApiGetJsonConfigdumpGet /v1/configdumpGet the configuration in JSON.
V1ConfigdumpApiGetJsonConfigdumpForTypeGet /v1/configdump/{type}Get the configuration for type in JSON.
V1ConfigdumpApiGetJsonConfigdumpForTypeAndSettingGet /v1/configdump/{type}/{setting}Get the configuration for a type and setting in JSON.
V1ConfigdumpApiGetZipExportGet /v1/configdump/configdump.zipGet the configuration as a ZIP file.
V1ConfigdumpApiPostJsonImportPost /v1/configdumpPut the configuration in JSON.
V1ConfigdumpApiPostZipImportPost /v1/configdump/configdump.zipPut the configuration as a ZIP file.
V1ConfigdumpApiStatus4Get /v1/configdump/statusGet the status of this REST Resource
V1CryptotokenApiActivate1Put /v1/cryptotoken/{cryptotoken_name}/activateActivate a Crypto Token
V1CryptotokenApiDeactivate1Put /v1/cryptotoken/{cryptotoken_name}/deactivateDeactivate a Crypto Token
V1CryptotokenApiGenerateKeysPost /v1/cryptotoken/{cryptotoken_name}/generatekeysGenerate keys
V1CryptotokenApiRemoveKeysPost /v1/cryptotoken/{cryptotoken_name}/{key_pair_alias}/removekeysRemove keys
V1CryptotokenApiStatus5Get /v1/cryptotoken/statusGet the status of this REST Resource
V1EndentityApiAddPost /v1/endentityAdd new end entity, if it does not exist
V1EndentityApiDeleteDelete /v1/endentity/{endentity_name}Deletes end entity
V1EndentityApiRevokePut /v1/endentity/{endentity_name}/revokeRevokes all end entity certificates
V1EndentityApiSearchPost /v1/endentity/searchSearches for end entity confirming given criteria.
V1EndentityApiSetstatusPost /v1/endentity/{endentity_name}/setstatusEdits end entity setting new status
V1EndentityApiStatus6Get /v1/endentity/statusGet the status of this REST Resource
V1SshApiPubkeyGet /v1/ssh/{ca_name}/pubkeyRetrieves a CA's public key in SSH format.
V1SshApiStatus8Get /v1/ssh/statusGet the status of this REST Resource
V2CertificateApiGetCertificateProfileInfoGet /v2/certificate/profile/{profile_name}Get Certificate Profile Info.
V2CertificateApiSearchCertificates1Post /v2/certificate/searchSearches for certificates confirming given criteria and pagination.
V2CertificateApiStatus3Get /v2/certificate/statusGet the status of this REST Resource
V2EndentityApiGetAuthorizedEndEntityProfilesGet /v2/endentity/profiles/authorizedList of authorized end entity profiles for the current admin.
V2EndentityApiProfileGet /v2/endentity/profile/{endentity_profile_name}Get End Entity Profile content
V2EndentityApiSortedSearchPost /v2/endentity/searchSearches and sorts for end entity conforming given criteria.
V2EndentityApiStatus7Get /v2/endentity/statusGet the status of this REST Resource

Documentation For Models

Application Notes

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

# Packages

No description provided by the author