Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e411085a authored by Yoshiaki Naka's avatar Yoshiaki Naka Committed by Jordan Liu
Browse files

Avoid logging text string TLV objects in TERMINAL RESPONSE

The text string TLV object shall be hidden in the log as it might
contain personal information like password input by user.

Bug: 68786549
Test: Confirmed that the text string is not output in the radio log.
Change-Id: I6cbf4827db4094e535b5188e522eac9b2f22f988
parent db868671
Loading
Loading
Loading
Loading
+31 −1
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ import android.hardware.radio.V1_0.UusInfo;
import android.hardware.radio.deprecated.V1_0.IOemHook;
import android.hardware.radio.deprecated.V1_0.IOemHook;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.os.AsyncResult;
import android.os.AsyncResult;
import android.os.Build;
import android.os.Handler;
import android.os.Handler;
import android.os.HwBinder;
import android.os.HwBinder;
import android.os.Message;
import android.os.Message;
@@ -86,6 +87,8 @@ import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.cat.ComprehensionTlv;
import com.android.internal.telephony.cat.ComprehensionTlvTag;
import com.android.internal.telephony.cdma.CdmaInformationRecords;
import com.android.internal.telephony.cdma.CdmaInformationRecords;
import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
import com.android.internal.telephony.dataconnection.DataCallResponse;
import com.android.internal.telephony.dataconnection.DataCallResponse;
@@ -2130,7 +2133,7 @@ public class RIL extends BaseCommands implements CommandsInterface {


            if (RILJ_LOGD) {
            if (RILJ_LOGD) {
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " contents = "
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " contents = "
                        + contents);
                        + (Build.IS_DEBUGGABLE ? contents : censoredTerminalResponse(contents)));
            }
            }


            try {
            try {
@@ -2142,6 +2145,33 @@ public class RIL extends BaseCommands implements CommandsInterface {
        }
        }
    }
    }


    private String censoredTerminalResponse(String terminalResponse) {
        try {
            byte[] bytes = IccUtils.hexStringToBytes(terminalResponse);
            if (bytes != null) {
                List<ComprehensionTlv> ctlvs = ComprehensionTlv.decodeMany(bytes, 0);
                int from = 0;
                for (ComprehensionTlv ctlv : ctlvs) {
                    // Find text strings which might be personal information input by user,
                    // then replace it with "********".
                    if (ComprehensionTlvTag.TEXT_STRING.value() == ctlv.getTag()) {
                        byte[] target = Arrays.copyOfRange(ctlv.getRawValue(), from,
                                ctlv.getValueIndex() + ctlv.getLength());
                        terminalResponse = terminalResponse.toLowerCase().replace(
                                IccUtils.bytesToHexString(target), "********");
                    }
                    // The text string tag and the length field should also be hidden.
                    from = ctlv.getValueIndex() + ctlv.getLength();
                }
            }
        } catch (Exception e) {
            Rlog.e(RILJ_LOG_TAG, "Could not censor the terminal response: " + e);
            terminalResponse = null;
        }

        return terminalResponse;
    }

    @Override
    @Override
    public void sendEnvelopeWithStatus(String contents, Message result) {
    public void sendEnvelopeWithStatus(String contents, Message result) {
        IRadio radioProxy = getRadioProxy(result);
        IRadio radioProxy = getRadioProxy(result);
+1 −1
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ import java.util.List;
 *
 *
 * {@hide}
 * {@hide}
 */
 */
class ComprehensionTlv {
public class ComprehensionTlv {
    private static final String LOG_TAG = "ComprehensionTlv";
    private static final String LOG_TAG = "ComprehensionTlv";
    private int mTag;
    private int mTag;
    private boolean mCr;
    private boolean mCr;