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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* Copyright 2011-2016 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Written originally for the Pkcs11Interop project by:
* Jaroslav IMRICH <jimrich@jimrich.sk>
*/
#define _POSIX_C_SOURCE 200809
#include <config.h>
#include <stdio.h>
#include <string.h>
// PKCS#11 related stuff
#define CK_PTR *
#define CK_DEFINE_FUNCTION(returnType, name) returnType name
#define CK_DECLARE_FUNCTION(returnType, name) returnType name
#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
#define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
#include <p11-kit/pkcs11.h>
#include <p11-kit/pkcs11x.h>
#ifndef NULL_PTR
#define NULL_PTR 0
#endif
#define IGNORE(P) (void)(P)
#define PKCS11_MOCK_CK_INFO_MANUFACTURER_ID "Pkcs11Interop Project"
#define PKCS11_MOCK_CK_INFO_LIBRARY_DESCRIPTION "Mock module"
#define PKCS11_MOCK_CK_SLOT_ID 1
#define PKCS11_MOCK_CK_SLOT_INFO_SLOT_DESCRIPTION "Mock slot"
#define PKCS11_MOCK_CK_SLOT_INFO_MANUFACTURER_ID "Pkcs11Interop Project"
#define PKCS11_MOCK_CK_TOKEN_INFO_LABEL "Pkcs11Interop"
#define PKCS11_MOCK_CK_TOKEN_INFO_MANUFACTURER_ID "Pkcs11Interop Project"
#define PKCS11_MOCK_CK_TOKEN_INFO_MODEL "Mock token"
#define PKCS11_MOCK_CK_TOKEN_INFO_SERIAL_NUMBER "0123456789A"
#define PKCS11_MOCK_CK_TOKEN_INFO_MAX_PIN_LEN 256
#define PKCS11_MOCK_CK_TOKEN_INFO_MIN_PIN_LEN 4
#define PKCS11_MOCK_CK_SESSION_ID 1
#define PKCS11_MOCK_CK_OBJECT_CKA_LABEL "Pkcs11Interop"
#define PKCS11_MOCK_CK_OBJECT_CKA_VALUE "Hello world!"
#define PKCS11_MOCK_CK_OBJECT_SIZE 256
#define PKCS11_MOCK_CK_OBJECT_HANDLE_DATA 1
#define PKCS11_MOCK_CK_OBJECT_HANDLE_SECRET_KEY 2
#define PKCS11_MOCK_CK_OBJECT_HANDLE_PUBLIC_KEY 3
#define PKCS11_MOCK_CK_OBJECT_HANDLE_PRIVATE_KEY 4
#define PKCS11_MOCK_CK_OBJECT_HANDLE_CERTIFICATE_EXTENSION 5
#define PKCS11_MOCK_CK_OBJECT_HANDLE_CERTIFICATE 6
typedef enum
{
PKCS11_MOCK_CK_OPERATION_NONE,
PKCS11_MOCK_CK_OPERATION_FIND,
PKCS11_MOCK_CK_OPERATION_ENCRYPT,
PKCS11_MOCK_CK_OPERATION_DECRYPT,
PKCS11_MOCK_CK_OPERATION_DIGEST,
PKCS11_MOCK_CK_OPERATION_SIGN,
PKCS11_MOCK_CK_OPERATION_SIGN_RECOVER,
PKCS11_MOCK_CK_OPERATION_VERIFY,
PKCS11_MOCK_CK_OPERATION_VERIFY_RECOVER,
PKCS11_MOCK_CK_OPERATION_DIGEST_ENCRYPT,
PKCS11_MOCK_CK_OPERATION_DECRYPT_DIGEST,
PKCS11_MOCK_CK_OPERATION_SIGN_ENCRYPT,
PKCS11_MOCK_CK_OPERATION_DECRYPT_VERIFY
}
PKCS11_MOCK_CK_OPERATION;
struct find_ptr_st {
int remaining_data;
PKCS11_MOCK_CK_OPERATION active_operation;
CK_OBJECT_HANDLE find_result;
};
typedef struct session_ptr_st {
char *find_label;
CK_ULONG state;
struct find_ptr_st find_op;
} session_ptr_st;
|