Skip to content

Commit 18ebd2e

Browse files
authored
Merge pull request #6 from djw8605/add-uuid
Adding UUID for jti generation
2 parents dafd864 + 16de433 commit 18ebd2e

File tree

4 files changed

+130
-2
lines changed

4 files changed

+130
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
66

77
find_package( jwt-cpp REQUIRED )
88
find_package( CURL REQUIRED )
9+
find_package( UUID REQUIRED )
910

1011
if( CMAKE_COMPILER_IS_GNUCXX )
1112
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror" )
@@ -33,10 +34,10 @@ endif()
3334

3435
pkg_check_modules(SQLITE REQUIRED sqlite3)
3536

36-
include_directories( "${PROJECT_SOURCE_DIR}" ${JWT_CPP_INCLUDES} ${CURL_INCLUDES} ${LIBCRYPTO_INCLUDE_DIRS} ${SQLITE_INCLUDE_DIRS})
37+
include_directories( "${PROJECT_SOURCE_DIR}" ${JWT_CPP_INCLUDES} ${CURL_INCLUDES} ${LIBCRYPTO_INCLUDE_DIRS} ${SQLITE_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} )
3738

3839
add_library(SciTokens SHARED src/scitokens.cpp src/scitokens_internal.cpp src/scitokens_cache.cpp)
39-
target_link_libraries(SciTokens ${LIBCRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${SQLITE_LIBRARIES})
40+
target_link_libraries(SciTokens ${LIBCRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${SQLITE_LIBRARIES} ${UUID_LIBRARIES})
4041

4142
if ( UNIX )
4243
set_target_properties(SciTokens PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/configs/export-symbols")

cmake/FindUUID.cmake

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# - Try to find UUID
2+
# Once done this will define
3+
#
4+
# UUID_FOUND - system has UUID
5+
# UUID_INCLUDE_DIRS - the UUID include directory
6+
# UUID_LIBRARIES - Link these to use UUID
7+
# UUID_DEFINITIONS - Compiler switches required for using UUID
8+
#
9+
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
10+
#
11+
# Redistribution and use is allowed according to the terms of the New
12+
# BSD license.
13+
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14+
#
15+
16+
include(CheckSymbolExists)
17+
18+
# On mac, it can't find uuid library
19+
# So, just check for the functions with the default include
20+
CHECK_SYMBOL_EXISTS("uuid_generate" "uuid/uuid.h" UUID_SYMBOL)
21+
22+
if (UUID_SYMBOL)
23+
set(UUID_FOUND TRUE)
24+
elseif (UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
25+
# in cache already
26+
set(UUID_FOUND TRUE)
27+
else (UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
28+
find_path(UUID_INCLUDE_DIR
29+
NAMES
30+
uuid/uuid.h
31+
PATHS
32+
${UUID_DIR}/include
33+
$ENV{UUID_DIR}/include
34+
$ENV{UUID_DIR}
35+
${DELTA3D_EXT_DIR}/inc
36+
$ENV{DELTA_ROOT}/ext/inc
37+
$ENV{DELTA_ROOT}
38+
~/Library/Frameworks
39+
/Library/Frameworks
40+
/usr/local/include
41+
/usr/include
42+
/usr/include/gdal
43+
/sw/include # Fink
44+
/opt/local/include # DarwinPorts
45+
/opt/csw/include # Blastwave
46+
/opt/include
47+
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include
48+
/usr/freeware/include
49+
)
50+
51+
find_library(UUID_LIBRARY
52+
NAMES
53+
uuid
54+
PATHS
55+
${UUID_DIR}/lib
56+
$ENV{UUID_DIR}/lib
57+
$ENV{UUID_DIR}
58+
${DELTA3D_EXT_DIR}/lib
59+
$ENV{DELTA_ROOT}/ext/lib
60+
$ENV{DELTA_ROOT}
61+
$ENV{OSG_ROOT}/lib
62+
~/Library/Frameworks
63+
/Library/Frameworks
64+
/usr/local/lib
65+
/usr/lib
66+
/sw/lib
67+
/opt/local/lib
68+
/opt/csw/lib
69+
/opt/lib
70+
/usr/freeware/lib64
71+
)
72+
73+
find_library(UUID_LIBRARY_DEBUG
74+
NAMES
75+
uuidd
76+
PATHS
77+
${UUID_DIR}/lib
78+
$ENV{UUID_DIR}/lib
79+
$ENV{UUID_DIR}
80+
${DELTA3D_EXT_DIR}/lib
81+
$ENV{DELTA_ROOT}/ext/lib
82+
$ENV{DELTA_ROOT}
83+
$ENV{OSG_ROOT}/lib
84+
~/Library/Frameworks
85+
/Library/Frameworks
86+
/usr/local/lib
87+
/usr/lib
88+
/sw/lib
89+
/opt/local/lib
90+
/opt/csw/lib
91+
/opt/lib
92+
/usr/freeware/lib64
93+
)
94+
95+
set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR})
96+
set(UUID_LIBRARIES ${UUID_LIBRARY})
97+
98+
if (UUID_INCLUDE_DIRS AND UUID_LIBRARIES)
99+
set(UUID_FOUND TRUE)
100+
endif (UUID_INCLUDE_DIRS AND UUID_LIBRARIES)
101+
102+
if (UUID_FOUND)
103+
if (NOT UUID_FIND_QUIETLY)
104+
message(STATUS "Found UUID : ${UUID_LIBRARIES}")
105+
endif (NOT UUID_FIND_QUIETLY)
106+
else (UUID_FOUND)
107+
if (UUID_FIND_REQUIRED)
108+
message(FATAL_ERROR "Could not find UUID")
109+
endif (UUID_FIND_REQUIRED)
110+
endif (UUID_FOUND)
111+
112+
# show the UUID_INCLUDE_DIRS and UUID_LIBRARIES variables only in the advanced view
113+
mark_as_advanced(UUID_INCLUDE_DIRS UUID_LIBRARIES)
114+
115+
endif (UUID_SYMBOL)

src/scitokens_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sstream>
44

55
#include <jwt-cpp/jwt.h>
6+
#include <uuid/uuid.h>
67

78
namespace scitokens {
89

@@ -135,6 +136,12 @@ friend class scitokens::Validator;
135136
m_builder.set_not_before(time);
136137
m_builder.set_expires_at(time + std::chrono::seconds(m_lifetime));
137138

139+
uuid_t uuid;
140+
uuid_generate(uuid);
141+
char uuid_str[37];
142+
uuid_unparse_lower(uuid, uuid_str);
143+
m_builder.set_payload_claim("jti", std::string(uuid_str));
144+
138145
// TODO: handle JTI
139146
return m_key.serialize(m_builder);
140147
}

src/test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ int main(int argc, const char** argv) {
3737
return 1;
3838
}
3939
std::cout << "SciToken: " << value << std::endl;
40+
auto decoded2 = jwt::decode(value);
41+
42+
for (auto& e : decoded2.get_payload_claims())
43+
std::cout << e.first << " = " << e.second.to_json() << std::endl;
44+
4045
scitoken_destroy(scitoken);
4146
scitoken_key_destroy(key);
4247

0 commit comments

Comments
 (0)