-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal-oidc.spthy
306 lines (277 loc) · 11.9 KB
/
signal-oidc.spthy
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
theory MessagingOIDC
begin
heuristic: o "./oracle.py"
#include "src/header.spthy"
#include "src/tls.spthy"
#include "src/idp.spthy"
#include "src/messaging.spthy"
rule Client:
[]
-->
[ !Client($App) ]
rule MessagingApp:
[ !Client($App) ]
--[ IsMessagingApp($App)
, OnlyOnce('messaging_app_client') ]->
[ !MessagingApp($App) ]
rule RedirectURL:
[ !IdP($IdP), !Client($App), !Domain($RedirectURL) ]
--[ IsRedirectURL($IdP, $App, $RedirectURL) ]->
[ !RedirectURL($IdP, $App, $RedirectURL) ]
// NOTE: This restriction might seem overly strict. This practically means that:
// We require the messaging app uses unique redirect URLs per IdP, and that any
// usage of the messaging app's redirect URL in other contexts counts as
// malicious. (Honest other apps cannot do that.)
restriction UniqueRedirectURLs:
"All idp1 idp2 app1 app2 url #t1 #t2 #t3.
( IsMessagingApp(app1) @ #t1
& IsRedirectURL(idp1, app1, url) @ #t2
& IsRedirectURL(idp2, app2, url) @ #t3)
==> (idp1 = idp2 & app1 = app2)"
// Clients need to memorize which query they issued last. We prefix rule name
// with 0_ s.t. it comes first in case ordering (which is alphabetical) of the
// executability lemma. Otherwise, there is an infinite loop.
rule 0_InitSessionStore:
[]
--[ OnlyOnce(<'init_session_store', $User>) ]->
[ SessionStore($User, 'null', 'null') ]
rule ClearSessionStore:
[ SessionStore($User, x, y) ]
-->
[ SessionStore($User, 'null', 'null') ]
// It is necessary handle forwards from the adversary dedicatedly, because
// otherwise, the adversary can choose the session they forward to. This would
// be unrealistic.
rule LinkClick[color=#FF6961]:
[ Fr(~sess), In(m), !Domain($Domain) ]
--[ AdversaryActivity() ]->
[ TLSClient_Out('GET', ~sess, $Domain, m)
, !Browser($Prover, ~sess) ]
// OpenID Connect Auth code + PKCE flow
rule OIDCAppLaunchBrowser[color=#B4D9EF]:
let fp = fingerprint(<pk(skProver), pkVerifier>)
hash = h(fp, salt)
code_challenge = s256(code_verifier)
in
[ !IdP($IdP), !MessagingApp($App)
, !RedirectURL($IdP, $App, $RedirectURL)
, !MessagingLtkUser($Prover, $ProverPhone, skProver)[no_precomp]
, !UseMessagingKeyFor($Prover, $VerifierPhone, pkVerifier)[no_precomp]
, SessionStore($Prover, drop1, drop2)
, Fr(salt), Fr(nonce), Fr(code_verifier), Fr(~sess) ]
--[ IsNonce(nonce)
, GenerateCodeVerifierFor(code_verifier, $IdP)
, SOAPStart($Prover, nonce)
, SOAPMessaging($Prover, nonce, pkVerifier, pk(skProver)) ]->
[ TLSClient_Out('GET', ~sess, $IdP, <'oidc_req', $App, hash, nonce, code_challenge, $RedirectURL>)
// This Out fact models that the adversary can access authorization requests.
, Out(<hash, nonce, code_challenge>)
, SessionStore($Prover, nonce, <$IdP, $VerifierPhone, hash, salt, code_verifier>)
, !Browser($Prover, ~sess) ]
rule OIDCIdPInit[color=#B4D9EF]:
[ !IdP($IdP)
, !RedirectURL($IdP, $Client, $RedirectURL)
, TLSServer_In('GET', ~sess, $IdP, <'oidc_req', $Client, hash, nonce, code_challenge, $RedirectURL>) ]
--[ MustBeNonce(nonce) ]->
[ TLSServer_Out('GET', ~sess, $IdP, 'auth_req')
, St_OIDCServer_Auth($IdP, $Client, $RedirectURL, ~sess, hash, nonce, code_challenge) ]
rule OIDCAppLogin[color=#B4D9EF]:
[ !Browser($Prover, ~sess)
, !IdP($IdP)
, TLSClient_In('GET', ~sess, $IdP, 'auth_req')
, !IdPAccount($Prover, $IdP, $Username, ~pw) ]
-->
[ TLSClient_Out('GET', ~sess, $IdP, <'login', $Username, ~pw>) ]
lemma PasswordsConfidential[reuse]:
"All user idp username pw #t1 #t2.
( Username(user, idp, username, pw) @ #t1
& KU(pw) @ #t2)
==> ( (Ex #x. CompromisedDomain(idp) @ #x)
| (Ex someone #x. CompromisedAccount(someone, idp, username) @ #x))"
lemma MessagingKeysUnique[reuse]:
"All userA userB phoneA phoneB sk #a #b.
ClaimMessagingKey(userA, phoneA, sk) @ #a
& ClaimMessagingKey(userB, phoneB, sk) @ #b
==> (#a = #b & userA = userB & phoneA = phoneB)
| KeyServerCompromise()"
rule OIDCIdPIssueCode[color=#B4D9EF]:
[ !IdP($IdP)
, !IdPAccount($User, $IdP, $Username, pw)
, Fr(~code)
, St_OIDCServer_Auth($IdP, $Client, $RedirectURL, ~sess, hash, nonce, code_challenge)
, TLSServer_In('GET', ~sess, $IdP, <'login', $Username, pw>) ]
--[ IsCode(~code)
, MustBeNonce(nonce)
, SOAPIdP($User, nonce, $IdP, $Username) ]->
[ TLSClient_Out('GET', ~sess, $RedirectURL, <'code', ~code, nonce>)
, St_OIDCIdP_Code($IdP, $Username, $Client, $RedirectURL, ~code, hash, nonce, code_challenge) ]
rule OIDCAppCodeRedirect[color=#B4D9EF]:
[ !RedirectURL($IdP, $App, $RedirectURL), !IdP($IdP)
, !MessagingApp($App)
, Fr(~sessPost)
, SessionStore($Prover, nonce, <$IdP, $VerifierPhone, hash, salt, code_verifier>)
, !Browser($Prover, ~sess)
, TLSServer_In('GET', ~sess, $RedirectURL, <'code', code, nonce>) ]
--[ SelfIssued($Prover, nonce)
, Neq(nonce, 'null')
, MustBeCode(code) ]->
[ TLSClient_Out('POST', ~sessPost, $IdP, <'token_req', code, code_verifier, $RedirectURL>)
, St_OIDCApp_CodeReq($Prover, $IdP, $VerifierPhone, ~sessPost, hash, salt, code)
, SessionStore($Prover, 'null', 'null') ]
rule OIDCIdPTokenIssue[color=#B4D9EF]:
let tokenBody = <$IdP, $Client, $Username, nonce, hash>
token = <tokenBody, sign(tokenBody, idpSk)>
in
[ !IdPLtk($IdP, idpSk)
, St_OIDCIdP_Code($IdP, $Username, $Client, $RedirectURL, code, hash, nonce, code_challenge)
, TLSServer_In('POST', ~sess, $IdP, <'token_req', code, code_verifier, $RedirectURL>) ]
--[ Eq(s256(code_verifier), code_challenge)
, IssueTokenForCode($IdP, ~sess, code)
, MustBeToken(token)
, UseCode($IdP, $Client, code)
, UseCodeVerifierFor($IdP, code_verifier) ]->
[ TLSServer_Out('POST', ~sess, $IdP, <'token', token>) ]
lemma CodeSecrecy[reuse]:
"All idp client code #t1 #t2 #t3.
( UseCode(idp, client, code) @ #t1
& IsMessagingApp(client) @ #t2
& KU(code) @ #t3)
==> ( (Ex #x. UsedCode(idp, code) @ #x & #x < #t3)
| (Ex url #x #y. IsRedirectURL(idp, client, url) @ #x & CompromisedDomain(url) @ #y)
| (Ex #x. CompromisedDomain(idp) @ #x))"
lemma CodeVerifierSecrecy[reuse]:
" All verifier idp #x #y.
UseCodeVerifierFor(idp, verifier) @ #x
& GenerateCodeVerifierFor(verifier, idp) @ #y
==> not (Ex #z. KU(verifier) @ #z)
| (Ex #z. CompromisedDomain(idp) @ #z)"
// This sources lemma combines multiple in spirit, but they need to assist each
// other in the proof, hence, they are combined.
lemma TokenFormatAndOTPLearning[sources]:
"(All token #i.
MustBeToken(token) @ #i
==> (Ex first second user idp client nonce hashed sk.
token = <first, second>
& first = <idp, client, user, nonce, hashed>
& ((Ex #h. KU(nonce) @ #h & #h < #i) | (Ex #h. IsNonce(nonce) @ #h))
& ((Ex #h. KU(hashed) @ #h & #h < #i) | (Ex fp salt. hashed = h(fp, salt)))
& second = sign(first, sk))
) & (All nonce #i.
MustBeNonce(nonce) @ #i
==> ( (Ex #h. KU(nonce) @ #h & #h < #i)
| (Ex #h. IsNonce(nonce) @ #h)))
& (All code #i.
MustBeCode(code) @ #i
==> ( (Ex #h. KU(code) @ #h & #h < #i)
| (Ex #h. IsCode(code) @ #h)))
& (All chall #i.
MustBeOTP(chall) @ #i
==> ( (Ex #j. IsOTP(chall) @ #j & #j < #i)
| (Ex #j. KU(chall) @ #j & #j < #i)))
& (All ltk #i.
MustBeMessagingKey(ltk) @ #i
==> ( (Ex sk #j. IsMessagingKey(sk) @ #j & ltk = pk(sk))
| (Ex #j. KU(ltk) @ #j & #j < #i)))"
rule OIDCTokenForward[color=#B4D9EF]:
let body = <$IdP, $App, $Username, nonce, hash>
fp = fingerprint(<pk(skProver), pkVerifier>)
token = <body, signature>
in
[ !IdP($IdP), !MessagingApp($App)
, !UseMessagingKeyFor($Prover, $VerifierPhone, pkVerifier)[no_precomp]
, !UseIdPKey($Prover, $IdP, pkIdP)
, !MessagingLtkUser($Prover, $ProverPhone, skProver)[no_precomp]
, St_OIDCApp_CodeReq($Prover, $IdP, $VerifierPhone, ~sessPost, hash, salt, code)
// We do not check the nonce in the ID token. This is to highlight that the
// inclusion of a true nonce in the ID token is not strictly necessary in the
// protocols design.
, TLSClient_In('POST', ~sessPost, $IdP, <'token', <<$IdP, $App, $Username, nonce, hash>, signature>>) ]
--[ Eq(h(fp, salt), hash)
, Eq(verify(signature, body, pkIdP), true)
, GetTokenForCode($IdP, ~sessPost, code)
, MustBeToken(token)
, MustBeCode(code)
, UsedCode($IdP, code) ]->
[ SendAsTo($Prover, $VerifierPhone, <'fwd_token', token, salt>)
// Sending the code models that the adversary can access the authorization
// response after the OpenID Connect protocol termianted successfully.
, Out(code) ]
lemma CodeAgreement[use_induction,reuse]:
"All idp sess codeClient codeIdP #t1 #t2.
GetTokenForCode(idp, sess, codeClient) @ #t1
& IssueTokenForCode(idp, sess, codeIdP) @ #t2
==> ( (codeClient = codeIdP)
| (Ex #x. CompromisedDomain(idp) @ #x))"
lemma CodeIsSingleUse[reuse]:
"All idp code #a #b.
(UsedCode(idp, code) @ #a & UsedCode(idp, code) @ #b)
==> ( #a = #b
| (Ex #x. CompromisedDomain(idp) @ #x)
| (Ex app url #x #y.
IsRedirectURL(idp, app, url) @ #x
& CompromisedDomain(url) @ #y))"
rule OIDCTokenReceive[color=#B4D9EF]:
let body = <$IdP, $App, $Username, nonce, hash>
fp = fingerprint(<pk(skProver), pk(skVerifier)>)
in
[ !MessagingLtkUser($Verifier, $VerifierPhone, skVerifier)[no_precomp]
, !UseMessagingKeyFor($Verifier, $ProverPhone, pk(skProver))[no_precomp]
, !MessagingApp($App)
, !UseIdPKey($Verifier, $IdP, pkIdP)
, In(e2ee(skProver, pk(skVerifier), <'fwd_token', <body, signature>, salt>)) ]
--[ Eq(h(fp, salt), hash)
, Eq(verify(signature, body, pkIdP), true)
, DidNotIssueSelf($Verifier, nonce)
, ReceivingKey(pk(skVerifier))
, Correspond($Verifier, pk(skProver), $IdP, $Username) ]->
[]
restriction CheckNonceReplay:
"All verifier nonce #t1.
DidNotIssueSelf(verifier, nonce) @ #t1
==> (not Ex #t2. SelfIssued(verifier, nonce) @ #t2)"
lemma Executability:
exists-trace
"Ex verifier proverKey idp acc verifierKey m1 m2 s1 s2
#t1 #t2 #t3 #t4 #t5.
Correspond(verifier, proverKey, idp, acc) @ #t1
& ReceiveMessaging(proverKey, verifierKey, m1) @ #t2
& ReceiveIdP(idp, acc, m2) @ #t3
& SendMessaging(proverKey, verifierKey, m1) @ #t4
& Sender(s1) @ #t4
& SendIdP(idp, acc, m2) @ #t5
& Sender(s2) @ #t5
& s1 = s2
& (not Ex #x. AdversaryActivity() @ #x)"
lemma SOAPAgreement[reuse]:
"All v proverKey idp acc verifierKey #t1.
( Correspond(v, proverKey, idp, acc) @ #t1
& ReceivingKey(verifierKey) @ #t1)
==> (Ex prover nonce #x1 #x2.
SOAPStart(prover, nonce) @ #x1
& SOAPMessaging(prover, nonce, verifierKey, proverKey) @ #x1
& SOAPIdP(prover, nonce, idp, acc) @ #x2)
| (Ex #x. CompromisedIdP(idp) @ #x)
| (Ex #x. CompromisedDomain(idp) @ #x)
| (Ex app redirectURL #x #y #z.
IsMessagingApp(app) @ #x
& IsRedirectURL(idp, app, redirectURL) @ #y
& CompromisedDomain(redirectURL) @ #z)
| (Ex p #x. CompromisedAccount(p, idp, acc) @ #x)
| (Ex p #x. CompromisedMessaging(p, proverKey) @ #x)"
lemma SocialAuthentication:
"All v sendKey rcvKey m1 idp acc m2 #t #r1 #r2.
( Correspond(v, sendKey, idp, acc) @ #t
& ReceiveMessaging(sendKey, rcvKey, m1) @ #r1
& ReceiveIdP(idp, acc, m2) @ #r2)
==> ( (Ex s #x1 #x2.
( SendMessaging(sendKey, rcvKey, m1) @ #x1 & Sender(s) @ #x1 & #x1 < #r1
& SendIdP(idp, acc, m2) @ #x2 & Sender(s) @ #x2 & #x2 < #r2))
| (Ex #x. CompromisedIdP(idp) @ #x)
| (Ex #x. CompromisedDomain(idp) @ #x)
| (Ex app redirectURL #x #y #z.
IsMessagingApp(app) @ #x
& IsRedirectURL(idp, app, redirectURL) @ #y
& CompromisedDomain(redirectURL) @ #z)
| (Ex p #x. CompromisedAccount(p, idp, acc) @ #x)
| (Ex p #x. CompromisedMessaging(p, sendKey) @ #x))"
end