/usr/sbin/yhsm-db-export is in yhsm-yubikey-ksm 1.0.4k-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | #!/usr/bin/python
#
# Copyright (c) 2013-2014 Yubico AB
# See the file COPYING for licence statement.
#
"""
Export AEAD from database.
"""
import os
import sys
import io
import hashlib
import re
import time
import errno
import argparse
import sqlalchemy
from os.path import abspath
sys.path.append('Lib')
from pyhsm.util import key_handle_to_int
import pyhsm.aead_cmd
##########################
# Functions Declarartion #
##########################
#
#insert_slash insert / every 2 char
#
def insert_slash(string, every=2):
return '/'.join(string[i:i+every] for i in xrange(0, len(string), every))
#
#mkdir -p: creates path like mkdir -p
#
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise
#################################
# END of functions declariation #
#################################
#######################
# #
# Initialization Area #
# #
#######################
parser = argparse.ArgumentParser(description='Import AEADs into the database')
parser.add_argument('path', action="store", type=str)
parser.add_argument('dburl', action="store")
args = vars(parser.parse_args())
if len(sys.argv) != 3:
print("\nUsage: python export_aeads.py /path/to/export/ database_url\ni.e. python export_aeads.py /root/aeads/ mysql://root:password@localhost:3306/database_name")
sys.exit(2)
if not os.path.isdir(sys.argv[1]):
print("\nInvalid path, check your spelling.\n")
sys.exit(2)
#set the path
path = args['path']
#mysql url
databaseUrl = args['dburl']
try:
#check database connection
engine = sqlalchemy.create_engine(databaseUrl)
#SQLAlchemy voodoo
metadata = sqlalchemy.MetaData()
aeadobj = sqlalchemy.Table('aead_table', metadata, autoload=True, autoload_with=engine)
connection = engine.connect()
except:
print "FATAL: Database connect failure"
sys.exit(1)
aead = None
nonce = None
key_handle = None
aead = pyhsm.aead_cmd.YHSM_GeneratedAEAD(nonce, key_handle, aead)
#get data from the database
result = connection.execute("SELECT * from aead_table")
#cycle through resutls
for row in result:
#read values row by row
aead.data = row['aead']
publicId = row['public_id']
aead.key_handle = row['keyhandle']
aead.nonce = row['nonce']
path = ''.join([path, '/', str(hex(aead.key_handle)).rstrip('L'), '/', insert_slash(publicId)])
#sanitize path
path = os.path.normpath(path)
#create path
mkdir_p(path)
#write the file in the path
pyhsm.aead_cmd.YHSM_GeneratedAEAD.save(aead, path+'/'+publicId)
#reset path constructor
path = sys.argv[1]
#close connection
connection.close()
#exit without error
sys.exit(0)
|