5
5
import com .google .api .client .util .Clock ;
6
6
import com .google .auth .oauth2 .TokenVerifier ;
7
7
import com .google .common .base .Strings ;
8
- import com .uid2 .shared .secure .AttestationException ;
8
+ import com .uid2 .shared .secure .AttestationClientException ;
9
+ import com .uid2 .shared .secure .AttestationFailure ;
9
10
10
11
import java .io .IOException ;
11
12
import java .security .PublicKey ;
@@ -51,7 +52,7 @@ protected TokenSignatureValidator(PublicKey publicKeyOverride, Clock clockOverri
51
52
}
52
53
53
54
@ Override
54
- public TokenPayload validate (String tokenString ) throws AttestationException {
55
+ public TokenPayload validate (String tokenString ) throws AttestationClientException {
55
56
if (Strings .isNullOrEmpty (tokenString )) {
56
57
throw new IllegalArgumentException ("tokenString can not be null or empty" );
57
58
}
@@ -65,9 +66,9 @@ public TokenPayload validate(String tokenString) throws AttestationException {
65
66
signature = tokenVerifier .verify (tokenString );
66
67
}
67
68
} catch (TokenVerifier .VerificationException e ) {
68
- throw new AttestationException ("Fail to validate the token signature, error: " + e .getMessage ());
69
+ throw new AttestationClientException ("Fail to validate the token signature, error: " + e .getMessage (), AttestationFailure . BAD_CERTIFICATE );
69
70
} catch (IOException e ) {
70
- throw new AttestationException ("Fail to parse token, error: " + e .getMessage ());
71
+ throw new AttestationClientException ("Fail to parse token, error: " + e .getMessage (), AttestationFailure . BAD_PAYLOAD );
71
72
}
72
73
73
74
// Parse Payload
@@ -78,20 +79,20 @@ public TokenPayload validate(String tokenString) throws AttestationException {
78
79
tokenPayloadBuilder .dbgStat (tryGetField (rawPayload , "dbgstat" , String .class ));
79
80
tokenPayloadBuilder .swName (tryGetField (rawPayload , "swname" , String .class ));
80
81
var swVersion = tryGetField (rawPayload , "swversion" , List .class );
81
- if (swVersion != null && !swVersion .isEmpty ()){
82
+ if (swVersion != null && !swVersion .isEmpty ()) {
82
83
tokenPayloadBuilder .swVersion (tryConvert (swVersion .get (0 ), String .class ));
83
84
}
84
85
85
- var subModsDetails = tryGetField (rawPayload ,"submods" , Map .class );
86
+ var subModsDetails = tryGetField (rawPayload , "submods" , Map .class );
86
87
87
- if (subModsDetails != null ){
88
+ if (subModsDetails != null ) {
88
89
var confidential_space = tryGetField (subModsDetails , "confidential_space" , Map .class );
89
- if (confidential_space != null ){
90
+ if (confidential_space != null ) {
90
91
tokenPayloadBuilder .csSupportedAttributes (tryGetField (confidential_space , "support_attributes" , List .class ));
91
92
}
92
93
93
94
var container = tryGetField (subModsDetails , "container" , Map .class );
94
- if (container != null ){
95
+ if (container != null ) {
95
96
tokenPayloadBuilder .workloadImageReference (tryGetField (container , "image_reference" , String .class ));
96
97
tokenPayloadBuilder .workloadImageDigest (tryGetField (container , "image_digest" , String .class ));
97
98
tokenPayloadBuilder .restartPolicy (tryGetField (container , "restart_policy" , String .class ));
@@ -101,14 +102,12 @@ public TokenPayload validate(String tokenString) throws AttestationException {
101
102
}
102
103
103
104
var gce = tryGetField (subModsDetails , "gce" , Map .class );
104
- if (gce != null ){
105
+ if (gce != null ) {
105
106
var gceZone = tryGetField (gce , "zone" , String .class );
106
107
tokenPayloadBuilder .gceZone (gceZone );
107
108
}
108
109
}
109
110
110
111
return tokenPayloadBuilder .build ();
111
112
}
112
-
113
-
114
113
}
0 commit comments