Skip to content

Commit

Permalink
Fix PayPal crash when device name is too long
Browse files Browse the repository at this point in the history
Reported in #67
  • Loading branch information
lkorth committed Jan 14, 2016
1 parent 6bb39f8 commit ac674f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ private JSONObject getJsonObjectToEncrypt() throws JSONException {
payloadEnc.put("timestamp", new RFC3339DateFormat().format(new Date()));
payloadEnc.put("msg_GUID", mMsgGuid);
payloadEnc.put("sym_key", EncryptionUtils.byteArrayToHexString(mEncryptionKey));
payloadEnc.put("device_name", DeviceInspector.getDeviceName());
String deviceName = DeviceInspector.getDeviceName();
payloadEnc.put("device_name", deviceName.substring(0, Math.min(deviceName.length(), 30)));
return payloadEnc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class OtcCrypto {
private static final int AES_KEY_SIZE = 16;
private static final int DIGEST_SIZE = 32;
private static final int PUBLIC_KEY_SIZE = 256;
private static final int MAX_RSA_ENCRYPTABLE_BYTES = 214;

private byte[] dataDigest(byte[] data, byte[] key)
throws NoSuchAlgorithmException, InvalidKeyException {
Expand All @@ -42,9 +43,9 @@ public byte[] generateRandom256BitKey() {
public byte[] encryptRSAData(byte[] plainData, Certificate certificate)
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, InvalidEncryptionDataException {
// data cannot be bigger than 256 bytes
if (plainData.length > PUBLIC_KEY_SIZE) {
throw new InvalidEncryptionDataException("Data is too large for public key encryption");
if (plainData.length > MAX_RSA_ENCRYPTABLE_BYTES) {
throw new InvalidEncryptionDataException("Data is too large for public key encryption: " +
plainData.length + " > " + MAX_RSA_ENCRYPTABLE_BYTES);
}

PublicKey publicKey = certificate.getPublicKey();
Expand Down

0 comments on commit ac674f2

Please sign in to comment.