-
Notifications
You must be signed in to change notification settings - Fork 1
/
boot_signer
executable file
·63 lines (54 loc) · 2.23 KB
/
boot_signer
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
57
58
59
60
61
62
63
#!/usr/bin/env python
# Copyright © 2018 Playground Global, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import requests
import sys
import urllib
WARDEN_HOST = os.environ.get("WARDEN_HOST", "localhost")
WARDEN_PORT = os.environ.get("WARDEN_PORT", 9000)
WARDEN_PRODUCT = os.environ.get("WARDEN_PRODUCT")
WARDEN_KEYSET = os.environ.get("WARDEN_KEYSET", "dev")
WARDEN_CLIENT_CERT = os.environ.get("WARDEN_CLIENT_CERT", "./client.crt")
WARDEN_CLIENT_KEY = os.environ.get("WARDEN_CLIENT_KEY", "./client.key")
WARDEN_SERVER_CERT = os.environ.get("WARDEN_SERVER_CERT")
if not WARDEN_PRODUCT:
print >> sys.stderr, "required ${WARDEN_PRODUCT} environment variable not found"
raise SystemExit(1)
if not WARDEN_SERVER_CERT:
print >> sys.stderr, "required ${WARDEN_SERVER_CERT} environment variable not found"
raise SystemExit(1)
if len(sys.argv) < 4:
print >> sys.stderr, "usage: %s <target> <input> <key> <cert> <output>" % (sys.argv[0],)
raise SystemExit(2)
target = urllib.quote(sys.argv[1])
URL = "https://%s:%s/sign/%s-%s-boot?target=%s" % (WARDEN_HOST, WARDEN_PORT, WARDEN_PRODUCT, WARDEN_KEYSET, target)
try:
data = file(sys.argv[2]).read()
except Exception, err:
print >> sys.stderr, "error reading input file", err
raise SystemExit(3)
try:
resp = requests.post(URL, cert=(WARDEN_CLIENT_CERT, WARDEN_CLIENT_KEY), data=data, verify=WARDEN_SERVER_CERT)
if resp.status_code != 200:
print >> sys.stderr, "server returned error: %s" % (resp.status_code,)
raise SystemExit(4)
except Exception, err:
print >> sys.stderr, "error communicating with server", err
raise SystemExit(5)
try:
file(sys.argv[5], 'w').write(resp.content)
except Exception, err:
print >> sys.stderr, "error writing server output", err
raise SystemExit(6)