MCPcopy Create free account
hub / github.com/crewjam/saml / newKeyPair

Function newKeyPair

example/service.go:199–220  ·  view source on GitHub ↗

newKeyPair returns a freshly generated RSA key and a matching self-signed certificate. The example uses a throwaway key so that it never ships a private key or a certificate that can expire.

()

Source from the content-addressed store, hash-verified

197// certificate. The example uses a throwaway key so that it never ships a
198// private key or a certificate that can expire.
199func newKeyPair() (*rsa.PrivateKey, *x509.Certificate, error) {
200 key, err := rsa.GenerateKey(rand.Reader, 2048)
201 if err != nil {
202 return nil, nil, err
203 }
204 template := &x509.Certificate{
205 SerialNumber: big.NewInt(1),
206 Subject: pkix.Name{CommonName: "example service"},
207 NotBefore: time.Now().Add(-time.Hour),
208 NotAfter: time.Now().Add(365 * 24 * time.Hour),
209 KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
210 }
211 der, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
212 if err != nil {
213 return nil, nil, err
214 }
215 cert, err := x509.ParseCertificate(der)
216 if err != nil {
217 return nil, nil, err
218 }
219 return key, cert, nil
220}
221
222func main() {
223 rootURLstr := flag.String("url", "http://localhost:8000", "The base URL of this service")

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected