예제 #1
0
StatusWith<std::tuple<bool, std::string>> SaslSCRAMServerMechanism<Policy>::stepImpl(
    OperationContext* opCtx, StringData inputData) {
    _step++;

    if (_step > 3 || _step <= 0) {
        return Status(ErrorCodes::AuthenticationFailed,
                      str::stream() << "Invalid SCRAM authentication step: " << _step);
    }

    if (_step == 1) {
        return _firstStep(opCtx, inputData);
    }
    if (_step == 2) {
        return _secondStep(opCtx, inputData);
    }

    return std::make_tuple(true, std::string{});
}
    StatusWith<bool> SaslSCRAMSHA1ClientConversation::step(const StringData& inputData,
                                                           std::string* outputData) {
        std::vector<std::string> input = StringSplitter::split(inputData.toString(), ",");
        _step++;

        switch (_step) {
            case 1:
                return _firstStep(outputData);
            case 2:
                // Append server-first-message to _authMessage
                _authMessage += inputData.toString() + ",";
                return _secondStep(input, outputData);
            case 3:
                return _thirdStep(input, outputData);
            default:
                return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
                                        mongoutils::str::stream() <<
                                        "Invalid SCRAM-SHA-1 authentication step: " << _step);
        }
    }
    StatusWith<bool> SaslSCRAMSHA1ServerConversation::step(const StringData& inputData,
                                                           std::string* outputData) {

        std::vector<std::string> input = StringSplitter::split(inputData.toString(), ",");
        _step++;

        if (_step > 3 || _step <= 0) {
            return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
                mongoutils::str::stream() << "Invalid SCRAM-SHA-1 authentication step: " << _step);
        }
        if (_step == 1) {
            return _firstStep(input, outputData);
        }
        if (_step == 2) {
            return _secondStep(input, outputData);
        }

        *outputData = "";

        return StatusWith<bool>(true);
    }