Giter Site home page Giter Site logo

zorroroot / certutil Goto Github PK

View Code? Open in Web Editor NEW

This project forked from suolapeikko/certutil

0.0 1.0 0.0 174 KB

macOS command line utility for deleting duplicates and multiple copies of the same certificate from the macOS's Keychain

Swift 100.00%

certutil's Introduction

certutil

macOS command line tool for deleting expired/duplicate/not used certificates and associated private keys from Keychain. The idea of certutil is to always leave the most recent certificate in Keychain.

If you are running macOS 10.3 (High Sierra) or below, you need to install Swift 5 Runtime Support for Command Line Tools to run certutil.

Usage:

$ ./certutil
certutil: Command line utility for listing and cleaning certificates from Keychain (Version 4.1)

   Usage:
   certutil -list <name>           List all certificates with <name> in CN
   certutil -list_exp <name>       List all expired certificates with <name> in CN
   certutil -verify <name>         List and verify all certificates with <name> in CN
   certutil -delete <name>         Delete all certificates except the most recent one with <name> in CN
   certutil -delete_exp <name>     Delete all expired certificates with <name> in CN
   certutil -count <name>          Count all certificates with <name> in CN
   certutil -count_exp <name>      Count all expired certificates with <name> in CN

Options:

The whole idea of the tool is to remove copies of defined certificates and associated private (and possible public) keys that are not used, thus leaving only the latest one to the macOS's Keychain.

./certutil -list <name> searches keychain for all certificates which have name variable in their CN. For example, it will match both "Developer ID Application: Antti" and "Developer ID Installer: Antti". The idea of the tool is to not restrict user to do only exact matches.

./certutil -list_exp <name> searches keychain for all expired certificates which have name variable in their CN. For example, it will match both "Developer ID Application: Antti" and "Developer ID Installer: Antti". The idea of the tool is to not restrict user to do only exact matches.

./certutil -verify <name>is used to verify the selected name variable and show what the tool will actually delete by marking them with -> Remove in the list that it prints to the screen. This way you can test the result before deleting anything.

./certutil -delete <name> deletes all certificates from Keychain which have name variable in their CN. Be careful with the name attribute. Use at your own risk!

./certutil -delete_exp <name> deletes all expired certificates from Keychain which have name variable in their CN. Be careful with the name attribute. Use at your own risk!

./certutil -count <name> counts the number of certificates with the given full or substring of CN.

./certutil -count_exp <name> counts the number of expired certificates with the given full or substring of CN.

How to get started:

Download the latest certutil from GitHub:

curl -OL https://github.com/suolapeikko/certutil/releases/download/4.1/CertUtil-4.1.pkg

Install certutil to /usr/local/bin:

sudo installer -package CertUtil-4.1.pkg -target /

Make a test run with "-verify" command:

certutil -verify "your_cn_value_here"

You should make a backup copy of your Keychain before running "-delete" command in case something goes wrong:

sudo cp -Rpf ~/Library/Keychains ~/Desktop

Usage examples:

antti@my-mbp ~ % certutil -count "@antti.com"
Total amount of certificates having '@antti.com' in CN: 3

antti@my-mbp ~ % certutil -list "@antti.com"
[email protected], Expiration: 14. Mar 2021 15:26:59
[email protected], Expiration: 14. Mar 2021 15:26:44
[email protected], Expiration: 14. Mar 2021 15:01:17

antti@my-mbp ~ % certutil -verify "@antti.com"
[email protected], Expiration: 14. Mar 2021 15:26:59 -> Keep
[email protected], Expiration: 14. Mar 2021 15:26:44 -> Delete
[email protected], Expiration: 14. Mar 2021 15:01:17 -> Delete

antti@my-mbp ~ % certutil -delete "@antti.com" 
[email protected], Expiration: 14. Mar 2021 15:26:59 -> Keeping
[email protected], Expiration: 14. Mar 2021 15:26:44 -> Deleting
[email protected], Expiration: 14. Mar 2021 15:01:17 -> Deleting

certutil's People

Contributors

suolapeikko avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.