-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitsec_pki.h
119 lines (99 loc) · 3.63 KB
/
fitsec_pki.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef _FITSEC_PKI_H_
#define _FITSEC_PKI_H_
#include "fitsec.h"
#include "fitsec_geometry.h"
#include "fitsec_time.h"
#define FS_PKI_VERSION 1
#define FS_PKI_VERSION_CTL 1
#define FS_PKI_VERSION_CRL 1
#define FS_CTL_SSP_TLM 0x80
#define FS_CTL_SSP_RCA 0x40
#define FS_CTL_SSP_EA 0x20
#define FS_CTL_SSP_AA 0x10
#define FS_CTL_SSP_DC 0x08
#define FS_CREQ_SSP_ENR_REQ 0x80
#define FS_CREQ_SSP_AUTH_REQ 0x40
#define FS_CREQ_SSP_VAL_REQ 0x20
#define FS_CREQ_SSP_AUTH_RES 0x10
#define FS_CREQ_SSP_VAL_RES 0x08
#define FS_CREQ_SSP_ENR_RES 0x04
#define FS_CREQ_SSP_CA_REQ 0x02
#define DEFAULT_REQ_STORAGE_DURATION 30 // 30 sec is more than enough
#define DEFAULT_EC_REQUEST_REPETITION_COUNT 2
#define DEFAULT_EC_REQUEST_REPETITION_TTL 120 // 2 minutes
#ifndef FSPKI_EXPORT
# ifdef _MSC_VER
# ifdef LIBFSPKI_EXPORTS
# define FSPKI_EXPORT __declspec(dllexport)
# else
# define FSPKI_EXPORT __declspec(dllimport)
# endif
# else
# define FSPKI_EXPORT
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct FitSecPkiConfig {
struct {
const uint8_t * id;
size_t id_len;
FSCurve alg;
const uint8_t * priv;
}station;
bool repetition;
bool disablePrivacy;
uint32_t reqStorageDuration; // seconds to store sent requests
} FitSecPkiConfig;
#define FS_PKI_DEFAULT_REQ_STORAGE_DURATION 20
typedef struct FitSecPki {
FitSec * e;
FitSecPkiConfig cfg;
}FitSecPki;
FSPKI_EXPORT FitSecPki * FitSecPki_New(FitSec * e, const FitSecPkiConfig * cfg);
FSPKI_EXPORT void FitSecPki_Free(FitSecPki * const pki);
FSPKI_EXPORT void FitSecPki_Clean(FitSecPki * const _pki);
/** Load PKI message from the given buffer.
* Each PKI message is an IEEE1609Dot2Data signed message containing PKI related payload.
* This function parses the IEEE1609Dot2Data, validate the message and and call the
* FitSecPki_loadMessage to perform all necessary actions
* @param e [In] The engine
* @param buf [In] The message buffer to be parsed.
* @param buflen [In] The message buffer length.
* @return error value or 0 siccess
*/
FSPKI_EXPORT int FitSecPki_loadData(FitSecPki* pki, const void* buf, size_t buflen);
/** Apply the already parsed and validated PKI responds.
* @param e [In] The engine
* @param m [In] The message information structure been used to parse the PKI message.
* @return error value or 0 siccess
*
* Description of fields in FSMessageInfo:
* ---------------|--------------------------------------------
* generationTime | in: the current ITS time
* payload | in: points to the payload containing EtsiTs102941Data message
* payloadSize | in: the size of the payload
* cert | in: the certificate been used to sign message
*/
FSPKI_EXPORT bool FitSecPki_loadMessage(FitSecPki* pki, FSMessageInfo* m);
typedef struct FSCertificateParams
{
FSCurve vKeyAlg;
FSCurve eKeyAlg;
uint32_t startTime;
duration_t durationType;
uint32_t duration;
const FSGeoRegion * region;
FSItsAidSsp appPermissions[16];
FSItsAidSsp issuePermissions[16];
struct {
const char * name;
}ca;
}FSCertificateParams;
FSPKI_EXPORT size_t FitSecPki_PrepareATRequest(FitSecPki* pki, const FSCertificateParams* params, FSMessageInfo * m);
FSPKI_EXPORT size_t FitSecPki_PrepareECRequest(FitSecPki* pki, const FSCertificateParams * params, FSMessageInfo * m);
#ifdef __cplusplus
}
#endif
#endif