Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.048.042 Times

signedimp 0.3.1

Company: Ryan Kelly
Date Added: July 22, 2013  |  Visits: 485

signedimp

Report Broken Link
Printer Friendly Version


Product Homepage
Download (39 downloads)

This module implements an import hook for verifying Python modules before they are loaded, by means of cryptographically-signed hashes. It is compatible with PEP 302 and designed to complement the code-signing functionality of your host OS (e.g. Microsoft Authenticode, Apple OSX Code Signing) which may be able to verify the Python executable itself but not the code that is dynamically loaded<br />at runtime.<br /><br />It will mostly be useful for frozen Python applications, or other situations where code is not expected to change. It will be almost useless with a standard Python interpreter.<br /><br />If you're just after a black-box solution, you could try one of the following function calls to sign your app with a new randomly-generated key::<br /><br /> signedimp.tools.sign_py2exe_app(path_to_app_dir)<br /> signedimp.tools.sign_py2app_bundle(path_to_app_dir)<br /> signedimp.tools.sign_cxfreeze_app(path_to_app_dir)<br /><br />These functions modify a frozen Python application so that it verifies the integrity of its modules before they are loaded, using a one-time key generated just for that application.<br /><br />But really, you should read on to understand exactly what's going on. There are plenty of caveats to be had.<br /><br />Enabling Signed Imports<br />-----------------------<br /><br />To enable signed imports, you need to create a SignedImportManager with the appropriate cryptographic keys and install it into the import machinery::<br /><br /> from signedimp import SignedImportManager, RSAKeyWithPSS<br /><br /> key = RSAKeyWithPSS(modulus,pub_exponent)<br /> mgr = SignedImportManager([key])<br /> mgr.install()<br /><br />From this point on, all requests to import a module will be checked against signed manifest files before being allow to proceed. If a module cannot be verified then the import will fail.<br /><br />Verification is performed in coopertion with the existing import machinery, using the optional loader method get_data(). It works with at least the default import machinery and the zipimport module; if you have custom import hooks that don't offer this method, or that don't conform to the standard file layout for python imports, they will will not be usable with signedimp.<br /><br />Keys<br />----<br /><br />Currently signedimp uses RSA keys for its digital signatures, along with the "Probabilistic Signature Scheme" padding mechanism. To generate a new key you will need PyCrypto installed, and to do the following::<br /><br /> from signedimp.crypto.rsa import RSAKeyWithPSS<br /> key = RSAKeyWithPSS.generate()<br /> pubkey = key.get_public_key()<br /><br />Store this key somewhere safe, you'll need it to sign files. The simplest way is using the "save_to_file" method::<br /><br /> with open("mykeyfile","wb") as f:<br /> key.save_to_file(f,"mypassword")<br /><br />To retreive the key in e.g. your build scripts, do something like this::<br /><br /> with open("mykeyfile","rb") as f:<br /> key = RSAKeyWithPSS.load_from_file(f,getpass())<br /><br />You'll also need to embed the public key somewhere in your final executable so it's available for verifying imports. The functions in signedimp.tools will do this for you - if you're writing you own scheme you can either pickle it, or embed its repr() somewhere in your source code.<br /><br /><br />Manifests<br />---------<br /><br />To verify imports, each entry on sys.path must contain a manifest file, which contains a cryptographic hash for each module and is signed by one or more private keys. This file is called "signedimp-manifest.txt" and it will be requested from each import loader using the get_data() method - in practice this means that the file must exist in the root of each directory and each zipfile listed on sys.path.<br /><br />The manifest is a simple text file. It begins with zero or more lines giving a key fingerprint followed by a signature using that key; these are separated from the hash data by a blank line. It then contains a hash type identifier and one line for each module hash. Here's a short example::<br /><br /> ----<br /> key1fingerprint b64-encoded-signature1<br /> key2fingerprint b64-encoded-signature2<br /><br /> md5<br /> m 76f3f13442c26fd4f1c709c7b03c6b76 os<br /> m f56dbc5ee6774e857a7ef07accdbd19b hashlib<br /> d 43b74fc5d2acb6b4e417f4feff06dd81 some/data/file.txt<br /> ----<br /><br />The file can contain hashes for different kinds of data; "m" indicates a module hash while "d" indicates a generic data file. The format of the fingerprint and signature depend on the types of key being used, and should be treated as ASCII blobs.<br /><br />To create a manifest file you will need a key object that includes the private key data. You can then use the functions in the "tools" submodule::<br /><br /> key = RSAKeyWithPSS(modulus,pub_exponent,priv_exponent)<br /> signedimp.tools.sign_directory("some/dir/on/sys/path",key)<br /> signedimp.tools.sign_zipfile("some/zipfile/on/sys/path.zip",key)<br /><br /><br />Bootstrapping<br />-------------<br /><br />Clearly there is a serious bootstrapping issue when using this module - while we can verify imports one this module is loaded, how do we verify the import of this module itself? To be of any use, it must be incorporated as part of a signed executable. There are several options:<br /><br /> * include signedimp as a "frozen" module in the Python interpreter itself, by mucking with the PyImport_FrozenModules pointer.<br /><br /> * include signedimp in a zipfile appended to the executable, and put the executable itself as the first item on sys.path.<br /><br /> * use the signedimp.tools.get_bootstrap_code() function to obtain code that can be included verbatim in your startup script, and embed the startup script in the executable.<br /><br />Since the bootstrapping code can't perform any imports, everything (even the cryptographic primitives) is implemented in pure Python by default. It is thus rather slow. If you're able to securely bundle e.g. hashlib or PyCrypto in the executable itself, import them before* installing the signed import manager so that it knows they are safe to use.<br /><br />Of course, the first thing the import manager does once installed is try to import these modules and speed up imports for the rest of the process.<br /><br />A word of caution - most freezer programs (e.g. py2exe or bbfreeze) execute their own startup scripts before running the user-supplied script, and these startup scripts often import common modules such as "os". You'll either need to hack the frozen exe to run the signedimp bootstrapping code first, or securely bundle these modules into the executable itself.<br /><br />So far I've worked out the necessary incantations for signing py2exe, py2app and cxfreeze applications, and there are helper functions in "signedimp.tools" that will do it for you.<br /><br />I don't belive it's possible to sign a bbfreeze application without patching bbfreeze itsel. Since bbfreeze always sets sys.path to the library.zip and the application dir, there is no way to bundle the bootstrapping code into the executable itself.<br /><br /><br />Caveats<br />-------<br /><br />All of the usual crypto caveats apply here. I'm not a security expert. The system is only a safe as your private key, as the signature on the main python executable, and as the operating system it's run on. In addition, there are some specific caveats for this module based on the way it works.<br /><br />This module operates by wrapping the existing import machinery. To check the hash of a module, it asks the appropriate loader object for the code of that module, verifies the hash, then gives the loader the OK to import it. It's quite likely that the loader will re-read the data from disk when loading the module, so there is a brief window in which it could be replaced by malicious code. I don't see any way to avoid this short of replacing all the existing import machinery, which I'm not going to do.<br /><br />As mentioned above, this module is useless if you load it from an untrusted source. You will need to sign your actual executable and you will need to<br />somehow bundle some signedimp bootstrapping code into it. See the section on "bootstrapping" for more details.<br /><br />You must also be careful not to import anything before you have installed the signed import manager. (One exception is the "sys" module, which should always be built into the executable itself and so safe to import.)<br /><br />Finally, you may have noticated that I'm going against all sensible crypto<br />advice and rolling my own scheme from basic primitives such as RSA and SHA1.<br />It would be much better to depend on a third-party crypto library like keyczar,<br />however:<br /><br /> * I want the verification code to be runnable as pure python without any third-party imports, to make it as easy to bootstrap as possible.<br /><br /> * I've copied the signature scheme directly from PKCS#1 and it's broadly the same as that used by keyczar etc. This is a very simple and well understood signing protocol.<br /><br /> * The signing code is supposed to be run offline, in a controlled setting with controlled inputs, so the risk of e.g. timing attacks is small.<br /><br /> * The verifying code can't leak any info about the private key because<br /> it simply doesn't have any, so it can be as slow and sloppy and clunky as needed.<br /><br />#md5=e43a54ca920bf63c5914d6038e9724f9

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Bbfreeze Bootstrapping Bundle Executable Import Imports Loader Machinery Module Modules Private Python Signature Signed Signedimp
Users rating: 0/10

License: Freeware Size: 40.96 KB
SIGNEDIMP RELATED
Libraries  -  Bundle::OpenSRF 0.07
Bundle::OpenSRF Perl module can install all OpenSRF prereq modules available on CPAN. SYNOPSIS perl -MCPAN -e install Bundle::OpenSRF or ... cpan Bundle::OpenSRF CONTENTS Cache::FileCache Cache::Memcached DBI DBD::SQLite Digest::MD5...
3.07 KB  
Libraries  -  Bundle::MusicBrainz::Client 0.01
Bundle::MusicBrainz::Client is a Perl module with a bundle to install MusicBrainz::Client and required modules. SYNOPSIS perl -MCPAN -e install Bundle::MusicBrainz::Client CONTENTS MusicBrainz::Client - for to get to know thyself...
2.05 KB  
Modules  -  Migrate Extras 7.x-2.2
Migrate Extras is a package of files that integrate the Migrate Module with many of the non-core modules available for drupal, allowing you to import content from other modules, older versions of drupal, or a non-drupal CMS.Hear Awesome Lullabot...
20.48 KB  
File Security  -  Certificate Import 1.2
Certificate Import imports digital Certificates via Drag & Drop into your Keychain and supports Certificates in popular Apache-Format (.der Files).
 
Modules  -  SSL Users 6.x-1.0
Allows user or bot to add new or update existent data for specified tasks in theirs files and then process it via cron by Node import module. It may help if you want to automatize data import. Module works in several modes: * Imports only new...
10 KB  
Programming  -  Github::Import for Linux 0.05
Github::Import is a Perl module that provides a way to import a git repository into http://github.com. SYNOPSIS # You can see your token at https://github.com/account % cd some_project_in_git % github-import...
20.48 KB  
Libraries  -  IO::Tty 1.07
IO::Tty is a Perl module to low-level allocate a pseudo-Tty, import constants. SYNOPSIS use IO::Tty qw(TIOCNOTTY); ... # use only to import constants, see IO::Pty to create ptys. IO::Tty is used internally by IO::Pty to create a...
21.5 KB  
Code Management Tools  -  MySQL Data Wizard 11.1.0.1
Data Wizard for MySQL is a very useful toolkit for managing your MySQL data. It includes the following modules: Data Pump: · Converts schema and data from any ADO-compatible database to MySQL. · Transfers tables, indexes, and foreign key...
 
Modules  -  Views Importer 6.x-1.0
This module provides an easy way to import previously exported Views definitions. 1. Export the views you wish to import and paste the export text into separate text files (name and extension not important). 2. Place the newly created text files...
10 KB  
Modules  -  CCK Importer 6.x-1.0
This module provides an easy way to import previously exported CCK definitions. 1. Export the content types you wish to import and paste the exported text into separate text files (name and extension not important). 2. Place the newly created text...
10 KB  
NEW DOWNLOADS IN LINUX SOFTWARE, PROGRAMMING
Linux Software  -  EasyEDA PCB Designer for Linux 2.0.0
EasyEDA, a great web based EDA(Electronics Design Automation) tool, online PCB tool, online PCB software for electronics engineers, educators, students, makers and enthusiasts. Theres no need to install any software. Just open EasyEDA in any...
34.4 MB  
Linux Software  -  wpCache® WordPress HTTP Cache 1.9
wpCache® is a high-performance, distributed object, caching system application, generic in nature, but intended for use in speeding up dynamic web applications, by decreasing database load time. wpCache® decreases dramatically the page...
3.51 MB  
Linux Software  -  Polling Autodialer Software 3.4
ICTBroadcast Auto Dialer software has a survey campaign for telephone surveys and polls. This auto dialer software automatically dials a list of numbers and asks them a set of questions that they can respond to, by using their telephone keypad....
488 B  
Linux Software  -  Total Video Converter Mac Free 3.5.5
Total Video Converter Mac Free developed by EffectMatrix Ltd is the official legal version of Total Video Converter which was a globally recognized brand since 2006. Total Video Converter Mac Free is a free but powerful all-in-one video...
17.7 MB  
Linux Software  -  Skeith mod_log_sql Analyzer 2.10beta2
Skeith is a php based front end for analyzing logs for Apache using mod_log_sql.
47.5 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB