예제 #1
0
func (c *ClientKeyManager) loadKeys() error {
	// Load authorized keys file
	var clients []libtrust.PublicKey
	if c.clientFile != "" {
		fileClients, err := libtrust.LoadKeySetFile(c.clientFile)
		if err != nil {
			return fmt.Errorf("unable to load authorized keys: %s", err)
		}
		clients = fileClients
	}

	// Add clients from authorized keys directory
	files, err := ioutil.ReadDir(c.clientDir)
	if err != nil && !os.IsNotExist(err) {
		return fmt.Errorf("unable to open authorized keys directory: %s", err)
	}
	for _, f := range files {
		if !f.IsDir() {
			publicKey, err := libtrust.LoadPublicKeyFile(path.Join(c.clientDir, f.Name()))
			if err != nil {
				return fmt.Errorf("unable to load authorized key file: %s", err)
			}
			clients = append(clients, publicKey)
		}
	}

	c.clientLock.Lock()
	c.clients = clients
	c.clientLock.Unlock()

	return nil
}
예제 #2
0
func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "Usage: kid_generator <public_key>\n")
		os.Exit(1)
	}
	fmt.Println(os.Args)

	public_key, err := libtrust.LoadPublicKeyFile(os.Args[1])

	if err != nil {
		fmt.Fprintf(os.Stderr, "Something went wrong while reading %s: %v\n", os.Args[1], err)
		os.Exit(1)
	}

	fmt.Println("The KeyID of Public Key is:", public_key.KeyID())
}