123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include <phpcpp.h>
- #include <string.h>
- #include <string>
- #include <unistd.h>
- #include <errno.h>
- //#include <fcntl.h>
- //#include <sys/types.h>
- //#include <sys/stat.h>
- #include <stdio.h>
- //#include "crypto.h"
- #include "ProtobufLAInitiator.h"
- using namespace std;
- // #include <unistd.h>
- // based off the example functionreturnvalue.cpp in PHP-CPP
- /**
- * Namespace to use
- */
- //using namespace std;
- #define DECRYPTOR_PORT 3825
- int local_attestation_successful=0;
- int __ImageBase=0;
- //extern "C" {
- class Mitigator : public Php::Base
- {
- private:
- static std::string mitigator_header;
- // int x;
- public:
- // adding to extension throws an error if this method is not public
- static void local_attestation_initiator_wrapper()
- {
- setbuf(stdout,NULL); uint32_t count;
- uint32_t return_sgx;
- unsigned char base64_encoded_mitigator_header[229] ; //216=(ceil(160/3) * 4) + 1 (for null character) + 12 for "X-Mitigator:"
- memcpy(base64_encoded_mitigator_header, "X-Mitigator:", 12);
- return_sgx = local_attestation_initiator(DECRYPTOR_PORT, base64_encoded_mitigator_header+12);
- if(return_sgx != 0)
- {
- if(return_sgx== 0xFFFFFFFF)
- {
- perror("\nCould not set up the socket: had the following error: "); fflush(stderr);
- }
- else
- {
- printf("\nHad the following error in SGX local attestation: 0x%x", return_sgx);
- fflush(stdout);
- }
- }
- else {
- printf("\nSuccessful LA with port %d.\n", DECRYPTOR_PORT);
- fflush(stdout);
- local_attestation_successful=1;
- char base64_encoding[229];
- for(count=0;count<229;count++)
- base64_encoding[count]=base64_encoded_mitigator_header[count];
- printf("String:%s\nThat string was of length 0x%x\n", base64_encoding, strlen(base64_encoding)); fflush(stdout);
- mitigator_header=std::string(base64_encoding,228);
- }
- }
- // std::cout << "MyCustomClass::MyCustomClass()" << std::endl;
- Mitigator() = default; // {x=3;} //{ mitigator_header=std::string("Miti: Miti"); }
- virtual ~Mitigator() = default;
- // call this function in PHP async or call add_header here.
- Php::Value get_mitigator_header()
- {
- return mitigator_header; //Php::Value(mitigator_header, 176);
- }
- // call this func onRequest
- /* Php::Value decrypt_php_wrapper()
- {
- return "miti";
- }
- */
- };
-
- std::string Mitigator::mitigator_header=std::string("Miti: Miti");
- extern "C" {
- // export the "get_module" function that will be called by the Zend engine
- PHPCPP_EXPORT void *get_module()
- {
- // create extension
- static Php::Extension extension("decryptor_la_setup_and_decryption","1.0");
-
- Php::Class<Mitigator> mitigator("Mitigator");
- mitigator.method<&Mitigator::get_mitigator_header>("get_mitigator_header");
- // mitigator.property("mitigator_header", &Mitigator::get_mitigator_header);
- extension.onStartup(&Mitigator::local_attestation_initiator_wrapper);
- // return the extension module
- extension.add(mitigator);
- return extension.module();
- }
- }
|