/
tokenreader-interfac.ads
333 lines (304 loc) · 14.4 KB
/
tokenreader-interfac.ads
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
------------------------------------------------------------------
-- Tokeneer ID Station Core Software
--
-- Copyright (2003) United States Government, as represented
-- by the Director, National Security Agency.All rights reserved.
--
-- This material was originally developed by Praxis High Integrity
-- Systems Ltd.under contract to the National Security Agency.
------------------------------------------------------------------
------------------------------------------------------------------
-- TokenReader.Interfac
--
-- Description:
-- Interfaces to the TokenAPI.
--
------------------------------------------------------------------
with CommonTypes;
with CertTypes;
with TokenTypes;
private package TokenReader.Interfac
with SPARK_Mode,
Abstract_State => ((ReaderInput with External => Async_Writers,
Part_Of => TokenReader.Input),
(ReaderStatus with External => Async_Writers,
Part_Of => TokenReader.Status),
(ReaderOutput with External => Async_Readers,
Part_Of => TokenReader.Output))
is
------------------------------------------------------------------
-- Types
--
------------------------------------------------------------------
type CardHandleT is private;
NullHandle : constant CardHandleT;
subtype ReaderNameI is Positive range 1..8;
subtype ReaderNameT is String(ReaderNameI);
subtype ReaderArrayI is Positive range 1..10;
type ReaderNameArrayT is Array(ReaderArrayI) of ReaderNameT;
type ResponseCodeT is
(Success, -- No error.
InvalidHandle, -- Supplied handle is invalid.
InvalidValue, -- Parameter Value(s) could not be
-- properly interpreted.
Cancelled, -- Action was cancelled by the
-- application.
NoMemory, -- Not enough memory to complete
-- command.
InsufficientBuffer, -- Data buffer to receive returned
-- data is too small.
UnknownReader, -- Reader name is not recognized.
Timedout, -- Timeout has expired.
SharingViolation, -- ICC cannot be accessed -
-- outstanding connections.
NoSmartcard, -- Required ICC not in device.
UnknownCard, -- Specified name is not recognized.
ProtoMismatch, -- Requested protocols incompatible
-- with protocol currently in use
-- with the ICC.
NotReady, -- Device or card not ready for
-- commands.
SystemCancelled, -- Action cancelled by system.
ReaderUnavailable, -- Device not currently available
-- for use.
UnsupportedCard, -- Reader cannot communicate, due to
-- ATR conflicts.
UnresponsiveCard, -- Card not responding to a reset.
UnpoweredCard, -- Power has been removed from the
-- card.
ResetCard, -- Card has been reset, so any
-- shared state info is invalid.
RemovedCard, -- ICC has been removed.
InvalidResponseCode);
function ResponseCodeT_Image (X : ResponseCodeT) return CommonTypes.StringF1L1000 is
(ResponseCodeT'Image (X));
pragma Annotate (GNATprove, False_Positive,
"predicate check might fail",
"Image of enums of type ResponseCodeT are short strings starting at index 1");
type CardStateT is
(InvalidCardState,
Absent, -- No card in the reader.
Present, -- Card in the reader, but not in position
-- for use.
Swallowed, -- Card in reader, in position for use.Card
-- is not powered.
Powered, -- Power is being provided to the card, but
-- reader driver is unaware of the mode of
-- the card.
Negotiable, -- Card has been reset and is awaiting PTS
-- negotiation.
Specific -- Card has been reset and specific
-- protocols have been established.
);
type ReaderStateT is
(InvalidReaderState,
Unaware, -- State is unknown by the application
Ignore, -- Reader should be ignored
Unavailable, -- Reader is not available for use
Empty, -- No card in the reader
CardPresent, -- A card is present in the reader
Mute -- An unresponsive card is in the reader
);
subtype ValidReaderStateT is ReaderStateT range Unaware..Mute;
------------------------------------------------------------------
-- ListReaders
--
-- Description:
-- ListReaders will be called at initialisation to provide the TIS with
-- a list of strings used to interface with visible token readers.
--
------------------------------------------------------------------
procedure ListReaders (List : out ReaderNameArrayT;
Number : in out CommonTypes.Unsigned32T;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (Input => ReaderStatus),
Depends => ((List,
Number,
ResponseCode) => (Number,
ReaderStatus));
------------------------------------------------------------------
-- GetStatusChange
--
-- Description:
-- Used by TIS as a means of 'polling' the reader, to determine whether
-- a card is present.
--
------------------------------------------------------------------
procedure GetStatusChange (Timeout : in CommonTypes.Unsigned32T;
Reader : in ReaderNameT;
CurrentState : in ReaderStateT;
NewState : out CommonTypes.Unsigned32T;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => ReaderStatus,
Depends => (NewState => (Reader,
ReaderStatus,
Timeout),
ResponseCode => (CurrentState,
Reader,
ReaderStatus,
Timeout));
------------------------------------------------------------------
-- Connect
--
-- Description:
-- Connect is called once GetStatusChange has determined that a card is
-- present in a reader, and establishes a connection between TIS and the
-- card in the reader.
--
------------------------------------------------------------------
procedure Connect (Reader : in ReaderNameT;
CardHandle : out CardHandleT;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => ReaderStatus,
Depends => ((CardHandle,
ResponseCode) => (Reader,
ReaderStatus));
------------------------------------------------------------------
-- Status
--
-- Description:
-- Status will be called once a card has been connected to provide TIS
-- with the status of the card.This can be used to obtain the card's
-- unique ID, contained in the answer-to-reset (ATR).The ATR is
-- only defined if the card is in 'Negotiable' or 'Specific' state, so
-- should be ignored when the card is in any other state.
--
------------------------------------------------------------------
procedure Status (CardHandle : in CardHandleT;
CState : out CommonTypes.Unsigned32T;
ATR : out TokenTypes.TokenIDT;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (ReaderInput,
ReaderStatus),
Depends => (ATR => (CardHandle,
ReaderInput,
ReaderStatus),
(CState,
ResponseCode) => (CardHandle,
ReaderStatus));
------------------------------------------------------------------
-- Disconnect
--
-- Description:
-- Disconnect is called once TIS has finished communications with the
-- card.
--
------------------------------------------------------------------
procedure Disconnect (CardHandle : in CardHandleT;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => ReaderStatus,
Depends => (ResponseCode => (CardHandle,
ReaderStatus));
------------------------------------------------------------------
-- GetIDCert
--
-- Description:
-- GetIDCert is called by TIS once it is in communication with a card,
-- and is used to obtain the ID certificate from that card.
-- StatusOK reports whether card communications were OK or not.
--
------------------------------------------------------------------
procedure GetIDCert (CardHandle : in CardHandleT;
RawIDCert : out CertTypes.RawCertificateT;
StatusOK : out Boolean;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (ReaderInput,
ReaderStatus),
Depends => (RawIDCert => (CardHandle,
ReaderInput,
ReaderStatus),
(ResponseCode,
StatusOK) => (CardHandle,
ReaderStatus));
------------------------------------------------------------------
-- GetPrivCert
--
-- Description:
-- GetPrivCert is called by TIS once it is in communication with a card,
-- and is used to obtain the Privilege certificate from that card.
-- StatusOK reports whether card communications were OK or not.
--
------------------------------------------------------------------
procedure GetPrivCert (CardHandle : in CardHandleT;
RawPrivCert : out CertTypes.RawCertificateT;
StatusOK : out Boolean;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (ReaderInput,
ReaderStatus),
Depends => (RawPrivCert => (CardHandle,
ReaderInput,
ReaderStatus),
(ResponseCode,
StatusOK) => (CardHandle,
ReaderStatus));
------------------------------------------------------------------
-- GetIACert
--
-- Description:
-- GetIACert is called by TIS once it is in communication with a card,
-- and is used to obtain the I&A certificate from that card.
-- StatusOK reports whether card communications were OK or not.
--
------------------------------------------------------------------
procedure GetIACert (CardHandle : in CardHandleT;
RawIACert : out CertTypes.RawCertificateT;
StatusOK : out Boolean;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (ReaderInput,
ReaderStatus),
Depends => (RawIACert => (CardHandle,
ReaderInput,
ReaderStatus),
(ResponseCode,
StatusOK) => (CardHandle,
ReaderStatus));
------------------------------------------------------------------
-- GetAuthCert
--
-- Description:
-- GetAuthCert is called by TIS once it is in communication with a card,
-- and is used to obtain the Authorisation certificate from that card.
-- There may not be an Auth Cert; Exists indicates this.
-- StatusOK reports whether card communications were OK or not.
--
------------------------------------------------------------------
procedure GetAuthCert (CardHandle : in CardHandleT;
RawAuthCert : out CertTypes.RawCertificateT;
Exists : out Boolean;
StatusOK : out Boolean;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (ReaderInput,
ReaderStatus),
Depends => ((Exists,
ResponseCode,
StatusOK) => (CardHandle,
ReaderStatus),
RawAuthCert => (CardHandle,
ReaderInput,
ReaderStatus));
------------------------------------------------------------------
-- UpdateAuthCert
--
-- Description:
-- UpdateAuthCert is called when a new Auth Cert has been created for a
-- user, and attempts to write the provided Auth Cert to the user's card.
-- StatusOK reports whether card communications were OK or not.
--
------------------------------------------------------------------
procedure UpdateAuthCert (CardHandle : in CardHandleT;
RawAuthCert : in CertTypes.RawCertificateT;
StatusOK : out Boolean;
ResponseCode : out CommonTypes.Unsigned32T)
with Global => (Input => ReaderStatus,
Output => ReaderOutput),
Depends => (ReaderOutput => (CardHandle,
RawAuthCert,
ReaderStatus),
(ResponseCode,
StatusOK) => (CardHandle,
ReaderStatus));
private
type CardHandleT is range 0..2**32 - 1;
for CardHandleT'Size use 32;
NullHandle : constant CardHandleT := 0;
end TokenReader.Interfac;