Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extract certtificates and keys from astrill OVPN files. Should work for others
import os, shutil
from glob import glob
def write_file(data, out_file_name, new_dir):
with open(os.path.join(new_dir, out_file_name), 'w') as f:
for ovpn_file in glob('*.ovpn'):
new_dir = os.path.join(ovpn_file.replace('.ovpn', ''))
os.makedirs(new_dir, exist_ok=True)
shutil.copy2(ovpn_file, os.path.join(new_dir, ovpn_file.split('/')[-1]))
with open(ovpn_file) as f:
file_data = f.readlines()
in_block = False
data = []
for line in file_data:
if line.startswith('<') and line.strip().endswith('>'): # if this is a tag line
if in_block: # we're in a block, write data
file_ext = line.strip().replace('</', '').replace('>', '') + ".pem"
write_file(data, ovpn_file.split('/')[-1] + '-' + file_ext, new_dir)
data = []
in_block = False
in_block = True
elif in_block:
print("Exported {}".format(ovpn_file.split('/')[-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.