@@ -25,9 +25,9 @@ export function initUserAuthWebAuthn() {
25
25
26
26
$ . getJSON ( `${ appSubUrl } /user/webauthn/assertion` , { } )
27
27
. done ( ( makeAssertionOptions ) => {
28
- makeAssertionOptions . publicKey . challenge = decodeFromBase64 ( makeAssertionOptions . publicKey . challenge ) ;
28
+ makeAssertionOptions . publicKey . challenge = decodeURLEncodedBase64 ( makeAssertionOptions . publicKey . challenge ) ;
29
29
for ( let i = 0 ; i < makeAssertionOptions . publicKey . allowCredentials . length ; i ++ ) {
30
- makeAssertionOptions . publicKey . allowCredentials [ i ] . id = decodeFromBase64 ( makeAssertionOptions . publicKey . allowCredentials [ i ] . id ) ;
30
+ makeAssertionOptions . publicKey . allowCredentials [ i ] . id = decodeURLEncodedBase64 ( makeAssertionOptions . publicKey . allowCredentials [ i ] . id ) ;
31
31
}
32
32
navigator . credentials . get ( {
33
33
publicKey : makeAssertionOptions . publicKey
@@ -67,14 +67,14 @@ function verifyAssertion(assertedCredential) {
67
67
type : 'POST' ,
68
68
data : JSON . stringify ( {
69
69
id : assertedCredential . id ,
70
- rawId : bufferEncode ( rawId ) ,
70
+ rawId : bufferURLEncodedBase64 ( rawId ) ,
71
71
type : assertedCredential . type ,
72
72
clientExtensionResults : assertedCredential . getClientExtensionResults ( ) ,
73
73
response : {
74
- authenticatorData : bufferEncode ( authData ) ,
75
- clientDataJSON : bufferEncode ( clientDataJSON ) ,
76
- signature : bufferEncode ( sig ) ,
77
- userHandle : bufferEncode ( userHandle ) ,
74
+ authenticatorData : bufferURLEncodedBase64 ( authData ) ,
75
+ clientDataJSON : bufferURLEncodedBase64 ( clientDataJSON ) ,
76
+ signature : bufferURLEncodedBase64 ( sig ) ,
77
+ userHandle : bufferURLEncodedBase64 ( userHandle ) ,
78
78
} ,
79
79
} ) ,
80
80
contentType : 'application/json; charset=utf-8' ,
@@ -96,14 +96,21 @@ function verifyAssertion(assertedCredential) {
96
96
} ) ;
97
97
}
98
98
99
- // Encode an ArrayBuffer into a base64 string.
100
- function bufferEncode ( value ) {
99
+ // Encode an ArrayBuffer into a URLEncoded base64 string.
100
+ function bufferURLEncodedBase64 ( value ) {
101
101
return encodeToBase64 ( value )
102
102
. replace ( / \+ / g, '-' )
103
103
. replace ( / \/ / g, '_' )
104
104
. replace ( / = / g, '' ) ;
105
105
}
106
106
107
+ // Dccode a URLEncoded base64 to an ArrayBuffer string.
108
+ function decodeURLEncodedBase64 ( value ) {
109
+ return decodeFromBase64 ( value
110
+ . replace ( / _ / g, '/' )
111
+ . replace ( / - / g, '+' ) ) ;
112
+ }
113
+
107
114
function webauthnRegistered ( newCredential ) {
108
115
const attestationObject = new Uint8Array ( newCredential . response . attestationObject ) ;
109
116
const clientDataJSON = new Uint8Array ( newCredential . response . clientDataJSON ) ;
@@ -115,11 +122,11 @@ function webauthnRegistered(newCredential) {
115
122
headers : { 'X-Csrf-Token' : csrfToken } ,
116
123
data : JSON . stringify ( {
117
124
id : newCredential . id ,
118
- rawId : bufferEncode ( rawId ) ,
125
+ rawId : bufferURLEncodedBase64 ( rawId ) ,
119
126
type : newCredential . type ,
120
127
response : {
121
- attestationObject : bufferEncode ( attestationObject ) ,
122
- clientDataJSON : bufferEncode ( clientDataJSON ) ,
128
+ attestationObject : bufferURLEncodedBase64 ( attestationObject ) ,
129
+ clientDataJSON : bufferURLEncodedBase64 ( clientDataJSON ) ,
123
130
} ,
124
131
} ) ,
125
132
dataType : 'json' ,
@@ -195,11 +202,11 @@ function webAuthnRegisterRequest() {
195
202
} ) . done ( ( makeCredentialOptions ) => {
196
203
$ ( '#nickname' ) . closest ( 'div.field' ) . removeClass ( 'error' ) ;
197
204
198
- makeCredentialOptions . publicKey . challenge = decodeFromBase64 ( makeCredentialOptions . publicKey . challenge ) ;
199
- makeCredentialOptions . publicKey . user . id = decodeFromBase64 ( makeCredentialOptions . publicKey . user . id ) ;
205
+ makeCredentialOptions . publicKey . challenge = decodeURLEncodedBase64 ( makeCredentialOptions . publicKey . challenge ) ;
206
+ makeCredentialOptions . publicKey . user . id = decodeURLEncodedBase64 ( makeCredentialOptions . publicKey . user . id ) ;
200
207
if ( makeCredentialOptions . publicKey . excludeCredentials ) {
201
208
for ( let i = 0 ; i < makeCredentialOptions . publicKey . excludeCredentials . length ; i ++ ) {
202
- makeCredentialOptions . publicKey . excludeCredentials [ i ] . id = decodeFromBase64 ( makeCredentialOptions . publicKey . excludeCredentials [ i ] . id ) ;
209
+ makeCredentialOptions . publicKey . excludeCredentials [ i ] . id = decodeURLEncodedBase64 ( makeCredentialOptions . publicKey . excludeCredentials [ i ] . id ) ;
203
210
}
204
211
}
205
212
0 commit comments