少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "os/c-api/il2cpp-config-platforms.h"
 
#if IL2CPP_TARGET_OSX
 
#include "os/SystemCertificates.h"
#include <Security/SecTrust.h>
#include <Security/SecCertificate.h>
#include <Security/SecImportExport.h>
 
namespace il2cpp
{
namespace os
{
    void* SystemCertificates::OpenSystemRootStore()
    {
        CFArrayRef anchors = NULL;
        OSStatus s;
 
        s = SecTrustCopyAnchorCertificates(&anchors);
 
        IL2CPP_ASSERT(s == noErr);
 
        return (void*)anchors;
    }
 
    int SystemCertificates::EnumSystemCertificates(void* certStore, void** iter, int *format, int* size, void** data)
    {
        OSStatus s;
        CFDataRef certData;
        int numCerts = (int)CFArrayGetCount((CFArrayRef)certStore);
        *format = DATATYPE_STRING;
        // Order matters when it comes to certificates need to read in reverse
        int currentCert = numCerts;
        if (*iter != NULL)
        {
            currentCert = static_cast<int>(reinterpret_cast<intptr_t>(*iter));
        }
 
        SecCertificateRef cert = (SecCertificateRef)CFArrayGetValueAtIndex((CFArrayRef)certStore, (currentCert - 1));
 
        s = SecItemExport(cert, kSecFormatPEMSequence, kSecItemPemArmour, NULL, &certData);
 
        if (s == errSecSuccess)
        {
            char* certPEMStr = (char*)CFDataGetBytePtr(certData);
            *iter = reinterpret_cast<void*>(static_cast<intptr_t>((currentCert - 1)));
            *data = certPEMStr;
            *size = sizeof(certPEMStr);
            if ((currentCert - 1) > 0)
            {
                return TRUE;
            }
        }
 
        return FALSE;
    }
 
    void SystemCertificates::CloseSystemRootStore(void* cStore)
    {
        CFRelease((CFArrayRef)cStore);
    }
}
}
 
#endif