base64.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 23 Jun 2017 17:28:03 -0400
changeset 58 1390348facc7
parent 0 d7ee4e2ed49d
permissions -rw-r--r--
Command line tool that decrypts an OPVault keychain and dumps it to stdout.

To compile: gcc -o opvault opvault.c cJSON.c -lcrypto

Usage: ./opvault </path/to/mykeychain.opvault> <password>

This is just a proof of concept; I'll be recycling this into proper OPVault
support in 1pass later and deleting this tool.

This uses OpenSSL's libcrypto for the math instead of all the homegrown
crypto this project is otherwise using. I'll probably migrate the rest in
this direction, too, since this wasn't as bad as I expected to use and
gets you all the package-manager mojo of automatic bug fixes and security
patches and shared code, etc.

cJSON parses JSON in C. That is from https://github.com/DaveGamble/cJSON

An example OPVault keychain from AgileBits is available here:

https://cache.agilebits.com/security-kb/
icculus@0
     1
/*
icculus@0
     2
cdecode.h - c header for a base64 decoding algorithm
icculus@0
     3
This is part of the libb64 project, and has been placed in the public domain.
icculus@0
     4
For details, see http://sourceforge.net/projects/libb64
icculus@0
     5
*/
icculus@0
     6
icculus@0
     7
#ifndef _INCL_BASE64_H_
icculus@0
     8
#define _INCL_BASE64_H_
icculus@0
     9
icculus@0
    10
#include <stdint.h>
icculus@0
    11
icculus@0
    12
typedef enum
icculus@0
    13
{
icculus@0
    14
	step_a, step_b, step_c, step_d
icculus@0
    15
} base64_decodestep;
icculus@0
    16
icculus@0
    17
typedef struct
icculus@0
    18
{
icculus@0
    19
	base64_decodestep step;
icculus@0
    20
	char plainchar;
icculus@0
    21
} base64_decodestate;
icculus@0
    22
icculus@0
    23
void base64_init_decodestate(base64_decodestate* state_in);
icculus@0
    24
int base64_decode_value(char value_in);
icculus@0
    25
int base64_decode_block(const char* code_in, const int length_in, uint8_t* plaintext_out, base64_decodestate* state_in);
icculus@0
    26
icculus@0
    27
icculus@0
    28
typedef enum
icculus@0
    29
{
icculus@0
    30
	step_A, step_B, step_C
icculus@0
    31
} base64_encodestep;
icculus@0
    32
icculus@0
    33
typedef struct
icculus@0
    34
{
icculus@0
    35
	base64_encodestep step;
icculus@0
    36
	char result;
icculus@0
    37
	int stepcount;
icculus@0
    38
} base64_encodestate;
icculus@0
    39
icculus@0
    40
void base64_init_encodestate(base64_encodestate* state_in);
icculus@0
    41
char base64_encode_value(char value_in);
icculus@0
    42
int base64_encode_block(const uint8_t* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
icculus@0
    43
int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
icculus@0
    44
icculus@0
    45
#endif
icculus@0
    46