Hello

Hello,

I'm playing with the APK format of a sample "Hello world" Android application.

my (first) goal is to be able to rebuild an APK from a unzipped one...in fact a part of it.

like:
- META-INF/MANIFEST.MF << know how to produce it
- META-INF/ANDROIDT.SF << know how to produce it
- META-INF/ANDROIDT.RSA << this is the problem !
- AndroidManifest.xml << will know soon
- classes.dex << not my actual goal
- res/drawable/mylogo.png << just a PNG file
- resources.arsc << not my actual goal

so I can recreate MANIFEST.MF and ANDROIDT.SF, now I want to create ANDROIDT.RSA from the keystore...this is my actual code:

function TKeystore.Sign(const AData: TBytes): TBytes;
begin
SetLength(RSA, 128); // ?? how to compute the RSA-SHA256 signature ?

Result := DER.Chunk($30,
OID_PKCS7_SIGN // 1.2.840.113549.1.1.1
+DER.Chunk($A0,
DER.Chunk($30,
DER_INTEGER_1
+DER.Chunk($31,
DER.Chunk($30, OID_SHA256 + DER_NULL) // 2.16.840.1.101.3.4.2.1
)
+DER.Chunk($30, OID_PKCS7_DATA) // 1.2.840.113549.1.7.1
+DER.Chunk($A0, FCert) // directly extracted from keystore file
+DER.Chunk($31,
DER.Chunk($30,
DER_INTEGER_1
+DER.Chunk($30,
DER.Chunk($30,
CertInfo // portion of FCert (?)
)
+DER.IntValue(1349777951) // ??? what is this value ?
)
+DER.Chunk($30, OID_SHA256 + DER_NULL)
+DER.Chunk($30, OID_RSA + DER_NULL)
+DER.Chunk($04, RSA) // need to compute that !
)
)
)
)
);
end;

AFAIK the AData parameter should be the ANDROIDT.SF file, but I don't know how to compute the 128 bytes signature ... and I don't know where the 1349777951 value come from.

Any help will be greatly appreciated :)

Comments