101101 gap : 10px ;
102102 margin : 20px 0 ;
103103 }
104+ .success-message {
105+ color : # 2e7d32 ;
106+ margin-top : 10px ;
107+ display : none;
108+ padding : 15px ;
109+ background-color : rgba (232 , 245 , 233 , 0.9 );
110+ border-radius : 20px ;
111+ backdrop-filter : blur (8px );
112+ }
104113 </ style >
105114</ head >
106115< body >
@@ -113,6 +122,9 @@ <h1>Tesla Fleet Telemetry Operator</h1>
113122 < button class ="tesla-button " onclick ="generateToken() ">
114123 Generate Partner Token & Register
115124 </ button >
125+ < button class ="tesla-button secondary " onclick ="verifyKey() ">
126+ Verify Public Key
127+ </ button >
116128 < button class ="tesla-button secondary " onclick ="window.location.href='/.well-known/appspecific/com.tesla.3p.public-key.pem' ">
117129 Download Public Key
118130 </ button >
@@ -126,16 +138,23 @@ <h3>Partner Authentication Token:</h3>
126138 < h3 > Registration Response:</ h3 >
127139 < pre id ="registrationContent "> </ pre >
128140 </ div >
141+ < div class ="response-section ">
142+ < h3 > Verification Response:</ h3 >
143+ < pre id ="verificationContent "> </ pre >
144+ </ div >
129145 </ div >
130146 < div id ="errorMessage " class ="error-message "> </ div >
147+ < div id ="successMessage " class ="success-message "> </ div >
131148 </ div >
132149
133150 < script >
134151 async function generateToken ( ) {
135152 const responseDisplay = document . getElementById ( 'responseDisplay' ) ;
136153 const tokenContent = document . getElementById ( 'tokenContent' ) ;
137154 const registrationContent = document . getElementById ( 'registrationContent' ) ;
155+ const verificationContent = document . getElementById ( 'verificationContent' ) ;
138156 const errorMessage = document . getElementById ( 'errorMessage' ) ;
157+ const successMessage = document . getElementById ( 'successMessage' ) ;
139158
140159 try {
141160 const response = await fetch ( '/generate-token' , {
@@ -150,11 +169,48 @@ <h3>Registration Response:</h3>
150169 const data = await response . json ( ) ;
151170 tokenContent . textContent = JSON . stringify ( data . token , null , 2 ) ;
152171 registrationContent . textContent = JSON . stringify ( data . registration , null , 2 ) ;
172+ verificationContent . textContent = JSON . stringify ( data . verification , null , 2 ) ;
173+ responseDisplay . style . display = 'block' ;
174+ errorMessage . style . display = 'none' ;
175+ successMessage . textContent = 'Registration and verification successful!' ;
176+ successMessage . style . display = 'block' ;
177+ } catch ( error ) {
178+ errorMessage . textContent = error . message ;
179+ errorMessage . style . display = 'block' ;
180+ successMessage . style . display = 'none' ;
181+ responseDisplay . style . display = 'none' ;
182+ }
183+ }
184+
185+ async function verifyKey ( ) {
186+ const responseDisplay = document . getElementById ( 'responseDisplay' ) ;
187+ const tokenContent = document . getElementById ( 'tokenContent' ) ;
188+ const verificationContent = document . getElementById ( 'verificationContent' ) ;
189+ const errorMessage = document . getElementById ( 'errorMessage' ) ;
190+ const successMessage = document . getElementById ( 'successMessage' ) ;
191+
192+ try {
193+ const response = await fetch ( '/verify-key' , {
194+ method : 'POST' ,
195+ } ) ;
196+
197+ if ( ! response . ok ) {
198+ const errorData = await response . json ( ) ;
199+ throw new Error ( errorData . error || 'Failed to verify public key' ) ;
200+ }
201+
202+ const data = await response . json ( ) ;
203+ tokenContent . textContent = JSON . stringify ( data . token , null , 2 ) ;
204+ verificationContent . textContent = JSON . stringify ( data . verification , null , 2 ) ;
205+ document . querySelector ( '.response-section:nth-child(2)' ) . style . display = 'none' ;
153206 responseDisplay . style . display = 'block' ;
154207 errorMessage . style . display = 'none' ;
208+ successMessage . textContent = 'Public key verification successful!' ;
209+ successMessage . style . display = 'block' ;
155210 } catch ( error ) {
156211 errorMessage . textContent = error . message ;
157212 errorMessage . style . display = 'block' ;
213+ successMessage . style . display = 'none' ;
158214 responseDisplay . style . display = 'none' ;
159215 }
160216 }
0 commit comments