summaryrefslogtreecommitdiff
path: root/package/system/opkg/files/opkg-key
blob: ae5e8a4591078764352ae766000f92e8230265fb (plain)
1
2
3
4
5
6
7
8
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
#!/bin/sh

usage() {
	cat <<EOF
Usage: $0 <command> <arguments...>
Commands:
  add <file>:			Add keyfile <file> to opkg trusted keys
  remove <file>:		Remove keyfile matching <file> from opkg trusted keys
  verify <sigfile> <list>:	Check list file <list> against signature file <sigfile>

EOF
	exit 1
}

opkg_key_verify() {
	local sigfile="$1"
	local msgfile="$2"

	(
		zcat "$msgfile" 2>/dev/null ||
		cat "$msgfile" 2>/dev/null
	) | usign -V -P /etc/opkg/keys -q -x "$sigfile" -m -
}

opkg_key_add() {
	local key="$1"
	[ -n "$key" ] || usage
	[ -f "$key" ] || echo "Cannot open file $1"
	local fingerprint="$(usign -F -p "$key")"
	mkdir -p "/etc/opkg/keys"
	cp "$key" "/etc/opkg/keys/$fingerprint"
}

opkg_key_remove() {
	local key="$1"
	[ -n "$key" ] || usage
	[ -f "$key" ] || echo "Cannot open file $1"
	local fingerprint="$(usign -F -p "$key")"
	rm -f "/etc/opkg/keys/$fingerprint"
}

case "$1" in
	add)
		shift
		opkg_key_add "$@"
		;;
	remove)
		shift
		opkg_key_remove "$@"
		;;
	verify)
		shift
		opkg_key_verify "$@"
		;;
	*) usage ;;
esac