static void get_args(int argc, char *argv[])
{
	u32 i;

	if (argc != 9 && argc != 10)
		fail("usage: makeself [-c] [type] [version suffix] [version] [vendor id] [auth id] [sdk type] [elf] [self]");

	i = 1;

	if (argc == 10) {
		if (strcmp(argv[1], "-c") != 0)
			fail("invalid option: %s", argv[1]);
		compression = 1;
		i++;
	}

	get_type(argv[i++]);
	get_keys(argv[i++]);
	get_version(argv[i++]);
	get_vendor(argv[i++]);
	get_auth(argv[i++]);
	get_sdktype(argv[i++]);

	elf_name = argv[i++];
	self_name = argv[i++];

	if (compression) {
		if (type == KEY_ISO)
			fail("no compression support for isolated modules");
		if (type == KEY_LDR)
			fail("no compression support for secure loaders");
	}
}
Exemple #2
0
result_t Url::get_href(exlib::string& retVal)
{
    retVal.clear();

    if (m_protocol.length() > 0)
        retVal.append(m_protocol);

    if (m_slashes)
        retVal.append("//", 2);

    exlib::string str;

    if (m_username.length() > 0) {
        get_auth(str);
        retVal.append(str);
        retVal.append(1, '@');
    }

    get_host(str);
    retVal.append(str);

    get_path(str);
    retVal.append(str);

    retVal.append(m_hash);

    return 0;
}
Exemple #3
0
void pocket_get(const char *key, const char *token) 
{
    struct buffer s;

    buffer_init(&s);
    request(URL_GET, get_auth(key, token), &s, 0);
    buffer_cleanup(&s);
}
Exemple #4
0
static void handshake()
{
    const char* session_key = scrobsub_session_key();
    const char* username = scrobsub_username();
    
    if (!session_key || !username)
        return; //TODO auth required
    
    time_t time = now();
    char auth[33];
    get_auth(auth, time);
    int n = 34+8+8+6+11+3+strlen(username)+13+32+9+32+4+32+1;
    char url[n];
    
    n = snprintf(url, n, "http://post.audioscrobbler.com:80/"
                 "?hs=true"
                 "&p=1.2.1"
                 "&c=" SCROBSUB_CLIENT_ID      // length 3
                 "&v=" SCROBSUB_CLIENT_VERSION // length 8 max
                 "&u=%s"
                 "&t=%d" // length 10 for the next millenia at least :P
                 "&a=%s" // length 32
                 "&api_key=" SCROBSUB_API_KEY // length 32
                 "&sk=%s", // length 32
                 username, time, auth, session_key);
    if (n<0) return; //TODO error callback

    char responses[256];
    char* response = responses;
    scrobsub_get(responses, url);

    if(ok(response)){
        response += 3;
        session_id = handshake_response_strdup(&response);
        np_url = handshake_response_strdup(&response);
        submit_url = handshake_response_strdup(&response);
    }else
        //TODO better
        (scrobsub_callback)(SCROBSUB_ERROR_RESPONSE, response);
}
static gboolean
http_poll (gpointer data)
{
    PnNode *conn;
    PnHttpServer *http_conn;
    GIOStatus status = G_IO_STATUS_NORMAL;
    GError *tmp_error = NULL;
    gsize bytes_written = 0;
    static guint count = 0;

    gchar *header;
    gchar *params;
    gchar *auth = NULL;

    g_return_val_if_fail (data != NULL, FALSE);

    conn = PN_NODE (data);
    http_conn = PN_HTTP_SERVER (data);

    pn_debug ("stream=%p", conn->stream);

    if (!http_conn->cur)
        return TRUE;

    g_return_val_if_fail (http_conn->cur, FALSE);

    count++;

    /* Don't poll if we already sent something, unless we have been waiting for
     * too long; a disconnection might have happened. */
    if (http_conn->waiting_response && count < 10)
    {
        /* There's no need to poll if we're already waiting for a response */
        pn_debug ("waiting for response");
        return TRUE;
    }

#ifdef HAVE_LIBPURPLE
    auth = get_auth(conn);
#endif /* HAVE_LIBPURPLE */

    params = g_strdup_printf ("Action=poll&SessionID=%s",
                              (gchar *) http_conn->cur->foo_data);

    header = g_strdup_printf ("POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n"
                              "Accept: */*\r\n"
                              "User-Agent: MSMSGS\r\n"
                              "Host: %s\r\n"
                              "%s" /* Proxy auth */
                              "Proxy-Connection: Keep-Alive\r\n"
                              "Connection: Keep-Alive\r\n"
                              "Pragma: no-cache\r\n"
                              "Cache-Control: no-cache\r\n"
                              "Content-Type: application/x-msn-messenger\r\n"
                              "Content-Length: 0\r\n\r\n",
                              http_conn->gateway,
                              params,
                              http_conn->gateway,
                              auth ? auth : "");

#ifdef PECAN_DEBUG_HTTP
    pn_debug ("header=[%s]", header);
#endif

    g_free (params);

    status = pn_stream_write_full (conn->stream, header, strlen (header), &bytes_written, &tmp_error);

    g_free (header);

    http_conn->waiting_response = TRUE;
    pn_timer_stop (http_conn->timer);

    if (status == G_IO_STATUS_NORMAL)
    {
        status = pn_stream_flush (conn->stream, &tmp_error);

        if (status == G_IO_STATUS_AGAIN) {
            http_conn->last_flush = status;
            http_conn->write_watch = g_io_add_watch(conn->stream->channel,
                                                    G_IO_OUT, write_cb, http_conn);
            /* fake status */
            status = G_IO_STATUS_NORMAL;
        }

        if (status == G_IO_STATUS_NORMAL)
            pn_log ("bytes_written=%zu", bytes_written);
    }

    if (status != G_IO_STATUS_NORMAL)
    {
        PnNodeClass *class;
        pn_error ("not normal: status=%d", status);
        class = g_type_class_peek (PN_NODE_TYPE);
        g_signal_emit (G_OBJECT (conn), class->error_sig, 0, conn);
        return FALSE;
    }
Exemple #6
0
std::string api::orders()
{
	return https_post("open_orders/", get_auth());
}
Exemple #7
0
std::string api::unconfirmed_btc()
{
	return https_post("unconfirmed_btc/", get_auth());
}
Exemple #8
0
std::string api::withdrawal_requests()
{
	return https_post("withdrawal_requests/", get_auth());
}
Exemple #9
0
std::string api::cancel(const std::string& order)
{
	std::stringstream post;
	post << get_auth() << "&id=" << order;
	return https_post("cancel_order/", post.str());
}
Exemple #10
0
std::string api::balance()
{
	return https_post("balance/", get_auth());
}
Exemple #11
0
std::string api::bitcoin_withdrawal(const std::string& amount, const std::string& address)
{
	std::stringstream post;
	post << get_auth() << "&amount=" << amount << "&address=" << address;
	return https_post("bitcoin_withdrawal/", post.str());
}
Exemple #12
0
std::string api::buy(const std::string& amount, const std::string& price)
{
	std::stringstream post;
	post << get_auth() << "&amount=" << amount << "&price=" << price;
	return https_post("buy/", post.str());
}
Exemple #13
0
std::string api::transactions(const std::string& offset, const std::string& limit, const std::string& sort)
{
	std::stringstream post;
	post << get_auth() << "&offset=" << offset << "&limit=" << limit << "&sort=" << sort;
	return https_post("user_transactions/", post.str());
}
Exemple #14
0
int main(int argc, char *argv[])
{
	FILE *fp;
	u8 bfr[ALIGNMENT];

	if (argc != 9)
		fail("usage: makeself [type] [version suffix] [version] [vendor id] [auth id] [sdk type] [elf] [self]");

	get_type(argv[1]);
	get_keys(argv[2]);
	get_version(argv[3]);
	get_vendor(argv[4]);
	get_auth(argv[5]);
	get_sdktype(argv[6]);

	elf_size = get_filesize(argv[7]);
	elf = mmap_file(argv[7]);

	parse_elf();

	meta_header_size = 0x80 + ehdr.e_phnum * (0x30 + 0x20 + 0x60) + 0x30;
	info_offset = 0x70;
	elf_offset = 0x90;
	phdr_offset = elf_offset + ehdr.e_ehsize;
	sec_offset = round_up(phdr_offset + ehdr.e_phentsize * ehdr.e_phnum, ALIGNMENT);
	version_offset = round_up(sec_offset + ehdr.e_phnum *  0x20, ALIGNMENT);
	ctrl_offset = round_up(version_offset + 0x10, ALIGNMENT);
	meta_offset = round_up(ctrl_offset + 0x70, ALIGNMENT);
	header_size = round_up(meta_offset + meta_header_size, 0x80);
	shdr_offset = ehdr.e_shoff + header_size;

	build_sce_hdr();
	build_info_hdr();
	build_ctrl_hdr();
	build_sec_hdr();
	build_version_hdr();
	build_meta_hdr();

	self = malloc(header_size + elf_size);
	memset(self, 0, header_size + elf_size);

	build_hdr();
	calculate_hashes();
	sign_hdr();

	sce_encrypt_data(self);
	sce_encrypt_header(self, &ks);

	fp = fopen(argv[8], "wb");
	if (fp == NULL)
		fail("fopen(%s) failed", argv[4]);

	if (fwrite(self, header_size + elf_size, 1, fp) != 1)
		fail("unable to write self");

	memset(bfr, 0, sizeof bfr);
	fwrite(bfr, round_up(elf_size, ALIGNMENT) - elf_size, 1, fp);

	fclose(fp);

	return 0;
}
Exemple #15
0
std::string api::bitcoin_deposit_address()
{
	return https_post("bitcoin_deposit_address/", get_auth());
}
Exemple #16
0
int
do_shishi_login (int infd, struct auth_data *ad, const char **err_msg)
{
  int rc;
  int error = 0;
  int keylen, keytype;
  struct passwd *pwd = NULL;
  int cksumtype, cksumlen = 30;
  char *cksum;
  char *compcksum;
  size_t compcksumlen;
  char cksumdata[100];
  struct sockaddr_in sock;
  size_t socklen = sizeof (struct sockaddr_in);

#  ifdef ENCRYPTION
  rc = get_auth (infd, &ad->h, &ad->ap, &ad->enckey, err_msg, &ad->protocol,
		 &cksumtype, &cksum, &cksumlen);
#  else
  rc = get_auth (infd, &ad->h, &ad->ap, NULL, err_msg, &ad->protocol,
		 &cksumtype, &cksum, &cksumlen);
#  endif
  if (rc != SHISHI_OK)
    return rc;

#  ifdef ENCRYPTION
  /* init IV */
  if (encrypt_io)
    {
      int i;
      char *iv;

      ad->ivtab[0] = &ad->iv1;
      ad->ivtab[1] = &ad->iv2;

      keytype = shishi_key_type (ad->enckey);
      keylen = shishi_cipher_blocksize (keytype);

      for (i = 0; i < 2; i++)
	{
	  ad->ivtab[i]->ivlen = keylen;

	  switch (keytype)
	    {
	    case SHISHI_DES_CBC_CRC:
	    case SHISHI_DES_CBC_MD4:
	    case SHISHI_DES_CBC_MD5:
	    case SHISHI_DES_CBC_NONE:
	    case SHISHI_DES3_CBC_HMAC_SHA1_KD:
	      ad->ivtab[i]->keyusage = SHISHI_KEYUSAGE_KCMD_DES;
	      ad->ivtab[i]->iv = malloc (ad->ivtab[i]->ivlen);
	      memset (ad->ivtab[i]->iv, i, ad->ivtab[i]->ivlen);
	      ad->ivtab[i]->ctx =
		shishi_crypto (ad->h, ad->enckey, ad->ivtab[i]->keyusage,
			       shishi_key_type (ad->enckey), ad->ivtab[i]->iv,
			       ad->ivtab[i]->ivlen);
	      break;
	    case SHISHI_ARCFOUR_HMAC:
	    case SHISHI_ARCFOUR_HMAC_EXP:
	      ad->ivtab[i]->keyusage = SHISHI_KEYUSAGE_KCMD_DES + 6 - 4 * i;
	      ad->ivtab[i]->ctx =
		shishi_crypto (ad->h, ad->enckey, ad->ivtab[i]->keyusage,
			       shishi_key_type (ad->enckey), NULL, 0);
	      break;
	    default:
	      ad->ivtab[i]->keyusage = SHISHI_KEYUSAGE_KCMD_DES + 6 - 4 * i;
	      ad->ivtab[i]->iv = malloc (ad->ivtab[i]->ivlen);
	      memset (ad->ivtab[i]->iv, 0, ad->ivtab[i]->ivlen);
	      if (ad->protocol == 2)
		ad->ivtab[i]->ctx =
		  shishi_crypto (ad->h, ad->enckey, ad->ivtab[i]->keyusage,
				 shishi_key_type (ad->enckey),
				 ad->ivtab[i]->iv, ad->ivtab[i]->ivlen);
	    }
	}
    }
#  endif

  getstr (infd, &ad->lusername, NULL);
  getstr (infd, &ad->term, "TERM=");
  getstr (infd, &ad->rusername, NULL);

  rc = read (infd, &error, sizeof (int));
  if ((rc != sizeof (int)) && rc)
    {
      free (pwd);
      free (cksum);
      return 1;
    }

  /*
     getpwnam crash !!!!

     pwd = getpwnam (ad->lusername);
     if (pwd == NULL)
     {
     *err_msg = "getpwnam failed";
     syslog (LOG_ERR, "getpwnam failed: %m");
     return 1;
     }

     syslog (LOG_INFO | LOG_AUTH,
     "%sKerberos V login from %s on %s\n",
     (pwd->pw_uid == 0) ? "ROOT " : "",
     ad->lusername, ad->hostname);

   */

  free (pwd);

  syslog (LOG_INFO | LOG_AUTH,
	  "Kerberos V login from %s on %s\n", ad->lusername, ad->hostname);

  /* verify checksum */

  if (getsockname (infd, (struct sockaddr *) &sock, &socklen) < 0)
    {
      syslog (LOG_ERR, "Can't get sock name");
      fatal (infd, "Can't get sockname", 1);
    }

  snprintf (cksumdata, 100, "%u:%s%s", ntohs (sock.sin_port), ad->term + 5,
	    ad->lusername);
  rc = shishi_checksum (ad->h, ad->enckey, 0, cksumtype, cksumdata,
			strlen (cksumdata), &compcksum, &compcksumlen);
  free (cksum);
  if (rc != SHISHI_OK
      || compcksumlen != cksumlen || memcmp (compcksum, cksum, cksumlen) != 0)
    {
      /* err_msg crash ? */
      /* *err_msg = "checksum verify failed"; */
      syslog (LOG_ERR, "checksum verify failed: %s", shishi_error (ad->h));
      free (compcksum);
      return 1;
    }

  free (compcksum);

  rc = shishi_authorized_p (ad->h, shishi_ap_tkt (ad->ap), ad->lusername);
  if (!rc)
    {
      syslog (LOG_ERR, "User is not authorized to log in as: %s",
	      ad->lusername);
      shishi_ap_done (ad->ap);
      return 1;
    }

  shishi_ap_done (ad->ap);

  return SHISHI_OK;
}
Exemple #17
0
static int dummy_portmap(int sock, FILE *portmap_file)
{
	struct sockaddr_in sin;
	int pktlen, addrlen;
	unsigned char pkt[65536];	/* Max UDP packet size */
	/* RPC UDP packets do not include TCP fragment size */
	struct rpc_call *rpc = (struct rpc_call *) &pkt[-4];
	struct rpc_auth *cred;
	struct rpc_auth *vrf;
	struct portmap_args *args;
	struct portmap_reply rply;

	for (;;) {
		addrlen = sizeof sin;
		pktlen = recvfrom(sock, &pkt, sizeof pkt, 0,
				  (struct sockaddr *)&sin, &addrlen);

		if (pktlen < 0) {
			if (errno == EINTR)
				continue;

			return -1;
		}

		/* +4 to skip the TCP fragment header */
		if (pktlen + 4 < sizeof(struct portmap_call))
			continue;	/* Bad packet */

		if (rpc->hdr.udp.msg_type != htonl(RPC_CALL))
			continue;	/* Bad packet */

		memset(&rply, 0, sizeof rply);

		rply.rpc.hdr.udp.xid = rpc->hdr.udp.xid;
		rply.rpc.hdr.udp.msg_type = htonl(RPC_REPLY);

		cred = (struct rpc_auth *) &rpc->cred_flavor;
		if (rpc->rpc_vers != htonl(2)) {
			rply.rpc.reply_state = htonl(REPLY_DENIED);
			/* state <- RPC_MISMATCH == 0 */
		} else if (rpc->program != htonl(PORTMAP_PROGRAM)) {
			rply.rpc.reply_state = htonl(PROG_UNAVAIL);
		} else if (rpc->prog_vers != htonl(2)) {
			rply.rpc.reply_state = htonl(PROG_MISMATCH);
		} else if (!(vrf = get_auth(cred)) ||
			   (char *)vrf > (char *)pkt + pktlen - 8 - sizeof(*args) ||
			   !(args = get_auth(vrf)) ||
			   (char *)args > (char *)pkt + pktlen - sizeof(*args) ||
			   check_cred(cred) || check_vrf(vrf)) {
			/* Can't deal with credentials data; the kernel
			   won't send them */
			rply.rpc.reply_state = htonl(SYSTEM_ERR);
		} else {
			switch (ntohl(rpc->proc)) {
			case PMAP_PROC_NULL:
				break;
			case PMAP_PROC_SET:
				if (args->proto == htonl(IPPROTO_TCP) ||
				    args->proto == htonl(IPPROTO_UDP)) {
					if (portmap_file)
						fprintf(portmap_file,
							"%u %u %s %u\n",
							ntohl(args->program),
							ntohl(args->version),
							protoname(args->proto),
							ntohl(args->port));
					rply.port = htonl(1);	/* TRUE = success */
				}
				break;
			case PMAP_PROC_UNSET:
				rply.port = htonl(1);	/* TRUE = success */
				break;
			case PMAP_PROC_GETPORT:
				break;
			case PMAP_PROC_DUMP:
				break;
			default:
				rply.rpc.reply_state = htonl(PROC_UNAVAIL);
				break;
			}
		}

		sendto(sock, &rply.rpc.hdr.udp, sizeof rply - 4, 0,
		       (struct sockaddr *)&sin, addrlen);
	}
}