Beispiel #1
0
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);
}
Beispiel #2
0
BOOL WINAPI CertAddEncodedCTLToStore(HCERTSTORE hCertStore,
 DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded, DWORD cbCtlEncoded,
 DWORD dwAddDisposition, PCCTL_CONTEXT *ppCtlContext)
{
    PCCTL_CONTEXT ctl = CertCreateCTLContext(dwMsgAndCertEncodingType,
     pbCtlEncoded, cbCtlEncoded);
    BOOL ret;

    TRACE("(%p, %08x, %p, %d, %08x, %p)\n", hCertStore,
     dwMsgAndCertEncodingType, pbCtlEncoded, cbCtlEncoded, dwAddDisposition,
     ppCtlContext);

    if (ctl)
    {
        ret = CertAddCTLContextToStore(hCertStore, ctl, dwAddDisposition,
         ppCtlContext);
        CertFreeCTLContext(ctl);
    }
    else
        ret = FALSE;
    return ret;
}
Beispiel #3
0
static void testDupCTL(void)
{
    PCCTL_CONTEXT context, dupContext;
    BOOL res;

    context = CertDuplicateCTLContext(NULL);
    ok(context == NULL, "expected NULL\n");
    context = CertCreateCTLContext(X509_ASN_ENCODING,
     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
    dupContext = CertDuplicateCTLContext(context);
    ok(dupContext != NULL, "expected a context\n");
    ok(dupContext == context, "expected identical context addresses\n");

    res = CertFreeCTLContext(dupContext);
    ok(res, "CertFreeCTLContext failed\n");

    res = CertFreeCTLContext(context);
    ok(res, "CertFreeCTLContext failed\n");

    res = CertFreeCTLContext(NULL);
    ok(res, "CertFreeCTLContext failed\n");
}
Beispiel #4
0
static void testCreateCTL(void)
{
    PCCTL_CONTEXT ctl;

    SetLastError(0xdeadbeef);
    ctl = CertCreateCTLContext(0, NULL, 0);
    ok(!ctl && GetLastError() == E_INVALIDARG,
     "expected E_INVALIDARG, got %08x\n", GetLastError());
    SetLastError(0xdeadbeef);
    ctl = CertCreateCTLContext(X509_ASN_ENCODING, NULL, 0);
    ok(!ctl &&
     (GetLastError() == ERROR_INVALID_DATA ||
      GetLastError() == OSS_MORE_INPUT), /* win9x */
     "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
     GetLastError());
    /* An empty CTL can't be created.. */
    SetLastError(0xdeadbeef);
    ctl = CertCreateCTLContext(X509_ASN_ENCODING, emptyCTL, sizeof(emptyCTL));
    ok(!ctl &&
     (GetLastError() == ERROR_INVALID_DATA ||
      GetLastError() == OSS_DATA_ERROR), /* win9x */
     "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
     GetLastError());
    /* Nor can any of these "signed" CTLs whose inner content OID isn't
     * szOID_CTL.
     */
    SetLastError(0xdeadbeef);
    ctl = CertCreateCTLContext(X509_ASN_ENCODING, signedCTL, sizeof(signedCTL));
    ok(!ctl &&
     (GetLastError() == ERROR_INVALID_DATA ||
      GetLastError() == CRYPT_E_UNEXPECTED_MSG_TYPE /* win9x */ ||
      GetLastError() == ERROR_SUCCESS /* some win98 */),
     "expected ERROR_INVALID_DATA, CRYPT_E_UNEXPECTED_MSG_TYPE, or ERROR_SUCCESS, got %d (0x%08x)\n", GetLastError(),
     GetLastError());
    SetLastError(0xdeadbeef);
    ctl = CertCreateCTLContext(X509_ASN_ENCODING, ctlWithOneEntry,
     sizeof(ctlWithOneEntry));
    ok(!ctl &&
     (GetLastError() == ERROR_INVALID_DATA ||
      GetLastError() == CRYPT_E_UNEXPECTED_MSG_TYPE /* win9x */ ||
      GetLastError() == OSS_DATA_ERROR /* some win98 */ ||
      GetLastError() == ERROR_SUCCESS /* some win98 */),
     "expected ERROR_INVALID_DATA, CRYPT_E_UNEXPECTED_MSG_TYPE, OSS_DATA_ERROR, or ERROR_SUCCESS, got %d (0x%08x)\n", GetLastError(),
     GetLastError());
    SetLastError(0xdeadbeef);
    ctl = CertCreateCTLContext(X509_ASN_ENCODING,
     signedCTLWithSubjectAlgorithm, sizeof(signedCTLWithSubjectAlgorithm));
    ok(!ctl &&
     (GetLastError() == ERROR_INVALID_DATA ||
      GetLastError() == CRYPT_E_UNEXPECTED_MSG_TYPE /* win9x */ ||
      GetLastError() == ERROR_SUCCESS /* some win98 */),
     "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
     GetLastError());
    /* This signed CTL with the appropriate inner content type can be decoded.
     */
    ctl = CertCreateCTLContext(X509_ASN_ENCODING,
     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
    ok(ctl != NULL, "CertCreateCTLContext failed: %08x\n", GetLastError());
    if (ctl)
    {
        /* Even though the CTL was decoded with X509_ASN_ENCODING, the
         * message encoding type is included in the CTL's encoding type.
         */
        ok(ctl->dwMsgAndCertEncodingType ==
         (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING),
         "expected X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, got %08x\n",
         ctl->dwMsgAndCertEncodingType);
        CertFreeCTLContext(ctl);
    }
    /* This CTL with a bad signature can also be decoded, so the sig isn't
     * checked when loading the CTL.
     */
    ctl = CertCreateCTLContext(X509_ASN_ENCODING,
     signedCTLWithCTLInnerContentAndBadSig,
     sizeof(signedCTLWithCTLInnerContentAndBadSig));
    ok(ctl != NULL, "CertCreateCTLContext failed: %08x\n", GetLastError());
    if (ctl)
        CertFreeCTLContext(ctl);
}