mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
better feedback on unsuccessful license
This commit is contained in:
parent
2ec56b2dba
commit
ed444f4661
@ -32,18 +32,21 @@ public class LicenseResponse {
|
|||||||
private final Boolean hostChanged;
|
private final Boolean hostChanged;
|
||||||
private final Long hostChangesRemaining;
|
private final Long hostChangesRemaining;
|
||||||
private final BoostLicenseResponse boostLicense;
|
private final BoostLicenseResponse boostLicense;
|
||||||
|
private final String errorMsg;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public LicenseResponse(
|
public LicenseResponse(
|
||||||
@JsonProperty("success") Boolean success,
|
@JsonProperty("success") Boolean success,
|
||||||
@JsonProperty("hostChanged") Boolean hostChanged,
|
@JsonProperty("hostChanged") Boolean hostChanged,
|
||||||
@JsonProperty("hostChangesRemaining") Long hostChangesRemaining,
|
@JsonProperty("hostChangesRemaining") Long hostChangesRemaining,
|
||||||
@JsonProperty("boostLicense") BoostLicenseResponse boostLicense
|
@JsonProperty("boostLicense") BoostLicenseResponse boostLicense,
|
||||||
|
@JsonProperty("errorMsg") String errorMsg
|
||||||
) {
|
) {
|
||||||
this.success = success;
|
this.success = success;
|
||||||
this.hostChanged = hostChanged;
|
this.hostChanged = hostChanged;
|
||||||
this.hostChangesRemaining = hostChangesRemaining;
|
this.hostChangesRemaining = hostChangesRemaining;
|
||||||
this.boostLicense = boostLicense;
|
this.boostLicense = boostLicense;
|
||||||
|
this.errorMsg = errorMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isSuccess() {
|
public Boolean isSuccess() {
|
||||||
@ -61,4 +64,8 @@ public class LicenseResponse {
|
|||||||
public BoostLicenseResponse getBoostLicense() {
|
public BoostLicenseResponse getBoostLicense() {
|
||||||
return boostLicense;
|
return boostLicense;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getErrorMsg() {
|
||||||
|
return errorMsg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import java.security.PublicKey;
|
|||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.KeySpec;
|
import java.security.spec.KeySpec;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
@ -42,6 +43,7 @@ import javax.crypto.NoSuchPaddingException;
|
|||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.spec.IvParameterSpec;
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypts the payload of boost license.
|
* Decrypts the payload of boost license.
|
||||||
@ -58,12 +60,12 @@ public class LicenseDecryptorUtil {
|
|||||||
|
|
||||||
private LicenseDecryptorUtil() {
|
private LicenseDecryptorUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LicenseInfo createLicenseInfo(LicenseResponse licenseResponse) throws JsonProcessingException, InvalidLicenseException {
|
public LicenseInfo createLicenseInfo(LicenseResponse licenseResponse) throws JsonProcessingException, InvalidLicenseException {
|
||||||
if (licenseResponse == null || licenseResponse.getBoostLicense() == null) {
|
if (licenseResponse == null) {
|
||||||
throw new InvalidLicenseException("License or boost license are null");
|
throw new InvalidLicenseException("License is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
DecryptedLicenseResponse decrypted = parseLicenseJSON(licenseResponse.getBoostLicense());
|
DecryptedLicenseResponse decrypted = parseLicenseJSON(licenseResponse.getBoostLicense());
|
||||||
return new LicenseInfo(licenseResponse, decrypted);
|
return new LicenseInfo(licenseResponse, decrypted);
|
||||||
}
|
}
|
||||||
@ -78,6 +80,9 @@ public class LicenseDecryptorUtil {
|
|||||||
* com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException
|
* com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException
|
||||||
*/
|
*/
|
||||||
public DecryptedLicenseResponse parseLicenseJSON(BoostLicenseResponse licenseResponse) throws JsonProcessingException, InvalidLicenseException {
|
public DecryptedLicenseResponse parseLicenseJSON(BoostLicenseResponse licenseResponse) throws JsonProcessingException, InvalidLicenseException {
|
||||||
|
if (licenseResponse == null) {
|
||||||
|
throw new InvalidLicenseException("Boost license is null");
|
||||||
|
}
|
||||||
|
|
||||||
String decryptedJsonResponse;
|
String decryptedJsonResponse;
|
||||||
try {
|
try {
|
||||||
@ -101,6 +106,12 @@ public class LicenseDecryptorUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String decryptLicenseString(String encryptedJson, String ivBase64, String encryptedKey, String version) throws IOException, GeneralSecurityException, InvalidLicenseException {
|
private String decryptLicenseString(String encryptedJson, String ivBase64, String encryptedKey, String version) throws IOException, GeneralSecurityException, InvalidLicenseException {
|
||||||
|
if (ObjectUtils.anyNull(encryptedJson, ivBase64, encryptedKey, version)) {
|
||||||
|
throw new InvalidLicenseException(MessageFormat.format(
|
||||||
|
"encryptedJson: {0}, iv: {1}, encryptedKey: {2}, version: {3} must all be non-null",
|
||||||
|
encryptedJson, ivBase64, encryptedKey, version));
|
||||||
|
}
|
||||||
|
|
||||||
if (!"1.0".equals(version)) {
|
if (!"1.0".equals(version)) {
|
||||||
throw new InvalidLicenseException("Unexpected file version: " + version);
|
throw new InvalidLicenseException("Unexpected file version: " + version);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_title=License Number Alr
|
|||||||
CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_desc=Please verify that license number is of format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_desc=Please verify that license number is of format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
||||||
CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_title=Invalid License Number
|
CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_title=Invalid License Number
|
||||||
CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error
|
CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error
|
||||||
|
# {0} - licenseCode
|
||||||
|
CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc=Error activating boost license {0}
|
||||||
CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.
|
CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.
|
||||||
CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error
|
CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error
|
||||||
# {0} - expiresDate
|
# {0} - expiresDate
|
||||||
|
@ -608,6 +608,8 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
|
|||||||
@NbBundle.Messages({
|
@NbBundle.Messages({
|
||||||
"CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error",
|
"CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error",
|
||||||
"CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error",
|
"CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error",
|
||||||
|
"# {0} - licenseCode",
|
||||||
|
"CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc=Error activating boost license {0}",
|
||||||
"CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.",})
|
"CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.",})
|
||||||
private class LicenseFetcher extends SwingWorker<LicenseResponse, Void> {
|
private class LicenseFetcher extends SwingWorker<LicenseResponse, Void> {
|
||||||
|
|
||||||
@ -629,10 +631,9 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
|
|||||||
protected void done() {
|
protected void done() {
|
||||||
try {
|
try {
|
||||||
LicenseResponse licenseResponse = get();
|
LicenseResponse licenseResponse = get();
|
||||||
if (licenseResponse != null && licenseResponse.isSuccess()) {
|
// if no result, show unauthorized
|
||||||
SwingUtilities.invokeLater(() -> acceptEula(licenseResponse));
|
if (licenseResponse == null) {
|
||||||
} else {
|
logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch returned no result.");
|
||||||
logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch was not successful");
|
|
||||||
JOptionPane.showMessageDialog(
|
JOptionPane.showMessageDialog(
|
||||||
CTMalwareScannerOptionsPanel.this,
|
CTMalwareScannerOptionsPanel.this,
|
||||||
CTCloudException.ErrorCode.UN_AUTHORIZED.getDescription(),
|
CTCloudException.ErrorCode.UN_AUTHORIZED.getDescription(),
|
||||||
@ -640,7 +641,30 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
|
|||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
setLicenseDisplay(licenseInfo, null);
|
setLicenseDisplay(licenseInfo, null);
|
||||||
loadMalwareScansInfo(licenseInfo);
|
loadMalwareScansInfo(licenseInfo);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if not successful response
|
||||||
|
if (!Boolean.TRUE.equals(licenseResponse.isSuccess())) {
|
||||||
|
logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch was not successful");
|
||||||
|
// use default message unless error message specified
|
||||||
|
String message = Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc(licenseText);
|
||||||
|
if (!StringUtils.isBlank(licenseResponse.getErrorMsg())) {
|
||||||
|
message = licenseResponse.getErrorMsg();
|
||||||
|
}
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
CTMalwareScannerOptionsPanel.this,
|
||||||
|
message,
|
||||||
|
Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title(),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
setLicenseDisplay(licenseInfo, null);
|
||||||
|
loadMalwareScansInfo(licenseInfo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise, load
|
||||||
|
SwingUtilities.invokeLater(() -> acceptEula(licenseResponse));
|
||||||
|
|
||||||
} catch (InterruptedException | CancellationException ex) {
|
} catch (InterruptedException | CancellationException ex) {
|
||||||
// ignore cancellation; just load current license
|
// ignore cancellation; just load current license
|
||||||
setLicenseDisplay(licenseInfo, null);
|
setLicenseDisplay(licenseInfo, null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user