How is UUID for recorded sessions generated in Apache Guacamole?

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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');

New contributor

kk666 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật