lua/lctype.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
** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $
icculus@0
     3
** 'ctype' functions for Lua
icculus@0
     4
** See Copyright Notice in lua.h
icculus@0
     5
*/
icculus@0
     6
icculus@0
     7
#ifndef lctype_h
icculus@0
     8
#define lctype_h
icculus@0
     9
icculus@0
    10
#include "lua.h"
icculus@0
    11
icculus@0
    12
icculus@0
    13
/*
icculus@0
    14
** WARNING: the functions defined here do not necessarily correspond
icculus@0
    15
** to the similar functions in the standard C ctype.h. They are
icculus@0
    16
** optimized for the specific needs of Lua
icculus@0
    17
*/
icculus@0
    18
icculus@0
    19
#if !defined(LUA_USE_CTYPE)
icculus@0
    20
icculus@0
    21
#if 'A' == 65 && '0' == 48
icculus@0
    22
/* ASCII case: can use its own tables; faster and fixed */
icculus@0
    23
#define LUA_USE_CTYPE	0
icculus@0
    24
#else
icculus@0
    25
/* must use standard C ctype */
icculus@0
    26
#define LUA_USE_CTYPE	1
icculus@0
    27
#endif
icculus@0
    28
icculus@0
    29
#endif
icculus@0
    30
icculus@0
    31
icculus@0
    32
#if !LUA_USE_CTYPE	/* { */
icculus@0
    33
icculus@0
    34
#include <limits.h>
icculus@0
    35
icculus@0
    36
#include "llimits.h"
icculus@0
    37
icculus@0
    38
icculus@0
    39
#define ALPHABIT	0
icculus@0
    40
#define DIGITBIT	1
icculus@0
    41
#define PRINTBIT	2
icculus@0
    42
#define SPACEBIT	3
icculus@0
    43
#define XDIGITBIT	4
icculus@0
    44
icculus@0
    45
icculus@0
    46
#define MASK(B)		(1 << (B))
icculus@0
    47
icculus@0
    48
icculus@0
    49
/*
icculus@0
    50
** add 1 to char to allow index -1 (EOZ)
icculus@0
    51
*/
icculus@0
    52
#define testprop(c,p)	(luai_ctype_[(c)+1] & (p))
icculus@0
    53
icculus@0
    54
/*
icculus@0
    55
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
icculus@0
    56
*/
icculus@0
    57
#define lislalpha(c)	testprop(c, MASK(ALPHABIT))
icculus@0
    58
#define lislalnum(c)	testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
icculus@0
    59
#define lisdigit(c)	testprop(c, MASK(DIGITBIT))
icculus@0
    60
#define lisspace(c)	testprop(c, MASK(SPACEBIT))
icculus@0
    61
#define lisprint(c)	testprop(c, MASK(PRINTBIT))
icculus@0
    62
#define lisxdigit(c)	testprop(c, MASK(XDIGITBIT))
icculus@0
    63
icculus@0
    64
/*
icculus@0
    65
** this 'ltolower' only works for alphabetic characters
icculus@0
    66
*/
icculus@0
    67
#define ltolower(c)	((c) | ('A' ^ 'a'))
icculus@0
    68
icculus@0
    69
icculus@0
    70
/* two more entries for 0 and -1 (EOZ) */
icculus@0
    71
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
icculus@0
    72
icculus@0
    73
icculus@0
    74
#else			/* }{ */
icculus@0
    75
icculus@0
    76
/*
icculus@0
    77
** use standard C ctypes
icculus@0
    78
*/
icculus@0
    79
icculus@0
    80
#include <ctype.h>
icculus@0
    81
icculus@0
    82
icculus@0
    83
#define lislalpha(c)	(isalpha(c) || (c) == '_')
icculus@0
    84
#define lislalnum(c)	(isalnum(c) || (c) == '_')
icculus@0
    85
#define lisdigit(c)	(isdigit(c))
icculus@0
    86
#define lisspace(c)	(isspace(c))
icculus@0
    87
#define lisprint(c)	(isprint(c))
icculus@0
    88
#define lisxdigit(c)	(isxdigit(c))
icculus@0
    89
icculus@0
    90
#define ltolower(c)	(tolower(c))
icculus@0
    91
icculus@0
    92
#endif			/* } */
icculus@0
    93
icculus@0
    94
#endif
icculus@0
    95