Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Use PKCS7_dataDecode instead of accessing profile digests directly

kabiroberaia501ccb3c57e
diff --git a/Supersign/Sources/CSupersign/mobileprovision.c b/Supersign/Sources/CSupersign/mobileprovision.c
index 14b3df3..ee39f1f 100644
--- a/Supersign/Sources/CSupersign/mobileprovision.c
+++ b/Supersign/Sources/CSupersign/mobileprovision.c
@@ -60,7 +60,14 @@ void *mobileprovision_get_data(mobileprovision_t profile, size_t *len) {
}
const void *mobileprovision_get_digest(mobileprovision_t profile, size_t *len) {
- ASN1_OCTET_STRING *str = profile->raw->d.sign->contents->d.data;
- if (len) *len = str->length;
- return (char *)str->data;
+ // we could dig into the struct ourselves instead but using the
+ // documented API is better.
+ BIO *digest_bio = PKCS7_dataDecode(profile->raw, NULL, NULL, NULL);
+ if (!digest_bio) return NULL;
+ char *data = NULL;
+ long digest_len = BIO_get_mem_data(digest_bio, &data);
+ // the mem pointer is owned by `profile`, not the bio
+ BIO_free_all(digest_bio);
+ if (len) *len = digest_len;
+ return data;
}
diff --git a/Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swift b/Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swift
index 85e82f9..2d0596b 100644
--- a/Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swift
+++ b/Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swift
@@ -77,7 +77,11 @@ public final class Mobileprovision: Decodable {
guard let ptr = mobileprovision_get_digest(raw, &len), len > 0 else {
throw Error.invalidProfile
}
- let data = Data(bytes: ptr, count: len)
+ let data = Data(
+ bytesNoCopy: UnsafeMutableRawPointer(mutating: ptr),
+ count: len,
+ deallocator: .none
+ )
return try PropertyListDecoder().decode(Digest.self, from: data)
}