-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,014 additions
and
1,327 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/segmentio/ksuid" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
//=========================================================================== | ||
// Admin Functions | ||
//=========================================================================== | ||
|
||
func generateTokenKey(c *cli.Context) (err error) { | ||
// Create ksuid and determine outpath | ||
var keyid ksuid.KSUID | ||
if keyid, err = ksuid.NewRandom(); err != nil { | ||
return cli.Exit(err, 1) | ||
} | ||
|
||
var out string | ||
if out = c.String("out"); out == "" { | ||
out = fmt.Sprintf("%s.pem", keyid) | ||
} | ||
|
||
// Generate RSA keys using crypto random | ||
var key *rsa.PrivateKey | ||
if key, err = rsa.GenerateKey(rand.Reader, c.Int("size")); err != nil { | ||
return cli.Exit(err, 1) | ||
} | ||
|
||
// Open file to PEM encode keys to | ||
var f *os.File | ||
if f, err = os.OpenFile(out, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600); err != nil { | ||
return cli.Exit(err, 1) | ||
} | ||
|
||
if err = pem.Encode(f, &pem.Block{ | ||
Type: "RSA PRIVATE KEY", | ||
Bytes: x509.MarshalPKCS1PrivateKey(key), | ||
}); err != nil { | ||
return cli.Exit(err, 1) | ||
} | ||
|
||
fmt.Printf("RSA key id: %s -- saved with PEM encoding to %s\n", keyid, out) | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.