Go
Available Libraries
There are two Go implementations of OHTTP:
cloudflare/circl (Recommended)
Part of Cloudflare’s cryptographic library with OHTTP support.
go get github.com/cloudflare/circl/hpke
chris-wood/ohttp-go
Standalone OHTTP implementation.
go get github.com/chris-wood/ohttp-go
Client Example (ohttp-go)
package main
import (
"github.com/chris-wood/ohttp-go"
)
func main() {
// Parse gateway's key configuration
keyConfig, err := ohttp.ParseKeyConfig(keyBytes)
if err != nil {
panic(err)
}
// Create client
client := ohttp.NewClient(keyConfig)
// Encapsulate request
encRequest, context, err := client.Encapsulate(requestBytes)
if err != nil {
panic(err)
}
// Send through relay and get response...
encResponse := sendToRelay(encRequest)
// Decapsulate response
response, err := context.Decapsulate(encResponse)
if err != nil {
panic(err)
}
}
Server Example
package main
import (
"github.com/chris-wood/ohttp-go"
)
func main() {
// Generate or load key configuration
keyConfig, err := ohttp.GenerateKeyConfig(keyID, kemID, kdfID, aeadID)
if err != nil {
panic(err)
}
// Create server
server := ohttp.NewServer(keyConfig)
// Handle incoming request
request, context, err := server.Decapsulate(encRequest)
if err != nil {
panic(err)
}
// Process and respond
response := processRequest(request)
encResponse, err := context.Encapsulate(response)
if err != nil {
panic(err)
}
}