├── VERSION ├── docs └── .gitignore ├── tests ├── src │ ├── resources │ │ ├── testData.txt │ │ └── consts.json.enc │ ├── helpers.cxx │ ├── test_runner.cxx │ ├── TestData.cxx │ ├── managerTests │ │ ├── AccessTokenProviderStub_STC26.cxx │ │ └── CardClientStub_STC34.cxx │ └── TestConst.cxx ├── include │ ├── TestData.h │ ├── stubs │ │ ├── VerifierTrueStub.h │ │ ├── AccessTokenProviderStub_STC26.h │ │ └── CardClientStub_STC34.h │ ├── TestConst.h │ └── helpers.h └── CMakeLists.txt ├── logo.png ├── .gitignore ├── .travis.yml ├── LICENSE ├── cmake ├── config │ └── config.cmake.in └── utils │ └── virgil_depends.cmake ├── ci ├── run.sh ├── decrypt-consts.sh ├── configure.sh ├── install-cmake.sh └── install-doxygen.sh ├── ext ├── restless │ ├── patch │ │ └── cmake │ │ │ └── config.cmake.in │ └── restless.cmake ├── nlohman_json │ ├── cmake │ │ └── config.cmake.in │ └── nlohman_json.cmake └── virgil_crypto │ └── virgil_crypto.cmake ├── src └── virgil │ └── sdk │ ├── crypto │ └── keys │ │ ├── PublicKey.cxx │ │ ├── PrivateKey.cxx │ │ └── KeyPair.cxx │ ├── client │ ├── networking │ │ ├── errors │ │ │ ├── VirgilError.cxx │ │ │ └── Error.cxx │ │ ├── CardEndpointUri.cxx │ │ ├── ClientRequest.cxx │ │ └── Response.cxx │ └── models │ │ ├── GetCardResponse.cxx │ │ ├── RawSignature.cxx │ │ └── RawCardContent.cxx │ ├── cards │ ├── verification │ │ ├── VerifierCredentials.cxx │ │ └── Whitelist.cxx │ └── CardSignature.cxx │ ├── jwt │ ├── TokenContext.cxx │ ├── providers │ │ ├── ConstAccessTokenProvier.cxx │ │ ├── CallbackJwtProvider.cxx │ │ ├── GeneratorJwtProvider.cxx │ │ └── CachingJwtProvider.cxx │ ├── JwtVerifier.cxx │ ├── JwtHeaderContent.cxx │ ├── JwtBodyContent.cxx │ └── JwtGenerator.cxx │ ├── Version.cxx.in │ ├── VirgilSdkError.cxx │ ├── util │ ├── JsonKey.cxx │ ├── Base64Url.cxx │ └── JsonUtils.cxx │ └── serialization │ └── VirgilErrorSerializer.cxx ├── ChangeLog ├── .clang-format ├── include └── virgil │ └── sdk │ ├── Common.h │ ├── util │ ├── Memory.h │ ├── CaseInsensitiveCompare.h │ ├── Base64Url.h │ ├── JsonUtils.h │ └── JsonKey.h │ ├── crypto │ └── keys │ │ ├── PublicKey.h │ │ ├── PrivateKey.h │ │ └── KeyPair.h │ ├── cards │ └── verification │ │ ├── CardVerifierInterface.h │ │ ├── Whitelist.h │ │ └── VerifierCredentials.h │ ├── Version.h │ ├── client │ ├── networking │ │ ├── Connection.h │ │ ├── ClientRequest.h │ │ ├── CardEndpointUri.h │ │ └── errors │ │ │ └── VirgilError.h │ └── models │ │ └── GetCardResponse.h │ ├── jwt │ └── interfaces │ │ ├── AccessTokenInterface.h │ │ └── AccessTokenProviderInterface.h │ └── serialization │ ├── JsonSerializer.h │ └── CanonicalSerializer.h └── utils └── format_code.sh /VERSION: -------------------------------------------------------------------------------- 1 | 5.0.0 2 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | -------------------------------------------------------------------------------- /tests/src/resources/testData.txt: -------------------------------------------------------------------------------- 1 | Hello, Bob! 2 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-sdk-cpp/HEAD/logo.png -------------------------------------------------------------------------------- /tests/src/resources/consts.json.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-sdk-cpp/HEAD/tests/src/resources/consts.json.enc -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ##### 2 | *build*/ 3 | *install*/ 4 | origin_lib/ 5 | examples_bin/ 6 | .depends_cache/ 7 | 8 | ##### 9 | # OS X temporary files that should never be committed 10 | 11 | .DS_Store 12 | *.swp 13 | *.lock 14 | profile 15 | 16 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 17 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 18 | 19 | # User-specific stuff: 20 | .idea/* 21 | 22 | ## File-based project format: 23 | *.iws 24 | 25 | ## Plugin-specific files: 26 | 27 | # IntelliJ 28 | /out/ 29 | 30 | # mpeltonen/sbt-idea plugin 31 | .idea_modules/ 32 | 33 | # JIRA plugin 34 | atlassian-ide-plugin.xml 35 | 36 | # Test Consts 37 | consts.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: generic 3 | 4 | cache: 5 | apt: true 6 | 7 | matrix: 8 | include: 9 | - compiler: gcc 10 | os: linux 11 | env: CXX=g++-5 CC=gcc-5 BUILD_DIR_NAME=build PUBLISH_DOCS="NO" 12 | addons: 13 | apt: 14 | packages: 15 | - g++-5 16 | sources: 17 | - ubuntu-toolchain-r-test 18 | 19 | - compiler: clang 20 | os: linux 21 | env: CXX=clang++-3.7 CC=clang-3.7 BUILD_DIR_NAME=build PUBLISH_DOCS="YES" 22 | addons: 23 | apt: 24 | packages: 25 | - clang-3.7 26 | sources: 27 | - ubuntu-toolchain-r-test 28 | - llvm-toolchain-precise-3.7 29 | 30 | exclude: 31 | - compiler: gcc 32 | 33 | cache: 34 | directories: 35 | - $HOME/cmake 36 | - $HOME/doxygen 37 | 38 | addons: 39 | apt: 40 | packages: 41 | - libcurl4-openssl-dev 42 | - python-yaml 43 | - graphviz 44 | 45 | before_install: 46 | - bash ./ci/install-cmake.sh 47 | - bash ./ci/install-doxygen.sh 48 | - bash ./ci/decrypt-consts.sh 49 | before_script: 50 | - bash ./ci/configure.sh 51 | script: 52 | - bash ./ci/run.sh 53 | 54 | deploy: 55 | provider: pages 56 | github-token: $GITHUB_TOKEN 57 | skip-cleanup: true 58 | local_dir: "docs/html" 59 | keep-history: true 60 | on: 61 | tags: true 62 | condition: $PUBLISH_DOCS = "YES" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2015-2020, Virgil Security, Inc. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | Lead Maintainer: Virgil Security, Inc. 32 | -------------------------------------------------------------------------------- /tests/src/helpers.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | -------------------------------------------------------------------------------- /cmake/config/config.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018 Virgil Security Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # (1) Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # (2) Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # 18 | # (3) Neither the name of the copyright holder nor the names of its 19 | # contributors may be used to endorse or promote products derived from 20 | # this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | # POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # Lead Maintainer: Virgil Security Inc. 35 | # 36 | 37 | @PACKAGE_INIT@ 38 | 39 | include ("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 40 | check_required_components ("@PROJECT_NAME@") 41 | -------------------------------------------------------------------------------- /ci/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015 Virgil Security Inc. 4 | # 5 | # Lead Maintainer: Virgil Security Inc. 6 | # 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # (1) Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 16 | # (2) Redistributions in binary form must reproduce the above copyright 17 | # notice, this list of conditions and the following disclaimer in 18 | # the documentation and/or other materials provided with the 19 | # distribution. 20 | # 21 | # (3) Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 26 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | # POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | 38 | set -ev 39 | 40 | cd "${TRAVIS_BUILD_DIR}/${BUILD_DIR_NAME}" 41 | 42 | # Build 43 | make -j4 VERBOSE=1 44 | ctest --verbose 45 | make doc 46 | make install 47 | -------------------------------------------------------------------------------- /ext/restless/patch/cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018 Virgil Security Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # (1) Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # (2) Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # 18 | # (3) Neither the name of the copyright holder nor the names of its 19 | # contributors may be used to endorse or promote products derived from 20 | # this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | # POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # Lead Maintainer: Virgil Security Inc. 35 | # 36 | 37 | @PACKAGE_INIT@ 38 | 39 | include ("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 40 | check_required_components ("@PROJECT_NAME@") 41 | -------------------------------------------------------------------------------- /tests/src/test_runner.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | /** 38 | * @file test_runner.cxx 39 | * @brief Tests entrypoint 40 | */ 41 | 42 | #define CATCH_CONFIG_MAIN 43 | #include "catch.hpp" 44 | -------------------------------------------------------------------------------- /ext/nlohman_json/cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018 Virgil Security Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # (1) Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # (2) Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # 18 | # (3) Neither the name of the copyright holder nor the names of its 19 | # contributors may be used to endorse or promote products derived from 20 | # this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | # POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # Lead Maintainer: Virgil Security Inc. 35 | # 36 | 37 | @PACKAGE_INIT@ 38 | 39 | string (TOUPPER "@PROJECT_NAME@" PROJECT_NAME_UPPERCASE) 40 | 41 | set_and_check (${PROJECT_NAME_UPPERCASE}_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") 42 | 43 | set (PROJECT_NAME_UPPERCASE) 44 | -------------------------------------------------------------------------------- /ci/decrypt-consts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2018 Virgil Security Inc. 4 | # 5 | # Lead Maintainer: Virgil Security Inc. 6 | # 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # (1) Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 16 | # (2) Redistributions in binary form must reproduce the above copyright 17 | # notice, this list of conditions and the following disclaimer in 18 | # the documentation and/or other materials provided with the 19 | # distribution. 20 | # 21 | # (3) Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 26 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | # POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | 38 | set -ev 39 | 40 | openssl aes-256-cbc -K $encrypted_067cfd0bede1_key -iv $encrypted_067cfd0bede1_iv \ 41 | -in "${TRAVIS_BUILD_DIR}/tests/src/resources/consts.json.enc" -out "${TRAVIS_BUILD_DIR}/tests/src/resources/consts.json" -d 42 | -------------------------------------------------------------------------------- /src/virgil/sdk/crypto/keys/PublicKey.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::VirgilByteArray; 40 | using virgil::sdk::crypto::keys::PublicKey; 41 | 42 | PublicKey::PublicKey(VirgilByteArray key, VirgilByteArray identifier) 43 | : key_(std::move(key)), identifier_(std::move(identifier)) {} -------------------------------------------------------------------------------- /src/virgil/sdk/client/networking/errors/VirgilError.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::client::networking::errors::VirgilError; 40 | 41 | VirgilError::VirgilError(int virgilErrorCode, std::string errorMsg) 42 | : virgilErrorCode_(virgilErrorCode), errorMsg_(std::move(errorMsg)) {} -------------------------------------------------------------------------------- /src/virgil/sdk/crypto/keys/PrivateKey.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::VirgilByteArray; 40 | using virgil::sdk::crypto::keys::PrivateKey; 41 | 42 | PrivateKey::PrivateKey(VirgilByteArray key, VirgilByteArray identifier) 43 | : key_(std::move(key)), identifier_(std::move(identifier)) {} 44 | -------------------------------------------------------------------------------- /src/virgil/sdk/crypto/keys/KeyPair.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::crypto::keys::PrivateKey; 40 | using virgil::sdk::crypto::keys::PublicKey; 41 | using virgil::sdk::crypto::keys::KeyPair; 42 | 43 | KeyPair::KeyPair(PrivateKey privateKey, PublicKey publicKey) 44 | : privateKey_(std::move(privateKey)), publicKey_(std::move(publicKey)) {} -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Virgil Security C++ SDK ChangeLog (Sorted per date) 2 | 3 | # Version 3.2.3 released 2016-07-01 4 | 5 | ## Changes 6 | 7 | * Use virgil-crypto lib 1.8.1 8 | 9 | 10 | 11 | # Version 3.2.2 released 2016-06-28 12 | 13 | ## Changes 14 | 15 | * Use virgil-crypto lib 1.8.0 16 | 17 | 18 | # Version 3.2.1 released 2016-06-21 19 | 20 | ## Changes 21 | 22 | * Use virgil-crypto lib 1.7.0 23 | 24 | 25 | 26 | # Version 3.2.0 released 2016-05-12 27 | 28 | ## Changes 29 | 30 | * Split VirgilCards to Global scope and Private scope 31 | 32 | ## Features 33 | 34 | * [Build] Implement in-house package manager based on CMake 35 | 36 | # Version 3.1.0 released 2016-04-29 37 | 38 | ## Features 39 | 40 | * Add custom identities functionality 41 | 42 | ## Changes 43 | 44 | * Use virgil-crypto lib 1.5.0 45 | 46 | 47 | 48 | # Version 3.0.6 released 2016-04-18 49 | 50 | ## Changes 51 | 52 | * Use virgil-crypto lib 1.4.0 53 | 54 | 55 | 56 | # Version 3.0.5 released 2016-04-06 57 | 58 | ## Changes 59 | 60 | * Use virgil-crypto lib 1.4.0-rc1 61 | 62 | ## Bugfix 63 | 64 | * Add missed code error handle ( 30306 ) for Virgil Keys Service 65 | 66 | 67 | # Version 3.0.4 released 2016-03-30 68 | 69 | ## Changes 70 | 71 | * Use virgil-crypto lib 1.3.4 72 | * Fix bug in http::Request - when parameters_ empty added '?' 73 | * Add IPMessaging in examples 74 | * Update docs with new template 75 | 76 | 77 | # Version 3.0.2 released 2016-03-25 78 | 79 | ## Changes 80 | 81 | * Fix bug: wrong default base address of the Virgil Private Keys Service 82 | 83 | 84 | 85 | # Version 3.0.1 released 2016-03-21 86 | 87 | ## Changes 88 | 89 | * Use virgil-crypto lib 1.3.2. 90 | 91 | 92 | # Version 3.0.0 released 2016-03-15 93 | 94 | ## Changes 95 | 96 | * Use virgil-crypto lib 1.3.1. 97 | 98 | 99 | # Version 3.0.0-RC1 released 2016-02-29 100 | 101 | ## Changes 102 | 103 | * Merge all SDKs to one. 104 | * Add Virgil Identity Service API version 1. 105 | * Add Virgil Keys Service API version 3. 106 | * Add Virgil Private Keys Service API version 3. 107 | 108 | -------------------------------------------------------------------------------- /ci/configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015 Virgil Security Inc. 4 | # 5 | # Lead Maintainer: Virgil Security Inc. 6 | # 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # (1) Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 16 | # (2) Redistributions in binary form must reproduce the above copyright 17 | # notice, this list of conditions and the following disclaimer in 18 | # the documentation and/or other materials provided with the 19 | # distribution. 20 | # 21 | # (3) Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 26 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | # POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | 38 | set -ev 39 | 40 | # Configure CMake arguments 41 | CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=install -DENABLE_TESTING=ON" 42 | 43 | # Run CMake 44 | cd "${TRAVIS_BUILD_DIR}" 45 | if [ -d "${BUILD_DIR_NAME}" ]; then 46 | rm -fr "${BUILD_DIR_NAME}" 47 | fi 48 | mkdir "${BUILD_DIR_NAME}" 49 | cd "${BUILD_DIR_NAME}" 50 | 51 | export PATH=$HOME/cmake/bin:$PATH 52 | cmake --version 53 | 54 | export PATH=$HOME/doxygen/bin:$PATH 55 | doxygen --version 56 | 57 | cmake ${CMAKE_ARGS} .. 58 | -------------------------------------------------------------------------------- /src/virgil/sdk/client/networking/CardEndpointUri.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::client::networking::CardEndpointUri; 40 | 41 | std::string CardEndpointUri::publish() { 42 | return "/card/v5"; 43 | } 44 | 45 | std::string CardEndpointUri::get(const std::string& cardId) { 46 | return "/card/v5/" + cardId; 47 | } 48 | 49 | std::string CardEndpointUri::search() { 50 | return "/card/v5/actions/search"; 51 | } 52 | -------------------------------------------------------------------------------- /ci/install-cmake.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015 Virgil Security Inc. 4 | # 5 | # Lead Maintainer: Virgil Security Inc. 6 | # 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # (1) Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 16 | # (2) Redistributions in binary form must reproduce the above copyright 17 | # notice, this list of conditions and the following disclaimer in 18 | # the documentation and/or other materials provided with the 19 | # distribution. 20 | # 21 | # (3) Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 26 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | # POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | 38 | set -ev 39 | CMAKE_VERSION_MAJOR=3.10 40 | CMAKE_VERSION="${CMAKE_VERSION_MAJOR}.0" 41 | if [ ! -d "$HOME/cmake/bin" ] || [[ "`$HOME/cmake/bin/cmake --version`" != *"${CMAKE_VERSION}"* ]]; then 42 | curl -L -O http://www.cmake.org/files/v${CMAKE_VERSION_MAJOR}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz 43 | tar -xzf cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz 44 | cp -fa cmake-${CMAKE_VERSION}-Linux-x86_64/. $HOME/cmake/ 45 | else 46 | echo "Using CMake cached directory." 47 | fi 48 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -4 5 | AlignAfterOpenBracket: true 6 | AlignConsecutiveAssignments: false 7 | AlignEscapedNewlinesLeft: false 8 | AlignOperands: true 9 | AlignTrailingComments: true 10 | AllowAllParametersOfDeclarationOnNextLine: true 11 | AllowShortBlocksOnASingleLine: false 12 | AllowShortCaseLabelsOnASingleLine: false 13 | AllowShortFunctionsOnASingleLine: false 14 | AllowShortIfStatementsOnASingleLine: false 15 | AllowShortLoopsOnASingleLine: false 16 | AlwaysBreakAfterDefinitionReturnType: None 17 | AlwaysBreakBeforeMultilineStrings: false 18 | AlwaysBreakTemplateDeclarations: false 19 | BinPackArguments: true 20 | BinPackParameters: true 21 | BreakBeforeBinaryOperators: None 22 | BreakBeforeBraces: Attach 23 | BreakBeforeTernaryOperators: true 24 | BreakConstructorInitializersBeforeComma: false 25 | ColumnLimit: 120 26 | CommentPragmas: '^ IWYU pragma:' 27 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 28 | ConstructorInitializerIndentWidth: 8 29 | ContinuationIndentWidth: 4 30 | Cpp11BracedListStyle: true 31 | DerivePointerAlignment: false 32 | DisableFormat: false 33 | ExperimentalAutoDetectBinPacking: false 34 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 35 | IndentCaseLabels: true 36 | IndentWidth: 4 37 | IndentWrappedFunctionNames: false 38 | KeepEmptyLinesAtTheStartOfBlocks: true 39 | MacroBlockBegin: '' 40 | MacroBlockEnd: '' 41 | MaxEmptyLinesToKeep: 1 42 | NamespaceIndentation: Inner 43 | ObjCBlockIndentWidth: 2 44 | ObjCSpaceAfterProperty: false 45 | ObjCSpaceBeforeProtocolList: true 46 | PenaltyBreakBeforeFirstCallParameter: 19 47 | PenaltyBreakComment: 300 48 | PenaltyBreakFirstLessLess: 120 49 | PenaltyBreakString: 1000 50 | PenaltyExcessCharacter: 1000000 51 | PenaltyReturnTypeOnItsOwnLine: 60 52 | PointerAlignment: Left 53 | SpaceAfterCStyleCast: false 54 | SpaceBeforeAssignmentOperators: true 55 | SpaceBeforeParens: ControlStatements 56 | SpaceInEmptyParentheses: false 57 | SpacesBeforeTrailingComments: 1 58 | SpacesInAngles: false 59 | SpacesInContainerLiterals: true 60 | SpacesInCStyleCastParentheses: false 61 | SpacesInParentheses: false 62 | SpacesInSquareBrackets: false 63 | Standard: Cpp11 64 | TabWidth: 4 65 | UseTab: Never 66 | -------------------------------------------------------------------------------- /src/virgil/sdk/client/models/GetCardResponse.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::client::models::GetCardResponse; 40 | using virgil::sdk::client::models::RawSignedModel; 41 | 42 | GetCardResponse::GetCardResponse(RawSignedModel rawCard, bool isOutdated) 43 | : rawCard_(std::move(rawCard)), isOutdated_(isOutdated) {} 44 | 45 | const RawSignedModel& GetCardResponse::rawCard() const { return rawCard_; } 46 | 47 | bool GetCardResponse::isOutdated() const { return isOutdated_; } -------------------------------------------------------------------------------- /tests/src/TestData.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | using virgil::sdk::test::TestData; 41 | using json = nlohmann::json; 42 | 43 | TestData::TestData(const std::string &fileName) { 44 | std::ifstream input(fileName); 45 | 46 | std::string str((std::istreambuf_iterator(input)), 47 | std::istreambuf_iterator()); 48 | 49 | if (!str.empty()) 50 | dict_ = json::parse(str); 51 | 52 | input.close(); 53 | } 54 | 55 | const json& TestData::dict() const { return dict_; } 56 | -------------------------------------------------------------------------------- /src/virgil/sdk/client/networking/ClientRequest.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::client::networking::ClientRequest; 40 | 41 | const std::string ClientRequest::accessTokenHeader = "Authorization"; 42 | const std::string ClientRequest::accessTokenPrefix = "Virgil"; 43 | 44 | ClientRequest::ClientRequest(std::string accessToken) { 45 | header(std::map { std::make_pair(accessTokenHeader, accessTokenPrefix + " " + accessToken) }); 46 | contentType("application/json"); 47 | } 48 | -------------------------------------------------------------------------------- /src/virgil/sdk/cards/verification/VerifierCredentials.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::cards::verification::VerifierCredentials; 40 | using virgil::sdk::VirgilByteArray; 41 | 42 | VerifierCredentials::VerifierCredentials(std::string signer, VirgilByteArray publicKey) 43 | : signer_(std::move(signer)), publicKey_(std::move(publicKey)) {} 44 | 45 | const std::string& VerifierCredentials::signer() const { return signer_; } 46 | 47 | const VirgilByteArray& VerifierCredentials::publicKey() const { return publicKey_; } -------------------------------------------------------------------------------- /ci/install-doxygen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015 Virgil Security Inc. 4 | # 5 | # Lead Maintainer: Virgil Security Inc. 6 | # 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # (1) Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 16 | # (2) Redistributions in binary form must reproduce the above copyright 17 | # notice, this list of conditions and the following disclaimer in 18 | # the documentation and/or other materials provided with the 19 | # distribution. 20 | # 21 | # (3) Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 26 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | # POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | 38 | set -ev 39 | 40 | if [ ! -d "$HOME/doxygen/bin" ]; then 41 | curl -L -O https://github.com/doxygen/doxygen/archive/ca2e7ae50604cfdf9c0661b5be4264d1df9176f3.tar.gz 42 | tar -xf ca2e7ae50604cfdf9c0661b5be4264d1df9176f3.tar.gz 43 | mkdir doxygen-ca2e7ae50604cfdf9c0661b5be4264d1df9176f3/build 44 | pushd doxygen-ca2e7ae50604cfdf9c0661b5be4264d1df9176f3/build 45 | cmake -G "Unix Makefiles" .. 46 | make 47 | popd 48 | cp -fa doxygen-ca2e7ae50604cfdf9c0661b5be4264d1df9176f3/build/. $HOME/doxygen/ 49 | else 50 | echo "Using Doxygen cached directory." 51 | fi 52 | -------------------------------------------------------------------------------- /tests/include/TestData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_TESTDATA_H 38 | #define VIRGIL_SDK_TESTDATA_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | namespace test { 46 | class TestData { 47 | public: 48 | TestData(const std::string &fileName = "data.json"); 49 | 50 | const nlohmann::json& dict() const; 51 | 52 | private: 53 | nlohmann::json dict_; 54 | }; 55 | } 56 | } 57 | } 58 | 59 | #endif //VIRGIL_SDK_TESTDATA_H -------------------------------------------------------------------------------- /tests/include/stubs/VerifierTrueStub.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_VERIFIERTRUESTUB_H 38 | #define VIRGIL_SDK_VERIFIERTRUESTUB_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace test { 45 | namespace stubs { 46 | class VerifierStubFalse : public cards::verification::CardVerifierInterface { 47 | bool verifyCard(const cards::Card &card) const { return false; } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | 54 | #endif //VIRGIL_SDK_VERIFIERTRUESTUB_H -------------------------------------------------------------------------------- /src/virgil/sdk/client/networking/errors/Error.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::client::networking::errors::Error; 40 | using virgil::sdk::client::networking::errors::VirgilError; 41 | 42 | Error::Error(int httpErrorCode, const VirgilError &virgilError) 43 | : httpErrorCode_(httpErrorCode), 44 | virgilErrorCode_(virgilError.virgilErrorCode()) { 45 | errorMsg_ = "HTTP Code: " + std::to_string(httpErrorCode) 46 | + "; Virgil Code: " + std::to_string(virgilErrorCode_) 47 | + "; Description: " + virgilError.errorMsg(); 48 | } -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/TokenContext.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::jwt::TokenContext; 40 | 41 | TokenContext::TokenContext(std::string operation, std::string service, std::string identity, bool forceReload) 42 | : operation_(std::move(operation)), service_(std::move(service)), 43 | identity_(std::move(identity)), forceReload_(forceReload) {} 44 | 45 | const std::string& TokenContext::operation() const { return operation_; } 46 | 47 | const std::string& TokenContext::identity() const { return identity_; } 48 | 49 | bool TokenContext::forceReload() const { return forceReload_; } -------------------------------------------------------------------------------- /cmake/utils/virgil_depends.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018 Virgil Security Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # (1) Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # (2) Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # 18 | # (3) Neither the name of the copyright holder nor the names of its 19 | # contributors may be used to endorse or promote products derived from 20 | # this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | # POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # Lead Maintainer: Virgil Security Inc. 35 | # 36 | 37 | # 38 | # See 'virgil_depends_local.cmake' for documentation 39 | # Note: 40 | # VIRGIL_DEPENDS_CMAKE_FILE cache varibale can be used to define alternative 'virgil_depends.cmake' 41 | # module implementation, i.e. from an upstream project. 42 | # 43 | 44 | if (EXISTS "${VIRGIL_DEPENDS_CMAKE_FILE}") 45 | include ("${VIRGIL_DEPENDS_CMAKE_FILE}") 46 | else () 47 | find_file (VIRGIL_DEPENDS_CMAKE_FILE "virgil_depends_local.cmake" HINTS ${CMAKE_MODULE_PATH}) 48 | if (VIRGIL_DEPENDS_CMAKE_FILE) 49 | include ("${VIRGIL_DEPENDS_CMAKE_FILE}") 50 | else () 51 | include (virgil_depends_local) 52 | endif () 53 | endif () -------------------------------------------------------------------------------- /src/virgil/sdk/client/models/RawSignature.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::client::models::RawSignature; 40 | using virgil::sdk::VirgilByteArray; 41 | 42 | RawSignature::RawSignature(std::string signer, VirgilByteArray signature, VirgilByteArray snapshot) 43 | : signer_(std::move(signer)), snapshot_(std::move(snapshot)), signature_(std::move(signature)) {} 44 | 45 | const std::string& RawSignature::signer() const { return signer_; } 46 | 47 | const VirgilByteArray& RawSignature::snapshot() const { return snapshot_; } 48 | 49 | const VirgilByteArray& RawSignature::signature() const { return signature_; } -------------------------------------------------------------------------------- /include/virgil/sdk/Common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_COMMON_H 38 | #define VIRGIL_SDK_COMMON_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace virgil { 46 | namespace sdk { 47 | using VirgilByteArray = virgil::crypto::VirgilByteArray; 48 | using VirgilBase64 = virgil::crypto::foundation::VirgilBase64; 49 | using VirgilByteArrayUtils = virgil::crypto::VirgilByteArrayUtils; 50 | using VirgilHashAlgorithm = virgil::crypto::foundation::VirgilHash::Algorithm; 51 | } 52 | } 53 | 54 | #endif //VIRGIL_SDK_COMMON_H -------------------------------------------------------------------------------- /include/virgil/sdk/util/Memory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_UTIL_MEMORY_H 38 | #define VIRGIL_SDK_UTIL_MEMORY_H 39 | 40 | #include 41 | 42 | // Define custom implementation of std::make_unique() function 43 | #if !defined(__cpp_lib_make_unique) 44 | #if !defined(_MSC_VER) || _MSC_VER < 1800 45 | 46 | namespace std { 47 | /*! 48 | * @brief Custom implementation of std::make_unique() function 49 | */ 50 | template 51 | std::unique_ptr make_unique(Args&& ... args) { 52 | return std::unique_ptr(new T(std::forward(args)...)); 53 | } 54 | } 55 | 56 | #endif // !defined(_MSC_VER) || _MSC_VER < 1800 57 | #endif // __cpp_lib_make_unique 58 | 59 | #endif //VIRGIL_CLI_MEMORY_H -------------------------------------------------------------------------------- /src/virgil/sdk/Version.cxx.in: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::Version; 40 | 41 | size_t Version::asNumber() { 42 | return (majorVersion() << 16) | (minorVersion() << 8) | patchVersion(); 43 | } 44 | 45 | std::string Version::asString() { 46 | return std::string("@virgil_sdk_VERSION@"); 47 | } 48 | 49 | size_t Version::majorVersion() { 50 | // clang-format off 51 | return @virgil_sdk_VERSION_MAJOR@; 52 | // clang-format on 53 | } 54 | 55 | size_t Version::minorVersion() { 56 | // clang-format off 57 | return @virgil_sdk_VERSION_MINOR@; 58 | // clang-format on 59 | } 60 | 61 | size_t Version::patchVersion() { 62 | // clang-format off 63 | return @virgil_sdk_VERSION_PATCH@; 64 | // clang-format on 65 | } -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/providers/ConstAccessTokenProvier.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::jwt::providers::ConstAccessTokenProvider; 40 | using virgil::sdk::jwt::interfaces::AccessTokenInterface; 41 | 42 | ConstAccessTokenProvider::ConstAccessTokenProvider(std::shared_ptr accessToken) 43 | : accessToken_(std::move(accessToken)) {} 44 | 45 | std::future> ConstAccessTokenProvider::getToken(const virgil::sdk::jwt::TokenContext &tokenContext) { 46 | std::promise> p; 47 | p.set_value(accessToken_); 48 | 49 | return p.get_future(); 50 | } 51 | 52 | const std::shared_ptr& ConstAccessTokenProvider::accessToken() const { return accessToken_; } -------------------------------------------------------------------------------- /include/virgil/sdk/util/CaseInsensitiveCompare.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_MAPINSENSITIVECOMPARE_H 38 | #define VIRGIL_SDK_MAPINSENSITIVECOMPARE_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | namespace util { 46 | /*! 47 | * @brief Struct for case-insensitive comparison 48 | */ 49 | struct CaseInsensitiveCompare { 50 | /*! 51 | * @brief operator for case-insensitive comparison 52 | */ 53 | bool operator()(const std::string &lhs, const std::string &rhs) const { 54 | return strcasecmp(lhs.c_str(), rhs.c_str()) < 0; 55 | } 56 | }; 57 | } 58 | } 59 | } 60 | 61 | #endif //VIRGIL_SDK_MAPINSENSITIVECOMPARE_H -------------------------------------------------------------------------------- /src/virgil/sdk/cards/CardSignature.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::cards::CardSignature; 40 | using virgil::sdk::VirgilByteArray; 41 | 42 | CardSignature::CardSignature(std::string signer, VirgilByteArray signature, VirgilByteArray snapshot, 43 | std::unordered_map extraFields) 44 | : signer_(std::move(signer)), signature_(std::move(signature)), 45 | snapshot_(std::move(snapshot)), extraFields_(std::move(extraFields)) {} 46 | 47 | const std::string& CardSignature::signer() const { return signer_; } 48 | 49 | const VirgilByteArray& CardSignature::signature() const { return signature_; } 50 | 51 | const VirgilByteArray& CardSignature::snapshot() const { return snapshot_; } 52 | 53 | const std::unordered_map& CardSignature::extraFields() const { return extraFields_; } -------------------------------------------------------------------------------- /tests/include/TestConst.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_TESTCONST_H 38 | #define VIRGIL_SDK_TESTCONST_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace test { 45 | class TestConst { 46 | public: 47 | TestConst(const std::string &fileName = "consts.json"); 48 | 49 | const std::string& ApiPublicKeyId() const; 50 | const std::string& ApiPrivateKey() const; 51 | const std::string& ApiPublicKey() const; 52 | const std::string& AppId() const; 53 | const std::string& ServiceURL() const; 54 | 55 | bool enableStg() const; 56 | 57 | private: 58 | std::string ApiPublicKeyId_; 59 | std::string ApiPrivateKey_; 60 | std::string ApiPublicKey_; 61 | std::string AppId_; 62 | std::string ServiceURL_; 63 | 64 | bool enableStg_; 65 | }; 66 | } 67 | } 68 | } 69 | 70 | #endif //VIRGIL_SDK_TESTCONST_H -------------------------------------------------------------------------------- /src/virgil/sdk/cards/verification/Whitelist.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | using virgil::sdk::cards::verification::VerifierCredentials; 42 | using virgil::sdk::cards::verification::Whitelist; 43 | 44 | Whitelist::Whitelist(std::vector verifierCredentials) 45 | : verifierCredentials_(std::move(verifierCredentials)) { 46 | std::vector dic; 47 | for (auto& credentials : verifierCredentials) { 48 | if (std::find(dic.begin(), dic.end(), credentials.signer()) != dic.end()) { 49 | throw make_error(VirgilSdkError::AddVerifierCredentialsFailed, "Verifier credentials with same signer already exists"); 50 | } else { 51 | dic.push_back(credentials.signer()); 52 | } 53 | } 54 | } 55 | 56 | const std::vector& Whitelist::verifierCredentials() const { return verifierCredentials_; } -------------------------------------------------------------------------------- /include/virgil/sdk/crypto/keys/PublicKey.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_PUBLICKEY_H 38 | #define VIRGIL_SDK_PUBLICKEY_H 39 | 40 | #include 41 | 42 | /// forward decl 43 | namespace virgil { 44 | namespace sdk { 45 | namespace crypto { 46 | class Crypto; 47 | } 48 | } 49 | } 50 | 51 | namespace virgil { 52 | namespace sdk { 53 | namespace crypto { 54 | namespace keys { 55 | /*! 56 | * @brief Container for Public Key which is used for crypto operations. 57 | */ 58 | class PublicKey { 59 | private: 60 | PublicKey(VirgilByteArray key, VirgilByteArray identifier); 61 | 62 | const VirgilByteArray &key() const { return key_; } 63 | const VirgilByteArray &identifier() const { return identifier_; } 64 | 65 | VirgilByteArray key_; 66 | VirgilByteArray identifier_; 67 | 68 | friend Crypto; 69 | }; 70 | } 71 | } 72 | } 73 | } 74 | 75 | #endif //VIRGIL_SDK_PUBLICKEY_H -------------------------------------------------------------------------------- /include/virgil/sdk/crypto/keys/PrivateKey.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_PRIVATEKEY_H 38 | #define VIRGIL_SDK_PRIVATEKEY_H 39 | 40 | #include 41 | 42 | /// forward decl 43 | namespace virgil { 44 | namespace sdk { 45 | namespace crypto { 46 | class Crypto; 47 | } 48 | } 49 | } 50 | 51 | namespace virgil { 52 | namespace sdk { 53 | namespace crypto { 54 | namespace keys { 55 | /*! 56 | * @brief Container for Private Key which is used for crypto operations. 57 | */ 58 | class PrivateKey { 59 | private: 60 | PrivateKey(VirgilByteArray key, VirgilByteArray identifier); 61 | 62 | const VirgilByteArray &key() const { return key_; } 63 | const VirgilByteArray &identifier() const { return identifier_; } 64 | 65 | VirgilByteArray key_; 66 | VirgilByteArray identifier_; 67 | 68 | friend Crypto; 69 | }; 70 | } 71 | } 72 | } 73 | } 74 | 75 | #endif //VIRGIL_SDK_PRIVATEKEY_H -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Virgil Security Inc. 3 | # 4 | # Lead Maintainer: Virgil Security Inc. 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions are 10 | # met: 11 | # 12 | # (1) Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 15 | # (2) Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in 17 | # the documentation and/or other materials provided with the 18 | # distribution. 19 | # 20 | # (3) Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 25 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | 37 | cmake_minimum_required (VERSION 3.2 FATAL_ERROR) 38 | 39 | # Define variables 40 | set (TEST_RUNNER test_runner) 41 | 42 | include_directories ("include") 43 | 44 | file(GLOB_RECURSE UUT_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cxx") 45 | 46 | # list of files for which we add a copy rule 47 | file(GLOB_RECURSE RES_LIST "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/*") 48 | 49 | # Configure test target 50 | add_executable(${TEST_RUNNER} ${UUT_SRC_LIST}) 51 | target_link_libraries (${TEST_RUNNER} virgil_sdk) 52 | 53 | foreach(ITEM IN LISTS RES_LIST) 54 | string (REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/" "" ITEM_REL_PATH ${ITEM}) 55 | 56 | add_custom_command( 57 | TARGET ${TEST_RUNNER} PRE_BUILD 58 | COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/${ITEM_REL_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/${ITEM_REL_PATH}" 59 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/${ITEM_REL_PATH}" 60 | ) 61 | endforeach() 62 | 63 | # Run tests 64 | add_test ( 65 | NAME ${TEST_RUNNER} 66 | COMMAND ./${TEST_RUNNER} 67 | ) 68 | -------------------------------------------------------------------------------- /utils/format_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015 Virgil Security Inc. 4 | # 5 | # Lead Maintainer: Virgil Security Inc. 6 | # 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # (1) Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 16 | # (2) Redistributions in binary form must reproduce the above copyright 17 | # notice, this list of conditions and the following disclaimer in 18 | # the documentation and/or other materials provided with the 19 | # distribution. 20 | # 21 | # (3) Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 26 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | # POSSIBILITY OF SUCH DAMAGE. 36 | 37 | # 38 | # Performs code formatting by using .clang-format configuration file located in the project root folder 39 | # 40 | 41 | function abspath() { 42 | ( 43 | if [ -d "$1" ]; then 44 | cd "$1" && pwd -P 45 | else 46 | echo "$(cd "$(dirname "$1")" && pwd -P)/$(basename "$1")" 47 | fi 48 | ) 49 | } 50 | 51 | SCRIPT_DIR=$(dirname "$(abspath "${BASH_SOURCE[0]}")") 52 | 53 | SDK_INC_FILES=$(find "$(abspath ${SCRIPT_DIR}/../include)" -name "*.h") 54 | SDK_SRC_FILES=$(find "$(abspath ${SCRIPT_DIR}/../src)" -name "*.cxx") 55 | 56 | TESTS_INC_FILES=$(find "$(abspath ${SCRIPT_DIR}/../tests)" -name "*.h") 57 | TESTS_SRC_FILES=$(find "$(abspath ${SCRIPT_DIR}/../tests)" -name "*.cxx") 58 | 59 | EXAMPLES_INC_FILES=$(find "$(abspath ${SCRIPT_DIR}/../examples)" -name "*.h") 60 | EXAMPLES_SRC_FILES=$(find "$(abspath ${SCRIPT_DIR}/../examples)" -name "*.cxx") 61 | 62 | for f in ${SDK_INC_FILES} ${SDK_SRC_FILES} \ 63 | ${TESTS_INC_FILES} ${TESTS_SRC_FILES} \ 64 | ${EXAMPLES_INC_FILES} ${EXAMPLES_SRC_FILES} 65 | do 66 | clang-format "$f" > "$f.formatted" && mv "$f.formatted" "$f" 67 | done 68 | -------------------------------------------------------------------------------- /include/virgil/sdk/cards/verification/CardVerifierInterface.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_CARDVERIFIERINTERFACE_H 38 | #define VIRGIL_SDK_CARDVERIFIERINTERFACE_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace cards { 45 | namespace verification { 46 | /*! 47 | * @brief Interface representing Card verification process 48 | */ 49 | class CardVerifierInterface { 50 | public: 51 | /*! 52 | * @brief Verifies Card instance 53 | * @param card Card to verify 54 | * @return true if Card verified, false otherwise 55 | */ 56 | virtual bool verifyCard(const Card &card) const = 0; 57 | 58 | /*! 59 | * @brief Virtual destructor 60 | */ 61 | virtual ~CardVerifierInterface() = default; 62 | }; 63 | } 64 | } 65 | } 66 | } 67 | 68 | #endif //VIRGIL_SDK_CARDVERIFIERINTERFACE_H -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/JwtVerifier.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::jwt::JwtVerifier; 40 | using virgil::sdk::jwt::Jwt; 41 | using virgil::sdk::crypto::Crypto; 42 | using virgil::sdk::crypto::keys::PublicKey; 43 | 44 | JwtVerifier::JwtVerifier(PublicKey apiPublicKey, std::string apiPublicKeyIdentifier, std::shared_ptr crypto) 45 | : apiPublicKey_(std::move(apiPublicKey)), 46 | apiPublicKeyIdentifier_(std::move(apiPublicKeyIdentifier)), 47 | crypto_(std::move(crypto)) {} 48 | 49 | bool JwtVerifier::verifyToken(const Jwt &token) const { 50 | try { 51 | const auto& data = token.dataToSign(); 52 | const auto& signature = token.signatureContent(); 53 | 54 | return crypto_->verify(data, signature, apiPublicKey_); 55 | } catch (...) { 56 | return false; 57 | } 58 | } 59 | 60 | const PublicKey& JwtVerifier::apiPublicKey() const { return apiPublicKey_; } 61 | 62 | const std::string& JwtVerifier::apiPublicKeyIdentifier() const { return apiPublicKeyIdentifier_; } 63 | 64 | const std::shared_ptr& JwtVerifier::crypto() const { return crypto_; } -------------------------------------------------------------------------------- /include/virgil/sdk/Version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_VERSION_H 38 | #define VIRGIL_SDK_VERSION_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | /** 46 | * @brief Provides information about Virgil Keys SDK version 47 | */ 48 | class Version { 49 | public: 50 | /** 51 | * Return version number in the format MMNNPP (Major, Minor, Patch) 52 | * 53 | */ 54 | static size_t asNumber(); 55 | /** 56 | * Return the version number as string 57 | */ 58 | static std::string asString(); 59 | /** 60 | * Return the major version number 61 | */ 62 | static size_t majorVersion(); 63 | /** 64 | * Return the minor version number 65 | */ 66 | static size_t minorVersion(); 67 | /** 68 | * Return the minor version number 69 | */ 70 | static size_t patchVersion(); 71 | }; 72 | } 73 | } 74 | 75 | #endif /* VIRGIL_SDK_VERSION_H */ -------------------------------------------------------------------------------- /src/virgil/sdk/VirgilSdkError.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::VirgilSdkErrorCategory; 40 | 41 | const char* VirgilSdkErrorCategory::name() const noexcept { 42 | return "virgil/sdk"; 43 | } 44 | 45 | std::string VirgilSdkErrorCategory::message(int ev) const noexcept { 46 | switch (static_cast(ev)) { 47 | case VirgilSdkError::VerificationFailed: 48 | return "Verification of signature failed."; 49 | case VirgilSdkError::CardVerificationFailed: 50 | return "Verification of Virgil Card failed."; 51 | case VirgilSdkError::ServiceQueryFailed: 52 | return "REST Query to Virgil Service failed."; 53 | case VirgilSdkError::AddSignatureFailed: 54 | return "Adding duplicate signature failed."; 55 | case VirgilSdkError::AddVerifierCredentialsFailed: 56 | return "Adding duplicate verifier credentials failed."; 57 | default: 58 | return "Undefined error."; 59 | } 60 | } 61 | 62 | const VirgilSdkErrorCategory& virgil::sdk::sdk_category() noexcept { 63 | static VirgilSdkErrorCategory inst; 64 | return inst; 65 | } -------------------------------------------------------------------------------- /tests/include/stubs/AccessTokenProviderStub_STC26.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_ACCESSTOKENPROVIDERSTUB_STC26_H 38 | #define VIRGIL_SDK_ACCESSTOKENPROVIDERSTUB_STC26_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace virgil { 46 | namespace sdk { 47 | namespace test { 48 | namespace stubs { 49 | class AccessTokenProviderStub_STC26 : public jwt::interfaces::AccessTokenProviderInterface { 50 | public: 51 | AccessTokenProviderStub_STC26(std::string identity, std::function forceCallback); 52 | 53 | std::future> getToken(const jwt::TokenContext& tokenContext); 54 | 55 | private: 56 | std::string identity_; 57 | std::function forceCallback_; 58 | int counter_; 59 | TestUtils utils_; 60 | }; 61 | } 62 | } 63 | } 64 | } 65 | 66 | #endif //VIRGIL_SDK_ACCESSTOKENPROVIDERSTUB_STC26_H -------------------------------------------------------------------------------- /src/virgil/sdk/util/JsonKey.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::util::JsonKey; 40 | 41 | const std::string JsonKey::Signer = "signer"; 42 | const std::string JsonKey::Snapshot = "snapshot"; 43 | const std::string JsonKey::Signature = "signature"; 44 | const std::string JsonKey::Signatures = "signatures"; 45 | const std::string JsonKey::PublicKey = "public_key"; 46 | const std::string JsonKey::ContentSnapshot = "content_snapshot"; 47 | const std::string JsonKey::PreviousCardId = "previous_card_id"; 48 | const std::string JsonKey::CreatedAt = "created_at"; 49 | const std::string JsonKey::Identity = "identity"; 50 | const std::string JsonKey::Version = "version"; 51 | const std::string JsonKey::Code = "code"; 52 | const std::string JsonKey::Message = "message"; 53 | 54 | const std::string JsonKey::Algorithm = "alg"; 55 | const std::string JsonKey::Type = "typ"; 56 | const std::string JsonKey::ContentType = "cty"; 57 | const std::string JsonKey::KeyIdentifier = "kid"; 58 | 59 | const std::string JsonKey::AppId = "iss"; 60 | const std::string JsonKey::IdentityJWT = "sub"; 61 | const std::string JsonKey::IssuedAt = "iat"; 62 | const std::string JsonKey::ExpiresAt = "exp"; 63 | const std::string JsonKey::AdditionalData = "ada"; -------------------------------------------------------------------------------- /include/virgil/sdk/client/networking/Connection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_HTTP_CONNECTION_H 38 | #define VIRGIL_SDK_HTTP_CONNECTION_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | namespace client { 46 | namespace networking { 47 | /** 48 | * @brief This class encapsulates access to the HTTP layer. 49 | * @note This class belongs to the **private** API 50 | */ 51 | class Connection { 52 | public: 53 | /** 54 | * @brief Send synchronous request. 55 | * @param request - request to be send. 56 | * @throw std::logic_error - if given parameters are inconsistent. 57 | * @throw std::runtime_error - if error was occurred when send request. 58 | */ 59 | virtual virgil::sdk::client::networking::Response send(const virgil::sdk::client::networking::Request &request); 60 | }; 61 | } 62 | } 63 | } 64 | } 65 | 66 | #endif /* VIRGIL_SDK_HTTP_CONNECTION_H */ -------------------------------------------------------------------------------- /ext/restless/restless.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Virgil Security Inc. 3 | # 4 | # Lead Maintainer: Virgil Security Inc. 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions are 10 | # met: 11 | # 12 | # (1) Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 15 | # (2) Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in 17 | # the documentation and/or other materials provided with the 18 | # distribution. 19 | # 20 | # (3) Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 25 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | 37 | cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR) 38 | 39 | project ("@VIRGIL_DEPENDS_PACKAGE_NAME@-depends") 40 | 41 | include (ExternalProject) 42 | 43 | # Configure additional CMake parameters 44 | file (APPEND "@VIRGIL_DEPENDS_ARGS_FILE@" 45 | "set (BUILD_RESTLESS_TESTS OFF CACHE INTERNAL \"\")\n" 46 | "set (GENERATE_COVERAGE OFF CACHE INTERNAL \"\")\n" 47 | "set (USE_SYSTEM_GTEST OFF CACHE INTERNAL \"\")\n" 48 | "set (INSECURE_CURL OFF CACHE INTERNAL \"\")\n" 49 | "set (USE_LOCAL_CURL OFF CACHE INTERNAL \"\")\n" 50 | ) 51 | 52 | ExternalProject_Add (${PROJECT_NAME} 53 | DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@" 54 | URL "https://github.com/VirgilSecurity/restless/archive/dbd3a789fda874f1390a4344dd875b700ecf442f.tar.gz" 55 | URL_HASH SHA1=0C48BB85C10E48F6A9E45FED5D2155FBF2BFF08E 56 | PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@" 57 | CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@" 58 | PATCH_COMMAND ${CMAKE_COMMAND} -E copy_directory 59 | "${CMAKE_CURRENT_SOURCE_DIR}/patch" 60 | "${CMAKE_CURRENT_BINARY_DIR}/src/${PROJECT_NAME}/src" 61 | ) 62 | 63 | add_custom_target ("${PROJECT_NAME}-build" ALL COMMENT "Build package ${PROJECT_NAME}") 64 | add_dependencies ("${PROJECT_NAME}-build" ${PROJECT_NAME}) 65 | -------------------------------------------------------------------------------- /include/virgil/sdk/crypto/keys/KeyPair.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_KEYPAIR_H 38 | #define VIRGIL_SDK_KEYPAIR_H 39 | 40 | #include 41 | #include 42 | 43 | /// forward decl 44 | namespace virgil { 45 | namespace sdk { 46 | namespace crypto { 47 | class Crypto; 48 | } 49 | } 50 | } 51 | 52 | namespace virgil { 53 | namespace sdk { 54 | namespace crypto { 55 | namespace keys { 56 | /*! 57 | * @brief Wrapper for related Public Key and Private Key. 58 | */ 59 | class KeyPair { 60 | public: 61 | /*! 62 | * @brief Getter. 63 | * @return Public Key 64 | */ 65 | const PublicKey& publicKey() const { return publicKey_; } 66 | 67 | /*! 68 | * @brief Getter. 69 | * @return Private Key 70 | */ 71 | const PrivateKey& privateKey() const { return privateKey_; } 72 | 73 | private: 74 | KeyPair(PrivateKey privateKey, PublicKey publicKey); 75 | 76 | PrivateKey privateKey_; 77 | PublicKey publicKey_; 78 | 79 | friend Crypto; 80 | }; 81 | } 82 | } 83 | } 84 | } 85 | 86 | #endif //VIRGIL_SDK_KEYPAIR_H -------------------------------------------------------------------------------- /tests/src/managerTests/AccessTokenProviderStub_STC26.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | using virgil::sdk::test::stubs::AccessTokenProviderStub_STC26; 41 | using virgil::sdk::jwt::interfaces::AccessTokenInterface; 42 | using virgil::sdk::jwt::TokenContext; 43 | using virgil::sdk::jwt::Jwt; 44 | 45 | AccessTokenProviderStub_STC26::AccessTokenProviderStub_STC26(std::string identity, 46 | std::function forceCallback) 47 | : identity_(std::move(identity)), forceCallback_(std::move(forceCallback)), 48 | counter_(0), utils_(TestUtils(TestConst())) {} 49 | 50 | std::future> AccessTokenProviderStub_STC26::getToken( 51 | const TokenContext &tokenContext) { 52 | std::promise> p; 53 | auto interval = (counter_ % 2) == 0 ? 5 : 1000; 54 | forceCallback_(tokenContext.forceReload()); 55 | 56 | auto token = utils_.getToken(identity_, interval); 57 | p.set_value(std::make_shared(token)); 58 | 59 | if (counter_ % 2 == 0) 60 | std::this_thread::sleep_for(std::chrono::seconds(10)); 61 | 62 | counter_++; 63 | 64 | return p.get_future(); 65 | } -------------------------------------------------------------------------------- /include/virgil/sdk/jwt/interfaces/AccessTokenInterface.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_ACCESSTOKENINTERFACE_H 38 | #define VIRGIL_SDK_ACCESSTOKENINTERFACE_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace jwt { 45 | namespace interfaces { 46 | /*! 47 | * @brief Interface representing Access Token 48 | */ 49 | class AccessTokenInterface { 50 | public: 51 | /*! 52 | * @brief Provides string representation of token 53 | * @return std::string with token 54 | */ 55 | virtual const std::string& stringRepresentation() const = 0; 56 | 57 | /*! 58 | * @brief Extracts identity 59 | * @return std::string with identity 60 | */ 61 | virtual const std::string& identity() const = 0; 62 | 63 | /*! 64 | * @brief Virtual destructor 65 | */ 66 | virtual ~AccessTokenInterface() = default; 67 | }; 68 | } 69 | } 70 | } 71 | } 72 | 73 | #endif //VIRGIL_SDK_ACCESSTOKENINTERFACE_H -------------------------------------------------------------------------------- /ext/virgil_crypto/virgil_crypto.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Virgil Security Inc. 3 | # 4 | # Lead Maintainer: Virgil Security Inc. 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions are 10 | # met: 11 | # 12 | # (1) Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 15 | # (2) Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in 17 | # the documentation and/or other materials provided with the 18 | # distribution. 19 | # 20 | # (3) Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 25 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | 37 | cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR) 38 | 39 | project ("@VIRGIL_DEPENDS_PACKAGE_NAME@-depends") 40 | 41 | include (ExternalProject) 42 | 43 | # Configure additional CMake parameters 44 | file (APPEND "@VIRGIL_DEPENDS_ARGS_FILE@" 45 | "set (ENABLE_FILE_IO ON CACHE INTERNAL \"\")\n" 46 | "set (ENABLE_TESTING OFF CACHE INTERNAL \"\")\n" 47 | "set (LIB_LOW_LEVEL_API ON CACHE INTERNAL \"\")\n" 48 | "set (LIB_STATIC_RUNTIME OFF CACHE INTERNAL \"\")\n" 49 | "set (LIB_FILE_IO ON CACHE INTERNAL \"\")\n" 50 | "set (INSTALL_EXT_LIBS @INSTALL_EXT_LIBS@ CACHE INTERNAL \"\")\n" 51 | "set (INSTALL_EXT_HEADERS @INSTALL_EXT_HEADERS@ CACHE INTERNAL \"\")\n" 52 | "set (VIRGIL_CRYPTO_FEATURE_RNG_SEED_FILE @VIRGIL_CRYPTO_FEATURE_RNG_SEED_FILE@ CACHE INTERNAL \"\")\n" 53 | ) 54 | 55 | ExternalProject_Add (${PROJECT_NAME} 56 | DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@" 57 | URL "https://github.com/VirgilSecurity/virgil-crypto/archive/v2.6.1.tar.gz" 58 | URL_HASH SHA1=DA6214CF37B81D22EF5ABED1C4D78EED288D89DC 59 | PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@" 60 | CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@" 61 | ) 62 | 63 | add_custom_target ("${PROJECT_NAME}-build" ALL COMMENT "Build package ${PROJECT_NAME}") 64 | add_dependencies ("${PROJECT_NAME}-build" ${PROJECT_NAME}) 65 | -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/providers/CallbackJwtProvider.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | using virgil::sdk::jwt::providers::CallbackJwtProvider; 41 | using virgil::sdk::jwt::interfaces::AccessTokenInterface; 42 | using virgil::sdk::jwt::TokenContext; 43 | using virgil::sdk::jwt::Jwt; 44 | 45 | CallbackJwtProvider::CallbackJwtProvider(std::function(const TokenContext&)> getTokenCallback) 46 | : getTokenCallback_(std::move(getTokenCallback)) {} 47 | 48 | std::future> CallbackJwtProvider::getToken(const TokenContext &tokenContext) { 49 | auto future = std::async([=]{ 50 | std::promise> p; 51 | try { 52 | auto future = getTokenCallback_(tokenContext); 53 | auto jwt = Jwt::parse(future.get()); 54 | p.set_value(std::make_shared(jwt)); 55 | } catch (...) { 56 | p.set_exception(std::current_exception()); 57 | } 58 | 59 | return p.get_future().get(); 60 | }); 61 | 62 | return future; 63 | } 64 | 65 | const std::function(const TokenContext&)>& CallbackJwtProvider::getTokenCallback() const { 66 | return getTokenCallback_; 67 | } -------------------------------------------------------------------------------- /include/virgil/sdk/util/Base64Url.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_BASE64URL_H 38 | #define VIRGIL_SDK_BASE64URL_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace util { 45 | /*! 46 | * @brief Class for base64Url encoding and decoding 47 | */ 48 | class Base64Url { 49 | public: 50 | /*! 51 | * @brief Encodes passed std::string in base64Url format 52 | * @param in std::string to be encoded 53 | * @return base64Url encoded std::string 54 | */ 55 | static std::string encode(const std::string &in); 56 | 57 | /*! 58 | * @brief Decodes passed base64Url encoded std::string 59 | * @param in base64Url encoded std::string 60 | * @return decoded std::string 61 | */ 62 | static std::string decode(const std::string &in); 63 | 64 | /*! 65 | * @brief Forbid creation. 66 | */ 67 | Base64Url() = delete; 68 | 69 | private: 70 | static const char base64_url_alphabet[]; 71 | }; 72 | } 73 | } 74 | } 75 | 76 | #endif //VIRGIL_SDK_BASE64URL_H -------------------------------------------------------------------------------- /include/virgil/sdk/client/networking/ClientRequest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_CLIENTREQUEST_H 38 | #define VIRGIL_SDK_CLIENTREQUEST_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace client { 45 | namespace networking { 46 | /** 47 | * @brief This is base class for all HTTP requests to the Virgil Service. 48 | */ 49 | class ClientRequest : public Request { 50 | public: 51 | /*! 52 | * @brief std::string with header key for authorization 53 | */ 54 | static const std::string accessTokenHeader; 55 | /*! 56 | * @brief std::string with prefix to Access Token in authentication header 57 | */ 58 | static const std::string accessTokenPrefix; 59 | 60 | /*! 61 | * @brief Constructor. 62 | * @param accessToken std::string with access token for the Virgil Service 63 | */ 64 | ClientRequest(std::string accessToken); 65 | }; 66 | } 67 | } 68 | } 69 | } 70 | 71 | #endif //VIRGIL_SDK_CLIENTREQUEST_H -------------------------------------------------------------------------------- /tests/src/TestConst.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | using virgil::sdk::test::TestConst; 42 | using json = nlohmann::json; 43 | 44 | TestConst::TestConst(const std::string &fileName) 45 | : enableStg_(ENABLE_STAGING_ENV) { 46 | std::ifstream input(fileName); 47 | 48 | std::string str((std::istreambuf_iterator(input)), 49 | std::istreambuf_iterator()); 50 | 51 | if (!str.empty()) { 52 | auto j = json::parse(str); 53 | 54 | json dict = enableStg_ ? j["staging"] : j["prod"]; 55 | 56 | ApiPublicKeyId_ = dict["ApiPublicKeyId"]; 57 | ApiPrivateKey_ = dict["ApiPrivateKey"]; 58 | ApiPublicKey_ = dict["ApiPublicKey"]; 59 | AppId_ = dict["AppId"]; 60 | ServiceURL_ = dict["ServiceURL"]; 61 | } 62 | input.close(); 63 | } 64 | 65 | const std::string& TestConst::ApiPublicKeyId() const { return ApiPublicKeyId_; } 66 | 67 | const std::string& TestConst::ApiPrivateKey() const { return ApiPrivateKey_; } 68 | 69 | const std::string& TestConst::ApiPublicKey() const { return ApiPublicKey_; } 70 | 71 | const std::string& TestConst::AppId() const { return AppId_; } 72 | 73 | const std::string& TestConst::ServiceURL() const { return ServiceURL_; } 74 | 75 | bool TestConst::enableStg() const { return enableStg_; } -------------------------------------------------------------------------------- /include/virgil/sdk/serialization/JsonSerializer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_JSONSERIALIZER_H 38 | #define VIRGIL_SDK_JSONSERIALIZER_H 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | namespace virgil { 46 | namespace sdk { 47 | namespace serialization { 48 | /*! 49 | * @brief This class is responsible for the data object marshalling. 50 | * @note Supported classes: CreateCardSnapshotModel, RevokeCardSnapshotModel, SearchCardsCriteria, 51 | * SignableRequestInterface 52 | * @tparam T represents class to be serialized 53 | */ 54 | template 55 | class JsonSerializer { 56 | public: 57 | /*! 58 | * @brief Serializes given object to std::string Json representation. 59 | * @tparam INDENT if > 0 - pretty print, 0 - only new lines, -1 - compact 60 | * @param obj object to be serialized 61 | * @return std::string json representation of the object 62 | */ 63 | template 64 | static std::string toJson(const T &obj); 65 | 66 | /*! 67 | * @brief Forbid instantiation 68 | */ 69 | JsonSerializer() = delete; 70 | }; 71 | } 72 | } 73 | } 74 | 75 | #endif //VIRGIL_SDK_JSONSERIALIZER_H -------------------------------------------------------------------------------- /ext/nlohman_json/nlohman_json.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Virgil Security Inc. 3 | # 4 | # Lead Maintainer: Virgil Security Inc. 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions are 10 | # met: 11 | # 12 | # (1) Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 15 | # (2) Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in 17 | # the documentation and/or other materials provided with the 18 | # distribution. 19 | # 20 | # (3) Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 25 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | 37 | cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR) 38 | 39 | project (nlohman_json VERSION 1.1.0 LANGUAGES CXX) 40 | 41 | # Define names for configuration files 42 | set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") 43 | set (INSTALL_CFG_DIR_NAME 44 | "lib/cmake/${PROJECT_NAME}" CACHE STRING 45 | "Path to the CMake configuration files be installed" 46 | ) 47 | set (generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") 48 | set (version_config "${generated_dir}/${PROJECT_NAME}-config-version.cmake") 49 | set (project_config "${generated_dir}/${PROJECT_NAME}-config.cmake") 50 | 51 | # Create configuration files 52 | include (CMakePackageConfigHelpers) 53 | 54 | # Write Version Config 55 | write_basic_package_version_file ( 56 | "${version_config}" COMPATIBILITY SameMajorVersion 57 | ) 58 | 59 | # Write Project Config 60 | configure_package_config_file ( 61 | "cmake/config.cmake.in" 62 | "${project_config}" 63 | INSTALL_DESTINATION "${INSTALL_CFG_DIR_NAME}" 64 | PATH_VARS INCLUDE_INSTALL_DIR 65 | ) 66 | 67 | # Install headers 68 | install ( 69 | DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" 70 | DESTINATION "include/nlohman" 71 | ) 72 | 73 | # Install configurations 74 | install ( 75 | FILES "${project_config}" "${version_config}" 76 | DESTINATION "${INSTALL_CFG_DIR_NAME}" 77 | ) 78 | -------------------------------------------------------------------------------- /tests/include/stubs/CardClientStub_STC34.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_CARDCLIENTSTUB_STC34_H 38 | #define VIRGIL_SDK_CARDCLIENTSTUB_STC34_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | namespace test { 46 | namespace stubs { 47 | class CardClientStub_STC34 : public client::CardClientInterface { 48 | public: 49 | CardClientStub_STC34(); 50 | 51 | std::future publishCard(const client::models::RawSignedModel& model, 52 | const std::string& token) const; 53 | 54 | std::future getCard(const std::string &cardId, 55 | const std::string& token) const; 56 | 57 | std::future> searchCards(const std::string &identity, 58 | const std::string& token) const; 59 | 60 | private: 61 | virgil::sdk::test::TestData testData_; 62 | }; 63 | } 64 | } 65 | } 66 | } 67 | 68 | #endif //VIRGIL_SDK_CARDCLIENTSTUB_STC34_H -------------------------------------------------------------------------------- /include/virgil/sdk/jwt/interfaces/AccessTokenProviderInterface.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_ACCESSTOKENPROVIDERINTERFACE_H 38 | #define VIRGIL_SDK_ACCESSTOKENPROVIDERINTERFACE_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace virgil { 46 | namespace sdk { 47 | namespace jwt { 48 | namespace interfaces { 49 | /*! 50 | * @brief Interface responsible for providing AccessToken 51 | */ 52 | class AccessTokenProviderInterface { 53 | public: 54 | /*! 55 | * @brief Provides access token 56 | * @param tokenContext TokenContext provides context explaining why token is needed 57 | * @return std::future with std::shared_ptr to AccessTokenInterface implementation 58 | */ 59 | virtual std::future> getToken(const TokenContext& tokenContext) = 0; 60 | 61 | /*! 62 | * @brief Virtual destructor 63 | */ 64 | virtual ~AccessTokenProviderInterface() = default; 65 | }; 66 | } 67 | } 68 | } 69 | } 70 | 71 | #endif //VIRGIL_SDK_ACCESSTOKENPROVIDERINTERFACE_H -------------------------------------------------------------------------------- /include/virgil/sdk/client/networking/CardEndpointUri.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_CARD_ENDPOINT_URI_H 38 | #define VIRGIL_SDK_CARD_ENDPOINT_URI_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace client { 45 | namespace networking { 46 | /** 47 | * @brief This class provides URIs to the Virgil Service endpoints. 48 | */ 49 | class CardEndpointUri { 50 | public: 51 | /** 52 | * @brief Returns the endpoint in charge of a Virgil Card publishing. 53 | */ 54 | static std::string publish(); 55 | 56 | /** 57 | * @brief Returns the endpoint in charge of a Virgil Card grab. 58 | */ 59 | static std::string get(const std::string &cardId); 60 | 61 | /** 62 | * @brief Returns the endpoint in charge of the Virgil Card searches by provided parameters. 63 | */ 64 | static std::string search(); 65 | 66 | /** 67 | * @brief Deny object creation 68 | */ 69 | CardEndpointUri() = delete; 70 | }; 71 | } 72 | } 73 | } 74 | } 75 | 76 | #endif /* VIRGIL_SDK_CARD_ENDPOINT_URI_H */ -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/JwtHeaderContent.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | using virgil::sdk::jwt::JwtHeaderContent; 43 | using virgil::sdk::util::Base64Url; 44 | using virgil::sdk::serialization::JsonSerializer; 45 | using virgil::sdk::serialization::JsonDeserializer; 46 | 47 | JwtHeaderContent::JwtHeaderContent(std::string keyIdentifier, std::string algorithm, 48 | std::string type, std::string contentType) 49 | : keyIdentifier_(std::move(keyIdentifier)), algorithm_(std::move(algorithm)), 50 | type_(std::move(type)), contentType_(std::move(contentType)) {} 51 | 52 | JwtHeaderContent JwtHeaderContent::parse(const std::string &base64url) { 53 | return JsonDeserializer::fromJsonString(Base64Url::decode(base64url)); 54 | } 55 | 56 | std::string JwtHeaderContent::base64Url() const { 57 | return Base64Url::encode(JsonSerializer::toJson(*this)); 58 | } 59 | 60 | const std::string& JwtHeaderContent::algorithm() const { return algorithm_; } 61 | 62 | const std::string& JwtHeaderContent::type() const { return type_; } 63 | 64 | const std::string& JwtHeaderContent::contentType() const { return contentType_; } 65 | 66 | const std::string& JwtHeaderContent::keyIdentifier() const { return keyIdentifier_; } -------------------------------------------------------------------------------- /include/virgil/sdk/util/JsonUtils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_JSONUTILS_H 38 | #define VIRGIL_SDK_JSONUTILS_H 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | #include 46 | 47 | namespace virgil { 48 | namespace sdk { 49 | namespace util { 50 | /** 51 | * @brief This class holds utils for Json processing. 52 | * 53 | * @note This class belongs to the **private** API 54 | */ 55 | class JsonUtils { 56 | public: 57 | //! @cond Doxygen_Suppress 58 | static std::unordered_map jsonToUnorderedMap(const nlohmann::json &jsonObj); 59 | 60 | static std::unordered_map jsonToUnorderedBinaryMap( 61 | const nlohmann::json &jsonObj); 62 | 63 | static nlohmann::json unorderedMapToJson(const std::unordered_map &map); 64 | 65 | static nlohmann::json unorderedBinaryMapToJson(const std::unordered_map &map); 66 | 67 | static std::unordered_map bytesToUnorderedMap(const VirgilByteArray& bytes); 68 | //! @endcond 69 | 70 | /*! 71 | * @brief Forbid creation. 72 | */ 73 | JsonUtils() = delete; 74 | }; 75 | } 76 | } 77 | } 78 | 79 | #endif //VIRGIL_SDK_JSONUTILS_H -------------------------------------------------------------------------------- /include/virgil/sdk/cards/verification/Whitelist.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_WHITELIST_H 38 | #define VIRGIL_SDK_WHITELIST_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | namespace cards { 46 | namespace verification { 47 | /*! 48 | * @brief Class representing collection of verifiers 49 | * @note Card should contain signature from AT LEAST one verifier from collection of verifiers 50 | */ 51 | class Whitelist { 52 | public: 53 | /*! 54 | * @brief Constructor 55 | * @param verifierCredentials std::vector with VerifierCredentials 56 | */ 57 | Whitelist(std::vector verifierCredentials); 58 | 59 | /*! 60 | * @brief Getter 61 | * @return std::vector with VerifierCredentials 62 | * @note Card must be signed by AT LEAST one of them 63 | */ 64 | const std::vector& verifierCredentials() const; 65 | 66 | private: 67 | std::vector verifierCredentials_; 68 | }; 69 | } 70 | } 71 | } 72 | } 73 | 74 | #endif //VIRGIL_SDK_WHITELIST_H -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/providers/GeneratorJwtProvider.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::jwt::providers::GeneratorJwtProvider; 40 | using virgil::sdk::jwt::interfaces::AccessTokenInterface; 41 | using virgil::sdk::jwt::JwtGenerator; 42 | 43 | GeneratorJwtProvider::GeneratorJwtProvider(JwtGenerator jwtGenerator, std::string defaultIdentity, 44 | std::unordered_map additionalData) 45 | : jwtGenerator_(std::move(jwtGenerator)), defaultIdentity_(std::move(defaultIdentity)), 46 | additionalData_(std::move(additionalData)) {} 47 | 48 | std::future> GeneratorJwtProvider::getToken( 49 | const virgil::sdk::jwt::TokenContext &tokenContext) 50 | { 51 | auto identity = tokenContext.identity().empty() ? defaultIdentity_ : tokenContext.identity(); 52 | auto token = jwtGenerator_.generateToken(identity, additionalData_); 53 | 54 | std::promise> p; 55 | p.set_value(std::make_shared(token)); 56 | 57 | return p.get_future(); 58 | } 59 | 60 | const JwtGenerator& GeneratorJwtProvider::jwtGenerator() const { return jwtGenerator_; } 61 | 62 | const std::string& GeneratorJwtProvider::defaultIdentity() const { return defaultIdentity_; } 63 | 64 | const std::unordered_map& GeneratorJwtProvider::additionalData() const { return additionalData_; } -------------------------------------------------------------------------------- /tests/include/helpers.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef HELPERS_H 38 | #define HELPERS_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include 46 | 47 | namespace virgil { 48 | namespace sdk { 49 | namespace test { 50 | using random_bytes_engine = std::independent_bits_engine; 51 | 52 | class Utils { 53 | public: 54 | static virgil::sdk::VirgilByteArray generateRandomData(int size) { 55 | std::random_device rd; 56 | random_bytes_engine rbe(rd()); 57 | std::vector data(size); 58 | std::generate(begin(data), end(data), std::ref(rbe)); 59 | return data; 60 | } 61 | 62 | static std::string generateRandomStr(int size) { 63 | static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 64 | 65 | std::random_device rd; 66 | std::default_random_engine generator(rd()); 67 | std::uniform_int_distribution distribution(0, sizeof(alphanum) - 1); 68 | auto randomCharNum = std::bind(distribution, generator); 69 | 70 | std::string st; 71 | for (int i = 0; i < size; ++i) { 72 | st += alphanum[randomCharNum()]; 73 | } 74 | 75 | return st; 76 | } 77 | }; 78 | } 79 | } 80 | } 81 | 82 | #endif /* HELPERS_H */ -------------------------------------------------------------------------------- /src/virgil/sdk/serialization/VirgilErrorSerializer.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | using json = nlohmann::json; 46 | 47 | using virgil::sdk::util::JsonKey; 48 | using virgil::sdk::client::networking::errors::VirgilError; 49 | 50 | namespace virgil { 51 | namespace sdk { 52 | namespace serialization { 53 | /** 54 | * @brief JSONSerializer specialization. 55 | */ 56 | template<> 57 | class JsonDeserializer { 58 | public: 59 | template 60 | static VirgilError fromJson(const json &j) { 61 | try { 62 | int errorCodeStr = j[JsonKey::Code]; 63 | std::string errorMsg = j[JsonKey::Message]; 64 | 65 | return VirgilError(errorCodeStr, errorMsg); 66 | } catch (std::exception &exception) { 67 | throw std::logic_error(std::string("virgil-sdk:\n JsonDeserializer::fromJson ") + 68 | exception.what()); 69 | } 70 | } 71 | 72 | JsonDeserializer() = delete; 73 | }; 74 | } 75 | } 76 | } 77 | 78 | /** 79 | * Explicit methods instantiation 80 | */ 81 | template VirgilError 82 | virgil::sdk::serialization::JsonDeserializer::fromJson(const json&); -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/providers/CachingJwtProvider.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::jwt::providers::CachingJwtProvider; 40 | using virgil::sdk::jwt::interfaces::AccessTokenInterface; 41 | using virgil::sdk::jwt::TokenContext; 42 | using virgil::sdk::jwt::Jwt; 43 | 44 | CachingJwtProvider::CachingJwtProvider(std::function(const TokenContext &)> renewJwtCallback) 45 | : renewJwtCallback_(std::move(renewJwtCallback)), jwt_(nullptr) {} 46 | 47 | std::future> CachingJwtProvider::getToken(const TokenContext &tokenContext) { 48 | auto future = std::async([=]{ 49 | std::promise> p; 50 | 51 | if (jwt_ == nullptr || jwt_->isExpired(std::time(0) + 5)) { 52 | try { 53 | auto future = renewJwtCallback_(tokenContext); 54 | auto jwt = Jwt::parse(future.get()); 55 | jwt_ = std::make_shared(jwt); 56 | } catch (...) { 57 | p.set_exception(std::current_exception()); 58 | 59 | return p.get_future().get(); 60 | } 61 | } 62 | p.set_value(jwt_); 63 | 64 | return p.get_future().get(); 65 | }); 66 | 67 | return future; 68 | } 69 | 70 | const std::function(const TokenContext&)>& CachingJwtProvider::renewJwtCallback() const { 71 | return renewJwtCallback_; 72 | } 73 | 74 | const std::shared_ptr& CachingJwtProvider::jwt() const { 75 | return jwt_; 76 | } -------------------------------------------------------------------------------- /include/virgil/sdk/client/models/GetCardResponse.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_GETCARDRESPONSE_H 38 | #define VIRGIL_SDK_GETCARDRESPONSE_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace client { 45 | namespace models { 46 | /*! 47 | * @brief Represents response from CardClient's getCard function with RawSignedModel and whether or not card is outdated 48 | */ 49 | class GetCardResponse { 50 | public: 51 | /*! 52 | * @brief Constructor 53 | * @param rawCard RawSignedModel representing Virgil Card 54 | * @param isOutdated whether card is outdated or not 55 | */ 56 | GetCardResponse(RawSignedModel rawCard, bool isOutdated); 57 | 58 | /*! 59 | * @brief Getter 60 | * @return RawSignedModel representing Virgil Card 61 | */ 62 | const RawSignedModel& rawCard() const; 63 | 64 | /*! 65 | * @brief Getter 66 | * @return true if Virgil Card is outdated, false otherwise 67 | */ 68 | bool isOutdated() const; 69 | 70 | private: 71 | RawSignedModel rawCard_; 72 | bool isOutdated_; 73 | }; 74 | } 75 | } 76 | } 77 | } 78 | 79 | #endif //VIRGIL_SDK_GETCARDRESPONSE_H -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/JwtBodyContent.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | using virgil::sdk::jwt::JwtBodyContent; 43 | using virgil::sdk::VirgilByteArray; 44 | using virgil::sdk::util::Base64Url; 45 | using virgil::sdk::serialization::JsonSerializer; 46 | using virgil::sdk::serialization::JsonDeserializer; 47 | 48 | JwtBodyContent::JwtBodyContent(std::string appId, std::string identity, 49 | std::time_t expiresAt, std::time_t issuedAt, 50 | std::unordered_map additionalData) 51 | : appId_(std::move(appId)), identity_(std::move(identity)), expiresAt_(expiresAt), 52 | issuedAt_(issuedAt), additionalData_(std::move(additionalData)) {} 53 | 54 | JwtBodyContent JwtBodyContent::parse(const std::string &base64url) { 55 | return JsonDeserializer::fromJsonString(Base64Url::decode(base64url)); 56 | } 57 | 58 | std::string JwtBodyContent::base64Url() const { 59 | return Base64Url::encode(JsonSerializer::toJson(*this)); 60 | } 61 | 62 | const std::string& JwtBodyContent::appId() const { return appId_; } 63 | 64 | const std::string& JwtBodyContent::identity() const { return identity_; } 65 | 66 | std::time_t JwtBodyContent::expiresAt() const { return expiresAt_; } 67 | 68 | std::time_t JwtBodyContent::issuedAt() const { return issuedAt_; } 69 | 70 | const std::unordered_map& JwtBodyContent::additionalData() const { return additionalData_; } -------------------------------------------------------------------------------- /src/virgil/sdk/jwt/JwtGenerator.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::sdk::jwt::JwtGenerator; 40 | using virgil::sdk::jwt::Jwt; 41 | using virgil::sdk::jwt::JwtHeaderContent; 42 | using virgil::sdk::jwt::JwtBodyContent; 43 | using virgil::sdk::crypto::Crypto; 44 | using virgil::sdk::crypto::keys::PrivateKey; 45 | 46 | JwtGenerator::JwtGenerator(PrivateKey apiKey, std::string apiPublicKeyIdentifier, 47 | std::shared_ptr crypto, std::string appId, int ttl) 48 | : apiKey_(std::move(apiKey)), apiPublicKeyIdentifier_(std::move(apiPublicKeyIdentifier)), 49 | crypto_(std::move(crypto)), appId_(std::move(appId)), ttl_(ttl) {} 50 | 51 | Jwt JwtGenerator::generateToken(const std::string &identity, 52 | const std::unordered_map &additionalData) const { 53 | auto headerContent = JwtHeaderContent(apiPublicKeyIdentifier_); 54 | auto bodyContent = JwtBodyContent(appId_, identity, std::time(0) + ttl_, std::time(0), additionalData); 55 | auto data = Jwt::dataToSign(headerContent, bodyContent); 56 | auto signatureContent = crypto_->generateSignature(data, apiKey_); 57 | 58 | return Jwt(headerContent, bodyContent, signatureContent); 59 | } 60 | 61 | const PrivateKey& JwtGenerator::apiKey() const { return apiKey_; } 62 | 63 | const std::string& JwtGenerator::apiPublicKeyIdentifier() const { return apiPublicKeyIdentifier_; } 64 | 65 | const std::shared_ptr& JwtGenerator::crypto() const { return crypto_; } 66 | 67 | const std::string& JwtGenerator::appId() const { return appId_; } 68 | 69 | int JwtGenerator::ttl() const { return ttl_; } -------------------------------------------------------------------------------- /src/virgil/sdk/client/networking/Response.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | using virgil::sdk::client::networking::Response; 43 | 44 | Response& Response::body(const std::string& body) { 45 | body_ = body; 46 | return *this; 47 | } 48 | 49 | std::string Response::body() const { 50 | return body_; 51 | } 52 | 53 | Response& Response::contentType(const std::string& contentType) { 54 | contentType_ = contentType; 55 | return *this; 56 | } 57 | 58 | std::string Response::contentType() const { 59 | return contentType_; 60 | } 61 | 62 | Response& Response::header(const Response::Header& header) { 63 | header_ = header; 64 | return *this; 65 | } 66 | 67 | Response::Header Response::header() const { 68 | return header_; 69 | } 70 | 71 | Response& Response::statusCode(Response::StatusCode statusCode) { 72 | statusCode_ = statusCode; 73 | return *this; 74 | } 75 | 76 | Response::StatusCode Response::statusCode() const { 77 | return statusCode_; 78 | } 79 | 80 | Response& Response::statusCodeRaw(int code) { 81 | std::set availableCodes{200, 201, 400, 401, 403, 404, 405, 500}; 82 | if (availableCodes.find(code) != availableCodes.end()) { 83 | statusCode_ = static_cast(code); 84 | } else { 85 | throw std::logic_error("Given status code is not supported."); 86 | } 87 | return *this; 88 | } 89 | 90 | int Response::statusCodeRaw() const { 91 | return static_cast(statusCode_); 92 | } 93 | 94 | bool Response::fail() const { 95 | return !(statusCode_ == StatusCode::OK || statusCode_ == StatusCode ::CREATED); 96 | } -------------------------------------------------------------------------------- /tests/src/managerTests/CardClientStub_STC34.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | using virgil::sdk::test::stubs::CardClientStub_STC34; 41 | using virgil::sdk::client::models::RawSignedModel; 42 | using virgil::sdk::client::models::GetCardResponse; 43 | 44 | CardClientStub_STC34::CardClientStub_STC34() { 45 | testData_ = virgil::sdk::test::TestData(); 46 | } 47 | 48 | std::future CardClientStub_STC34::publishCard(const RawSignedModel &model, 49 | const std::string &token) const { 50 | std::promise p; 51 | p.set_value(RawSignedModel::importFromBase64EncodedString(testData_.dict()["STC-34.as_string"])); 52 | 53 | return p.get_future(); 54 | } 55 | 56 | std::future CardClientStub_STC34::getCard(const std::string &cardId, 57 | const std::string &token) const { 58 | std::promise p; 59 | auto rawCard = RawSignedModel::importFromBase64EncodedString(testData_.dict()["STC-34.as_string"]); 60 | p.set_value(GetCardResponse(rawCard, false)); 61 | 62 | return p.get_future(); 63 | } 64 | 65 | std::future> CardClientStub_STC34::searchCards(const std::string &identity, 66 | const std::string &token) const { 67 | std::promise> p; 68 | p.set_value({RawSignedModel::importFromBase64EncodedString(testData_.dict()["STC-34.as_string"])}); 69 | 70 | return p.get_future(); 71 | } -------------------------------------------------------------------------------- /include/virgil/sdk/client/networking/errors/VirgilError.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_VIRGILERROR_H 38 | #define VIRGIL_SDK_VIRGILERROR_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace client { 45 | namespace networking { 46 | namespace errors { 47 | /*! 48 | * @brief Model for errors which can be received from the Virgil Service. 49 | */ 50 | class VirgilError { 51 | public: 52 | /*! 53 | * @brief Constructor 54 | * @param virgilErrorCode int with error code 55 | * @param errorMsg std::string with error message 56 | */ 57 | VirgilError(int virgilErrorCode, std::string errorMsg = "Unknown error"); 58 | 59 | /*! 60 | * @brief Getter. 61 | * @return int with error code 62 | */ 63 | int virgilErrorCode() const { return virgilErrorCode_; } 64 | 65 | /*! 66 | * @brief Getter. 67 | * @return std::string with english (debug-only) error message. 68 | */ 69 | const std::string &errorMsg() const { return errorMsg_; } 70 | 71 | private: 72 | int virgilErrorCode_; 73 | std::string errorMsg_; 74 | }; 75 | } 76 | } 77 | } 78 | } 79 | } 80 | 81 | #endif //VIRGIL_SDK_VIRGILERROR_H -------------------------------------------------------------------------------- /include/virgil/sdk/cards/verification/VerifierCredentials.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_VERIFIERCREDENTIALS_H 38 | #define VIRGIL_SDK_VERIFIERCREDENTIALS_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { 44 | namespace sdk { 45 | namespace cards { 46 | namespace verification { 47 | /*! 48 | * Class representing verifier credentials 49 | */ 50 | class VerifierCredentials { 51 | public: 52 | /*! 53 | * @brief Constructor 54 | * @param signer identifier of signer 55 | * @param publicKey exported Public Key to verify with 56 | * @note signer must be unique. Reserved values: 57 | * - Self verifier: "self" 58 | * - Virgil Service verifier: "virgil" 59 | */ 60 | VerifierCredentials(std::string signer, VirgilByteArray publicKey); 61 | 62 | /*! 63 | * @brief Getter 64 | * @return identifier of signer 65 | */ 66 | const std::string& signer() const; 67 | 68 | /*! 69 | * @brief Getter 70 | * @return exported Public Key to verify with 71 | */ 72 | const VirgilByteArray& publicKey() const; 73 | 74 | private: 75 | std::string signer_; 76 | VirgilByteArray publicKey_; 77 | }; 78 | } 79 | } 80 | } 81 | } 82 | 83 | #endif //VIRGIL_SDK_VERIFIERCREDENTIALS_H -------------------------------------------------------------------------------- /src/virgil/sdk/util/Base64Url.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | using virgil::sdk::util::Base64Url; 41 | 42 | const char Base64Url::base64_url_alphabet[] = { 43 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 44 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 45 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 46 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 47 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' 48 | }; 49 | 50 | std::string Base64Url::encode(const std::string &in) { 51 | std::string out; 52 | int val = 0, valb = -6; 53 | size_t len = in.length(); 54 | unsigned int i = 0; 55 | for (i = 0; i < len; i++) { 56 | unsigned char c = in[i]; 57 | val = (val<<8) + c; 58 | valb += 8; 59 | while (valb >= 0) { 60 | out.push_back(base64_url_alphabet[(val>>valb)&0x3F]); 61 | valb -= 6; 62 | } 63 | } 64 | if (valb > -6) { 65 | out.push_back(base64_url_alphabet[((val<<8)>>(valb+8))&0x3F]); 66 | } 67 | return out; 68 | } 69 | 70 | std::string Base64Url::decode(const std::string &in) { 71 | std::string out; 72 | std::vector T(256, -1); 73 | unsigned int i; 74 | for (i =0; i < 64; i++) T[base64_url_alphabet[i]] = i; 75 | 76 | int val = 0, valb = -8; 77 | for (i = 0; i < in.length(); i++) { 78 | unsigned char c = in[i]; 79 | if (T[c] == -1) break; 80 | val = (val<<6) + T[c]; 81 | valb += 6; 82 | if (valb >= 0) { 83 | out.push_back(char((val>>valb)&0xFF)); 84 | valb -= 8; 85 | } 86 | } 87 | return out; 88 | } -------------------------------------------------------------------------------- /src/virgil/sdk/util/JsonUtils.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | using nlohmann::json; 41 | 42 | using virgil::sdk::util::JsonUtils; 43 | using virgil::sdk::VirgilByteArray; 44 | 45 | std::unordered_map JsonUtils::jsonToUnorderedMap(const json &jsonObj) { 46 | std::unordered_map res; 47 | 48 | for (auto it = jsonObj.begin(); it != jsonObj.end(); ++it) { 49 | res[it.key()] = it.value(); 50 | } 51 | 52 | return res; 53 | }; 54 | 55 | std::unordered_map JsonUtils::jsonToUnorderedBinaryMap(const json &jsonObj) { 56 | std::unordered_map res; 57 | 58 | for (auto it = jsonObj.begin(); it != jsonObj.end(); ++it) { 59 | res[it.key()] = VirgilBase64::decode(it.value()); 60 | } 61 | 62 | return res; 63 | }; 64 | 65 | json JsonUtils::unorderedMapToJson(const std::unordered_map &map) { 66 | json j; 67 | 68 | for (auto it = map.begin(); it != map.end(); ++it) { 69 | j[it->first] = it->second; 70 | } 71 | 72 | return j; 73 | } 74 | 75 | json JsonUtils::unorderedBinaryMapToJson(const std::unordered_map &map) { 76 | json j; 77 | 78 | for (auto it = map.begin(); it != map.end(); ++it) { 79 | j[it->first] = VirgilBase64::encode(it->second); 80 | } 81 | 82 | return j; 83 | } 84 | 85 | std::unordered_map JsonUtils::bytesToUnorderedMap( 86 | const virgil::sdk::VirgilByteArray &bytes) { 87 | auto str = VirgilByteArrayUtils::bytesToString(bytes); 88 | 89 | json j = json::parse(str); 90 | 91 | return JsonUtils::jsonToUnorderedMap(j); 92 | } -------------------------------------------------------------------------------- /src/virgil/sdk/client/models/RawCardContent.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | using virgil::sdk::client::models::RawCardContent; 42 | using virgil::sdk::VirgilByteArray; 43 | using virgil::sdk::serialization::JsonSerializer; 44 | using virgil::sdk::serialization::JsonDeserializer; 45 | using virgil::sdk::VirgilByteArrayUtils; 46 | 47 | RawCardContent::RawCardContent(std::string identity, VirgilByteArray publicKey, 48 | std::time_t createdAt, std::string previousCardId, 49 | std::string version) 50 | : identity_(std::move(identity)), publicKey_(std::move(publicKey)), 51 | version_(std::move(version)), createdAt_(createdAt), 52 | previousCardId_(std::move(previousCardId)) {} 53 | 54 | RawCardContent RawCardContent::parse(const VirgilByteArray &snapshot) { 55 | auto contentStr = VirgilByteArrayUtils::bytesToString(snapshot); 56 | 57 | return JsonDeserializer::fromJsonString(contentStr); 58 | } 59 | 60 | const std::string& RawCardContent::identity() const { return identity_; } 61 | 62 | const VirgilByteArray& RawCardContent::publicKey() const { return publicKey_; } 63 | 64 | const std::string& RawCardContent::version() const { return version_; } 65 | 66 | std::time_t RawCardContent::createdAt() const { return createdAt_; } 67 | 68 | const std::string& RawCardContent::previousCardId() const { return previousCardId_; } 69 | 70 | VirgilByteArray RawCardContent::snapshot() const { 71 | auto contentStr = JsonSerializer::toJson(*this); 72 | 73 | return VirgilByteArrayUtils::stringToBytes(contentStr); 74 | } -------------------------------------------------------------------------------- /include/virgil/sdk/serialization/CanonicalSerializer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_CANONICALSERIALIZER_H 38 | #define VIRGIL_SDK_CANONICALSERIALIZER_H 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | 46 | namespace virgil { 47 | namespace sdk { 48 | namespace serialization { 49 | /** 50 | * @brief This class is responsible for serializing and deserializing models in Canonical Form. 51 | * @tparam T concrete subclass 52 | * @note Supported classes: CreateCardSnapshotModel, RevokeCardSnapshotModel 53 | */ 54 | template 55 | class CanonicalSerializer { 56 | public: 57 | /*! 58 | * @brief Serizalizes model to Canonical Form. 59 | * @tparam INDENT if > 0 - pretty print, 0 - only new lines, -1 - compact 60 | * @param model model to serialize 61 | * @return serialized representation of model 62 | */ 63 | template 64 | static VirgilByteArray toCanonicalForm(const T &model) ; 65 | 66 | /*! 67 | * @brief Constructs object from its Canonical Form representation. 68 | * @tparam FAKE fake argument to allow template implementation in source file. 69 | * @param data Canonical representation of object 70 | * @return Constructed object 71 | */ 72 | template 73 | static T fromCanonicalForm(const VirgilByteArray &data); 74 | 75 | /*! 76 | * @brief Forbid instantiation. 77 | */ 78 | CanonicalSerializer() = delete; 79 | }; 80 | } 81 | } 82 | } 83 | 84 | #endif //VIRGIL_SDK_CANONICALSERIALIZER_H -------------------------------------------------------------------------------- /include/virgil/sdk/util/JsonKey.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2018 Virgil Security Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * (1) Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * (2) Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * (3) Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Lead Maintainer: Virgil Security Inc. 35 | */ 36 | 37 | #ifndef VIRGIL_SDK_UTIL_JSON_KEY_H 38 | #define VIRGIL_SDK_UTIL_JSON_KEY_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace sdk { 44 | namespace util { 45 | /** 46 | * @brief This class holds string constants of Json keys. 47 | * 48 | * @note This class belongs to the **private** API 49 | */ 50 | class JsonKey { 51 | public: 52 | //! @cond Doxygen_Suppress 53 | static const std::string Signer; 54 | static const std::string Snapshot; 55 | static const std::string Signature; 56 | static const std::string Signatures; 57 | static const std::string PublicKey; 58 | static const std::string ContentSnapshot; 59 | static const std::string PreviousCardId; 60 | static const std::string CreatedAt; 61 | static const std::string Identity; 62 | static const std::string Version; 63 | static const std::string Code; 64 | static const std::string Message; 65 | 66 | static const std::string Algorithm; 67 | static const std::string Type; 68 | static const std::string ContentType; 69 | static const std::string KeyIdentifier; 70 | 71 | static const std::string AppId; 72 | static const std::string IdentityJWT; 73 | static const std::string IssuedAt; 74 | static const std::string ExpiresAt; 75 | static const std::string AdditionalData; 76 | 77 | //! @endcond 78 | 79 | /*! 80 | * @brief Forbid creation. 81 | * 82 | */ 83 | JsonKey() = delete; 84 | }; 85 | } 86 | } 87 | } 88 | 89 | #endif /* VIRGIL_SDK_UTIL_JSON_KEY_H */ --------------------------------------------------------------------------------