Compare commits

...

2 Commits

Author SHA1 Message Date
Gulliver
fa746dd925 extended README.md to doxygen mainpage and add to doxygen build
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-31 14:36:37 +01:00
Gulliver
0e4c094eed corrected name RequestCDD to RequestCDDC 2022-12-31 14:36:37 +01:00
6 changed files with 132 additions and 57 deletions

View File

@ -14,7 +14,7 @@ else()
add_compile_options(-Wall -Wextra -pedantic) add_compile_options(-Wall -Wextra -pedantic)
endif() endif()
project(oc-mint VERSION 0.0.1 LANGUAGES CXX) project(oc-issuer VERSION 0.0.2 LANGUAGES CXX)
include(FetchContent) include(FetchContent)
@ -64,10 +64,10 @@ find_package(Doxygen
REQUIRED dot REQUIRED dot
OPTIONAL_COMPONENTS mscgen dia) OPTIONAL_COMPONENTS mscgen dia)
set(DOXYGEN_HAVE_DOT YES) set(DOXYGEN_HAVE_DOT YES)
doxygen_add_docs( doxygen_add_docs( doc
doc README.md
src src
COMMENT "Generate documentation" COMMENT "Generate documentation"
) )
# build common library # build common library
@ -76,8 +76,8 @@ add_library(oc-mint-lib ${LIB_SOURCES})
target_link_libraries(oc-mint-lib PUBLIC Crow::Crow) target_link_libraries(oc-mint-lib PUBLIC Crow::Crow)
target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src) target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src)
add_executable(oc-mint src/main.cpp) add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(oc-mint PRIVATE oc-mint-lib INTERFACE tl::expected::expected) target_link_libraries(${PROJECT_NAME} PRIVATE oc-mint-lib INTERFACE tl::expected::expected)
## these are unittests that can be run on any platform ## these are unittests that can be run on any platform
add_executable(tests test/test_big_int.cpp test/test.cpp) add_executable(tests test/test_big_int.cpp test/test.cpp)

View File

@ -1,11 +1,40 @@
![build](https://github.com/OpenCoin/oc-mint-cpp/actions/workflows/cmake.yaml/badge.svg) opencoin-issuer-cpp - a C++ OpenCoin Issuer REST-API implementation {#mainpage}
=============================================================
# oc mint sample ![build](https://github.com/OpenCoin/opencoin-issuer-cpp/actions/workflows/cmake.yaml/badge.svg)
[![Documentation](https://github.com/OpenCoin/opencoin-issuer-cpp/actions/workflows/doxygen-gh-pages.yml/badge.svg)](https://github.com/OpenCoin/opencoin-issuer-cpp/actions/workflows/doxygen-gh-pages.yml)
this is a C++ implementation of the opencoin protocol # opencoin issuer
as mapping to some kind of REST interface
actually it is a work in progress. this is a C++ implementation of the [opencoin protocol](https://opencoin.org/0.4/OpenCoin.html)
done as mapping to some kind of REST interface.
As all issuer related interactions of the protocol follows a request/response mechanism we are able to map all of them to Http-Requests.
We decided to use POST-Requests in all cases,
as the protocol uses JSON-formatted messages for requests.
The following table gives an overview of the mapping of requests to URLs:
| Request | URL | Response | C++ Interface Method |
|:------------------|:-------------|:------------------------------|:---------------------------------------------------|
| RequestCDDCSerial | /cddc/serial | ResponseCDDCSerial | cdd.cdd_serial of Model::getCurrentCDDC() |
| RequestCDDC | /cddc | ResponseCDDC | Model::getCurrentCDDC() |
| RequestMKCs | /mkcs | ResponseMKCs | Model::getMKCs |
| RequestMint | /mint | ResponseMint | Model::mint |
| RequestRenew | /renew | ResponseMint or ResponseDelay | ? |
| RequestResume | /resume | ResponseMint or ResponseDelay | ? |
| RequestRedeem | /redeem | ResponseRedeem | Model::redeem |
actually the implementation is a work in progress.
## TODO
- [ ] select crypto library
+ https://en.wikipedia.org/wiki/Comparison_of_cryptography_libraries
+ [ ] blinding utilizing crypto++
+ [ ] integrate session and login to make transactions account based
+ [ ] bookkeeping for accounts
## Protocol Questions ## Protocol Questions
@ -14,11 +43,6 @@ or also the key?
+ the weighted URL as array has a different js encoding as other elements + the weighted URL as array has a different js encoding as other elements
+ Clarify PSS usage (see https://crypto.stackexchange.com/questions/12707/usability-of-padding-scheme-in-blinded-rsa-signature) + Clarify PSS usage (see https://crypto.stackexchange.com/questions/12707/usability-of-padding-scheme-in-blinded-rsa-signature)
## TODO
+ [ ] bigint type for big integers encoded as string
+ [ ] blinding utilizing crypto++
### Blinding Notes ### Blinding Notes
https://stackoverflow.com/questions/47860570/how-to-create-and-verify-blind-rsa-signatures-with-crypto https://stackoverflow.com/questions/47860570/how-to-create-and-verify-blind-rsa-signatures-with-crypto

View File

@ -29,11 +29,11 @@ int main() {
CROW_ROUTE(app, "/cddc/serial") CROW_ROUTE(app, "/cddc/serial")
.methods(crow::HTTPMethod::POST)([&model](const crow::request &request) { .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestCDDSerial::from_string(request.body); auto req = RequestCDDCSerial::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
ResponseCDDSerial res; ResponseCDDCSerial res;
res.message_reference = req->message_reference; res.message_reference = req->message_reference;
auto cddc = model->getCurrentCDDC(); auto cddc = model->getCurrentCDDC();

View File

@ -104,7 +104,7 @@ crow::json::wvalue Response::to_json() const {
return r; return r;
} }
crow::json::wvalue ResponseCDDSerial::to_json() const { crow::json::wvalue ResponseCDDCSerial::to_json() const {
crow::json::wvalue r = Response::to_json(); crow::json::wvalue r = Response::to_json();
TO_JSON(cdd_serial); TO_JSON(cdd_serial);
@ -112,8 +112,8 @@ crow::json::wvalue ResponseCDDSerial::to_json() const {
return r; return r;
} }
tl::expected<RequestCDDSerial, eError> tl::expected<RequestCDDCSerial, eError>
RequestCDDSerial::from_string(const std::string &str) { RequestCDDCSerial::from_string(const std::string &str) {
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
@ -122,7 +122,7 @@ RequestCDDSerial::from_string(const std::string &str) {
} else if (json["type"] != "request cdd serial") { } else if (json["type"] != "request cdd serial") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else { } else {
RequestCDDSerial r; RequestCDDCSerial r;
r.message_reference = json["message_reference"].u(); r.message_reference = json["message_reference"].u();
return r; return r;
} }

View File

@ -25,30 +25,36 @@ struct WeightedUrl {
crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
/** currency description document */ /** @brief currency description document
*
* this structure describes a currency based on opencoin protocol.
* It can be converted to json to provide the specified currency
* description document.
*/
struct CDD { struct CDD {
std::string additional_info; std::string additional_info;
time_t cdd_expiry_date;//: 2023-07-22T15:45:53.164685 time_t cdd_expiry_date; /// expiry date of this document (e.g.
std::string cdd_location;//: https://opencent.org, ///2023-07-22T15:45:53.164685)
size_t cdd_serial;//: 1, std::string cdd_location; /// URL of location of this document (e.g
time_t cdd_signing_date;//: 2022-07-22T15:45:53.164685, ///https://opencent.org)
size_t currency_divisor;//: 100, size_t cdd_serial; /// serial number of currency description document
std::string currency_name;//: OpenCent, time_t cdd_signing_date; /// date of signing this document (e.g.
std::vector<unsigned> denominations;//: [1, 2, 5], ///2022-07-22T15:45:53.164685)
BigInt id;//: 23ed956e629ba35f0002eaf833ea436aea7db5c2, size_t currency_divisor; /// divisor used for coins of this currency
std::string currency_name; /// name of the currency (e.g. OpenCent)
std::vector<unsigned>
denominations; /// the available denominations of this currency
BigInt id; /// an identity for this currency
std::vector<WeightedUrl> info_service; std::vector<WeightedUrl> info_service;
/* eCipherSuite*/ std::string issuer_cipher_suite; //: RSA-SHA256-PSS-CHAUM82, /* eCipherSuite*/
PublicKey std::string issuer_cipher_suite; /// the cipher suite used for this currencey
issuer_public_master_key; //: { /// (currently only RSA-SHA256-PSS-CHAUM82
// modulus: /// is supported)
// daaa63ddda38c189b8c49020c8276adbe0a695685a..., PublicKey issuer_public_master_key; /// the public key of this currency
// public_exponent: 65537,
// type: rsa public key
//},
std::vector<WeightedUrl> mint_service; std::vector<WeightedUrl> mint_service;
std::string protocol_version; //: https://opencoin.org/1.0, std::string protocol_version; // e.g. https://opencoin.org/1.0
std::vector<WeightedUrl> redeem_service; std::vector<WeightedUrl> redeem_service;
std::vector<WeightedUrl> renew_service; std::vector<WeightedUrl> renew_service;
@ -100,14 +106,14 @@ struct Response {
virtual crow::json::wvalue to_json() const; virtual crow::json::wvalue to_json() const;
}; };
struct RequestCDDSerial { struct RequestCDDCSerial {
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
static tl::expected<RequestCDDSerial, eError> static tl::expected<RequestCDDCSerial, eError>
from_string(const std::string &str); from_string(const std::string &str);
}; };
struct ResponseCDDSerial : Response { struct ResponseCDDCSerial : Response {
unsigned int cdd_serial; unsigned int cdd_serial;
crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
@ -237,18 +243,63 @@ class Model {
public: public:
virtual ~Model(){}; virtual ~Model(){};
/**
* return the CurrencyDocumentDescription certifikate for a specific
* serial version number of it.
* [see spec](https://opencoin.org/0.4/schemata.html#cddc)
* @return returns a pointer to the CDDC if successful, false otherwise
*/
virtual tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) = 0; virtual tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) = 0;
virtual tl::expected<CDDC *, bool> getCurrentCDDC() = 0;
/**
* return the CurrencyDocumentDescription certifikate
* [see spec](https://opencoin.org/0.4/schemata.html#cddc)
* @return returns a pointer to the CDDC if successful, false otherwise
*/virtual tl::expected<CDDC *, bool> getCurrentCDDC() = 0;
/**
* return the MintKey certificates for a given list of denominations
* and mint key ids
*
* @param denominations
* @param mint_key_ids
*
* @return mint key certificates for given denominations and mint_key_ids
*/
virtual const std::vector<MintKeyCert> virtual const std::vector<MintKeyCert>
getMKCs(const std::vector<unsigned int> &denominations, getMKCs(const std::vector<unsigned int> &denominations,
const std::vector<BigInt> &mint_key_ids) = 0; const std::vector<BigInt> &mint_key_ids) = 0;
/**
* returns the vector of blind signatures for a given vector of blinds
*
* @param transaction_reference reference to a transaction (send from client)
* @param blinds the vector of blinds to sign
*
* @return
*/
virtual std::vector<BlindSignature> virtual std::vector<BlindSignature>
mint(std::string const& transaction_reference, mint(std::string const& transaction_reference,
const std::vector<Blind> &blinds) = 0; const std::vector<Blind> &blinds) = 0;
/**
* redeem valid coins into real money
*
* @param coins the coins to redeem
*
* @return true if successful, false on error
*/
virtual bool redeem(const std::vector<Coin> &coins) = 0; virtual bool redeem(const std::vector<Coin> &coins) = 0;
/**
* factory function returning a concrete backend for Opencoin API handling.
* based on backend_name a concrete backend will be returned
* or in case of error null.
* @param backend_name
*
* @return pointer to backend instance or null on invalid backend name
*/
static std::unique_ptr<Model> getModel(const std::string &backend_name); static std::unique_ptr<Model> getModel(const std::string &backend_name);
private: private:

View File

@ -15,32 +15,32 @@ TEST_CASE( "PublicKey::to_json", "[to_json]" ) {
REQUIRE( json.keys().size() == 3 ); REQUIRE( json.keys().size() == 3 );
} }
TEST_CASE("RequestCDDSerial::from_string", "[from_string]") { TEST_CASE("RequestCDDCSerial::from_string", "[from_string]") {
// good case // good case
std::string good = "{" std::string good = "{"
"\"message_reference\": 100000," "\"message_reference\": 100000,"
"\"type\": \"request cdd serial\"" "\"type\": \"request cdd serial\""
"}"; "}";
auto res = RequestCDDSerial::from_string(good); auto res = RequestCDDCSerial::from_string(good);
REQUIRE(res.has_value() == true); REQUIRE(res.has_value() == true);
REQUIRE(res->message_reference == 100000); REQUIRE(res->message_reference == 100000);
// bad cases // bad cases
res = RequestCDDSerial::from_string(""); res = RequestCDDCSerial::from_string("");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid type // invalid type
res = RequestCDDSerial::from_string("{" res = RequestCDDCSerial::from_string("{"
"\"message_reference\": 100000," "\"message_reference\": 100000,"
"\"type\": \"request something wrong\"" "\"type\": \"request something wrong\""
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid attribute name // invalid attribute name
res = RequestCDDSerial::from_string("{" res = RequestCDDCSerial::from_string("{"
"\"x_message_reference\": 100000," "\"x_message_reference\": 100000,"
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
} }