Skip to content

Commit

Permalink
define/use an additional secret key
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Jun 14, 2022
1 parent 55fafa5 commit 881e3db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private AuthenticatedUser getAuthenticatedUserFromSignedUrl() {
//ToDo - add null checks/ verify that calling methods catch things.
String user = httpRequest.getParameter("user");
AuthenticatedUser targetUser = authSvc.getAuthenticatedUser(user);
String key = authSvc.findApiTokenByUser(targetUser).getTokenString();
String key = System.getProperty(SystemConfig.API_SIGNING_SECRET,"") + authSvc.findApiTokenByUser(targetUser).getTokenString();
String signedUrl = httpRequest.getRequestURL().toString();
String method = httpRequest.getMethod();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ public Response getSignedUrl(JsonObject urlInfo) throws WrappedResponse {
userId=superuser.getIdentifier();
//We ~know this exists - the superuser just used it and it was unexpired/not disabled. (ToDo - if we want this to work with workflow tokens (or as a signed URL, we should do more checking as for the user above))
}
key = authSvc.findApiTokenByUser(superuser).getTokenString();
key = System.getProperty(SystemConfig.API_SIGNING_SECRET,"") + authSvc.findApiTokenByUser(superuser).getTokenString();
}
if(key==null) {
return error(Response.Status.CONFLICT, "Do not have a valid user with apiToken");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public class SystemConfig {
public final static String DEFAULTCURATIONLABELSET = "DEFAULT";
public final static String CURATIONLABELSDISABLED = "DISABLED";

// A secret used in signing URLs - individual urls are signed using this and the
// intended user's apiKey, creating an aggregate key that is unique to the user
// but not known to the user (as their apiKey is)
public final static String API_SIGNING_SECRET = "dataverse.api-signing-secret;";

public String getVersion() {
return getVersion(false);
}
Expand Down

0 comments on commit 881e3db

Please sign in to comment.