Modern Apps git

← xtool.git

Use PKCS7_dataDecode instead of accessing profile digests directly

Commit
a501ccb3c57e704782c9a1f7f578c12cccda4c6d
Author
kabiroberai <[email protected]>
When
2021-07-15 21:24 UTC (5 years ago)
Parents
db45492
Using the intended function is better than digging into the struct ourselves: especially since OpenSSL has an unstable API

Diff

Supersign/Sources/CSupersign/mobileprovision.c
diff --git a/Supersign/Sources/CSupersign/mobileprovision.c b/Supersign/Sources/CSupersign/mobileprovision.cindex 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; }
Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swift
diff --git a/Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swift b/Supersign/Sources/Supersign/Model/Mobileprovision/Mobileprovision.swiftindex 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)     }