Go to file
Urko ee967277d4 feat: handle key encrypted looking at headers too 2023-04-15 20:42:33 +02:00
pkg/credentials feat: handle key encrypted looking at headers too 2023-04-15 20:42:33 +02:00
.gitignore feat: add .gitignore 2023-03-06 16:13:47 +01:00
LICENSE feat: add license 2023-03-06 16:13:56 +01:00
Makefile feat: add Makefile 2023-03-06 16:13:25 +01:00
README.md feat: add readme 2023-03-06 18:00:40 +01:00
go.mod fix mod typo 2023-03-06 16:37:57 +01:00
go.sum feat: get grpc credentials by certificate from key with password 2023-03-06 16:14:50 +01:00

README.md

go-grpc-certificate

Problem's context

I've got some trouble while I want to use gRPC through TLS certificates. I've created a certificated from a .pem key file which had a password and I couldn't use it through go standard library. I found a solution based on this SO answer to this question

Solution

I've decided to use openssl to achieve this task as far as I was not able to found a solution in go standard library.

Installation requirements

I've used this version on development. So we should check if it backwards compatible.

$ openssl version
OpenSSL 3.0.8 7 Feb 2023 (Library: OpenSSL 3.0.8 7 Feb 2023)

How to use

In your go project you just have to type in your terminal:

$ go get gitea.urkob.com/urko/go-grpc-certificate

Then place in your code like this

package main

// here should be defined your imports
certcreds "gitea.urkob.com/urko/go-grpc-certificate/pkg/credentials"


func main() {
    certPath := "place your certificate path"
    certKeyPath := "place your key file path"
    keyPassword := "place your key password here"

    creds, err = certcreds.CredentialsFromKeyWithPasswd(
        certPah, certKeyPath, keyPassword,
    )
    if err != nil {
        log.Fatalf("Failed loading certificates: %v\n", err)
    }
}