Repository navigation
fix: escape RUFLET_ANDROID_* signing values in key.properties so Gradle reads them as set - #132
Merged
Merged
Conversation
…le reads them as set The client's build.gradle.kts reads build/client/android/key.properties with java.util.Properties#load, which decodes backslash escapes and reads the file as ISO-8859-1. The CLI wrote the RUFLET_ANDROID_* values raw, so a password with a backslash or non-ASCII text reached Gradle as another value (p\ssw0rd#1 -> pssw0rd#1, pässwörd -> pässwörd), a trailing backslash swallowed the keyAlias line, and under a C/POSIX locale a non-ASCII value raised Encoding::UndefinedConversionError. A relative storeFile resolved against a non-ASCII project folder was garbled too. - Escape what load misreads in the values taken from the environment (backslash, LF, CR, a leading blank, non-ASCII as \uXXXX UTF-16 code units). Values load already reads correctly are written byte for byte as before. - Copy the project's own key.properties values unchanged; escape only the non-ASCII characters of the storeFile the CLI resolves against the project folder. - Treat binary-tagged values (C locale) as UTF-8 instead of raising. - Create key.properties 0600 and reset the mode on a leftover file. Fixes #131
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #131
What changed
packages/ruflet/lib/ruflet/cli/build/native_config/gradle.rb: the client'sbuild.gradle.ktsreadsbuild/client/android/key.propertieswithjava.util.Properties#load. That loader decodes backslash escapes, ends a value at a line break, skips the blanks a value starts with, and reads the file as ISO-8859-1. The CLI now writes values so thatloadreturns them as set.RUFLET_ANDROID_*values (the passwords themselves, plus the expanded keystore path) are escaped, but only whereloadwould misread them:\becomes\\;\nand\r;\uXXXXUTF-16 code units, asProperties#storewrites it.A leading
#/!, tabs and form feeds are left alone.Properties#storewould escape them, butloadalready reads them correctly, so escaping them would change working output.The project's own
android/key.propertiesis Properties text already, so its values are copied unchanged. The one exception is the relativestoreFilethe CLI resolves against the project folder: its non-ASCII characters (from a folder such asDéveloppement) are escaped. Its backslashes are the author's escapes and stay as written. Raw non-ASCII can never be read back byload.C/POSIX locale: Ruby tags the environment as binary there. Those values are treated as UTF-8 bytes instead of raising
Encoding::UndefinedConversionErrorinwrite_text_file. Values in another locale encoding are transcoded, as writing them did before.File mode:
key.propertiesholds plaintext passwords, so it is created0600and the mode is reset on a file an earlier build left inbuild/client.The
.stripof environment values is unchanged.Tests:
test/build_android_signing_test.rb(new) reads the written file through a port of the JDK'sProperties.load(LineReader and loadConvert). When a JVM is installed, it checks that port and the escaping againstjava.util.Propertiesitself; otherwise that test skips. It covers:0600mode on a new file and on a leftover file.#,!,=,:, tab, FF) and a project file in an ASCII folder are written byte for byte as before. Both also pass on unmodified main.build-apk-with-escaped-signing-env: a backslash and a non-ASCII password. The existingbuild-apk-with-signing-envandbuild-apk-with-partial-signing-envgoldens are unchanged.How verified
gradle.rbwith the new tests in place. UnderLANG=en_US.UTF-8, 7 of the 9 new tests fail: 5 failures and 2 errors. The two hard-rule tests pass. The new golden fails with the rawcompat\not-a-secret/compat-pässwörd-€content, and the two existing signing goldens pass.ruby test/compat/compat.rb --jobs 4reports 359 goldens checked, 0 failing.packages/ruflet/test/*_test.rb, run one process per file (28 files), has 0 failures and 0 errors.LANG=en_US.UTF-8andLC_ALL=C.apply_android_signing_configand read the result withjava.util.Properties:p\ssw0rd#1,C:\keys\pass,pa\ss\word,pässwörd€😀andendslash\load back exactly, andkeyAliasis no longer swallowed.storeFileinDéveloppement/loads as the real path andFile.exists()is true..ruby-version3.4.5.Behavior changes
Every configuration that works today writes byte-identical
key.propertiescontent. That covers plain ASCII values, and a project file with any escapes in an ASCII folder. The changed outputs below are all bug fixes:RUFLET_ANDROID_*value containing a backslash, a line break or non-ASCII text is now escaped. Before, Gradle read a different password and release signing failed with "keystore password was incorrect", or the CLI crashed under a C locale. Visible to one group: someone who worked around the bug by pre-escaping a CI secret (settingC:\\keys\\passto meanC:\keys\pass, or pasting escaped values fromkey.properties) now gets the literal value. They need to set the plain password instead. The docs say to "set the same values in the environment"; the environment values are the passwords themselves.storeFilefrom the project'sandroid/key.properties, resolved against a folder with non-ASCII characters, now has those characters escaped. Before, Gradle could not find the keystore.build/client/android/key.propertiesis now mode0600instead of following the umask (usually0644). Gradle runs as the same user, so builds are unaffected.Docs note (not edited here):
publishing_android.mdsays "In CI, set the same values in the environment instead". It could say that these are the plain values, not Properties-escaped text.