9
9
10
10
import java .security .interfaces .*;
11
11
12
-
13
12
import org .json .JSONArray ;
14
13
import org .json .JSONException ;
15
14
import org .json .JSONObject ;
@@ -86,8 +85,12 @@ private static String computeHash(InputStream dataStream) {
86
85
throw new CodePushUnknownException ("Unable to compute hash of update contents." , e );
87
86
} finally {
88
87
try {
89
- if (digestInputStream != null ) digestInputStream .close ();
90
- if (dataStream != null ) dataStream .close ();
88
+ if (digestInputStream != null ) {
89
+ digestInputStream .close ();
90
+ }
91
+ if (dataStream != null ) {
92
+ dataStream .close ();
93
+ }
91
94
} catch (IOException e ) {
92
95
e .printStackTrace ();
93
96
}
@@ -98,7 +101,11 @@ private static String computeHash(InputStream dataStream) {
98
101
}
99
102
100
103
public static void copyNecessaryFilesFromCurrentPackage (String diffManifestFilePath , String currentPackageFolderPath , String newPackageFolderPath ) throws IOException {
101
- FileUtils .copyDirectoryContents (currentPackageFolderPath , newPackageFolderPath );
104
+ if (currentPackageFolderPath == null || !new File (currentPackageFolderPath ).exists ()) {
105
+ CodePushUtils .log ("Unable to copy files from current package during diff update, because currentPackageFolderPath is invalid." );
106
+ return ;
107
+ }
108
+ FileUtils .copyDirectoryContents (currentPackageFolderPath , newPackageFolderPath );
102
109
JSONObject diffManifest = CodePushUtils .getJsonObjectFromFile (diffManifestFilePath );
103
110
try {
104
111
JSONArray deletedFiles = diffManifest .getJSONArray ("deletedFiles" );
@@ -184,7 +191,7 @@ public static void verifyFolderHash(String folderPath, String expectedHash) {
184
191
public static Map <String , Object > verifyAndDecodeJWT (String jwt , PublicKey publicKey ) {
185
192
try {
186
193
SignedJWT signedJWT = SignedJWT .parse (jwt );
187
- JWSVerifier verifier = new RSASSAVerifier ((RSAPublicKey )publicKey );
194
+ JWSVerifier verifier = new RSASSAVerifier ((RSAPublicKey ) publicKey );
188
195
if (signedJWT .verify (verifier )) {
189
196
Map <String , Object > claims = signedJWT .getJWTClaimsSet ().getClaims ();
190
197
CodePushUtils .log ("JWT verification succeeded, payload content: " + claims .toString ());
@@ -217,7 +224,7 @@ public static PublicKey parsePublicKey(String stringPublicKey) {
217
224
}
218
225
}
219
226
220
- public static String getSignatureFilePath (String updateFolderPath ){
227
+ public static String getSignatureFilePath (String updateFolderPath ) {
221
228
return CodePushUtils .appendPathComponent (
222
229
CodePushUtils .appendPathComponent (updateFolderPath , CodePushConstants .CODE_PUSH_FOLDER_PREFIX ),
223
230
CodePushConstants .BUNDLE_JWT_FILE
@@ -254,7 +261,7 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,
254
261
throw new CodePushInvalidUpdateException ("The update could not be verified because it was not signed by a trusted party." );
255
262
}
256
263
257
- final String contentHash = (String )claims .get ("contentHash" );
264
+ final String contentHash = (String ) claims .get ("contentHash" );
258
265
if (contentHash == null ) {
259
266
throw new CodePushInvalidUpdateException ("The update could not be verified because the signature did not specify a content hash." );
260
267
}
@@ -265,4 +272,4 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,
265
272
266
273
CodePushUtils .log ("The update contents succeeded the code signing check." );
267
274
}
268
- }
275
+ }
0 commit comments