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

Commit 1381c1ad authored by Mathew Inwood's avatar Mathew Inwood
Browse files

Use base64 encoded config in metadata.

Encoding it in plain text makes escaping it really fiddley and hard to get
right. Base64 encoding it sidesteps these issues.

Bug: 110509075
Test: atest CtsSignedConfigHostTestCases
Change-Id: Id5de418ebf0bd1d147e006a1529f13af52c8485e
parent 9a7fdeb3
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,9 @@ import android.util.Slog;


import com.android.server.LocalServices;
import com.android.server.LocalServices;


import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
/**
 * Signed config service. This is not an Android Service, but just owns a broadcast receiver for
 * Signed config service. This is not an Android Service, but just owns a broadcast receiver for
 * receiving package install and update notifications from the package manager.
 * receiving package install and update notifications from the package manager.
@@ -81,6 +84,13 @@ public class SignedConfigService {
                && metaData.containsKey(KEY_CONFIG_SIGNATURE)) {
                && metaData.containsKey(KEY_CONFIG_SIGNATURE)) {
            String config = metaData.getString(KEY_CONFIG);
            String config = metaData.getString(KEY_CONFIG);
            String signature = metaData.getString(KEY_CONFIG_SIGNATURE);
            String signature = metaData.getString(KEY_CONFIG_SIGNATURE);
            try {
                // Base64 encoding is standard (not URL safe) encoding: RFC4648
                config = new String(Base64.getDecoder().decode(config), StandardCharsets.UTF_8);
            } catch (IllegalArgumentException iae) {
                Slog.e(TAG, "Failed to base64 decode config from " + packageName);
                return;
            }
            if (DBG) {
            if (DBG) {
                Slog.d(TAG, "Got signed config: " + config);
                Slog.d(TAG, "Got signed config: " + config);
                Slog.d(TAG, "Got config signature: " + signature);
                Slog.d(TAG, "Got config signature: " + signature);