Skip to content

Commit cf717dc

Browse files
Added missing require statement for the new JWT Key class, reverted the JWT signing algorith to HS256 is RS256 and ES256 don't seem to be supported by OpenSSL on pfSense 2.5
1 parent 2e530bd commit cf717dc

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎pfSense-pkg-API/files/etc/inc/api/framework/APITools.inc‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require_once("php-jwt/src/JWT.php");
1818
require_once("php-jwt/src/ExpiredException.php");
1919
require_once("php-jwt/src/SignatureInvalidException.php");
2020
require_once("php-jwt/src/BeforeValidException.php");
21+
require_once("php-jwt/src/Key.php");
2122
require_once("config.inc");
2223
require_once("util.inc");
2324
require_once("interfaces.inc");
@@ -131,25 +132,28 @@ function create_jwt_server_key($rotate=false) {
131132
function create_jwt($data) {
132133
global $config;
133134

134-
# Pull the API configuration and extract the jwt expiration value, then ensure a server key exists.
135+
# Pull the API configuration and extract the jwt expiration value, then ensure a server key and payload exists.
135136
$api_config = get_api_config()[1];
136137
$token_exp = $api_config["jwt_exp"];
137138
create_jwt_server_key();
138139
$payload = array(
139140
"iss" => $config["system"]["hostname"],
141+
"aud" => $config["system"]["hostname"],
140142
"exp" => time() + $token_exp,
141143
"nbf" => time(),
142144
"data" => $data
143145
);
144-
return JWT::encode($payload, $api_config["server_key"], "ES256");
146+
147+
# Return the encoded JWT
148+
return JWT::encode($payload, $api_config["server_key"], "HS256");
145149
}
146150

147151
# Decodes a JWT using our store server key
148152
function decode_jwt($token) {
149153
$token = (is_string($token)) ? $token : "";
150-
$key = get_api_config()[1]["server_key"]; // Save our current server key
154+
$key = get_api_config()[1]["server_key"];
151155
try {
152-
$decoded = (array) JWT::decode($token, new Key($key, "ES256"));
156+
$decoded = (array) JWT::decode($token, new Key($key, "HS256"));
153157
} catch (\Exception $e) {
154158
$decoded = false;
155159
}

0 commit comments

Comments
 (0)