Changeset 256201 in webkit
- Timestamp:
- Feb 10, 2020 12:26:04 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r256196 r256201 1 2020-02-10 Jiewen Tan <jiewen_tan@apple.com> 2 3 [WebAuthn] Merge some of the CTAP response decoder's code 4 https://bugs.webkit.org/show_bug.cgi?id=205375 5 6 Reviewed by Darin Adler. 7 8 This patch makes those code more compact and maintainable. 9 10 No change of behaviors. 11 12 * Modules/webauthn/fido/DeviceResponseConverter.cpp: 13 (fido::decodeResponseMap): 14 (fido::readCTAPMakeCredentialResponse): 15 (fido::readCTAPGetAssertionResponse): 16 (fido::readCTAPGetInfoResponse): 17 * Modules/webauthn/fido/DeviceResponseConverter.h: 18 * Modules/webauthn/fido/Pin.cpp: 19 (fido::pin::encodePinCommand): 20 (fido::pin::RetriesResponse::parse): 21 (fido::pin::KeyAgreementResponse::parse): 22 (fido::pin::TokenResponse::parse): 23 1 24 2020-02-10 Megan Gardner <megan_gardner@apple.com> 2 25 -
trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp
r254356 r256201 55 55 } 56 56 57 Optional<cbor::CBORValue> decodeResponseMap(const Vector<uint8_t>& inBuffer) 58 { 59 if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess) 60 return WTF::nullopt; 61 62 Vector<uint8_t> buffer; 63 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 64 Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer); 65 if (!decodedResponse || !decodedResponse->isMap()) 66 return WTF::nullopt; 67 return decodedResponse; 68 } 69 57 70 CtapDeviceResponseCode getResponseCode(const Vector<uint8_t>& buffer) 58 71 { … … 86 99 RefPtr<AuthenticatorAttestationResponse> readCTAPMakeCredentialResponse(const Vector<uint8_t>& inBuffer, const AttestationConveyancePreference& attestation) 87 100 { 88 if (inBuffer.size() <= kResponseCodeLength) 89 return nullptr; 90 91 Vector<uint8_t> buffer; 92 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 93 Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer); 94 if (!decodedResponse || !decodedResponse->isMap()) 95 return nullptr; 96 const auto& decodedMap = decodedResponse->getMap(); 97 98 auto it = decodedMap.find(CBOR(1)); 99 if (it == decodedMap.end() || !it->second.isString()) 101 auto decodedMap = decodeResponseMap(inBuffer); 102 if (!decodedMap) 103 return nullptr; 104 const auto& responseMap = decodedMap->getMap(); 105 106 auto it = responseMap.find(CBOR(1)); 107 if (it == responseMap.end() || !it->second.isString()) 100 108 return nullptr; 101 109 auto format = it->second.clone(); 102 110 103 it = decodedMap.find(CBOR(2));104 if (it == decodedMap.end() || !it->second.isByteString())111 it = responseMap.find(CBOR(2)); 112 if (it == responseMap.end() || !it->second.isByteString()) 105 113 return nullptr; 106 114 auto authenticatorData = it->second.clone(); … … 110 118 return nullptr; 111 119 112 it = decodedMap.find(CBOR(3));113 if (it == decodedMap.end() || !it->second.isMap())120 it = responseMap.find(CBOR(3)); 121 if (it == responseMap.end() || !it->second.isMap()) 114 122 return nullptr; 115 123 auto attStmt = it->second.clone(); … … 134 142 RefPtr<AuthenticatorAssertionResponse> readCTAPGetAssertionResponse(const Vector<uint8_t>& inBuffer) 135 143 { 136 if (inBuffer.size() <= kResponseCodeLength) 137 return nullptr; 138 139 Vector<uint8_t> buffer; 140 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 141 Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer); 142 143 if (!decodedResponse || !decodedResponse->isMap()) 144 return nullptr; 145 146 auto& responseMap = decodedResponse->getMap(); 144 auto decodedMap = decodeResponseMap(inBuffer); 145 if (!decodedMap) 146 return nullptr; 147 const auto& responseMap = decodedMap->getMap(); 147 148 148 149 auto it = responseMap.find(CBOR(1)); … … 201 202 Optional<AuthenticatorGetInfoResponse> readCTAPGetInfoResponse(const Vector<uint8_t>& inBuffer) 202 203 { 203 if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess) 204 return WTF::nullopt; 205 206 Vector<uint8_t> buffer; 207 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 208 Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer); 209 if (!decodedResponse || !decodedResponse->isMap()) 210 return WTF::nullopt; 211 const auto& responseMap = decodedResponse->getMap(); 204 auto decodedMap = decodeResponseMap(inBuffer); 205 if (!decodedMap) 206 return WTF::nullopt; 207 const auto& responseMap = decodedMap->getMap(); 212 208 213 209 auto it = responseMap.find(CBOR(1)); -
trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.h
r253398 r256201 43 43 namespace fido { 44 44 45 Optional<cbor::CBORValue> decodeResponseMap(const Vector<uint8_t>&); 46 45 47 // Parses response code from response received from the authenticator. If 46 48 // unknown response code value is received, then CTAP2_ERR_OTHER is returned. -
trunk/Source/WebCore/Modules/webauthn/fido/Pin.cpp
r254439 r256201 103 103 addAdditional(&map); 104 104 105 // FIXME(205375)106 105 auto serializedParam = CBORWriter::write(CBORValue(WTFMove(map))); 107 106 ASSERT(serializedParam); … … 116 115 Optional<RetriesResponse> RetriesResponse::parse(const Vector<uint8_t>& inBuffer) 117 116 { 118 // FIXME(205375) 119 if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess) 120 return WTF::nullopt; 121 122 Vector<uint8_t> buffer; 123 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 124 Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer); 125 if (!decodedResponse || !decodedResponse->isMap()) 126 return WTF::nullopt; 127 const auto& responseMap = decodedResponse->getMap(); 117 auto decodedMap = decodeResponseMap(inBuffer); 118 if (!decodedMap) 119 return WTF::nullopt; 120 const auto& responseMap = decodedMap->getMap(); 128 121 129 122 auto it = responseMap.find(CBORValue(static_cast<int64_t>(ResponseKey::kRetries))); … … 143 136 Optional<KeyAgreementResponse> KeyAgreementResponse::parse(const Vector<uint8_t>& inBuffer) 144 137 { 145 // FIXME(205375) 146 if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess) 147 return WTF::nullopt; 148 149 Vector<uint8_t> buffer; 150 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 151 auto decodedResponse = cbor::CBORReader::read(buffer); 152 if (!decodedResponse || !decodedResponse->isMap()) 153 return WTF::nullopt; 154 const auto& responseMap = decodedResponse->getMap(); 138 auto decodedMap = decodeResponseMap(inBuffer); 139 if (!decodedMap) 140 return WTF::nullopt; 141 const auto& responseMap = decodedMap->getMap(); 155 142 156 143 // The ephemeral key is encoded as a COSE structure. … … 217 204 Optional<TokenResponse> TokenResponse::parse(const WebCore::CryptoKeyAES& sharedKey, const Vector<uint8_t>& inBuffer) 218 205 { 219 // FIXME(205375) 220 if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess) 221 return WTF::nullopt; 222 223 Vector<uint8_t> buffer; 224 buffer.append(inBuffer.data() + 1, inBuffer.size() - 1); 225 auto decodedResponse = cbor::CBORReader::read(buffer); 226 if (!decodedResponse || !decodedResponse->isMap()) 227 return WTF::nullopt; 228 const auto& responseMap = decodedResponse->getMap(); 206 auto decodedMap = decodeResponseMap(inBuffer); 207 if (!decodedMap) 208 return WTF::nullopt; 209 const auto& responseMap = decodedMap->getMap(); 229 210 230 211 auto it = responseMap.find(CBORValue(static_cast<int64_t>(ResponseKey::kPinToken)));
Note: See TracChangeset
for help on using the changeset viewer.