Repository navigation
Description
Summary
Certificate.serialNumber() strips leading 0 hex characters, but the App Store Connect API returns serialNumber with them. When the development certificate's serial starts with 0, the stored SigningInfo never matches Apple's certificate. Every xtool dev after the first one then asks to revoke a certificate that is actually valid and known locally.
Environment
- xtool 1.21.0 (x86_64 AppImage), Ubuntu 24.04 on WSL2
- Swift 6.4.0, Xcode 27 SDK
- Free (personal) team, iPhone 17 / iOS 27.0
Steps to reproduce
- Use a free team with no existing certificates and run
xtool dev. xtool creates a certificate and the install works. - If that certificate's serial starts with
0(ours was033742570D6F…), runxtool devagain.
Expected: the stored certificate is reused.
Actual:
[Provisioning] 33%
The following certificates must be revoked:
- Apple Development: <name> (expires 9 Oct 2027 at 1:10 PM)
Continue? (yes/no):
Evidence
xtool ds certificates listshows one certificate,serial number: 033742570D6F9684A23311711956A084.- The certificate saved in
~/.config/xtool/data/<teamID>has the same serial (openssl x509 -serialgivesserial=033742570D6F9684A23311711956A084), and its private key matches the certificate's public key. serialNumber()turns this into33742570D6F9684A23311711956A084, so thefirst(where: { $0.attributes?.serialNumber == knownSerialNumber })check inDeveloperServicesFetchCertificateOperation.perform()fails, and it falls through toreplaceCertificates(_, requireConfirmation: true).
Cause
Sources/XKit/Model/Certificate.swift:
public func serialNumber() -> String {
// big endian, hex-encoded
let content = raw.serialNumber.bytes.lazy
.map { String(format: "%02hhX", $0) }
.joined()
.drop { $0 == "0" } // drops leading zero *nibbles*, e.g. "03…" -> "3…"
return String(content)
}My guess is that the drop is there to remove the 0x00 padding byte DER adds when the serial's high bit is set. Because it works on characters, it also removes a significant leading 0 nibble. Unless the serial is regenerated, the next run (or about 1 in 8 replacement certs) hits this again.
The same value is also passed as filter[serialNumber] in DeveloperServicesFetchProfileOperation, so profile lookup may be affected as well (not verified).
Suggested fix
Strip leading zero bytes before hex-encoding, rather than zero characters:
public func serialNumber() -> String {
// big endian, hex-encoded, without DER sign-padding bytes
raw.serialNumber.bytes
.drop { $0 == 0 }
.map { String(format: "%02hhX", $0) }
.joined()
}This gives 033742… in our case. For high-bit serials it removes the 00 padding byte, as the current code does. I haven't checked how Apple formats high-bit serials, so a more defensive option is to compare both sides with leading zeros removed (trimmingPrefix("0") on each) instead of changing serialNumber().
Activity
certs: match certificates whose serial starts with 0
certs: match certificates whose serial starts with 0
certs: match certificates whose serial starts with 0
certs: match certificates whose serial starts with 0 (xtool-org#306)