Changeset 33 in chevmsgr for trunk/msgsrv.cpp


Ignore:
Timestamp:
12/09/15 06:47:21 (8 years ago)
Author:
cheese
Message:
  1. 클라이언트 UI ID/PW 입력 안하면 죽는 문제 수정
  2. UI 종료 함수 exit로 수정
  3. 그룹챗 인덱스 변수 형 때문에 나오는 warning 수정
  4. toOpenSession 함수 가끔 죽는 문제 수정
  5. generateRandom()에서 time()하던거 rand()로 수정
  6. sms 전송 url 및 sms 코드 생성 로직 대폭 수정 (주석 참고)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/msgsrv.cpp

    r31 r33  
    294294}
    295295
    296 static unsigned int generateSeed()
    297 {
    298     unsigned int ret = 0;
    299     int t = (int)time(NULL);
    300 
    301     cf::bin b;
    302     b.resize(sizeof(int));
    303 
    304     b.set((cf::uint8_t*)&t, sizeof(int));
    305     cf::bin s = crypto().sha256(b);
    306 
    307     memcpy(&ret, s.buffer(), sizeof(unsigned int));
    308 
    309     return ret;
    310 }
    311 
    312296static std::string generateSMSCode()
    313297{
    314     return "545454";
    315     char random[8] = {0x00,};
    316     sprintf(random, "%06d", generateSeed() % 1000000);
    317 
    318     return random;
     298    cf::bin random  = generateRandom(); // ·£´ý °ª °¡Á®¿È
     299    cf::bin hash    = crypto().sha256(random); // ·£´ý °ª Çؽ¬
     300    std::string enc = cf::codec::hex::getInstance()->encode(hash); // Çؽ¬ÇÑ °á°ú hex encode
     301
     302    std::string sms; // ÃÖÁ¾ sms¹ÞÀ» º¯¼ö
     303
     304    // xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
     305    for (int i = 0; i < 8 ; i++)
     306    {
     307        char buf[128] = {0,};
     308
     309        // [0] ºÎÅÍ 4±ÛÀÚ, [4] ºÎÅÍ 4±ÛÀÚ, ...
     310        size_t start = i * 4;
     311
     312        // 1. enc º¯¼ö¿¡¼­ 4ÀÚ¸®¾¿ ¼ø¼­´ë·Î ¶¼¾î³»¼­ xxxx- ·Î ¸¸µë
     313        //    std::string::substr(½ÃÀÛ À妽º, °³¼ö)
     314        // 2. std::string::substr() ´Â std::stringÀ» return ÇϹǷÎ,
     315        //    std::string::c_str() ÇÏ¿© const char * ÇüÀ¸·Î ¹Þ¾Æ¿È
     316        snprintf(buf, sizeof(buf), "%s-", enc.substr(start, 4).c_str());
     317
     318        // xxxx- ·Î ¸¸µç°Å sms °á°ú¿¡ Ãß°¡
     319        sms += buf;
     320    }
     321
     322    // ·çÇÁ¿¡¼­ xxxx- ¸¦ °è¼Ó ºÙ¿©¼­ ´Ù ¸¸µé°í ³ª¸é ¸¶Áö¸·ÀÌ '-' ·Î ³¡³ª°Ô µÇ¹Ç·Î ¸¶Áö¸· ±ÛÀÚ ¶¼¾î³¿
     323    sms[sms.length() - 1] = 0;
     324
     325    return sms;
    319326}
    320327
     
    325332#define CRLF    "\r\n"
    326333    std::string code = generateSMSCode();
    327     std::string url = "unsigned.kr";
    328     std::string uri = "/~cheese/sms/req.php?to=" + phone + "&code=" + code;
     334    std::string url = "chev.unsigned.kr";
     335    std::string uri = "/sms/req.php?to=" + phone + "&code=" + code;
    329336    std::string http =
    330337        "GET " + uri + " HTTP/1.1" CRLF
Note: See TracChangeset for help on using the changeset viewer.