Beispiel #1
0
func (g *GenKey) Export() (err error) {
	id, err := GetId()
	if err != nil {
		return
	}

	data, err := utils.ExecOutput(g.Root,
		"gpg", "-a", "--export-secret-keys", id)
	if err != nil {
		return
	}

	err = utils.CreateWrite(filepath.Join(g.Root, "sign.key"), data)
	if err != nil {
		return
	}

	data, err = utils.ExecOutput(g.Root,
		"gpg", "-a", "--export", id)
	if err != nil {
		return
	}

	err = utils.CreateWrite(filepath.Join(g.Root, "sign.pub"), data)
	if err != nil {
		return
	}

	return
}
Beispiel #2
0
func GetName() (name string, err error) {
	output, err := utils.ExecOutput("", "gpg", "--list-keys")
	if err != nil {
		return
	}

	for _, line := range strings.Split(output, "\n") {
		if !strings.HasPrefix(line, "uid") {
			continue
		}

		index := strings.Index(line, "]")
		if index == -1 {
			fields := strings.Fields(line)
			if len(fields) < 2 {
				continue
			}

			name = strings.Join(fields[1:], " ")
		} else {
			name = strings.TrimSpace(line[index+1:])
		}

		return
	}

	err = &LookupError{
		errors.New("signing: Failed to find gpg name"),
	}
	return
}
Beispiel #3
0
func (d *Debian) getSums() (err error) {
	output, err := utils.ExecOutput(d.Pack.PackageDir, "find", ".",
		"-type", "f", "-exec", "md5sum", "{}", ";")
	if err != nil {
		return
	}

	d.sums = ""
	for _, line := range strings.Split(output, "\n") {
		d.sums += strings.Replace(line, "./", "", 1) + "\n"
	}

	return
}
Beispiel #4
0
func (r *Redhat) getFiles() (files []string, err error) {
	backup := set.NewSet()
	paths := set.NewSet()

	for _, path := range r.Pack.Backup {
		if !strings.HasPrefix(path, "/") {
			path = "/" + path
		}
		backup.Add(path)
	}

	rpmPath, err := r.getRpmPath()
	if err != nil {
		return
	}

	output, err := utils.ExecOutput(r.Pack.PackageDir, "rpm", "-qlp", rpmPath)
	if err != nil {
		return
	}

	for _, path := range strings.Split(output, "\n") {
		if len(path) < 1 {
			continue
		}

		paths.Remove(filepath.Dir(path))
		paths.Add(path)
	}

	for pathInf := range paths.Iter() {
		path := pathInf.(string)

		if backup.Contains(path) {
			path = `%config "` + path + `"`
		} else {
			path = `"` + path + `"`
		}

		files = append(files, path)
	}

	return
}
Beispiel #5
0
func GetId() (id string, err error) {
	output, err := utils.ExecOutput("", "gpg", "--list-keys")
	if err != nil {
		return
	}

	hasKey := false
	for _, line := range strings.Split(output, "\n") {
		if hasKey {
			id = strings.TrimSpace(line)
			break
		}

		if !strings.HasPrefix(line, "pub") {
			continue
		}

		if !strings.Contains(line, "/") {
			hasKey = true
			continue
		}

		fields := strings.Fields(line)
		if len(fields) < 2 {
			continue
		}

		split := strings.Split(fields[1], "/")
		if len(split) < 2 {
			continue
		}

		id = split[1]
		break
	}

	if id == "" {
		err = &LookupError{
			errors.New("signing: Failed to find gpg id"),
		}
	}
	return
}