├── .ci ├── common │ ├── get_log_dir.sh │ └── utils.sh ├── config │ ├── cdf.conf │ ├── ctf.json │ ├── dealer-in.json │ ├── dealer-out.json │ ├── hss.json │ └── kms.json └── install │ ├── hss-auto-install.txt │ ├── hss │ ├── hss-auto-install.txt │ ├── install_hss.sh │ └── install_hss_config.sh │ ├── install_config.sh │ ├── sgx-auto-install.txt │ └── sgx │ ├── c3po-submodule-auto-install.txt │ ├── install_sgx.sh │ ├── install_sgx_config.sh │ └── sgx-auto-install.txt ├── .fossa.yml ├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── Makefile ├── README.txt ├── REFERENCE.md ├── RELEASE_NOTES.txt ├── VERSION ├── cdf ├── .gitignore ├── Makefile ├── README.md ├── README.txt ├── bin │ └── make_certs.sh ├── conf │ └── cdf.conf ├── include │ ├── cdf.h │ ├── options.h │ ├── rf.h │ └── rf_impl.h └── src │ ├── cdf.cpp │ ├── main.cpp │ ├── options.cpp │ ├── rf.cpp │ └── rf_impl.cpp ├── cli ├── .gitignore ├── README.txt ├── autocomplete.sh ├── c3pocli │ ├── __init__.py │ └── c3pocli.py ├── requirements.txt ├── setup.cfg └── setup.py ├── ctf ├── .gitignore ├── Makefile ├── README.md ├── README.txt ├── bin │ └── make_certs.sh ├── certs │ ├── cert.pem │ └── key.pem ├── conf │ ├── ctf.conf │ ├── ctf.json │ └── oss.json ├── docs │ └── logs_c3poctf.md ├── include │ ├── common_def.h │ ├── csvfile.h │ ├── csvproc.h │ ├── csvtrack.h │ ├── logger.h │ ├── msg_event.h │ ├── options.h │ ├── rf.h │ ├── rf_impl.h │ ├── sdn.h │ ├── sgx_crt_info.h │ ├── sslcommhndlr.h │ ├── statsctf.h │ └── tests.h ├── src │ ├── csvfile.cpp │ ├── csvproc.cpp │ ├── csvtrack.cpp │ ├── logger.cpp │ ├── main.cpp │ ├── msg_event.cpp │ ├── options.cpp │ ├── rf.cpp │ ├── rf_impl.cpp │ ├── sdn.cpp │ ├── sgx_crt_info.c │ ├── sslcommhndlr.cpp │ ├── statsctf.cpp │ └── tests.cpp └── test │ └── cdr_170615_110717.csv ├── db_docs ├── Cassandra_Initialize_Schema.docx ├── Cassandra_Install.docx ├── Cassandra_Single_Node_Install.docx ├── DataStax_Agent_Install.docx ├── OpsCenter_Install.docx ├── PCRF_Schema.md ├── Subscriber_Provisioning.docx ├── data_provisioning_mme.sh ├── data_provisioning_users.py ├── data_provisioning_users.sh ├── policy_membership_change.md └── subscriber_policy_change.md ├── hss ├── .gitignore ├── Makefile ├── README.txt ├── bin │ └── make_certs.sh ├── conf │ ├── acl.conf │ ├── hss.conf │ ├── hss.json │ └── oss.json ├── db │ └── oai_db.cql ├── hssperf │ ├── .gitignore │ ├── Makefile │ ├── bin │ │ └── make_certs.sh │ ├── conf │ │ ├── hssperf.conf │ │ └── hssperf.json │ ├── include │ │ ├── airtest.h │ │ ├── attachtest.h │ │ ├── hssperf.h │ │ ├── logger.h │ │ ├── options.h │ │ ├── s6as6d.h │ │ ├── s6as6d_impl.h │ │ └── ulrtest.h │ └── src │ │ ├── airtest.cpp │ │ ├── attachtest.cpp │ │ ├── hssperf.cpp │ │ ├── logger.cpp │ │ ├── main.cpp │ │ ├── options.cpp │ │ ├── s6as6d.cpp │ │ ├── s6as6d_impl.cpp │ │ └── ulrtest.cpp ├── include │ ├── common_def.h │ ├── dataaccess.h │ ├── fdhss.h │ ├── hssStatsPromClient.h │ ├── logger.h │ ├── msg_event.h │ ├── options.h │ ├── portal_config.h │ ├── resthandler.h │ ├── s6as6d.h │ ├── s6as6d_impl.h │ ├── s6c.h │ ├── s6c_impl.h │ ├── s6t.h │ ├── s6t_impl.h │ ├── statshss.h │ ├── timer.h │ ├── util.h │ └── worker.h ├── logs │ └── .gitignore ├── prometheus │ ├── autocodegen.py │ ├── hssStats.json │ └── hssStats.json.license ├── smsrouter │ ├── .gitignore │ ├── Makefile │ ├── bin │ │ └── make_certs.sh │ ├── conf │ │ ├── sms.conf │ │ └── sms.json │ ├── include │ │ ├── logger.h │ │ ├── options.h │ │ ├── s6c.h │ │ ├── s6c_impl.h │ │ ├── sgd.h │ │ ├── sgd_impl.h │ │ └── sms.h │ └── src │ │ ├── logger.cpp │ │ ├── main.cpp │ │ ├── options.cpp │ │ ├── s6c.cpp │ │ ├── s6c_impl.cpp │ │ ├── sgd.cpp │ │ ├── sgd_impl.cpp │ │ └── sms.cpp └── src │ ├── dataaccess.cpp │ ├── fdhss.cpp │ ├── hssStatsPromClient.cpp │ ├── logger.cpp │ ├── main.cpp │ ├── msg_event.cpp │ ├── options.cpp │ ├── portal_config.cpp │ ├── resthandler.cpp │ ├── s6as6d.cpp │ ├── s6as6d_impl.cpp │ ├── s6c.cpp │ ├── s6c_impl.cpp │ ├── s6t.cpp │ ├── s6t_impl.cpp │ ├── statshss.cpp │ ├── util.cpp │ └── worker.cpp ├── hssgtw ├── .gitignore ├── Makefile ├── README.md ├── README.txt ├── conf │ ├── hssgtw.json │ └── user-imsi-schema.json ├── etc │ ├── data_provisioning_users_r1.01.sh │ ├── delete_imsi.sh │ ├── insert_imsi.sh │ └── update_imsi.sh ├── include │ ├── db.h │ ├── jsonvalidator.h │ ├── options.h │ ├── provisionhandler.h │ └── restclient.h └── src │ ├── db.cpp │ ├── jsonvalidator.cpp │ ├── main.cpp │ ├── options.cpp │ ├── provisionhandler.cpp │ └── restclient.cpp ├── hsssec ├── .gitignore ├── Makefile ├── README.md ├── README.txt ├── bin │ └── make_certs.sh ├── include │ ├── access_restriction.h │ ├── auc.h │ ├── aucpp.h │ ├── conversion.h │ ├── hss_config.h │ └── log.h └── src │ ├── access_restriction.c │ ├── aucpp.c │ ├── conversion.c │ ├── fx.c │ ├── kdf.c │ ├── random.c │ ├── rijndael.c │ └── sequence_number.c ├── install.sh ├── install_builddeps.sh ├── install_rundeps.sh ├── patches └── pistache.patch.1.txt ├── pcrf ├── .gitignore ├── Makefile ├── README.md ├── README.txt ├── bin │ └── make_certs.sh ├── conf │ ├── oss.json │ ├── pcrf.conf │ └── pcrf.json ├── include │ ├── apn.h │ ├── bearer.h │ ├── chronos.h │ ├── common_def.h │ ├── dataaccess.h │ ├── diaconst.h │ ├── endpoint.h │ ├── gx.h │ ├── gx_impl.h │ ├── logger.h │ ├── msg_event.h │ ├── options.h │ ├── pcrf.h │ ├── rule.h │ ├── rx.h │ ├── rx_impl.h │ ├── sd.h │ ├── sd_impl.h │ ├── session.h │ ├── st.h │ ├── st_impl.h │ ├── statpcrf.h │ └── subscriber.h ├── pcef │ ├── .gitignore │ ├── Makefile │ ├── bin │ │ └── make_certs.sh │ ├── conf │ │ ├── pcef.conf │ │ └── pcef.json │ ├── include │ │ ├── gx.h │ │ ├── gx_impl.h │ │ ├── logger.h │ │ ├── options.h │ │ ├── pcef.h │ │ └── spdlog │ │ │ └── tweakme.h │ └── src │ │ ├── gx.cpp │ │ ├── gx_impl.cpp │ │ ├── logger.cpp │ │ ├── main.cpp │ │ ├── options.cpp │ │ └── pcef.cpp ├── pcrf_cassandra.sql ├── src │ ├── apn.cpp │ ├── bearer.cpp │ ├── chronos.cpp │ ├── dataaccess.cpp │ ├── endpoint.cpp │ ├── gx.cpp │ ├── gx_impl.cpp │ ├── logger.cpp │ ├── main.cpp │ ├── msg_event.cpp │ ├── options.cpp │ ├── pcrf.cpp │ ├── rule.cpp │ ├── rx.cpp │ ├── rx_impl.cpp │ ├── sd.cpp │ ├── sd_impl.cpp │ ├── session.cpp │ ├── st.cpp │ ├── st_impl.cpp │ ├── statpcrf.cpp │ └── subscriber.cpp ├── tdf │ ├── .gitignore │ ├── Makefile │ ├── bin │ │ └── make_certs.sh │ ├── conf │ │ ├── tdf.conf │ │ └── tdf.json │ ├── include │ │ ├── logger.h │ │ ├── options.h │ │ ├── sd.h │ │ ├── sd_impl.h │ │ └── tdf.h │ └── src │ │ ├── logger.cpp │ │ ├── main.cpp │ │ ├── options.cpp │ │ ├── sd.cpp │ │ ├── sd_impl.cpp │ │ └── tdf.cpp └── tssf │ ├── .gitignore │ ├── Makefile │ ├── bin │ └── make_certs.sh │ ├── conf │ ├── tssf.conf │ └── tssf.json │ ├── include │ ├── logger.h │ ├── options.h │ ├── st.h │ ├── st_impl.h │ └── tssf.h │ └── src │ ├── logger.cpp │ ├── main.cpp │ ├── options.cpp │ ├── st.cpp │ ├── st_impl.cpp │ └── tssf.cpp ├── sgxcdr ├── README.md ├── dealer │ ├── App │ │ ├── dealer.cpp │ │ ├── ias-ra.c │ │ ├── options.cpp │ │ ├── sgxsdk-ra-attester_u.c │ │ └── utils.cpp │ ├── Enclave │ │ ├── CMakeLists.txt_ │ │ ├── Enclave.config.xml │ │ ├── Enclave.edl │ │ ├── Enclave.lds │ │ ├── Enclave_private.pem │ │ ├── ca_bundle.h │ │ ├── certs │ │ │ └── .gitignore │ │ ├── config_client.h │ │ ├── config_srv.h │ │ ├── crypto.cpp │ │ ├── crypto.h │ │ ├── ecalls.cpp │ │ ├── embed_cert.args │ │ ├── embed_cert.py │ │ ├── helper.cpp │ │ ├── helper.h │ │ ├── kms_client.cpp │ │ ├── kms_client.h │ │ ├── mbedtls-ra-attester.c │ │ ├── mbedtls_sgx.edl │ │ ├── memmem.c │ │ ├── memmem.cpp │ │ ├── memmem.h │ │ ├── ra-challenger.cpp │ │ ├── sgxsdk-ra-attester_t.c │ │ ├── ssl_conn_hdlr.cpp │ │ └── ssl_conn_hdlr.h │ ├── Makefile │ ├── README.txt │ ├── certs │ │ ├── csr_details.txt │ │ ├── ias-client-cert.pem │ │ ├── ias-client-key.pem │ │ ├── ias-leaf-cert.der │ │ ├── ias-leaf-cert.pem │ │ ├── ias-root-cert.der │ │ ├── ias-root-cert.pem │ │ ├── server-cert.pem │ │ ├── server-pubkey.der │ │ └── server.csr │ ├── conf │ │ └── dealer.json │ ├── deps │ │ ├── mbedtls_sgx_ra_postbuild.patch │ │ ├── mbedtls_sgx_ra_prebuild.patch │ │ └── sgx_zmq │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── sgx_tcdr │ │ │ ├── Makefile │ │ │ ├── include │ │ │ │ ├── sgx_tcdr.edl │ │ │ │ └── sgx_tcdr.h │ │ │ ├── sgx_t_static.mk │ │ │ ├── sgx_u.mk │ │ │ └── trusted │ │ │ │ └── sgx_tcdr.c │ │ │ └── sgx_ucdr │ │ │ ├── Makefile │ │ │ ├── obj │ │ │ └── .gitkeep │ │ │ ├── uprotected_cdr.c │ │ │ └── uprotected_cdr.h │ ├── include │ │ ├── Utils.h │ │ ├── ias-ra.h │ │ ├── mbedtls-ra-attester.h │ │ ├── memmem.h │ │ ├── options.h │ │ ├── ra-challenger.h │ │ ├── ra.h │ │ └── ssl_context.h │ └── install.sh ├── kms │ ├── App │ │ ├── ias-ra.c │ │ ├── kms.cpp │ │ ├── options.cpp │ │ ├── sgxsdk-ra-attester_u.c │ │ └── utils.cpp │ ├── Enclave │ │ ├── Enclave.config.xml │ │ ├── Enclave.edl │ │ ├── Enclave.lds │ │ ├── Enclave_private.pem │ │ ├── ca_bundle.h │ │ ├── certs │ │ │ └── .gitignore │ │ ├── config_client.h │ │ ├── config_srv.h │ │ ├── ecalls.cpp │ │ ├── embed_cert.args │ │ ├── embed_cert.py │ │ ├── key_store.cpp │ │ ├── key_store.h │ │ ├── mbedtls-ra-attester.c │ │ ├── mbedtls_sgx.edl │ │ ├── memmem.cpp │ │ ├── memmem.h │ │ ├── ra-challenger.cpp │ │ ├── sgxsdk-ra-attester_t.c │ │ ├── ssl_conn_hdlr.cpp │ │ └── ssl_conn_hdlr.h │ ├── Makefile │ ├── README.txt │ ├── certs │ │ ├── csr_details.txt │ │ ├── ias-client-cert.pem │ │ ├── ias-client-key.pem │ │ ├── ias-leaf-cert.der │ │ ├── ias-leaf-cert.pem │ │ ├── ias-root-cert.der │ │ ├── ias-root-cert.pem │ │ ├── server-cert.pem │ │ ├── server-pubkey.der │ │ └── server.csr │ ├── conf │ │ └── kms.json │ ├── include │ │ ├── Utils.h │ │ ├── ias-ra.h │ │ ├── mbedtls-ra-attester.h │ │ ├── memmem.h │ │ ├── options.h │ │ ├── ra-challenger.h │ │ ├── ra.h │ │ └── ssl_context.h │ ├── install.sh │ └── store │ │ └── .gitignore └── router │ ├── README.txt │ ├── cdr_slave_streamer_device.py │ ├── in_queue_router.py │ ├── install.sh │ ├── out_queue_router.py │ └── start_and__monitor.py └── util ├── .gitignore ├── Makefile ├── README.md ├── README.txt ├── include ├── cdnscache.h ├── cdnsparser.h ├── cdnsquery.h ├── cdnsrecord.h ├── epc.h ├── fd.h ├── fdjson.h ├── satomic.h ├── scassandra.h ├── sdir.h ├── serror.h ├── sfile.h ├── slogger.h ├── soss.h ├── spath.h ├── squeue.h ├── sstats.h ├── ssync.h ├── ssyslog.h ├── sthread.h ├── stime.h ├── stimer.h └── sutility.h └── src ├── cdnscache.cpp ├── cdnsparser.cpp ├── epc.cpp ├── fd.cpp ├── fdjson.cpp ├── scassandra.cpp ├── sdir.cpp ├── sfile.cpp ├── slogger.cpp ├── spath.cpp ├── squeue.cpp ├── sstats.cpp ├── ssync.cpp ├── ssyslog.cpp ├── sthread.cpp ├── stime.cpp ├── stimer.cpp └── sutility.cpp /.ci/common/get_log_dir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-present Open Networking Foundation 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | set -o nounset 8 | set -o errexit 9 | 10 | INSTALL_CI_PATH=$1 11 | APP=$2 12 | 13 | cd "$(dirname "${BASH_SOURCE[0]}")" 14 | source "${INSTALL_CI_PATH}"/c3po/.ci/install/"${APP}"/install_"${APP}"_config.sh 15 | 16 | echo "${LOG_DIR}" 17 | -------------------------------------------------------------------------------- /.ci/common/utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-present Open Networking Foundation 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | set -o nounset 8 | set -o errexit 9 | 10 | clean_all_logs() 11 | { 12 | # Clean all logs 13 | local LOG_DIR=$1 14 | 15 | if [ ! -d "${LOG_DIR}" ]; then mkdir -p "${LOG_DIR}"; fi 16 | rm -fr "${LOG_DIR:?}"/* 17 | } 18 | 19 | 20 | log_step() 21 | { 22 | local ARG=$1 23 | local LENGTH=${#ARG} 24 | printf "\n%s\n" "${ARG}" 25 | # shellcheck disable=SC2046 26 | printf "%.s-" $(seq 1 "${LENGTH}") 27 | printf "\n" 28 | } 29 | 30 | 31 | update_ca_bundle_keys() 32 | { 33 | local INSTALL_PATH=$1 34 | local MRENCLAVE=$2 35 | local MRSIGNER=$3 36 | cd "${INSTALL_PATH}"/c3po/sgxcdr/kms/Enclave 37 | sed -i '0,/"",/{s/"",/"'"${MRENCLAVE}"'",/}' ca_bundle.h 38 | sed -i '0,/"",/{s/"",/"'"${MRSIGNER}"'",/}' ca_bundle.h 39 | } 40 | 41 | 42 | get_sgx_dealer_keys() 43 | { 44 | local INSTALL_PATH=$1 45 | 46 | cd "${INSTALL_PATH}"/c3po/sgxcdr/dealer 47 | 48 | local OUTPUT= 49 | mapfile -t OUTPUT < <(./dealer -j conf/dealer.json -x | sed -n "s/MR.* ://p") 50 | 51 | local MRENCLAVE=${OUTPUT[0]} 52 | local MRSIGNER=${OUTPUT[1]} 53 | 54 | echo "${MRENCLAVE}" 55 | echo "${MRSIGNER}" 56 | } 57 | -------------------------------------------------------------------------------- /.ci/config/ctf.json: -------------------------------------------------------------------------------- 1 | {"common": { 2 | "fdcfg": "conf/ctf.conf", 3 | "originhost": "ctf.test3gpp.net", 4 | "originrealm": "test3gpp.net" 5 | }, 6 | "ctf": { 7 | "datapfx": "2019", 8 | "datapath": "/tmp", 9 | "archivepath": "test/data/archive", 10 | "trackpath": "test/data/tracking", 11 | "trackext": ".trk", 12 | "curext": ".cur", 13 | "skiprows": 1, 14 | "idledur": 1000, 15 | "maxacrs": 10, 16 | "savefreq": 10, 17 | "sdnmemcsvr": "10.31.14.83", 18 | "sdnmemcport": 11211, 19 | "logsize": 20, 20 | "lognumber": 5, 21 | "logname": "logs/ctf.log", 22 | "logqsize": 8192, 23 | "statlogsize": 20, 24 | "statlognumber": 5, 25 | "statlogname": "logs/ctf_stat.log", 26 | "auditlogsize": 20, 27 | "auditlognumber": 5, 28 | "auditlogname": "logs/ctf_audit.log", 29 | "statfreq": 2000, 30 | "ossport" : 9082, 31 | "certfile": "./certs/cert.pem", 32 | "isvsvn": 0, 33 | "mrenclave": "79d2efd06da712d71e7228570b3df433f564298f3dd28611738a01be68522959", 34 | "mrsigner": "63ef969cbc34ee465f277cd3c27e9b3c681d743e455f899daced1b3cf85ceb8f", 35 | "privkeyfile": "./certs/key.pem", 36 | "sgxserverip": "10.5.4.100", 37 | "sgxserverport": 444, 38 | "streamname": "0s1", 39 | "ossfile": "conf/oss.json" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.ci/config/dealer-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "maxconnections": "16", 4 | "kmsserver": "10.5.4.100", 5 | "kmsport": "8443", 6 | "keynamespace": "dealer_namespace" 7 | }, 8 | 9 | "dealer": { 10 | "runmode": "IN", 11 | "cdrhost": "10.5.4.100", 12 | "cdrport": "6789", 13 | "port": "443", 14 | "cdrpath": "./cdr", 15 | "cdrarchpath": "/tmp" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.ci/config/dealer-out.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "maxconnections": "16", 4 | "kmsserver": "10.5.4.100", 5 | "kmsport": "8443", 6 | "keynamespace": "dealer_namespace" 7 | }, 8 | 9 | "dealer": { 10 | "runmode": "OUT", 11 | "cdrhost": "10.5.4.100", 12 | "cdrport": "6790", 13 | "port": "444", 14 | "cdrpath": "./cdr", 15 | "cdrarchpath": "/tmp" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.ci/config/hss.json: -------------------------------------------------------------------------------- 1 | {"common": { 2 | "fdcfg": "conf/hss.conf", 3 | "originhost": "hss.openair4G.eur", 4 | "originrealm": "openair4G.eur" 5 | }, 6 | "hss": { 7 | "gtwhost": "*", 8 | "gtwport" : 9080, 9 | "restport" : 9081, 10 | "ossport" : 9082, 11 | "casssrv": "10.0.4.60", 12 | "cassusr": "root", 13 | "casspwd": "root", 14 | "cassdb" : "vhss", 15 | "casscoreconnections" : 2, 16 | "cassmaxconnections" : 8, 17 | "cassioqueuesize" : 32768, 18 | "cassiothreads" : 2, 19 | "randv" : true, 20 | "optkey" : "63bfa50ee6523365ff14c1f45f88737d", 21 | "reloadkey" : false, 22 | "logsize": 20, 23 | "lognumber": 5, 24 | "logname": "logs/hss.log", 25 | "logqsize": 8192, 26 | "statlogsize": 20, 27 | "statlognumber": 5, 28 | "statlogname": "logs/hss_stat.log", 29 | "auditlogsize": 20, 30 | "auditlognumber": 5, 31 | "auditlogname": "logs/hss_audit.log", 32 | "statfreq": 2000, 33 | "numworkers": 4, 34 | "concurrent": 10, 35 | "ossfile": "conf/oss.json" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.ci/config/kms.json: -------------------------------------------------------------------------------- 1 | { 2 | "kms": { 3 | "storepath": "./store", 4 | "port": "8443", 5 | "maxconnections": "16", 6 | "mrenclave": "79d2efd06da712d71e7228570b3df433f564298f3dd28611738a01be68522959", 7 | "mrsigner": "63ef969cbc34ee465f277cd3c27e9b3c681d743e455f899daced1b3cf85ceb8f" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /.ci/install/hss-auto-install.txt: -------------------------------------------------------------------------------- 1 | hss/hss-auto-install.txt -------------------------------------------------------------------------------- /.ci/install/hss/hss-auto-install.txt: -------------------------------------------------------------------------------- 1 | 3 2 | \r 3 | 4 4 | \r 5 | 6 6 | -------------------------------------------------------------------------------- /.ci/install/hss/install_hss.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-present Open Networking Foundation 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | set -o nounset 8 | set -o errexit 9 | 10 | export INSTALL_CI_PATH=$1 11 | 12 | cd "$(dirname "${BASH_SOURCE[0]}")" 13 | # shellcheck disable=SC1091 14 | source "${INSTALL_CI_PATH}"/c3po/.ci/install/hss/install_hss_config.sh 15 | # shellcheck disable=SC1091 16 | source "${INSTALL_CI_PATH}"/c3po/.ci/common/utils.sh 17 | 18 | check_process() 19 | { 20 | # Kill any running process 21 | if pgrep -xl hss; then pkill -x hss; fi 22 | } 23 | 24 | 25 | # Main 26 | 27 | # Clean log dir or create it, if needed 28 | log_step "Clean log directory ${LOG_DIR} ..." 29 | clean_all_logs "${LOG_DIR}" 30 | 31 | 32 | log_step "Check/kill processes, if any ..." 33 | check_process 34 | 35 | 36 | log_step "Install hss ..." 37 | cd "${INSTALL_CI_PATH}"/c3po && ./install.sh < "${INSTALL_CI_PATH}"/c3po/.ci/install/hss/hss-auto-install.txt 1>"${HSS_INSTALL_STDOUT_LOG}" 2>"${HSS_INSTALL_STDERR_LOG}" 38 | 39 | 40 | log_step "Make util ..." 41 | make clean WHAT=util && make WHAT=util 1>"${HSSSEC_STDOUT_LOG}" 2>"${HSSSEC_STDERR_LOG}" 42 | 43 | 44 | log_step "Make hsssec ..." 45 | make clean WHAT=hsssec && make WHAT=hsssec 1>>"${HSSSEC_STDOUT_LOG}" 2>>"${HSSSEC_STDERR_LOG}" 46 | 47 | 48 | log_step "Copy config ..." 49 | cp -f "${INSTALL_CI_PATH}"/c3po/.ci/config/hss.json "${INSTALL_CI_PATH}"/c3po/hss/conf/hss.json 50 | 51 | 52 | log_step "Make Certificates ..." 53 | cd "${INSTALL_CI_PATH}"/c3po/hss/conf && ../bin/make_certs.sh hss openair4G.eur 2>&1 54 | 55 | 56 | log_step "Make hss ..." 57 | cd "${INSTALL_CI_PATH}"/c3po 58 | make clean WHAT=hss && make WHAT=hss 1>"${HSS_STDOUT_LOG}" 2>"${HSS_STDERR_LOG}" 59 | -------------------------------------------------------------------------------- /.ci/install/hss/install_hss_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-present Open Networking Foundation 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | set -o nounset 8 | 9 | # Import common variables. 10 | cd "$(dirname "${BASH_SOURCE[0]}")" || exit 11 | source "${INSTALL_CI_PATH}"/c3po/.ci/install/install_config.sh 12 | 13 | HSS_APP="hss" 14 | export LOG_DIR=${BASE_LOG_DIR}/${HSS_APP} 15 | 16 | 17 | # Log file names. 18 | 19 | export HSS_INSTALL_STDOUT_LOG="${LOG_DIR}/hss${ACTION_INST}${STDOUT_EXT}" 20 | export HSS_INSTALL_STDERR_LOG="${LOG_DIR}/hss${ACTION_INST}${STDERR_EXT}" 21 | 22 | export HSSSEC_STDOUT_LOG="${LOG_DIR}/hsssec${ACTION_MAKE}${STDOUT_EXT}" 23 | export HSSSEC_STDERR_LOG="${LOG_DIR}/hsssec${ACTION_MAKE}${STDERR_EXT}" 24 | 25 | export HSS_STDOUT_LOG="${LOG_DIR}/hss${ACTION_MAKE}${STDOUT_EXT}" 26 | export HSS_STDERR_LOG="${LOG_DIR}/hss${ACTION_MAKE}${STDERR_EXT}" 27 | -------------------------------------------------------------------------------- /.ci/install/install_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-present Open Networking Foundation 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | set -o nounset 8 | 9 | export BASE_LOG_DIR="/var/log/cicd/install" 10 | 11 | export ACTION_INST="_install" 12 | export ACTION_MAKE="_make" 13 | 14 | export STDOUT_EXT=".stdout.log" 15 | export STDERR_EXT=".stderr.log" 16 | -------------------------------------------------------------------------------- /.ci/install/sgx-auto-install.txt: -------------------------------------------------------------------------------- 1 | sgx/sgx-auto-install.txt -------------------------------------------------------------------------------- /.ci/install/sgx/c3po-submodule-auto-install.txt: -------------------------------------------------------------------------------- 1 | 3 2 | \r 3 | 4 4 | \r 5 | 6 6 | -------------------------------------------------------------------------------- /.ci/install/sgx/install_sgx_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-present Open Networking Foundation 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | set -o nounset 8 | 9 | # Import common variables. 10 | cd "$(dirname "${BASH_SOURCE[0]}")" || exit 11 | source "${INSTALL_CI_PATH}"/c3po/.ci/install/install_config.sh 12 | 13 | SGX_APP="sgx" 14 | export LOG_DIR=${BASE_LOG_DIR}/${SGX_APP} 15 | 16 | 17 | # Log file names. 18 | 19 | export DEALER_INSTALL_STDOUT_LOG="${LOG_DIR}/dealer${ACTION_INST}${STDOUT_EXT}" 20 | export DEALER_INSTALL_STDERR_LOG="${LOG_DIR}/dealer${ACTION_INST}${STDERR_EXT}" 21 | 22 | export DEALER_STDOUT_LOG="${LOG_DIR}/dealer${ACTION_MAKE}${STDOUT_EXT}" 23 | export DEALER_STDERR_LOG="${LOG_DIR}/dealer${ACTION_MAKE}${STDERR_EXT}" 24 | 25 | export KMS_INSTALL_STDOUT_LOG="${LOG_DIR}/kms${ACTION_INST}${STDOUT_EXT}" 26 | export KMS_INSTALL_STDERR_LOG="${LOG_DIR}/kms${ACTION_INST}${STDERR_EXT}" 27 | 28 | export KMS_STDOUT_LOG="${LOG_DIR}/kms${ACTION_MAKE}${STDOUT_EXT}" 29 | export KMS_STDERR_LOG="${LOG_DIR}/kms${ACTION_MAKE}${STDERR_EXT}" 30 | 31 | export ROUTER_INSTALL_STDOUT_LOG="${LOG_DIR}/router${ACTION_INST}${STDOUT_EXT}" 32 | export ROUTER_INSTALL_STDERR_LOG="${LOG_DIR}/router${ACTION_INST}${STDERR_EXT}" 33 | 34 | export C3PO_DEPS_INSTALL_STDOUT_LOG="${LOG_DIR}/c3podeps${ACTION_INST}${STDOUT_EXT}" 35 | export C3PO_DEPS_INSTALL_STDERR_LOG="${LOG_DIR}/c3podeps${ACTION_INST}${STDERR_EXT}" 36 | 37 | export UTIL_STDOUT_LOG="${LOG_DIR}/util${ACTION_MAKE}${STDOUT_EXT}" 38 | export UTIL_STDERR_LOG="${LOG_DIR}/util${ACTION_MAKE}${STDERR_EXT}" 39 | 40 | export CTF_STDOUT_LOG="${LOG_DIR}/ctf${ACTION_MAKE}${STDOUT_EXT}" 41 | export CTF_STDERR_LOG="${LOG_DIR}/ctf${ACTION_MAKE}${STDERR_EXT}" 42 | 43 | export CDF_STDOUT_LOG="${LOG_DIR}/cdf${ACTION_MAKE}${STDOUT_EXT}" 44 | export CDF_STDERR_LOG="${LOG_DIR}/cdf${ACTION_MAKE}${STDERR_EXT}" 45 | -------------------------------------------------------------------------------- /.ci/install/sgx/sgx-auto-install.txt: -------------------------------------------------------------------------------- 1 | no 2 | /home/jenkins/sgx_test 3 | -------------------------------------------------------------------------------- /.fossa.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2019-present Open Networking Foundation 2 | # 3 | # SPDX-License-Identifier: Apache-2.0 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Generated by FOSSA CLI (https://github.com/fossas/fossa-cli) 18 | # Visit https://fossa.com to learn more 19 | 20 | # Usage: FOSSA_API_KEY=<> fossa analyze 21 | # -T is not supported at this moment from fossa side. 22 | version: 2 23 | cli: 24 | server: https://app.fossa.com 25 | fetcher: custom 26 | project: c3po 27 | analyze: 28 | modules: 29 | - name: c3po 30 | type: raw 31 | target: ../c3po 32 | path: ../c3po 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | modules/libmemcached-1.0.18/ 2 | .DS_Store 3 | .cproject 4 | .project 5 | .settings/ 6 | modules/.DS_Store 7 | .agree 8 | cscope.out 9 | modules/prometheus-cpp/ 10 | tags 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "modules/c-ares"] 2 | path = modules/c-ares 3 | url = https://github.com/c-ares/c-ares.git 4 | [submodule "modules/rapidjson"] 5 | path = modules/rapidjson 6 | url = https://github.com/miloyip/rapidjson.git 7 | [submodule "modules/cpp-driver"] 8 | path = modules/cpp-driver 9 | url = https://github.com/datastax/cpp-driver.git 10 | [submodule "modules/spdlog"] 11 | path = modules/spdlog 12 | url = https://github.com/gabime/spdlog.git 13 | [submodule "modules/pistache"] 14 | path = modules/pistache 15 | url = https://github.com/oktal/pistache.git 16 | [submodule "modules/linux-sgx"] 17 | path = modules/linux-sgx 18 | url = https://github.com/intel/linux-sgx 19 | [submodule "modules/freeDiameter"] 20 | path = modules/freeDiameter 21 | url = https://github.com/omec-project/freediameter.git 22 | [submodule "modules/prometheus-cpp"] 23 | path = modules/prometheus-cpp 24 | url = https://github.com/jupp0r/prometheus-cpp 25 | -------------------------------------------------------------------------------- /REFERENCE.md: -------------------------------------------------------------------------------- 1 | LICENSE INFORMATION 2 | 3 | This page should capture all third party software used in the project OMEC and list the license information of those components. 4 | 5 | OPENAIRINTERFACE License 6 | 7 | openinterface is covered under APACHE 2.0 license 8 | -- https://github.com/OPENAIRINTERFACE/openair-cn/tree/master/src/hss_rel14/hsssec : c3po/hsssec 9 | -- https://github.com/OPENAIRINTERFACE/openair-cn/tree/master/src/hss_rel14/util : c3po/util 10 | 11 | DPDK License 12 | 13 | DPDK Reference is covered under BSD-3 License. 14 | 15 | SSL License 16 | 17 | Reference to SSL is covered under Apache 2.0 License. 18 | -- https://tls.mbed.org/ : c3po/sgxcdr/dealer/Enclave 19 | 20 | Eclipse License 21 | 22 | Reference to Eclipse SGX is covered under BSD3/GPLv2 license. 23 | -- License : https://github.com/intel/linux-sgx/blob/master/License.txt 24 | -- License : https://github.com/intel/linux-sgx-driver/blob/master/License.txt 25 | -- https://github.com/intel/linux-sgx/tree/master/SampleCode/SampleEnclave/App : c3po/sgxcdr/kms/App 26 | -- https://github.com/intel/linux-sgx/tree/master/SampleCode/SampleEnclave/App : c3po/sgxcdr/dealer/App 27 | -------------------------------------------------------------------------------- /RELEASE_NOTES.txt: -------------------------------------------------------------------------------- 1 | Release Notes 2 | 3 | MME 4 | - created "clean" bash script 5 | - combinec "bldmme" and "bldsec" into "build" bash script 6 | - Added NOLOG and PERFORMANCE_TIMING arguments to "build" bash script 7 | which cause the NOLOG and PERFORMANCE_TIMING code level defines to 8 | be set. 9 | 10 | HSSSEC 11 | - added NODEBUG compile option to suppress runtime debug messages 12 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.1.0-dev 2 | -------------------------------------------------------------------------------- /cdf/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/cdf 3 | conf/*pem 4 | conf/demoCA 5 | -------------------------------------------------------------------------------- /cdf/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/cdf 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++14 # -Wall 13 | LFLAGS := -g -pthread -lpthread 14 | LIBS := \ 15 | ../util/lib/libc3po.a \ 16 | -lcares \ 17 | -lfdcore \ 18 | -lfdproto \ 19 | -lmemcached \ 20 | -lrt 21 | INCS := \ 22 | -I ./include \ 23 | -I $(ROOT)/util/include 24 | 25 | $(TARGET): $(OBJECTS) 26 | @echo " Linking..." 27 | @mkdir -p $(BINDIR) 28 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 29 | 30 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 31 | @mkdir -p $(BUILDDIR) 32 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 33 | 34 | clean: 35 | @echo " Cleaning..."; 36 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 37 | 38 | -include $(DEPENDS) 39 | 40 | .PHONY: clean 41 | -------------------------------------------------------------------------------- /cdf/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | C3PO: CDF Build and Run Instructions 3 | --- 4 | Perform the following procedures in order. 5 | 1. Follow the instructions located in the **_"Build and Installation Instructions for External Modules"_** provided in _{installation_root}/c3po/README.md_. Make sure these steps are complete. 6 | 2. Build the **CDF**. 7 | 8 | $ cd {installation_root}/c3po/cdf 9 | $ make 10 | 3. Update the following files with any configuration changes: 11 | + {installation_root}/c3po/cdf/conf/cdf.conf 12 | + {installation_root}/c3po/cdf/conf/cdf.json 13 | 4. If this is the first time you are running the application, create the freeDiameter certificates using the following steps. **make_certs.sh** takes two parameters, supply the diameter host name without realm and then the diameter realm. 14 | **NOTE - the diameter host and realm names must match the names set in step 3**. 15 | 16 | $ cd {installation_root}/c3po/cdf/conf 17 | $ ../bin/make_certs.sh cdf test3gpp.net 18 | 5. To run the application: 19 | 20 | $ cd ${installation_root}/c3po/cdf 21 | $ bin/cdf -j conf/cdf.json 22 | 23 | -------------------------------------------------------------------------------- /cdf/README.txt: -------------------------------------------------------------------------------- 1 | C3PO: CDF Build and Run Instructions 2 | 3 | Perform the following procedures in order. 4 | 5 | 1. Follow the instructions located in the "Build and Installation 6 | Instructions for External Modules" provided in 7 | {installation_root}/c3po/README.txt. Make sure these steps are complete. 8 | 9 | 2. Build the CDF. 10 | 11 | $ cd {installation_root}/c3po/cdf 12 | $ make 13 | 14 | 3. Update the following files with any configuration changes: 15 | 16 | {installation_root}/c3po/cdf/conf/cdf.conf 17 | {installation_root}/c3po/cdf/conf/cdf.json 18 | 19 | 4. If this is the first time you are running the application, create the 20 | freeDiameter certificates using the following steps. make_certs.sh takes 21 | two parameters, supply the diameter host name without realm and then the 22 | diameter realm. 23 | 24 | NOTE - the diameter host and realm names must match the names set in step 3 25 | 26 | $ cd {installation_root}/c3po/cdf/conf 27 | $ ../bin/make_certs.sh cdf test3gpp.net 28 | 29 | 5. To run the application: 30 | 31 | $ cd ${installation_root}/c3po/cdf 32 | $ bin/cdf -j conf/cdf.json 33 | 34 | -------------------------------------------------------------------------------- /cdf/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /cdf/include/cdf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __CDF_H 9 | #define __CDF_H 10 | 11 | #include 12 | #include "rf_impl.h" 13 | 14 | 15 | class CDF 16 | { 17 | public: 18 | CDF(); 19 | ~CDF(); 20 | 21 | bool start(); 22 | void shutdown(); 23 | 24 | void waitForShutdown(); 25 | 26 | static std::string currentTime(); 27 | 28 | private: 29 | FDEngine m_diameter; 30 | rf::Application *m_rf; 31 | 32 | 33 | }; 34 | 35 | #endif // __CDF_H 36 | -------------------------------------------------------------------------------- /cdf/include/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __OPTIONS_H 9 | #define __OPTIONS_H 10 | 11 | #include 12 | #include 13 | 14 | class Options 15 | { 16 | public: 17 | static bool parse( int argc, char **argv ); 18 | 19 | static const std::string &diameterConfiguration() { return m_diameterconfiguration; } 20 | 21 | private: 22 | static void help(); 23 | 24 | static std::string m_diameterconfiguration; 25 | }; 26 | 27 | #endif // #define __OPTIONS_H 28 | -------------------------------------------------------------------------------- /cdf/include/rf_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include "rf.h" 9 | 10 | namespace rf { 11 | 12 | // Member functions that customize the individual application 13 | class Application : public ApplicationBase 14 | { 15 | friend ACRreq; 16 | 17 | public: 18 | Application(); 19 | ~Application(); 20 | 21 | // Parameters for sendXXXreq, if present below, may be changed 22 | // based upon processing needs 23 | bool sendACRreq(FDPeer &peer); 24 | 25 | private: 26 | void registerHandlers(); 27 | 28 | ACRcmd m_cmd_acr; 29 | 30 | // the parameters for createXXXreq, if present below, may be 31 | // changed based processing needs 32 | ACRreq *createACRreq(FDPeer &peer); 33 | 34 | 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cdf/src/cdf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "cdf.h" 14 | #include "options.h" 15 | 16 | CDF::CDF() 17 | { 18 | m_rf = NULL; 19 | } 20 | 21 | CDF::~CDF() 22 | { 23 | } 24 | 25 | bool CDF::start() 26 | { 27 | bool result = true; 28 | 29 | try 30 | { 31 | // set the freeDiameter config file 32 | m_diameter.setConfigFile( Options::diameterConfiguration().c_str() ); 33 | 34 | // start diameter 35 | std::cout << "Starting Diameter" << std::endl; 36 | result = m_diameter.init(); 37 | 38 | if ( result ) 39 | { 40 | // create the accounting application object 41 | std::cout << "Creating Appication object" << std::endl; 42 | m_rf = new rf::Application(); 43 | 44 | // advertise support for the accounting application 45 | m_diameter.advertiseSupport( m_rf->getDict().app(), 0, 1 ); 46 | result &= m_diameter.start(); 47 | } 48 | } 49 | catch ( FDException &e ) 50 | { 51 | std::cout << CDF::currentTime() << " - EXCEPTION - " << e.what() << std::endl; 52 | result = false; 53 | } 54 | 55 | return result; 56 | } 57 | 58 | void CDF::shutdown() 59 | { 60 | m_diameter.uninit( false ); 61 | } 62 | 63 | void CDF::waitForShutdown() 64 | { 65 | m_diameter.waitForShutdown(); 66 | } 67 | 68 | std::string CDF::currentTime() 69 | { 70 | time_t t = time( NULL ); 71 | struct tm *now = localtime( &t ); 72 | std::stringstream ss; 73 | 74 | ss << (now->tm_year + 1900) << '-' 75 | << (now->tm_mon + 1) << '-' 76 | << (now->tm_mday) << ' ' 77 | << now->tm_hour << ':' 78 | << now->tm_min << ':' 79 | << now->tm_sec; 80 | 81 | return ss.str(); 82 | } 83 | -------------------------------------------------------------------------------- /cli/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | c3pocli.egg-info/* 3 | c3pocli/__pycache__/* 4 | venv/* 5 | -------------------------------------------------------------------------------- /cli/autocomplete.sh: -------------------------------------------------------------------------------- 1 | _c3pocli_completion() { 2 | COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ 3 | COMP_CWORD=$COMP_CWORD \ 4 | _C3POCLI_COMPLETE=complete $1 ) ) 5 | return 0 6 | } 7 | 8 | complete -F _c3pocli_completion -o default c3pocli; 9 | 10 | -------------------------------------------------------------------------------- /cli/c3pocli/__init__.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright 2019-present Open Networking Foundation 3 | SPDX-License-Identifier: Apache-2.0 4 | ''' 5 | -------------------------------------------------------------------------------- /cli/requirements.txt: -------------------------------------------------------------------------------- 1 | -e . -------------------------------------------------------------------------------- /cli/setup.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/cli/setup.cfg -------------------------------------------------------------------------------- /cli/setup.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright 2019-present Open Networking Foundation 3 | SPDX-License-Identifier: Apache-2.0 4 | ''' 5 | from setuptools import setup 6 | import os 7 | 8 | VERSION = '0.0.0' 9 | 10 | 11 | setup( 12 | name='c3pocli', 13 | packages=['c3pocli'], 14 | entry_points={ 15 | 'console_scripts': [ 16 | 'c3pocli = c3pocli.c3pocli:c3pocli' 17 | ] 18 | }, 19 | install_requires=['Click', 'requests'], 20 | description='c3pocli util', 21 | version=VERSION, 22 | author='GSLab', 23 | author_email='javier.conde@gslab.com', 24 | keywords=['c3po', 'cli', 'gslab'] 25 | ) 26 | -------------------------------------------------------------------------------- /ctf/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | cert_mme/* 3 | demoCA/* 4 | bin/ctf 5 | gmon.out 6 | out 7 | test.csv 8 | tracktest 9 | tracktest2 10 | conf/*pem 11 | conf/demoCA 12 | test/archive/ 13 | test/data/ 14 | test/tracking/ 15 | -------------------------------------------------------------------------------- /ctf/Makefile: -------------------------------------------------------------------------------- 1 | #SGX_CDR = 1 Build CTF with SGX 2 | #SGX_CDR = 0 Build CTF without SGX 3 | 4 | SGX_CDR ?= 0 5 | SGX_CDR_LIVE ?= 0 6 | 7 | ifeq ($(SGX_CDR), 1) 8 | SGX_CDR_CFLAGS := -DSGX_CDR 9 | endif 10 | 11 | ifeq ($(SGX_CDR_LIVE), 1) 12 | SGX_CDR_CFLAGS := -DSGX_CDR -DSGX_CDR_LIVE 13 | endif 14 | 15 | 16 | CC := g++ # This is the main compiler 17 | SRCDIR := src 18 | BINDIR := bin 19 | BUILDDIR := build 20 | TARGETDIR := bin 21 | TARGET := $(TARGETDIR)/ctf 22 | 23 | SRCEXT := cpp 24 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 25 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 26 | DEPENDS := $(OBJECTS:%.o=%.d) 27 | CFLAGS := -g -pthread -std=c++14 $(SGX_CDR_CFLAGS)# -Wall 28 | LFLAGS := -g -pthread -lpthread 29 | LIBS := \ 30 | $(ROOT)/util/lib/libc3po.a \ 31 | -l:libpistache.a \ 32 | -lcares \ 33 | -lcrypto \ 34 | -lfdcore \ 35 | -lfdproto \ 36 | -lmemcached \ 37 | -lrt \ 38 | -lssl 39 | INCS := \ 40 | -I ./include \ 41 | -I $(ROOT)/modules/linux-sgx/common/inc \ 42 | -I $(ROOT)/modules/spdlog/include \ 43 | -I $(ROOT)/util/include 44 | 45 | $(TARGET): $(OBJECTS) 46 | @echo " Linking..." 47 | @mkdir -p $(BINDIR) 48 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 49 | 50 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 51 | @mkdir -p $(BUILDDIR) 52 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 53 | 54 | clean: 55 | @echo " Cleaning..."; 56 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 57 | 58 | -include $(DEPENDS) 59 | 60 | .PHONY: clean 61 | -------------------------------------------------------------------------------- /ctf/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | C3PO: CTF Build and Run Instructions 3 | --- 4 | Perform the following procedures in order. 5 | 1. Follow the instructions located in the **_"Build and Installation Instructions for External Modules"_** provided in _{installation_root}/c3po/README.md_. Make sure these steps are complete. 6 | 2. Build **CTF**. 7 | 8 | $ cd {isntallation_root}/c3po/ctf 9 | $ make 10 | 3. Update the following files with any configuration changes: 11 | + {installation_root}/c3po/ctf/conf/ctf.conf 12 | + {installation_root}/c3po/ctf/conf/ctf.json 13 | 4. If this is the first time you are running the application, create the freeDiameter certificates using the following steps. **make_certs.sh** takes two parameters, supply the diameter host name without realm and then the diameter realm. 14 | **NOTE - the diameter host and realm names must match the names set in step 3**. 15 | 16 | $ cd {installation_root}/c3po/ctf/conf 17 | $ ../bin/make_certs.sh cdf test3gpp.net 18 | 5. To run the application: 19 | 20 | $ cd ${installation_root}/c3po/ctf 21 | $ bin/ctf -j conf/ctf.json 22 | Configuration Instructions 23 | -------------------------- 24 | 1. Mount a network share that corresponds to the network share where the Data Plane (DP) writes the CSV usage files. For example, the development share is mounted on /dpcsv. Update the **_datapath_**, **_archivepath_**, and **_trackpath_** accordingly. 25 | 26 | -------------------------------------------------------------------------------- /ctf/README.txt: -------------------------------------------------------------------------------- 1 | C3PO: CTF Build and Run Instructions 2 | 3 | Perform the following procedures in order. 4 | 5 | 1. Follow the instructions located in the "Build and Installation 6 | Instructions for External Modules" provided in 7 | {installation_root}/c3po/README.txt. Make sure these steps are complete. 8 | 9 | 2. Build CTF. 10 | 11 | $ cd {isntallation_root}/c3po/ctf 12 | $ make 13 | 14 | 3. Update the following files with any configuration changes: 15 | 16 | {installation_root}/c3po/ctf/conf/ctf.conf 17 | {installation_root}/c3po/ctf/conf/ctf.json 18 | 19 | 4. If this is the first time you are running the application, create the 20 | freeDiameter certificates using the following steps. make_certs.sh takes 21 | two parameters, supply the diameter host name without realm and then the 22 | diameter realm. 23 | 24 | NOTE - the diameter host and realm names must match the names set in step 3 25 | 26 | $ cd {installation_root}/c3po/ctf/conf 27 | $ ../bin/make_certs.sh ctf test3gpp.net 28 | 29 | 5. To run the application: 30 | 31 | $ cd ${installation_root}/c3po/ctf 32 | $ bin/ctf -j conf/ctf.json 33 | 34 | Configuration Instructions 35 | -------------------------- 36 | 1. Mount a network share that corresponds to the network share where the Data 37 | Plane (DP) writes the CSV usage files. For example, the development share 38 | is mounted on /dpcsv. Update the datapath, archivepath, and trackpath 39 | accordingly. 40 | -------------------------------------------------------------------------------- /ctf/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /ctf/certs/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDtzCCAp+gAwIBAgIJANRdpGQ5No18MA0GCSqGSIb3DQEBCwUAMHIxCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJPUjESMBAGA1UEBwwJSGlsbHNib3JvMRQwEgYDVQQK 4 | DAtJbnRlbCBDb3JwLjETMBEGA1UECwwKSW50ZWwgTGFiczEXMBUGA1UEAwwOTkdJ 5 | Qy1EYXRhcGxhbmUwHhcNMTcwODA0MDYwNDM1WhcNMTgwODA0MDYwNDM1WjByMQsw 6 | CQYDVQQGEwJVUzELMAkGA1UECAwCT1IxEjAQBgNVBAcMCUhpbGxzYm9ybzEUMBIG 7 | A1UECgwLSW50ZWwgQ29ycC4xEzARBgNVBAsMCkludGVsIExhYnMxFzAVBgNVBAMM 8 | Dk5HSUMtRGF0YXBsYW5lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA 9 | reHKFrMUo0vTebk5egy0YEVUnYyomtS5fwLLTu2ZS+L+53MqcvMU1Cq80htR6pf+ 10 | 7t5Sr9qCRxXEa0RaUZYy+svi23k2HAMVpzdQnNZDwAYSkeihWORGKSnK/+9uivfg 11 | vaiSJf7oNgj7P8Zy4gxjCDn6pCIlCTJm+v8mxTERTv59FpZT9/t1i4sr1upsz3+H 12 | zuhTMxvAx5XjdQrENA9qtvEni11PDCylG9OQ0nLQA4dJPWsH0KVc8x0Axc7PyInf 13 | qttYPwIhh7GNNCMvHcQxGR15IACB+v8xgm4MeU4v1vGyHsFD4oSKluyCp47eLeEp 14 | NsdiKHlWb6RHbVlN6fqSDwIDAQABo1AwTjAdBgNVHQ4EFgQU/Od+QFS1E8zln3GV 15 | V961WL9B5aMwHwYDVR0jBBgwFoAU/Od+QFS1E8zln3GVV961WL9B5aMwDAYDVR0T 16 | BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAAiROnWtiCcUVLsQ1m80M1BrxmsRd 17 | G9PBlebuJ9XVjAfyzfi1sR4h3mjbzjXwSSF+TX5nYBwuHTFVJJg0OYsZUsoZLrxa 18 | V7OOXvKlH2pKcex4mzDmpA+UCaru8X0UCpJ9F2sM0A+YkFk+GjoJt5pglgWQZzjh 19 | PeC6YSWJpCLZxpRHpaVvOwxqDzJLkKtZVDz7UrvEl0tdTcf+G9AbK/nVUDg8YTmr 20 | oRuGvBgs4ZnxOJ2nsrP7rw8X0YLG176Y94sOMx4BEIRF2uV85VNMiL9qdT/MGz3K 21 | 8qvKkMC/yWwSHOfCImwL2V7OFdcWy6HW92Y7eSG7/3OD3UbXkuZSjMirdQ== 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /ctf/certs/key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCt4coWsxSjS9N5 3 | uTl6DLRgRVSdjKia1Ll/AstO7ZlL4v7ncypy8xTUKrzSG1Hql/7u3lKv2oJHFcRr 4 | RFpRljL6y+LbeTYcAxWnN1Cc1kPABhKR6KFY5EYpKcr/726K9+C9qJIl/ug2CPs/ 5 | xnLiDGMIOfqkIiUJMmb6/ybFMRFO/n0WllP3+3WLiyvW6mzPf4fO6FMzG8DHleN1 6 | CsQ0D2q28SeLXU8MLKUb05DSctADh0k9awfQpVzzHQDFzs/Iid+q21g/AiGHsY00 7 | Iy8dxDEZHXkgAIH6/zGCbgx5Ti/W8bIewUPihIqW7IKnjt4t4Sk2x2IoeVZvpEdt 8 | WU3p+pIPAgMBAAECggEAB4uw1WNYFe4Ic1PSZrV+bl8T2PJtrqpkklpwsDAnYt+q 9 | 6ChbQznBQaPJJeUBnQiTi5IiTHdTB/qt12nT8Y5vD+shIR0VeAm6OtNvsB6sOf0J 10 | eUN7HPxq/wZNROYDCgzPt+tEzFlPgmjJXm8iNSUMdyLs+YpxyQBi76l66TvD4IWg 11 | WaVJDCY4LPSJIuICT9Z5K0w0NbmtF1yY9ZNxhhNUuIulMNCT9pwJTtuIzqooI0RK 12 | MBbpuPGOclcgL1gDKNEKLAQGYPyiYV1Qvg05ZmJN1hb2bsom0s5RzTH8VrNJsOmC 13 | mH/3tWnO+1IxVgN9bj+B2dxX7iw4qP4lSMK1gyigwQKBgQDee5FU9dRdQyBz47RH 14 | 2nKmff52l9lt+sdmTSSlbwc+KNQhoPMfOw2qtGHmA901RisvvDx/JRN6Tb4BvEqp 15 | v2a02uugcK2gZaI2g/GwviSn0T6u0tMqh3bzfFmDzDPEa2Kj2lCtwBryhkeoM47i 16 | wjUvTs/OnQpsjg/AO1pSqv0buQKBgQDIE9noMhsvCmxUoHm6Nt6zyiD+o17f2UGt 17 | kVvwi7S/1EqYDp8Lhjq1u58QgUP6vx8eguIJ8XxWO7up13NcVF8HEllb5oruDNgP 18 | dD85o1clJlApMtckmOAKlFJTU3uZfUYCNF3YQq5URdOZ/AbfijEwJseHE4VXlsvF 19 | lV9FnA1QBwKBgF+lwgpDkWPy6u3HtAa8DFQ1kINNrwVQLg92FM4mmHeJuAEpH7yK 20 | d8qut/PaL2yq2QAxrdR/jQskhw5Z88NcbPxNrcURDCQL7ZwAR5TTehDHrWodavk6 21 | udHd4OH/lTXZcNO+lLbOAwfG4OGYINKt6Y2IFWDfNM8MmArtuVwW9K/JAoGAN0wN 22 | QLiAfNrTn/wOSKIboPMvdVEvyoxgM5lmILBsD0ycJTR9TpEVrt6hEs23PRkPf75K 23 | vNbKN4cg0csjLhR/gxPWMKkiIrLYEEVfqA1162WQaCKOBaZe3W2q5y6+jWhrLfbN 24 | LRUY21/FINzgBW5LM/Sz1qhVhSS/QueKwlFj+IcCgYAW7KTaEO4jfFEQI2MOdVQJ 25 | vfK7oAKzmv2EhySv3mPUM3ziVytfsJS1CVKIcT4to0CuRnv99GL0NAFd0KUamdkN 26 | c7O8o9d2oVetmI8e1TrckaHfEt2V9iFVUo5Oex0LKoCR3V8TWq0Li22QuiiMBgh9 27 | CJWnrdUMplVkb5LOZXpVwQ== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /ctf/conf/ctf.json: -------------------------------------------------------------------------------- 1 | {"common": { 2 | "fdcfg": "conf/ctf.conf", 3 | "originhost": "ctf.test3gpp.net", 4 | "originrealm": "test3gpp.net" 5 | }, 6 | "ctf": { 7 | "datapfx": "cdr", 8 | "datapath": "test/data", 9 | "archivepath": "test/data/archive", 10 | "trackpath": "test/data/tracking", 11 | "trackext": ".trk", 12 | "curext": ".cur", 13 | "skiprows": 1, 14 | "idledur": 1000, 15 | "maxacrs": 10, 16 | "savefreq": 10, 17 | "sdnmemcsvr": "10.31.14.83", 18 | "sdnmemcport": 11211, 19 | "logsize": 20, 20 | "lognumber": 5, 21 | "logname": "logs/ctf.log", 22 | "logqsize": 8192, 23 | "statlogsize": 20, 24 | "statlognumber": 5, 25 | "statlogname": "logs/ctf_stat.log", 26 | "auditlogsize": 20, 27 | "auditlognumber": 5, 28 | "auditlogname": "logs/ctf_audit.log", 29 | "statfreq": 2000, 30 | "ossport" : 9082, 31 | "certfile": "./certs/cert.pem", 32 | "isvsvn": 0, 33 | "mrenclave": "cb4c94f52fb1c2d840a4df31b1e0e75a1cf7327caae2e7dd106c0c3c12e6a77d", 34 | "mrsigner": "63ef969cbc34ee465f277cd3c27e9b3c681d743e455f899daced1b3cf85ceb8f", 35 | "privkeyfile": "./certs/key.pem", 36 | "sgxserverip": "10.212.44.98", 37 | "sgxserverport": 443, 38 | "streamname": "0s1", 39 | "ossfile": "conf/oss.json" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ctf/conf/oss.json: -------------------------------------------------------------------------------- 1 | { 2 | "option": { 3 | "id": "url", 4 | "type": "string" 5 | }, 6 | "services": [ 7 | { 8 | "id": "logger", 9 | "commands": [ 10 | { 11 | "id": "describe_loggers" 12 | }, 13 | { 14 | "id": "set_logger_level", 15 | "options": [ 16 | { 17 | "id": "name", 18 | "type": "string" 19 | }, 20 | { 21 | "id": "level", 22 | "type": "integer" 23 | } 24 | ] 25 | } 26 | ] 27 | }, 28 | { 29 | "id": "stats", 30 | "commands": [ 31 | { 32 | "id": "describe_stats_frequency" 33 | }, 34 | { 35 | "id": "describe_stats_live" 36 | }, 37 | { 38 | "id": "set_stats_frequency", 39 | "options": [ 40 | { 41 | "id": "frequency", 42 | "type": "integer" 43 | } 44 | ] 45 | } 46 | ] 47 | } 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /ctf/include/csvfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __CSVFILE_H 9 | #define __CSVFILE_H 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "sfile.h" 17 | 18 | class CSVRow : public std::vector 19 | { 20 | public: 21 | CSVRow() {} 22 | ~CSVRow() {} 23 | 24 | CSVRow &parse( const std::string &data ); 25 | 26 | int32_t getInt32( int ofs ) const { return atoi( (*this)[ofs].c_str() ); } 27 | int64_t getInt64( int ofs ) const { return strtoll( (*this)[ofs].c_str(), NULL, 10 ); } 28 | uint32_t getUint32( int ofs ) const { return (uint32_t)strtoul( (*this)[ofs].c_str(), NULL, 10 ); } 29 | uint64_t getUint64( int ofs ) const { return strtoull( (*this)[ofs].c_str(), NULL, 10 ); } 30 | 31 | }; 32 | 33 | class CSVFile : public SFile 34 | { 35 | public: 36 | CSVFile(); 37 | ~CSVFile(); 38 | 39 | const CSVRow &row() { return m_row; } 40 | 41 | uint32_t getSkip() { return m_skip; } 42 | uint32_t setSkip( uint32_t s ) { return m_skip = s; } 43 | 44 | void parse(); 45 | 46 | private: 47 | CSVRow m_row; 48 | uint32_t m_skip; 49 | }; 50 | 51 | #endif // #define __CSVFILE_H 52 | -------------------------------------------------------------------------------- /ctf/include/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __LOGGER_H 9 | #define __LOGGER_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include "slogger.h" 15 | 16 | class Logger 17 | { 18 | public: 19 | 20 | static void init( const char *app ) { singleton()._init( app ); } 21 | static void init( const std::string &app ) { init( app.c_str() ); } 22 | static void cleanup() { singleton()._cleanup(); } 23 | static void flush() { singleton()._flush(); } 24 | static std::string serialize() { return singleton()._serialize(); } 25 | static bool updateLogger(const std::string &loggerName, int value) { return singleton()._updateLogger(loggerName, value); } 26 | 27 | static SLogger &system() { return *singleton().m_system; } 28 | static SLogger &rf() { return *singleton().m_rf; } 29 | static SLogger &stat() { return *singleton().m_stat; } 30 | static SLogger &audit() { return *singleton().m_audit; } 31 | 32 | static Logger &singleton() { if (!m_singleton) m_singleton = new Logger(); return *m_singleton; } 33 | 34 | private: 35 | static Logger *m_singleton; 36 | 37 | 38 | Logger() {} 39 | ~Logger() {} 40 | 41 | void _init( const char *app ); 42 | void _cleanup(); 43 | void _flush(); 44 | std::string _serialize(); 45 | bool _updateLogger(const std::string &loggerName, int value); 46 | 47 | std::vector m_sinks; 48 | std::vector m_statsinks; 49 | std::vector m_auditsinks; 50 | 51 | std::string m_pattern; 52 | 53 | SLogger *m_system; 54 | SLogger *m_rf; 55 | SLogger *m_stat; 56 | SLogger *m_audit; 57 | }; 58 | 59 | #endif // __LOGGER_H 60 | -------------------------------------------------------------------------------- /ctf/include/msg_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #ifndef HSS_SRC_HOOKEVENT_H_ 10 | #define HSS_SRC_HOOKEVENT_H_ 11 | 12 | #include "sstats.h" 13 | #include "freeDiameter/freeDiameter-host.h" 14 | #include "freeDiameter/libfdproto.h" 15 | #include "freeDiameter/libfdcore.h" 16 | 17 | #include "rf_impl.h" 18 | 19 | 20 | class HookEvent { 21 | public: 22 | static void init(SStats* stat, rf::Application *rf); 23 | static void md_hook_cb_error(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 24 | static void md_hook_cb_ok(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 25 | 26 | private: 27 | 28 | static struct fd_hook_hdl *m_hdl[2]; 29 | static SStats *m_stat; 30 | 31 | static rf::Application *m_rf; 32 | }; 33 | 34 | #endif /* HSS_SRC_HOOKEVENT_H_ */ 35 | -------------------------------------------------------------------------------- /ctf/include/sdn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SDN_H 9 | #define __SDN_H 10 | 11 | #include 12 | #include 13 | 14 | struct memcached_st; 15 | struct memcached_server_st; 16 | 17 | 18 | class SDNException : public std::runtime_error 19 | { 20 | public: 21 | SDNException(const char *m) : std::runtime_error(m) {} 22 | SDNException(const std::string &m) : std::runtime_error(m) {} 23 | }; 24 | 25 | class SDN 26 | { 27 | public: 28 | 29 | SDN(); 30 | ~SDN(); 31 | 32 | bool get( const char *ipaddr ); 33 | bool get( const std::string &ipaddr ) { return get( ipaddr.c_str() ); } 34 | 35 | const std::string &getIpAddress() { return m_ipaddress; } 36 | const std::string &getIMSI() { return m_imsi; } 37 | const std::string &getMDN() { return m_mdn; } 38 | const std::string &getContext() { return m_context; } 39 | time_t getStartTime() { return m_start; } 40 | time_t getEndTime() { return m_end; } 41 | 42 | private: 43 | memcached_st *m_mc; 44 | memcached_server_st *m_mcs; 45 | 46 | std::string m_ipaddress; 47 | std::string m_imsi; 48 | std::string m_mdn; 49 | std::string m_context; 50 | time_t m_start; 51 | time_t m_end; 52 | }; 53 | 54 | #endif // #define __SDN_H 55 | -------------------------------------------------------------------------------- /ctf/include/sgx_crt_info.h: -------------------------------------------------------------------------------- 1 | #include "/opt/intel/sgxsdk/include/sgx_quote.h" 2 | #include "/home/inteluser/il_spr_ssl_dcs-tls_attestation_framework/deps/local/include/mbedtls/x509.h" 3 | #include "/home/inteluser/il_spr_ssl_dcs-tls_attestation_framework/deps/local/include/mbedtls/ssl.h" 4 | 5 | void print_sgx_crt_info(X509* crt); 6 | 7 | void get_quote_from_report(const uint8_t* report /* in */, 8 | const int report_len /* in */, 9 | sgx_quote_t* quote); 10 | 11 | void get_quote_from_cert( 12 | const uint8_t* der_crt, 13 | uint32_t der_crt_len, 14 | sgx_quote_t* q 15 | ); 16 | 17 | int verify_sgx_cert_extensions 18 | ( 19 | const uint8_t* der_crt, 20 | uint32_t der_crt_len 21 | ); 22 | 23 | -------------------------------------------------------------------------------- /ctf/include/statsctf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __STATSCTF_H 9 | #define __STATSCTF_H 10 | 11 | #include 12 | #include "sstats.h" 13 | #include "stimer.h" 14 | 15 | class StatsCtf : public SStats { 16 | public: 17 | static void initstats(SLogger* statlogger) { singleton().setStatLogger(statlogger); }; 18 | static StatsCtf &singleton() { if (!m_singleton) m_singleton = new StatsCtf(); return *m_singleton; } 19 | void getSerializedStat(std::string& stats); 20 | void dispatchDerived(SEventThreadMessage &msg); 21 | void resetStats(); 22 | void processStatResult(StatResultMessage& stat); 23 | void processStatAttemp(StatAttempMessage& stat); 24 | void processStatGetLive(StatLive& msg); 25 | 26 | private: 27 | StatsCtf(); 28 | ~StatsCtf(); 29 | 30 | static StatsCtf *m_singleton; 31 | StatCollector m_acr_collector; 32 | uint32_t m_max_codes_tracked; 33 | }; 34 | 35 | 36 | #endif // #define __TESTS_H 37 | -------------------------------------------------------------------------------- /ctf/include/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __TESTS_H 9 | #define __TESTS_H 10 | 11 | namespace rf { class Application; } 12 | 13 | class Tests 14 | { 15 | public: 16 | static bool syslogTest(); 17 | static bool dateTimeTest(); 18 | static bool timerTest(); 19 | static bool queueTest(); 20 | static bool threadTest(); 21 | static bool directoryTest(); 22 | static bool pathTest(); 23 | static bool csvTest(); 24 | static bool splitTest(); 25 | static bool trackTest(); 26 | static bool fdTest1(rf::Application& app); 27 | }; 28 | 29 | #endif // #define __TESTS_H 30 | -------------------------------------------------------------------------------- /ctf/src/csvfile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #include 10 | 11 | #include "csvfile.h" 12 | #include "sutility.h" 13 | 14 | CSVRow &CSVRow::parse( const std::string &data ) 15 | { 16 | clear(); 17 | 18 | std::istringstream ss( data ); 19 | std::string f; 20 | 21 | while ( ss.good() ) 22 | { 23 | std::getline( ss, f, ',' ); 24 | push_back( f ); 25 | } 26 | 27 | return *this; 28 | } 29 | 30 | //////////////////////////////////////////////////////////////////////////////// 31 | //////////////////////////////////////////////////////////////////////////////// 32 | 33 | 34 | CSVFile::CSVFile() 35 | : m_skip( 0 ) 36 | { 37 | } 38 | 39 | CSVFile::~CSVFile() 40 | { 41 | } 42 | 43 | void CSVFile::parse() 44 | { 45 | m_row.parse( data() ); 46 | } 47 | -------------------------------------------------------------------------------- /ctf/src/sgx_crt_info.c: -------------------------------------------------------------------------------- 1 | #include "sgx_crt_info.h" 2 | 3 | void get_quote_from_cert 4 | ( 5 | const uint8_t* der_crt, 6 | uint32_t der_crt_len, 7 | sgx_quote_t* q 8 | ) 9 | { 10 | mbedtls_x509_crt crt; 11 | mbedtls_x509_crt_init(&crt); 12 | mbedtls_x509_crt_parse(&crt, der_crt, der_crt_len); 13 | get_quote_from_extension(crt.v3_ext.p, crt.v3_ext.len, q); 14 | mbedtls_x509_crt_free(&crt); 15 | } 16 | 17 | 18 | void print_sgx_crt_info(X509* crt) 19 | { 20 | int der_len = i2d_X509(crt, NULL); 21 | //assert(der_len > 0); 22 | 23 | unsigned char der[der_len]; 24 | unsigned char *p = der; 25 | i2d_X509(crt, &p); 26 | 27 | sgx_quote_t quote; 28 | get_quote_from_cert(der, der_len, "e); 29 | sgx_report_body_t* body = "e.report_body; 30 | 31 | printf("Certificate's SGX information:\n"); 32 | printf(" . MRENCLAVE = "); 33 | for (int i=0; i < SGX_HASH_SIZE; ++i) printf("%02x", body->mr_enclave.m[i]); 34 | printf("\n"); 35 | 36 | printf(" . MRSIGNER = "); 37 | for (int i=0; i < SGX_HASH_SIZE; ++i) printf("%02x", body->mr_signer.m[i]); 38 | printf("\n"); 39 | } 40 | -------------------------------------------------------------------------------- /db_docs/Cassandra_Initialize_Schema.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/db_docs/Cassandra_Initialize_Schema.docx -------------------------------------------------------------------------------- /db_docs/Cassandra_Install.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/db_docs/Cassandra_Install.docx -------------------------------------------------------------------------------- /db_docs/Cassandra_Single_Node_Install.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/db_docs/Cassandra_Single_Node_Install.docx -------------------------------------------------------------------------------- /db_docs/DataStax_Agent_Install.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/db_docs/DataStax_Agent_Install.docx -------------------------------------------------------------------------------- /db_docs/OpsCenter_Install.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/db_docs/OpsCenter_Install.docx -------------------------------------------------------------------------------- /db_docs/Subscriber_Provisioning.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/db_docs/Subscriber_Provisioning.docx -------------------------------------------------------------------------------- /db_docs/data_provisioning_mme.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | ### Add an entry to the mme_identity table ###### 9 | 10 | id=$1 11 | isdn=$2 12 | host=$3 13 | realm=$4 14 | uereachability=$5 15 | cassandra_ip=$6 16 | if [ "$*" == "" -o $# -ne 6 ] ; then 17 | echo -e "You must provide all of the arguments to the script\n" 18 | echo -e "$0 \n" 19 | exit 20 | fi 21 | 22 | cqlsh $cassandra_ip -e "INSERT INTO vhss.mmeidentity (idmmeidentity, mmeisdn, mmehost, mmerealm, ue_reachability) VALUES ($id, '$isdn', '$host', '$realm', $uereachability);" 23 | if [ $? -ne 0 ];then 24 | echo -e "Oops! Something went wrong adding to vhss.mmeidentity!\n" 25 | exit 26 | fi 27 | 28 | cqlsh $cassandra_ip -e "INSERT INTO vhss.mmeidentity_host (idmmeidentity, mmeisdn, mmehost, mmerealm, ue_reachability) VALUES ($id, '$isdn', '$host', '$realm', $uereachability);" 29 | if [ $? -ne 0 ];then 30 | echo -e "Oops! Something went wrong adding to vhss.mmeidentity_host!\n" 31 | exit 32 | fi 33 | 34 | echo -e "The mmeidentity provisioning is successfull\n" 35 | -------------------------------------------------------------------------------- /db_docs/policy_membership_change.md: -------------------------------------------------------------------------------- 1 | Run this script if Policy MemberShip Changes: 2 | 3 | ./PM_MV_Changes.sh 4 | 5 | THis script will get all the Subscriber policy values which are having same domains as Policy Membership values. 6 | 7 | For each Subscriber policy value it checks the below case 8 | 9 | If ( PM.MV PM.Matchtype SP.MV) == TRUE then rulename will be added in computed reule names of Subscriber policy table 10 | 11 | Else it will ensure that rulename from PM table is not present in computed reule names of Subscriber policy table 12 | 13 | 14 | 15 | PM.Matchtype -- operator 16 | 17 | PM - Policy MemberShip 18 | MV - MemberShip Value 19 | SP - Subscriber Policyi 20 | -------------------------------------------------------------------------------- /db_docs/subscriber_policy_change.md: -------------------------------------------------------------------------------- 1 | Run this script if Subscriber Policy Changes: 2 | 3 | ./SP_MV_Changes.sh 4 | 5 | → THis script will clear all the computed rulename from the Subscriber policy table 6 | → Will get all the Policy membership values with same domain. 7 | → For each Policy Membership value it check the below case 8 | 9 | 10 | If ( PM.MV PM.Matchtype SP.MV) == TRUE then rulename will be added in computed reule names of Subscriber policy table 11 | 12 | PM.Matchtype -- operator 13 | 14 | PM - Policy MemberShip 15 | MV - MemberShip Value 16 | SP - Subscriber Policy 17 | 18 | -------------------------------------------------------------------------------- /hss/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/hss 3 | conf/*pem 4 | conf/demoCA 5 | out.txt 6 | -------------------------------------------------------------------------------- /hss/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/hss 7 | #PERFORMANCE_TIMING := -DPERFORMANCE_TIMING 8 | PERFORMANCE_TIMING := 9 | #TRACK_EXECUTION := -DTRACK_EXECUTION 10 | TRACK_EXECUTION := 11 | #MONITOR_PENDING_MESSAGE_LEVEL :=-DMONITOR_PENDING_MESSAGE_LEVEL 12 | MONITOR_PENDING_MESSAGE_LEVEL := 13 | 14 | SECURITY_FLAGS := -D_FORTIFY_SOURCE=2 -fasynchronous-unwind-tables -fexceptions 15 | SECURITY_FLAGS += -fstack-protector-all -fstack-protector-strong -Wall 16 | SECURITY_FLAGS += -Werror=format-security -Werror=implicit-function-declaration 17 | 18 | SRCEXT := cpp 19 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 20 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 21 | DEPENDS := $(OBJECTS:%.o=%.d) 22 | CFLAGS := -g -pthread -std=c++14 $(PERFORMANCE_TIMING) $(TRACK_EXECUTION) $(MONITOR_PENDING_MESSAGE_LEVEL) $(SECURITY_FLAGS)# -Wall 23 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 24 | LIBS := \ 25 | $(ROOT)/util/lib/libc3po.a \ 26 | $(ROOT)/hsssec/lib/libhsssec.a \ 27 | -l:libpistache.a \ 28 | -lcassandra \ 29 | -lfdcore \ 30 | -lfdproto \ 31 | -lgmp \ 32 | -lnettle \ 33 | -lprometheus-cpp-pull -lprometheus-cpp-core -lz \ 34 | -lrt 35 | 36 | INCS := \ 37 | -I ./include \ 38 | -I $(ROOT)/util/include \ 39 | -I $(ROOT)/hsssec/include \ 40 | -I $(ROOT)/modules/spdlog/include 41 | 42 | $(TARGET): $(OBJECTS) 43 | @echo " Linking..." 44 | @mkdir -p $(BINDIR) 45 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 46 | 47 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 48 | @mkdir -p $(BUILDDIR) 49 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 50 | 51 | clean: 52 | @echo " Cleaning..."; 53 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 54 | 55 | -include $(DEPENDS) 56 | 57 | .PHONY: clean 58 | -------------------------------------------------------------------------------- /hss/README.txt: -------------------------------------------------------------------------------- 1 | C3PO: HSS Build and Run Instructions 2 | 3 | Perform the following procedures in order. 4 | 5 | 1. Follow the instructions located in the "Build and Installation 6 | Instructions for External Modules" provided in 7 | {installation_root}/c3po/README.md_. Make sure these steps are complete. 8 | 9 | 2. Build HSS. 10 | 11 | $ cd {isntallation_root}/c3po/hss 12 | $ make 13 | 14 | 3. Update the following files with any configuration changes: 15 | 16 | {installation_root}/c3po/hss/conf/hss.conf 17 | {installation_root}/c3po/hss/conf/hss.json 18 | 19 | 4. If this is the first time you are running the application, create the 20 | freeDiameter certificates using the following steps. make_certs.sh takes 21 | two parameters, supply the diameter host name without realm and then the 22 | diameter realm. 23 | 24 | NOTE - the diameter host and realm names must match the names set in step 3 25 | 26 | $ cd {installation_root}/c3po/hss/conf 27 | $ ../bin/make_certs.sh hss test3gpp.net 28 | 29 | 5. To run the application: 30 | 31 | $ cd ${installation_root}/c3po/hss 32 | $ bin/hss -j conf/hss.json 33 | -------------------------------------------------------------------------------- /hss/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /hss/conf/acl.conf: -------------------------------------------------------------------------------- 1 | # Configuration file for the peer whitelist extension. 2 | # 3 | # This extension is meant to allow connection from remote peers, without actively 4 | # maintaining this connection ourselves (as it would be the case by declaring the 5 | # peer in a ConnectPeer directive). 6 | # The format of this file is very simple. It contains a list of peer names 7 | # separated by spaces or newlines. 8 | # 9 | # The peer name must be a fqdn. We allow also a special "*" character as the 10 | # first label of the fqdn, to allow all fqdn with the same domain name. 11 | # Example: *.example.net will allow host1.example.net and host2.example.net 12 | # 13 | # At the beginning of a line, the following flags are allowed (case sensitive) -- either or both can appear: 14 | # ALLOW_OLD_TLS : we accept unprotected CER/CEA exchange with Inband-Security-Id = TLS 15 | # ALLOW_IPSEC : we accept implicitly protected connection with with peer (Inband-Security-Id = IPSec) 16 | # It is specified for example as: 17 | # ALLOW_IPSEC vpn.example.net vpn2.example.net *.vpn.example.net 18 | 19 | ALLOW_OLD_TLS *.localdomain *.test3gpp.net 20 | -------------------------------------------------------------------------------- /hss/conf/hss.json: -------------------------------------------------------------------------------- 1 | {"common": { 2 | "fdcfg": "conf/hss.conf", 3 | "originhost": "hss.openair4G.eur", 4 | "originrealm": "openair4G.eur" 5 | }, 6 | "hss": { 7 | "gtwhost": "*", 8 | "gtwport" : 9080, 9 | "restport" : 9081, 10 | "ossport" : 9082, 11 | "casssrv": "192.168.33.10", 12 | "cassusr": "root", 13 | "casspwd": "root", 14 | "cassdb" : "vhss", 15 | "casscoreconnections" : 2, 16 | "cassmaxconnections" : 8, 17 | "cassioqueuesize" : 32768, 18 | "cassiothreads" : 2, 19 | "randv" : true, 20 | "optkey" : "63bfa50ee6523365ff14c1f45f88737d", 21 | "reloadkey" : false, 22 | "logsize": 20, 23 | "lognumber": 5, 24 | "logname": "logs/hss.log", 25 | "logqsize": 8192, 26 | "statlogsize": 20, 27 | "statlognumber": 5, 28 | "statlogname": "logs/hss_stat.log", 29 | "auditlogsize": 20, 30 | "auditlognumber": 5, 31 | "auditlogname": "logs/hss_audit.log", 32 | "statfreq": 2000, 33 | "numworkers": 4, 34 | "concurrent": 10, 35 | "ossfile": "conf/oss.json", 36 | "verifyroamingsubscribers": true 37 | "prom_port": 9089 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hss/conf/oss.json: -------------------------------------------------------------------------------- 1 | { 2 | "option": { 3 | "id": "url", 4 | "type": "string" 5 | }, 6 | "services": [ 7 | { 8 | "id": "logger", 9 | "commands": [ 10 | { 11 | "id": "describe_loggers" 12 | }, 13 | { 14 | "id": "set_logger_level", 15 | "options": [ 16 | { 17 | "id": "name", 18 | "type": "string" 19 | }, 20 | { 21 | "id": "level", 22 | "type": "integer" 23 | } 24 | ] 25 | } 26 | ] 27 | }, 28 | { 29 | "id": "stats", 30 | "commands": [ 31 | { 32 | "id": "describe_stats_frequency" 33 | }, 34 | { 35 | "id": "describe_stats_live" 36 | }, 37 | { 38 | "id": "set_stats_frequency", 39 | "options": [ 40 | { 41 | "id": "frequency", 42 | "type": "integer" 43 | } 44 | ] 45 | } 46 | ] 47 | } 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /hss/hssperf/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/smsrouter 3 | conf/*pem 4 | conf/demoCA 5 | out.txt 6 | logs 7 | -------------------------------------------------------------------------------- /hss/hssperf/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/hssperf 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++11 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | LIBS := \ 15 | $(ROOT)/util/lib/libc3po.a \ 16 | -lcares \ 17 | -lcassandra \ 18 | -lfdcore \ 19 | -lfdproto \ 20 | -lmemcached \ 21 | -lrt 22 | 23 | INCS := \ 24 | -I ./include \ 25 | -I $(ROOT)/util/include \ 26 | -I $(ROOT)/modules/spdlog/include 27 | 28 | $(TARGET): $(OBJECTS) 29 | @echo " Linking..." 30 | @mkdir -p $(BINDIR) 31 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 32 | 33 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 34 | @mkdir -p $(BUILDDIR) 35 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 36 | 37 | clean: 38 | @echo " Cleaning..."; 39 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 40 | 41 | -include $(DEPENDS) 42 | 43 | .PHONY: clean 44 | -------------------------------------------------------------------------------- /hss/hssperf/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /hss/hssperf/conf/hssperf.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "fdcfg": "conf/sms.conf", 4 | "originhost": "hssperf.localdomain", 5 | "originrealm": "localdomain" 6 | }, 7 | "hssperf": { 8 | "logsize": 20, 9 | "lognumber": 5, 10 | "logname": "logs/hssperf.log", 11 | "logqsize": 8192 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /hss/hssperf/include/hssperf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __HSSPERF_H 9 | #define __HSSPERF_H 10 | 11 | #include "s6as6d_impl.h" 12 | 13 | class HSSPerformance 14 | { 15 | public: 16 | HSSPerformance(); 17 | ~HSSPerformance(); 18 | 19 | bool init(); 20 | void uninit(); 21 | 22 | void waitForShutdown(); 23 | 24 | s6as6d::Application &s6as6dApp() { return *m_s6as6d; } 25 | 26 | private: 27 | FDEngine m_diameter; 28 | 29 | s6as6d::Application *m_s6as6d; 30 | bool m_repetitive; 31 | }; 32 | 33 | #endif // #define __HSSPERF_H 34 | -------------------------------------------------------------------------------- /hss/hssperf/src/hssperf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include 9 | 10 | #include "hssperf.h" 11 | #include "sutility.h" 12 | 13 | #include "options.h" 14 | #include "logger.h" 15 | 16 | HSSPerformance::HSSPerformance() 17 | : m_s6as6d( NULL ) 18 | { 19 | } 20 | 21 | HSSPerformance::~HSSPerformance() 22 | { 23 | } 24 | 25 | bool HSSPerformance::init() 26 | { 27 | // set the diameter configuration file 28 | m_diameter.setConfigFile( Options::diameterConfiguration() ); 29 | 30 | // initialize diameter 31 | if ( !m_diameter.init() ) 32 | return false; 33 | 34 | try 35 | { 36 | m_s6as6d = new s6as6d::Application(); 37 | FDDictionaryEntryVendor vnd3gpp( m_s6as6d->getDict().app() ); 38 | m_diameter.advertiseSupport( m_s6as6d->getDict().app(), vnd3gpp, 1, 0 ); 39 | Logger::s6as6d().startup( "%s:%d - interface initialized", __FILE__, __LINE__ ); 40 | } 41 | catch ( FDException &e ) 42 | { 43 | Logger::s6as6d().startup( "%s:%d - FDException initializing interface - %s", __FILE__, __LINE__, e.what() ); 44 | return false; 45 | } 46 | 47 | return m_diameter.start(); 48 | } 49 | 50 | void HSSPerformance::uninit() 51 | { 52 | if ( m_s6as6d ) 53 | { 54 | Logger::s6as6d().startup( "%s:%d - interface shutdown", __FILE__, __LINE__ ); 55 | delete m_s6as6d; 56 | } 57 | 58 | m_diameter.uninit(); 59 | } 60 | 61 | void HSSPerformance::waitForShutdown() 62 | { 63 | m_diameter.waitForShutdown(); 64 | } 65 | -------------------------------------------------------------------------------- /hss/include/msg_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #ifndef HSS_SRC_HOOKEVENT_H_ 10 | #define HSS_SRC_HOOKEVENT_H_ 11 | 12 | #include "sstats.h" 13 | #include "freeDiameter/freeDiameter-host.h" 14 | #include "freeDiameter/libfdproto.h" 15 | #include "freeDiameter/libfdcore.h" 16 | 17 | #include "s6as6d_impl.h" 18 | #include "s6c_impl.h" 19 | #include "s6t_impl.h" 20 | 21 | 22 | class HookEvent { 23 | public: 24 | static void init(SStats* stat, s6t::Application *s6t, s6as6d::Application *s6as6d, s6c::Application *s6c); 25 | static void md_hook_cb_error(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 26 | static void md_hook_cb_ok(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 27 | 28 | private: 29 | 30 | static struct fd_hook_hdl *m_hdl[2]; 31 | static SStats *m_stat; 32 | static s6t::Application *m_s6t; 33 | static s6as6d::Application *m_s6as6d; 34 | static s6c::Application *m_s6c; 35 | }; 36 | 37 | #endif /* HSS_SRC_HOOKEVENT_H_ */ 38 | -------------------------------------------------------------------------------- /hss/include/resthandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | 10 | #ifndef HSSGTW_INCLUDE_PROVISIONHANDLER_H_ 11 | #define HSSGTW_INCLUDE_PROVISIONHANDLER_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #define RAPIDJSON_NAMESPACE fdrapidjson 20 | #include "rapidjson/filereadstream.h" 21 | #include "rapidjson/document.h" 22 | 23 | 24 | extern RAPIDJSON_NAMESPACE::Document docSchema; 25 | 26 | class SStats; 27 | 28 | class RestHandler : public Pistache::Http::Handler { 29 | 30 | public: 31 | HTTP_PROTOTYPE(RestHandler) 32 | void onRequest(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter response); 33 | }; 34 | 35 | #endif /* HSSGTW_INCLUDE_PROVISIONHANDLER_H_ */ 36 | -------------------------------------------------------------------------------- /hss/include/s6c_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __S6C_IMPL_H 9 | #define __S6C_IMPL_H 10 | 11 | #include "s6c.h" 12 | 13 | class DataAccess; 14 | 15 | namespace s6c { 16 | 17 | // Member functions that customize the individual application 18 | class Application : public ApplicationBase 19 | { 20 | friend SERIFSRreq; 21 | friend ALSCRreq; 22 | friend RESDSRreq; 23 | 24 | public: 25 | Application( DataAccess & dbobj ); 26 | ~Application(); 27 | 28 | SERIFSRcmd &getSERIFSRcmd() { return m_cmd_serifsr; } 29 | //ALSCRcmd &getALSCRcmd() { return m_cmd_alscr; } 30 | //RESDSRcmd &getRESDSRcmd() { return m_cmd_resdsr; } 31 | 32 | // Parameters for sendXXXreq, if present below, may be changed 33 | // based upon processing needs 34 | bool sendSERIFSRreq(FDPeer &peer); 35 | bool sendALSCRreq(FDPeer &peer); 36 | bool sendRESDSRreq(FDPeer &peer); 37 | 38 | DataAccess &getDbObj() { return m_dbobj; } 39 | 40 | private: 41 | void registerHandlers(); 42 | SERIFSRcmd m_cmd_serifsr; 43 | //ALSCRcmd m_cmd_alscr; 44 | //RESDSRcmd m_cmd_resdsr; 45 | 46 | // the parameters for createXXXreq, if present below, may be 47 | // changed based processing needs 48 | SERIFSRreq *createSERIFSRreq(FDPeer &peer); 49 | ALSCRreq *createALSCRreq(FDPeer &peer); 50 | RESDSRreq *createRESDSRreq(FDPeer &peer); 51 | 52 | DataAccess &m_dbobj; 53 | }; 54 | 55 | } 56 | 57 | #endif // __S6C_IMPL_H 58 | -------------------------------------------------------------------------------- /hss/include/s6t_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __S6T_IMPL_H 9 | #define __S6T_IMPL_H 10 | 11 | #ifdef __cplusplus 12 | 13 | #include "s6t.h" 14 | 15 | class DataAccess; 16 | 17 | namespace s6t { 18 | 19 | // Member functions that customize the individual application 20 | class Application : public ApplicationBase 21 | { 22 | friend COIRreq; 23 | friend REIRreq; 24 | friend NIIRreq; 25 | 26 | public: 27 | Application( DataAccess & dbobj ); 28 | ~Application(); 29 | 30 | COIRcmd &getCOIRcmd() { return m_cmd_coir; } 31 | //REIRcmd &getREIRcmd() { return m_cmd_reir; } 32 | NIIRcmd &getNIIRcmd() { return m_cmd_niir; } 33 | 34 | // Parameters for sendXXXreq, if present below, may be changed 35 | // based upon processing needs 36 | bool sendCOIRreq(FDPeer &peer); 37 | bool sendREIRreq(FDPeer &peer); 38 | bool sendNIIRreq(FDPeer &peer); 39 | 40 | DataAccess &getDbObj(); 41 | 42 | private: 43 | void registerHandlers(); 44 | COIRcmd m_cmd_coir; 45 | //REIRcmd m_cmd_reir; 46 | NIIRcmd m_cmd_niir; 47 | 48 | // the parameters for createXXXreq, if present below, may be 49 | // changed based processing needs 50 | COIRreq *createCOIRreq(FDPeer &peer); 51 | REIRreq *createREIRreq(FDPeer &peer); 52 | NIIRreq *createNIIRreq(FDPeer &peer); 53 | 54 | DataAccess &m_dbobj; 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | #endif // __S6T_IMPL_H 61 | -------------------------------------------------------------------------------- /hss/include/statshss.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef HSS_SRC_STATSHSS_H_ 9 | #define HSS_SRC_STATSHSS_H_ 10 | 11 | #include "sstats.h" 12 | #include "stimer.h" 13 | 14 | 15 | class StatsHss : public SStats { 16 | public: 17 | 18 | virtual ~StatsHss(); 19 | 20 | static void initstats(SLogger* statlogger) { singleton().setStatLogger(statlogger); }; 21 | static StatsHss &singleton() { if (!m_singleton) m_singleton = new StatsHss(); return *m_singleton; } 22 | void getSerializedStat(std::string& stats); 23 | void dispatchDerived(SEventThreadMessage &msg); 24 | void resetStats(); 25 | void processStatResult(StatResultMessage& stat); 26 | void processStatAttemp(StatAttempMessage& stat); 27 | void processStatGetLive(StatLive& msg); 28 | 29 | private: 30 | 31 | StatsHss(); 32 | 33 | static StatsHss *m_singleton; 34 | 35 | StatCollector m_ulr_collector; 36 | StatCollector m_air_collector; 37 | StatCollector m_pur_collector; 38 | StatCollector m_cir_collector; 39 | StatCollector m_nir_collector; 40 | StatCollector m_idr_collector; 41 | StatCollector m_rir_collector; 42 | StatCollector m_srr_collector; 43 | 44 | uint32_t m_max_codes_tracked; 45 | 46 | }; 47 | 48 | #endif /* HSS_SRC_STATSHSS_H_ */ 49 | -------------------------------------------------------------------------------- /hss/include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef C3PO_HSS_INCLUDE_UTIL_H_ 9 | #define C3PO_HSS_INCLUDE_UTIL_H_ 10 | 11 | typedef union 12 | { 13 | uint64_t u64; 14 | uint8_t u8[8]; 15 | } SqnU64Union; 16 | 17 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 18 | #define SQN_TO_U64(_sqn,_u) \ 19 | { \ 20 | _u.u64 = 0; \ 21 | _u.u8[5] = _sqn[0]; \ 22 | _u.u8[4] = _sqn[1]; \ 23 | _u.u8[3] = _sqn[2]; \ 24 | _u.u8[2] = _sqn[3]; \ 25 | _u.u8[1] = _sqn[4]; \ 26 | _u.u8[0] = _sqn[5]; \ 27 | } 28 | #define U64_TO_SQN(_u,_sqn) \ 29 | { \ 30 | _sqn[0] = _u.u8[5]; \ 31 | _sqn[1] = _u.u8[4]; \ 32 | _sqn[2] = _u.u8[3]; \ 33 | _sqn[3] = _u.u8[2]; \ 34 | _sqn[4] = _u.u8[1]; \ 35 | _sqn[5] = _u.u8[0]; \ 36 | } 37 | #else 38 | #define SQN_TO_U64(_sqn,_u) \ 39 | { \ 40 | _u.u64 = 0; \ 41 | _u.u8[2] = sqn[0]; \ 42 | _u.u8[3] = sqn[1]; \ 43 | _u.u8[4] = sqn[2]; \ 44 | _u.u8[5] = sqn[3]; \ 45 | _u.u8[6] = sqn[4]; \ 46 | _u.u8[7] = sqn[5]; \ 47 | } 48 | #define U64_TO_SQN(_u,_sqn) \ 49 | { \ 50 | _sqn[0] = _u.u8[2]; \ 51 | _sqn[1] = _u.u8[3]; \ 52 | _sqn[2] = _u.u8[4]; \ 53 | _sqn[3] = _u.u8[5]; \ 54 | _sqn[4] = _u.u8[6]; \ 55 | _sqn[5] = _u.u8[7]; \ 56 | } 57 | #endif 58 | 59 | class Utility 60 | { 61 | public: 62 | static std::string bytes2hex(const uint8_t *bytes, size_t len, char delim='\0', bool upper=false); 63 | }; 64 | 65 | 66 | #endif /* C3PO_HSS_INCLUDE_UTIL_H_ */ 67 | -------------------------------------------------------------------------------- /hss/logs/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | -------------------------------------------------------------------------------- /hss/prometheus/hssStats.json.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2020-present Open Networking Foundation 2 | 3 | SPDX-License-Identifier: Apache-2.0 4 | -------------------------------------------------------------------------------- /hss/smsrouter/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/smsrouter 3 | conf/*pem 4 | conf/demoCA 5 | out.txt 6 | logs 7 | -------------------------------------------------------------------------------- /hss/smsrouter/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/smsrouter 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++11 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | LIBS := \ 15 | $(ROOT)/util/lib/libc3po.a \ 16 | -lcares \ 17 | -lcassandra \ 18 | -lfdcore \ 19 | -lfdproto \ 20 | -lmemcached \ 21 | -lrt 22 | 23 | INCS := \ 24 | -I ./include \ 25 | -I $(ROOT)/util/include \ 26 | -I $(ROOT)/modules/spdlog/include 27 | 28 | $(TARGET): $(OBJECTS) 29 | @echo " Linking..." 30 | @mkdir -p $(BINDIR) 31 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 32 | 33 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 34 | @mkdir -p $(BUILDDIR) 35 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 36 | 37 | clean: 38 | @echo " Cleaning..."; 39 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 40 | 41 | -include $(DEPENDS) 42 | 43 | .PHONY: clean 44 | -------------------------------------------------------------------------------- /hss/smsrouter/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /hss/smsrouter/conf/sms.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "fdcfg": "conf/sms.conf", 4 | "originhost": "smsrouter.test3gpp.net", 5 | "originrealm": "test3gpp.net" 6 | }, 7 | "smsrouter": { 8 | "hsshost": "hss.openair4G.eur", 9 | "hssrealm": "openair4G.eur", 10 | "logsize": 20, 11 | "lognumber": 5, 12 | "logname": "logs/pcef.log", 13 | "logqsize": 8192 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /hss/smsrouter/include/s6c_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __S6C_IMPL_H 9 | #define __S6C_IMPL_H 10 | 11 | #include "s6c.h" 12 | 13 | namespace s6c { 14 | 15 | // Member functions that customize the individual application 16 | class Application : public ApplicationBase 17 | { 18 | friend SERIFSRreq; 19 | friend ALSCRreq; 20 | friend RESDSRreq; 21 | 22 | public: 23 | Application(); 24 | ~Application(); 25 | 26 | //SERIFSRcmd &getSERIFSRcmd() { return m_cmd_serifsr; } 27 | //ALSCRcmd &getALSCRcmd() { return m_cmd_alscr; } 28 | //RESDSRcmd &getRESDSRcmd() { return m_cmd_resdsr; } 29 | 30 | // Parameters for sendXXXreq, if present below, may be changed 31 | // based upon processing needs 32 | bool sendSERIFSRreq( bool withMsisdn, bool withImsi ); 33 | bool sendALSCRreq(FDPeer &peer); 34 | bool sendRESDSRreq(FDPeer &peer); 35 | 36 | private: 37 | void registerHandlers(); 38 | //SERIFSRcmd m_cmd_serifsr; 39 | //ALSCRcmd m_cmd_alscr; 40 | //RESDSRcmd m_cmd_resdsr; 41 | 42 | // the parameters for createXXXreq, if present below, may be 43 | // changed based processing needs 44 | SERIFSRreq *createSERIFSRreq( bool withMsisdn, bool withImsi ); 45 | ALSCRreq *createALSCRreq(FDPeer &peer); 46 | RESDSRreq *createRESDSRreq(FDPeer &peer); 47 | }; 48 | 49 | } 50 | 51 | #endif // __S6C_IMPL_H 52 | -------------------------------------------------------------------------------- /hss/smsrouter/include/sgd_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SGD_IMPL_H 9 | #define __SGD_IMPL_H 10 | 11 | #include "sgd.h" 12 | 13 | namespace sgd { 14 | 15 | // Member functions that customize the individual application 16 | class Application : public ApplicationBase 17 | { 18 | friend MOFSMRreq; 19 | friend MTFSMRreq; 20 | friend ALSCRreq; 21 | 22 | public: 23 | Application(); 24 | ~Application(); 25 | 26 | MOFSMRcmd &getMOFSMRcmd() { return m_cmd_mofsmr; } 27 | //MTFSMRcmd &getMTFSMRcmd() { return m_cmd_mtfsmr; } 28 | //ALSCRcmd &getALSCRcmd() { return m_cmd_alscr; } 29 | 30 | // Parameters for sendXXXreq, if present below, may be changed 31 | // based upon processing needs 32 | bool sendMOFSMRreq(FDPeer &peer); 33 | bool sendMTFSMRreq(MoForwardShortMessageRequestExtractor &ofr); 34 | bool sendALSCRreq(FDPeer &peer); 35 | 36 | private: 37 | void registerHandlers(); 38 | MOFSMRcmd m_cmd_mofsmr; 39 | //MTFSMRcmd m_cmd_mtfsmr; 40 | //ALSCRcmd m_cmd_alscr; 41 | 42 | // the parameters for createXXXreq, if present below, may be 43 | // changed based processing needs 44 | MOFSMRreq *createMOFSMRreq(FDPeer &peer); 45 | MTFSMRreq *createMTFSMRreq(MoForwardShortMessageRequestExtractor &ofr); 46 | ALSCRreq *createALSCRreq(FDPeer &peer); 47 | }; 48 | 49 | } 50 | 51 | #endif // __SGD_IMPL_H 52 | -------------------------------------------------------------------------------- /hss/smsrouter/include/sms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SMSROUTER_H 9 | #define __SMSROUTER_H 10 | 11 | #include "s6c_impl.h" 12 | #include "sgd_impl.h" 13 | 14 | class SMSRouter 15 | { 16 | public: 17 | SMSRouter(); 18 | ~SMSRouter(); 19 | 20 | bool init(); 21 | void uninit(); 22 | 23 | void waitForShutdown(); 24 | 25 | s6c::Application &s6cApp() { return *m_s6c; } 26 | sgd::Application &sgdApp() { return *m_sgd; } 27 | 28 | private: 29 | FDEngine m_diameter; 30 | 31 | s6c::Application *m_s6c; 32 | sgd::Application *m_sgd; 33 | bool m_repetitive; 34 | }; 35 | 36 | #endif // #define __SMSROUTER_H 37 | -------------------------------------------------------------------------------- /hss/src/util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "util.h" 13 | 14 | std::string Utility::bytes2hex( const uint8_t *bytes, size_t len, char delim, bool upper ) 15 | { 16 | static const char *hexl = "0123456789abcdef"; 17 | static const char *hexu = "0123456789ABCDEF"; 18 | 19 | size_t olen(delim ? 3 : 2); 20 | const char *hexc(upper ? hexu : hexl); 21 | char hex[ len * olen + 1 ]; 22 | 23 | for (size_t i=0; i> 4) & 0x0f ]; 26 | hex[i * olen + 1] = hexc[ bytes[i] & 0x0f ]; 27 | if ( delim ) 28 | hex[i * olen + 2] = delim; 29 | } 30 | hex[len * olen] = '\0'; 31 | 32 | return std::string(hex); 33 | } 34 | -------------------------------------------------------------------------------- /hssgtw/.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | bin/* 3 | conf/*pem 4 | conf/demoCA 5 | -------------------------------------------------------------------------------- /hssgtw/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/hssgtw 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++14 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | LIBS := \ 15 | $(ROOT)/util/lib/libc3po.a \ 16 | $(ROOT)/hsssec/lib/libhsssec.a \ 17 | -l:libpistache.a \ 18 | -lcassandra \ 19 | -lfdcore \ 20 | -lfdproto \ 21 | -lgmp \ 22 | -lnettle \ 23 | -lrt 24 | 25 | INCS := \ 26 | -I ./include \ 27 | -I $(ROOT)/util/include \ 28 | -I $(ROOT)/hsssec/include \ 29 | 30 | $(TARGET): $(OBJECTS) 31 | @echo " Linking..." 32 | @mkdir -p $(BINDIR) 33 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 34 | 35 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 36 | @mkdir -p $(BUILDDIR) 37 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 38 | 39 | clean: 40 | @echo " Cleaning..."; 41 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 42 | 43 | -include $(DEPENDS) 44 | 45 | .PHONY: clean 46 | -------------------------------------------------------------------------------- /hssgtw/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | C3PO: HSSGTW Build and Run Instructions 3 | --- 4 | Perform the following procedures in order. 5 | 1. Follow the instructions located in the **_"Build and Installation Instructions for External Modules"_** provided in _{installation_root}/c3po/README.md_. Make sure these steps are complete. 6 | 2. Build **HSSGTW**. 7 | 8 | $ cd {isntallation_root}/c3po/hssgtw 9 | $ make 10 | 3. Update the following files with any configuration changes: 11 | + {installation_root}/c3po/hssgtw/conf/hssgtw.json 12 | 4. To run the application: 13 | 14 | cd {installation_root}/c3po/hssgtw 15 | bin/hssgtw -j conf/hssgtw.json 16 | 17 | -------------------------------------------------------------------------------- /hssgtw/README.txt: -------------------------------------------------------------------------------- 1 | C3PO: HSSGTW Build and Run Instructions 2 | 3 | Perform the following procedures in order. 4 | 5 | 1. Follow the instructions located in the "Build and Installation 6 | Instructions for External Modules" provided in 7 | {installation_root}/c3po/README.md_. Make sure these steps are complete. 8 | 9 | 2. Build HSSGTW. 10 | 11 | $ cd {isntallation_root}/c3po/hssgtw 12 | $ make 13 | 14 | 3. Update the following files with any configuration changes: 15 | 16 | {installation_root}/c3po/hssgtw/conf/hssgtw.json 17 | 18 | 4. To run the application: 19 | 20 | cd {installation_root}/c3po/hssgtw 21 | bin/hssgtw -j conf/hssgtw.json 22 | 23 | -------------------------------------------------------------------------------- /hssgtw/conf/hssgtw.json: -------------------------------------------------------------------------------- 1 | {"common": { 2 | }, 3 | "hssgtw": { 4 | "gtwhost": "*", 5 | "gtwport" : 9081, 6 | "casssrv": "10.31.14.79", 7 | "cassusr": "root", 8 | "casspwd": "root", 9 | "cassdb" : "oai_db", 10 | "userschema" : "./conf/user-imsi-schema.json", 11 | "hss_target_host" : "localhost", 12 | "hss_target_port" : 9080 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /hssgtw/etc/delete_imsi.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | curl -X DELETE http://localhost:9081/imsis/string 9 | -------------------------------------------------------------------------------- /hssgtw/etc/insert_imsi.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | curl -d '{"imsi":"string","access_restriction":0,"idmmeidentity":0,"imei":"string","imei_sv":"string","key":"string","lipa_permissions":"string","mme_cap":0,"mmehost":"string","mmeidentity_idmmeidentity":0,"mmerealm":"string","ms_ps_status":"string","msisdn":0,"niddvalidity":"string","nir_dest_host":"string","nir_dest_realm":"string","opc":"string","pgw_id":0,"rand":"string","rfsp_index":0,"sqn":0,"subscription_data":"string","ue_reachability":0,"urrp_mme":0,"user_identifier":"string","visited_plmnid":"string"}' http://localhost:9081/imsis 9 | -------------------------------------------------------------------------------- /hssgtw/etc/update_imsi.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | curl -X PUT -d '{"imsi":"string","access_restriction":10,"idmmeidentity":0,"imei":"string","imei_sv":"string_up","key":"string","lipa_permissions":"string","mme_cap":0,"mmehost":"string","mmeidentity_idmmeidentity":0,"mmerealm":"string","ms_ps_status":"string","msisdn":0,"niddvalidity":"string","nir_dest_host":"string","nir_dest_realm":"string","opc":"string","pgw_id":0,"rand":"string","rfsp_index":0,"sqn":0,"subscription_data":"string","ue_reachability":0,"urrp_mme":0,"user_identifier":"string","visited_plmnid":"string"}' http://localhost:9081/imsis 9 | -------------------------------------------------------------------------------- /hssgtw/include/jsonvalidator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef HSSGTW_INCLUDE_JSONVALIDATOR_H_ 9 | #define HSSGTW_INCLUDE_JSONVALIDATOR_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #define RAPIDJSON_NAMESPACE hssrapidjson 16 | #include "rapidjson/filereadstream.h" 17 | #include "rapidjson/document.h" 18 | #include "rapidjson/schema.h" 19 | #include "rapidjson/stringbuffer.h" 20 | #include "rapidjson/writer.h" 21 | 22 | class JsonValidator { 23 | 24 | public: 25 | 26 | static JsonValidator& getInstance(); 27 | 28 | bool readDocFromPath(RAPIDJSON_NAMESPACE::Document& doc, const std::string& path ); 29 | 30 | bool readDocFromString(RAPIDJSON_NAMESPACE::Document& doc, std::string& json ); 31 | 32 | bool validate(std::string &keyschema, RAPIDJSON_NAMESPACE::Document& docData); 33 | 34 | bool validate(RAPIDJSON_NAMESPACE::Document& docSchema, RAPIDJSON_NAMESPACE::Document& docData); 35 | 36 | RAPIDJSON_NAMESPACE::Document* getSchema(std::string &key); 37 | 38 | void addSchema(std::string &key, RAPIDJSON_NAMESPACE::Document* schema); 39 | 40 | private: 41 | 42 | std::map m_jsonschemas; 43 | 44 | }; 45 | 46 | 47 | 48 | #endif /* HSSGTW_INCLUDE_JSONVALIDATOR_H_ */ 49 | -------------------------------------------------------------------------------- /hssgtw/include/provisionhandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #ifndef HSSGTW_INCLUDE_PROVISIONHANDLER_H_ 10 | #define HSSGTW_INCLUDE_PROVISIONHANDLER_H_ 11 | 12 | #include 13 | #include 14 | #include "db.h" 15 | 16 | #include 17 | 18 | #define RAPIDJSON_NAMESPACE hssrapidjson 19 | #include "rapidjson/filereadstream.h" 20 | #include "rapidjson/document.h" 21 | 22 | extern RAPIDJSON_NAMESPACE::Document docSchema; 23 | 24 | class ProvisionHandler : public Pistache::Http::Handler { 25 | 26 | public: 27 | HTTP_PROTOTYPE(ProvisionHandler) 28 | 29 | void onRequest(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter response); 30 | 31 | void fillEvent(RAPIDJSON_NAMESPACE::Document &document, const char *imsi, int64_t msisdn, 32 | const char *prev_imei, const char *prev_imei_sv, const char *new_imei, const char *new_imei_sv); 33 | void fillBody(RAPIDJSON_NAMESPACE::Document &document, std::string &jsonbody); 34 | 35 | }; 36 | 37 | #endif /* HSSGTW_INCLUDE_PROVISIONHANDLER_H_ */ 38 | -------------------------------------------------------------------------------- /hssgtw/include/restclient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | 10 | #ifndef HSSGTW_INCLUDE_RESTCLIENT_H_ 11 | #define HSSGTW_INCLUDE_RESTCLIENT_H_ 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | class RestClient { 20 | 21 | public: 22 | static RestClient& getInstance(); 23 | void post(std::string &url, std::string &body); 24 | 25 | private: 26 | RestClient(); 27 | Pistache::Http::Client m_restclient; 28 | }; 29 | 30 | 31 | #endif /* HSSGTW_INCLUDE_RESTCLIENT_H_ */ 32 | -------------------------------------------------------------------------------- /hssgtw/src/restclient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #include "restclient.h" 10 | 11 | RestClient& RestClient::getInstance(){ 12 | static RestClient instance; 13 | return instance; 14 | } 15 | 16 | 17 | void RestClient::post(std::string &url, std::string &body){ 18 | 19 | std::cout << "sending request" << std::endl; 20 | auto resp = m_restclient.post(url).body(body).send(); 21 | resp.then([&](Pistache::Http::Response response) { 22 | std::cout << "Response code = " << response.code() << std::endl; 23 | auto body = response.body(); 24 | if (!body.empty()) 25 | std::cout << "Response body = " << body << std::endl; 26 | }, Pistache::Async::IgnoreException); 27 | 28 | } 29 | 30 | RestClient::RestClient(){ 31 | //TOO move these harcoded values to options 32 | auto opts = Pistache::Http::Client::options() 33 | .threads(1) 34 | .maxConnectionsPerHost(8); 35 | m_restclient.init(opts); 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /hsssec/.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | lib/* 3 | 4 | -------------------------------------------------------------------------------- /hsssec/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc # This is the main compiler 2 | SRCDIR := src 3 | BUILDDIR := build 4 | TARGETDIR := lib 5 | LIBNAME := libhsssec.a 6 | TARGET := $(TARGETDIR)/$(LIBNAME) 7 | INSTDIRINC := /usr/local/include/hsssec 8 | INSTDIRLIB := /usr/local/lib 9 | INSTLIB := $(INSTDIRLIB)/$(LIBNAME) 10 | 11 | SECURITY_FLAGS := -D_FORTIFY_SOURCE=2 -fasynchronous-unwind-tables -fexceptions 12 | SECURITY_FLAGS += -fstack-protector-all -fstack-protector-strong -Wall 13 | SECURITY_FLAGS += -Werror=format-security -Werror=implicit-function-declaration 14 | 15 | SRCEXT := c 16 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 17 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 18 | DEPENDS := $(OBJECTS:%.o=%.d) 19 | CFLAGS := -std=c99 -Wreturn-type -g -pthread -lrt -DNODEBUG $(SECURITY_FLAGS)# -Wall 20 | INC := -I include 21 | 22 | $(TARGET): $(OBJECTS) 23 | @echo " Linking..." 24 | @mkdir -p $(TARGETDIR) 25 | @echo " ar rcs $(TARGET) $(OBJECTS)"; ar rcs $(TARGET) $(OBJECTS) 26 | 27 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) Makefile 28 | @mkdir -p $(BUILDDIR) 29 | @echo " $(CC) $(CFLAGS) $(INC) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -MMD -c -o $@ $< 30 | 31 | clean: 32 | @echo " Cleaning..."; 33 | @echo " $(RM) -r $(BUILDDIR) $(TARGETDIR)"; $(RM) -r $(BUILDDIR) $(TARGETDIR) 34 | 35 | install: $(TARGET) 36 | @echo " Installing..." 37 | @echo " creating/verifying $(INSTDIRINC)" 38 | @mkdir -p $(INSTDIRINC) 39 | @echo " copying headers to $(INSTDIRINC)" 40 | @cp -a include/* $(INSTDIRINC) 41 | @echo " creating/verifying $(INSTDIRLIB)" 42 | @mkdir -p $(INSTDIRLIB) 43 | @echo " copying $(TARGET) to $(INSTLIB)" 44 | @cp -a $(TARGET) $(INSTLIB) 45 | @echo " Installation complete" 46 | 47 | -include $(DEPENDS) 48 | 49 | .PHONY: clean 50 | -------------------------------------------------------------------------------- /hsssec/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | C3PO: HSSSEC Library Build Instructions 3 | --- 4 | Perform the following procedures in order. 5 | 1. Follow the instructions located in the **_"Build and Installation Instructions for External Modules"_** provided in _{installation_root}/c3po/README.md_. Make sure these steps are complete. 6 | 2. Build HSSSEC. 7 | 8 | cd {installation_root}/c3po/hsssec 9 | make 10 | -------------------------------------------------------------------------------- /hsssec/README.txt: -------------------------------------------------------------------------------- 1 | C3PO: HSSSEC Library Build Instructions 2 | 3 | Perform the following procedures in order. 4 | 1. Follow the instructions located in the "Build and Installation 5 | Instructions for External Modules" provided in 6 | {installation_root}/c3po/README.txt. Make sure these steps are complete. 7 | 8 | 2. Build HSSSEC. 9 | 10 | cd {installation_root}/c3po/hsssec 11 | make 12 | -------------------------------------------------------------------------------- /hsssec/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | if [ $# -ne 2 ] 9 | then 10 | echo usage: make_certs.sh diameter_host_name diameter_realm_name 11 | exit 12 | fi 13 | 14 | rm -rf demoCA 15 | mkdir demoCA 16 | echo 01 > demoCA/serial 17 | touch demoCA/index.txt 18 | 19 | HOST=$1 20 | DOMAIN=$2 21 | 22 | # CA self certificate 23 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 24 | 25 | # 26 | openssl genrsa -out $HOST.key.pem 1024 27 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 28 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 29 | 30 | -------------------------------------------------------------------------------- /hsssec/include/access_restriction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The OpenAirInterface Software Alliance licenses this file to You under 6 | * the Apache License, Version 2.0 (the "License"); you may not use this file 7 | * except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *------------------------------------------------------------------------------- 18 | * For more information about the OpenAirInterface (OAI) Software Alliance: 19 | * contact@openairinterface.org 20 | */ 21 | 22 | #ifndef ACCESS_RESTRICTION_H_ 23 | #define ACCESS_RESTRICTION_H_ 24 | 25 | int split_plmn(uint8_t *plmn, uint8_t mcc[3], uint8_t mnc[3]); 26 | 27 | int apply_access_restriction(char *imsi, uint8_t *vplmn); 28 | 29 | #endif /* ACCESS_RESTRICTION_H_ */ 30 | -------------------------------------------------------------------------------- /hsssec/include/aucpp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The OpenAirInterface Software Alliance licenses this file to You under 6 | * the Apache License, Version 2.0 (the "License"); you may not use this file 7 | * except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *------------------------------------------------------------------------------- 18 | * For more information about the OpenAirInterface (OAI) Software Alliance: 19 | * contact@openairinterface.org 20 | */ 21 | 22 | #ifndef AUCPP_H_ 23 | #define AUCPP_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | typedef struct { 30 | uint8_t rand[16]; 31 | uint8_t rand_new; 32 | uint8_t xres[8]; 33 | uint8_t autn[16]; 34 | uint8_t kasme[32]; 35 | } auc_vector_t; 36 | 37 | uint8_t *sqn_ms_derive_cpp(const uint8_t opc[16], uint8_t *key, uint8_t *auts, uint8_t *rand); 38 | 39 | void generate_random_cpp(uint8_t *random, ssize_t length); 40 | 41 | int generate_vector_cpp(const uint8_t opc[16], uint64_t imsi, uint8_t key[16], uint8_t plmn[3], 42 | uint8_t sqn[6], auc_vector_t *vector); 43 | 44 | void random_init(void); 45 | 46 | 47 | #endif /* AUCPP_H_ */ 48 | -------------------------------------------------------------------------------- /hsssec/include/conversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The OpenAirInterface Software Alliance licenses this file to You under 6 | * the Apache License, Version 2.0 (the "License"); you may not use this file 7 | * except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *------------------------------------------------------------------------------- 18 | * For more information about the OpenAirInterface (OAI) Software Alliance: 19 | * contact@openairinterface.org 20 | */ 21 | 22 | #ifndef CONVERSION_H_ 23 | #define CONVERSION_H_ 24 | 25 | void hexa_to_ascii(uint8_t *from, char *to, size_t length); 26 | int ascii_to_hex(uint8_t *dst, const char *h); 27 | int bcd_to_hex(uint8_t *dst, const char *h, int h_length); 28 | 29 | #endif /* CONVERSION_H_ */ 30 | -------------------------------------------------------------------------------- /hsssec/include/hss_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The OpenAirInterface Software Alliance licenses this file to You under 6 | * the Apache License, Version 2.0 (the "License"); you may not use this file 7 | * except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *------------------------------------------------------------------------------- 18 | * For more information about the OpenAirInterface (OAI) Software Alliance: 19 | * contact@openairinterface.org 20 | */ 21 | 22 | #ifndef HSS_CONFIG_H_ 23 | #define HSS_CONFIG_H_ 24 | #include "stdbool.h" 25 | 26 | typedef struct hss_config_s { 27 | char *cassandra_server; 28 | char *cassandra_user; 29 | char *cassandra_password; 30 | char *cassandra_database; 31 | 32 | 33 | char *operator_key; 34 | unsigned char operator_key_bin[16]; 35 | int valid_op; 36 | 37 | /* The freediameter configuration file */ 38 | char *freediameter_config; 39 | 40 | /* THe HSS global configuration file */ 41 | char *config; 42 | 43 | char *random; 44 | char random_bool; 45 | bool verify_roaming; 46 | short int prom_port; 47 | } hss_config_t; 48 | 49 | //int hss_config_init(int argc, char *argv[], hss_config_t *hss_config_p); 50 | 51 | #endif /* HSS_CONFIG_H_ */ 52 | -------------------------------------------------------------------------------- /hsssec/src/aucpp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The OpenAirInterface Software Alliance licenses this file to You under 6 | * the Apache License, Version 2.0 (the "License"); you may not use this file 7 | * except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *------------------------------------------------------------------------------- 18 | * For more information about the OpenAirInterface (OAI) Software Alliance: 19 | * contact@openairinterface.org 20 | */ 21 | 22 | #include "aucpp.h" 23 | #include "auc.h" 24 | 25 | uint8_t * 26 | sqn_ms_derive_cpp ( 27 | const uint8_t opc[16], 28 | uint8_t * key, 29 | uint8_t * auts, 30 | uint8_t * rand_p) 31 | { 32 | return sqn_ms_derive(opc, key, auts, rand_p); 33 | } 34 | 35 | void 36 | generate_random_cpp ( 37 | uint8_t * random_p, 38 | ssize_t length) 39 | { 40 | generate_random(random_p, length); 41 | } 42 | 43 | int generate_vector_cpp(const uint8_t opc[16], uint64_t imsi, uint8_t key[16], uint8_t plmn[3], 44 | uint8_t sqn[6], auc_vector_t *vector){ 45 | return generate_vector(opc, imsi, key, plmn, sqn, vector); 46 | } 47 | -------------------------------------------------------------------------------- /install_rundeps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019-present Open Networking Foundation 3 | # SPDX-License-Identifier: Apache-2.0 4 | # Copyright (c) 2019 Intel Corporation 5 | 6 | SUDO='' 7 | [[ $EUID -ne 0 ]] && SUDO=sudo 8 | 9 | update_pkg_cache() { 10 | $SUDO apt-get update 11 | } 12 | 13 | install_run_cdf_deps() { 14 | $SUDO apt-get -y install \ 15 | libgnutls30 \ 16 | libidn11 17 | } 18 | 19 | install_run_ctf_deps() { 20 | $SUDO apt-get -y install \ 21 | libgnutls30 \ 22 | libidn11 \ 23 | libmemcached11 24 | } 25 | 26 | install_run_hss_deps() { 27 | $SUDO apt-get -y install \ 28 | libgmp10 \ 29 | libgnutls30 \ 30 | libidn11 \ 31 | libnettle6 \ 32 | libssl1.0.0 \ 33 | libuv1 \ 34 | openssl 35 | } 36 | 37 | install_run_hssgtw_deps() { 38 | $SUDO apt-get -y install \ 39 | libssl1.0.0 \ 40 | libuv1 41 | } 42 | 43 | install_run_pcrf_deps() { 44 | $SUDO apt-get -y install \ 45 | libgmp10 \ 46 | libgnutls30 \ 47 | libidn11 \ 48 | libnettle6 \ 49 | libssl1.0.0 \ 50 | libuv1 51 | } 52 | 53 | install_run_pcef_deps() { 54 | $SUDO apt-get -y install \ 55 | libgnutls30 \ 56 | libidn11 57 | } 58 | 59 | install_run_tdf_deps() { 60 | $SUDO apt-get -y install \ 61 | libgnutls30 \ 62 | libidn11 63 | } 64 | 65 | install_run_tssf_deps() { 66 | $SUDO apt-get -y install \ 67 | libgnutls30 \ 68 | libidn11 69 | } 70 | 71 | install_run_utils() { 72 | $SUDO apt-get -y install \ 73 | dnsutils \ 74 | iproute2 \ 75 | iputils-ping \ 76 | tcpdump 77 | } 78 | 79 | cleanup_image() { 80 | $SUDO rm -rf /var/lib/apt/lists/* 81 | } 82 | 83 | (return 2>/dev/null) && echo "Sourced" && return 84 | -------------------------------------------------------------------------------- /patches/pistache.patch.1.txt: -------------------------------------------------------------------------------- 1 | diff --git a/include/pistache/router.h b/include/pistache/router.h 2 | index 7ca53a3..667c665 100644 3 | --- a/include/pistache/router.h 4 | +++ b/include/pistache/router.h 5 | @@ -330,8 +330,7 @@ template 6 | struct BindChecks { 7 | constexpr static bool request_check = 8 | std::is_const::type>::value && 9 | - std::is_lvalue_reference::type>::value && 10 | - std::is_same::type, Rest::Request>::value; 11 | + std::is_lvalue_reference::type>::value; 12 | 13 | constexpr static bool response_check = 14 | !std::is_const::type>::value && 15 | diff --git a/include/pistache/string_logger.h b/include/pistache/string_logger.h 16 | index a60f88f..3f55ecf 100644 17 | --- a/include/pistache/string_logger.h 18 | +++ b/include/pistache/string_logger.h 19 | @@ -15,7 +15,7 @@ namespace Log { 20 | 21 | enum class Level { 22 | TRACE, 23 | - DEBUG, 24 | + DEBUG1, 25 | INFO, 26 | WARN, 27 | ERROR, 28 | -------------------------------------------------------------------------------- /pcrf/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/pcrf 3 | gmon.out 4 | conf/*pem 5 | conf/demoCA 6 | out.txt 7 | logs 8 | -------------------------------------------------------------------------------- /pcrf/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/pcrf 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++14 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | 15 | LIBS := \ 16 | $(ROOT)/util/lib/libc3po.a \ 17 | -l:libpistache.a \ 18 | -lcares \ 19 | -lcassandra \ 20 | -lfdcore \ 21 | -lfdproto \ 22 | -lmemcached \ 23 | -lrt 24 | 25 | INCS := \ 26 | -I ./include \ 27 | -I $(ROOT)/util/include \ 28 | -I $(ROOT)/modules/spdlog/include 29 | 30 | all: $(TARGET) 31 | $(MAKE) -C pcef 32 | $(MAKE) -C tdf 33 | $(MAKE) -C tssf 34 | 35 | $(TARGET): $(OBJECTS) 36 | @echo " Linking..." 37 | @mkdir -p $(BINDIR) 38 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 39 | 40 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 41 | @mkdir -p $(BUILDDIR) 42 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 43 | 44 | clean: 45 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 46 | $(MAKE) -C pcef clean 47 | $(MAKE) -C tdf clean 48 | $(MAKE) -C tssf clean 49 | 50 | -include $(DEPENDS) 51 | 52 | .PHONY: clean 53 | -------------------------------------------------------------------------------- /pcrf/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /pcrf/conf/oss.json: -------------------------------------------------------------------------------- 1 | { 2 | "option": { 3 | "id": "url", 4 | "type": "string" 5 | }, 6 | "services": [ 7 | { 8 | "id": "logger", 9 | "commands": [ 10 | { 11 | "id": "describe_loggers" 12 | }, 13 | { 14 | "id": "set_logger_level", 15 | "options": [ 16 | { 17 | "id": "name", 18 | "type": "string" 19 | }, 20 | { 21 | "id": "level", 22 | "type": "integer" 23 | } 24 | ] 25 | } 26 | ] 27 | }, 28 | { 29 | "id": "stats", 30 | "commands": [ 31 | { 32 | "id": "describe_stats_frequency" 33 | }, 34 | { 35 | "id": "describe_stats_live" 36 | }, 37 | { 38 | "id": "set_stats_frequency", 39 | "options": [ 40 | { 41 | "id": "frequency", 42 | "type": "integer" 43 | } 44 | ] 45 | } 46 | ] 47 | } 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /pcrf/conf/pcrf.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "fdcfg": "conf/pcrf.conf", 4 | "originhost": "pcrf.test3gpp.net", 5 | "originrealm": "test3gpp.net" 6 | }, 7 | "pcrf": { 8 | "hsshost": "hss.localdomain", 9 | "hssrealm": "localdomain", 10 | "casshost": "192.168.33.10", 11 | "casskeyspace": "pcrf", 12 | "logsize": 20, 13 | "lognumber": 5, 14 | "logname": "logs/c3popcrf.log", 15 | "logqsize": 8192, 16 | "selfredirect": false, 17 | "enableruletimers": true, 18 | "rulecallbackport": 9081, 19 | "rulecallbackthreads": 1, 20 | "rulecallbackurl": "http://192.168.33.18:9081/ruleTimer", 21 | "chronosapiurl": "http://192.168.33.17:7253", 22 | "statlogsize": 20, 23 | "statlognumber": 5, 24 | "statlogname": "logs/pcrf_stat.log", 25 | "auditlogsize": 20, 26 | "auditlognumber": 5, 27 | "auditlogname": "logs/pcrf_audit.log", 28 | "statfreq": 2000, 29 | "ossport" : 9082, 30 | "ossfile" : "conf/oss.json" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pcrf/include/bearer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __BEARER_H 9 | #define __BEARER_H 10 | 11 | #include 12 | #include 13 | 14 | #include "rule.h" 15 | 16 | class Bearer 17 | { 18 | public: 19 | Bearer() {} 20 | ~Bearer() {} 21 | 22 | int32_t getEBI() { return m_ebi; } 23 | int32_t setEBI( int32_t v ) { m_ebi = v; return getEBI(); } 24 | 25 | RulesList &getComputedRules() { return m_computed_rules; } 26 | RulesList &getActivateNow() { return m_activate_now; } 27 | RulesList &getPcefInstalled() { return m_pcef_installed; } 28 | RulesList &getTdfInstalled() { return m_tdf_installed; } 29 | RulesList &getTscInstalled() { return m_tsc_installed; } 30 | 31 | private: 32 | int32_t m_ebi; 33 | RulesList m_computed_rules; 34 | RulesList m_activate_now; 35 | RulesList m_pcef_installed; 36 | RulesList m_tdf_installed; 37 | RulesList m_tsc_installed; 38 | }; 39 | 40 | class BearerMap : public std::map 41 | { 42 | public: 43 | BearerMap(); 44 | ~BearerMap(); 45 | }; 46 | 47 | #endif // __BEARER_H 48 | -------------------------------------------------------------------------------- /pcrf/include/chronos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef PCRF_INCLUDE_CHRONOS_H_ 9 | #define PCRF_INCLUDE_CHRONOS_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | class ChronosHandler : public Pistache::Http::Handler 16 | { 17 | public: 18 | HTTP_PROTOTYPE(ChronosHandler) 19 | 20 | void onRequest( const Pistache::Http::Request& request, Pistache::Http::ResponseWriter response ); 21 | }; 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | //////////////////////////////////////////////////////////////////////////////// 25 | 26 | class ChronosLocation : public Pistache::Http::Header::Header 27 | { 28 | public: 29 | NAME( "Location" ) 30 | 31 | ChronosLocation() {} 32 | 33 | void parseRaw( const char *str, size_t len ) 34 | { 35 | m_location.assign( str, len ); 36 | } 37 | 38 | void write( std::ostream &os ) const 39 | { 40 | os << m_location; 41 | } 42 | 43 | const std::string &getLocation() const 44 | { 45 | return m_location; 46 | } 47 | 48 | private: 49 | std::string m_location; 50 | }; 51 | 52 | class Chronos 53 | { 54 | public: 55 | static void init(); 56 | static void uninit(); 57 | static Pistache::Http::Client &client() { return m_client; } 58 | 59 | private: 60 | static Pistache::Http::Client m_client; 61 | }; 62 | 63 | #endif /* PCRF_INCLUDE_CHRONOS_H_ */ 64 | -------------------------------------------------------------------------------- /pcrf/include/gx_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __GX_IMPL_H 9 | #define __GX_IMPL_H 10 | 11 | #include "gx.h" 12 | 13 | class PCRF; 14 | class GxSession; 15 | class SessionEvent; 16 | class RulesList; 17 | 18 | namespace gx { 19 | 20 | class GxRulesRARreq : public REARreq 21 | { 22 | public: 23 | GxRulesRARreq( Application &app, SessionEvent *event ); 24 | ~GxRulesRARreq(); 25 | 26 | void processAnswer( FDMessageAnswer &ans ); 27 | 28 | private: 29 | GxRulesRARreq(); 30 | 31 | SessionEvent *m_event; 32 | }; 33 | 34 | // Member functions that customize the individual application 35 | class Application : public ApplicationBase 36 | { 37 | friend CRCRreq; 38 | friend REARreq; 39 | 40 | public: 41 | Application( PCRF &pcrf ); 42 | ~Application(); 43 | 44 | //CRCRcmd &getCRCRcmd() { return m_cmd_crcr; } 45 | //REARcmd &getREARcmd() { return m_cmd_rear; } 46 | 47 | // Parameters for sendXXXreq, if present below, may be changed 48 | // based upon processing needs 49 | bool sendREARreq(FDPeer &peer); 50 | bool sendRulesRARreq( GxSession &gx, RulesList &installRules, RulesList &removeRules, SessionEvent *event ); 51 | 52 | PCRF &getPCRF() { return m_pcrf; } 53 | 54 | private: 55 | void registerHandlers(); 56 | CRCRcmd m_cmd_crcr; 57 | //REARcmd m_cmd_rear; 58 | 59 | // the parameters for createXXXreq, if present below, may be 60 | // changed based processing needs 61 | REARreq *createREARreq(FDPeer &peer); 62 | GxRulesRARreq *createRulesRARreq( GxSession &gx, RulesList &installRules, RulesList &removeRules, SessionEvent *event ); 63 | 64 | PCRF &m_pcrf; 65 | }; 66 | 67 | } 68 | 69 | #endif // __GX_IMPL_H 70 | -------------------------------------------------------------------------------- /pcrf/include/msg_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | #ifndef PCRF_SRC_HOOKEVENT_H_ 10 | #define PCRF_SRC_HOOKEVENT_H_ 11 | 12 | #include "sstats.h" 13 | #include "freeDiameter/freeDiameter-host.h" 14 | #include "freeDiameter/libfdproto.h" 15 | #include "freeDiameter/libfdcore.h" 16 | 17 | #include "gx_impl.h" 18 | #include "rx_impl.h" 19 | #include "sd_impl.h" 20 | #include "st_impl.h" 21 | 22 | 23 | class HookEvent { 24 | public: 25 | static void init(SStats* stat, gx::Application *gx, rx::Application *rx, sd::Application *sd, st::Application *st); 26 | static void md_hook_cb_error(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 27 | static void md_hook_cb_ok(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 28 | 29 | private: 30 | 31 | static struct fd_hook_hdl *m_hdl[2]; 32 | static SStats *m_stat; 33 | static gx::Application *m_gx; 34 | static rx::Application *m_rx; 35 | static sd::Application *m_sd; 36 | static st::Application *m_st; 37 | 38 | }; 39 | 40 | #endif /* PCRF_SRC_HOOKEVENT_H_ */ 41 | -------------------------------------------------------------------------------- /pcrf/include/rx_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __RX_IMPL_H 9 | #define __RX_IMPL_H 10 | 11 | #include "rx.h" 12 | 13 | class PCRF; 14 | 15 | namespace rx { 16 | 17 | // Member functions that customize the individual application 18 | class Application : public ApplicationBase 19 | { 20 | friend AARreq; 21 | friend REARreq; 22 | friend SETRreq; 23 | friend ABSRreq; 24 | 25 | public: 26 | Application( PCRF &pcrf ); 27 | ~Application(); 28 | 29 | //AARcmd &getAARcmd() { return m_cmd_aar; } 30 | //REARcmd &getREARcmd() { return m_cmd_rear; } 31 | //SETRcmd &getSETRcmd() { return m_cmd_setr; } 32 | //ABSRcmd &getABSRcmd() { return m_cmd_absr; } 33 | 34 | // Parameters for sendXXXreq, if present below, may be changed 35 | // based upon processing needs 36 | bool sendAARreq(FDPeer &peer); 37 | bool sendREARreq(FDPeer &peer); 38 | bool sendSETRreq(FDPeer &peer); 39 | bool sendABSRreq(FDPeer &peer); 40 | 41 | private: 42 | Application(); 43 | 44 | void registerHandlers(); 45 | //AARcmd m_cmd_aar; 46 | //REARcmd m_cmd_rear; 47 | //SETRcmd m_cmd_setr; 48 | //ABSRcmd m_cmd_absr; 49 | 50 | // the parameters for createXXXreq, if present below, may be 51 | // changed based processing needs 52 | AARreq *createAARreq(FDPeer &peer); 53 | REARreq *createREARreq(FDPeer &peer); 54 | SETRreq *createSETRreq(FDPeer &peer); 55 | ABSRreq *createABSRreq(FDPeer &peer); 56 | 57 | PCRF &m_pcrf; 58 | }; 59 | 60 | } 61 | 62 | #endif // __RX_IMPL_H 63 | -------------------------------------------------------------------------------- /pcrf/include/statpcrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef HSS_SRC_STATPCRF_H_ 9 | #define HSS_SRC_STATPCRF_H_ 10 | 11 | #include "sstats.h" 12 | #include "stimer.h" 13 | 14 | 15 | class StatsPcrf : public SStats { 16 | public: 17 | 18 | virtual ~StatsPcrf(); 19 | 20 | static void initstats(SLogger* statlogger) { singleton().setStatLogger(statlogger); }; 21 | static StatsPcrf &singleton() { if (!m_singleton) m_singleton = new StatsPcrf(); return *m_singleton; } 22 | void getSerializedStat(std::string& stats); 23 | void dispatchDerived(SEventThreadMessage &msg); 24 | void resetStats(); 25 | void processStatResult(StatResultMessage& stat); 26 | void processStatAttemp(StatAttempMessage& stat); 27 | void processStatGetLive(StatLive& msg); 28 | 29 | private: 30 | 31 | StatsPcrf(); 32 | 33 | static StatsPcrf *m_singleton; 34 | 35 | StatCollector m_gx_ccr_collector; 36 | StatCollector m_gx_rar_collector; 37 | StatCollector m_sd_tsr_collector; 38 | StatCollector m_sd_rar_collector; 39 | StatCollector m_sd_ccr_collector; 40 | StatCollector m_st_tsr_collector; 41 | StatCollector m_st_str_collector; 42 | 43 | uint32_t m_max_codes_tracked; 44 | 45 | }; 46 | 47 | #endif /* HSS_SRC_STATPCRF_H_ */ 48 | -------------------------------------------------------------------------------- /pcrf/pcef/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/pcef 3 | gmon.out 4 | conf/*pem 5 | conf/demoCA 6 | out.txt 7 | logs 8 | -------------------------------------------------------------------------------- /pcrf/pcef/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/pcef 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++14 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | LIBS := \ 15 | $(ROOT)/util/lib/libc3po.a \ 16 | -lcares \ 17 | -lcassandra \ 18 | -lfdcore \ 19 | -lfdproto \ 20 | -lmemcached \ 21 | -lrt 22 | 23 | INCS := \ 24 | -I ./include \ 25 | -I ./include/spdlog \ 26 | -I $(ROOT)/util/include \ 27 | -I $(ROOT)/modules/spdlog/include 28 | 29 | $(TARGET): $(OBJECTS) 30 | @echo " Linking..." 31 | @mkdir -p $(BINDIR) 32 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 33 | 34 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 35 | @mkdir -p $(BUILDDIR) 36 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 37 | 38 | clean: 39 | @echo " Cleaning..."; 40 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 41 | 42 | -include $(DEPENDS) 43 | 44 | .PHONY: clean 45 | -------------------------------------------------------------------------------- /pcrf/pcef/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /pcrf/pcef/conf/pcef.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "fdcfg": "conf/pcef.conf", 4 | "originhost": "pcef.test3gpp.net", 5 | "originrealm": "test3gpp.net" 6 | }, 7 | "pcef": { 8 | "pcrfhost": "pcrf.test3gpp.net", 9 | "pcrfrealm": "test3gpp.net", 10 | "casshost": "10.31.14.79", 11 | "casskeyspace": "pcrf", 12 | "logsize": 20, 13 | "lognumber": 5, 14 | "logname": "logs/pcef.log", 15 | "logqsize": 8192 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pcrf/pcef/include/gx_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __GX_IMPL_H 9 | #define __GX_IMPL_H 10 | 11 | #include "gx.h" 12 | 13 | class PCEF; 14 | 15 | namespace gx { 16 | 17 | // Member functions that customize the individual application 18 | class Application : public ApplicationBase 19 | { 20 | friend CRCRreq; 21 | friend REARreq; 22 | 23 | public: 24 | Application( PCEF &pcef ); 25 | ~Application(); 26 | 27 | //CRCRcmd &getCRCRcmd() { return m_cmd_crcr; } 28 | REARcmd &getREARcmd() { return m_cmd_rear; } 29 | 30 | // Parameters for sendXXXreq, if present below, may be changed 31 | // based upon processing needs 32 | bool sendCRCRreq( int32_t ccRequestType ); 33 | //bool sendREARreq(FDPeer &peer); 34 | 35 | PCEF &getPCEF() { return m_pcef; } 36 | std::string &getSessionId() { return m_sessionid; } 37 | 38 | private: 39 | Application(); 40 | 41 | void registerHandlers(); 42 | //CRCRcmd m_cmd_crcr; 43 | REARcmd m_cmd_rear; 44 | 45 | // the parameters for createXXXreq, if present below, may be 46 | // changed based processing needs 47 | CRCRreq *createCRCRreq( int32_t ccRequestType ); 48 | //REARreq *createREARreq(FDPeer &peer); 49 | 50 | PCEF &m_pcef; 51 | std::string m_sessionid; 52 | }; 53 | 54 | } 55 | 56 | #endif // __GX_IMPL_H 57 | -------------------------------------------------------------------------------- /pcrf/pcef/include/pcef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __PCEF_H 9 | #define __PCEF_H 10 | 11 | #include "gx_impl.h" 12 | 13 | class PCEF 14 | { 15 | public: 16 | PCEF(); 17 | ~PCEF(); 18 | 19 | bool init(); 20 | void uninit(); 21 | 22 | void waitForShutdown(); 23 | 24 | gx::Application &gxApp() { return *m_gx; } 25 | 26 | bool getRepetitive() { return m_repetitive; } 27 | bool setRepetitive( bool v ) { return m_repetitive = v; } 28 | 29 | private: 30 | FDEngine m_diameter; 31 | 32 | gx::Application *m_gx; 33 | bool m_repetitive; 34 | }; 35 | 36 | #endif // #define __PCEF_H 37 | -------------------------------------------------------------------------------- /pcrf/src/apn.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include "apn.h" 9 | 10 | ApnMap::ApnMap() 11 | { 12 | } 13 | 14 | ApnMap::~ApnMap() 15 | { 16 | ApnMap::iterator it; 17 | 18 | while ( (it = begin()) != end() ) 19 | { 20 | delete it->second; 21 | erase( it ); 22 | } 23 | } 24 | 25 | bool ApnMap::getApn( const std::string &apn, Apn* &papn ) 26 | { 27 | auto it = find( apn ); 28 | if ( it == end() ) 29 | return false; 30 | 31 | papn = it->second; 32 | return true; 33 | } 34 | -------------------------------------------------------------------------------- /pcrf/src/bearer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include "bearer.h" 9 | 10 | BearerMap::BearerMap() 11 | { 12 | } 13 | 14 | BearerMap::~BearerMap() 15 | { 16 | BearerMap::iterator it; 17 | 18 | while ( (it = begin()) != end() ) 19 | { 20 | delete it->second; 21 | erase( it ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pcrf/src/endpoint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include "endpoint.h" 9 | 10 | EndpointMap::EndpointMap() 11 | { 12 | } 13 | 14 | EndpointMap::~EndpointMap() 15 | { 16 | EndpointMap::iterator it; 17 | 18 | while ( (it = begin()) != end() ) 19 | { 20 | delete it->second; 21 | erase( it ); 22 | } 23 | } 24 | 25 | bool EndpointMap::getEndpoint( const std::string &endpoint, Endpoint* &pendpoint ) 26 | { 27 | SMutexLock l( m_mutex ); 28 | 29 | auto it = find( endpoint ); 30 | if ( it == end() ) 31 | return false; 32 | 33 | pendpoint = it->second; 34 | return true; 35 | } 36 | 37 | bool EndpointMap::addEndpoint( Endpoint *pendpoint ) 38 | { 39 | auto it = insert( std::pair( pendpoint->getHost(), pendpoint ) ); 40 | return it.second; 41 | } 42 | -------------------------------------------------------------------------------- /pcrf/tdf/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/tdf 3 | gmon.out 4 | conf/*pem 5 | conf/demoCA 6 | out.txt 7 | logs 8 | -------------------------------------------------------------------------------- /pcrf/tdf/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/tdf 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++11 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | LIBS := \ 15 | $(ROOT)/util/lib/libc3po.a \ 16 | -lcares \ 17 | -lcassandra \ 18 | -lfdcore \ 19 | -lfdproto \ 20 | -lmemcached \ 21 | -lrt 22 | 23 | INCS := \ 24 | -I ./include \ 25 | -I ./include/spdlog \ 26 | -I $(ROOT)/util/include \ 27 | -I $(ROOT)/modules/spdlog/include 28 | 29 | $(TARGET): $(OBJECTS) 30 | @echo " Linking..." 31 | @mkdir -p $(BINDIR) 32 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 33 | 34 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 35 | @mkdir -p $(BUILDDIR) 36 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 37 | 38 | clean: 39 | @echo " Cleaning..."; 40 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 41 | 42 | -include $(DEPENDS) 43 | 44 | .PHONY: clean 45 | -------------------------------------------------------------------------------- /pcrf/tdf/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /pcrf/tdf/conf/tdf.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "fdcfg": "conf/tdf.conf", 4 | "originhost": "tdf.test3gpp.net", 5 | "originrealm": "test3gpp.net" 6 | }, 7 | "tdf": { 8 | "pcrfhost": "pcrf.test3gpp.net", 9 | "pcrfrealm": "test3gpp.net", 10 | "casshost": "10.31.14.79", 11 | "casskeyspace": "pcrf", 12 | "logsize": 20, 13 | "lognumber": 5, 14 | "logname": "logs/tdf.log", 15 | "logqsize": 8192 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pcrf/tdf/include/sd_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SD_IMPL_H 9 | #define __SD_IMPL_H 10 | 11 | #include "sd.h" 12 | 13 | class TDF; 14 | 15 | namespace sd { 16 | 17 | // Member functions that customize the individual application 18 | class Application : public ApplicationBase 19 | { 20 | friend TSRreq; 21 | friend CRCRreq; 22 | friend REARreq; 23 | 24 | public: 25 | Application( TDF &tdf ); 26 | ~Application(); 27 | 28 | TSRcmd &getTSRcmd() { return m_cmd_tsr; } 29 | REARcmd &getREARcmd() { return m_cmd_rear; } 30 | 31 | // Parameters for sendXXXreq, if present below, may be changed 32 | // based upon processing needs 33 | bool sendCRCRreq(FDPeer &peer); 34 | 35 | std::string &getSessionId() { return m_sessionid; } 36 | 37 | private: 38 | void registerHandlers(); 39 | TSRcmd m_cmd_tsr; 40 | REARcmd m_cmd_rear; 41 | 42 | // the parameters for createXXXreq, if present below, may be 43 | // changed based processing needs 44 | CRCRreq *createCRCRreq(FDPeer &peer); 45 | 46 | TDF &m_tdf; 47 | std::string m_sessionid; 48 | }; 49 | 50 | } 51 | 52 | #endif // __SD_IMPL_H 53 | -------------------------------------------------------------------------------- /pcrf/tdf/include/tdf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __TDF_H 9 | #define __TDF_H 10 | 11 | #include "sd_impl.h" 12 | 13 | class TDF 14 | { 15 | public: 16 | TDF(); 17 | ~TDF(); 18 | 19 | bool init(); 20 | void uninit(); 21 | 22 | void waitForShutdown(); 23 | 24 | sd::Application &sdApp() { return *m_sd; } 25 | 26 | private: 27 | FDEngine m_diameter; 28 | 29 | sd::Application *m_sd; 30 | }; 31 | 32 | #endif // #define __TDF_H 33 | -------------------------------------------------------------------------------- /pcrf/tssf/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/tssf 3 | gmon.out 4 | conf/*pem 5 | conf/demoCA 6 | out.txt 7 | logs 8 | -------------------------------------------------------------------------------- /pcrf/tssf/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BINDIR := bin 4 | BUILDDIR := build 5 | TARGETDIR := bin 6 | TARGET := $(TARGETDIR)/tssf 7 | 8 | SRCEXT := cpp 9 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 10 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 11 | DEPENDS := $(OBJECTS:%.o=%.d) 12 | CFLAGS := -g -pthread -std=c++11 # -Wall 13 | LFLAGS := -g -pthread -lpthread -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib 14 | LIBS := \ 15 | $(ROOT)/util/lib/libc3po.a \ 16 | -lcares \ 17 | -lcassandra \ 18 | -lfdcore \ 19 | -lfdproto \ 20 | -lmemcached \ 21 | -lrt 22 | 23 | INCS := \ 24 | -I ./include \ 25 | -I ./include/spdlog \ 26 | -I $(ROOT)/util/include \ 27 | -I $(ROOT)/modules/spdlog/include 28 | 29 | $(TARGET): $(OBJECTS) 30 | @echo " Linking..." 31 | @mkdir -p $(BINDIR) 32 | @echo " $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS)"; $(CC) $(LFLAGS) $^ -o $(TARGET) $(LIBS) 33 | 34 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 35 | @mkdir -p $(BUILDDIR) 36 | @echo " $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INCS) -MMD -c -o $@ $< 37 | 38 | clean: 39 | @echo " Cleaning..."; 40 | @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) 41 | 42 | -include $(DEPENDS) 43 | 44 | .PHONY: clean 45 | -------------------------------------------------------------------------------- /pcrf/tssf/bin/make_certs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright 2019-present Open Networking Foundation 3 | 4 | #Copyright (c) 2017 Sprint 5 | # 6 | # SPDX-License-Identifier: Apache-2.0 7 | 8 | rm -rf demoCA 9 | mkdir demoCA 10 | echo 01 > demoCA/serial 11 | touch demoCA/index.txt 12 | 13 | HOST=$1 14 | DOMAIN=$2 15 | 16 | # CA self certificate 17 | openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 18 | 19 | # 20 | openssl genrsa -out $HOST.key.pem 1024 21 | openssl req -new -batch -out $HOST.csr.pem -key $HOST.key.pem -subj /CN=$HOST.$DOMAIN/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests 22 | openssl ca -cert cacert.pem -keyfile cakey.pem -in $HOST.csr.pem -out $HOST.cert.pem -outdir . -batch 23 | 24 | -------------------------------------------------------------------------------- /pcrf/tssf/conf/tssf.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "fdcfg": "conf/tssf.conf", 4 | "originhost": "tssf.test3gpp.net", 5 | "originrealm": "test3gpp.net" 6 | }, 7 | "tssf": { 8 | "pcrfhost": "pcrf.test3gpp.net", 9 | "pcrfrealm": "test3gpp.net", 10 | "casshost": "10.31.14.79", 11 | "casskeyspace": "pcrf", 12 | "logsize": 20, 13 | "lognumber": 5, 14 | "logname": "logs/tssf.log", 15 | "logqsize": 8192 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pcrf/tssf/include/st_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __ST_IMPL_H 9 | #define __ST_IMPL_H 10 | 11 | #include "st.h" 12 | 13 | class TSSF; 14 | 15 | namespace st { 16 | 17 | // Member functions that customize the individual application 18 | class Application : public ApplicationBase 19 | { 20 | friend TSRreq; 21 | friend SETRreq; 22 | friend TNRreq; 23 | 24 | public: 25 | Application( TSSF &tssf ); 26 | ~Application(); 27 | 28 | TSRcmd &getTSRcmd() { return m_cmd_tsr; } 29 | SETRcmd &getSETRcmd() { return m_cmd_setr; } 30 | //TNRcmd &getTNRcmd() { return m_cmd_tnr; } 31 | 32 | // Parameters for sendXXXreq, if present below, may be changed 33 | // based upon processing needs 34 | bool sendTNRreq(FDPeer &peer); 35 | 36 | std::string &getSessionId() { return m_sessionid; } 37 | 38 | private: 39 | void registerHandlers(); 40 | TSRcmd m_cmd_tsr; 41 | SETRcmd m_cmd_setr; 42 | 43 | // the parameters for createXXXreq, if present below, may be 44 | // changed based processing needs 45 | TNRreq *createTNRreq(FDPeer &peer); 46 | 47 | TSSF &m_tssf; 48 | std::string m_sessionid; 49 | }; 50 | 51 | } 52 | 53 | #endif // __ST_IMPL_H 54 | -------------------------------------------------------------------------------- /pcrf/tssf/include/tssf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __TSSF_H 9 | #define __TSSF_H 10 | 11 | #include "st_impl.h" 12 | 13 | class TSSF 14 | { 15 | public: 16 | TSSF(); 17 | ~TSSF(); 18 | 19 | bool init(); 20 | void uninit(); 21 | 22 | void waitForShutdown(); 23 | 24 | st::Application &stApp() { return *m_st; } 25 | 26 | private: 27 | FDEngine m_diameter; 28 | 29 | st::Application *m_st; 30 | }; 31 | 32 | #endif // #define __TSSF_H 33 | -------------------------------------------------------------------------------- /sgxcdr/dealer/App/sgxsdk-ra-attester_u.c: -------------------------------------------------------------------------------- 1 | //TODO: ADD LICENSE 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | /* Untrusted code to do remote attestation with the SGX SDK. */ 12 | 13 | void ocall_remote_attestation 14 | ( 15 | sgx_report_t* report, 16 | attestation_verification_report_t* attn_report 17 | ) 18 | { 19 | // produce quote 20 | uint32_t quote_size; 21 | sgx_calc_quote_size(NULL, 0, "e_size); 22 | 23 | sgx_quote_t* quote = (sgx_quote_t*) calloc(1, quote_size); 24 | static const sgx_spid_t spid = {{0xC2, 0xEB, 0x8C, 0x29, 25 | 0xAB, 0x26, 0x9C, 0x88, 26 | 0x7E, 0x59, 0x78, 0x93, 27 | 0xD0, 0x2C, 0xD8, 0xAB}}; 28 | 29 | sgx_status_t status; 30 | status = sgx_get_quote(report, 31 | SGX_UNLINKABLE_SIGNATURE, 32 | &spid, 33 | NULL, 34 | NULL, 35 | 0, 36 | NULL, 37 | quote, 38 | quote_size); 39 | assert(SGX_SUCCESS == status); 40 | 41 | // verify against IAS 42 | obtain_attestation_verification_report(quote, quote_size, attn_report); 43 | } 44 | 45 | void ocall_sgx_init_quote 46 | ( 47 | sgx_target_info_t* target_info 48 | ) 49 | { 50 | sgx_epid_group_id_t gid; 51 | sgx_status_t status = sgx_init_quote(target_info, &gid); 52 | assert(status == SGX_SUCCESS); 53 | } 54 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/Enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x800000 5 | 0x2000000 6 | 16 7 | 1 8 | 0 9 | 0 10 | 0xFFFFFFFF 11 | 12 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/Enclave.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | from "mbedtls_sgx.edl" import *; 3 | from "sgx_tstdc.edl" import *; 4 | include "ssl_context.h" 5 | include "sgx_utils.h" 6 | 7 | from "sgx_tae_service.edl" import create_session_ocall, exchange_report_ocall, close_session_ocall, invoke_service_ocall; 8 | 9 | include "ra.h" 10 | 11 | from "../deps/sgx_zmq/sgx_tcdr/include/sgx_tcdr.edl" import *; 12 | trusted { 13 | /* define ECALLs here. */ 14 | public void ssl_conn_init(long int mode, [in,out] enclave_params_t *params); 15 | public void ssl_conn_teardown(void); 16 | public void ssl_conn_handle(long int thread_id, [in,out] thread_info_t* thread_info); 17 | 18 | public void offline_handle([in,out] thread_info_t* thread_info); 19 | }; 20 | 21 | untrusted { 22 | /* define OCALLs here. */ 23 | void ocall_sgx_init_quote([out] sgx_target_info_t* target_info); 24 | void ocall_remote_attestation([in] sgx_report_t* report, 25 | [out] attestation_verification_report_t* attn_report 26 | ); 27 | void ocall_rename_file([in,string] const char *oldname, [in,string] const char *newname); 28 | }; 29 | }; 30 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/Enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | local: 8 | *; 9 | }; 10 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/certs/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/crypto.h: -------------------------------------------------------------------------------- 1 | //TODO: Add license 2 | #ifndef CRYPTO_H 3 | #define CRYPTO_H 4 | 5 | #include "sgx_trts.h" 6 | #include "sgx_tcrypto.h" 7 | 8 | #define BUFLEN 2048 9 | #define CRYPTO_TYPE_AES_GCM 1 10 | #define CRYPTO_TYPE_AES_CTR 2 11 | #define CRYPTO_TYPE_UNKNOWN -500 12 | 13 | class Crypto { 14 | public: 15 | Crypto(int t); 16 | ~Crypto(); 17 | 18 | // APIs 19 | int encrypt(char *, size_t, char *, size_t *); 20 | int decrypt(char *, size_t, char *, size_t *); 21 | int set_params_aesgcm(sgx_aes_gcm_128bit_key_t, uint8_t*, size_t); 22 | int set_params_aesctr(sgx_aes_ctr_128bit_key_t, uint8_t*); 23 | 24 | private: 25 | // encryption type 26 | int type; 27 | 28 | // internal APIs for AES-GCM 29 | int encrypt_aesgcm(char*, size_t, char*, size_t *); 30 | int decrypt_aesgcm(char*, size_t, char*, size_t *); 31 | sgx_aes_gcm_128bit_key_t aesgcm_key; 32 | uint8_t *aad; 33 | size_t aad_size; 34 | 35 | // internal APIs for AES-CTR 36 | int encrypt_aesctr(char*, size_t, char*); 37 | int decrypt_aesctr(char*, size_t, char*); 38 | sgx_aes_ctr_128bit_key_t aesctr_key; 39 | uint32_t ctr_num_bit_size; 40 | uint8_t ctr[16]; 41 | 42 | }; 43 | 44 | // other testing related fuctions 45 | void test_crypto(int); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/ecalls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Enclave_t.h" 5 | #include "ssl_conn_hdlr.h" 6 | #include "helper.h" 7 | 8 | TLSConnectionHandler* connectionHandler; 9 | 10 | void ssl_conn_init(long int mode, enclave_params_t *params) { 11 | try { 12 | connectionHandler = new TLSConnectionHandler(params); 13 | connectionHandler->initialize_dealer_mode(mode); 14 | } catch (std::exception e) { 15 | return; 16 | } 17 | } 18 | 19 | void ssl_conn_handle(long int thread_id, thread_info_t* thread_info) { 20 | connectionHandler->handle(thread_id, thread_info); 21 | } 22 | 23 | void ssl_conn_teardown(void) { 24 | delete connectionHandler; 25 | } 26 | 27 | void offline_handle(thread_info_t* thread_info) 28 | { 29 | mbedtls_printf("from enclave : %s and %d \n", thread_info->cdr_router_host, thread_info->cdr_router_port); 30 | char key[17] = {0}; 31 | 32 | if (!connectionHandler) 33 | return; 34 | 35 | if (connectionHandler->get_key_from_kms(key) != 0) { 36 | mbedtls_printf("ERROR: Offline mode :failed to get key from KMS\n"); 37 | return; 38 | } 39 | 40 | mbedtls_ssl_context *ssl=NULL; 41 | int offline_mode = 1; 42 | std::string cdrPath; 43 | std::string cdrArchPath; 44 | 45 | connectionHandler->get_cdr_filepath(cdrPath, cdrArchPath); 46 | 47 | get_msg_out_router_send_to_ctf(1, ssl, 48 | thread_info->cdr_router_host, 49 | thread_info->cdr_router_port, key, offline_mode, 50 | cdrPath, cdrArchPath); 51 | } 52 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/embed_cert.args: -------------------------------------------------------------------------------- 1 | -c ./certs 2 | -e 36fb2eccd79ef59f72aeb806deb7052c38a1f75620f8fc8d947d855d638fd369 3 | -s 63ef969cbc34ee465f277cd3c27e9b3c681d743e455f899daced1b3cf85ceb8f 4 | -i 0 5 | -f ca_bundle.h 6 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/helper.h: -------------------------------------------------------------------------------- 1 | //TODO: Add license 2 | #ifndef HELPER_H 3 | #define HELPER_H 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include "mbedtls/debug.h" 10 | #include "sgx_tae_service.h" 11 | #include "sgx_tcrypto.h" 12 | #include "../deps/sgx_zmq/sgx_tcdr/include/sgx_tcdr.h" 13 | 14 | #define POLL_INTERVAL 10000 15 | #define READ_BUFFER_SIZE 256 16 | 17 | enum Modes {IN = 1, OUT}; 18 | enum MsgType {MSG_UNKNOWN = -1, MSG_FILENAME = 0, MSG_DATA, MSG_CLOSE_PROTECTED_FILE}; 19 | enum zmq_errcodes 20 | { 21 | SUCCESS_ZMQ = 0, 22 | ERR_ZMQ_CONN_ROUTER_FAIL, 23 | ERR_ZMQ_POLL_READ_ROUTER_FAIL, 24 | ERR_ZMQ_POLL_READ_ROUTER_TIMEOUT, 25 | ERR_ZMQ_SEND_ROUTER_FAIL, 26 | ERR_ZMQ_RECV_ROUTER_FAIL, 27 | ERR_ZMQ_CLOSE_ROTER_FAIL 28 | }; 29 | 30 | extern "C" { 31 | int get_msg_out_router_send_to_ctf(long int thread_id, mbedtls_ssl_context *ssl, 32 | char *cdr_out_router_host, int cdr_out_router_port, char *key_from_kms, 33 | int offline, std::string &cdrPath, std::string &cdrArchPath); 34 | int close_router_conn(zmq_handle* handle, zmq_context *context); 35 | SGX_FILE *open_protected_fs_file(const char *dp_id, char *); 36 | SGX_FILE *open_secure_file(const char *, const char *, char *); 37 | int read_stream_from_file(long int, mbedtls_ssl_context *, char *, char *); 38 | int write_to_protected_fs(SGX_FILE *file_handle, uint8_t *write_buff, size_t len); 39 | 40 | int close_protected_fs(SGX_FILE *file_handle); 41 | zmq_handle *conn_to_in_router(char *cdr_router_host, int cdr_router_port, 42 | char *dealer_identity); 43 | int send_msg_to_in_router(zmq_handle *handle, unsigned char *msg, int len); 44 | int get_message_type(char msg_type); 45 | } 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/mbedtls_sgx.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | include "mbedtls/net.h" 3 | include "mbedtls/timing.h" 4 | 5 | trusted { 6 | public void dummy(void); 7 | }; 8 | 9 | untrusted { 10 | // implemented in net_v.h 11 | // [in] means going with the call 12 | // [out] means getting out from the call 13 | int ocall_mbedtls_net_connect([in, out] mbedtls_net_context *ctx, [in,string] const char *host, [in,string] const char *port, int proto ); 14 | int ocall_mbedtls_net_bind( [out] mbedtls_net_context *ctx, [in,string] const char *bind_ip, [in,string] const char *port, int proto ); 15 | int ocall_mbedtls_net_accept( [in] mbedtls_net_context *bind_ctx, [out] mbedtls_net_context *client_ctx, [out, size=buf_size] void *client_ip, size_t buf_size, [out] size_t *ip_len ); 16 | int ocall_mbedtls_net_set_block([in,out] mbedtls_net_context *ctx ); 17 | int ocall_mbedtls_net_set_nonblock( [in,out] mbedtls_net_context *ctx ); 18 | void ocall_mbedtls_net_usleep( unsigned long usec ); 19 | int ocall_mbedtls_net_recv( [in,out] mbedtls_net_context *ctx, [out, size=len] unsigned char *buf, size_t len ); 20 | int ocall_mbedtls_net_send( [in,out] mbedtls_net_context *ctx, [in, size=len] const unsigned char *buf, size_t len ); 21 | int ocall_mbedtls_net_recv_timeout( [in,out] mbedtls_net_context *ctx, [out, size=len] unsigned char *buf, size_t len, uint32_t timeout ); 22 | void ocall_mbedtls_net_free( [in, out] mbedtls_net_context *ctx ); 23 | 24 | // printf 25 | int ocall_print_string([in, string] const char *str); 26 | }; 27 | }; 28 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/memmem.h: -------------------------------------------------------------------------------- 1 | void *memmem(const void *h0, size_t k, const void *n0, size_t l); 2 | -------------------------------------------------------------------------------- /sgxcdr/dealer/Enclave/sgxsdk-ra-attester_t.c: -------------------------------------------------------------------------------- 1 | // TODO: ADD license 2 | #include 3 | 4 | #include 5 | 6 | #include "Enclave_t.h" // OCALLs 7 | 8 | /* Trusted portion (called from within the enclave) to do remote 9 | attestation with the SGX SDK. */ 10 | 11 | void do_remote_attestation(sgx_report_data_t* report_data, 12 | attestation_verification_report_t* r); 13 | 14 | void do_remote_attestation 15 | ( 16 | sgx_report_data_t* report_data, 17 | attestation_verification_report_t* attn_report 18 | ) 19 | { 20 | sgx_target_info_t target_info = {0, }; 21 | ocall_sgx_init_quote(&target_info); 22 | 23 | sgx_report_t report = {0, }; 24 | sgx_status_t status = sgx_create_report(&target_info, report_data, &report); 25 | assert(status == SGX_SUCCESS); 26 | 27 | ocall_remote_attestation(&report, attn_report); 28 | } 29 | -------------------------------------------------------------------------------- /sgxcdr/dealer/certs/ias-leaf-cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/dealer/certs/ias-leaf-cert.der -------------------------------------------------------------------------------- /sgxcdr/dealer/certs/ias-leaf-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEoTCCAwmgAwIBAgIJANEHdl0yo7CWMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNV 4 | BAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQDDCdJbnRlbCBTR1ggQXR0ZXN0 5 | YXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwHhcNMTYxMTIyMDkzNjU4WhcNMjYxMTIw 6 | MDkzNjU4WjB7MQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFDASBgNVBAcMC1Nh 7 | bnRhIENsYXJhMRowGAYDVQQKDBFJbnRlbCBDb3Jwb3JhdGlvbjEtMCsGA1UEAwwk 8 | SW50ZWwgU0dYIEF0dGVzdGF0aW9uIFJlcG9ydCBTaWduaW5nMIIBIjANBgkqhkiG 9 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqXot4OZuphR8nudFrAFiaGxxkgma/Es/BA+t 10 | beCTUR106AL1ENcWA4FX3K+E9BBL0/7X5rj5nIgX/R/1ubhkKWw9gfqPG3KeAtId 11 | cv/uTO1yXv50vqaPvE1CRChvzdS/ZEBqQ5oVvLTPZ3VEicQjlytKgN9cLnxbwtuv 12 | LUK7eyRPfJW/ksddOzP8VBBniolYnRCD2jrMRZ8nBM2ZWYwnXnwYeOAHV+W9tOhA 13 | ImwRwKF/95yAsVwd21ryHMJBcGH70qLagZ7Ttyt++qO/6+KAXJuKwZqjRlEtSEz8 14 | gZQeFfVYgcwSfo96oSMAzVr7V0L6HSDLRnpb6xxmbPdqNol4tQIDAQABo4GkMIGh 15 | MB8GA1UdIwQYMBaAFHhDe3amfrzQr35CN+s1fDuHAVE8MA4GA1UdDwEB/wQEAwIG 16 | wDAMBgNVHRMBAf8EAjAAMGAGA1UdHwRZMFcwVaBToFGGT2h0dHA6Ly90cnVzdGVk 17 | c2VydmljZXMuaW50ZWwuY29tL2NvbnRlbnQvQ1JML1NHWC9BdHRlc3RhdGlvblJl 18 | cG9ydFNpZ25pbmdDQS5jcmwwDQYJKoZIhvcNAQELBQADggGBAGcIthtcK9IVRz4r 19 | Rq+ZKE+7k50/OxUsmW8aavOzKb0iCx07YQ9rzi5nU73tME2yGRLzhSViFs/LpFa9 20 | lpQL6JL1aQwmDR74TxYGBAIi5f4I5TJoCCEqRHz91kpG6Uvyn2tLmnIdJbPE4vYv 21 | WLrtXXfFBSSPD4Afn7+3/XUggAlc7oCTizOfbbtOFlYA4g5KcYgS1J2ZAeMQqbUd 22 | ZseZCcaZZZn65tdqee8UXZlDvx0+NdO0LR+5pFy+juM0wWbu59MvzcmTXbjsi7HY 23 | 6zd53Yq5K244fwFHRQ8eOB0IWB+4PfM7FeAApZvlfqlKOlLcZL2uyVmzRkyR5yW7 24 | 2uo9mehX44CiPJ2fse9Y6eQtcfEhMPkmHXI01sN+KwPbpA39+xOsStjhP9N1Y1a2 25 | tQAVo+yVgLgV2Hws73Fc0o3wC78qPEA+v2aRs/Be3ZFDgDyghc/1fgU+7C+P6kbq 26 | d4poyb6IW8KCJbxfMJvkordNOgOUUxndPHEi/tb/U7uLjLOgPA== 27 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /sgxcdr/dealer/certs/ias-root-cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/dealer/certs/ias-root-cert.der -------------------------------------------------------------------------------- /sgxcdr/dealer/certs/ias-root-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFSzCCA7OgAwIBAgIJANEHdl0yo7CUMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNV 4 | BAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQDDCdJbnRlbCBTR1ggQXR0ZXN0 5 | YXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwIBcNMTYxMTE0MTUzNzMxWhgPMjA0OTEy 6 | MzEyMzU5NTlaMH4xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwL 7 | U2FudGEgQ2xhcmExGjAYBgNVBAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQD 8 | DCdJbnRlbCBTR1ggQXR0ZXN0YXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwggGiMA0G 9 | CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCfPGR+tXc8u1EtJzLA10Feu1Wg+p7e 10 | LmSRmeaCHbkQ1TF3Nwl3RmpqXkeGzNLd69QUnWovYyVSndEMyYc3sHecGgfinEeh 11 | rgBJSEdsSJ9FpaFdesjsxqzGRa20PYdnnfWcCTvFoulpbFR4VBuXnnVLVzkUvlXT 12 | L/TAnd8nIZk0zZkFJ7P5LtePvykkar7LcSQO85wtcQe0R1Raf/sQ6wYKaKmFgCGe 13 | NpEJUmg4ktal4qgIAxk+QHUxQE42sxViN5mqglB0QJdUot/o9a/V/mMeH8KvOAiQ 14 | byinkNndn+Bgk5sSV5DFgF0DffVqmVMblt5p3jPtImzBIH0QQrXJq39AT8cRwP5H 15 | afuVeLHcDsRp6hol4P+ZFIhu8mmbI1u0hH3W/0C2BuYXB5PC+5izFFh/nP0lc2Lf 16 | 6rELO9LZdnOhpL1ExFOq9H/B8tPQ84T3Sgb4nAifDabNt/zu6MmCGo5U8lwEFtGM 17 | RoOaX4AS+909x00lYnmtwsDVWv9vBiJCXRsCAwEAAaOByTCBxjBgBgNVHR8EWTBX 18 | MFWgU6BRhk9odHRwOi8vdHJ1c3RlZHNlcnZpY2VzLmludGVsLmNvbS9jb250ZW50 19 | L0NSTC9TR1gvQXR0ZXN0YXRpb25SZXBvcnRTaWduaW5nQ0EuY3JsMB0GA1UdDgQW 20 | BBR4Q3t2pn680K9+QjfrNXw7hwFRPDAfBgNVHSMEGDAWgBR4Q3t2pn680K9+Qjfr 21 | NXw7hwFRPDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADANBgkq 22 | hkiG9w0BAQsFAAOCAYEAeF8tYMXICvQqeXYQITkV2oLJsp6J4JAqJabHWxYJHGir 23 | IEqucRiJSSx+HjIJEUVaj8E0QjEud6Y5lNmXlcjqRXaCPOqK0eGRz6hi+ripMtPZ 24 | sFNaBwLQVV905SDjAzDzNIDnrcnXyB4gcDFCvwDFKKgLRjOB/WAqgscDUoGq5ZVi 25 | zLUzTqiQPmULAQaB9c6Oti6snEFJiCQ67JLyW/E83/frzCmO5Ru6WjU4tmsmy8Ra 26 | Ud4APK0wZTGtfPXU7w+IBdG5Ez0kE1qzxGQaL4gINJ1zMyleDnbuS8UicjJijvqA 27 | 152Sq049ESDz+1rRGc2NVEqh1KaGXmtXvqxXcTB+Ljy5Bw2ke0v8iGngFBPqCTVB 28 | 3op5KBG3RjbF6RRSzwzuWfL7QErNC8WEy5yDVARzTA5+xmBc388v9Dm21HGfcC8O 29 | DD+gT9sSpssq0ascmvH49MOgjt1yoysLtdCtJW/9FZpoOypaHx0R+mJTLwPXVMrv 30 | DaVzWh5aiEx+idkSGMnX 31 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /sgxcdr/dealer/certs/server-pubkey.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/dealer/certs/server-pubkey.der -------------------------------------------------------------------------------- /sgxcdr/dealer/certs/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIDYDCCAkgCAQAwgdAxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhOZXcgWW9yazES 3 | MBAGA1UEBwwJUm9jaGVzdGVyMRIwEAYDVQQKDAlFbmQgUG9pbnQxFzAVBgNVBAsM 4 | DlRlc3RpbmcgRG9tYWluMUswSQYJKoZIhvcNAQkBFjx5b3VyLWFkbWluaXN0cmF0 5 | aXZlLWFkZHJlc3NAeW91ci1hd2Vzb21lLWV4aXN0aW5nLWRvbWFpbi5jb20xIDAe 6 | BgNVBAMMF3d3dy55b3VyLW5ldy1kb21haW4uY29tMIIBIjANBgkqhkiG9w0BAQEF 7 | AAOCAQ8AMIIBCgKCAQEAwJUI4VdB8nFtt9JFQScBZcZFrvK8JDC4lc4vTtb2HIi8 8 | fJ/7qGd//lycUXX3isoH5zUvj+G9e8AvfKtkqBf8yl17uuAh5XIuby6G2JVz2qwb 9 | U7lfP9cZDSVP4WNjUYsLZD+tQ7ilHFw0s64AoGPF9n8LWWh4c6aMGKkCba/DGQEu 10 | uBDjxsxAtGmjRjNph27Euxem8+jdrXO8ey8htf1mUQy9VLPhbV8cvCNz0QkDiRTS 11 | ELlkwyrQoZZKvOHUGlvHoMDBY3gPRDcwMpaAMiOVoXe6E9KXc+JdJclqDcM5YKS0 12 | sGlCQgnp2Ai8MyCzWCKnquvE4eZhg8XSlt/Z0E+t1wIDAQABoEowSAYJKoZIhvcN 13 | AQkOMTswOTA3BgNVHREEMDAughN5b3VyLW5ldy1kb21haW4uY29tghd3d3cueW91 14 | ci1uZXctZG9tYWluLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAuQfWU6HmMGhtkVQx 15 | vHY6cuXv9dUgnDa3FxJEa6JtTyi6hjb1miefw9D3Cge13jk0WJ75Cd83ubCG4qq8 16 | pqXCY54yehDl8UWjNqRks3Mq45KOm+a2u4ZPWghvaHyoa6GIsvSpu3Rzb2HEFWVW 17 | 5rfnMCd/zoUvipov5Cr/Jb6s4rF29DsAZpkz+3y1/Xw9tyzI/g/y9SjIE2aWJRMr 18 | AOdo6jZ2Q0svpFAlkUCiiIof426vBJ/zxdzYBMXTu+6arNhVZcfVt4KgQMRP6Unx 19 | /WWrQgMELNbn43X1y5yzP0m+PK1ttMsgjz+Q6uMb1YwfOAf1bOvSEU1f3U+fwVAs 20 | fTrXOA== 21 | -----END CERTIFICATE REQUEST----- 22 | -------------------------------------------------------------------------------- /sgxcdr/dealer/conf/dealer.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "maxconnections": "16", 4 | "kmsserver": "10.212.93.77", 5 | "kmsport": "8443", 6 | "keynamespace": "dealer_namespace" 7 | }, 8 | 9 | "dealer": { 10 | "runmode": "OUT", 11 | "cdrhost": "10.212.93.77", 12 | "cdrport": "6790", 13 | "port": "443", 14 | "cdrpath": "./cdr", 15 | "cdrarchpath": "/tmp" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/mbedtls_sgx_ra_postbuild.patch: -------------------------------------------------------------------------------- 1 | --- trusted/mbedtls-2.6.0/library-2.15.1/net_sockets.c 2018-12-17 19:42:44.707733126 -0800 2 | +++ trusted/mbedtls-2.6.0/library/net_sockets.c 2018-12-17 21:14:10.931754954 -0800 3 | @@ -24,26 +24,6 @@ 4 | * Harmless on other platforms. */ 5 | #define _POSIX_C_SOURCE 200112L 6 | 7 | -#if !defined(MBEDTLS_CONFIG_FILE) 8 | -#include "mbedtls/config.h" 9 | -#else 10 | -#include MBEDTLS_CONFIG_FILE 11 | -#endif 12 | - 13 | -#if defined(MBEDTLS_NET_C) 14 | - 15 | -#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ 16 | - !defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \ 17 | - !defined(__HAIKU__) 18 | -#error "This module only works on Unix and Windows, see MBEDTLS_NET_C in config.h" 19 | -#endif 20 | - 21 | -#if defined(MBEDTLS_PLATFORM_C) 22 | -#include "mbedtls/platform.h" 23 | -#else 24 | -#include 25 | -#endif 26 | - 27 | #include "mbedtls/net_sockets.h" 28 | 29 | #include 30 | @@ -664,5 +644,3 @@ 31 | 32 | ctx->fd = -1; 33 | } 34 | - 35 | -#endif /* MBEDTLS_NET_C */ 36 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/README.md: -------------------------------------------------------------------------------- 1 | About : 2 | Provides ZMQ socket support and protected fs wrapper for secure CDR 3 | processing. 4 | 5 | Source code structure: 6 | - sgx_tcdr : Trusted static library to be linked with an enclave. Exposes APIs 7 | to connect to ZMQ in PULL/PUSH config, connect to ZMQ router and read/write 8 | messages. Also exposes wrapper API over protected FS. 9 | - sgx_ucdr : Untrusted static library to be linked with an untrusted 10 | Application. Actual implementation of ZMQ mechanism. 11 | 12 | Prerequisites: 13 | - Ubuntu 16.04 14 | - Intel SGX SDK 1.9 15 | - ZeroMQ 4.0.* (http://download.zeromq.org/#ZeroMQ_4) 16 | 17 | Build Library : 18 | - Inside sgx_tcdr directory, run "make" to build libsgx_tcdr.a library. 19 | - Inside sgx_ucdr directory, run "make" to build libsgx_ucdr.a library. 20 | 21 | Usage : 22 | Makefile : 23 | - Define a variable CDR_LIB_PATH with value of parent directory of 24 | sgx_tcdr and sgx_ucdr. 25 | - In App Include Path add "-I$(CDR_LIB_PATH)/sgx_ucdr" 26 | - In App Link Flags add "-lsgx_uprotected_fs -L$(CDR_LIB_PATH)/sgx_ucdr 27 | -lsgx_uprotected_cdr -lzmq" 28 | - In Enclave Include Path add "-I$(CDR_LIB_PATH)/sgx_tcdr" 29 | - In Enclave Link Flags add "-L$(CDR_LIB_PATH)/sgx_tcdr" after 30 | "-L$(SGX_LIBRARY_PATH)". Add " -lsgx_tcxx -lsgx_tcdr 31 | -lsgx_tprotected_fs" and between --start-group and --end-group. 32 | 33 | Enclave : 34 | - Include "include/sgx_tcdr.h" from Enclave code to call trusted 35 | functions. Also import all the functions from 36 | sgx_tcdr/trusted/sgx_tcdr.edl in Enclave edl file. 37 | 38 | Untrusted App: 39 | - Include "uprotected_cdr.h from Untrusted App code. 40 | 41 | Limitations: 42 | - Platform dependednt. Tested only on Ubuntu 16.04. 43 | 44 | TODO : 45 | - Add custom error codes. 46 | 47 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/sgx_tcdr/Makefile: -------------------------------------------------------------------------------- 1 | ALL_UNTRUSTED_MK=$(shell find . -name '*sgx_u.mk') 2 | #ALL_TRUSTED_MK=$(shell find . -name '*sgx_t.mk') 3 | ALL_STATIC_MK=$(shell find . -name '*sgx_t_static.mk') 4 | 5 | 6 | 7 | .PHONY: all clean run 8 | 9 | 10 | all clean: 11 | $(foreach U_MK, $(ALL_UNTRUSTED_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) 12 | $(foreach T_MK, $(ALL_TRUSTED_MK), $(MAKE) -C $(shell dirname $(T_MK)) -f $(shell basename $(T_MK)) $@;) 13 | $(foreach U_MK, $(ALL_STATIC_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) 14 | 15 | run: 16 | $(foreach U_MK, $(ALL_UNTRUSTED_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) 17 | $(foreach U_MK, $(ALL_UNTRUSTED_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) 18 | 19 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/sgx_tcdr/include/sgx_tcdr.edl: -------------------------------------------------------------------------------- 1 | /* sgx_tcdr.edl - Top EDL file. */ 2 | 3 | enclave { 4 | from "/opt/intel/sgxsdk/include/sgx_tprotected_fs.edl" 5 | import u_sgxprotectedfs_exclusive_file_open, 6 | u_sgxprotectedfs_check_if_file_exists, u_sgxprotectedfs_fread_node, 7 | u_sgxprotectedfs_fwrite_node, u_sgxprotectedfs_fclose, 8 | u_sgxprotectedfs_fflush, u_sgxprotectedfs_remove, 9 | u_sgxprotectedfs_recovery_file_open, 10 | u_sgxprotectedfs_fwrite_recovery_node, 11 | u_sgxprotectedfs_do_file_recovery; 12 | 13 | untrusted { 14 | 15 | void* u_sgxcdr_connect_cdr_mq([in, string] const char* host, 16 | uint16_t port, uint8_t pattern); 17 | 18 | int32_t u_sgxcdr_get_cdr_message([user_check]void* handle, 19 | [out, size=buffer_size] uint8_t* buffer, uint32_t buffer_size); 20 | 21 | int32_t u_sgxcdr_send_cdr_message([user_check] void* handle, 22 | [in, size=buffer_size] uint8_t* buffer, uint32_t buffer_size); 23 | 24 | int32_t u_sgxcdr_close_cdr_mq([user_check] void* handle); 25 | 26 | void* u_sgxcdr_connect_to_zmq_router([in, string] const char* host, 27 | uint16_t port, uint8_t mode, 28 | [in, string] const char* identity, [out] int8_t* err, 29 | [user_check] void * context); 30 | 31 | int32_t u_sgxcdr_send_zmq_router_socket([user_check] void* handle, 32 | [in, size=buffer_size] uint8_t* buffer, uint32_t buffer_size); 33 | 34 | void u_sgxcdr_zmq_router_read_poll([user_check] void* handle, 35 | uint32_t msec, [out] int8_t* result, 36 | [out, size=buffer_size] uint8_t* buffer, uint32_t buffer_size); 37 | 38 | void u_sgxcdr_recv_zmq_router_socket([user_check]void* handle, 39 | [out, size=buffer_size] uint8_t* buffer, uint32_t buffer_size, 40 | [out] int32_t* actual_read); 41 | 42 | int32_t u_sgxcdr_close_zmq_router([user_check] void* handle, 43 | [user_check] void * context); 44 | }; 45 | 46 | trusted { 47 | public int ecall_sgx_tcdr(); 48 | }; 49 | }; 50 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/sgx_tcdr/include/sgx_tcdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef SGX_TCDR_H_ 9 | #define SGX_TCDR_H_ 10 | 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "sgx_tprotected_fs.h" 17 | 18 | typedef void zmq_handle; 19 | typedef void zmq_context; 20 | 21 | typedef enum _zmq_pattern_t { 22 | SGX_ZMQ_PUSH, 23 | SGX_ZMQ_PULL, 24 | } zmq_pattern_t; 25 | 26 | 27 | zmq_handle *sgx_connect_cdr_mq(const char *host, uint16_t port, 28 | zmq_pattern_t pattern); 29 | 30 | int32_t sgx_get_cdr_message(zmq_handle *handle, uint8_t *buffer, 31 | uint32_t buffer_size); 32 | 33 | int32_t sgx_send_cdr_message(zmq_handle *handle, uint8_t *buffer, 34 | uint32_t buffer_size); 35 | 36 | int32_t sgx_close_cdr_mq(zmq_handle *handle); 37 | 38 | SGX_FILE *sgx_open_cdr_file(const char *filename, const char *mode, 39 | sgx_key_128bit_t *key); 40 | 41 | int32_t sgx_close_cdr_file(SGX_FILE *file); 42 | 43 | int sgx_read_cdr_file(void *ptr_buff, size_t size, size_t count, 44 | SGX_FILE *file); 45 | 46 | int sgx_write_cdr_file(void *ptr_buff, size_t size, size_t count, 47 | SGX_FILE *file); 48 | 49 | int sgx_flush_cdr_file(SGX_FILE *file); 50 | //TODO: Add custom error codes 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | 57 | #endif /* SGX_TCDR_H_ */ 58 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/sgx_ucdr/Makefile: -------------------------------------------------------------------------------- 1 | CC = cc 2 | OUT_FILE_NAME = libsgx_uprotected_cdr.a 3 | 4 | CFLAGS= -fPIC -O0 -Wall -c #-DDEBUG 5 | 6 | INC = -I. 7 | 8 | OBJ_DIR=./obj 9 | 10 | OUT_DIR=. 11 | 12 | FILES = uprotected_cdr.c 13 | 14 | 15 | $(OUT_FILE_NAME): $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard $(FILES))) 16 | 17 | ar rcs $(OUT_DIR)/$@ $^ 18 | 19 | 20 | 21 | $(OBJ_DIR)/%.o: %.c dirmake 22 | $(CC) -c $(INC) $(CFLAGS) -lzmq -o $@ $< 23 | 24 | dirmake: 25 | @mkdir -p $(OUT_DIR) 26 | @mkdir -p $(OBJ_DIR) 27 | 28 | clean: 29 | rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/$(OUT_FILE_NAME) 30 | 31 | rebuild: clean build 32 | -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/sgx_ucdr/obj/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/dealer/deps/sgx_zmq/sgx_ucdr/obj/.gitkeep -------------------------------------------------------------------------------- /sgxcdr/dealer/deps/sgx_zmq/sgx_ucdr/uprotected_cdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef SGX_UCDR_H_ 9 | #define SGX_UCDR_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define MAX_BUFFER_SIZE 255 16 | #define MAX_IDENTITY_LEN 256 17 | 18 | void *context; 19 | //void *context_router; 20 | 21 | void *u_sgxcdr_connect_cdr_mq(const char *host, uint16_t port, 22 | uint8_t pattern); 23 | 24 | int32_t u_sgxcdr_get_cdr_message(void *handle, uint8_t *buffer, 25 | uint32_t buffer_size); 26 | 27 | int32_t u_sgxcdr_send_cdr_message(void *handle, uint8_t *buffer, 28 | uint32_t buffer_size); 29 | 30 | int32_t u_sgxcdr_close_cdr_mq(void *handle); 31 | 32 | void *u_sgxcdr_connect_to_zmq_router(const char *host, uint16_t port, 33 | uint8_t mode, const char *identity, int8_t *err, void *context); 34 | 35 | int32_t u_sgxcdr_send_zmq_router_socket(void *handle, uint8_t *buffer, 36 | uint32_t buffer_size); 37 | 38 | void u_sgxcdr_zmq_router_read_poll(void *handle, uint32_t msec, 39 | int8_t *result, uint8_t *buffer, uint32_t buffer_size); 40 | 41 | void u_sgxcdr_recv_zmq_router_socket(void *handle, uint8_t *buffer, 42 | uint32_t buffer_size, int32_t *actual_read); 43 | 44 | int32_t u_sgxcdr_close_zmq_router(void *handle, void *context); 45 | 46 | //TODO: 1. Performance optimization: Change buffer_size, actual_read type 47 | // 2. Add custom error codes 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* SGX_UCDR_H_ */ 54 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/Utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sgx_error.h" 4 | #include "sgx_eid.h" /* sgx_enclave_id_t */ 5 | 6 | #ifndef TRUE 7 | # define TRUE 1 8 | #endif 9 | 10 | #ifndef FALSE 11 | # define FALSE 0 12 | #endif 13 | 14 | #if defined(_MSC_VER) 15 | #define TOKEN_FILENAME "Enclave.token" 16 | #define ENCLAVE_FILENAME "Enclave.signed.dll" 17 | #elif defined(__GNUC__) 18 | #define TOKEN_FILENAME "enclave.token" 19 | #define ENCLAVE_FILENAME "enclave.signed.so" 20 | #endif 21 | 22 | void print_error_message(sgx_status_t ret); 23 | int initialize_enclave(sgx_enclave_id_t *eid); 24 | 25 | #if defined(_MSC_VER) 26 | int query_sgx_status(); 27 | #endif 28 | 29 | #if defined(__cplusplus) 30 | extern "C" { 31 | #endif 32 | 33 | //extern sgx_enclave_id_t global_eid; /* global enclave id */ 34 | 35 | 36 | typedef struct _sgx_errlist_t { 37 | sgx_status_t err; 38 | const char *msg; 39 | const char *sug; /* Suggestion */ 40 | } sgx_errlist_t; 41 | 42 | 43 | #if defined(__cplusplus) 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/ias-ra.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | void obtain_attestation_verification_report( 6 | const sgx_quote_t* quote, 7 | const uint32_t quote_size, 8 | attestation_verification_report_t* attn_report 9 | ); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/mbedtls-ra-attester.h: -------------------------------------------------------------------------------- 1 | void create_key_and_x509 2 | ( 3 | mbedtls_pk_context* key, 4 | mbedtls_x509_crt* cert 5 | ); 6 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/memmem.h: -------------------------------------------------------------------------------- 1 | void *memmem(const void *h0, size_t k, const void *n0, size_t l); 2 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/ra-challenger.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void get_quote_from_report(const uint8_t* report /* in */, 4 | const int report_len /* in */, 5 | sgx_quote_t* quote); 6 | 7 | void get_quote_from_cert( 8 | const uint8_t* der_crt, 9 | uint32_t der_crt_len, 10 | sgx_quote_t* q 11 | ); 12 | 13 | int verify_sgx_cert_extensions 14 | ( 15 | const uint8_t* der_crt, 16 | uint32_t der_crt_len 17 | ); 18 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/ra.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | uint8_t ias_report[2*1024]; 3 | uint32_t ias_report_len; 4 | uint8_t ias_sign_ca_cert[2*1024]; 5 | uint32_t ias_sign_ca_cert_len; 6 | uint8_t ias_sign_cert[2*1024]; 7 | uint32_t ias_sign_cert_len; 8 | uint8_t ias_report_signature[2*1024]; 9 | uint32_t ias_report_signature_len; 10 | } attestation_verification_report_t; 11 | -------------------------------------------------------------------------------- /sgxcdr/dealer/include/ssl_context.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by fanz on 4/7/17. 3 | // 4 | 5 | #ifndef MBEDTLS_SGX_SSL_CONTEXT_H 6 | #define MBEDTLS_SGX_SSL_CONTEXT_H 7 | 8 | #include "mbedtls/ssl.h" 9 | #include "mbedtls/net.h" 10 | 11 | typedef struct { 12 | mbedtls_net_context client_fd; 13 | int thread_complete; 14 | const mbedtls_ssl_config *config; 15 | unsigned char client_ip[16]; 16 | size_t ip_len; 17 | char cdr_router_host[16]; 18 | size_t cdr_router_port; 19 | } thread_info_t; 20 | 21 | typedef struct { 22 | char kmsserver[16]; 23 | char kmsport[6]; 24 | char keynamespace[33]; 25 | char cdrpath[4096]; 26 | char cdrarchpath[4096]; 27 | }enclave_params_t; 28 | 29 | #endif //MBEDTLS_SGX_SSL_CONTEXT_H 30 | -------------------------------------------------------------------------------- /sgxcdr/kms/App/sgxsdk-ra-attester_u.c: -------------------------------------------------------------------------------- 1 | //TODO: ADD LICENSE 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | /* Untrusted code to do remote attestation with the SGX SDK. */ 12 | 13 | void ocall_remote_attestation 14 | ( 15 | sgx_report_t* report, 16 | attestation_verification_report_t* attn_report 17 | ) 18 | { 19 | // produce quote 20 | uint32_t quote_size; 21 | sgx_calc_quote_size(NULL, 0, "e_size); 22 | 23 | sgx_quote_t* quote = (sgx_quote_t*) calloc(1, quote_size); 24 | static const sgx_spid_t spid = {{0xC2, 0xEB, 0x8C, 0x29, 25 | 0xAB, 0x26, 0x9C, 0x88, 26 | 0x7E, 0x59, 0x78, 0x93, 27 | 0xD0, 0x2C, 0xD8, 0xAB}}; 28 | 29 | sgx_status_t status; 30 | status = sgx_get_quote(report, 31 | SGX_UNLINKABLE_SIGNATURE, 32 | &spid, 33 | NULL, 34 | NULL, 35 | 0, 36 | NULL, 37 | quote, 38 | quote_size); 39 | assert(SGX_SUCCESS == status); 40 | 41 | // verify against IAS 42 | obtain_attestation_verification_report(quote, quote_size, attn_report); 43 | } 44 | 45 | void ocall_sgx_init_quote 46 | ( 47 | sgx_target_info_t* target_info 48 | ) 49 | { 50 | sgx_epid_group_id_t gid; 51 | sgx_status_t status = sgx_init_quote(target_info, &gid); 52 | assert(status == SGX_SUCCESS); 53 | } 54 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/Enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x800000 5 | 0x2000000 6 | 16 7 | 1 8 | 0 9 | 0 10 | 0xFFFFFFFF 11 | 12 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/Enclave.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | from "/opt/intel/sgxsdk/include/sgx_tprotected_fs.edl" 3 | import u_sgxprotectedfs_exclusive_file_open, 4 | u_sgxprotectedfs_check_if_file_exists, u_sgxprotectedfs_fread_node, 5 | u_sgxprotectedfs_fwrite_node, u_sgxprotectedfs_fclose, 6 | u_sgxprotectedfs_fflush, u_sgxprotectedfs_remove, 7 | u_sgxprotectedfs_recovery_file_open, 8 | u_sgxprotectedfs_fwrite_recovery_node, 9 | u_sgxprotectedfs_do_file_recovery; 10 | 11 | from "mbedtls_sgx.edl" import *; 12 | from "sgx_tstdc.edl" import *; 13 | include "ssl_context.h" 14 | include "sgx_utils.h" 15 | 16 | from "sgx_tae_service.edl" import create_session_ocall, exchange_report_ocall, close_session_ocall, invoke_service_ocall; 17 | 18 | include "ra.h" 19 | 20 | /* from "../deps/sgx_zmq/sgx_tcdr/include/sgx_tcdr.edl" import *; */ 21 | trusted { 22 | /* define ECALLs here. */ 23 | public void ssl_conn_init([in,out] enclave_params_t *params); 24 | public void ssl_conn_teardown(void); 25 | public void ssl_conn_handle(long int thread_id, [in,out] thread_info_t* thread_info); 26 | }; 27 | 28 | untrusted { 29 | /* define OCALLs here. */ 30 | void ocall_sgx_init_quote([out] sgx_target_info_t* target_info); 31 | void ocall_remote_attestation([in] sgx_report_t* report, 32 | [out] attestation_verification_report_t* attn_report 33 | ); 34 | }; 35 | }; 36 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/Enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | local: 8 | *; 9 | }; 10 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/certs/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/ecalls.cpp: -------------------------------------------------------------------------------- 1 | #include "Enclave_t.h" 2 | #include "ssl_conn_hdlr.h" 3 | 4 | TLSConnectionHandler* connectionHandler; 5 | 6 | void ssl_conn_init(enclave_params_t *params) { 7 | connectionHandler = new TLSConnectionHandler(params); 8 | } 9 | 10 | void ssl_conn_handle(long int thread_id, thread_info_t* thread_info) { 11 | connectionHandler->handle(thread_id, thread_info); 12 | } 13 | 14 | void ssl_conn_teardown(void) { 15 | delete connectionHandler; 16 | } 17 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/embed_cert.args: -------------------------------------------------------------------------------- 1 | -c ./certs 2 | -e 36fb2eccd79ef59f72aeb806deb7052c38a1f75620f8fc8d947d855d638fd369 3 | -s 63ef969cbc34ee465f277cd3c27e9b3c681d743e455f899daced1b3cf85ceb8f 4 | -i 0 5 | -f ca_bundle.h 6 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/key_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * key_store.h 3 | * 4 | */ 5 | 6 | #ifndef KMS_ENCLAVE_KEY_STORE_H_ 7 | #define KMS_ENCLAVE_KEY_STORE_H_ 8 | 9 | #include 10 | #include 11 | #include "sgx_trts.h" 12 | //#include "sgx_tae_service.h" 13 | #include "sgx_tprotected_fs.h" 14 | #include "sgx_tcrypto.h" 15 | #include "sgx_tseal.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | // namespace format: 26 | #define MAX_PATH_LEN 1024 27 | #define DEFAULT_KEY_SIZE 16 // 128 bits 28 | 29 | class KeyStore { 30 | public: 31 | KeyStore(); 32 | ~KeyStore(); 33 | 34 | //APIs 35 | int get_key(char*, char*); 36 | void set_store_path(char*); 37 | bool load_fs_key(); 38 | int delete_key(char*); 39 | 40 | private: 41 | // key store path where sealed keys will be stored 42 | char *store_path; 43 | // master key used to protect all name space keys 44 | sgx_key_128bit_t fs_key; 45 | 46 | // Internal APIs 47 | bool seal_key(char*, sgx_sealed_data_t*, size_t); 48 | bool unseal_key(sgx_sealed_data_t *, char*); 49 | int create_random_key(char*, size_t); 50 | bool get_fs_key_filename(char *); 51 | bool create_fs_key(); 52 | 53 | 54 | // File handling 55 | SGX_FILE *open_secure_file(char*, const char*, bool); 56 | bool write_to_file(char*, char*, size_t); 57 | bool read_from_file(char*, char*, size_t); 58 | int namespace_to_path(char*, char*); 59 | 60 | }; 61 | 62 | // test 63 | int test_key_store(); 64 | 65 | #endif /* KMS_ENCLAVE_KEY_STORE_H_ */ 66 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/mbedtls_sgx.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | include "mbedtls/net.h" 3 | include "mbedtls/timing.h" 4 | 5 | trusted { 6 | public void dummy(void); 7 | }; 8 | 9 | untrusted { 10 | // implemented in net_v.h 11 | // [in] means going with the call 12 | // [out] means getting out from the call 13 | int ocall_mbedtls_net_connect([in, out] mbedtls_net_context *ctx, [in,string] const char *host, [in,string] const char *port, int proto ); 14 | int ocall_mbedtls_net_bind( [out] mbedtls_net_context *ctx, [in,string] const char *bind_ip, [in,string] const char *port, int proto ); 15 | int ocall_mbedtls_net_accept( [in] mbedtls_net_context *bind_ctx, [out] mbedtls_net_context *client_ctx, [out, size=buf_size] void *client_ip, size_t buf_size, [out] size_t *ip_len ); 16 | int ocall_mbedtls_net_set_block([in,out] mbedtls_net_context *ctx ); 17 | int ocall_mbedtls_net_set_nonblock( [in,out] mbedtls_net_context *ctx ); 18 | void ocall_mbedtls_net_usleep( unsigned long usec ); 19 | int ocall_mbedtls_net_recv( [in,out] mbedtls_net_context *ctx, [out, size=len] unsigned char *buf, size_t len ); 20 | int ocall_mbedtls_net_send( [in,out] mbedtls_net_context *ctx, [in, size=len] const unsigned char *buf, size_t len ); 21 | int ocall_mbedtls_net_recv_timeout( [in,out] mbedtls_net_context *ctx, [out, size=len] unsigned char *buf, size_t len, uint32_t timeout ); 22 | void ocall_mbedtls_net_free( [in, out] mbedtls_net_context *ctx ); 23 | 24 | // printf 25 | int ocall_print_string([in, string] const char *str); 26 | }; 27 | }; 28 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/memmem.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMMEM_H 2 | #define MEMMEM_H 3 | 4 | void *memmem(const void *h0, size_t k, const void *n0, size_t l); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /sgxcdr/kms/Enclave/sgxsdk-ra-attester_t.c: -------------------------------------------------------------------------------- 1 | // TODO: ADD license 2 | #include 3 | 4 | #include 5 | 6 | #include "Enclave_t.h" // OCALLs 7 | 8 | /* Trusted portion (called from within the enclave) to do remote 9 | attestation with the SGX SDK. */ 10 | 11 | void do_remote_attestation(sgx_report_data_t* report_data, 12 | attestation_verification_report_t* r); 13 | 14 | void do_remote_attestation 15 | ( 16 | sgx_report_data_t* report_data, 17 | attestation_verification_report_t* attn_report 18 | ) 19 | { 20 | sgx_target_info_t target_info = {0, }; 21 | ocall_sgx_init_quote(&target_info); 22 | 23 | sgx_report_t report = {0, }; 24 | sgx_status_t status = sgx_create_report(&target_info, report_data, &report); 25 | assert(status == SGX_SUCCESS); 26 | 27 | ocall_remote_attestation(&report, attn_report); 28 | } 29 | -------------------------------------------------------------------------------- /sgxcdr/kms/certs/ias-leaf-cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/kms/certs/ias-leaf-cert.der -------------------------------------------------------------------------------- /sgxcdr/kms/certs/ias-leaf-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEoTCCAwmgAwIBAgIJANEHdl0yo7CWMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNV 4 | BAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQDDCdJbnRlbCBTR1ggQXR0ZXN0 5 | YXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwHhcNMTYxMTIyMDkzNjU4WhcNMjYxMTIw 6 | MDkzNjU4WjB7MQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFDASBgNVBAcMC1Nh 7 | bnRhIENsYXJhMRowGAYDVQQKDBFJbnRlbCBDb3Jwb3JhdGlvbjEtMCsGA1UEAwwk 8 | SW50ZWwgU0dYIEF0dGVzdGF0aW9uIFJlcG9ydCBTaWduaW5nMIIBIjANBgkqhkiG 9 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqXot4OZuphR8nudFrAFiaGxxkgma/Es/BA+t 10 | beCTUR106AL1ENcWA4FX3K+E9BBL0/7X5rj5nIgX/R/1ubhkKWw9gfqPG3KeAtId 11 | cv/uTO1yXv50vqaPvE1CRChvzdS/ZEBqQ5oVvLTPZ3VEicQjlytKgN9cLnxbwtuv 12 | LUK7eyRPfJW/ksddOzP8VBBniolYnRCD2jrMRZ8nBM2ZWYwnXnwYeOAHV+W9tOhA 13 | ImwRwKF/95yAsVwd21ryHMJBcGH70qLagZ7Ttyt++qO/6+KAXJuKwZqjRlEtSEz8 14 | gZQeFfVYgcwSfo96oSMAzVr7V0L6HSDLRnpb6xxmbPdqNol4tQIDAQABo4GkMIGh 15 | MB8GA1UdIwQYMBaAFHhDe3amfrzQr35CN+s1fDuHAVE8MA4GA1UdDwEB/wQEAwIG 16 | wDAMBgNVHRMBAf8EAjAAMGAGA1UdHwRZMFcwVaBToFGGT2h0dHA6Ly90cnVzdGVk 17 | c2VydmljZXMuaW50ZWwuY29tL2NvbnRlbnQvQ1JML1NHWC9BdHRlc3RhdGlvblJl 18 | cG9ydFNpZ25pbmdDQS5jcmwwDQYJKoZIhvcNAQELBQADggGBAGcIthtcK9IVRz4r 19 | Rq+ZKE+7k50/OxUsmW8aavOzKb0iCx07YQ9rzi5nU73tME2yGRLzhSViFs/LpFa9 20 | lpQL6JL1aQwmDR74TxYGBAIi5f4I5TJoCCEqRHz91kpG6Uvyn2tLmnIdJbPE4vYv 21 | WLrtXXfFBSSPD4Afn7+3/XUggAlc7oCTizOfbbtOFlYA4g5KcYgS1J2ZAeMQqbUd 22 | ZseZCcaZZZn65tdqee8UXZlDvx0+NdO0LR+5pFy+juM0wWbu59MvzcmTXbjsi7HY 23 | 6zd53Yq5K244fwFHRQ8eOB0IWB+4PfM7FeAApZvlfqlKOlLcZL2uyVmzRkyR5yW7 24 | 2uo9mehX44CiPJ2fse9Y6eQtcfEhMPkmHXI01sN+KwPbpA39+xOsStjhP9N1Y1a2 25 | tQAVo+yVgLgV2Hws73Fc0o3wC78qPEA+v2aRs/Be3ZFDgDyghc/1fgU+7C+P6kbq 26 | d4poyb6IW8KCJbxfMJvkordNOgOUUxndPHEi/tb/U7uLjLOgPA== 27 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /sgxcdr/kms/certs/ias-root-cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/kms/certs/ias-root-cert.der -------------------------------------------------------------------------------- /sgxcdr/kms/certs/ias-root-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFSzCCA7OgAwIBAgIJANEHdl0yo7CUMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNV 4 | BAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQDDCdJbnRlbCBTR1ggQXR0ZXN0 5 | YXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwIBcNMTYxMTE0MTUzNzMxWhgPMjA0OTEy 6 | MzEyMzU5NTlaMH4xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwL 7 | U2FudGEgQ2xhcmExGjAYBgNVBAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQD 8 | DCdJbnRlbCBTR1ggQXR0ZXN0YXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwggGiMA0G 9 | CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCfPGR+tXc8u1EtJzLA10Feu1Wg+p7e 10 | LmSRmeaCHbkQ1TF3Nwl3RmpqXkeGzNLd69QUnWovYyVSndEMyYc3sHecGgfinEeh 11 | rgBJSEdsSJ9FpaFdesjsxqzGRa20PYdnnfWcCTvFoulpbFR4VBuXnnVLVzkUvlXT 12 | L/TAnd8nIZk0zZkFJ7P5LtePvykkar7LcSQO85wtcQe0R1Raf/sQ6wYKaKmFgCGe 13 | NpEJUmg4ktal4qgIAxk+QHUxQE42sxViN5mqglB0QJdUot/o9a/V/mMeH8KvOAiQ 14 | byinkNndn+Bgk5sSV5DFgF0DffVqmVMblt5p3jPtImzBIH0QQrXJq39AT8cRwP5H 15 | afuVeLHcDsRp6hol4P+ZFIhu8mmbI1u0hH3W/0C2BuYXB5PC+5izFFh/nP0lc2Lf 16 | 6rELO9LZdnOhpL1ExFOq9H/B8tPQ84T3Sgb4nAifDabNt/zu6MmCGo5U8lwEFtGM 17 | RoOaX4AS+909x00lYnmtwsDVWv9vBiJCXRsCAwEAAaOByTCBxjBgBgNVHR8EWTBX 18 | MFWgU6BRhk9odHRwOi8vdHJ1c3RlZHNlcnZpY2VzLmludGVsLmNvbS9jb250ZW50 19 | L0NSTC9TR1gvQXR0ZXN0YXRpb25SZXBvcnRTaWduaW5nQ0EuY3JsMB0GA1UdDgQW 20 | BBR4Q3t2pn680K9+QjfrNXw7hwFRPDAfBgNVHSMEGDAWgBR4Q3t2pn680K9+Qjfr 21 | NXw7hwFRPDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADANBgkq 22 | hkiG9w0BAQsFAAOCAYEAeF8tYMXICvQqeXYQITkV2oLJsp6J4JAqJabHWxYJHGir 23 | IEqucRiJSSx+HjIJEUVaj8E0QjEud6Y5lNmXlcjqRXaCPOqK0eGRz6hi+ripMtPZ 24 | sFNaBwLQVV905SDjAzDzNIDnrcnXyB4gcDFCvwDFKKgLRjOB/WAqgscDUoGq5ZVi 25 | zLUzTqiQPmULAQaB9c6Oti6snEFJiCQ67JLyW/E83/frzCmO5Ru6WjU4tmsmy8Ra 26 | Ud4APK0wZTGtfPXU7w+IBdG5Ez0kE1qzxGQaL4gINJ1zMyleDnbuS8UicjJijvqA 27 | 152Sq049ESDz+1rRGc2NVEqh1KaGXmtXvqxXcTB+Ljy5Bw2ke0v8iGngFBPqCTVB 28 | 3op5KBG3RjbF6RRSzwzuWfL7QErNC8WEy5yDVARzTA5+xmBc388v9Dm21HGfcC8O 29 | DD+gT9sSpssq0ascmvH49MOgjt1yoysLtdCtJW/9FZpoOypaHx0R+mJTLwPXVMrv 30 | DaVzWh5aiEx+idkSGMnX 31 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /sgxcdr/kms/certs/server-pubkey.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omec-project/c3po/df54425693014cfc0cbe10be897364df00f8523e/sgxcdr/kms/certs/server-pubkey.der -------------------------------------------------------------------------------- /sgxcdr/kms/certs/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIDYDCCAkgCAQAwgdAxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhOZXcgWW9yazES 3 | MBAGA1UEBwwJUm9jaGVzdGVyMRIwEAYDVQQKDAlFbmQgUG9pbnQxFzAVBgNVBAsM 4 | DlRlc3RpbmcgRG9tYWluMUswSQYJKoZIhvcNAQkBFjx5b3VyLWFkbWluaXN0cmF0 5 | aXZlLWFkZHJlc3NAeW91ci1hd2Vzb21lLWV4aXN0aW5nLWRvbWFpbi5jb20xIDAe 6 | BgNVBAMMF3d3dy55b3VyLW5ldy1kb21haW4uY29tMIIBIjANBgkqhkiG9w0BAQEF 7 | AAOCAQ8AMIIBCgKCAQEAwJUI4VdB8nFtt9JFQScBZcZFrvK8JDC4lc4vTtb2HIi8 8 | fJ/7qGd//lycUXX3isoH5zUvj+G9e8AvfKtkqBf8yl17uuAh5XIuby6G2JVz2qwb 9 | U7lfP9cZDSVP4WNjUYsLZD+tQ7ilHFw0s64AoGPF9n8LWWh4c6aMGKkCba/DGQEu 10 | uBDjxsxAtGmjRjNph27Euxem8+jdrXO8ey8htf1mUQy9VLPhbV8cvCNz0QkDiRTS 11 | ELlkwyrQoZZKvOHUGlvHoMDBY3gPRDcwMpaAMiOVoXe6E9KXc+JdJclqDcM5YKS0 12 | sGlCQgnp2Ai8MyCzWCKnquvE4eZhg8XSlt/Z0E+t1wIDAQABoEowSAYJKoZIhvcN 13 | AQkOMTswOTA3BgNVHREEMDAughN5b3VyLW5ldy1kb21haW4uY29tghd3d3cueW91 14 | ci1uZXctZG9tYWluLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAuQfWU6HmMGhtkVQx 15 | vHY6cuXv9dUgnDa3FxJEa6JtTyi6hjb1miefw9D3Cge13jk0WJ75Cd83ubCG4qq8 16 | pqXCY54yehDl8UWjNqRks3Mq45KOm+a2u4ZPWghvaHyoa6GIsvSpu3Rzb2HEFWVW 17 | 5rfnMCd/zoUvipov5Cr/Jb6s4rF29DsAZpkz+3y1/Xw9tyzI/g/y9SjIE2aWJRMr 18 | AOdo6jZ2Q0svpFAlkUCiiIof426vBJ/zxdzYBMXTu+6arNhVZcfVt4KgQMRP6Unx 19 | /WWrQgMELNbn43X1y5yzP0m+PK1ttMsgjz+Q6uMb1YwfOAf1bOvSEU1f3U+fwVAs 20 | fTrXOA== 21 | -----END CERTIFICATE REQUEST----- 22 | -------------------------------------------------------------------------------- /sgxcdr/kms/conf/kms.json: -------------------------------------------------------------------------------- 1 | { 2 | "kms": { 3 | "storepath": "./store", 4 | "port": "8443", 5 | "maxconnections": "16" 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/Utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sgx_error.h" 4 | #include "sgx_eid.h" /* sgx_enclave_id_t */ 5 | 6 | #ifndef TRUE 7 | # define TRUE 1 8 | #endif 9 | 10 | #ifndef FALSE 11 | # define FALSE 0 12 | #endif 13 | 14 | #if defined(_MSC_VER) 15 | #define TOKEN_FILENAME "Enclave.token" 16 | #define ENCLAVE_FILENAME "Enclave.signed.dll" 17 | #elif defined(__GNUC__) 18 | #define TOKEN_FILENAME "enclave.token" 19 | #define ENCLAVE_FILENAME "enclave.signed.so" 20 | #endif 21 | 22 | void print_error_message(sgx_status_t ret); 23 | int initialize_enclave(sgx_enclave_id_t *eid); 24 | 25 | #if defined(_MSC_VER) 26 | int query_sgx_status(); 27 | #endif 28 | 29 | #if defined(__cplusplus) 30 | extern "C" { 31 | #endif 32 | 33 | //extern sgx_enclave_id_t global_eid; /* global enclave id */ 34 | 35 | 36 | typedef struct _sgx_errlist_t { 37 | sgx_status_t err; 38 | const char *msg; 39 | const char *sug; /* Suggestion */ 40 | } sgx_errlist_t; 41 | 42 | 43 | #if defined(__cplusplus) 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/ias-ra.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | void obtain_attestation_verification_report( 6 | const sgx_quote_t* quote, 7 | const uint32_t quote_size, 8 | attestation_verification_report_t* attn_report 9 | ); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/mbedtls-ra-attester.h: -------------------------------------------------------------------------------- 1 | void create_key_and_x509 2 | ( 3 | mbedtls_pk_context* key, 4 | mbedtls_x509_crt* cert 5 | ); 6 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/memmem.h: -------------------------------------------------------------------------------- 1 | void *memmem(const void *h0, size_t k, const void *n0, size_t l); 2 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __OPTIONS_H 9 | #define __OPTIONS_H 10 | 11 | #include 12 | #include 13 | 14 | class Options 15 | { 16 | public: 17 | 18 | static bool parse( int argc, char **argv ); 19 | static bool parseInputOptions( int argc, char **argv ); 20 | static bool parseJson(); 21 | static bool validateOptions(); 22 | static const std::string &jsonConfig() { return m_jsoncfg; } 23 | static const std::string &Port() { return m_port; } 24 | static const size_t maxConnections() { return m_maxconnections; } 25 | static const std::string &storePath() { return m_storepath; } 26 | 27 | private: 28 | 29 | enum OptionsSelected { 30 | jsoncfg = 0x01, 31 | port = 0x02, 32 | maxconnections = 0x04, 33 | storepath = 0x08, 34 | whitelisted = 0x10, 35 | }; 36 | 37 | static void help(); 38 | 39 | static const int JSONFILEBUFFER; 40 | static int options; 41 | 42 | static std::string m_jsoncfg; 43 | static std::string m_port; 44 | static size_t m_maxconnections; 45 | static std::string m_storepath; 46 | 47 | }; 48 | 49 | #endif // #define __OPTIONS_H 50 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/ra-challenger.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void get_quote_from_report(const uint8_t* report /* in */, 4 | const int report_len /* in */, 5 | sgx_quote_t* quote); 6 | 7 | void get_quote_from_cert( 8 | const uint8_t* der_crt, 9 | uint32_t der_crt_len, 10 | sgx_quote_t* q 11 | ); 12 | 13 | void get_quote_from_cert1( 14 | const uint8_t* der_crt, 15 | uint32_t der_crt_len, 16 | sgx_quote_t* q 17 | ); 18 | 19 | int verify_sgx_cert_extensions 20 | ( 21 | const uint8_t* der_crt, 22 | uint32_t der_crt_len 23 | ); 24 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/ra.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | uint8_t ias_report[2*1024]; 3 | uint32_t ias_report_len; 4 | uint8_t ias_sign_ca_cert[2*1024]; 5 | uint32_t ias_sign_ca_cert_len; 6 | uint8_t ias_sign_cert[2*1024]; 7 | uint32_t ias_sign_cert_len; 8 | uint8_t ias_report_signature[2*1024]; 9 | uint32_t ias_report_signature_len; 10 | } attestation_verification_report_t; 11 | -------------------------------------------------------------------------------- /sgxcdr/kms/include/ssl_context.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by fanz on 4/7/17. 3 | // 4 | 5 | #ifndef MBEDTLS_SGX_SSL_CONTEXT_H 6 | #define MBEDTLS_SGX_SSL_CONTEXT_H 7 | 8 | #include "mbedtls/ssl.h" 9 | #include "mbedtls/net.h" 10 | 11 | #define MAX_PATH_LEN 1024 12 | typedef struct { 13 | mbedtls_net_context client_fd; 14 | int thread_complete; 15 | const mbedtls_ssl_config *config; 16 | unsigned char client_ip[16]; 17 | size_t ip_len; 18 | } thread_info_t; 19 | 20 | typedef struct { 21 | char store_path[MAX_PATH_LEN]; 22 | }enclave_params_t; 23 | 24 | #endif //MBEDTLS_SGX_SSL_CONTEXT_H 25 | -------------------------------------------------------------------------------- /sgxcdr/kms/store/.gitignore: -------------------------------------------------------------------------------- 1 | **/kms/store/* 2 | -------------------------------------------------------------------------------- /sgxcdr/router/README.txt: -------------------------------------------------------------------------------- 1 | Router System Dependency Install and Run guide 2 | 3 | ZeroMQ based store and forward asynchronous queue. Router system assigns 4 | input stream from DealerIn to output stream for DealerOut. 5 | 6 | About this guide 7 | 8 | This document provides instructions on "How to build and run KMS". 9 | 10 | =================== 11 | Supported Platforms 12 | =================== 13 | 14 | 1. OS: Ubuntu:16.04, Arch: x64 15 | 16 | ============ 17 | Dependencies 18 | ============ 19 | 20 | Following is the list of dependency. 21 | 22 | 1. Python 2.7 23 | 2. PyZMQ - Python bindings for zeromq. 24 | 25 | ==================== 26 | Install Dependencies 27 | ==================== 28 | 29 | * Installer Script 30 | Execute install.sh script to install dependencies. 31 | 32 | #./install.sh 33 | 34 | * Manual Installation 35 | 1. Install Python 2.7 36 | 37 | #sudo apt update 38 | #sudo apt install python2.7 python-pip 39 | 40 | 2. Install PyZMQ 41 | 42 | #pip install pyzmq==17.0.0 43 | 44 | ================== 45 | Run Router System 46 | ================== 47 | 1. Start Monitor 48 | 49 | #python start_and__monitor.py 50 | 51 | 2. Start InQueue Router 52 | 53 | #python in_queue_router.py 54 | 55 | 3. Start OutQueue Router 56 | 57 | #python out_queue_router.py 58 | 59 | -------------------------------------------------------------------------------- /sgxcdr/router/cdr_slave_streamer_device.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright 2019-present Open Networking Foundation 3 | SPDX-License-Identifier: Apache-2.0 4 | ''' 5 | import time 6 | import zmq 7 | import socket 8 | import os 9 | import sys 10 | 11 | def create_slave_streamer_queue(dp_ip): 12 | 13 | try: 14 | context = zmq.Context(1) 15 | 16 | frontend = context.socket(zmq.PULL) 17 | frontend.setsockopt(zmq.RCVBUF,32768) 18 | frontend.setsockopt(zmq.RCVHWM,999999) 19 | frontend.bind("ipc://ipc/slaves/pull/"+dp_ip) 20 | 21 | backend = context.socket(zmq.PUSH) 22 | backend.setsockopt(zmq.SNDBUF,32768) 23 | backend.setsockopt(zmq.SNDHWM,999999) 24 | backend.bind("ipc://ipc/slaves/push/"+dp_ip) 25 | 26 | zmq.device(zmq.STREAMER, frontend, backend) 27 | except: 28 | print "bringing down zmq device" 29 | finally: 30 | pass 31 | frontend.close() 32 | backend.close() 33 | context.term() 34 | 35 | 36 | os.system("mkdir -p ./ipc/slaves/pull") 37 | os.system("mkdir -p ./ipc/slaves/push") 38 | 39 | print len(sys.argv[1]) 40 | create_slave_streamer_queue(sys.argv[1]) 41 | 42 | -------------------------------------------------------------------------------- /sgxcdr/router/install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | sudo apt update 4 | sudo apt install python2.7 python-pip 5 | pip install pyzmq==17.0.0 6 | -------------------------------------------------------------------------------- /util/.gitignore: -------------------------------------------------------------------------------- 1 | .depend 2 | build/* 3 | lib/* 4 | -------------------------------------------------------------------------------- /util/Makefile: -------------------------------------------------------------------------------- 1 | CC := g++ # This is the main compiler 2 | SRCDIR := src 3 | BUILDDIR := build 4 | TARGETDIR := lib 5 | LIBNAME := libc3po.a 6 | TARGET := $(TARGETDIR)/$(LIBNAME) 7 | INSTDIRINC := /usr/local/include/c3po 8 | INSTDIRLIB := /usr/local/lib 9 | INSTLIB := $(INSTDIRLIB)/$(LIBNAME) 10 | 11 | SECURITY_FLAGS := -D_FORTIFY_SOURCE=2 -fasynchronous-unwind-tables -fexceptions 12 | SECURITY_FLAGS += -fstack-protector-all -fstack-protector-strong -Wall 13 | SECURITY_FLAGS += -Werror=format-security -Werror=implicit-function-declaration 14 | SRCEXT := cpp 15 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 16 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 17 | DEPENDS := $(OBJECTS:%.o=%.d) 18 | CFLAGS := -std=c++14 -Wreturn-type -g -pthread -lrt $(SECURITY_FLAGS)# -Wall 19 | 20 | LIBS := \ 21 | -l:libpistache.a 22 | 23 | 24 | INC := -I include \ 25 | -I $(ROOT)/modules/c-ares \ 26 | -I $(ROOT)/modules/spdlog/include 27 | 28 | $(TARGET): $(OBJECTS) 29 | @echo " Linking..." 30 | @mkdir -p $(TARGETDIR) 31 | @echo " ar rcs $(TARGET) $(OBJECTS) "; ar rcs $(TARGET) $(OBJECTS) 32 | 33 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) Makefile 34 | @mkdir -p $(BUILDDIR) 35 | @echo " $(CC) $(CFLAGS) $(INC) -MMD -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -MMD -c -o $@ $< 36 | 37 | clean: 38 | @echo " Cleaning..."; 39 | @echo " $(RM) -r $(BUILDDIR) $(TARGETDIR)"; $(RM) -r $(BUILDDIR) $(TARGETDIR) 40 | 41 | install: $(TARGET) 42 | @echo " Installing..." 43 | @echo " creating/verifying $(INSTDIRINC)" 44 | @mkdir -p $(INSTDIRINC) 45 | @echo " copying headers to $(INSTDIRINC)" 46 | @cp -a include/* $(INSTDIRINC) 47 | @echo " creating/verifying $(INSTDIRLIB)" 48 | @mkdir -p $(INSTDIRLIB) 49 | @echo " copying $(TARGET) to $(INSTLIB)" 50 | @cp -a $(TARGET) $(INSTLIB) 51 | @echo " Installation complete" 52 | 53 | -include $(DEPENDS) 54 | 55 | .PHONY: clean 56 | -------------------------------------------------------------------------------- /util/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | # C3PO: UTIL Library Build Instructions 3 | --- 4 | Perform the following procedures in order. 5 | 1. Follow the instructions located in the **_"Build and Installation Instructions for External Modules"_** provided in _{installation_root}/c3po/README.md_. Make sure these steps are complete. 6 | 2. Build the **UTIL** library. 7 | 8 | $ cd {installation_root}/c3po/util 9 | $ make 10 | -------------------------------------------------------------------------------- /util/README.txt: -------------------------------------------------------------------------------- 1 | C3PO: UTIL Library Build Instructions 2 | 3 | Perform the following procedures in order. 4 | 5 | 1. Follow the instructions located in the "Build and Installation 6 | Instructions for External Modules" provided in 7 | {installation_root}/c3po/README.txt. Make sure these steps are complete. 8 | 9 | 2. Build the UTIL library. 10 | 11 | $ cd {installation_root}/c3po/util 12 | $ make 13 | -------------------------------------------------------------------------------- /util/include/cdnscache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __CDNSCACHE_H 9 | #define __CDNSCACHE_H 10 | 11 | #include "cdnsquery.h" 12 | #include "ssync.h" 13 | 14 | namespace CachedDNS 15 | { 16 | extern "C" typedef void(*CachedDNSQueryCallback)(Query *q, bool cacheHit, void *data); 17 | 18 | class QueryProcessor; 19 | 20 | class Cache 21 | { 22 | friend QueryProcessor; 23 | 24 | public: 25 | static Cache& getInstance(); 26 | 27 | Query* query( ns_type rtype, const std::string &domain, bool &cacheHit ); 28 | void query( ns_type rtype, const std::string &domain, CachedDNSQueryCallback cb, void *data=NULL ); 29 | 30 | protected: 31 | Query* processQuery( ns_type rtype, const std::string &domain ); 32 | 33 | private: 34 | Cache(); 35 | ~Cache(); 36 | 37 | Query* lookupQuery( ns_type rtype, const std::string &domain ); 38 | bool processQuery( ns_type rtype, const std::string &domain, CachedDNSQueryCallback cb); 39 | 40 | static void ares_callback(void *arg, int status, int timeouts, unsigned char *abuf, int alen); 41 | 42 | QueryCache m_cache; 43 | SMutex m_cachemutex; 44 | }; 45 | } 46 | 47 | #endif // #ifndef __CDNSCACHE_H 48 | -------------------------------------------------------------------------------- /util/include/fdjson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __FDJSON_H 9 | #define __FDJSON_H 10 | 11 | #include 12 | #include "freeDiameter/libfdproto.h" 13 | #include "freeDiameter/libfdcore.h" 14 | 15 | #ifdef __cplusplus 16 | void fdJsonGetJSON( msg_or_avp *ref, std::string &json, void (*errfunc)(const char *) ); 17 | bool fdJsonGetValueOfMember( std::string json, std::string member, std::string &value ); 18 | bool fdJsonGetApnValueFromSubData( std::string json, std::string &apn ); 19 | extern "C" { 20 | #endif 21 | 22 | int fdJsonAddAvps( const char *json, msg_or_avp *msg, void (*errfunc)(const char *) ); 23 | const char *fdJsonGetJSON( msg_or_avp *msg, void (*errfunc)(const char *) ); 24 | 25 | #define FDJSON_SUCCESS 0 26 | #define FDJSON_JSON_PARSING_ERROR 1 27 | #define FDJSON_EXCEPTION 2 28 | 29 | #ifdef __cplusplus 30 | }; 31 | #endif 32 | 33 | #endif /* #define __FDJSON_H */ 34 | -------------------------------------------------------------------------------- /util/include/satomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SATOMIC_H 9 | #define __SATOMIC_H 10 | 11 | #include 12 | 13 | #define atomic_dec_fetch(a) __sync_sub_and_fetch(&a,1) 14 | #define atomic_inc_fetch(a) __sync_add_and_fetch(&a,1) 15 | #define atomic_fetch_dec(a) __sync_fetch_and_sub(&a,1) 16 | #define atomic_fetch_inc(a) __sync_fetch_and_add(&a,1) 17 | 18 | #define atomic_add_fetch(a,b) __sync_add_and_fetch(&a,b) 19 | #define atomic_sub_fetch(a,b) __sync_sub_and_fetch(&a,b) 20 | #define atomic_fetch_add(a,b) __sync_fetch_and_add(&a,b) 21 | #define atomic_fetch_sub(a,b) __sync_fetch_and_sub(&a,b) 22 | 23 | #define atomic_fetch_and(a,b) __sync_fetch_and_and(&a,b) 24 | #define atomic_fetch_or(a,b) __sync_fetch_and_or(&a,b) 25 | #define atomic_and_fetch(a,b) __sync_and_and_fetch(&a,b) 26 | #define atomic_or_fetch(a,b) __sync_or_and_fetch(&a,b) 27 | 28 | #define atomic_cas(a,b,c) __sync_val_compare_and_swap(&a,b,c) 29 | #define atomic_swap(a,b) __sync_lock_test_and_set(&a,b) 30 | 31 | #endif // #define __SATOMIC_H 32 | 33 | -------------------------------------------------------------------------------- /util/include/sdir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SDIR_H 9 | #define __SDIR_H 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | //////////////////////////////////////////////////////////////////////////////// 17 | //////////////////////////////////////////////////////////////////////////////// 18 | 19 | typedef std::list SDirectoryListing; 20 | 21 | class SDirectory 22 | { 23 | public: 24 | SDirectory(); 25 | ~SDirectory(); 26 | 27 | const char *getFirstEntry( const char *directory, const char *filemask ); 28 | const char *getFirstEntry(); 29 | const char *getNextEntry(); 30 | 31 | static void getCurrentDirectory(std::string &dir); 32 | 33 | SDirectoryListing getListing( const char *directory, const char *filemask ); 34 | SDirectoryListing getListing(); 35 | 36 | const std::string &getDirectory() { return m_directory; } 37 | const std::string &setDirectory( const std::string &directory ) { return setDirectory( directory.c_str() ); } 38 | const std::string &setDirectory( const char *directory ) { return m_directory = directory; } 39 | 40 | const std::string &getFilemask() { return m_filemask; } 41 | const std::string &setFilemask( const std::string &filemask ) { return setFilemask( filemask.c_str() ); } 42 | const std::string &setFilemask( const char *filemask ); 43 | 44 | private: 45 | static void buildTable(); 46 | static bool match( const char *str, const char *mask, bool ignoreCase = false ); 47 | 48 | void closeHandle(); 49 | 50 | static char *m_table; 51 | 52 | DIR* m_handle; 53 | std::string m_directory; 54 | std::string m_filemask; 55 | std::string m_filename; 56 | }; 57 | 58 | #endif // #define __SDIR_H 59 | -------------------------------------------------------------------------------- /util/include/sfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SFILE_H 9 | #define __SFILE_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class SFile 17 | { 18 | public: 19 | SFile(); 20 | ~SFile(); 21 | 22 | bool open( const char *filename ); 23 | bool open( const std::string &filename ) 24 | { 25 | return open(filename.c_str()); 26 | } 27 | 28 | void setStream( FILE *stream ) 29 | { 30 | csv_file = stream; 31 | } 32 | 33 | void setfilename( std::string &filename ) 34 | { 35 | m_filename = filename; 36 | } 37 | 38 | char *getStreamBuffer() 39 | { 40 | return stream_buffer; 41 | } 42 | 43 | void close(); 44 | 45 | bool read(); 46 | 47 | bool is_open() { return (csv_file != NULL); } 48 | 49 | const std::string &filename() { return m_filename; } 50 | const std::string &data() { return m_data; } 51 | int64_t dataoffset() { return m_dataofs; } 52 | uint32_t datarecnbr() { return m_datarn; } 53 | 54 | bool renamed(); 55 | 56 | bool seek( uint32_t recnbr, std::ios::streampos offset ); 57 | 58 | private: 59 | FILE *csv_file; 60 | char *stream_buffer; 61 | std::ifstream m_stream; 62 | std::string m_filename; 63 | std::string m_data; 64 | uint32_t m_datarn; 65 | std::ios::streampos m_dataofs; 66 | uint32_t m_nextrn; 67 | std::ios::streampos m_nextofs; 68 | }; 69 | 70 | #endif // #define __SFILE_H 71 | -------------------------------------------------------------------------------- /util/include/slogger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SLOGGER_H 9 | #define __SLOGGER_H 10 | 11 | //#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" }; 12 | #define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "startup", "warn", "error", "off" }; 13 | 14 | #define SPDLOG_ENABLE_SYSLOG 15 | #include "spdlog/spdlog.h" 16 | 17 | class LoggerException : public std::runtime_error 18 | { 19 | public: 20 | LoggerException(const char *m) : std::runtime_error(m) {} 21 | LoggerException(const std::string &m) : std::runtime_error(m) {} 22 | }; 23 | 24 | class SLogger 25 | { 26 | public: 27 | SLogger( const char *category, std::vector &sinks, const char *pattern, size_t queue_size ); 28 | void trace( const char *format, ... ); 29 | void trace( const std::string &format, ... ); 30 | void debug( const char *format, ... ); 31 | void debug( const std::string &format, ... ); 32 | void info( const char *format, ... ); 33 | void info( const std::string &format, ... ); 34 | void startup( const char *format, ... ); 35 | void startup( const std::string &format, ... ); 36 | void warn( const char *format, ... ); 37 | void warn( const std::string &format, ... ); 38 | void error( const char *format, ... ); 39 | void error( const std::string &format, ... ); 40 | 41 | void flush() { m_log.flush(); } 42 | 43 | void set_level( spdlog::level::level_enum lvl ); 44 | 45 | spdlog::level::level_enum get_level(); 46 | 47 | const std::string & get_name(); 48 | 49 | private: 50 | SLogger(); 51 | 52 | enum _LogType 53 | { 54 | _ltTrace, 55 | _ltDebug, 56 | _ltInfo, 57 | _ltStartup, 58 | _ltWarn, 59 | _ltError 60 | }; 61 | 62 | void log( _LogType lt, const char *format, va_list &args ); 63 | 64 | spdlog::async_logger m_log; 65 | }; 66 | 67 | 68 | #endif // #define __SLOGGER_H 69 | -------------------------------------------------------------------------------- /util/include/squeue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SQUEUE_H 9 | #define __SQUEUE_H 10 | 11 | #include 12 | 13 | #include "ssync.h" 14 | 15 | class SQueueMessage 16 | { 17 | public: 18 | SQueueMessage( uint16_t id ); 19 | virtual ~SQueueMessage(); 20 | 21 | uint16_t getId() { return m_id; } 22 | uint16_t setId( uint16_t id ) { return m_id = id; } 23 | 24 | private: 25 | SQueueMessage(); 26 | 27 | uint16_t m_id; 28 | }; 29 | 30 | class SQueue 31 | { 32 | public: 33 | SQueue(); 34 | ~SQueue(); 35 | 36 | bool push( uint16_t msgid, bool wait = true ); 37 | bool push( SQueueMessage *msg, bool wait = true ); 38 | 39 | SQueueMessage *pop( bool wait = true ); 40 | 41 | private: 42 | SMutex m_mutex; 43 | SSemaphore m_sem; 44 | std::queue m_queue; 45 | }; 46 | 47 | #endif // #define __SQUEUE_H 48 | -------------------------------------------------------------------------------- /util/include/ssyslog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SSYSLOG_H 9 | #define __SSYSLOG_H 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include "ssync.h" 16 | 17 | class SSysLog 18 | { 19 | public: 20 | 21 | SSysLog(const std::string &identity); 22 | SSysLog(const std::string &identity, int option); 23 | SSysLog(const std::string &identity, int option, int facility); 24 | 25 | 26 | ~SSysLog(); 27 | 28 | std::string& getIdentity() { return m_ident; } 29 | std::string& setIdentity(std::string& v) { m_ident = v; return getIdentity(); } 30 | int getOption() { return m_option; } 31 | int setOption(int v) { m_option = v; return getOption(); } 32 | int getFacility() { return m_facility; } 33 | int setFacility(int v) { m_facility = v; return getFacility(); } 34 | 35 | void syslog(int priority, const char* format, ...); 36 | void syslogs(const std::string& val); 37 | 38 | protected: 39 | private: 40 | 41 | SSysLog(); 42 | 43 | void openSysLog(); 44 | void closeSysLog(); 45 | 46 | std::string m_ident; 47 | int m_option; 48 | int m_facility; 49 | bool m_isopen; 50 | 51 | SMutex m_mutex; 52 | 53 | }; 54 | 55 | 56 | 57 | 58 | #endif //#define __SSYSLOG_H 59 | -------------------------------------------------------------------------------- /util/include/stimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __STIMER_H 9 | #define __STIMER_H 10 | 11 | typedef long long int stime_t; 12 | 13 | 14 | class STimerElapsed 15 | { 16 | public: 17 | STimerElapsed(); 18 | STimerElapsed(STimerElapsed &a); 19 | STimerElapsed(stime_t t); 20 | ~STimerElapsed(); 21 | 22 | void Start(); 23 | void Stop(); 24 | void Set(stime_t a); 25 | stime_t MilliSeconds(bool bRestart = false); 26 | stime_t MicroSeconds(bool bRestart = false); 27 | 28 | STimerElapsed &operator = (STimerElapsed &a); 29 | STimerElapsed &operator = (stime_t t); 30 | 31 | operator stime_t() { return _time; } 32 | 33 | private: 34 | stime_t _time; 35 | stime_t _endtime; 36 | }; 37 | 38 | #endif // #define __STIMER_H 39 | -------------------------------------------------------------------------------- /util/include/sutility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __SUTILITY_H 9 | #define __SUTILITY_H 10 | 11 | #include 12 | #include 13 | 14 | class SUtility 15 | { 16 | public: 17 | static int indexOf(const char *path, char search, int start = 0); 18 | static int indexOfAny(const char *path, const char *search); 19 | static int lastIndexOfAny(const char *path, const char *search); 20 | static std::vector split( const std::string &s, const char delim ); 21 | static std::string string_format( const char *format, ... ); 22 | static void string_format( std::string &dest, const char *format, ... ); 23 | 24 | static void copyfile( const std::string &dst, const std::string &src ) { copyfile( dst.c_str(), src.c_str() ); } 25 | static void copyfile( const char *dst, const std::string &src ) { copyfile( dst, src.c_str() ); } 26 | static void copyfile( const std::string &dst, const char *src ) { copyfile( dst.c_str(), src ); } 27 | static void copyfile( const char *dst, const char *src ); 28 | 29 | static void deletefile( const std::string &fn ) { deletefile( fn.c_str() ); } 30 | static void deletefile( const char *fn ); 31 | 32 | static std::string currentTime(); 33 | 34 | private: 35 | static void _string_format( std::string &dest, const char *format, va_list &args ); 36 | }; 37 | 38 | #endif // #define __SUTILITY_H 39 | -------------------------------------------------------------------------------- /util/src/squeue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include 9 | 10 | #include "squeue.h" 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | //////////////////////////////////////////////////////////////////////////////// 14 | 15 | SQueueMessage::SQueueMessage( uint16_t id ) 16 | { 17 | m_id = id; 18 | } 19 | 20 | SQueueMessage::~SQueueMessage() 21 | { 22 | } 23 | 24 | //////////////////////////////////////////////////////////////////////////////// 25 | //////////////////////////////////////////////////////////////////////////////// 26 | 27 | SQueue::SQueue() 28 | { 29 | //m_sem.init( 0, SEM_VALUE_MAX ); 30 | m_sem.init( 0, 0 ); 31 | } 32 | 33 | SQueue::~SQueue() 34 | { 35 | SQueueMessage *m; 36 | 37 | while ( ( m = pop( false ) ) ) 38 | delete m; 39 | } 40 | 41 | bool SQueue::push( uint16_t msgid, bool wait ) 42 | { 43 | SQueueMessage *m = new SQueueMessage( msgid ); 44 | 45 | bool result = push( m, wait ); 46 | 47 | if ( !result ) 48 | delete m; 49 | 50 | return result; 51 | } 52 | 53 | bool SQueue::push( SQueueMessage *msg, bool wait ) 54 | { 55 | SMutexLock l( m_mutex, false ); 56 | 57 | if ( l.acquire( wait ) ) 58 | { 59 | m_queue.push( msg ); 60 | m_sem.increment(); 61 | return true; 62 | } 63 | 64 | return false; 65 | } 66 | 67 | SQueueMessage *SQueue::pop( bool wait ) 68 | { 69 | SQueueMessage *msg = NULL; 70 | 71 | if ( m_sem.decrement( wait ) ) 72 | { 73 | SMutexLock l( m_mutex, false ); 74 | 75 | if ( l.acquire( wait ) ) 76 | { 77 | msg = m_queue.front(); 78 | m_queue.pop(); 79 | } 80 | else 81 | { 82 | // increment the message count since we could not lock the queue 83 | m_sem.increment(); 84 | } 85 | } 86 | 87 | return msg; 88 | } 89 | -------------------------------------------------------------------------------- /util/src/ssyslog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * Copyright (c) 2017 Sprint 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include "ssyslog.h" 9 | #include 10 | 11 | SSysLog::SSysLog() 12 | :m_option(0), 13 | m_facility(0), 14 | m_isopen(false) 15 | { 16 | openSysLog(); 17 | } 18 | 19 | SSysLog::SSysLog(const std::string &identity) 20 | :m_ident(identity), 21 | m_isopen(false) 22 | { 23 | m_option = (LOG_NDELAY|LOG_PID|LOG_CONS); 24 | m_facility = LOG_USER; 25 | openSysLog(); 26 | } 27 | SSysLog::SSysLog(const std::string &identity, int option) 28 | :m_ident(identity), 29 | m_option(option), 30 | m_isopen(false) 31 | { 32 | m_facility = LOG_USER; 33 | openSysLog(); 34 | } 35 | SSysLog::SSysLog(const std::string &identity, int option, int facility) 36 | :m_ident(identity), 37 | m_option(option), 38 | m_facility(facility) 39 | { 40 | openSysLog(); 41 | } 42 | 43 | 44 | SSysLog::~SSysLog() 45 | { 46 | closelog(); 47 | } 48 | 49 | void SSysLog::openSysLog(){ 50 | openlog(m_ident.c_str(), m_option, m_facility); 51 | } 52 | 53 | void SSysLog::syslog(int priority, const char* format, ...) 54 | { 55 | va_list args; 56 | va_start(args, format); 57 | vsyslog(priority, format, args); 58 | va_end(args); 59 | } 60 | 61 | void SSysLog::syslogs(const std::string& val){ 62 | ::syslog(0, "%s", val.c_str()); 63 | } 64 | --------------------------------------------------------------------------------