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

Fix null pointer exception #2761

Merged
merged 2 commits into from
Sep 23, 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
Expand Up @@ -9,7 +9,6 @@

import java.security.interfaces.*;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -86,8 +85,12 @@ private static String computeHash(InputStream dataStream) {
throw new CodePushUnknownException("Unable to compute hash of update contents.", e);
} finally {
try {
if (digestInputStream != null) digestInputStream.close();
if (dataStream != null) dataStream.close();
if (digestInputStream != null) {
digestInputStream.close();
}
if (dataStream != null) {
dataStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -98,7 +101,11 @@ private static String computeHash(InputStream dataStream) {
}

public static void copyNecessaryFilesFromCurrentPackage(String diffManifestFilePath, String currentPackageFolderPath, String newPackageFolderPath) throws IOException {
FileUtils.copyDirectoryContents(currentPackageFolderPath, newPackageFolderPath);
if (currentPackageFolderPath == null || !new File(currentPackageFolderPath).exists()) {
CodePushUtils.log("Unable to copy files from current package during diff update, because currentPackageFolderPath is invalid.");
return;
}
FileUtils.copyDirectoryContents(currentPackageFolderPath, newPackageFolderPath);
JSONObject diffManifest = CodePushUtils.getJsonObjectFromFile(diffManifestFilePath);
try {
JSONArray deletedFiles = diffManifest.getJSONArray("deletedFiles");
Expand Down Expand Up @@ -184,7 +191,7 @@ public static void verifyFolderHash(String folderPath, String expectedHash) {
public static Map<String, Object> verifyAndDecodeJWT(String jwt, PublicKey publicKey) {
try {
SignedJWT signedJWT = SignedJWT.parse(jwt);
JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey)publicKey);
JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) publicKey);
if (signedJWT.verify(verifier)) {
Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
CodePushUtils.log("JWT verification succeeded, payload content: " + claims.toString());
Expand Down Expand Up @@ -217,7 +224,7 @@ public static PublicKey parsePublicKey(String stringPublicKey) {
}
}

public static String getSignatureFilePath(String updateFolderPath){
public static String getSignatureFilePath(String updateFolderPath) {
return CodePushUtils.appendPathComponent(
CodePushUtils.appendPathComponent(updateFolderPath, CodePushConstants.CODE_PUSH_FOLDER_PREFIX),
CodePushConstants.BUNDLE_JWT_FILE
Expand Down Expand Up @@ -254,7 +261,7 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,
throw new CodePushInvalidUpdateException("The update could not be verified because it was not signed by a trusted party.");
}

final String contentHash = (String)claims.get("contentHash");
final String contentHash = (String) claims.get("contentHash");
if (contentHash == null) {
throw new CodePushInvalidUpdateException("The update could not be verified because the signature did not specify a content hash.");
}
Expand All @@ -265,4 +272,4 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,

CodePushUtils.log("The update contents succeeded the code signing check.");
}
}
}