tls.go 587 B

123456789101112131415161718192021222324
  1. // Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
  2. // Use of this source code is governed by an MIT-style license that can be
  3. // found in the LICENSE file.
  4. package main
  5. import (
  6. "crypto/sha256"
  7. "crypto/tls"
  8. "encoding/base32"
  9. "path/filepath"
  10. "strings"
  11. )
  12. func loadCert(dir string) (tls.Certificate, error) {
  13. return tls.LoadX509KeyPair(filepath.Join(dir, "cert.pem"), filepath.Join(dir, "key.pem"))
  14. }
  15. func certID(bs []byte) string {
  16. hf := sha256.New()
  17. hf.Write(bs)
  18. id := hf.Sum(nil)
  19. return strings.Trim(base32.StdEncoding.EncodeToString(id), "=")
  20. }