예제 #1
0
파일: tls.c 프로젝트: lavabit/magma
/**
 * @brief	Consolidate the complicated logic associated with handling SSL_read/SSL_write calls which result in 0, or a negative number.
 */
stringer_t * tls_error(TLS *tls, int_t code, stringer_t *output) {

	int tlserr = 0, syserr = 0;
	chr_t *message = MEMORYBUF(1024);
	stringer_t *result = NULL;

	// Check the SSL_get_error() function. If any of the codes listed here (0, 2 or 3) are returned, then the SSL input/output is
	// still valid, and may be used for future read and write operations.
	if ((tlserr = SSL_get_error_d(tls, code)) == SSL_ERROR_NONE || tlserr == SSL_ERROR_WANT_READ || tlserr == SSL_ERROR_WANT_WRITE) {
		return NULL;
	}

	// If we make it past here, then there should be an error message in the buffer by the time we exit this function.
	else if (!(result = st_output(output, 128))) {
		log_pedantic("Unable to record the TLS error because the output buffer is invalid.");
		return NULL;
	}

	// We need to record the errno locally to prevent any future function call from clobbering the relevant value.
	syserr = errno;

	// Note that if errno is non-zero, then the SSL error was probably just an indication we had a system level event, like a peer disconnect.
	if (syserr != 0) {
		st_sprint(result, "error = %i / errno = %i / message = %s", tlserr, syserr, strerror_r(syserr, message, 1024));
	}
	// If the operation returned a negative value, but errno indicate no particular problem, then we record that scenario here.
	else if (code < 0 && syserr == 0) {
		st_sprint(result, "error = %i / errno = 0", tlserr);
	}

	// SSL error code number 1, an SSL library error occurred, usually because of a protocol problem, and thus the OpenSSL
	// error queue should hold more information about the fault.
	else if (tlserr == SSL_ERROR_SSL) {
		ERR_error_string_n_d(ERR_get_error_d(), message, 1024);
		st_sprint(result, "error = %i / errno = 0 / message = %s", tlserr, message);
	}

	// SSL error code number 5, a non-recoverable I/O error occurred. Usually errno will provide a clue, but not always.
	else if (tlserr == SSL_ERROR_SYSCALL) {
		ERR_error_string_n_d(ERR_get_error_d(), message, 1024);
		st_sprint(result, "error = %i / errno = 0 / message = %s", tlserr, message);
	}

	// SSL error code number 6, which seems to indicate the remote host shut down the connection.
	else if (tlserr == SSL_ERROR_ZERO_RETURN) {
		st_sprint(result, "error = %i / message = Connection shut down.", tlserr);
	}

	// We end up here if the result was zero, and errno was zero, and we didn't recognize the SSL error code directly.
	else {
		st_sprint(result, "error = %i / errno = 0", tlserr);
	}

	return result;
}
예제 #2
0
파일: tls.c 프로젝트: lavabit/magma
/**
 * @brief	Return the name of the TLS cipher suite assoicated with a connection.
 * @see		SSL_CIPHER_get_name()
 * @param 	tls the TLS connection being inspected.
 * @param	output	a managed string to receive the encoded output; if passed as NULL, an output buffer will be allocated
 *				which must be freed by the caller.
 * @return	a pointer to the result, or NULL if an error occurs.
 */
 stringer_t * tls_cipher(TLS *tls, stringer_t *output) {

	 SSL_CIPHER *cipher = NULL;
	 stringer_t *result = NULL;
	 chr_t *version = NULL, *name = NULL;

	 if (!(cipher = SSL_get_current_cipher_d(tls))) {
		 return NULL;
	 }
	 else if (!(version = (chr_t *)SSL_get_version_d(tls))) {
		 return NULL;
	 }
	 else if (!(name = (chr_t *)SSL_CIPHER_get_name_d(cipher))) {
		 return NULL;
	 }
	 else if (!(result = st_output(output, 128))) {
		 return NULL;
	 }

	 st_sprint(result, "version = %s / suite = %s", (st_cmp_cs_eq(NULLER(version), PLACER("TLSv1", 5)) ? version : "TLSv1.0"), name);

	 return result;
 }
static bool split_file(wave_info *info)
{
  unsigned char header[CANONICAL_HEADER_SIZE];
  char outfilename[FILENAME_SIZE],filenum[FILENAME_SIZE];
  int current;
  wint discard,bytes;
  bool success;
  wlong leadin_bytes, leadout_bytes, bytes_to_xfer;
  progress_info proginfo;
 
  // uwe
  double start_time, end_time, last_end_time;	
  
	
  success = FALSE;

  proginfo.initialized = FALSE;
  proginfo.prefix = "Splitting";
  proginfo.clause = "-->";
  proginfo.filename1 = info->filename;
  proginfo.filedesc1 = info->m_ss;
  proginfo.filename2 = NULL;
  proginfo.filedesc2 = NULL;
  proginfo.bytes_total = 0;

  if (!open_input_stream(info)) {
    prog_error(&proginfo);
    st_error("could not reopen input file: [%s]",info->filename);
  }

  discard = info->header_size;
  while (discard > 0) {
    bytes = min(discard,CANONICAL_HEADER_SIZE);
    if (read_n_bytes(info->input,header,bytes,NULL) != bytes) {
      prog_error(&proginfo);
      st_error("error while discarding %d-byte WAVE header",info->header_size);
    }
    discard -= bytes;
  }

  leadin_bytes = (leadin) ? smrt_parse((unsigned char *)leadin,info) : 0;
  leadout_bytes = (leadout) ? smrt_parse((unsigned char *)leadout,info) : 0;
  adjust_for_leadinout(leadin_bytes,leadout_bytes);

  // uwe transcription
  st_output("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
  st_output("<Trans version=\"2\">\n\n");
  start_time = end_time = last_end_time = 0;
	
  for (current=0;current<numfiles;current++) {
    if (SPLIT_INPUT_CUE == input_type && cueinfo.format) {
      create_output_filename(cueinfo.filenames[current],"",outfilename);
    }
    else {
      st_snprintf(filenum,8,num_format,current+offset);
      create_output_filename(filenum,"",outfilename);
    }

    files[current]->chunk_size = files[current]->data_size + CANONICAL_HEADER_SIZE - 8;
    files[current]->channels = info->channels;
    files[current]->samples_per_sec = info->samples_per_sec;
    files[current]->avg_bytes_per_sec = info->avg_bytes_per_sec;
    files[current]->block_align = info->block_align;
    files[current]->bits_per_sample = info->bits_per_sample;
    files[current]->wave_format = info->wave_format;
    files[current]->rate = info->rate;
    files[current]->length = files[current]->data_size / (wlong)info->rate;
    files[current]->exact_length = (double)files[current]->data_size / (double)info->rate;
    files[current]->total_size = files[current]->chunk_size + 8;

    length_to_str(files[current]);

    proginfo.filedesc2 = files[current]->m_ss;
    proginfo.bytes_total = files[current]->total_size;

    if (extract_track[current]) {
      proginfo.prefix = "Splitting";
      proginfo.filename2 = outfilename;

	  // uwe transcription
	  start_time += last_end_time;
	  end_time += files[current]->data_size / (wlong)info->rate;
	  last_end_time = end_time;
		
	  printf("<Turn startTime=\"%.2f\"", start_time); // %.2f
	  st_output(" endTime=\"%.2f\"", end_time);
	  st_output(" splitFilename=\"%s\"", outfilename);
	  st_output(" speaker=\"spk1\">\n");
	  st_output("<Sync time=\"%.2f\"/>\n", start_time);
	  st_output("***Include transcript words here***\n");
	  st_output("</Turn>\n");
		
      if (NULL == (files[current]->output = open_output_stream(outfilename,&files[current]->output_proc))) {
        prog_error(&proginfo);
        st_error("could not open output file");
      }
    }
    else {
      proginfo.prefix = "Skipping ";
      proginfo.filename2 = NULLDEVICE;

      if (NULL == (files[current]->output = open_output(NULLDEVICE))) {
        prog_error(&proginfo);
        st_error("while skipping track %d: could not open output file: [%s]",current+1,NULLDEVICE);
      }

      files[current]->output_proc.pid = NO_CHILD_PID;
    }

    if (PROB_ODD_SIZED_DATA(files[current]))
      files[current]->chunk_size++;

    make_canonical_header(header,files[current]);

	// uwe disable
    //prog_update(&proginfo);

    if (write_n_bytes(files[current]->output,header,CANONICAL_HEADER_SIZE,&proginfo) != CANONICAL_HEADER_SIZE) {
      prog_error(&proginfo);
      st_warning("error while writing %d-byte WAVE header",CANONICAL_HEADER_SIZE);
      goto cleanup;
    }

    /* if this is not the first file, finish up writing previous file, and simultaneously start writing to current file */
    if (0 != current) {
      /* write overlapping lead-in/lead-out data to both previous and current files */
      if (transfer_n_bytes2(info->input,files[current]->output,files[current-1]->output,leadin_bytes+leadout_bytes,&proginfo) != leadin_bytes+leadout_bytes) {
        prog_error(&proginfo);
        st_warning("error while transferring %ld bytes of lead-in/lead-out",leadin_bytes+leadout_bytes);
        goto cleanup;
      }

      /* pad and close previous file */
      if (PROB_ODD_SIZED_DATA(files[current-1]) && (1 != write_padding(files[current-1]->output,1,&proginfo))) {
        prog_error(&proginfo);
        st_warning("error while NULL-padding odd-sized data chunk");
        goto cleanup;
      }

      close_output(files[current-1]->output,files[current-1]->output_proc);
    }

    /* transfer unique non-overlapping data from input file to current file */
    bytes_to_xfer = files[current]->new_data_size;
    if (0 != current)
      bytes_to_xfer -= leadout_bytes;
    if (numfiles - 1 != current)
      bytes_to_xfer -= leadin_bytes;

    if (transfer_n_bytes(info->input,files[current]->output,bytes_to_xfer,&proginfo) != bytes_to_xfer) {
      prog_error(&proginfo);
      st_warning("error while transferring %ld bytes of data",bytes_to_xfer);
      goto cleanup;
    }

    /* if this is the last file, close it */
    if (numfiles - 1 == current) {
      /* pad and close current file */
      if (PROB_ODD_SIZED_DATA(files[current]) && (1 != write_padding(files[current]->output,1,&proginfo))) {
        prog_error(&proginfo);
        st_warning("error while NULL-padding odd-sized data chunk");
        goto cleanup;
      }

      close_output(files[current]->output,files[current]->output_proc);

      // uwe transcription  
      st_output("</Trans>\n");

    }

	// uwe disable 
    // prog_success(&proginfo);
 
  }

  close_input_stream(info);

  success = TRUE;

cleanup:
  if (!success) {
    close_output(files[current]->output,files[current]->output_proc);
    remove_file(outfilename);
    st_error("failed to split file");
  }

  return success;
}