Mobile_Mastercard.spthy 10.9 KB
Newer Older
EMV RP's avatar
EMV RP committed
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
theory Mastercard_ApplePay

begin

builtins:   signing, asymmetric-encryption

functions:  MAC/2 //(Key, payload)

rule Terminal_Bank_Network:
    [ Send(S, R, channelID, msg) ]-->[ Recv(S, R, channelID, msg) ]

restriction once:
    "All a #i #j. Once(a)@i & Once(a)@j ==> #i = #j"

restriction equal:
  "All a b #i. Eq(a, b)@i ==> a = b"

/* Facts used in model:

The certificate autherites:
    !LtkCA($CA, ~privkCA) Cert auth $CA has the private key privkCA 
    !CertCA($CA, cert) Cert auth $CA's public key certificate is cert

The banks
    !LtkBank($Bank, ~privkBank),
    !CertBank($Bank, cert),
    !IssuingCA($Bank, $CA),

A Mastercard:
    !Card(~Track2, $Bank, ~KM, ~privkCard, certCard, certBank, cardAIP, CVMlist)   (We do not model the file locator: AFL

The Terminal
    !Terminal($Term,MCC) : The merchent code of the Terminal, either 'transit' or 'retail' 
    Terminal_Running($Term, ~Track2, 'high', ~UN, certCard)

Sign types: 
    01: card cert
    02: bank cert
    03: CA cert
    04: SDAD

Important checks made by the protocol
    CHECK 1: The Terminal_Sends_READRECORD_MC rule checks that the cards AIP is CDA mode
    CHECK 2: Before generating the GEN AC message the reader will check the CVM_list includes online.
    CHECK 3: After the read record the terminal must check bank and card Certs, using a CA. 
    CHECK 4: In reponse to GEN AC, the device may approve any amount if CDCVM used
    CHECK 5: Device may approve a low amount with No CDCVM if Magic Bytes are used and the MCC is transit
    CHECK 6: Check SDAD is correctly signed with the expected fields. 
    CHECK 7: Bank can approve a high or low amount if IAD to shows that CDCVM was used. 
     CHECK 8: Bank can approve a low amount without CDCVM if MCC = transit. 
*/


rule Create_Mastercard_Apple_Pay:
    let 
        pubkCard = pk(~privkCard)
        cont = <'01', ~Track2, pubkCard, $Bank>
        certCard = <cont, sign{cont}~privkBank>
        cardAIP = <'CDA','CDCVM'> // Card will only CDA and offers CDCVM
        CVMlist ='PIN_online'     // Card would like online auth, other list options (e.g. magstrip not modelled)
    in
    [ 
        !LtkBank($Bank, ~privkBank),  !CertBank($Bank, certBank),
        Fr(~Track2), Fr(~privkCard), Fr(~KM)
    ]
    -->
    [ !Card(~Track2, $Bank, ~KM, ~privkCard, pubkCard, certCard, certBank, cardAIP, CVMlist) ]
  
rule Create_CA:
    let pubkCA = pk(~privkCA)
        cont = <'03', $CA, pubkCA, $CA>
        cert = <cont, sign{cont}~privkCA>
    in
    [ Fr(~privkCA) ]
    --[ Once($CA) ]->
    [   
        !LtkCA($CA, ~privkCA),
        !CertCA($CA, cert),
        Out(pubkCA)
    ]

rule Create_Bank:
    let pubkBank = pk(~privkBank)
        cont = <'02', $Bank, pubkBank, $CA>
        cert = <cont, sign{cont}~privkCA>
    in
    [ Fr(~privkBank), !LtkCA($CA, ~privkCA) ]
  --[ Once($Bank) ]->
    [ 
        !LtkBank($Bank, ~privkBank), !CertBank($Bank, cert),
        !IssuingCA($Bank, $CA), Out(pubkBank)
    ]

rule Create_Transit_Terminal:
    let
        MCC='transit'
    in 
        [ ] --[ TerminalCreated($Term,MCC), Once($Term) ]-> [ !Terminal($Term,MCC) ]

rule Create_Retail_Terminal:
    let
        MCC='retail'
    in 
        [ ] --[ TerminalCreated($Term,MCC), Once($Term) ]-> [ !Terminal($Term,MCC) ]



/* We only consider comprimsed cards (e.g. key leakage via power analysis attacks) 
   Compromised terminals, banks and CAs are outisde our attack model. */

rule Compromise_Card:
    [ !Card(Track2, Bank, KM, privkCard, pubkCard, certCard, certBank, cardAIP, CVMlist) ]
  --[ Compromise(Track2) ]->
    [ Out(<Track2, privkCard, KM, certCard>) ]

/*
   PROTOCOL RULES 
*/

rule Terminal_Sends_GPO_MC:
    [  ] --> [ Out(<'GET_PROCESSING_OPTIONS'>) ]

rule Card_Responds_To_GPO_MC_AP:
    [ 
        !Card(~Track2, $Bank, ~KM, ~privkCard, pubkCard, certCard, certBank, cardAIP, CVMlist),
        In(<'GET_PROCESSING_OPTIONS'>) ] 
    --> [ Out(<cardAIP,'AFL'>) ]

// CHECK 1: Reader is online CDA only, so Check the AIP
rule Terminal_Sends_READRECORD_MC:
    let
        AIP =<'CDA',CDCVMmode>
    in
    [ In(<AIP,'AFL'>) ] 
    -->
    [ Out(<'READRECORD'>), Terminal_Started(AIP) ]

// Contents of CDOL1 and 2 not modelled, it is assumpted they will match the CDOL data below, 
// if they don't the protocol will halt.
rule Card_Responds_To_READRECORD_MC_AP:
    [ 
        !Card(~Track2, $Bank, ~KM, ~privkCard, pubkCard, certCard, certBank, cardAIP, CVMlist),
        In(<'READRECORD'>) ] 
    --> [ Out(<~Track2, CVMlist, certCard, certBank, 'CDOL1', 'CDOL2'>) ]

// GEN AC command for a high amout. 
// Reader does not check if the device can do CDCVM before trying a high amount, because the card
// might agree to a high amount without CDCVM and ask the reader to do Tap and PIN (Euro cards only
// Rest of The World cards do not support this.  
//
// CHECK 2: CVM_list must include 'PIN_online'.
// CHECK 3: Check bank and card Certs. 
rule Terminal_Sends_GEN_AC_High_MC:
    let 
        CDOL1_DATA = <'amount_high', ~UN, MCC, 'CDA'>
        AIP =<'CDA',CDCVMmode>
        certBank = <<'02', $Bank, pubkBank, $CA>, sigCA>
        certCard = <<'01', Track2, pubkCard, $Bank>, sigBank>
    in
    [ 
        Fr(~UN), In(<Track2, 'PIN_online', certCard, certBank, CDOL1, CDOL2>),
        !Terminal($Term,MCC), Terminal_Started(AIP),
        !CertCA($CA, <<'03', $CA, pubkCA, $CA>, sign1>)
    ] 
    --[
        Eq( verify(sigCA, <'02', $Bank, pubkBank, $CA>, pubkCA), true),
        Eq( verify(sigBank, <'01', Track2, pubkCard, $Bank>, pubkBank), true)
    ]-> 
    [ 
        Out(<'GEN_AC', CDOL1_DATA >),
        Terminal_Running($Term, Track2, 'amount_high', ~UN, AIP, pubkCard) 
    ]

// CHECK 2: CVM_list must include 'PIN_online'.
// CHECK 3: Check bank and card Certs. 
rule Terminal_Sends_GEN_AC_Low_MC:
    let 
        CDOL1_DATA = <'amount_low', ~UN, MCC, 'CDA'>
        AIP =<'CDA',CDCVMmode>
        certBank = <<'02', $Bank, pubkBank, $CA>, sigCA>
        certCard = <<'01', Track2, pubkCard, $Bank>, sigBank>
    in
    [ 
        Fr(~UN), In(<Track2, 'PIN_online', certCard, certBank, CDOL1, CDOL2>),
        !Terminal($Term,MCC), Terminal_Started(AIP), 
        !CertCA($CA, <<'03', $CA, pubkCA, $CA>, sign1>)
    ] 
    --[
        Eq( verify(sigCA, <'02', $Bank, pubkBank, $CA>, pubkCA), true),
        Eq( verify(sigBank, <'01', Track2, pubkCard, $Bank>, pubkBank), true)
    ]-> 
    [ 
        Out(<'GEN_AC', CDOL1_DATA >),
        Terminal_Running($Term, Track2, 'amount_low', ~UN, AIP, pubkCard) 
    ]


// CHECK 4: Device may approve any amount if CDCVM used
rule Card_Responds_To_GEN_AC_High_Or_Low_CDCVM_MC:
    let 
        CDOL1_DATA = <amount, UN, MCC, 'CDA'>
        cont = <'01', Track2, pubkCard, $Bank>
        certCard = <cont, sign{cont}~privkBank> // Reader needs bank pub key.
        KS = aenc{~ATC}KM
        AC = MAC(KS,<CDOL1_DATA,AIP,~ATC>)
        SDAD = sign{'04', AC, CDOL1_DATA, UN}privkCard
    in
    [ 
        Fr(~ATC), In(<'GEN_AC', CDOL1_DATA >),
        !Card(Track2, $Bank, KM, privkCard, pubkCard, certCard, certBank, AIP, CVMlist)
    ] 
    --[ CDCVM_Used( UN, Track2) ]->
    [ Out( <~ATC, SDAD, AC, 'IAD_AP_CDCVM'> ) ]

// CHECK 5: Device may approve a low amount with No CDCVM if Magic Bytes are used and the MCC is transit
rule Card_Responds_To_GEN_AC_Low_NoCDCVM_MC:
    let 
        CDOL1_DATA = <'amount_low', UN, 'transit', 'CDA'>
        KS = aenc{~ATC}KM
        AC = MAC(KS,<CDOL1_DATA,AIP,~ATC>)
        SDAD = sign{'04', AC, CDOL1_DATA, UN}privkCard
    in
    [ 
        Fr(~ATC), In(<'GEN_AC', CDOL1_DATA >),
        !Card(Track2, $Bank, KM, privkCard, pubkCard, certCard, certBank, AIP, CVMlist)
    ] 
    --[ MagicBytesRequired( UN, Track2) ]->
    [ Out( <~ATC, SDAD, AC, 'IAD_AP_NoCDCVM'> ) ]

// Reader does not check the IAD for CDCVM, but sends this to the bank to use.
// CHECK 6: Check SDAD is correctly signed with the expected fields. 
rule Terminal_Forward_To_Bank:
    let
        CDOL1_DATA = <amount, UN, MCC, 'CDA'>
    in
    [ 
        In(<ATC, SDAD, AC, IAD>), !Terminal($Term,MCC),  Fr(~sessionID),
        Terminal_Running($Term, Track2, amount, UN, AIP, pubkCard)
    ]
    --[
        Eq( verify(SDAD, <'04', AC, CDOL1_DATA, UN>, pubkCard), true)
    ]->
    [ 
        Send($Term,$Bank,~sessionID,< Track2, AIP, CDOL1_DATA, ATC, IAD, AC>),
        Terminal_Sent_to_Bank($Term, Track2, amount, UN, ~sessionID) 
    ]

// CHECK 7: Bank can approve a high or low amount if IAD to shows that CDCVM was used. 
rule Bank_response_to_Terminal_High:
    let
        CDOL1_DATA = <'amount_high', UN, MCC, 'CDA'>
        Ks = aenc{ATC}KM
        AC = MAC(Ks, <CDOL1_DATA, AIP, ATC>)
    in
    [ 
        Recv($Term,$Bank,sessionID,< Track2, AIP, CDOL1_DATA, ATC, 'IAD_AP_CDCVM', AC>),
        !Card(Track2, $Bank, KM, privkCard, pubkCard, certCard, certBank, AIP, CVMlist) ]
    --[ 
        Bank_Accepts($Term, $Bank, UN, MCC, sessionID, Track2, AIP, CDOL1_DATA, ATC, 'IAD_AP_CDCVM', AC),
        Bank_Accepts_Short(UN, Track2), Bank_Accepts_CDCVM(UN, Track2) 
    ]-> [ ]

// CHECK 8: Bank can approve a low amount without CDCVM if MCC = transit. 
rule Bank_response_to_Terminal_Low:
    let
        CDOL1_DATA = <'amount_low', UN, 'transit', 'CDA'>
        Ks = aenc{ATC}KM
        AC = MAC(Ks, <CDOL1_DATA, AIP, ATC>)
    in
    [ 
        Recv($Term,$Bank,sessionID,< Track2, AIP, CDOL1_DATA, ATC, 'IAD_AP_NoCDCVM', AC>),
        !Card(Track2, $Bank, KM, privkCard, pubkCard, certCard, certBank, AIP, CVMlist) ]
    --[ 
        Bank_Accepts($Term, $Bank, UN, 'transit', sessionID, Track2, AIP, CDOL1_DATA, ATC, 'IAD_AP_NoCDCVM', AC),
        Bank_Accepts_Short(UN, Track2), Bank_Accepts_NoCDCVM(UN, Track2) 
    ]-> [ ]


// Sanity checks: protocol can terminate with and without CDCVM


lemma Can_Finish_NoCDCVM:
  exists-trace
  "Ex Track2 UN #i.
     Bank_Accepts_NoCDCVM(UN, Track2)@i"

lemma Can_Finish_CDCVM:
  exists-trace
  "Ex Track2 UN #i.
    Bank_Accepts_CDCVM(UN, Track2)@i"


// Authentication of the MMC (need if this is going to be used by the bank for a correctness check
lemma  Bank_Gets_Correct_MMC:
  "All Term Bank sessionID Track2 AIP CDOL1_DATA ATC IAD AC UN MCC #i.
    Bank_Accepts( Term, Bank, UN, MCC, sessionID, Track2, AIP, CDOL1_DATA, ATC, IAD, AC )@i
   ==>
    Ex #j.  TerminalCreated(Term,MCC)@j"


// Following three results so that only transit terminals can bypass the CDCVM 
//   i.e., the Visa Apple Pay attack doesn't work against uncompromised Mastercard.  
lemma High_Amount_Needs_CDCVM:
  "All UN Track2 #i.
    (Bank_Accepts_CDCVM(UN, Track2)@i & not (Ex #a. Compromise(Track2)@a))
   ==>
    Ex #j. CDCVM_Used( UN, Track2)@j"

lemma Bypassing_CDCVM_Needs_MagicBytes:
  "All UN Track2 #i.
    (Bank_Accepts_Short(UN, Track2)@i & not (Ex #a. Compromise(Track2)@a))
   ==>
    (Ex #j. CDCVM_Used( UN, Track2)@j) | (Ex #k. MagicBytesRequired( UN, Track2)@k)"

lemma  Bypassing_CDCVM_Needs_MCC_Equal_Transit:
  "All Term Bank sessionID Track2 AIP CDOL1_DATA ATC IAD AC UN MCC #i.
    (Bank_Accepts( Term, Bank, UN, MCC, sessionID, Track2, AIP, CDOL1_DATA, ATC, IAD, AC )@i
      & not (Ex #a. Compromise(Track2)@a))
   ==>
    (Ex #j. CDCVM_Used( UN, Track2)@j) | (MCC='transit')"

end