Git Product home page Git Product logo

go-mtls's Introduction

mTLS example in Go

What is mutual TLS (mTLS)?

mTLS, short for Mutual Transport Layer Security, is a form of bi-directional security between two services where the TLS protocol is applied in both directions. The difference between mTLS and the standard form of browser HTTPS is, when you try to access an HTTPS/TLS endpoint, the client attempts to verify the presented certificate from the server, but in mTLS, the verification process is done by both the client and server for the corresponding other side of the connection.

Generate CA, Server and Client key/certificate

openssl genrsa -out ca.key 4096
openssl req -new -x509 -days 3650 -key ca.key -subj "/C=TH/ST=RB/O=IT Sec/CN=CA" -out ca.crt

openssl req -newkey rsa:4096 -nodes -keyout server.key -subj "/C=TH/ST=RB/O=Dev/CN=localhost" -out server.csr
openssl x509 -req -extfile <(printf "subjectAltName=DNS:localhost,DNS:www.example.com,IP.1:127.0.0.1") -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
openssl req -text -noout -in server.csr
openssl req -text -noout -verify -in server.csr
openssl x509 -text -noout -in server.crt
openssl genrsa -out client.key 4096
openssl req -new -key client.key -out client.csr -subj "/C=TH/ST=RB/O=Dev/CN=client"
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -out client.crt -days 365 -sha256 -CAcreateserial

Test

go run server/server.go

2021/12/05 23:36:03 listen on https://localhost:8443
2021/12/05 23:38:58 new request
go run client/client.go

hello world

Notes

go-mtls's People

Contributors

junlapong avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.