I’m using Apache Guacamole to manage remote connections, and I need to archive recorded sessions by moving them to another location. To do this, I need to determine which recorded session belongs to which connection from the connection history stored in the database.
But none of the generated UUIDs matched the UUID used for the recorded session.
My question is:
How exactly is the UUID for recorded sessions generated in Apache Guacamole? Are there specific fields or a specific method used to create these UUIDs that I might be missing?
Any help or pointers to the relevant part of the Guacamole codebase or documentation would be greatly appreciated.
The recorded sessions are stored with UUID names, but I haven’t been able to figure out how these UUIDs are generated based on the connection history data. Here is an example of a connection record from the guacamole_connection_history table:
<code> guacamole_db=# select * from guacamole_connection_history where history_id=464;
history_id | user_id | username | remote_host | connection_id | connection_name | sharing_profile_id | sharing_profile_name | start_date | end_date
------------+---------+----------+----------------+---------------+-----------------+--------------------+----------------------+----------------------------+----------------------------
464 | 3 | admin | 172.16.0.1 | 1 | Linux | | | 2024-08-07 07:00:56.646+00 | 2024-08-07 07:03:52.692+00
<code> guacamole_db=# select * from guacamole_connection_history where history_id=464;
history_id | user_id | username | remote_host | connection_id | connection_name | sharing_profile_id | sharing_profile_name | start_date | end_date
------------+---------+----------+----------------+---------------+-----------------+--------------------+----------------------+----------------------------+----------------------------
464 | 3 | admin | 172.16.0.1 | 1 | Linux | | | 2024-08-07 07:00:56.646+00 | 2024-08-07 07:03:52.692+00
</code>
guacamole_db=# select * from guacamole_connection_history where history_id=464;
history_id | user_id | username | remote_host | connection_id | connection_name | sharing_profile_id | sharing_profile_name | start_date | end_date
------------+---------+----------+----------------+---------------+-----------------+--------------------+----------------------+----------------------------+----------------------------
464 | 3 | admin | 172.16.0.1 | 1 | Linux | | | 2024-08-07 07:00:56.646+00 | 2024-08-07 07:03:52.692+00
From my research and looking at the Java code in Guacamole, it seems like the UUID might be generated using fields such as username, remoteHost, startDate, and connectionName. Below is the relevant part of the Java code that seems to handle the connection and record creation:
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
// Create a connection record model, starting at the current date/time
ConnectionRecordModel connectionRecordModel = new ConnectionRecordModel();
connectionRecordModel.setStartDate(new Date());
// Set the user information
connectionRecordModel.setUsername(this.currentUser.getIdentifier());
connectionRecordModel.setRemoteHost(this.remoteHost);
// Set the connection information
connectionRecordModel.setConnectionName(this.getDelegateConnection().getName());
// Insert the connection history record to mark the start of this connection
connectionRecordMapper.insert(connectionRecordModel);
// Include history record UUID as token
ModeledConnectionRecord modeledRecord = new ModeledConnectionRecord(connectionRecordModel);
Map<String, String> updatedTokens = new HashMap<>(tokens);
updatedTokens.put("HISTORY_UUID", modeledRecord.getUUID().toString());
// Connect, and wrap the tunnel for return
GuacamoleTunnel tunnel = super.connect(info, updatedTokens);
return new HistoryTrackingTunnel(
tunnel, this.connectionRecordMapper, connectionRecordModel);
<code>@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
// Create a connection record model, starting at the current date/time
ConnectionRecordModel connectionRecordModel = new ConnectionRecordModel();
connectionRecordModel.setStartDate(new Date());
// Set the user information
connectionRecordModel.setUsername(this.currentUser.getIdentifier());
connectionRecordModel.setRemoteHost(this.remoteHost);
// Set the connection information
connectionRecordModel.setConnectionName(this.getDelegateConnection().getName());
// Insert the connection history record to mark the start of this connection
connectionRecordMapper.insert(connectionRecordModel);
// Include history record UUID as token
ModeledConnectionRecord modeledRecord = new ModeledConnectionRecord(connectionRecordModel);
Map<String, String> updatedTokens = new HashMap<>(tokens);
updatedTokens.put("HISTORY_UUID", modeledRecord.getUUID().toString());
// Connect, and wrap the tunnel for return
GuacamoleTunnel tunnel = super.connect(info, updatedTokens);
return new HistoryTrackingTunnel(
tunnel, this.connectionRecordMapper, connectionRecordModel);
}
</code>
@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
// Create a connection record model, starting at the current date/time
ConnectionRecordModel connectionRecordModel = new ConnectionRecordModel();
connectionRecordModel.setStartDate(new Date());
// Set the user information
connectionRecordModel.setUsername(this.currentUser.getIdentifier());
connectionRecordModel.setRemoteHost(this.remoteHost);
// Set the connection information
connectionRecordModel.setConnectionName(this.getDelegateConnection().getName());
// Insert the connection history record to mark the start of this connection
connectionRecordMapper.insert(connectionRecordModel);
// Include history record UUID as token
ModeledConnectionRecord modeledRecord = new ModeledConnectionRecord(connectionRecordModel);
Map<String, String> updatedTokens = new HashMap<>(tokens);
updatedTokens.put("HISTORY_UUID", modeledRecord.getUUID().toString());
// Connect, and wrap the tunnel for return
GuacamoleTunnel tunnel = super.connect(info, updatedTokens);
return new HistoryTrackingTunnel(
tunnel, this.connectionRecordMapper, connectionRecordModel);
}
Based on this, I wrote the following PostgreSQL function to try to generate the UUID:
<code>CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE OR REPLACE FUNCTION generate_connection_uuid(
connection_record RECORD;
-- Retrieve connection data based on p_history_id
to_char(start_date, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS start_date,
FROM guacamole_connection_history gch
WHERE gch.history_id = p_history_id;
-- Check if the record exists
RAISE EXCEPTION 'Record with given p_history_id does not exist';
-- Combine fields into a unique string
unique_string := connection_record.username || '-' ||
connection_record.remote_host || '-' ||
connection_record.start_date || '-' ||
connection_record.connection_name;
-- Generate UUID based on namespace and unique string
generated_uuid := uuid_generate_v5(p_namespace, unique_string);
<code>CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE OR REPLACE FUNCTION generate_connection_uuid(
p_history_id BIGINT,
p_namespace UUID
) RETURNS UUID AS $$
DECLARE
connection_record RECORD;
unique_string TEXT;
generated_uuid UUID;
BEGIN
-- Retrieve connection data based on p_history_id
SELECT
username,
remote_host,
to_char(start_date, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS start_date,
connection_name
INTO connection_record
FROM guacamole_connection_history gch
WHERE gch.history_id = p_history_id;
-- Check if the record exists
IF NOT FOUND THEN
RAISE EXCEPTION 'Record with given p_history_id does not exist';
END IF;
-- Combine fields into a unique string
unique_string := connection_record.username || '-' ||
connection_record.remote_host || '-' ||
connection_record.start_date || '-' ||
connection_record.connection_name;
-- Generate UUID based on namespace and unique string
generated_uuid := uuid_generate_v5(p_namespace, unique_string);
RETURN generated_uuid;
END;
$$ LANGUAGE plpgsql;
</code>
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE OR REPLACE FUNCTION generate_connection_uuid(
p_history_id BIGINT,
p_namespace UUID
) RETURNS UUID AS $$
DECLARE
connection_record RECORD;
unique_string TEXT;
generated_uuid UUID;
BEGIN
-- Retrieve connection data based on p_history_id
SELECT
username,
remote_host,
to_char(start_date, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS start_date,
connection_name
INTO connection_record
FROM guacamole_connection_history gch
WHERE gch.history_id = p_history_id;
-- Check if the record exists
IF NOT FOUND THEN
RAISE EXCEPTION 'Record with given p_history_id does not exist';
END IF;
-- Combine fields into a unique string
unique_string := connection_record.username || '-' ||
connection_record.remote_host || '-' ||
connection_record.start_date || '-' ||
connection_record.connection_name;
-- Generate UUID based on namespace and unique string
generated_uuid := uuid_generate_v5(p_namespace, unique_string);
RETURN generated_uuid;
END;
$$ LANGUAGE plpgsql;
I tested this function with the following namespaces:
<code>SELECT generate_connection_uuid(464, '8b55f070-95f4-3d31-93ee-9c5845e7aa40');
SELECT generate_connection_uuid(464, 'e104741a-c949-3947-8d79-f3f2cdce7d6f');
SELECT generate_connection_uuid(464, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
<code>SELECT generate_connection_uuid(464, '8b55f070-95f4-3d31-93ee-9c5845e7aa40');
SELECT generate_connection_uuid(464, 'e104741a-c949-3947-8d79-f3f2cdce7d6f');
SELECT generate_connection_uuid(464, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
</code>
SELECT generate_connection_uuid(464, '8b55f070-95f4-3d31-93ee-9c5845e7aa40');
SELECT generate_connection_uuid(464, 'e104741a-c949-3947-8d79-f3f2cdce7d6f');
SELECT generate_connection_uuid(464, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');