Skip to content

Commit f214077

Browse files
committed
More OAuth/OpenID changes for the scheduler:
- Instead of treating the bearer token as a JWT, use the userinfo endpoint (via cupsOAuthGetUserId) to get the user information and (as a side-effect) validate the bearer token. - Set the verified AuthType when get have a valid token. - Support OAuth group files relative to the cupsd.conf file.
1 parent c0ea9cb commit f214077

4 files changed

Lines changed: 16 additions & 25 deletions

File tree

scheduler/auth.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */
710710
else if (!strncmp(authorization, "Bearer ", 7))
711711
{
712712
// OAuth/OpenID authorization using JWT bearer tokens...
713-
cups_jwt_t *jwt; // JWT decoded from bearer token...
713+
cups_jwt_t *jwt; // JWT user information
714714
const char *sub, // Subject/user ID
715715
*name, // Real name
716716
*email; // Email address
@@ -724,35 +724,22 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */
724724
authorization = bearer; // Use the cookie value for authorization
725725

726726
// Decode and validate the JWT...
727-
if ((jwt = cupsJWTImportString(authorization, CUPS_JWS_FORMAT_COMPACT)) == NULL)
727+
if ((jwt = cupsOAuthGetUserId(OAuthServer, OAuthMetadata, authorization)) == NULL)
728728
{
729-
cupsdLogClient(con, CUPSD_LOG_ERROR, "Unable to import JWT Bearer token: %s", cupsGetErrorString());
729+
cupsdLogClient(con, CUPSD_LOG_ERROR, "Unable to get user information from bearer token: %s", cupsGetErrorString());
730730
cupsCopyString(con->autherror, cupsGetErrorString(), sizeof(con->autherror));
731731
return;
732732
}
733-
else if (!cupsJWTHasValidSignature(jwt, OAuthJWKS))
734-
{
735-
cupsdLogClient(con, CUPSD_LOG_ERROR, "JWT Bearer token signature is bad.");
736-
cupsCopyString(con->autherror, "Invalid JWT signature.", sizeof(con->autherror));
737-
cupsJWTDelete(jwt);
738-
return;
739-
}
740-
else if (cupsJWTGetClaimNumber(jwt, CUPS_JWT_EXP) < time(NULL))
741-
{
742-
cupsdLogClient(con, CUPSD_LOG_ERROR, "JWT Bearer token is expired.");
743-
cupsCopyString(con->autherror, "Expired JWT.", sizeof(con->autherror));
744-
cupsJWTDelete(jwt);
745-
return;
746-
}
747733
else if ((sub = cupsJWTGetClaimString(jwt, CUPS_JWT_SUB)) == NULL)
748734
{
749-
cupsdLogClient(con, CUPSD_LOG_ERROR, "Missing subject name in JWT Bearer token.");
735+
cupsdLogClient(con, CUPSD_LOG_ERROR, "Missing subject name in user information.");
750736
cupsCopyString(con->autherror, "Missing subject name.", sizeof(con->autherror));
751737
cupsJWTDelete(jwt);
752738
return;
753739
}
754740

755741
// Good JWT, grab information from it and return...
742+
con->type = CUPSD_AUTH_BEARER;
756743
con->autherror[0] = '\0';
757744
con->password[0] = '\0';
758745

scheduler/auth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
#include <pwd.h>
13-
#include <cups/jwt.h>
13+
#include <cups/oauth.h>
1414

1515

1616
/*

scheduler/conf.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3698,7 +3698,8 @@ read_cups_files_conf(cups_file_t *fp) /* I - File to read from */
36983698
* OAuthGroup NAME FILENAME
36993699
*/
37003700

3701-
char *filename; /* Filename on line */
3701+
char temp[1024], /* Temporary filename */
3702+
*filename; /* Filename on line */
37023703

37033704
for (filename = value; *filename; filename ++)
37043705
{
@@ -3709,6 +3710,13 @@ read_cups_files_conf(cups_file_t *fp) /* I - File to read from */
37093710
while (*filename && isspace(*filename & 255))
37103711
*filename++ = '\0';
37113712

3713+
if (*filename != '/')
3714+
{
3715+
// Convert relative filename to CUPS_SERVERROOT/filename
3716+
snprintf(temp, sizeof(temp), "%s/%s", ServerRoot, filename);
3717+
filename = temp;
3718+
}
3719+
37123720
if (*filename && !access(filename, R_OK))
37133721
{
37143722
if (!cupsdAddOAuthGroup(value, filename) && (FatalErrors & CUPSD_FATAL_CONFIG))

scheduler/env.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/*
22
* Environment management routines for the CUPS scheduler.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2025 by OpenPrinting.
55
* Copyright © 2007-2016 by Apple Inc.
66
* Copyright © 1997-2006 by Easy Software Products, all rights reserved.
77
*
88
* Licensed under Apache License v2.0. See the file "LICENSE" for more
99
* information.
1010
*/
1111

12-
/*
13-
* Include necessary headers...
14-
*/
15-
1612
#include "cupsd.h"
1713

1814

0 commit comments

Comments
 (0)