Ejemplo n.º 1
0
 // TODO: make this a QgsGeometry member...
 QgsGeometry geomFromHexWKB( const char *hexwkb )
 {
   int wkbsize;
   unsigned char *wkb = hex2bytes( hexwkb, &wkbsize );
   QgsGeometry geom;
   // NOTE: QgsGeometry takes ownership of wkb
   geom.fromWkb( wkb, wkbsize );
   return geom;
 }
Ejemplo n.º 2
0
TEST set1_challenge2(void)
{
    char *buff1 = "1c0111001f010100061a024b53535009181c";
    char *buff2 = "686974207468652062756c6c277320657965";
    char *expected = "746865206b696420646f6e277420706c6179";

    uint8_t *buff1_bytes = (uint8_t *)malloc(strlen(buff1));
    uint8_t *buff2_bytes = (uint8_t *)malloc(strlen(buff2));
    uint8_t *expected_bytes = (uint8_t *)malloc(strlen(expected));

    size_t numbytes = strlen(expected) / 2;

    if(buff1_bytes == NULL || buff2_bytes == NULL || expected_bytes == NULL) {
        FAILm("Unable to allocate buffers.");
    }

    retval_t retval = hex2bytes(buff1, numbytes, buff1_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert buff1 to bytes.");
    }
    retval = hex2bytes(buff2, numbytes, buff2_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert buff2 to bytes.");
    }
    retval = hex2bytes(expected, numbytes, expected_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert expected to bytes.");
    }

    uint8_t *result = NULL;
    retval = fixed_xor(numbytes, buff1_bytes, buff2_bytes, &result);
    if(retval != CALL_OK) {
        FAILm("fixed_xor() failed");
    }

    ASSERT_EQm("Result didn't match expected", 0, memcmp(result, expected_bytes, numbytes));

    free(result);
    free(expected_bytes);
    free(buff2_bytes);
    free(buff1_bytes);

    PASS();
}
bool
str2authdbrec (sfsauth_dbrec *dbr, str s)
{
  static rxx _userrx ("^USER:(.*)$");
  rxx userrx (_userrx);
  static rxx grouprx ("^GROUP:(.*)$");
  static rxx cacherx ("^CACHE:(.*)$");
  static rxx logrx ("^LOG:(.*)$");
  static rxx revinfo ("^REVINFO:([0-9a-fA-F]+):(\\d+)$");

  if (revinfo.match (s)) {
    str id = hex2bytes (revinfo[1]);
    u_int64_t rev;
    if (!id || id.len () != sizeof (dbr->revinfo->dbid)
	|| !convertint (revinfo[2], &rev))
      return false;
    dbr->set_type (SFSAUTH_REVINFO);
    dbr->revinfo->dbrev = rev;
    memcpy (dbr->revinfo->dbid.base (), id, id.len ());
    return true;
  }
  else if (userrx.match (s)) {
    dbr->set_type (SFSAUTH_USER);
    return str2userinfo (dbr->userinfo, str2wstr (userrx[1]));
  }
  else if (grouprx.match (s)) {
    dbr->set_type (SFSAUTH_GROUP);
    return str2groupinfo (dbr->groupinfo, grouprx[1]);
  }
  else if (cacherx.match (s)) {
    dbr->set_type (SFSAUTH_CACHEENTRY);
    return str2cacheentry (dbr->cacheentry, cacherx[1]);
  }
  else if (logrx.match (s)) {
    dbr->set_type (SFSAUTH_LOGENTRY);
    return str2logentry (dbr->logentry, logrx[1]);
  }
  else
    return false;
}
Ejemplo n.º 4
0
jint get_uid(const int version, const int protocol,
             const void *saddr, const uint16_t sport,
             int dump) {
    char line[250];
    char hex[16 * 2 + 1];
    int fields;
    uint8_t addr4[4];
    uint8_t addr6[16];
    int port;
    jint uid = -1;

#ifdef PROFILE_UID
    float mselapsed;
    struct timeval start, end;
    gettimeofday(&start, NULL);
#endif

    // NETLINK is not available on Android due to SELinux policies :-(

    // Get proc file name
    char *fn = NULL;
    if (protocol == IPPROTO_ICMP && version == 4)
        fn = "/proc/net/icmp";
    else if (protocol == IPPROTO_ICMPV6 && version == 6)
        fn = "/proc/net/icmp6";
    else if (protocol == IPPROTO_TCP)
        fn = (version == 4 ? "/proc/net/tcp" : "/proc/net/tcp6");
    else if (protocol == IPPROTO_UDP)
        fn = (version == 4 ? "/proc/net/udp" : "/proc/net/udp6");
    else
        return uid;

    if (dump) {
        char source[INET6_ADDRSTRLEN + 1];
        inet_ntop(version == 4 ? AF_INET : AF_INET6, saddr, source, sizeof(source));
        log_android(ANDROID_LOG_INFO, "Searching %s/%u in %s", source, sport, fn);
    }

    // Open proc file
    FILE *fd = fopen(fn, "r");
    if (fd == NULL) {
        log_android(ANDROID_LOG_ERROR, "fopen %s error %d: %s", fn, errno, strerror(errno));
        return uid;
    }

    // Scan proc file
    jint u;
    int i = 0;
    *line = 0;
    while (fgets(line, sizeof(line), fd) != NULL) {
        if (i++) {
            *hex = 0;
            port = -1;
            u = -1;
            if (version == 4)
                fields = sscanf(
                        line,
                        "%*d: %8s:%X %*X:%*X %*X %*lX:%*lX %*X:%*X %*X %d %*d %*ld",
                        hex, &port, &u);
            else
                fields = sscanf(
                        line,
                        "%*d: %32s:%X %*X:%*X %*X %*lX:%*lX %*X:%*X %*X %d %*d %*ld",
                        hex, &port, &u);
            if (fields == 3 &&
                (version == 4 ? strlen(hex) == 8 : strlen(hex) == 32) && port >= 0 && u >= 0) {
                hex2bytes(hex, version == 4 ? addr4 : addr6);
                if (version == 4)
                    ((uint32_t *) addr4)[0] = htonl(((uint32_t *) addr4)[0]);
                for (int w = 0; w < 4; w++)
                    ((uint32_t *) addr6)[w] = htonl(((uint32_t *) addr6)[w]);

                if (dump) {
                    char source[INET6_ADDRSTRLEN + 1];
                    inet_ntop(version == 4 ? AF_INET : AF_INET6,
                              version == 4 ? addr4 : addr6,
                              source, sizeof(source));
                    log_android(ANDROID_LOG_INFO, "%s/%u %d %s", source, port, u, line);
                }

                if (port == sport) {
                    uid = u;
                    if (memcmp(version == 4 ? addr4 : addr6, saddr, version == 4 ? 4 : 16) == 0)
                        break;
                }
            } else
                log_android(ANDROID_LOG_ERROR, "Invalid field #%d: %s", fields, line);
        }
    }

    if (fclose(fd))
        log_android(ANDROID_LOG_ERROR, "fclose %s error %d: %s", fn, errno, strerror(errno));

#ifdef PROFILE_UID
    gettimeofday(&end, NULL);
    mselapsed = (end.tv_sec - start.tv_sec) * 1000.0 +
                (end.tv_usec - start.tv_usec) / 1000.0;
    if (mselapsed > PROFILE_UID)
        log_android(ANDROID_LOG_WARN, "get uid ip %f", mselapsed);
#endif

    return uid;
}
Ejemplo n.º 5
0
int main()
{
    char* KT="feffe9928665731c6d6a8f9467308308";
    char* MT="d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39";
    char* HT="feedfacedeadbeeffeedfacedeadbeefabaddad2";
    char* NT="9313225df88406e555909c5aff5269aa6a7a9538534f7da1e4c303d2a318a728c3c0c95156809539fcf0e2429a6b525416aedbf5a0de6a57a637b39b";
    // Tag should be 619cc5aefffe0bfa462af43c1699d050

    int lenM=strlen(MT)/2;
    int lenH=strlen(HT)/2;
    int lenK=strlen(KT)/2;
    int lenIV=strlen(NT)/2;

    char t1[16];  // Tag
    char t2[16];  // Tag
    char k[16];   // AES Key
    char h[64];   // Header - to be included in Authentication, but not encrypted
    char iv[100]; // IV - Initialisation vector
    char m[100];  // Plaintext to be encrypted/authenticated
    char c[100];  // Ciphertext
    char p[100];  // Recovered Plaintext
    octet T1= {sizeof(t1),sizeof(t1),t1};
    octet T2= {sizeof(t2),sizeof(t2),t2};
    octet K= {0,sizeof(k),k};
    octet H= {0,sizeof(h),h};
    octet IV= {0,sizeof(iv),iv};
    octet M= {0,sizeof(m),m};
    octet C= {0,sizeof(c),c};
    octet P= {0,sizeof(p),p};
    M.len=lenM;
    K.len=lenK;
    H.len=lenH;
    IV.len=lenIV;

    hex2bytes(MT, m);
    hex2bytes(HT, h);
    hex2bytes(NT, iv);
    hex2bytes(KT, k);

    printf("Plaintext: ");
    OCT_output(&M);
    printf("\n");

    AES_GCM_ENCRYPT(&K, &IV, &H, &M, &C, &T1);

    printf("Ciphertext: ");
    OCT_output(&C);
    printf("\n");

    printf("Encryption Tag: ");
    OCT_output(&T1);
    printf("\n");

    AES_GCM_DECRYPT(&K, &IV, &H, &C, &P, &T2);

    printf("Plaintext: ");
    OCT_output(&P);
    printf("\n");

    printf("Decryption Tag: ");
    OCT_output(&T2);
    printf("\n");

    if (!OCT_comp(&M,&P))
    {
        printf("FAILURE Decryption\n");
        return 1;
    }

    if (!OCT_comp(&T1,&T2))
    {
        printf("FAILURE TAG mismatch\n");
        return 1;
    }

    printf("SUCCESS\n");
    return 0;
}