source: trunk/bin/bletchley-decode

Last change on this file was 73, checked in by tim, 10 years ago

added PKCS12 capabilities to clonecertchain

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/env python3
2#-*- mode: Python;-*-
3#
4# Requires Python 3+
5
6'''
7Simple decoder script; useful in shell scripts
8
9Copyright (C) 2011-2012 Virtual Security Research, LLC
10Author: Timothy D. Morgan
11
12 This program is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License, version 3,
14 as published by the Free Software Foundation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program.  If not, see <http://www.gnu.org/licenses/>.
23'''
24
25
26import sys
27import argparse
28from bletchley import blobtools
29
30
31parser = argparse.ArgumentParser(
32    description='A simple decoder script that is useful in shell scripts.'
33    ' For more information, see:  http://code.google.com/p/bletchley/wiki/Overview')
34parser.add_argument(
35    'input_file', nargs='?', default=None,
36    help='File containing encrypted blobs to analyze, one per line.'
37    ' Omit to read from stdin.')
38parser.add_argument(
39    '-e', dest='encoding_chain', type=str, required=True,
40    help='Comma-separated sequence of encoding formats used to encode the token.'
41    ' (Use "?" for a listing of supported encodings.)')
42options = parser.parse_args()
43
44if options.encoding_chain == '?':
45    print('\n\t'.join(['Supported encodings:']+blobtools.supportedEncodings()))
46    sys.exit(0)
47
48input_file = sys.stdin.buffer
49if options.input_file is not None:
50    input_file = open(options.input_file, 'rb')
51
52blob = input_file.read().rstrip(b'\r\n')
53
54specified_encodings = options.encoding_chain.split(',')
55sys.stdout.buffer.write(blobtools.decodeChain(specified_encodings, blob))
Note: See TracBrowser for help on using the repository browser.