예제 #1
0
void
Dispatcher::Did_LocalPrefix_Updated(const Ccnx::Name& forwardingHint)
{
  Name effectiveForwardingHint;
  if (m_localUserName.size() >= forwardingHint.size() &&
      m_localUserName.getPartialName(0, forwardingHint.size()) == forwardingHint) {
    effectiveForwardingHint = Name("/"); // "directly" accesible
  }
  else {
    effectiveForwardingHint = forwardingHint;
  }

  Name oldLocalPrefix = m_syncLog->LookupLocalLocator();

  if (oldLocalPrefix == effectiveForwardingHint) {
    _LOG_DEBUG(
      "Got notification about prefix change from " << oldLocalPrefix << " to: " << forwardingHint
                                                   << ", but effective prefix didn't change");
    return;
  }

  if (effectiveForwardingHint == Name("/") || effectiveForwardingHint == Name(BROADCAST_DOMAIN)) {
    _LOG_DEBUG("Basic effective prefix [" << effectiveForwardingHint
                                          << "]. Updating local prefix, but don't reregister");
    m_syncLog->UpdateLocalLocator(effectiveForwardingHint);
    return;
  }

  _LOG_DEBUG("LocalPrefix changed from: " << oldLocalPrefix << " to: " << effectiveForwardingHint);

  m_server->registerPrefix(effectiveForwardingHint);
  m_syncLog->UpdateLocalLocator(effectiveForwardingHint);

  if (oldLocalPrefix == Name("/") || oldLocalPrefix == Name(BROADCAST_DOMAIN)) {
    _LOG_DEBUG("Don't deregister basic prefix: " << oldLocalPrefix);
    return;
  }
  m_server->deregisterPrefix(oldLocalPrefix);
}
예제 #2
0
Ccnx::Name remoteServer::parseSharedKey(Ccnx::Name name, std::string &ret,
	    OrganizerSession *oSession,	ParticipantSession *pSession){
    int flag;

     std::string consumer = name.getCompAsString(2); //consumer
    std::string producer = name.getCompAsString(1); //producer
    std::string endPoint = name.getCompAsString(3); //endpoint
    std::string action = name.getCompAsString(4); //action
    std::string prefix = name.getCompAsString(0); //prefix

    int size = name.size();
    int version = 0;
    int chunkNum = 0;
    int chunkSize = 0;
    Ccnx::Name dataName = name;
    if (action.compare("fetch") == 0){
        std::string lastComponent = name.getCompAsString(size-2);
        if (boost::starts_with(lastComponent,"chunk="))
        {
            flag = 1;  //later packet
        }
        else{
            flag = 0;  //para
        }
        //  
        if (flag == 0){
        	  chunkSize = 0;
        	  chunkNum = 0;        	  
        	  if (oSession)
        	  {
                  oSession->recvFetchSharedKeyRemote(consumer, version, chunkNum,chunkSize, ret);
              }

//encrypt
            vector<std::string> tmp2;
            boost::split(tmp2,prefix,boost::is_any_of("_"));
            std::string app = tmp2[0];
            std::string publicKey[3];
            KeyDB::instance().getKeyFromUser(app,(KeyDB::global), publicKey,consumer);
      //      cout<<"after fetch"<<endl;
            cout<<"key content"<<endl;
            cout<<publicKey[1]<<endl;
            EVP_PKEY *pub_key = KeyDB::instance().str2Key(publicKey[1]);
     //       std::string plain_string = ret;
   //         cout<<"plain "<<plain_string<<endl;
 //           char *plain2 = (char *)(plain_string.c_str());
	//					cout<<pub_key->type<<endl;
	//					cout<<pub_key->pkey.ptr<<endl;
            char plain[128];
            sprintf(plain,"%s",ret.c_str());
//            cout<<"aaaaa"<<endl;
//            cout<<plain<<endl;
//            plain[3]='\0';
//            plain[plain_string.size()] = '\0';
    
      //      cout<<"sadfsf"<<endl;
    /*for test*/
/*            RSA *encrypt_key;
            FILE *rsa_pkey_file;
            rsa_pkey_file = fopen("../db/pub1.pub", "r");
            if (rsa_pkey_file == NULL)
            {
                cout<<"no pointer"<<endl;
            }
            cout<<"before bbbbb"<<endl;
				    if (!PEM_read_RSA_PUBKEY(rsa_pkey_file, &encrypt_key, NULL, NULL))
    				{
        			fprintf(stderr, "Error loading RSA Public Key File.\n");
        			ERR_print_errors_fp(stderr);
    				}
            fclose(rsa_pkey_file);
  */  				/*test end*/
  
  
            RSA *encrypt_key;
        //    EVP_PKEY_set1_RSA(pub_key,encrypt_key);
            encrypt_key = EVP_PKEY_get1_RSA(pub_key);
            int encrypt_len;
            cout<<RSA_size(encrypt_key)<<endl;
            char *encrypt = (char *)malloc(RSA_size(encrypt_key));
//            memset(encrypt,0,RSA_size(encrypt_key));
        //    cout<<"before encrpyt"<<endl;
            if((encrypt_len = RSA_public_encrypt(strlen(plain), (unsigned char*)plain, 
    					(unsigned char*)encrypt, encrypt_key, RSA_PKCS1_OAEP_PADDING)) == -1) {
					        ERR_load_crypto_strings();
    				}
/*            char *encrypt_test = (char *)malloc(RSA_size(encrypt_key));
            //            memset(encrypt,0,RSA_size(encrypt_key));
            cout<<"before encrpyt"<<endl;
            if((encrypt_len = RSA_public_encrypt(strlen(plain), (unsigned char*)plain,
                                                 (unsigned char*)encrypt_test, encrypt_key_test, RSA_PKCS1_OAEP_PADDING)) == -1) {
                ERR_load_crypto_strings();
            }
            cout<<"test   "<<encrypt_test<<endl;
  */
    //        cout<<"encrypt text:"<<endl;
     //       cout<<encrypt<<endl;
            ret = string(encrypt,encrypt_len);
            std::string tmp = "code=0,version=";
            std::string v = boost::lexical_cast <string>(version);
            tmp.append(v);
            tmp.append(",chunk=");
            std::string ch = boost::lexical_cast <string>(chunkSize);
            tmp.append(ch);
            dataName.appendComp(tmp);
        }
        else{
            dataName= name;
            vector<std::string> str1;
            boost::split(str1,lastComponent,boost::is_any_of("="));
            std::string versionComponent = name.getCompAsString(size-3);
            vector<std::string> str2;
            boost::split(str2,versionComponent,boost::is_any_of("="));
            version = atoi(str2[1].c_str());
            chunkNum = atoi(str1[1].c_str());
            if (oSession)
            {
                oSession->recvFetchSharedKeyRemote(consumer, version, chunkNum, chunkSize, ret);
            }
            char *from = (char *)ret.c_str();
            char *to = NULL ;
            //          get public key
            //           do_encrypt(&to, from,key,len);
        }
    }
    else{
        if (boost::starts_with(action,"update")){
            dataName.appendComp("code=0");
            vector<std::string> tmp;
            boost::split(tmp,action,boost::is_any_of("_"));            
            version = atoi(tmp[1].c_str());
            if (pSession)
            {
            	 pSession->recvRenewSharedKeyRemote(version);
            }
//           
//						orgsession->recvRenewSharedKeyRemote(version);
        }
    }
    return dataName;
};
예제 #3
0
Ccnx::Name remoteServer::parsePublicKey(Ccnx::Name name, std::string &ret,
	 OrganizerSession *oSession,	ParticipantSession *pSession){
    int flag;
//    std::string consumer = name.getCompAsString(1); //consumer
//    std::string producer = name.getCompAsString(2); //producer
 //   std::string endPoint = name.getCompAsString(3); //endpoint
  //  std::string action = name.getCompAsString(4); //action
    std::string consumer = name.getCompAsString(2); //consumer
    std::string producer = name.getCompAsString(1); //producer
    std::string endPoint = name.getCompAsString(3); //endpoint
    std::string action = name.getCompAsString(4); //action

    int size = name.size();
    int version = 0;
    int chunkNum = 0;
    int chunkSize = 0;
    Ccnx::Name dataName = name;
    if (action.compare("fetch") == 0){
        std::string lastComponent = name.getCompAsString(size-2);
        if (boost::starts_with(lastComponent,"chunk="))
        {
            flag = 1;
        }
        else{
            flag = 0;  //para
        }
        //  
        if (flag == 0){
        	  chunkSize = 0;
        	  chunkNum = 0;        	  
        	  if (oSession)
        	  {
						  oSession->recvFetchPublicKeyRemote(consumer, version, chunkNum,chunkSize, ret);
            }
            if (pSession)
        	  {
						  pSession->recvFetchPublicKeyRemote(consumer, version, chunkNum,chunkSize, ret);
            }
            std::string tmp = "code=0,version=";
            std::string v = boost::lexical_cast <string>(version);
            tmp.append(v);
            tmp.append(",chunk=");
            std::string ch = boost::lexical_cast <string>(chunkNum);
            tmp.append(ch);
            dataName.appendComp(tmp);
        }
        else{
            dataName= name;
            vector<std::string> str1;
            boost::split(str1,lastComponent,boost::is_any_of("="));
            std::string versionComponent = name.getCompAsString(size-3);
            vector<std::string> str2;
            boost::split(str2,versionComponent,boost::is_any_of("="));
            version = atoi(str2[1].c_str());
            chunkNum = atoi(str1[1].c_str());
            if (oSession)
        	  {
						  oSession->recvFetchPublicKeyRemote(consumer, version, chunkNum,chunkSize, ret);
            }
            if (pSession)
        	  {
						  pSession->recvFetchPublicKeyRemote(consumer, version, chunkNum,chunkSize, ret);
            }
        }
    }
    return dataName;
};