forked from diafygi/acme-nosudo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsign_csr.py
executable file
·498 lines (455 loc) · 20.9 KB
/
sign_csr.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/usr/bin/env python
import argparse, subprocess, json, os, urllib2, sys, base64, binascii, ssl, \
hashlib, tempfile, re, time, copy, textwrap
from threading import Thread
from BaseHTTPServer import HTTPServer,BaseHTTPRequestHandler
def sign_csr(pubkey, csr, privkey, email=None, automatized=False):
"""Use the ACME protocol to get an ssl certificate signed by a
certificate authority.
:param string pubkey: Path to the user account public key.
:param string csr: Path to the certificate signing request.
:param string email: An optional user account contact email
(defaults to webmaster@<shortest_domain>)
:returns: Signed Certificate (PEM format)
:rtype: string
"""
#CA = "https://acme-staging.api.letsencrypt.org"
CA = "https://acme-v01.api.letsencrypt.org"
TERMS = "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf"
nonce_req = urllib2.Request("{}/directory".format(CA))
nonce_req.get_method = lambda : 'HEAD'
def _b64(b):
"Shortcut function to go from bytes to jwt base64 string"
return base64.urlsafe_b64encode(b).replace("=", "")
# Step 1: Get account public key
sys.stderr.write("Reading pubkey file...\n")
proc = subprocess.Popen(["openssl", "rsa", "-pubin", "-in", pubkey, "-noout", "-text"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if proc.returncode != 0:
raise IOError("Error loading {}".format(pubkey))
pub_hex, pub_exp = re.search(
"Modulus(?: \((?:2048|4096) bit\)|)\:\s+00:([a-f0-9\:\s]+?)Exponent\: ([0-9]+)",
out, re.MULTILINE|re.DOTALL).groups()
pub_mod = binascii.unhexlify(re.sub("(\s|:)", "", pub_hex))
pub_mod64 = _b64(pub_mod)
pub_exp = int(pub_exp)
pub_exp = "{0:x}".format(pub_exp)
pub_exp = "0{}".format(pub_exp) if len(pub_exp) % 2 else pub_exp
pub_exp = binascii.unhexlify(pub_exp)
pub_exp64 = _b64(pub_exp)
header = {
"alg": "RS256",
"jwk": {
"e": pub_exp64,
"kty": "RSA",
"n": pub_mod64,
},
}
accountkey_json = json.dumps(header['jwk'], sort_keys=True, separators=(',', ':'))
thumbprint = _b64(hashlib.sha256(accountkey_json).digest())
sys.stderr.write("Found public key!\n")
# Step 2: Get the domain names to be certified
sys.stderr.write("Reading csr file...\n")
proc = subprocess.Popen(["openssl", "req", "-in", csr, "-noout", "-text"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if proc.returncode != 0:
raise IOError("Error loading {}".format(csr))
domains = set([])
common_name = re.search("Subject:.*? CN=([^\s,;/]+)", out)
if common_name is not None:
domains.add(common_name.group(1))
subject_alt_names = re.search("X509v3 Subject Alternative Name: \n +([^\n]+)\n", out, re.MULTILINE|re.DOTALL)
if subject_alt_names is not None:
for san in subject_alt_names.group(1).split(", "):
if san.startswith("DNS:"):
domains.add(san[4:])
sys.stderr.write("Found domains {}\n".format(", ".join(domains)))
# Step 3: Ask user for contact email
if not email:
default_email = "webmaster@{}".format(min(domains, key=len))
stdout = sys.stdout
sys.stdout = sys.stderr
if automatized:
email=default_email
else:
input_email = raw_input("STEP 1: What is your contact email? ({}) ".format(default_email))
email = input_email if input_email else default_email
sys.stdout = stdout
# Step 4: Generate the payloads that need to be signed
# registration
sys.stderr.write("Building request payloads...\n")
reg_nonce = urllib2.urlopen(nonce_req).headers['Replay-Nonce']
reg_raw = json.dumps({
"resource": "new-reg",
"contact": ["mailto:{}".format(email)],
"agreement": TERMS,
}, sort_keys=True, indent=4)
reg_b64 = _b64(reg_raw)
reg_protected = copy.deepcopy(header)
reg_protected.update({"nonce": reg_nonce})
reg_protected64 = _b64(json.dumps(reg_protected, sort_keys=True, indent=4))
reg_file = tempfile.NamedTemporaryFile(dir=".", prefix="register_", suffix=".json")
reg_file.write("{}.{}".format(reg_protected64, reg_b64))
reg_file.flush()
reg_file_name = os.path.basename(reg_file.name)
reg_file_sig = tempfile.NamedTemporaryFile(dir=".", prefix="register_", suffix=".sig")
reg_file_sig_name = os.path.basename(reg_file_sig.name)
# need signature for each domain identifiers
ids = []
for domain in domains:
sys.stderr.write("Building request for {}...\n".format(domain))
id_nonce = urllib2.urlopen(nonce_req).headers['Replay-Nonce']
id_raw = json.dumps({
"resource": "new-authz",
"identifier": {
"type": "dns",
"value": domain,
},
}, sort_keys=True)
id_b64 = _b64(id_raw)
id_protected = copy.deepcopy(header)
id_protected.update({"nonce": id_nonce})
id_protected64 = _b64(json.dumps(id_protected, sort_keys=True, indent=4))
id_file = tempfile.NamedTemporaryFile(dir=".", prefix="domain_", suffix=".json")
id_file.write("{}.{}".format(id_protected64, id_b64))
id_file.flush()
id_file_name = os.path.basename(id_file.name)
id_file_sig = tempfile.NamedTemporaryFile(dir=".", prefix="domain_", suffix=".sig")
id_file_sig_name = os.path.basename(id_file_sig.name)
ids.append({
"domain": domain,
"protected64": id_protected64,
"data64": id_b64,
"file": id_file,
"file_name": id_file_name,
"sig": id_file_sig,
"sig_name": id_file_sig_name,
})
# need signature for the final certificate issuance
sys.stderr.write("Building request for CSR...\n")
proc = subprocess.Popen(["openssl", "req", "-in", csr, "-outform", "DER"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
csr_der, err = proc.communicate()
csr_der64 = _b64(csr_der)
csr_nonce = urllib2.urlopen(nonce_req).headers['Replay-Nonce']
csr_raw = json.dumps({
"resource": "new-cert",
"csr": csr_der64,
}, sort_keys=True, indent=4)
csr_b64 = _b64(csr_raw)
csr_protected = copy.deepcopy(header)
csr_protected.update({"nonce": csr_nonce})
csr_protected64 = _b64(json.dumps(csr_protected, sort_keys=True, indent=4))
csr_file = tempfile.NamedTemporaryFile(dir=".", prefix="cert_", suffix=".json")
csr_file.write("{}.{}".format(csr_protected64, csr_b64))
csr_file.flush()
csr_file_name = os.path.basename(csr_file.name)
csr_file_sig = tempfile.NamedTemporaryFile(dir=".", prefix="cert_", suffix=".sig")
csr_file_sig_name = os.path.basename(csr_file_sig.name)
# Step 5: Ask the user to sign the registration and requests
privkey_path='user.key' if privkey==None else privkey # privkey can be None only if atomatized==True
sys.stderr.write("""\
STEP 2: You need to sign some files{}.
openssl dgst -sha256 -sign {} -out {} {}
{}
openssl dgst -sha256 -sign {} -out {} {}
""".format(
' (replace \'user.key\' with your user private key).' if not privkey else '',\
privkey_path,reg_file_sig_name, reg_file_name,
"\n".join("openssl dgst -sha256 -sign {} -out {} {}".format(privkey_path,i['sig_name'], i['file_name']) for i in ids),
privkey_path,csr_file_sig_name, csr_file_name))
stdout = sys.stdout
sys.stdout = sys.stderr
if automatized:
toSign=ids[:]
toSign.append({'sig_name':reg_file_sig_name,'file_name':reg_file_name})
toSign.append({'sig_name':csr_file_sig_name,'file_name':csr_file_name})
print 'Signing',len(toSign),'files.\n'
for i in toSign:
subprocess.Popen(['openssl','dgst','-sha256','-sign',privkey_path,'-out',i['sig_name'],i['file_name']],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
else:
raw_input("Press Enter when you've run the above commands in a new terminal window...")
sys.stdout = stdout
# Step 6: Load the signatures
reg_file_sig.seek(0)
reg_sig64 = _b64(reg_file_sig.read())
for n, i in enumerate(ids):
i['sig'].seek(0)
i['sig64'] = _b64(i['sig'].read())
# Step 7: Register the user
sys.stderr.write("Registering {}...\n".format(email))
reg_data = json.dumps({
"header": header,
"protected": reg_protected64,
"payload": reg_b64,
"signature": reg_sig64,
}, sort_keys=True, indent=4)
reg_url = "{}/acme/new-reg".format(CA)
try:
resp = urllib2.urlopen(reg_url, reg_data)
result = json.loads(resp.read())
except urllib2.HTTPError as e:
err = e.read()
# skip already registered accounts
if "Registration key is already in use" in err:
sys.stderr.write("Already registered. Skipping...\n")
else:
sys.stderr.write("Error: reg_data:\n")
sys.stderr.write("POST {}\n".format(reg_url))
sys.stderr.write(reg_data)
sys.stderr.write("\n")
sys.stderr.write(err)
sys.stderr.write("\n")
raise
# Step 8: Request challenges for each domain
responses = []
tests = []
for n, i in enumerate(ids):
sys.stderr.write("Requesting challenges for {}...\n".format(i['domain']))
id_data = json.dumps({
"header": header,
"protected": i['protected64'],
"payload": i['data64'],
"signature": i['sig64'],
}, sort_keys=True, indent=4)
id_url = "{}/acme/new-authz".format(CA)
try:
resp = urllib2.urlopen(id_url, id_data)
result = json.loads(resp.read())
except urllib2.HTTPError as e:
sys.stderr.write("Error: id_data:\n")
sys.stderr.write("POST {}\n".format(id_url))
sys.stderr.write(id_data)
sys.stderr.write("\n")
sys.stderr.write(e.read())
sys.stderr.write("\n")
raise
challenge = [c for c in result['challenges'] if c['type'] == "http-01"][0]
keyauthorization = "{}.{}".format(challenge['token'], thumbprint)
# challenge request
sys.stderr.write("Building challenge responses for {}...\n".format(i['domain']))
test_nonce = urllib2.urlopen(nonce_req).headers['Replay-Nonce']
test_raw = json.dumps({
"resource": "challenge",
"keyAuthorization": keyauthorization,
}, sort_keys=True, indent=4)
test_b64 = _b64(test_raw)
test_protected = copy.deepcopy(header)
test_protected.update({"nonce": test_nonce})
test_protected64 = _b64(json.dumps(test_protected, sort_keys=True, indent=4))
test_file = tempfile.NamedTemporaryFile(dir=".", prefix="challenge_", suffix=".json")
test_file.write("{}.{}".format(test_protected64, test_b64))
test_file.flush()
test_file_name = os.path.basename(test_file.name)
test_file_sig = tempfile.NamedTemporaryFile(dir=".", prefix="challenge_", suffix=".sig")
test_file_sig_name = os.path.basename(test_file_sig.name)
tests.append({
"uri": challenge['uri'],
"protected64": test_protected64,
"data64": test_b64,
"file": test_file,
"file_name": test_file_name,
"sig": test_file_sig,
"sig_name": test_file_sig_name,
})
# challenge response for server
responses.append({
"uri": ".well-known/acme-challenge/{}".format(challenge['token']),
"data": keyauthorization,
})
# Step 9: Ask the user to sign the challenge responses
sys.stderr.write("""\
STEP 3: You need to sign some more files{}.
{}
""".format(
' (replace \'user.key\' with your user private key).' if not privkey else '',\
"\n".join("openssl dgst -sha256 -sign {} -out {} {}".format(
privkey_path,i['sig_name'], i['file_name']) for i in tests)))
stdout = sys.stdout
sys.stdout = sys.stderr
if automatized:
print 'Signing',len(responses),'files.\n'
for i in tests:
subprocess.Popen(['openssl','dgst','-sha256','-sign',privkey_path,'-out',i['sig_name'],i['file_name']],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
else:
raw_input("Press Enter when you've run the above commands in a new terminal window...")
sys.stdout = stdout
# Step 10: Load the response signatures
for n, i in enumerate(ids):
tests[n]['sig'].seek(0)
tests[n]['sig64'] = _b64(tests[n]['sig'].read())
# Step 11: Ask the user to host the token on their server
for n, i in enumerate(ids):
sys.stderr.write("""\
STEP {}: You need to run this command on {} (don't stop the python command until the next step).
sudo python -c "import BaseHTTPServer; \\
h = BaseHTTPServer.BaseHTTPRequestHandler; \\
h.do_GET = lambda r: r.send_response(200) or r.end_headers() or r.wfile.write('{}'); \\
s = BaseHTTPServer.HTTPServer(('0.0.0.0', 80), h); \\
s.serve_forever()"
""".format(n+4, i['domain'], responses[n]['data']))
stdout = sys.stdout
sys.stdout = sys.stderr
if automatized:
print 'starting web server on port 80'
def httpd(token):
h=BaseHTTPRequestHandler
h.do_GET=lambda r: r.send_response(200) or r.end_headers() or r.wfile.write(token);
s=HTTPServer(('0.0.0.0',80),h);
s.handle_request()
t=Thread(target=httpd,args=(responses[n]['data'].replace('\\"','"'),))
t.start()
else:
raw_input("Press Enter when you've got the python command running on your server...")
sys.stdout = stdout
# Step 12: Let the CA know you're ready for the challenge
sys.stderr.write("\nRequesting verification for {}...\n".format(i['domain']))
test_data = json.dumps({
"header": header,
"protected": tests[n]['protected64'],
"payload": tests[n]['data64'],
"signature": tests[n]['sig64'],
}, sort_keys=True, indent=4)
test_url = tests[n]['uri']
try:
resp = urllib2.urlopen(test_url, test_data)
test_result = json.loads(resp.read())
except urllib2.HTTPError as e:
sys.stderr.write("Error: test_data:\n")
sys.stderr.write("POST {}\n".format(test_url))
sys.stderr.write(test_data)
sys.stderr.write("\n")
sys.stderr.write(e.read())
sys.stderr.write("\n")
raise
# Step 13: Wait for CA to mark test as valid
sys.stderr.write("Waiting for {} challenge to pass...\n".format(i['domain']))
while True:
try:
resp = urllib2.urlopen(test_url)
challenge_status = json.loads(resp.read())
except urllib2.HTTPError as e:
sys.stderr.write("Error: test_data:\n")
sys.stderr.write("GET {}\n".format(test_url))
sys.stderr.write(test_data)
sys.stderr.write("\n")
sys.stderr.write(e.read())
sys.stderr.write("\n")
raise
if challenge_status['status'] == "pending":
time.sleep(2)
elif challenge_status['status'] == "valid":
sys.stderr.write("Passed {} challenge!\n".format(i['domain']))
break
else:
raise KeyError("'{}' challenge did not pass: {}".format(i['domain'], challenge_status))
# Step 14: Get the certificate signed
sys.stderr.write("Requesting signature...\n")
csr_file_sig.seek(0)
csr_sig64 = _b64(csr_file_sig.read())
csr_data = json.dumps({
"header": header,
"protected": csr_protected64,
"payload": csr_b64,
"signature": csr_sig64,
}, sort_keys=True, indent=4)
csr_url = "{}/acme/new-cert".format(CA)
try:
resp = urllib2.urlopen(csr_url, csr_data)
signed_der = resp.read()
except urllib2.HTTPError as e:
sys.stderr.write("Error: csr_data:\n")
sys.stderr.write("POST {}\n".format(csr_url))
sys.stderr.write(csr_data)
sys.stderr.write("\n")
sys.stderr.write(e.read())
sys.stderr.write("\n")
raise
# Step 15: Convert the signed cert from DER to PEM
sys.stderr.write("Certificate signed!\n")
signed_der64 = base64.b64encode(signed_der)
signed_pem = """\
-----BEGIN CERTIFICATE-----
{}
-----END CERTIFICATE-----
""".format("\n".join(textwrap.wrap(signed_der64, 64)))
return signed_pem
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""\
Get a SSL certificate signed by a Let's Encrypt (ACME) certificate authority and
output that signed certificate. You do NOT need to run this script on your
server and this script does not ask for your private keys. It will print out
commands that you need to run with your private key or on your server as root,
which gives you a chance to review the commands instead of trusting this script.
Optionally you can decide to trust this script and run it on your server as root
and use --trust switch. This allows you to have certificate signed in singe command.
NOTE: YOUR ACCOUNT KEY NEEDS TO BE DIFFERENT FROM YOUR DOMAIN KEY.
Prerequisites:
* openssl
* python
Example: Generate an account keypair, a domain key and csr, and have the domain csr signed.
--------------
$ openssl genrsa 4096 > user.key
$ openssl rsa -in user.key -pubout > user.pub
$ openssl genrsa 4096 > domain.key
$ openssl req -new -sha256 -key domain.key -subj "/CN=example.com" > domain.csr
$ python sign_csr.py --public-key user.pub domain.csr > signed.crt
--------------
""")
parser.add_argument('--trust',action='store_true',default=False,help='complete chalanges automaticaly')
parser.add_argument('-w',dest='crt_path',action='store',help='write output to file')
parser.add_argument("-p","--public-key",action="store",required=True,help="path to your account public key")
parser.add_argument("-k","--private-key",action="store",default=None,help='path to your account private key')
parser.add_argument("-e","--email",action="store",default=None, help="contact email, default is webmaster@<shortest_domain>")
parser.add_argument("-c","--chain",action='store_true',default=False, help="Append Lets Encrypt Authority X3 certificate")
parser.add_argument("csr_path", action="store",help="path to your certificate signing request")
args = parser.parse_args()
if args.trust:
if args.private_key==None:
print 'Define path to account private key with -k or --private-key. This is needed to sign challenges\nautomaticaly. You also to sign them manualy if you run program without --trust swith.'
exit()
if os.geteuid()!=0:
print 'Run as root or without --trust switch'
exit()
signed_crt = sign_csr(args.public_key, args.csr_path, args.private_key, email=args.email, automatized=args.trust)
if args.chain:
signed_crt+="""\
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF
q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8
SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0
Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA
a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
"""
if args.crt_path:
print 'Saving signed certificate in',args.crt_path
crtFile=open(args.crt_path,'w')
crtFile.write(signed_crt)
crtFile.close()
else:
sys.stdout.write(signed_crt)