진단을 다시 돌리자(signing-check run 11) SIGNING_KEY가 바뀌어 있었다. 4,632글자 한 줄, base64로 읽으면 3,474바이트이고 그 첫 바이트가 `-`였다. 곧 armored 키 파일을 base64로 한 줄에 감싼 값이다(CI secret에 여러 줄 값을 넣을 때 흔히 쓰는 방법). Gradle의 useInMemoryPgpKeys는 armored 글만 읽어서 이 값도 「Could not read PGP secret key」로 실패한다. build-logic SigningKeys.armoured가 값을 받아, armored 블록을 base64로 감싼 것이면 풀어서 돌려준다. 그 밖의 값은 그대로 돌려줘 원래 오류로 실패하게 한다. 모듈 서명(LibraryPublishingPlugin)과 SBOM 서명(루트 build.gradle)이 이것을 거친다. check-signing-key.sh도 같은 규칙으로 풀어 본다. 「form: base64 of an armoured key file」을 알리고 풀린 글로 나머지를 검사한다. 키는 gpg에 환경 변수 대신 임시 폴더(0700, 끝나면 지움)의 파일로 넘긴다. 버린 대안: 소유자에게 여러 줄로 다시 넣게 하기. 지금 값도 키로는 맞을 수 있고, base64 한 줄은 secret 저장소가 여러 줄을 망가뜨릴 때의 표준 우회다. 검증(desktop, 버리는 RSA 4096 키): - SigningKeysTest: 클래스가 없어 컴파일 실패(RED) → 통과(GREEN) - check-signing-key.sh: armored·base64 둘 다 rc=0, base64 + 틀린 암호 rc=1, 지문 rc=1 - base64 키로 서명 리허설: rc=0, 서명된 artifact 10개, gpg --verify Good signature
This commit is contained in:
+4
-2
@@ -37,7 +37,8 @@ import org.gradle.plugins.signing.SigningExtension;
|
||||
* the versions its own resolution chose ({@code versionMapping}), and the plugin's POM
|
||||
* customization, which would add the BOM imports a consumer never inherits, is off.
|
||||
*
|
||||
* <p>Signing: with {@code SIGNING_KEY} (an ASCII-armoured PGP secret key) and {@code
|
||||
* <p>Signing: with {@code SIGNING_KEY} (an ASCII-armoured PGP secret key, or the base64 of one;
|
||||
* {@link SigningKeys}) and {@code
|
||||
* SIGNING_PASSWORD} in the environment, every published file gets an {@code .asc}. Without them
|
||||
* nothing is signed, and a task that uploads to {@code gitea} fails before it starts: an unsigned
|
||||
* release is not a release.
|
||||
@@ -138,7 +139,8 @@ public final class LibraryPublishingPlugin implements Plugin<Project> {
|
||||
.dir("staging-repository"));
|
||||
});
|
||||
|
||||
String signingKey = project.getProviders().environmentVariable("SIGNING_KEY").getOrElse("");
|
||||
String signingKey =
|
||||
SigningKeys.armoured(project.getProviders().environmentVariable("SIGNING_KEY").getOrElse(""));
|
||||
String signingPassword =
|
||||
project.getProviders().environmentVariable("SIGNING_PASSWORD").getOrElse("");
|
||||
boolean signed = !signingKey.isBlank();
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package dev.caskeleton.buildlogic.publishing;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* The ASCII-armoured key Gradle's in-memory signatory reads, from what a CI secret holds.
|
||||
*
|
||||
* <p>A secret store keeps a multi-line value badly or not at all, so the common practice is to put
|
||||
* the armoured key file in base64 on one line ({@code base64 -w0 signing-key.asc}). Gradle's {@code
|
||||
* useInMemoryPgpKeys} reads only the armoured text and reports the base64 form as "Could not read
|
||||
* PGP secret key" (v1.0.0 release run 9 and the secret put in after it). Both forms are accepted:
|
||||
* a value that decodes to an armoured private key block is unwrapped, anything else is passed on
|
||||
* unchanged, so a wrong value still fails, and {@code verifySigningKey} says why.
|
||||
*/
|
||||
public final class SigningKeys {
|
||||
private static final String BEGIN = "-----BEGIN PGP PRIVATE KEY BLOCK-----";
|
||||
|
||||
private SigningKeys() {}
|
||||
|
||||
/**
|
||||
* The armoured key: {@code value} itself, or the armoured block it is the base64 of.
|
||||
*
|
||||
* @param value the secret as given (armoured, base64 of the armoured file, or anything else)
|
||||
* @return the armoured key, or {@code value} unchanged when it is neither form
|
||||
*/
|
||||
public static String armoured(String value) {
|
||||
if (value == null || value.isBlank() || value.contains(BEGIN)) {
|
||||
return value;
|
||||
}
|
||||
String compact = value.replaceAll("\\s", "");
|
||||
if (!compact.matches("[A-Za-z0-9+/]+={0,2}")) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
String decoded = new String(Base64.getDecoder().decode(compact), StandardCharsets.UTF_8);
|
||||
return decoded.strip().startsWith(BEGIN) ? decoded : value;
|
||||
} catch (IllegalArgumentException notBase64) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user