Created
August 19, 2014 23:00
-
-
Save joemiller/ac94c66866f75817f22e to your computer and use it in GitHub Desktop.
extract multiple PEM encoded certs from a single file. yak shave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def extract_pem_certs(str): | |
| buf = None | |
| certs = [] | |
| for line in str.split('\n'): | |
| if 'BEGIN CERTIFICATE' in line and buf is None: | |
| buf = line + '\n' | |
| elif 'END CERTIFICATE' in line: | |
| buf += line + '\n' | |
| certs.append(buf) | |
| buf = None | |
| elif buf is not None: | |
| buf += line + '\n' | |
| else: | |
| # garbage, throw it away | |
| pass | |
| return certs | |
| d = open('test.crts', 'r').read() | |
| for cert in extract_pem_certs(d): | |
| print cert |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment