11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

*.lvh.meでSSL

Last updated at Posted at 2018-08-18

オレオレ証明書を作る

mkdir ssl
cd ssl
openssl req \
-newkey rsa:4096 \
-keyout lvh.me.key \
-x509 \
-nodes \
-new \
-out lvh.me.crt \
-subj "/CN=*.lvh.me" \
-reqexts SAN \
-extensions SAN \
-config <(cat /System/Library/OpenSSL/openssl.cnf \
<(printf '[SAN]\nsubjectAltName=DNS:lvh.me,DNS:*.lvh.me')) \
-sha256 \
-days 3650

キーチェーンに登録する

1. 作成したlvh.me.crtを開く

open lvh.me.crt

2. キーチェーンアクセスで該当の証明書を選択しコンテキストメニューで「情報を見る」をクリック

3. 「:arrow_forward: 信頼」を開く

4. 「この証明書を使用するとき」を「常に信頼」へ変更

5. 開いているダイアログを閉じて、「証明書信頼設定に変更を加えようとしています。」で許可する。

サンプルコード

main.go
package main

import (
	"fmt"
	"net/http"
)

type myHandler struct{}

func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Hello World!")
}

func main() {
	handler := &myHandler{}
	server := http.Server{
		Addr:    "127.0.0.1:8080",
		Handler: handler,
	}

	println(fmt.Sprintf("Listening on tcp://%s", server.Addr))
	server.ListenAndServeTLS("./ssl/lvh.me.crt", "./ssl/lvh.me.key")
}
go run ./main.go
Listening on tcp://127.0.0.1:8080

別コンソールで

open https://www.lvh.me:8080

ワイルドカードの自己証明書なので、https://hoge.lvh.me:8080などでもよい。

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?