{"id":20571562,"url":"https://github.com/circl/pycirclean","last_synced_at":"2025-10-26T11:34:58.990Z","repository":{"id":31854962,"uuid":"35422260","full_name":"CIRCL/PyCIRCLean","owner":"CIRCL","description":"Python library used by CIRCLean (the USB sanitizer) and others","archived":false,"fork":false,"pushed_at":"2024-01-05T13:37:00.000Z","size":1778,"stargazers_count":54,"open_issues_count":14,"forks_count":21,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-04-14T17:07:04.096Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.circl.lu/projects/CIRCLean/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CIRCL.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-05-11T12:25:23.000Z","updated_at":"2025-03-13T16:31:04.000Z","dependencies_parsed_at":"2024-01-05T14:47:54.294Z","dependency_job_id":null,"html_url":"https://github.com/CIRCL/PyCIRCLean","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIRCL%2FPyCIRCLean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIRCL%2FPyCIRCLean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIRCL%2FPyCIRCLean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIRCL%2FPyCIRCLean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CIRCL","download_url":"https://codeload.github.com/CIRCL/PyCIRCLean/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923766,"owners_count":21183953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T05:16:33.477Z","updated_at":"2025-10-26T11:34:58.899Z","avatar_url":"https://github.com/CIRCL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/CIRCL/PyCIRCLean.svg?branch=master)](https://travis-ci.org/CIRCL/PyCIRCLean)\n[![codecov.io](https://codecov.io/github/CIRCL/PyCIRCLean/coverage.svg?branch=master)](https://codecov.io/github/CIRCL/PyCIRCLean?branch=master)\n\n# PyCIRCLean\n\nPyCIRCLean is the core Python code used by [CIRCLean](https://github.com/CIRCL/Circlean/), an open-source\nUSB key and document sanitizer created by [CIRCL](https://www.circl.lu/). This module has been separated from the\ndevice-specific scripts and can be used for dedicated security applications to sanitize documents from hostile environments\nto trusted environments. PyCIRCLean is currently Python 3.6+ compatible. Also, while [kittengroomer](./kittengroomer) can\nrun on any platform supported by python-magic/libmagic, [filecheck.py](./filecheck/filecheck.py) has some dependencies that\nare Linux-only, and running the full test suite will require access to a Linux box or VM.\n\n# Installation\n\n~~~\ngit clone https://github.com/CIRCL/PyCIRCLean.git\ncd PyCIRCLean\npip3 install -e .\n~~~\n\n# How to use PyCIRCLean\n\nPyCIRCLean is a simple Python library to handle file checking and sanitization.\nPyCIRCLean is designed to be extended to cover specific checking\nand sanitization workflows in different organizations such as industrial\nenvironments or restricted/classified ICT environments. A series of practical examples utilizing PyCIRCLean can be found\nin the [./examples](./examples) directory. Note: for commits beyond version 2.2.0 these\nexamples are out of date and not guaranteed to work with the PyCIRCLean API. Please check [helpers.py](./kittengroomer/\nhelpers.py) or [filecheck.py](./filecheck/filecheck.py) to see the new API interface.\n\nThe following simple example using PyCIRCLean will only copy files with a .conf extension matching the 'text/plain'\nmimetype. If any other file is found in the source directory, the files won't be copied to the destination directory.\n\n~~~python\n#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport os\nimport magic\n\nfrom kittengroomer import FileBase, KittenGroomerBase, main\n\n\n# Extension\nclass Config:\n    configfiles = {'.conf': 'text/plain'}\n\n\nclass FileSpec(FileBase):\n\n    def __init__(self, src_path, dst_path):\n        \"\"\"Init file object, set the extension.\"\"\"\n        super(FileSpec, self).__init__(src_path, dst_path)\n        self.valid_files = {}\n        # The initial version will only accept the file extensions/mimetypes listed here.\n        self.valid_files.update(Config.configfiles)\n\n    def check(self):\n        valid = True\n        expected_mime = self.valid_files.get(self.extension)\n        if expected_mime is None:\n            # Unexpected extension =\u003e disallowed\n            valid = False\n            compare_ext = 'Extension: {} - Expected: {}'.format(self.cur_file.extension, ', '.join(self.valid_files.keys()))\n        elif self.mimetype != expected_mime:\n            # Unexpected mimetype =\u003e disallowed\n            valid = False\n            compare_mime = 'Mime: {} - Expected: {}'.format(self.cur_file.mimetype, expected_mime)\n        else:\n            self.should_copy = False\n        if self.should_copy:\n            self.safe_copy()\n\n\nclass KittenGroomerSpec(KittenGroomerBase):\n\n    def __init__(self, root_src=None, root_dst=None):\n        \"\"\"Initialize the basics of the copy.\"\"\"\n        if root_src is None:\n            root_src = os.path.join(os.sep, 'media', 'src')\n        if root_dst is None:\n            root_dst = os.path.join(os.sep, 'media', 'dst')\n        super(KittenGroomerSpec, self).__init__(root_src, root_dst)\n\n    def processdir(self):\n        \"\"\"Main function doing the processing.\"\"\"\n        to_copy = []\n        error = []\n        for srcpath in self.list_all_files(self.src_root_dir):\n            dstpath = srcpath.replace(self.src_root_dir, self.dst_root_dir)\n            cur_file = FileSpec(srcpath, dstpath)\n            cur_file.check()\n\n\nif __name__ == '__main__':\n    main(KittenGroomerSpec, ' Only copy some files, returns an error is anything else is found')\n\n~~~\n\n# How to contribute\n\nWe welcome contributions (including bug fixes and new example file processing\nworkflows) via pull requests. We are particularly interested in any new workflows\nthat can be used to improve security in different organizations. If you see any\npotential enhancements required to support your sanitization workflow, please feel\nfree to open an issue. Read [CONTRIBUTING.md](/CONTRIBUTING.md) for more\ninformation.\n\n\n# License\n\n~~~\nCopyright (C) 2013-2015 Raphaël Vinot\nCopyright (C) 2013-2015 CIRCL - Computer Incident Response Center Luxembourg (℅ smile gie)\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n    * Redistributions of source code must retain the above copyright\n      notice, this list of conditions and the following disclaimer.\n    * Redistributions in binary form must reproduce the above copyright\n      notice, this list of conditions and the following disclaimer in the\n      documentation and/or other materials provided with the distribution.\n    * Neither the name of the organization nor the names of its contributors\n      may be used to endorse or promote products derived from this software\n      without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY\nDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcircl%2Fpycirclean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcircl%2Fpycirclean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcircl%2Fpycirclean/lists"}