コード例 #1
2
ファイル: ctl.c プロジェクト: devyn/wine
static void checkHash(const BYTE *data, DWORD dataLen, ALG_ID algID,
 PCCTL_CONTEXT context, DWORD propID)
{
    BYTE hash[20] = { 0 }, hashProperty[20];
    BOOL ret;
    DWORD size;

    memset(hash, 0, sizeof(hash));
    memset(hashProperty, 0, sizeof(hashProperty));
    size = sizeof(hash);
    ret = CryptHashCertificate(0, algID, 0, data, dataLen, hash, &size);
    ret = CertGetCTLContextProperty(context, propID, hashProperty, &size);
    ok(ret, "CertGetCTLContextProperty failed: %08x\n", GetLastError());
    if (ret)
        ok(!memcmp(hash, hashProperty, size),
         "Unexpected hash for property %d\n", propID);
}
コード例 #2
0
ファイル: ctl.c プロジェクト: hoangduit/reactos
static void testCTLProperties(void)
{
    PCCTL_CONTEXT ctl;
    BOOL ret;
    DWORD propID, numProps, access, size;

    ctl = CertCreateCTLContext(X509_ASN_ENCODING,
     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
    if (!ctl)
    {
        skip("CertCreateCTLContext failed: %08x\n", GetLastError());
        return;
    }

    /* No properties as yet */
    propID = 0;
    numProps = 0;
    do {
        propID = CertEnumCTLContextProperties(ctl, propID);
        if (propID)
            numProps++;
    } while (propID != 0);
    ok(numProps == 0, "Expected 0 properties, got %d\n", numProps);

    /* An implicit property */
    ret = CertGetCTLContextProperty(ctl, CERT_ACCESS_STATE_PROP_ID, NULL,
     &size);
    ok(ret || broken(GetLastError() == CRYPT_E_NOT_FOUND /* some win98 */),
     "CertGetCTLContextProperty failed: %08x\n", GetLastError());
    ret = CertGetCTLContextProperty(ctl, CERT_ACCESS_STATE_PROP_ID, &access,
     &size);
    ok(ret || broken(GetLastError() == CRYPT_E_NOT_FOUND /* some win98 */),
     "CertGetCTLContextProperty failed: %08x\n", GetLastError());
    if (ret)
        ok(!(access & CERT_ACCESS_STATE_WRITE_PERSIST_FLAG),
         "Didn't expect a persisted cert\n");

    checkHash(signedCTLWithCTLInnerContent,
     sizeof(signedCTLWithCTLInnerContent), CALG_SHA1, ctl, CERT_HASH_PROP_ID);

    /* Now that the hash property is set, we should get one property when
     * enumerating.
     */
    propID = 0;
    numProps = 0;
    do {
        propID = CertEnumCTLContextProperties(ctl, propID);
        if (propID)
            numProps++;
    } while (propID != 0);
    ok(numProps == 1, "Expected 1 properties, got %d\n", numProps);

    checkHash(signedCTLWithCTLInnerContent,
     sizeof(signedCTLWithCTLInnerContent), CALG_MD5, ctl,
     CERT_MD5_HASH_PROP_ID);

    CertFreeCTLContext(ctl);
}
コード例 #3
0
ファイル: ctl.c プロジェクト: MichaelMcDonnell/wine
static BOOL compare_ctl_by_sha1_hash(PCCTL_CONTEXT pCtlContext, DWORD dwType,
 DWORD dwFlags, const void *pvPara)
{
    BOOL ret;
    BYTE hash[20];
    DWORD size = sizeof(hash);

    ret = CertGetCTLContextProperty(pCtlContext, CERT_SHA1_HASH_PROP_ID, hash,
     &size);
    if (ret)
    {
        const CRYPT_HASH_BLOB *pHash = pvPara;

        if (size == pHash->cbData)
            ret = !memcmp(pHash->pbData, hash, size);
        else
            ret = FALSE;
    }
    return ret;
}