Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abandoned MD5 to SHA-256 used for caching command models #25148

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -21,23 +22,26 @@
import jakarta.xml.bind.DatatypeConverter;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

import org.glassfish.api.Param;
import org.glassfish.api.admin.CommandModel;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Stores ETeg with command model.
* Stores ETag with command model.
*
* @author mmares
*/
public class CachedCommandModel extends CommandModelData {

private String eTag;
private String usage;
private boolean addedUploadOption = false;
private boolean addedUploadOption;

public CachedCommandModel(String name) {
super(name);
Expand Down Expand Up @@ -100,7 +104,7 @@ public static String computeETag(CommandModel cm) {
}
if (cm.getParameters() != null) {
//sort
SortedSet<ParamModel> tree = new TreeSet<ParamModel>(new Comparator<ParamModel>() {
SortedSet<ParamModel> tree = new TreeSet<>(new Comparator<ParamModel>() {
@Override
public int compare(ParamModel o1, ParamModel o2) {
return o1.getName().compareTo(o2.getName());
Expand Down Expand Up @@ -143,12 +147,11 @@ public int compare(ParamModel o1, ParamModel o2) {
}
}
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(tag.toString().getBytes("UTF-8"));
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(tag.toString().getBytes(UTF_8));
return DatatypeConverter.printBase64Binary(md.digest());
} catch (Exception ex) {
return "v2" + tag.toString();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("Cannot cache commands!", e);
}
}

}