summaryrefslogtreecommitdiff
path: root/src/p11-tests-lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/p11-tests-lib.h')
-rw-r--r--src/p11-tests-lib.h252
1 files changed, 252 insertions, 0 deletions
diff --git a/src/p11-tests-lib.h b/src/p11-tests-lib.h
new file mode 100644
index 0000000..ac35204
--- /dev/null
+++ b/src/p11-tests-lib.h
@@ -0,0 +1,252 @@
+#ifndef P11_TESTS_PRIVATE_H_
+#define P11_TESTS_PRIVATE_H_
+
+#ifndef _WIN32
+#include "config.h"
+#endif
+
+#ifdef _MSC_VER
+#pragma warning(disable : 4996)
+#endif
+
+#include "p11-tests.h"
+
+#include "pkcs11/pkcs11.h"
+
+#include <assert.h>
+#include <stdarg.h>
+
+#include <openssl/rsa.h>
+#include <openssl/dsa.h>
+
+#define CK_INVALID ((CK_ULONG)-1)
+
+extern int p11t_test_unexpected;
+extern int p11t_test_write_session;
+
+/* -------------------------------------------------------------------
+ * certificate.c
+ */
+
+const char* p11t_certificate_validate_dn(CK_BYTE_PTR der, CK_ULONG n_der);
+
+void p11t_certificate_tests(void);
+
+/* -------------------------------------------------------------------
+ * check.c
+ */
+
+enum
+{
+ STOP = 0,
+ CONTINUE = 1
+};
+
+extern int p11t_check_verbose;
+
+#define P11T_SECTION(check) \
+ p11t_msg_prefix(check)
+
+#define _P11T_BEGIN do {
+#define _P11T_END } while(0)
+
+#define P11T_CHECK_FAIL(what) \
+ _P11T_BEGIN p11t_check_fail("%s", (what)); return STOP; _P11T_END
+
+#define P11T_CHECK_FAIL_MSG(what, msg) \
+ _P11T_BEGIN p11t_check_fail("%s: %s", (what), (msg)); return STOP; _P11T_END
+
+int p11t_check_fail(const char *message, ...);
+int p11t_check_warn(const char *message, ...);
+int p11t_check_info(const char *message, ...);
+
+#define P11T_CHECK_RV(what, have, want) \
+ _P11T_BEGIN if(!_p11t_check_rv((what), (have), (want))) return STOP; _P11T_END
+
+int _p11t_check_rv(const char *what, CK_RV have, CK_RV want);
+
+#define P11T_CHECK_PADDED(what, padded) \
+ _P11T_BEGIN if(!_p11t_check_padded((what), (padded), sizeof(padded))) return STOP; _P11T_END
+
+int _p11t_check_padded(const char *what, const CK_UTF8CHAR_PTR padded, CK_ULONG length);
+
+#define P11T_CHECK_ULONG(what, have, want) \
+ _P11T_BEGIN if(!_p11t_check_ulong((what), (have), (want))) return STOP; _P11T_END
+
+int _p11t_check_ulong(const char *what, CK_ULONG have, CK_ULONG want);
+
+#define P11T_CHECK_MASK(what, have, want) \
+ _P11T_BEGIN if(!_p11t_check_mask((what), (have), (want))) return STOP; _P11T_END
+
+int _p11t_check_mask(const char *what, CK_ULONG flags, CK_ULONG mask);
+
+#define P11T_CHECK_FLAG(what, have, want) \
+ _P11T_BEGIN if(!_p11t_check_flag((what), (have), (want))) return STOP; _P11T_END
+
+int _p11t_check_flag(const char *what, CK_ULONG flags, CK_ULONG flag);
+
+#define P11T_CHECK_NFLAG(what, have, want) \
+ _P11T_BEGIN if(!_p11t_check_nflag((what), (have), (want))) return STOP; _P11T_END
+
+int _p11t_check_nflag(const char *what, CK_ULONG flags, CK_ULONG nflag);
+
+#define P11T_CHECK_BOOL(what, value) \
+ _P11T_BEGIN if(!_p11t_check_bool((what), (value))) return STOP; _P11T_END
+
+int _p11t_check_bool(const char *what, CK_BBOOL value);
+
+#define P11T_CHECK_STRING(what, value, length) \
+ _P11T_BEGIN if(!_p11t_check_string((what), (value), (length))) return STOP; _P11T_END
+
+int _p11t_check_string(const char *what, CK_UTF8CHAR_PTR value, CK_ULONG length);
+
+#define P11T_CHECK_DATE(what, value) \
+ _P11T_BEGIN if(!_p11t_check_date((what), (value))) return STOP; _P11T_END
+
+int _p11t_check_date(const char *what, CK_DATE* value);
+
+#define P11T_CHECK_NOTE(what)
+
+/* -------------------------------------------------------------------
+ * config.c
+ */
+
+int p11t_config_parse(const char* filename);
+void p11t_config_cleanup(void);
+
+/* -------------------------------------------------------------------
+ * crypto.c
+ */
+
+int p11t_crypto_test_encrypt (CK_SESSION_HANDLE session, CK_MECHANISM_TYPE mech);
+int p11t_crypto_test_decrypt (CK_SESSION_HANDLE session, CK_MECHANISM_TYPE mech);
+int p11t_crypto_test_sign (CK_SESSION_HANDLE session, CK_MECHANISM_TYPE mech);
+int p11t_crypto_test_verify (CK_SESSION_HANDLE session, CK_MECHANISM_TYPE mech);
+
+/* -------------------------------------------------------------------
+ * dsa.c
+ */
+
+void p11t_dsa_tests(void);
+
+void p11t_dsa_test_public_key(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE handle);
+void p11t_dsa_test_private_key(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE handle);
+
+/* -------------------------------------------------------------------
+ * key.c
+ */
+
+CK_OBJECT_HANDLE p11t_key_get_public(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
+
+CK_OBJECT_HANDLE p11t_key_get_private(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
+
+CK_MECHANISM_TYPE_PTR p11t_key_get_mechanisms(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key, CK_ULONG_PTR n_mechanisms);
+
+RSA* p11t_key_export_public_rsa(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
+DSA* p11t_key_export_public_dsa(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
+
+CK_RV p11t_key_login_context_specific (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
+
+void p11t_key_tests(void);
+
+/* -------------------------------------------------------------------
+ * msg.c
+ */
+
+const char* p11t_msg_rv(CK_RV rv);
+const char* p11t_msg_os(void);
+const char* p11t_msg_openssl(void);
+
+void p11t_msg_va(int level, const char *message, va_list va);
+void p11t_msg_print(const char *message, ...);
+const char* p11t_msg_prefix(const char *prefix);
+
+#define p11t_msg_here() \
+ (__func__ "() at " __FILE__ ":" __LINE__)
+
+extern P11TestsLogFunc p11t_log_func;
+
+/* -------------------------------------------------------------------
+ * module.c
+ */
+
+extern CK_FUNCTION_LIST_PTR p11t_module_funcs;
+
+void p11t_module_config(const char *name, const char *value);
+
+int p11t_module_load(const char *filename);
+int p11t_module_unload(void);
+
+int p11t_module_initialize(void);
+int p11t_module_finalize(void);
+
+/* -------------------------------------------------------------------
+ * object.c
+ */
+
+CK_OBJECT_HANDLE_PTR p11t_object_find(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attrs,
+ CK_ULONG n_attrs, CK_ULONG_PTR n_objects);
+
+int p11t_object_get(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG count);
+
+CK_OBJECT_HANDLE p11t_object_find_one(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attrs,
+ CK_ULONG n_attrs);
+
+void p11t_object_tests(void);
+
+/* -------------------------------------------------------------------
+ * rsa.c
+ */
+
+void p11t_rsa_tests (void);
+void p11t_rsa_test_public_key (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE handle);
+void p11t_rsa_test_private_key(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE handle);
+
+/* -------------------------------------------------------------------
+ * session.c
+ */
+
+CK_SESSION_HANDLE p11t_session_open(CK_SLOT_ID slot, int readwrite);
+int p11t_session_login(CK_SESSION_HANDLE handle);
+int p11t_session_logout(CK_SESSION_HANDLE handle);
+int p11t_session_close(CK_SESSION_HANDLE handle);
+int p11t_session_close_all(CK_SLOT_ID slot);
+CK_UTF8CHAR_PTR p11t_session_get_pin(CK_SLOT_ID slot, CK_USER_TYPE user, CK_ULONG_PTR n_pin);
+
+void p11t_session_config(const char *name, const char *value);
+
+void p11t_session_tests(void);
+
+/* -------------------------------------------------------------------
+ * slot.c
+ */
+
+extern CK_ULONG p11t_slot_count;
+extern int p11t_slot_virtual;
+
+void p11t_slot_tests(void);
+
+void p11t_slot_cleanup(void);
+
+CK_SLOT_ID p11t_slot_get_id(int index);
+CK_SLOT_INFO_PTR p11t_slot_get_info(CK_SLOT_ID slot);
+CK_TOKEN_INFO_PTR p11t_slot_get_token_info(CK_SLOT_ID slot);
+
+typedef void (*P11tSlotMechCallback)(CK_SLOT_ID slot, CK_MECHANISM_TYPE mech_type,
+ CK_MECHANISM_INFO_PTR mech_info);
+
+void p11t_slot_for_each_mech(CK_MECHANISM_TYPE mech_type, P11tSlotMechCallback callback);
+
+CK_MECHANISM_INFO_PTR p11t_slot_get_mech_info(CK_SLOT_ID slot, CK_MECHANISM_TYPE mech_type);
+
+/* ------------------------------------------------------------------
+ * test-data.c
+ */
+
+#define P11T_BLOCK 10240
+extern const CK_BYTE p11t_test_data[];
+extern const CK_ULONG p11t_test_data_size;
+extern const CK_ULONG p11t_test_data_bits;
+
+#endif /* P11_TESTS_PRIVATE_H_ */