Skip to content

Commit 80b926a

Browse files
committed
Throw an error if a directory is passed instead of a filename
1 parent 83873a6 commit 80b926a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/sscg/main.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,17 @@ def parse_cmdline():
149149
print(_("Certificate file must be PEM or ASN.1"),
150150
file=sys.stderr)
151151

152+
# We must be passed a full path including target file
153+
if not os.path.basename(options.cert_file):
154+
raise SSCGBadInputError("Cert file path must include filename")
155+
156+
if not os.path.basename(options.cert_key_file):
157+
raise SSCGBadInputError("Key file path must include filename")
158+
152159
if not options.ca_file:
153160
options.ca_file = "{}/ca.crt".format(os.path.dirname(options.cert_file))
161+
elif not os.path.basename(options.ca_file):
162+
raise SSCGBadInputError("CA path must include filename")
154163

155164
if options.debug:
156165
# Dump all of the options so we see their values, including defaults
@@ -160,7 +169,11 @@ def parse_cmdline():
160169

161170

162171
def main():
163-
options = parse_cmdline()
172+
try:
173+
options = parse_cmdline()
174+
except SSCGBadInputError:
175+
print(_("Bad input on the command-line: {}".format(sys.exc_info()[1])))
176+
sys.exit(1)
164177

165178
try:
166179
(ca_cert, ca_key) = create_temp_ca(options)

0 commit comments

Comments
 (0)