int Stream::put( char const *s, int l) { NETWORK_TRACE("put string \"" << s << "\" and int " << l); switch(_code){ case internal: case external: if (!s){ if (get_encryption()) { int len = 1; if (put(len) == FALSE) { return FALSE; } } if (put_bytes(BIN_NULL_CHAR, 1) != 1) return FALSE; } else{ if (get_encryption()) { if (put(l) == FALSE) { return FALSE; } } if (put_bytes(s, l) != l) return FALSE; } break; case ascii: return FALSE; } return TRUE; }
int ReliSock::get_bytes(void *dta, int max_sz) { int bytes, length; unsigned char * data = 0; ignore_next_decode_eom = FALSE; while (!rcv_msg.ready) { if (!handle_incoming_packet()){ return FALSE; } } bytes = rcv_msg.buf.get(dta, max_sz); if (bytes > 0) { if (get_encryption()) { unwrap((unsigned char *) dta, bytes, data, length); memcpy(dta, data, bytes); free(data); } _bytes_recvd += bytes; } return bytes; }
int mailprivacy_encrypt_msg(struct mailprivacy * privacy, char * privacy_driver, char * privacy_encryption, mailmessage * msg, struct mailmime * mime, struct mailmime ** result) { struct mailprivacy_protocol * protocol; struct mailprivacy_encryption * encryption; int r; protocol = get_protocol(privacy, privacy_driver); if (protocol == NULL) return MAIL_ERROR_INVAL; encryption = get_encryption(protocol, privacy_encryption); if (encryption == NULL) return MAIL_ERROR_INVAL; if (encryption->encrypt == NULL) return MAIL_ERROR_NOT_IMPLEMENTED; r = encryption->encrypt(privacy, msg, mime, result); if (r != MAIL_NO_ERROR) return r; return MAIL_NO_ERROR; }
int Stream::get_string_ptr( char const *&s ) { char c; void *tmp_ptr = 0; int len; s = NULL; switch(_code){ case internal: case external: // For 6.2 compatibility, we had to put this code back if (!get_encryption()) { if (!peek(c)) return FALSE; if (c == '\255'){ if (get_bytes(&c, 1) != 1) return FALSE; s = NULL; } else{ if (get_ptr(tmp_ptr, '\0') <= 0) return FALSE; s = (char *)tmp_ptr; } } else { // 6.3 with encryption support // First, get length if (get(len) == FALSE) { return FALSE; } if( !decrypt_buf || decrypt_buf_len < len ) { free( decrypt_buf ); decrypt_buf = (char *)malloc(len); ASSERT( decrypt_buf ); decrypt_buf_len = len; } if( get_bytes(decrypt_buf, len) != len ) { return FALSE; } if( *decrypt_buf == '\255' ) { s = NULL; } else { s = decrypt_buf; } } break; case ascii: return FALSE; } if( s ) { NETWORK_TRACE("get string ptr " << s); } else { NETWORK_TRACE("get string ptr NULL"); } return TRUE; }
void Stream::prepare_crypto_for_secret() { m_crypto_state_before_secret = true; if( !prepare_crypto_for_secret_is_noop() ) { dprintf(D_NETWORK,"encrypting secret\n"); m_crypto_state_before_secret = get_encryption(); // always false set_crypto_mode(true); } }
int ReliSock::get_bytes_nobuffer(char *buffer, int max_length, int receive_size) { int result; int length; unsigned char * buf = NULL; ASSERT(buffer != NULL); ASSERT(max_length > 0); // Find out how big the file is going to be, if requested. // No receive_size means read max_length bytes. this->decode(); if ( receive_size ) { ASSERT( this->code(length) != FALSE ); ASSERT( this->end_of_message() != FALSE ); } else { length = max_length; } // First drain incoming buffers if ( !prepare_for_nobuffering(stream_decode) ) { // error draining buffers; error message already printed goto error; } if( length > max_length ) { dprintf(D_ALWAYS, "ReliSock::get_bytes_nobuffer: data too large for buffer.\n"); goto error; } result = condor_read(peer_description(), _sock, buffer, length, _timeout); if( result < 0 ) { dprintf(D_ALWAYS, "ReliSock::get_bytes_nobuffer: Failed to receive file.\n"); goto error; } else { // See if it needs to be decrypted if (get_encryption()) { unwrap((unsigned char *) buffer, result, buf, length); // I am reusing length memcpy(buffer, buf, result); free(buf); } _bytes_recvd += result; return result; } error: return -1; }
bool Stream::prepare_crypto_for_secret_is_noop() { CondorVersionInfo const *peer_ver = get_peer_version(); if( !peer_ver || peer_ver->built_since_version(7,1,3) ) { if( !get_encryption() ) { if( canEncrypt() ) { // do turn on encryption before sending secret return false; } } } return true; }
int Stream::put( char const *s) { int len; NETWORK_TRACE("put string " << s); switch(_code){ case internal: case external: if (!s){ if (get_encryption()) { len = 1; if (put(len) == FALSE) { return FALSE; } } if (put_bytes(BIN_NULL_CHAR, 1) != 1) return FALSE; } else{ len = strlen(s)+1; if (get_encryption()) { if (put(len) == FALSE) { return FALSE; } } if (put_bytes(s, len) != len) return FALSE; } break; case ascii: return FALSE; } return TRUE; }
char * mailprivacy_get_encryption_name(struct mailprivacy * privacy, char * privacy_driver, char * privacy_encryption) { struct mailprivacy_protocol * protocol; struct mailprivacy_encryption * encryption; protocol = get_protocol(privacy, privacy_driver); if (protocol == NULL) return NULL; encryption = get_encryption(protocol, privacy_encryption); if (encryption == NULL) return NULL; return encryption->description; }
int ReliSock::put_bytes(const void *data, int sz) { int tw=0, header_size = isOutgoing_MD5_on() ? MAX_HEADER_SIZE:NORMAL_HEADER_SIZE; int nw, l_out; unsigned char * dta = NULL; // Check to see if we need to encrypt // Okay, this is a bug! H.W. 9/25/2001 if (get_encryption()) { if (!wrap((unsigned char *)data, sz, dta , l_out)) { dprintf(D_SECURITY, "Encryption failed\n"); if (dta != NULL) { free(dta); dta = NULL; } return -1; // encryption failed! } } else { if((dta = (unsigned char *) malloc(sz)) != 0) memcpy(dta, data, sz); } ignore_next_encode_eom = FALSE; for(nw=0;;) { if (snd_msg.buf.full()) { if (!snd_msg.snd_packet(peer_description(), _sock, FALSE, _timeout)) { if (dta != NULL) { free(dta); dta = NULL; } return FALSE; } } if (snd_msg.buf.empty()) { snd_msg.buf.seek(header_size); } if (dta && (tw = snd_msg.buf.put_max(&((char *)dta)[nw], sz-nw)) < 0) { free(dta); dta = NULL; return -1; } nw += tw; if (nw >= sz) { break; } } if (nw > 0) { _bytes_sent += nw; } if (dta != NULL) { free(dta); dta = NULL; } return nw; }
int ReliSock::put_bytes_nobuffer( char *buffer, int length, int send_size ) { int i, result, l_out; int pagesize = 65536; // Optimize large writes to be page sized. unsigned char * cur; unsigned char * buf = NULL; // First, encrypt the data if necessary if (get_encryption()) { if (!wrap((unsigned char *) buffer, length, buf , l_out)) { dprintf(D_SECURITY, "Encryption failed\n"); goto error; } } else { buf = (unsigned char *) malloc(length); memcpy(buf, buffer, length); } cur = buf; // Tell peer how big the transfer is going to be, if requested. // Note: send_size param is 1 (true) by default. this->encode(); if ( send_size ) { ASSERT( this->code(length) != FALSE ); ASSERT( this->end_of_message() != FALSE ); } // First drain outgoing buffers if ( !prepare_for_nobuffering(stream_encode) ) { // error flushing buffers; error message already printed goto error; } // Optimize transfer by writing in pagesized chunks. for(i = 0; i < length;) { // If there is less then a page left. if( (length - i) < pagesize ) { result = condor_write(peer_description(), _sock, (char *)cur, (length - i), _timeout); if( result < 0 ) { goto error; } cur += (length - i); i += (length - i); } else { // Send another page... result = condor_write(peer_description(), _sock, (char *)cur, pagesize, _timeout); if( result < 0 ) { goto error; } cur += pagesize; i += pagesize; } } if (i > 0) { _bytes_sent += i; } free(buf); return i; error: dprintf(D_ALWAYS, "ReliSock::put_bytes_nobuffer: Send failed.\n"); free(buf); return -1; }