Skip to content

Commit

Permalink
pkcs11-tool.c - test CLASS for CKO_PRIVATE_KEY
Browse files Browse the repository at this point in the history
In tests for "CKO_PRIVATE_KEY" Use "getCLASS"  not "getKEY_TYPE"

 On branch object-class
 Changes to be committed:
	modified:   src/tools/pkcs11-tool.c
  • Loading branch information
dengert committed Oct 24, 2023
1 parent 1954e5d commit f1ced33
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/tools/pkcs11-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ static void sign_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
rv = p11->C_SignInit(session, &mech, key);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
if ((getCLASS(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
login(session,CKU_CONTEXT_SPECIFIC);

sig_len = sizeof(sig_buffer);
Expand All @@ -2309,7 +2309,7 @@ static void sign_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
rv = p11->C_SignInit(session, &mech, key);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
if ((getCLASS(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
login(session,CKU_CONTEXT_SPECIFIC);

do {
Expand Down Expand Up @@ -2629,15 +2629,15 @@ static void decrypt_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
rv = p11->C_DecryptInit(session, &mech, key);
if (rv != CKR_OK)
p11_fatal("C_DecryptInit", rv);
if ((getKEY_TYPE(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
if ((getCLASS(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
login(session, CKU_CONTEXT_SPECIFIC);
rv = p11->C_Decrypt(session, in_buffer, in_len, out_buffer, &out_len);
}
if (rv != CKR_OK) {
rv = p11->C_DecryptInit(session, &mech, key);
if (rv != CKR_OK)
p11_fatal("C_DecryptInit", rv);
if ((getKEY_TYPE(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
if ((getCLASS(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
login(session, CKU_CONTEXT_SPECIFIC);
do {
out_len = sizeof(out_buffer);
Expand Down Expand Up @@ -2729,7 +2729,7 @@ static void encrypt_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
rv = p11->C_EncryptInit(session, &mech, key);
if (rv != CKR_OK)
p11_fatal("C_EncryptInit", rv);
if ((getKEY_TYPE(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
if ((getCLASS(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
login(session, CKU_CONTEXT_SPECIFIC);
out_len = sizeof(out_buffer);
rv = p11->C_Encrypt(session, in_buffer, in_len, out_buffer, &out_len);
Expand All @@ -2738,7 +2738,7 @@ static void encrypt_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
rv = p11->C_EncryptInit(session, &mech, key);
if (rv != CKR_OK)
p11_fatal("C_EncryptInit", rv);
if ((getKEY_TYPE(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
if ((getCLASS(session, key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, key))
login(session, CKU_CONTEXT_SPECIFIC);
do {
out_len = sizeof(out_buffer);
Expand Down Expand Up @@ -6561,7 +6561,7 @@ static int sign_verify_openssl(CK_SESSION_HANDLE session,
return errors;
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, privKeyObject))
if ((getCLASS(session, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, privKeyObject))
login(session,CKU_CONTEXT_SPECIFIC);
printf(" %s: ", p11_mechanism_to_name(ck_mech->mechanism));

Expand Down Expand Up @@ -6739,7 +6739,7 @@ static int test_signature(CK_SESSION_HANDLE sess)
return errors;
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(sess, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(sess, privKeyObject))
if ((getCLASS(sess, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(sess, privKeyObject))
login(sess,CKU_CONTEXT_SPECIFIC);

rv = p11->C_SignUpdate(sess, data, 5);
Expand Down Expand Up @@ -6768,7 +6768,7 @@ static int test_signature(CK_SESSION_HANDLE sess)
rv = p11->C_SignInit(sess, &ck_mech, privKeyObject);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(sess, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(sess, privKeyObject))
if ((getCLASS(sess, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(sess, privKeyObject))
login(sess,CKU_CONTEXT_SPECIFIC);

sigLen2 = sizeof(sig2);
Expand Down Expand Up @@ -6807,7 +6807,7 @@ static int test_signature(CK_SESSION_HANDLE sess)
printf(" ERR: C_Sign() didn't return CKR_OK for a NULL output buf, but %s (0x%0x)\n",
CKR2Str(rv), (int) rv);
}
if ((getKEY_TYPE(sess, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(sess, privKeyObject))
if ((getCLASS(sess, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(sess, privKeyObject))
login(sess,CKU_CONTEXT_SPECIFIC);

rv = p11->C_Sign(sess, data, dataLen, sig2, &sigLen2);
Expand Down Expand Up @@ -6957,7 +6957,7 @@ static int sign_verify(CK_SESSION_HANDLE session,
printf(" ERR: C_SignInit() returned %s (0x%0x)\n", CKR2Str(rv), (int) rv);
return ++errors;
}
if ((getKEY_TYPE(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
if ((getCLASS(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
login(session,CKU_CONTEXT_SPECIFIC);
printf(" %s: ", p11_mechanism_to_name(*mech_type));

Expand Down Expand Up @@ -7543,7 +7543,7 @@ static int encrypt_decrypt(CK_SESSION_HANDLE session,
}
if (rv != CKR_OK)
p11_fatal("C_DecryptInit", rv);
if ((getKEY_TYPE(session, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, privKeyObject))
if ((getCLASS(session, privKeyObject) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, privKeyObject))
login(session,CKU_CONTEXT_SPECIFIC);

data_len = encrypted_len;
Expand Down Expand Up @@ -7874,7 +7874,7 @@ static CK_SESSION_HANDLE test_kpgen_certwrite(CK_SLOT_ID slot, CK_SESSION_HANDLE
rv = p11->C_SignInit(session, &mech, priv_key);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
if ((getCLASS(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
login(session,CKU_CONTEXT_SPECIFIC);

rv = p11->C_Sign(session, data, data_len, NULL, &sig_len);
Expand Down Expand Up @@ -7906,7 +7906,7 @@ static CK_SESSION_HANDLE test_kpgen_certwrite(CK_SLOT_ID slot, CK_SESSION_HANDLE
rv = p11->C_SignInit(session, &mech, priv_key);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
if ((getCLASS(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
login(session,CKU_CONTEXT_SPECIFIC);

rv = p11->C_Sign(session, data, data_len, sig, &sig_len);
Expand Down Expand Up @@ -8061,7 +8061,7 @@ static void test_ec(CK_SLOT_ID slot, CK_SESSION_HANDLE session)
rv = p11->C_SignInit(session, &mech, priv_key);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
if ((getCLASS(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
login(session,CKU_CONTEXT_SPECIFIC);
rv = p11->C_Sign(session, data, data_len, NULL, &sig_len);
if (rv != CKR_OK)
Expand All @@ -8081,7 +8081,7 @@ static void test_ec(CK_SLOT_ID slot, CK_SESSION_HANDLE session)
rv = p11->C_SignInit(session, &mech, priv_key);
if (rv != CKR_OK)
p11_fatal("C_SignInit", rv);
if ((getKEY_TYPE(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
if ((getCLASS(session, priv_key) == CKO_PRIVATE_KEY) && getALWAYS_AUTHENTICATE(session, priv_key))
login(session,CKU_CONTEXT_SPECIFIC);
rv = p11->C_Sign(session, data, data_len, sig, &sig_len);
if (rv != CKR_OK)
Expand Down

0 comments on commit f1ced33

Please sign in to comment.