github.com/blend/go-sdk@v1.20220411.3/examples/certutil/selfsigned/main.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"log"
    12  	"os"
    13  	"time"
    14  
    15  	"github.com/blend/go-sdk/certutil"
    16  )
    17  
    18  func main() {
    19  	ca, err := certutil.CreateCertificateAuthority(
    20  		certutil.OptSubjectOrganization("go-sdk"),
    21  		certutil.OptNotAfter(time.Now().UTC().AddDate(0, 0, 30)),
    22  	)
    23  	if err != nil {
    24  		log.Fatal(err)
    25  	}
    26  
    27  	server, err := certutil.CreateServer(
    28  		"dev.local", ca,
    29  		certutil.OptSubjectOrganization("go-sdk users"),
    30  		certutil.OptNotAfter(time.Now().UTC().AddDate(0, 0, 15)),
    31  	)
    32  	if err != nil {
    33  		log.Fatal(err)
    34  	}
    35  
    36  	err = server.WriteCertPem(os.Stdout)
    37  	if err != nil {
    38  		log.Fatal(err)
    39  	}
    40  
    41  	err = server.WriteKeyPem(os.Stderr)
    42  	if err != nil {
    43  		log.Fatal(err)
    44  	}
    45  }