File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 43
43
"mypy" ,
44
44
"types-cryptography" ,
45
45
"types-requests" ,
46
+ "types-pyjwt" ,
46
47
]
47
48
},
48
49
classifiers = [
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ class FulcioCertificateSigningRequest:
70
70
"""Certificate request"""
71
71
72
72
public_key : ec .EllipticCurvePublicKey
73
- signed_email_address : bytes
73
+ signed_proof : bytes
74
74
75
75
@property
76
76
def data (self ) -> str :
@@ -82,7 +82,7 @@ def data(self) -> str:
82
82
"publicKey" : {
83
83
"content" : base64 .b64encode (content ).decode (),
84
84
},
85
- "signedEmailAddress" : base64 .b64encode (self .signed_email_address ).decode (),
85
+ "signedEmailAddress" : base64 .b64encode (self .signed_proof ).decode (),
86
86
}
87
87
return json .dumps (data )
88
88
Original file line number Diff line number Diff line change
1
+ import jwt
2
+
3
+ # From https://github.com/sigstore/fulcio/blob/b2186c01da1ddf807bde3ea8c450226d8e001d88/pkg/config/config.go#L182-L201 # noqa
4
+ OIDC_ISSUERS = {
5
+ "https://accounts.google.com" : "email" ,
6
+ "https://oauth2.sigstore.dev/auth" : "email" ,
7
+ "https://token.actions.githubusercontent.com" : "sub" ,
8
+ }
9
+ AUDIENCE = "sigstore"
10
+
11
+
12
+ class IdentityError (Exception ):
13
+ pass
14
+
15
+
16
+ class Identity :
17
+ def __init__ (self , identity_token : str ) -> None :
18
+ identity_jwt = jwt .decode (identity_token , options = {"verify_signature" : False })
19
+
20
+ if "iss" not in identity_jwt :
21
+ raise IdentityError ("Identity token missing the required 'iss' claim" )
22
+
23
+ iss = identity_jwt .get ("iss" )
24
+
25
+ if iss not in OIDC_ISSUERS :
26
+ raise IdentityError (f"Not a valid OIDC issuer: { iss !r} " )
27
+
28
+ if "aud" not in identity_jwt :
29
+ raise IdentityError ("Identity token missing the required 'aud' claim" )
30
+
31
+ aud = identity_jwt .get ("aud" )
32
+
33
+ if aud != AUDIENCE :
34
+ raise IdentityError (f"Audience should be { AUDIENCE !r} , not { aud !r} " )
35
+
36
+ proof_claim = OIDC_ISSUERS [iss ]
37
+ if proof_claim not in identity_jwt :
38
+ raise IdentityError (
39
+ f"Identity token missing the required { proof_claim !r} claim"
40
+ )
41
+
42
+ self .proof = identity_jwt .get (proof_claim )
You can’t perform that action at this time.
0 commit comments