func moveKeys(oldKeyStore, newKeyStore *trustmanager.KeyFileStore) error {
	// List all files but no symlinks
	for f := range oldKeyStore.ListKeys() {
		privateKey, alias, err := oldKeyStore.GetKey(f)
		if err != nil {
			return err
		}

		err = newKeyStore.AddKey(f, alias, privateKey)

		if err != nil {
			return err
		}
	}

	// Recreate symlinks
	for _, relKeyPath := range oldKeyStore.ListFiles(true) {
		fullKeyPath := filepath.Join(oldKeyStore.BaseDir(), relKeyPath)

		fi, err := os.Lstat(fullKeyPath)
		if err != nil {
			return err
		}

		if (fi.Mode() & os.ModeSymlink) != 0 {
			target, err := os.Readlink(fullKeyPath)
			if err != nil {
				return err
			}
			os.Symlink(target, filepath.Join(newKeyStore.BaseDir(), relKeyPath))
		}
	}

	return nil
}
Beispiel #2
0
func moveKeys(oldKeyStore, newKeyStore *trustmanager.KeyFileStore) error {
	for f := range oldKeyStore.ListKeys() {
		privateKey, alias, err := oldKeyStore.GetKey(f)
		if err != nil {
			return err
		}

		err = newKeyStore.AddKey(f, alias, privateKey)

		if err != nil {
			return err
		}
	}

	return nil
}
Beispiel #3
0
func moveKeys(oldKeyStore, newKeyStore *trustmanager.KeyFileStore) error {
	// List all files but no symlinks
	for _, f := range oldKeyStore.ListKeys() {
		pemBytes, alias, err := oldKeyStore.GetKey(f)
		if err != nil {
			return err
		}

		err = newKeyStore.AddKey(f, alias, pemBytes)

		if err != nil {
			return err
		}
	}

	return nil
}
Beispiel #4
0
func moveKeysByGUN(oldKeyStore, newKeyStore *trustmanager.KeyFileStore, gun string) error {
	for relKeyPath := range oldKeyStore.ListKeys() {
		// Skip keys that aren't associated with this GUN
		if !strings.HasPrefix(relKeyPath, filepath.FromSlash(gun)) {
			continue
		}

		privKey, alias, err := oldKeyStore.GetKey(relKeyPath)
		if err != nil {
			return err
		}

		err = newKeyStore.AddKey(relKeyPath, alias, privKey)
		if err != nil {
			return err
		}
	}

	return nil
}