hancock

Check-in [6dd83bb80a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:cmd/hancock-sign: changed default key location also documentation tweaks
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6dd83bb80a6b67503a8c2d35e5b01a1017b0516fc497eb095e12555e7c9e5ee2
User & Date: dnc 2020-03-02 02:04:37
Context
2020-03-02
02:05
cmd/hancock: documentation edits check-in: b5d9be6c75 user: dnc tags: trunk
02:04
cmd/hancock-sign: changed default key location also documentation tweaks check-in: 6dd83bb80a user: dnc tags: trunk
02:03
cmd/hancock: encode manifest with newlines and tabs check-in: 7fa912b1c1 user: dnc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to cmd/hancock-sign/README.md.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## Usage

Example:

    hancock-sign [-private /path/to/private/key]

Optional parameter "-private" specifies the signing key (default
"~/.ssh/id_25519")

Currently, the only supported private key format is that produced by
`ssh-keygen -t ed25519`. For example, to produce a key in the default
location expected by hancock-sign:

    ssh-keygen -t ed25519 -N  -f ~/.ssh/id_ed25519

## User Configuration

Note that users of `hancock verify` configure your key as a signing
authority by including it in "~/.config/hancock/hancock.cfg" under the
[authority] section. For example:

    [authority]
        acme corp = ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBwXgvPPq9NEACJ6eGrckPxN2DXMDDBAYggmohpI+tQW

The format of the public key value must be as `ssh-keygen` wrote in
"~/.ssh/id_ed25519.pub".

By David N. Cohen, see source code for open source license terms (AGPL 3)








|





|










|
|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## Usage

Example:

    hancock-sign [-private /path/to/private/key]

Optional parameter "-private" specifies the signing key (default
"~/.config/hancock/id_25519")

Currently, the only supported private key format is that produced by
`ssh-keygen -t ed25519`. For example, to produce a key in the default
location expected by hancock-sign:

    ssh-keygen -t ed25519 -N '' -f ~/.config/hancock/id_ed25519

## User Configuration

Note that users of `hancock verify` configure your key as a signing
authority by including it in "~/.config/hancock/hancock.cfg" under the
[authority] section. For example:

    [authority]
        acme corp = ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBwXgvPPq9NEACJ6eGrckPxN2DXMDDBAYggmohpI+tQW

The format of the public key value must be as `ssh-keygen` created in
"~/.config/hancock/id_ed25519.pub".

By David N. Cohen, see source code for open source license terms (AGPL 3)

Changes to cmd/hancock-sign/hancock-sign.go.

9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108



109
110
111
112
113
114
115
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
155
156
157
158
159
160
161
162
163
164
165
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.



// The hancock-sign tool produces cryptographic signatures of file
// manifests.  Signed manifests are referred to as testimony.
//
// hancock-sign expects as input the output of `hancock manifest`, and
// produces output in the format expected by `hancock testimony`.
//
// The commands may be executed in a pipeline:
//
//    hancock manifest <source file> | hancock-sign | hancock testimony
//
// See https://src.d10.dev/hancock/cmd/hancock/ for more.
//
// Usage
//
// Example:
//
//     hancock-sign [-private /path/to/private/key]
//
// Optional parameter "-private" specifies the signing key (default "~/.ssh/id_25519")
//
// Currently, the only supported private key format is that produced
// by `ssh-keygen -t ed25519`.  For example, to produce a key in the
// default location expected by hancock-sign:
//
//     ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519
//
// User Configuration
//
// Note that users of `hancock verify` configure your key as a signing
// authority by including it in "~/.config/hancock/hancock.cfg" under
// the [authority] section.  For example:
//
//    [authority]
//        acme corp = ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBwXgvPPq9NEACJ6eGrckPxN2DXMDDBAYggmohpI+tQW
//
// The format of the public key value must be as `ssh-keygen` wrote in
// "~/.ssh/id_ed25519.pub".
//
// By David N. Cohen, see source code for open source license terms (AGPL 3)
package main

//go:generate sh -c "go doc | dumbdown > README.md"

import (
................................................................................
	} else {
		homeDir = usr.HomeDir
	}
	if homeDir == "" {
		homeDir = filepath.Join("", "var", "hancock")
	}

	privateFlag := flag.CommandLine.String("private", filepath.Join(homeDir, ".ssh", "id_ed25519"), "path to secret key file")
	numFlag := flag.CommandLine.Uint("n", 0, "how many json objects to sign, use 0 for no limit")

	err := flag.CommandLine.Parse(os.Args[1:])
	if err != nil {
		fmt.Println(err)
		flag.CommandLine.Usage()
		os.Exit(2)
	}

	// Load key in ssh format
	// TODO lock memory
	buffer, err := ioutil.ReadFile(*privateFlag)
	check(err)




	key, err := ssh.ParsePrivateKey(buffer)
	if err != nil {
		fmt.Printf("Failed to parse private key (%s): %s\n", *privateFlag, err)
		os.Exit(1)
	}

................................................................................
	public := key.PublicKey()
	out, err := json.MarshalIndent(strings.TrimSpace(string(ssh.MarshalAuthorizedKey(public))), "", "\t") // MarshalAuthorizedKey is a simple string, not a data structure
	check(err)
	_, err = os.Stdout.Write(out)
	fmt.Println("") // line break

	// We sign what is piped into stdin
	// Old way, sign everything (does not need to be json)
	//in, err := ioutil.ReadAll(os.Stdin)

	// new way, sign any number of json objects independently
	dec := json.NewDecoder(os.Stdin)
	var raw json.RawMessage
	i := uint(0)
	for *numFlag == 0 || i < *numFlag {
		err = dec.Decode(&raw)
		if err == io.EOF {
			break
................................................................................
	// too verbose?
	log.Printf("signed %d items with key %q", i, *privateFlag)
}

func check(err error) {
	if err != nil {
		fmt.Println(err)
		log.Panic(err) // debug, stack trace
		os.Exit(1)
	}
}







>
>

|








<







|





|










|
|







 







|












|
>
>
>







 







|
<

<







 







|



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
121
122
123
124
125
126
127
128

129

130
131
132
133
134
135
136
...
157
158
159
160
161
162
163
164
165
166
167
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

// Hancock-Sign
//
// The hancock-sign tool produces cryptographic signatures of file
// manifests.  Signed manifests are better known as testimony.
//
// hancock-sign expects as input the output of `hancock manifest`, and
// produces output in the format expected by `hancock testimony`.
//
// The commands may be executed in a pipeline:
//
//    hancock manifest <source file> | hancock-sign | hancock testimony
//

//
// Usage
//
// Example:
//
//     hancock-sign [-private /path/to/private/key]
//
// Optional parameter "-private" specifies the signing key (default "~/.config/hancock/id_25519")
//
// Currently, the only supported private key format is that produced
// by `ssh-keygen -t ed25519`.  For example, to produce a key in the
// default location expected by hancock-sign:
//
//     ssh-keygen -t ed25519 -N '' -f ~/.config/hancock/id_ed25519
//
// User Configuration
//
// Note that users of `hancock verify` configure your key as a signing
// authority by including it in "~/.config/hancock/hancock.cfg" under
// the [authority] section.  For example:
//
//    [authority]
//        acme corp = ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBwXgvPPq9NEACJ6eGrckPxN2DXMDDBAYggmohpI+tQW
//
// The format of the public key value must be as `ssh-keygen` created in
// "~/.config/hancock/id_ed25519.pub".
//
// By David N. Cohen, see source code for open source license terms (AGPL 3)
package main

//go:generate sh -c "go doc | dumbdown > README.md"

import (
................................................................................
	} else {
		homeDir = usr.HomeDir
	}
	if homeDir == "" {
		homeDir = filepath.Join("", "var", "hancock")
	}

	privateFlag := flag.CommandLine.String("private", filepath.Join(homeDir, ".config", "hancock", "id_ed25519"), "path to secret key file")
	numFlag := flag.CommandLine.Uint("n", 0, "how many json objects to sign, use 0 for no limit")

	err := flag.CommandLine.Parse(os.Args[1:])
	if err != nil {
		fmt.Println(err)
		flag.CommandLine.Usage()
		os.Exit(2)
	}

	// Load key in ssh format
	// TODO lock memory
	buffer, err := ioutil.ReadFile(*privateFlag)
	if err != nil {
		fmt.Printf("no private key (%q): %w", *privateFlag, err)
		os.Exit(1)
	}

	key, err := ssh.ParsePrivateKey(buffer)
	if err != nil {
		fmt.Printf("Failed to parse private key (%s): %s\n", *privateFlag, err)
		os.Exit(1)
	}

................................................................................
	public := key.PublicKey()
	out, err := json.MarshalIndent(strings.TrimSpace(string(ssh.MarshalAuthorizedKey(public))), "", "\t") // MarshalAuthorizedKey is a simple string, not a data structure
	check(err)
	_, err = os.Stdout.Write(out)
	fmt.Println("") // line break

	// We sign what is piped into stdin
	// JSON-encoded objects are expected.



	dec := json.NewDecoder(os.Stdin)
	var raw json.RawMessage
	i := uint(0)
	for *numFlag == 0 || i < *numFlag {
		err = dec.Decode(&raw)
		if err == io.EOF {
			break
................................................................................
	// too verbose?
	log.Printf("signed %d items with key %q", i, *privateFlag)
}

func check(err error) {
	if err != nil {
		fmt.Println(err)
		//log.Panic(err) // debug, uncomment for stack trace
		os.Exit(1)
	}
}