def main():
    parser = argparse.ArgumentParser(description='Import AEADs into the database')

    parser.add_argument('path', help='filesystem path of where to find AEADs')
    parser.add_argument('dburl', help='connection URL for the database')

    args = parser.parse_args()

    path = args.path
    databaseUrl = args.dburl

    if not os.path.isdir(path):
        print("\nInvalid path, check your spelling.\n")
        return 2

    try:
        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")
        return 1

    for root, subFolders, files in os.walk(path):
        if files:
            if not re.match(r'^[cbdefghijklnrtuv]+$', files[0]):
                continue

            #build file path
            filepath = os.path.join(root, files[0])

            #extract the key handle from the path
            keyhandle = extract_keyhandle(path, filepath)
            kh_int = pyhsm.util.key_handle_to_int(keyhandle)

            #instantiate a new aead object
            aead = pyhsm.aead_cmd.YHSM_GeneratedAEAD(None, kh_int, '')
            aead.load(filepath)

            #set the public_id
            public_id = str(files[0])

            #check it is old format aead
            if not aead.nonce:
                #configure values for oldformat
                aead.nonce = pyhsm.yubikey.modhex_decode(public_id).decode('hex')
                aead.key_handle = key_handle_to_int(keyhandle)

            if not insert_query(connection, public_id, aead, keyhandle, aeadobj):
                print("WARNING: could not insert %s" % public_id)

    #close sqlalchemy
    connection.close()
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser(description="Import AEADs into the database")

    parser.add_argument("path", help="filesystem path of where to find AEADs")
    parser.add_argument("dburl", help="connection URL for the database")

    args = parser.parse_args()

    path = args.path
    databaseUrl = args.dburl

    if not os.path.isdir(path):
        print("\nInvalid path, check your spelling.\n")
        return 2

    try:
        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")
        return 1

    for root, subFolders, files in os.walk(path):
        if files:
            if not re.match(r"^[cbdefghijklnrtuv]+$", files[0]):
                continue

            # build file path
            filepath = os.path.join(root, files[0])

            # extract the key handle from the path
            keyhandle = extract_keyhandle(path, filepath)
            kh_int = pyhsm.util.key_handle_to_int(keyhandle)

            # instantiate a new aead object
            aead = pyhsm.aead_cmd.YHSM_GeneratedAEAD(None, kh_int, "")
            aead.load(filepath)

            # set the public_id
            public_id = str(files[0])

            # check it is old format aead
            if not aead.nonce:
                # configure values for oldformat
                aead.nonce = pyhsm.yubikey.modhex_decode(public_id).decode("hex")
                aead.key_handle = key_handle_to_int(keyhandle)

            if not insert_query(connection, public_id, aead, keyhandle, aeadobj):
                print("WARNING: could not insert %s" % public_id)

    # close sqlalchemy
    connection.close()
def insert_query(connection, publicId, aead, keyhandle, aeadobj):
    """this functions read the response fields and creates sql query. then
    inserts everything inside the database"""

    # turn the keyhandle into an integer
    keyhandle = key_handle_to_int(keyhandle)
    if not keyhandle == aead.key_handle:
        print("WARNING: keyhandle does not match aead.key_handle")
        return None

    # creates the query object
    try:
        sql = aeadobj.insert().values(public_id=publicId, keyhandle=aead.key_handle, nonce=aead.nonce, aead=aead.data)
        # insert the query
        result = connection.execute(sql)
        return result
    except sqlalchemy.exc.IntegrityError:
        pass
    return None
Beispiel #4
0
def insert_query(connection, publicId, aead, keyhandle, aeadobj):
    """this functions read the response fields and creates sql query. then
    inserts everything inside the database"""

    # turn the keyhandle into an integer
    keyhandle = key_handle_to_int(keyhandle)
    if not keyhandle == aead.key_handle:
        print("WARNING: keyhandle does not match aead.key_handle")
        return None

    # creates the query object
    try:
        sql = aeadobj.insert().values(public_id=publicId, keyhandle=aead.key_handle, nonce=aead.nonce, aead=aead.data)
        # insert the query
        result = connection.execute(sql)
        return result
    except sqlalchemy.exc.IntegrityError:
        pass
    return None
Beispiel #5
0
def _yhsmcalc_checksum(base, self, secret):
    base_chk = super(base, self).calc_checksum(secret)
    result = hsm.hmac_sha1(key_handle_to_int(self.key_handle), base_chk)

    return result.result.hash_result
Beispiel #6
0
def _yhsmcalc_checksum(base, self, secret):
    base_chk = super(base, self).calc_checksum(secret)
    result = hsm.hmac_sha1(key_handle_to_int(self.key_handle), base_chk)

    return result.result.hash_result