Skip to content

Instantly share code, notes, and snippets.

@maxiwoj
Created May 29, 2023 17:40
Show Gist options
  • Save maxiwoj/be2b2a84b015b26ba89a3cb095cdde7a to your computer and use it in GitHub Desktop.
Save maxiwoj/be2b2a84b015b26ba89a3cb095cdde7a to your computer and use it in GitHub Desktop.
A set of tools for proecssing 1Password Unencrypted Archive (.1pux)

1PasswordArchiveProcessor

Whenever migrating to a different password manager an important thing is exporting all of the data. Unfortunately, most of the password managers export by default to csv or support importing from csv only. Exporting everything to a csv with 1password contains only the default fields (such as username, password, notes), but won't export all the custom fields (e.g. fields that it suggests to add for a passport, any imported SSH keys etc.). I created those functions in order to easily manage my items that have some additional information than what can be exported to a csv file.

Initialise data

In order to get the file, you need to export the 1password account to .1pux file (1password unencrypted archive). Then change the file extension to .zip - inside there is the export.data file with a dump of the whole account.

import json 
with open("export.data") as file:
    data = json.load(file)

Init functions

def get_all_vaults_for_the_first_account():
    return [item for vault in data['accounts'][0]['vaults'] for item in vault['items']]
def has_custom_sections(item):
    return len(item['details']['sections']) > 0
def create_dict(x):
    data_dict = {}
    elements = create_list(x)
    for el in elements:
        if el[0] in data_dict:
            data_dict[el[0]].append(el[1])
        else:
            data_dict[el[0]] = el[1:]
    return data_dict

def create_list(x):
    return [[section['title'], field['title']] for section in x['details']['sections'] for field in section['fields']]

def create_names(x):
    return [field['title'] for section in x['details']['sections'] for field in section['fields']]

List all items that have custom fields

[x['overview']['title'] for x in filter(has_custom_sections, get_all_vaults_for_the_first_account())]

Output e.g:

    ['Github'
     'My Passport'
     'Google'
     ...]

Get example item with custom sections

list(filter(has_custom_sections, get_all_vaults_for_the_first_account()))[0]

Process

All items with custom sections and create a list of:

(item_name, [custom_field_name]):

list(
    map(lambda x: (x['overview']['title'], create_names(x)), 
        filter(has_custom_sections, get_all_vaults_for_the_first_account())))

Output e.g:

    [('Github', ['private key', 'some field']),
     ('My Passport',
      ['number',
       'full name',
       'gender',
       'nationality',
       'issuing authority',
       'date of birth',
       'place of birth',
       'issued on',
       'expiry date'])
     ('Google', ['....'])
     ...]

(item_name, {section_name: [custom_field_name]}):

list(
    map(lambda x: (x['overview']['title'], create_dict(x)), 
        filter(has_custom_sections, get_all_vaults_for_the_first_account())))

Output e.g:

    [('Github', {'': ['private key']}, {'other section': ['some field']}),
     ('My Passport',
      {'details': ['number',
        'full name',
        'gender',
        'nationality',
        'issuing authority',
        'date of birth',
        'place of birth',
        'issued on',
        'expiry date']})
     ('Google', {'other fields': [.......]})
     ...]
     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment