| 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | #include "config.h" |
| 31 | #include "FidoConstants.h" |
| 32 | |
| 33 | #if ENABLE(WEB_AUTHN) |
| 34 | |
| 35 | namespace fido { |
| 36 | using namespace WebCore; |
| 37 | |
| 38 | bool isCtapDeviceResponseCode(CtapDeviceResponseCode code) |
| 39 | { |
| 40 | switch (code) { |
| 41 | case CtapDeviceResponseCode::kSuccess: |
| 42 | case CtapDeviceResponseCode::kCtap1ErrInvalidCommand: |
| 43 | case CtapDeviceResponseCode::kCtap1ErrInvalidParameter: |
| 44 | case CtapDeviceResponseCode::kCtap1ErrInvalidLength: |
| 45 | case CtapDeviceResponseCode::kCtap1ErrInvalidSeq: |
| 46 | case CtapDeviceResponseCode::kCtap1ErrTimeout: |
| 47 | case CtapDeviceResponseCode::kCtap1ErrChannelBusy: |
| 48 | case CtapDeviceResponseCode::kCtap1ErrLockRequired: |
| 49 | case CtapDeviceResponseCode::kCtap1ErrInvalidChannel: |
| 50 | case CtapDeviceResponseCode::kCtap2ErrCBORParsing: |
| 51 | case CtapDeviceResponseCode::kCtap2ErrUnexpectedType: |
| 52 | case CtapDeviceResponseCode::kCtap2ErrInvalidCBOR: |
| 53 | case CtapDeviceResponseCode::kCtap2ErrInvalidCBORType: |
| 54 | case CtapDeviceResponseCode::kCtap2ErrMissingParameter: |
| 55 | case CtapDeviceResponseCode::kCtap2ErrLimitExceeded: |
| 56 | case CtapDeviceResponseCode::kCtap2ErrUnsupportedExtension: |
| 57 | case CtapDeviceResponseCode::kCtap2ErrTooManyElements: |
| 58 | case CtapDeviceResponseCode::kCtap2ErrExtensionNotSupported: |
| 59 | case CtapDeviceResponseCode::kCtap2ErrCredentialExcluded: |
| 60 | case CtapDeviceResponseCode::kCtap2ErrProcesssing: |
| 61 | case CtapDeviceResponseCode::kCtap2ErrInvalidCredential: |
| 62 | case CtapDeviceResponseCode::kCtap2ErrUserActionPending: |
| 63 | case CtapDeviceResponseCode::kCtap2ErrOperationPending: |
| 64 | case CtapDeviceResponseCode::kCtap2ErrNoOperations: |
| 65 | case CtapDeviceResponseCode::kCtap2ErrUnsupportedAlgorithms: |
| 66 | case CtapDeviceResponseCode::kCtap2ErrOperationDenied: |
| 67 | case CtapDeviceResponseCode::kCtap2ErrKeyStoreFull: |
| 68 | case CtapDeviceResponseCode::kCtap2ErrNotBusy: |
| 69 | case CtapDeviceResponseCode::kCtap2ErrNoOperationPending: |
| 70 | case CtapDeviceResponseCode::kCtap2ErrUnsupportedOption: |
| 71 | case CtapDeviceResponseCode::kCtap2ErrInvalidOption: |
| 72 | case CtapDeviceResponseCode::kCtap2ErrKeepAliveCancel: |
| 73 | case CtapDeviceResponseCode::kCtap2ErrNoCredentials: |
| 74 | case CtapDeviceResponseCode::kCtap2ErrUserActionTimeout: |
| 75 | case CtapDeviceResponseCode::kCtap2ErrNotAllowed: |
| 76 | case CtapDeviceResponseCode::kCtap2ErrPinInvalid: |
| 77 | case CtapDeviceResponseCode::kCtap2ErrPinBlocked: |
| 78 | case CtapDeviceResponseCode::kCtap2ErrPinAuthInvalid: |
| 79 | case CtapDeviceResponseCode::kCtap2ErrPinAuthBlocked: |
| 80 | case CtapDeviceResponseCode::kCtap2ErrPinNotSet: |
| 81 | case CtapDeviceResponseCode::kCtap2ErrPinRequired: |
| 82 | case CtapDeviceResponseCode::kCtap2ErrPinPolicyViolation: |
| 83 | case CtapDeviceResponseCode::kCtap2ErrPinTokenExpired: |
| 84 | case CtapDeviceResponseCode::kCtap2ErrRequestTooLarge: |
| 85 | case CtapDeviceResponseCode::kCtap2ErrOther: |
| 86 | case CtapDeviceResponseCode::kCtap2ErrSpecLast: |
| 87 | case CtapDeviceResponseCode::kCtap2ErrExtensionFirst: |
| 88 | case CtapDeviceResponseCode::kCtap2ErrExtensionLast: |
| 89 | case CtapDeviceResponseCode::kCtap2ErrVendorFirst: |
| 90 | case CtapDeviceResponseCode::kCtap2ErrVendorLast: |
| 91 | return true; |
| 92 | default: |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | bool isFidoHidDeviceCommand(FidoHidDeviceCommand cmd) |
| 98 | { |
| 99 | switch (cmd) { |
| 100 | case FidoHidDeviceCommand::kMsg: |
| 101 | case FidoHidDeviceCommand::kCbor: |
| 102 | case FidoHidDeviceCommand::kInit: |
| 103 | case FidoHidDeviceCommand::kPing: |
| 104 | case FidoHidDeviceCommand::kCancel: |
| 105 | case FidoHidDeviceCommand::kError: |
| 106 | case FidoHidDeviceCommand::kKeepAlive: |
| 107 | case FidoHidDeviceCommand::kWink: |
| 108 | case FidoHidDeviceCommand::kLock: |
| 109 | return true; |
| 110 | default: |
| 111 | return false; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | const char* publicKeyCredentialTypeToString(PublicKeyCredentialType type) |
| 116 | { |
| 117 | switch (type) { |
| 118 | case PublicKeyCredentialType::PublicKey: |
| 119 | return kPublicKey; |
| 120 | } |
| 121 | ASSERT_NOT_REACHED(); |
| 122 | return kPublicKey; |
| 123 | } |
| 124 | |
| 125 | } // namespace fido |
| 126 | |
| 127 | #endif // ENABLE(WEB_AUTHN) |
| 128 | |