Hello,
since Thomas has not the time to fix the following function of CertTools contained in MacOSLibrary, and I myself am not familiar with Ptr, I’d appreciate if somebody could fix it.
When building for 64 bits, warnings appear that certain integers should actually be int32. Accordingly I modified the two instances into int32 (see below: ////modified into int32).
Building again for 64 bits, the above warnings disappear, but five new warnings appear saying: expected Ptr but got int32 (see below: ////after modifying into int32, new warning: expected Ptr but got int32). But in this particular cases I don’t have any idea how to proceed.
Any help would be appreciated. Thanks.
Protected Function ReadReceipt(certFile as FolderItem) As Dictionary
// This function reads certain entries from the App’s certification receipt file
#if TargetMacOS
declare function d2i_PKCS7_fp lib “/usr/lib/libcrypto.dylib” (fp as Int32, p7 as Ptr) as Ptr
declare sub PKCS7_free lib “/usr/lib/libcrypto.dylib” (p7 as Ptr)
declare function OBJ_obj2nid lib “/usr/lib/libcrypto.dylib” (ASN1_OBJECT as Ptr) as Int32
declare function ASN1_get_object lib “/usr/lib/libcrypto.dylib” (ByRef pp as Ptr, ByRef plength as Int32, ByRef ptag as Int32, ByRef pclass as Int32, omax as Int32) as Int32
dim result as Dictionary
if certFile = nil then return nil
dim bs as BinaryStream
try
bs = BinaryStream.Open(certFile)
catch exc as RuntimeException
return nil
end
dim fp as Int32 = bs.Handle(BinaryStream.HandleTypeFilePointer)
if fp = 0 then return nil
dim p7 as Ptr = d2i_PKCS7_fp (fp, nil)
bs.Close
bs = nil
if p7 = nil then return nil
// is it signed?
dim nid as Int32 = OBJ_obj2nid (p7.PKCS7.type)
if nid <> 22 then goto bail1
// is data?
nid = OBJ_obj2nid (p7.PKCS7.d.PKCS7_SIGNED.contents.PKCS7.type)
if nid <> 21 then goto bail1
dim octets as Ptr = p7.PKCS7.d.PKCS7_SIGNED.contents.PKCS7.d
dim p, e as Ptr
p = octets.ASN1_STRING.data
dim l as Integer = octets.ASN1_STRING.length
e = p + Ptr(l)
dim res, type, xclass, length as Integer////changed into int32
res = ASN1_get_object(p, length, type, xclass, e - p)
if type <> 17 then goto bail1 ' V_ASN1_SET
result = new Dictionary
while p < e
call ASN1_get_object (p, length, type, xclass, e - p)
if type <> 16 then
exit ' V_ASN1_SEQUENCE
end
dim seq_end as Ptr = p + Ptr(length)////after modifying into int32, new warning: expected Ptr but got int32
dim attr_type, attr_version as Integer
// Attribute type
call ASN1_get_object (p, length, type, xclass, seq_end - p)
if type = 2 and length = 1 then ' V_ASN1_INTEGER
attr_type = p.Byte(0)
end
p = p + Ptr(length)////after modifying into int32, new warning: expected Ptr but got int32
// Attribute version
call ASN1_get_object (p, length, type, xclass, seq_end - p)
if type = 2 and length = 1 then ' V_ASN1_INTEGER
attr_version = p.Byte(0)
end
p = p + Ptr(length)////after modifying into int32, new warning: expected Ptr but got int32
// Only parse attributes we're interested in
if ATTRS(attr_type) > ATTRS.ATTR_START and ATTRS(attr_type) < ATTRS.ATTR_END then
dim key as Keys
call ASN1_get_object (p, length, type, xclass, seq_end - p)
if type = 4 then ' V_ASN1_OCTET_STRING
// Bytes
if ATTRS(attr_type) = ATTRS.BUNDLE_ID or ATTRS(attr_type) = ATTRS.OPAQUE_VALUE or ATTRS(attr_type) = ATTRS.HASH then
select case ATTRS(attr_type)
case ATTRS.BUNDLE_ID
// This is included for hash generation
key = Keys.kReceiptBundleIdentiferData
case ATTRS.OPAQUE_VALUE
key = Keys.kReceiptOpaqueValue
case ATTRS.HASH
key = Keys.kReceiptHash
end select
dim mb as MemoryBlock = p
result.Value(key) = mb.StringValue(0, length)
end
// Strings
if ATTRS(attr_type) = ATTRS.BUNDLE_ID or ATTRS(attr_type) = ATTRS.VERSION then
dim str_type, str_length as Integer////after modifying into int32, new warning: modified into int32
dim str_p as Ptr = p
call ASN1_get_object (str_p, str_length, str_type, xclass, seq_end - str_p)
if str_type = 12 then ' V_ASN1_UTF8STRING
dim mb as MemoryBlock = str_p
dim s as String = mb.StringValue(0,str_length).DefineEncoding(Encodings.UTF8)
select case ATTRS(attr_type)
case ATTRS.BUNDLE_ID
key = Keys.kReceiptBundleIdentifer
case ATTRS.VERSION
key = Keys.kReceiptVersion
end select
result.Value(key) = s
end
end
end
p = p + Ptr(length)////after modifying into int32, new warning: expected Ptr but got int32
end if
// Skip any remaining fields in this SEQUENCE
while p < seq_end
call ASN1_get_object (p, length, type, xclass, seq_end - p)
p = p + Ptr(length)////expected Ptr but got int32
wend
wend
bail1:
PKCS7_free (p7)
return result
#endif
End Function