这篇教程C++ BIO_write函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中BIO_write函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_write函数的具体用法?C++ BIO_write怎么用?C++ BIO_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了BIO_write函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: checkout_file// This is a function that checks out a file from the server// - RETURNS 0 in case of success, 1 otherwiseint checkout_file(SSL* ssl, BIO *sslbio, char *buffer) { FILE* file; // pointer to the file to be received int ret; int length; // Sending the client name // BIO_write(sslbio, CLIENT_NAME, strlen(CLIENT_NAME)); // Receive number of options memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '/0'; printf("/nSelect file number to check out file./n"); printf("You have %s option(s):/n", buffer); int opns = atoi(buffer); if ( opns < 1 ) { //No files to choose from. printf("You have ZERO files stored at server.../n"); printf("Unable to check-out file: Choose a different option./n"); exit(1); } // If files are present, receive file options printf("/nFILE UID | FILE NAME | FILE OWNER/n"); int i; for (i = 0; i < opns; i++) { memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '/0'; printf("%s/n", buffer); } // Receive deliminated list of option numbers memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '/0'; // Tokenize options int options[opns]; int numtokens = str_to_ints(buffer, options); // Select Option, i.e., file UID choice int filechoice = getintchoice("Select FILE UID to checkout", options, opns); length = floor(log10(abs(filechoice))) + 1; char sfile[length]; sprintf(sfile, "%d", filechoice); // Send File UID to Server BIO_write(sslbio, sfile, length); // Get file name from Server memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '/0'; printf("Saving file '%s' to local disk./n", buffer); // Open file file = fopen(buffer, "w+"); if(file == NULL) { fprintf(stderr, "File not found: '%s'/n", buffer); return 1; } // Get file data from Server memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '/0'; printf("Plain text received:/n%s/n",buffer); // Writing to file fwrite(buffer, length, 1, file);//.........这里部分代码省略.........
开发者ID:jlr84,项目名称:cs6238-file-server,代码行数:101,
示例2: STACK_OF//.........这里部分代码省略......... if (pcert == NULL) { for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) { ri=sk_PKCS7_RECIP_INFO_value(rsk,i); if (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey) > 0) break; ERR_clear_error(); ri = NULL; } if (ri == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_RECIPIENT_MATCHES_KEY); goto err; } } else { if (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey) <= 0) goto err; } evp_ctx=NULL; BIO_get_cipher_ctx(etmp,&evp_ctx); if (EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0) <= 0) goto err; if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0) goto err; if (eklen != EVP_CIPHER_CTX_key_length(evp_ctx)) { /* Some S/MIME clients don't use the same key * and effective key length. The key length is * determined by the size of the decrypted RSA key. */ if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen)) { PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH); goto err; } } if (EVP_CipherInit_ex(evp_ctx,NULL,NULL,ek,NULL,0) <= 0) goto err; if (ek) { OPENSSL_cleanse(ek,eklen); OPENSSL_free(ek); } if (out == NULL) out=etmp; else BIO_push(out,etmp); etmp=NULL; }#if 1 if (PKCS7_is_detached(p7) || (in_bio != NULL)) { bio=in_bio; } else {#if 0 bio=BIO_new(BIO_s_mem()); /* We need to set this so that when we have read all * the data, the encrypt BIO, if present, will read * EOF and encode the last few bytes */ BIO_set_mem_eof_return(bio,0); if (data_body->length > 0) BIO_write(bio,(char *)data_body->data,data_body->length);#else if (data_body->length > 0) bio = BIO_new_mem_buf(data_body->data,data_body->length); else { bio=BIO_new(BIO_s_mem()); BIO_set_mem_eof_return(bio,0); } if (bio == NULL) goto err;#endif } BIO_push(out,bio); bio=NULL;#endif if (0) {err: if (out != NULL) BIO_free_all(out); if (btmp != NULL) BIO_free_all(btmp); if (etmp != NULL) BIO_free_all(etmp); if (bio != NULL) BIO_free_all(bio); out=NULL; } return(out); }
开发者ID:10045125,项目名称:xuggle-xuggler,代码行数:101,
示例3: s_client_main//.........这里部分代码省略......... if (mbuf_len == -1) { BIO_printf(bio_err, "BIO_read failed/n"); goto end; } } for (;;) { struct pollfd pfd[3]; /* stdin, stdout, socket */ int ptimeout = -1; if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_get_timeout(con, &timeout)) ptimeout = timeout.tv_sec * 1000 + timeout.tv_usec / 1000; if (SSL_in_init(con) && !SSL_total_renegotiations(con)) { in_init = 1; tty_on = 0; } else { tty_on = 1; if (in_init) { in_init = 0; if (sess_out) { BIO *stmp = BIO_new_file(sess_out, "w"); if (stmp) { PEM_write_bio_SSL_SESSION(stmp, SSL_get_session(con)); BIO_free(stmp); } else BIO_printf(bio_err, "Error writing session file %s/n", sess_out); } print_stuff(bio_c_out, con, full_log); if (full_log > 0) full_log--; if (starttls_proto) { BIO_write(bio_err, mbuf, mbuf_len); /* We don't need to know any more */ starttls_proto = PROTO_OFF; } if (reconnect) { reconnect--; BIO_printf(bio_c_out, "drop connection and then reconnect/n"); SSL_shutdown(con); SSL_set_connect_state(con); shutdown(SSL_get_fd(con), SHUT_RD); close(SSL_get_fd(con)); goto re_start; } } } ssl_pending = read_ssl && SSL_pending(con); pfd[0].fd = -1; pfd[1].fd = -1; if (!ssl_pending) { if (tty_on) { if (read_tty) { pfd[0].fd = fileno(stdin); pfd[0].events = POLLIN; } if (write_tty) { pfd[1].fd = fileno(stdout); pfd[1].events = POLLOUT; } } pfd[2].fd = SSL_get_fd(con);
开发者ID:GyazSquare,项目名称:LibreSSL-Framework,代码行数:67,
示例4: RSA_printint RSA_print(BIO *bp, RSA *x, int off) { char str[128]; const char *s; unsigned char *m=NULL; int ret=0; size_t buf_len=0, i; if (x->n) buf_len = (size_t)BN_num_bytes(x->n); if (x->e) if (buf_len < (i = (size_t)BN_num_bytes(x->e))) buf_len = i; if (x->d) if (buf_len < (i = (size_t)BN_num_bytes(x->d))) buf_len = i; if (x->p) if (buf_len < (i = (size_t)BN_num_bytes(x->p))) buf_len = i; if (x->q) if (buf_len < (i = (size_t)BN_num_bytes(x->q))) buf_len = i; if (x->dmp1) if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1))) buf_len = i; if (x->dmq1) if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1))) buf_len = i; if (x->iqmp) if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp))) buf_len = i; m=(unsigned char *)OPENSSL_malloc(buf_len+10); if (m == NULL) { RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE); goto err; } if (off) { if (off > 128) off=128; memset(str,' ',off); } if (x->d != NULL) { if (off && (BIO_write(bp,str,off) <= 0)) goto err; if (BIO_printf(bp,"Private-Key: (%d bit)/n",BN_num_bits(x->n)) <= 0) goto err; } if (x->d == NULL) sprintf(str,"Modulus (%d bit):",BN_num_bits(x->n)); else strcpy(str,"modulus:"); if (!print(bp,str,x->n,m,off)) goto err; s=(x->d == NULL)?"Exponent:":"publicExponent:"; if (!print(bp,s,x->e,m,off)) goto err; if (!print(bp,"privateExponent:",x->d,m,off)) goto err; if (!print(bp,"prime1:",x->p,m,off)) goto err; if (!print(bp,"prime2:",x->q,m,off)) goto err; if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err; if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err; if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err; ret=1;err: if (m != NULL) OPENSSL_free(m); return(ret); }
开发者ID:aosm,项目名称:OpenSSL096,代码行数:69,
示例5: process_filesint process_files(char **parameters, int param_count){ int i, success = 0; size_t siglen; long int filesize=0, bytes_written=0; unsigned char *signature, *file_mem; char *boincname, *filename; EVP_MD_CTX *mdctx = NULL; FILE *current_file; BIO *b64, *bio_out; printf("Boinc filename Filename Status/n"); printf("--------------------------------------------------------/n"); for(i = 0; i<param_count; i+=2){ boincname = parameters[i]; filename = parameters[i+1]; printf("%-18.18s %-18.18s ", boincname, filename); if(!(mdctx = EVP_MD_CTX_create())) goto err; if(1 != EVP_DigestSignInit(mdctx, NULL, EVP_sha256(), NULL, private_key)) goto err; /* Open file and get size */ current_file = fopen(filename, "rb"); if(current_file == NULL) {print_error("file_signing", "unable to open file", filename); goto err;} fseek(current_file, 0L, SEEK_END); filesize = ftell(current_file); file_mem = (unsigned char *)OPENSSL_malloc(filesize); if(file_mem == NULL) {print_error("file_signing", "unable to reserve memory for file", filename); goto err;} fseek(current_file, 0L, SEEK_SET); //rewind to beginning of file /* read file to memory */ bytes_written = fread(file_mem, 1, filesize, current_file); if(bytes_written != filesize){ if(ferror(current_file)) {print_error("file_signing", "Error reading file", filename); goto err;} else if(feof(current_file)) {printf("File: %s wrote %li of filesize %li", filename, bytes_written, filesize); goto err;} else {print_error("file_signing", "something strange happened", filename); goto err;} } if(1 != EVP_DigestSignUpdate(mdctx, file_mem, filesize)) goto err; if(1 != EVP_DigestSignFinal(mdctx, NULL, &siglen)) goto err; // Get signature size if(!(signature = OPENSSL_malloc(sizeof(unsigned char) * siglen))) goto err; if(1 != EVP_DigestSignFinal(mdctx, signature, &siglen)) goto err; fwrite(boincname, sizeof(char), strlen(boincname), outputfile); fputc(' ', outputfile); b64 = BIO_new(BIO_f_base64()); bio_out = BIO_new_fp(outputfile, BIO_NOCLOSE); BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); BIO_push(b64, bio_out); BIO_write(b64, signature, sizeof(unsigned char) * siglen); BIO_flush(b64); BIO_free_all(b64); fputc('/n', outputfile); success = 1; printf("%-18.18s/n", "Success!"); err: if(mdctx) EVP_MD_CTX_destroy(mdctx); if(current_file) fclose(current_file); if(file_mem) OPENSSL_free(file_mem); if(signature) OPENSSL_free(signature); if(!success) printf("%-18.18s/n", "Failed!"); }}
开发者ID:igemsoftware,项目名称:Heidelberg_2014,代码行数:73,
示例6: do_fpint do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, EVP_PKEY *key, unsigned char *sigin, int siglen, const char *sig_name, const char *md_name, const char *file, BIO *bmd){ size_t len; int i; for (;;) { i = BIO_read(bp, (char *)buf, BUFSIZE); if (i < 0) { BIO_printf(bio_err, "Read Error in %s/n", file); ERR_print_errors(bio_err); return 1; } if (i == 0) break; } if (sigin) { EVP_MD_CTX *ctx; BIO_get_md_ctx(bp, &ctx); i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen); if (i > 0) BIO_printf(out, "Verified OK/n"); else if (i == 0) { BIO_printf(out, "Verification Failure/n"); return 1; } else { BIO_printf(bio_err, "Error Verifying Data/n"); ERR_print_errors(bio_err); return 1; } return 0; } if (key) { EVP_MD_CTX *ctx; BIO_get_md_ctx(bp, &ctx); len = BUFSIZE; if (!EVP_DigestSignFinal(ctx, buf, &len)) { BIO_printf(bio_err, "Error Signing Data/n"); ERR_print_errors(bio_err); return 1; } } else { len = BIO_gets(bp, (char *)buf, BUFSIZE); if ((int)len < 0) { ERR_print_errors(bio_err); return 1; } } if (binout) BIO_write(out, buf, len); else if (sep == 2) { for (i = 0; i < (int)len; i++) BIO_printf(out, "%02x", buf[i]); BIO_printf(out, " *%s/n", file); } else { if (sig_name) { BIO_puts(out, sig_name); if (md_name) BIO_printf(out, "-%s", md_name); BIO_printf(out, "(%s)= ", file); } else if (md_name) BIO_printf(out, "%s(%s)= ", md_name, file); else BIO_printf(out, "(%s)= ", file); for (i = 0; i < (int)len; i++) { if (sep && (i != 0)) BIO_printf(out, ":"); BIO_printf(out, "%02x", buf[i]); } BIO_printf(out, "/n"); } return 0;}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:76,
示例7: b64_writestatic int b64_write(BIO *b, const char *in, int inl){ int ret = 0; int n; int i; BIO_B64_CTX *ctx; ctx = (BIO_B64_CTX *)b->ptr; BIO_clear_retry_flags(b); if (ctx->encode != B64_ENCODE) { ctx->encode = B64_ENCODE; ctx->buf_len = 0; ctx->buf_off = 0; ctx->tmp_len = 0; EVP_EncodeInit(ctx->base64); } OPENSSL_assert(ctx->buf_off < (int)sizeof(ctx->buf)); OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); OPENSSL_assert(ctx->buf_len >= ctx->buf_off); n = ctx->buf_len - ctx->buf_off; while (n > 0) { i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n); if (i <= 0) { BIO_copy_next_retry(b); return (i); } OPENSSL_assert(i <= n); ctx->buf_off += i; OPENSSL_assert(ctx->buf_off <= (int)sizeof(ctx->buf)); OPENSSL_assert(ctx->buf_len >= ctx->buf_off); n -= i; } /* at this point all pending data has been written */ ctx->buf_off = 0; ctx->buf_len = 0; if ((in == NULL) || (inl <= 0)) return (0); while (inl > 0) { n = (inl > B64_BLOCK_SIZE) ? B64_BLOCK_SIZE : inl; if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) { if (ctx->tmp_len > 0) { OPENSSL_assert(ctx->tmp_len <= 3); n = 3 - ctx->tmp_len; /* * There's a theoretical possibility for this */ if (n > inl) n = inl; memcpy(&(ctx->tmp[ctx->tmp_len]), in, n); ctx->tmp_len += n; ret += n; if (ctx->tmp_len < 3) break; ctx->buf_len = EVP_EncodeBlock((unsigned char *)ctx->buf, (unsigned char *)ctx->tmp, ctx->tmp_len); OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); OPENSSL_assert(ctx->buf_len >= ctx->buf_off); /* * Since we're now done using the temporary buffer, the * length should be 0'd */ ctx->tmp_len = 0; } else { if (n < 3) { memcpy(ctx->tmp, in, n); ctx->tmp_len = n; ret += n; break; } n -= n % 3; ctx->buf_len = EVP_EncodeBlock((unsigned char *)ctx->buf, (const unsigned char *)in, n); OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); OPENSSL_assert(ctx->buf_len >= ctx->buf_off); ret += n; } } else { EVP_EncodeUpdate(ctx->base64, (unsigned char *)ctx->buf, &ctx->buf_len, (unsigned char *)in, n); OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); OPENSSL_assert(ctx->buf_len >= ctx->buf_off); ret += n; } inl -= n; in += n; ctx->buf_off = 0; n = ctx->buf_len; while (n > 0) { i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n); if (i <= 0) { BIO_copy_next_retry(b);//.........这里部分代码省略.........
开发者ID:AndreV84,项目名称:openssl,代码行数:101,
示例8: buffer_writestatic int buffer_write(BIO *b, const char *in, int inl){ int i, num = 0; BIO_F_BUFFER_CTX *ctx; if ((in == NULL) || (inl <= 0)) return (0); ctx = (BIO_F_BUFFER_CTX *)b->ptr; if ((ctx == NULL) || (b->next_bio == NULL)) return (0); BIO_clear_retry_flags(b); start: i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off); /* add to buffer and return */ if (i >= inl) { memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl); ctx->obuf_len += inl; return (num + inl); } /* else */ /* stuff already in buffer, so add to it first, then flush */ if (ctx->obuf_len != 0) { if (i > 0) { /* lets fill it up if we can */ memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i); in += i; inl -= i; num += i; ctx->obuf_len += i; } /* we now have a full buffer needing flushing */ for (;;) { i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]), ctx->obuf_len); if (i <= 0) { BIO_copy_next_retry(b); if (i < 0) return ((num > 0) ? num : i); if (i == 0) return (num); } ctx->obuf_off += i; ctx->obuf_len -= i; if (ctx->obuf_len == 0) break; } } /* * we only get here if the buffer has been flushed and we still have * stuff to write */ ctx->obuf_off = 0; /* we now have inl bytes to write */ while (inl >= ctx->obuf_size) { i = BIO_write(b->next_bio, in, inl); if (i <= 0) { BIO_copy_next_retry(b); if (i < 0) return ((num > 0) ? num : i); if (i == 0) return (num); } num += i; in += i; inl -= i; if (inl == 0) return (num); } /* * copy the rest into the buffer since we have only a small amount left */ goto start;}
开发者ID:AimaTeam-hehai,项目名称:openssl,代码行数:76,
示例9: buffer_ctrl//.........这里部分代码省略......... memcpy(ctx->ibuf, ptr, (int)num); ret = 1; break; case BIO_C_SET_BUFF_SIZE: if (ptr != NULL) { ip = (int *)ptr; if (*ip == 0) { ibs = (int)num; obs = ctx->obuf_size; } else { /* if (*ip == 1) */ ibs = ctx->ibuf_size; obs = (int)num; } } else { ibs = (int)num; obs = (int)num; } p1 = ctx->ibuf; p2 = ctx->obuf; if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) { p1 = OPENSSL_malloc((int)num); if (p1 == NULL) goto malloc_error; } if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { p2 = OPENSSL_malloc((int)num); if (p2 == NULL) { if (p1 != ctx->ibuf) OPENSSL_free(p1); goto malloc_error; } } if (ctx->ibuf != p1) { OPENSSL_free(ctx->ibuf); ctx->ibuf = p1; ctx->ibuf_off = 0; ctx->ibuf_len = 0; ctx->ibuf_size = ibs; } if (ctx->obuf != p2) { OPENSSL_free(ctx->obuf); ctx->obuf = p2; ctx->obuf_off = 0; ctx->obuf_len = 0; ctx->obuf_size = obs; } break; case BIO_C_DO_STATE_MACHINE: if (b->next_bio == NULL) return (0); BIO_clear_retry_flags(b); ret = BIO_ctrl(b->next_bio, cmd, num, ptr); BIO_copy_next_retry(b); break; case BIO_CTRL_FLUSH: if (b->next_bio == NULL) return (0); if (ctx->obuf_len <= 0) { ret = BIO_ctrl(b->next_bio, cmd, num, ptr); break; } for (;;) { BIO_clear_retry_flags(b); if (ctx->obuf_len > 0) { r = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]), ctx->obuf_len); BIO_copy_next_retry(b); if (r <= 0) return ((long)r); ctx->obuf_off += r; ctx->obuf_len -= r; } else { ctx->obuf_len = 0; ctx->obuf_off = 0; ret = 1; break; } } ret = BIO_ctrl(b->next_bio, cmd, num, ptr); break; case BIO_CTRL_DUP: dbio = (BIO *)ptr; if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) || !BIO_set_write_buffer_size(dbio, ctx->obuf_size)) ret = 0; break; default: if (b->next_bio == NULL) return (0); ret = BIO_ctrl(b->next_bio, cmd, num, ptr); break; } return (ret); malloc_error: BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE); return (0);}
开发者ID:AimaTeam-hehai,项目名称:openssl,代码行数:101,
示例10: do_fpint do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title, const char *file) { int len; int i; for (;;) { i=BIO_read(bp,(char *)buf,BUFSIZE); if(i < 0) { BIO_printf(bio_err, "Read Error in %s/n",file); ERR_print_errors(bio_err); return 1; } if (i == 0) break; } if(sigin) { EVP_MD_CTX *ctx; BIO_get_md_ctx(bp, &ctx); i = EVP_VerifyFinal(ctx, sigin, (unsigned int)siglen, key); if(i > 0) BIO_printf(out, "Verified OK/n"); else if(i == 0) { BIO_printf(out, "Verification Failure/n"); return 1; } else { BIO_printf(bio_err, "Error Verifying Data/n"); ERR_print_errors(bio_err); return 1; } return 0; } if(key) { EVP_MD_CTX *ctx; BIO_get_md_ctx(bp, &ctx); if(!EVP_SignFinal(ctx, buf, (unsigned int *)&len, key)) { BIO_printf(bio_err, "Error Signing Data/n"); ERR_print_errors(bio_err); return 1; } } else len=BIO_gets(bp,(char *)buf,BUFSIZE); if(binout) BIO_write(out, buf, len); else { BIO_write(out,title,strlen(title)); for (i=0; i<len; i++) { if (sep && (i != 0)) BIO_printf(out, ":"); BIO_printf(out, "%02x",buf[i]); } BIO_printf(out, "/n"); } return 0; }
开发者ID:froggatt,项目名称:edimax-br-6528n,代码行数:66,
示例11: loge//.........这里部分代码省略......... chan = cur_chan; int flags = enc_buf [1]; // Flags int frame_len = be16toh(*((uint16_t*)&enc_buf[2])); logd("Frame flags %i len %i", flags, frame_len); if (frame_len > MAX_FRAME_PAYLOAD_SIZE) { loge ("Too big"); return (-1); } int header_size = 4; bool has_total_size_header = false; if ((flags & HU_FRAME_FIRST_FRAME) & !(flags & HU_FRAME_LAST_FRAME)) { //if first but not last, next 4 is total size has_total_size_header = true; header_size += 4; } int remaining_bytes_in_frame = (frame_len + header_size) - have_len; while(remaining_bytes_in_frame > 0) { logd("Getting more %i", remaining_bytes_in_frame); int got_bytes = hu_aap_tra_recv (&enc_buf[have_len], remaining_bytes_in_frame, tmo); // Get Rx packet from Transport if (got_bytes < 0) { // If we don't have a full 6 byte header at least... loge ("Recv got_bytes: %d", got_bytes); return (-1); } have_len += got_bytes; remaining_bytes_in_frame -= got_bytes; } if (!has_first && !(flags & HU_FRAME_FIRST_FRAME)) { loge ("No HU_FRAME_FIRST_FRAME"); return (-1); } has_first = true; has_last = (flags & HU_FRAME_LAST_FRAME) != 0; if (has_total_size_header) { uint32_t total_size = be32toh(*((uint32_t*)&enc_buf[4])); logd("First only, total len %u", total_size); temp_assembly_buffer.reserve(total_size); } else { temp_assembly_buffer.reserve(frame_len); } if (flags & HU_FRAME_ENCRYPTED) { size_t cur_vec = temp_assembly_buffer.size(); temp_assembly_buffer.resize(cur_vec + frame_len); //just incase int bytes_written = BIO_write (hu_ssl_rm_bio, &enc_buf[header_size], frame_len); // Write encrypted to SSL input BIO if (bytes_written <= 0) { loge ("BIO_write() bytes_written: %d", bytes_written); return (-1); } if (bytes_written != frame_len) loge ("BIO_write() len: %d bytes_written: %d chan: %d %s", frame_len, bytes_written, chan, chan_get (chan)); else if (ena_log_verbo) logd ("BIO_write() len: %d bytes_written: %d chan: %d %s", frame_len, bytes_written, chan, chan_get (chan)); int bytes_read = SSL_read (hu_ssl_ssl, &temp_assembly_buffer[cur_vec], frame_len); // Read decrypted to decrypted rx buf if (bytes_read <= 0 || bytes_read > frame_len) { loge ("SSL_read() bytes_read: %d errno: %d", bytes_read, errno); hu_ssl_ret_log (bytes_read); return (-1); // Fatal so return error and de-initialize; Should we be able to recover, if Transport data got corrupted ?? } if (ena_log_verbo) logd ("SSL_read() bytes_read: %d", bytes_read); temp_assembly_buffer.resize(cur_vec + bytes_read); } else { temp_assembly_buffer.insert(temp_assembly_buffer.end(), &enc_buf[header_size], &enc_buf[frame_len+header_size]); } } const int buf_len = temp_assembly_buffer.size(); if (buf_len >= 2) { uint16_t msg_type = be16toh(*reinterpret_cast<uint16_t*>(temp_assembly_buffer.data())); ret = iaap_msg_process (chan, msg_type, &temp_assembly_buffer[2], buf_len - 2); // Decrypt & Process 1 received encrypted message if (ret < 0 && iaap_state != hu_STATE_STOPPED) { // If error... loge ("Error iaap_msg_process() ret: %d ", ret); return (ret); } } return (ret); // Return value from the last iaap_recv_dec_process() call; should be 0 }
开发者ID:mishaaq,项目名称:headunit,代码行数:101,
示例12: pkeyutl_main//.........这里部分代码省略......... } /* Raw input data is handled elsewhere */ if (in != NULL && !rawin) { /* Read the input data */ buf_inlen = bio_to_mem(&buf_in, keysize * 10, in); if (buf_inlen < 0) { BIO_printf(bio_err, "Error reading input Data/n"); goto end; } if (rev) { size_t i; unsigned char ctmp; size_t l = (size_t)buf_inlen; for (i = 0; i < l / 2; i++) { ctmp = buf_in[i]; buf_in[i] = buf_in[l - 1 - i]; buf_in[l - 1 - i] = ctmp; } } } /* Sanity check the input if the input is not raw */ if (!rawin && buf_inlen > EVP_MAX_MD_SIZE && (pkey_op == EVP_PKEY_OP_SIGN || pkey_op == EVP_PKEY_OP_VERIFY || pkey_op == EVP_PKEY_OP_VERIFYRECOVER)) { BIO_printf(bio_err, "Error: The input data looks too long to be a hash/n"); goto end; } if (pkey_op == EVP_PKEY_OP_VERIFY) { if (rawin) { rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, sig, siglen, NULL, 0); } else { rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen, buf_in, (size_t)buf_inlen); } if (rv == 1) { BIO_puts(out, "Signature Verified Successfully/n"); ret = 0; } else { BIO_puts(out, "Signature Verification Failure/n"); } goto end; } if (kdflen != 0) { buf_outlen = kdflen; rv = 1; } else { if (rawin) { /* rawin allocates the buffer in do_raw_keyop() */ rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, NULL, 0, &buf_out, (size_t *)&buf_outlen); } else { rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen, buf_in, (size_t)buf_inlen); if (rv > 0 && buf_outlen != 0) { buf_out = app_malloc(buf_outlen, "buffer output"); rv = do_keyop(ctx, pkey_op, buf_out, (size_t *)&buf_outlen, buf_in, (size_t)buf_inlen); } } } if (rv <= 0) { if (pkey_op != EVP_PKEY_OP_DERIVE) { BIO_puts(bio_err, "Public Key operation error/n"); } else { BIO_puts(bio_err, "Key derivation failed/n"); } ERR_print_errors(bio_err); goto end; } ret = 0; if (asn1parse) { if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1)) ERR_print_errors(bio_err); } else if (hexdump) { BIO_dump(out, (char *)buf_out, buf_outlen); } else { BIO_write(out, buf_out, buf_outlen); } end: EVP_PKEY_CTX_free(ctx); release_engine(e); BIO_free(in); BIO_free_all(out); OPENSSL_free(buf_in); OPENSSL_free(buf_out); OPENSSL_free(sig); sk_OPENSSL_STRING_free(pkeyopts); sk_OPENSSL_STRING_free(pkeyopts_passin); return ret;}
开发者ID:tiran,项目名称:openssl,代码行数:101,
示例13: cas_validate//.........这里部分代码省略......... BIO_set_conn_port(bio, config->port); if(BIO_do_connect(bio) <= 0) { DEBUG_LOG("Error attempting to connect : %s/n", config->host); END(CAS_ERROR_CONN); } } /* build request */ full_request = malloc(strlen(CAS_METHOD) + strlen(" ") + strlen(config->uriValidate) + strlen("?ticket=") + strlen(ticket) + + strlen("&service=") + strlen(service) + strlen(" ") + strlen(GENERIC_HEADERS) + strlen ("/r/n")#ifdef HEADER_HOST_NAME + strlen(HEADER_HOST_NAME) + strlen (": ") + strlen (config->host)#endif + strlen("/r/n/r/n") + 1); if (full_request == NULL) { DEBUG_LOG("Error memory allocation%s/n", ""); END(CAS_ERROR_MEMORY_ALLOC); }#ifdef HEADER_HOST_NAME sprintf(full_request, "%s %s?ticket=%s&service=%s %s/r/n%s: %s/r/n/r/n", CAS_METHOD, config->uriValidate, ticket, service, GENERIC_HEADERS, HEADER_HOST_NAME,config->host);#else sprintf(full_request, "%s %s?ticket=%s&service=%s %s/r/n/r/n", CAS_METHOD, config->uriValidate, ticket, service, GENERIC_HEADERS);#endif /* send request */ DEBUG_LOG("---- request :/n%s/n", full_request); if (BIO_write(bio, full_request, strlen(full_request)) != strlen(full_request)) { DEBUG_LOG("Unable to correctly send request to %s/n", config->host); END(CAS_ERROR_HTTP); } /* Read the response */ total = 0; b = 0; do { b = BIO_read(bio, buf + total, (sizeof(buf) - 1) - total); total += b; } while (b > 0); buf[total] = '/0'; if (b != 0 || total >= sizeof(buf) - 1) { DEBUG_LOG("Unexpected read error or response too large from %s/n", config->host); DEBUG_LOG("b = %d/n", b); DEBUG_LOG("total = %d/n", total); DEBUG_LOG("buf = %s/n", buf); END(CAS_ERROR_HTTP); // unexpected read error or response too large } DEBUG_LOG("---- response :/n%s/n", buf); str = (char *)strstr(buf, "/r/n/r/n"); // find the end of the header if (!str) { DEBUG_LOG("no header in response%s/n", ""); END(CAS_ERROR_HTTP); // no header }
开发者ID:EsupPortail,项目名称:esup-pam-cas,代码行数:67,
示例14: main//.........这里部分代码省略......... /* Check the validity of Private Key */ if (!SSL_CTX_check_private_key(ctx)) { ERR_print_errors_fp(stdout); printf("ssl_ctx_check_private_key failed./r/n"); //goto free_ctx; BIO_free_all(sslbio); SSL_CTX_free(ctx); return 0; } /* Create the connection */ sslbio = BIO_new_ssl_connect(ctx); /* Get SSL from sslbio */ BIO_get_ssl(sslbio, &ssl); /* Set the SSL mode into SSL_MODE_AUTO_RETRY */ SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); ////////////////////////////////////////////////// // NOTE: Port# hardcoded here; change if necessary ////////////////////////////////////////////////// BIO_set_conn_port(sslbio, "7777"); BIO_set_conn_hostname(sslbio, server); /* Request Connection */ if(BIO_do_connect(sslbio) <= 0) { fprintf(stderr, "Error attempting to connect/n"); ERR_print_errors_fp(stderr); BIO_free_all(sslbio); SSL_CTX_free(ctx); return 0; } else { printf("Connection to server successful!/n"); } /* Verify Server Certificate Validity */ if(SSL_get_verify_result(ssl) != X509_V_OK) { printf("Certificate Verification Error: %ld/n", SSL_get_verify_result(ssl)); BIO_free_all(sslbio); SSL_CTX_free(ctx); return 0; } else { printf("verify server cert successful/n"); } //Send hostname to server printf("Sending client name to server./n"); BIO_write(sslbio, CLIENT_NAME, strlen(CLIENT_NAME)); do { choice = getchoice("Please select an action", menu); printf("You have chosen: %c/n", choice); if (choice == 'a') { printf("Check-in function will be executed/n"); choiceProcess (sslbio, buffer, choice); ret = checkin_file(ssl, sslbio, buffer); } else if (choice == 'b') { printf("Check-out function will be executed/n"); choiceProcess (sslbio, buffer, choice); ret = checkout_file(ssl, sslbio, buffer); } else if (choice == 'c') { printf("Delegate function will be executed/n"); choiceProcess (sslbio, buffer, choice); } else if (choice == 'd') { printf("Safe-delete function will be executed/n"); choiceProcess (sslbio, buffer, choice); } else { printf("Terminate function will be executed/n"); } } while (choice != 'q'); /* Terminate the connection by sending message */ clientTerminate (sslbio, buffer); /* Close the connection and free the context */ BIO_ssl_shutdown(sslbio); BIO_free_all(sslbio); SSL_CTX_free(ctx); } return 0; }
开发者ID:jlr84,项目名称:cs6238-file-server,代码行数:101,
示例15: process_output_sslstatic ssize_t process_output_ssl( pn_transport_t *transport, unsigned int layer, char *buffer, size_t max_len){ pni_ssl_t *ssl = transport->ssl; if (!ssl) return PN_EOS; if (ssl->ssl == NULL && init_ssl_socket(transport, ssl)) return PN_EOS; ssize_t written = 0; bool work_pending; do { work_pending = false; // first, get any pending application output, if possible if (!ssl->app_output_closed && ssl->out_count < ssl->out_size) { ssize_t app_bytes = transport->io_layers[layer+1]->process_output(transport, layer+1, &ssl->outbuf[ssl->out_count], ssl->out_size - ssl->out_count); if (app_bytes > 0) { ssl->out_count += app_bytes; work_pending = true; ssl_log(transport, "Gathered %d bytes from app to send to peer", app_bytes ); } else { if (app_bytes < 0) { ssl_log(transport, "Application layer closed its output, error=%d (%d bytes pending send)", (int) app_bytes, (int) ssl->out_count); ssl->app_output_closed = app_bytes; } } } // now push any pending app data into the socket if (!ssl->ssl_closed) { char *data = ssl->outbuf; if (ssl->out_count > 0) { int wrote = BIO_write( ssl->bio_ssl, data, ssl->out_count ); if (wrote > 0) { data += wrote; ssl->out_count -= wrote; work_pending = true; ssl_log( transport, "Wrote %d bytes from app to socket", wrote ); } else { if (!BIO_should_retry(ssl->bio_ssl)) { int reason = SSL_get_error( ssl->ssl, wrote ); switch (reason) { case SSL_ERROR_ZERO_RETURN: // SSL closed cleanly ssl_log(transport, "SSL connection has closed"); start_ssl_shutdown(transport); // KAG: not sure - this may not be necessary ssl->out_count = 0; // can no longer write to socket, so erase app output data ssl->ssl_closed = true; break; default: // unexpected error return (ssize_t)ssl_failed(transport); } } else { if (BIO_should_read( ssl->bio_ssl )) { ssl->read_blocked = true; ssl_log(transport, "Detected read-blocked"); } if (BIO_should_write( ssl->bio_ssl )) { ssl->write_blocked = true; ssl_log(transport, "Detected write-blocked"); } } } } if (ssl->out_count == 0) { if (ssl->app_input_closed && ssl->app_output_closed) { // application is done sending/receiving data, and all buffered output data has // been written to the SSL socket start_ssl_shutdown(transport); } } else if (data != ssl->outbuf) { memmove( ssl->outbuf, data, ssl->out_count ); } } // read from the network bio as much as possible, filling the buffer if (max_len) { int available = BIO_read( ssl->bio_net_io, buffer, max_len ); if (available > 0) { max_len -= available; buffer += available; written += available; ssl->write_blocked = false; work_pending = work_pending || max_len > 0; ssl_log(transport, "Read %d bytes from BIO Layer", available ); } } } while (work_pending); //_log(ssl, "written=%d ssl_closed=%d in_count=%d app_input_closed=%d app_output_closed=%d bio_pend=%d", // written, ssl->ssl_closed, ssl->in_count, ssl->app_input_closed, ssl->app_output_closed, BIO_pending(ssl->bio_net_io) ); // PROTON-82: close the output side as soon as we've sent the SSL close_notify. // We're not requiring the response, as some implementations never reply. // ---- // Once no more data is available "below" the SSL socket, tell the transport we are//.........这里部分代码省略.........
开发者ID:850361813,项目名称:qpid-proton,代码行数:101,
示例16: rand_mainint rand_main(int argc, char **argv){ BIO *out = NULL; char *inrand = NULL, *outfile = NULL, *prog; OPTION_CHOICE o; int format = FORMAT_BINARY, i, num = -1, r, ret = 1; prog = opt_init(argc, argv, rand_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary./n", prog); goto end; case OPT_HELP: opt_help(rand_options); ret = 0; goto end; case OPT_OUT: outfile = opt_arg(); break; case OPT_ENGINE: (void)setup_engine(opt_arg(), 0); break; case OPT_RAND: inrand = opt_arg(); break; case OPT_BASE64: format = FORMAT_BASE64; break; case OPT_HEX: format = FORMAT_TEXT; break; } } argc = opt_num_rest(); argv = opt_rest(); if (argc != 1) goto opthelp; if (sscanf(argv[0], "%d", &num) != 1 || num < 0) goto opthelp; app_RAND_load_file(NULL, (inrand != NULL)); if (inrand != NULL) BIO_printf(bio_err, "%ld semi-random bytes loaded/n", app_RAND_load_files(inrand)); out = bio_open_default(outfile, 'w', format); if (out == NULL) goto end; if (format == FORMAT_BASE64) { BIO *b64 = BIO_new(BIO_f_base64()); if (b64 == NULL) goto end; out = BIO_push(b64, out); } while (num > 0) { unsigned char buf[4096]; int chunk; chunk = num; if (chunk > (int)sizeof(buf)) chunk = sizeof buf; r = RAND_bytes(buf, chunk); if (r <= 0) goto end; if (format != FORMAT_TEXT) /* hex */ BIO_write(out, buf, chunk); else { for (i = 0; i < chunk; i++) BIO_printf(out, "%02x", buf[i]); } num -= chunk; } if (format == FORMAT_TEXT) BIO_puts(out, "/n"); (void)BIO_flush(out); app_RAND_write_file(NULL); ret = 0; end: BIO_free_all(out); return (ret);}
开发者ID:AndreV84,项目名称:openssl,代码行数:89,
示例17: process_input_ssl// take data from the network, and pass it into SSL. Attempt to read decrypted data from// SSL socket and pass it to the application.static ssize_t process_input_ssl( pn_transport_t *transport, unsigned int layer, const char *input_data, size_t available){ pni_ssl_t *ssl = transport->ssl; if (ssl->ssl == NULL && init_ssl_socket(transport, ssl)) return PN_EOS; ssl_log( transport, "process_input_ssl( data size=%d )",available ); ssize_t consumed = 0; bool work_pending; bool shutdown_input = (available == 0); // caller is closed do { work_pending = false; // Write to network bio as much as possible, consuming bytes/available if (available > 0) { int written = BIO_write( ssl->bio_net_io, input_data, available ); if (written > 0) { input_data += written; available -= written; consumed += written; ssl->read_blocked = false; work_pending = (available > 0); ssl_log( transport, "Wrote %d bytes to BIO Layer, %d left over", written, available ); } } else if (shutdown_input) { // lower layer (caller) has closed. Close the WRITE side of the BIO. This will cause // an EOF to be passed to SSL once all pending inbound data has been consumed. ssl_log( transport, "Lower layer closed - shutting down BIO write side"); (void)BIO_shutdown_wr( ssl->bio_net_io ); shutdown_input = false; } // Read all available data from the SSL socket if (!ssl->ssl_closed && ssl->in_count < ssl->in_size) { int read = BIO_read( ssl->bio_ssl, &ssl->inbuf[ssl->in_count], ssl->in_size - ssl->in_count ); if (read > 0) { ssl_log( transport, "Read %d bytes from SSL socket for app", read ); ssl_log_clear_data(transport, &ssl->inbuf[ssl->in_count], read ); ssl->in_count += read; work_pending = true; } else { if (!BIO_should_retry(ssl->bio_ssl)) { int reason = SSL_get_error( ssl->ssl, read ); switch (reason) { case SSL_ERROR_ZERO_RETURN: // SSL closed cleanly ssl_log(transport, "SSL connection has closed"); start_ssl_shutdown(transport); // KAG: not sure - this may not be necessary ssl->ssl_closed = true; break; default: // unexpected error return (ssize_t)ssl_failed(transport); } } else { if (BIO_should_write( ssl->bio_ssl )) { ssl->write_blocked = true; ssl_log(transport, "Detected write-blocked"); } if (BIO_should_read( ssl->bio_ssl )) { ssl->read_blocked = true; ssl_log(transport, "Detected read-blocked"); } } } } // write incoming data to app layer if (!ssl->app_input_closed) { if (ssl->in_count > 0 || ssl->ssl_closed) { /* if ssl_closed, send 0 count */ ssize_t consumed = transport->io_layers[layer+1]->process_input(transport, layer+1, ssl->inbuf, ssl->in_count); if (consumed > 0) { ssl->in_count -= consumed; if (ssl->in_count) memmove( ssl->inbuf, ssl->inbuf + consumed, ssl->in_count ); work_pending = true; ssl_log( transport, "Application consumed %d bytes from peer", (int) consumed ); } else if (consumed < 0) { ssl_log(transport, "Application layer closed its input, error=%d (discarding %d bytes)", (int) consumed, (int)ssl->in_count); ssl->in_count = 0; // discard any pending input ssl->app_input_closed = consumed; if (ssl->app_output_closed && ssl->out_count == 0) { // both sides of app closed, and no more app output pending: start_ssl_shutdown(transport); } } else { // app did not consume any bytes, must be waiting for a full frame if (ssl->in_count == ssl->in_size) { // but the buffer is full, not enough room for a full frame. // can we grow the buffer? uint32_t max_frame = pn_transport_get_max_frame(transport); if (!max_frame) max_frame = ssl->in_size * 2; // no limit if (ssl->in_size < max_frame) {//.........这里部分代码省略.........
开发者ID:850361813,项目名称:qpid-proton,代码行数:101,
示例18: get_timestamp_response//.........这里部分代码省略......... urlBuffer, url->Host, requestContentLength); requestLength = requestHeaderLength + requestContentLength; request = (char*)memory_alloc(requestLength); if (request == NULL) { goto end; } memcpy(request, requestHeader, requestHeaderLength); memcpy(request + requestHeaderLength, contentBuffer, requestContentLength); httpResult = http_read(url->Host, request, requestLength, url->Port, httpTimeOut, 1, &resultBuffer, &resultLength); if (httpResult == HTTP_REDIRECTION && (resultBuffer) && !redirection) { free_url(url); url = NULL; memory_free(request); request = NULL; /* Allocated buffer for redirected url */ urlBuffer = memory_realloc(urlBuffer, resultLength); if (!urlBuffer) { goto end; } memcpy(urlBuffer, resultBuffer, resultLength); memory_free(resultBuffer); redirection++; goto http_redirect; } else if ((httpResult == HTTP_NOERROR) && (resultBuffer)) { responseBio = BIO_new(BIO_s_mem()); if (responseBio == NULL) { goto end; } BIO_write(responseBio, resultBuffer, resultLength); *tsResponse = d2i_TS_RESP_bio(responseBio, NULL); if (*tsResponse == NULL) { goto end; } result = TNOERR; } else { switch (httpResult) { case HTTP_NOLIVEINTERNET_ERROR: result = TNONET; break; case HTTP_TIMEOUT_ERROR: result = TTIMEOUT; break; case HTTP_RESPONSESTATUS_ERROR: result = TSERVERERROR; break; default: result = TINTERNALERROR; break; } }end: free_url(url); if (tsRequest != NULL) { TS_REQ_free(tsRequest); } if (requestBio != NULL) { BIO_free_all(requestBio); } if (responseBio != NULL) { BIO_free_all(responseBio); } if (request != NULL) { memory_free(request); } if (contentBuffer != NULL) { memory_free(contentBuffer); } if (resultBuffer != NULL) { memory_free(resultBuffer); } if (urlBuffer != NULL) { memory_free(urlBuffer); } return result;}
开发者ID:samirmodyk7tcl,项目名称:IEEE_Taggant_System,代码行数:101,
示例19: enc_main//.........这里部分代码省略......... int retval; retval = snprintf(buf, sizeof buf, "enter %s %s password:", OBJ_nid2ln(EVP_CIPHER_nid(enc_config.cipher)), enc_config.enc ? "encryption" : "decryption"); if ((size_t)retval >= sizeof buf) { BIO_printf(bio_err, "Password prompt too long/n"); goto end; } strbuf[0] = '/0'; i = EVP_read_pw_string((char *)strbuf, SIZE, buf, enc_config.enc); if (i == 0) { if (strbuf[0] == '/0') { ret = 1; goto end; } enc_config.keystr = strbuf; break; } if (i < 0) { BIO_printf(bio_err, "bad password read/n"); goto end; } } } if (enc_config.outf == NULL) { BIO_set_fp(out, stdout, BIO_NOCLOSE); if (enc_config.bufsize != NULL) setvbuf(stdout, (char *)NULL, _IONBF, 0); } else { if (BIO_write_filename(out, enc_config.outf) <= 0) { perror(enc_config.outf); goto end; } } rbio = in; wbio = out;#ifdef ZLIB if (do_zlib) { if ((bzl = BIO_new(BIO_f_zlib())) == NULL) goto end; if (enc) wbio = BIO_push(bzl, wbio); else rbio = BIO_push(bzl, rbio); }#endif if (enc_config.base64) { if ((b64 = BIO_new(BIO_f_base64())) == NULL) goto end; if (enc_config.debug) { BIO_set_callback(b64, BIO_debug_callback); BIO_set_callback_arg(b64, (char *) bio_err); } if (enc_config.olb64) BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); if (enc_config.enc) wbio = BIO_push(b64, wbio); else rbio = BIO_push(b64, rbio);
开发者ID:bbbrumley,项目名称:openbsd,代码行数:67,
示例20: TlsHandleAlert/** Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero, TLS session has errors and the response packet needs to be Alert message based on error type. @param[in] Tls Pointer to the TLS object for state checking. @param[in] BufferIn Pointer to the most recently received TLS Alert packet. @param[in] BufferInSize Packet size in bytes for the most recently received TLS Alert packet. @param[out] BufferOut Pointer to the buffer to hold the built packet. @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is the buffer size provided by the caller. On output, it is the buffer size in fact needed to contain the packet. @retval EFI_SUCCESS The required TLS packet is built successfully. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: Tls is NULL. BufferIn is NULL but BufferInSize is NOT 0. BufferInSize is 0 but BufferIn is NOT NULL. BufferOutSize is NULL. BufferOut is NULL if *BufferOutSize is not zero. @retval EFI_ABORTED An error occurred. @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.**/EFI_STATUSEFIAPITlsHandleAlert ( IN VOID *Tls, IN UINT8 *BufferIn, OPTIONAL IN UINTN BufferInSize, OPTIONAL OUT UINT8 *BufferOut, OPTIONAL IN OUT UINTN *BufferOutSize ){ TLS_CONNECTION *TlsConn; UINTN PendingBufferSize; UINT8 *TempBuffer; INTN Ret; TlsConn = (TLS_CONNECTION *) Tls; PendingBufferSize = 0; TempBuffer = NULL; Ret = 0; if (TlsConn == NULL || / TlsConn->Ssl == NULL || TlsConn->InBio == NULL || TlsConn->OutBio == NULL || / BufferOutSize == NULL || / (BufferIn == NULL && BufferInSize != 0) || / (BufferIn != NULL && BufferInSize == 0) || / (BufferOut == NULL && *BufferOutSize != 0)) { return EFI_INVALID_PARAMETER; } PendingBufferSize = (UINTN) BIO_ctrl_pending (TlsConn->OutBio); if (PendingBufferSize == 0 && BufferIn != NULL && BufferInSize != 0) { Ret = BIO_write (TlsConn->InBio, BufferIn, (UINT32) BufferInSize); if (Ret != (INTN) BufferInSize) { return EFI_ABORTED; } TempBuffer = (UINT8 *) OPENSSL_malloc (MAX_BUFFER_SIZE); // // ssl3_send_alert() will be called in ssl3_read_bytes() function. // TempBuffer is invalid since it's a Alert message, so just ignore it. // SSL_read (TlsConn->Ssl, TempBuffer, MAX_BUFFER_SIZE); OPENSSL_free (TempBuffer); PendingBufferSize = (UINTN) BIO_ctrl_pending (TlsConn->OutBio); } if (PendingBufferSize > *BufferOutSize) { *BufferOutSize = PendingBufferSize; return EFI_BUFFER_TOO_SMALL; } if (PendingBufferSize > 0) { *BufferOutSize = BIO_read (TlsConn->OutBio, BufferOut, (UINT32) PendingBufferSize); } else { *BufferOutSize = 0; } return EFI_SUCCESS;}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:87,
示例21: asn1_bio_writestatic int asn1_bio_write(BIO *b, const char *in, int inl){ BIO_ASN1_BUF_CTX *ctx; int wrmax, wrlen, ret; unsigned char *p; if (!in || (inl < 0) || (b->next_bio == NULL)) return 0; ctx = (BIO_ASN1_BUF_CTX *)b->ptr; if (ctx == NULL) return 0; wrlen = 0; ret = -1; for (;;) { switch (ctx->state) { /* Setup prefix data, call it */ case ASN1_STATE_START: if (!asn1_bio_setup_ex(b, ctx, ctx->prefix, ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER)) return 0; break; /* Copy any pre data first */ case ASN1_STATE_PRE_COPY: ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free, ASN1_STATE_HEADER); if (ret <= 0) goto done; break; case ASN1_STATE_HEADER: ctx->buflen = ASN1_object_size(0, inl, ctx->asn1_tag) - inl; OPENSSL_assert(ctx->buflen <= ctx->bufsize); p = ctx->buf; ASN1_put_object(&p, 0, inl, ctx->asn1_tag, ctx->asn1_class); ctx->copylen = inl; ctx->state = ASN1_STATE_HEADER_COPY; break; case ASN1_STATE_HEADER_COPY: ret = BIO_write(b->next_bio, ctx->buf + ctx->bufpos, ctx->buflen); if (ret <= 0) goto done; ctx->buflen -= ret; if (ctx->buflen) ctx->bufpos += ret; else { ctx->bufpos = 0; ctx->state = ASN1_STATE_DATA_COPY; } break; case ASN1_STATE_DATA_COPY: if (inl > ctx->copylen) wrmax = ctx->copylen; else wrmax = inl; ret = BIO_write(b->next_bio, in, wrmax); if (ret <= 0) break; wrlen += ret; ctx->copylen -= ret; in += ret; inl -= ret; if (ctx->copylen == 0) ctx->state = ASN1_STATE_HEADER; if (inl == 0) goto done; break; default: BIO_clear_retry_flags(b); return 0; } } done: BIO_clear_retry_flags(b); BIO_copy_next_retry(b); return (wrlen > 0) ? wrlen : ret;}
开发者ID:gxliu,项目名称:openssl,代码行数:97,
示例22: TlsDoHandshake/** Perform a TLS/SSL handshake. This function will perform a TLS/SSL handshake. @param[in] Tls Pointer to the TLS object for handshake operation. @param[in] BufferIn Pointer to the most recently received TLS Handshake packet. @param[in] BufferInSize Packet size in bytes for the most recently received TLS Handshake packet. @param[out] BufferOut Pointer to the buffer to hold the built packet. @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is the buffer size provided by the caller. On output, it is the buffer size in fact needed to contain the packet. @retval EFI_SUCCESS The required TLS packet is built successfully. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: Tls is NULL. BufferIn is NULL but BufferInSize is NOT 0. BufferInSize is 0 but BufferIn is NOT NULL. BufferOutSize is NULL. BufferOut is NULL if *BufferOutSize is not zero. @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet. @retval EFI_ABORTED Something wrong during handshake.**/EFI_STATUSEFIAPITlsDoHandshake ( IN VOID *Tls, IN UINT8 *BufferIn, OPTIONAL IN UINTN BufferInSize, OPTIONAL OUT UINT8 *BufferOut, OPTIONAL IN OUT UINTN *BufferOutSize ){ TLS_CONNECTION *TlsConn; UINTN PendingBufferSize; INTN Ret; UINTN ErrorCode; TlsConn = (TLS_CONNECTION *) Tls; PendingBufferSize = 0; Ret = 1; if (TlsConn == NULL || / TlsConn->Ssl == NULL || TlsConn->InBio == NULL || TlsConn->OutBio == NULL || / BufferOutSize == NULL || / (BufferIn == NULL && BufferInSize != 0) || / (BufferIn != NULL && BufferInSize == 0) || / (BufferOut == NULL && *BufferOutSize != 0)) { return EFI_INVALID_PARAMETER; } if(BufferIn == NULL && BufferInSize == 0) { // // If RequestBuffer is NULL and RequestSize is 0, and TLS session // status is EfiTlsSessionNotStarted, the TLS session will be initiated // and the response packet needs to be ClientHello. // PendingBufferSize = (UINTN) BIO_ctrl_pending (TlsConn->OutBio); if (PendingBufferSize == 0) { SSL_set_connect_state (TlsConn->Ssl); Ret = SSL_do_handshake (TlsConn->Ssl); PendingBufferSize = (UINTN) BIO_ctrl_pending (TlsConn->OutBio); } } else { PendingBufferSize = (UINTN) BIO_ctrl_pending (TlsConn->OutBio); if (PendingBufferSize == 0) { BIO_write (TlsConn->InBio, BufferIn, (UINT32) BufferInSize); Ret = SSL_do_handshake (TlsConn->Ssl); PendingBufferSize = (UINTN) BIO_ctrl_pending (TlsConn->OutBio); } } if (Ret < 1) { Ret = SSL_get_error (TlsConn->Ssl, (int) Ret); if (Ret == SSL_ERROR_SSL || Ret == SSL_ERROR_SYSCALL || Ret == SSL_ERROR_ZERO_RETURN) { DEBUG (( DEBUG_ERROR, "%a SSL_HANDSHAKE_ERROR State=0x%x SSL_ERROR_%a/n", __FUNCTION__, SSL_get_state (TlsConn->Ssl), Ret == SSL_ERROR_SSL ? "SSL" : Ret == SSL_ERROR_SYSCALL ? "SYSCALL" : "ZERO_RETURN" )); DEBUG_CODE_BEGIN (); while (TRUE) { ErrorCode = ERR_get_error (); if (ErrorCode == 0) { break; } DEBUG (( DEBUG_ERROR, "%a ERROR 0x%x=L%x:F%x:R%x/n", __FUNCTION__, ErrorCode, ERR_GET_LIB (ErrorCode), ERR_GET_FUNC (ErrorCode),//.........这里部分代码省略.........
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:101,
示例23: schannel_openssl_client_process_tokensSECURITY_STATUS schannel_openssl_client_process_tokens(SCHANNEL_OPENSSL* context, PSecBufferDesc pInput, PSecBufferDesc pOutput){ int status; int ssl_error; PSecBuffer pBuffer; if (!context->connected) { if (pInput) { if (pInput->cBuffers < 1) return SEC_E_INVALID_TOKEN; pBuffer = sspi_FindSecBuffer(pInput, SECBUFFER_TOKEN); if (!pBuffer) return SEC_E_INVALID_TOKEN; status = BIO_write(context->bioRead, pBuffer->pvBuffer, pBuffer->cbBuffer); } status = SSL_connect(context->ssl); if (status < 0) { ssl_error = SSL_get_error(context->ssl, status); WLog_ERR(TAG, "SSL_connect error: %s", openssl_get_ssl_error_string(ssl_error)); } if (status == 1) context->connected = TRUE; status = BIO_read(context->bioWrite, context->ReadBuffer, SCHANNEL_CB_MAX_TOKEN); if (pOutput->cBuffers < 1) return SEC_E_INVALID_TOKEN; pBuffer = sspi_FindSecBuffer(pOutput, SECBUFFER_TOKEN); if (!pBuffer) return SEC_E_INVALID_TOKEN; if (status > 0) { if (pBuffer->cbBuffer < (unsigned long) status) return SEC_E_INSUFFICIENT_MEMORY; CopyMemory(pBuffer->pvBuffer, context->ReadBuffer, status); pBuffer->cbBuffer = status; return (context->connected) ? SEC_E_OK : SEC_I_CONTINUE_NEEDED; } else { pBuffer->cbBuffer = 0; return (context->connected) ? SEC_E_OK : SEC_I_CONTINUE_NEEDED; } } return SEC_E_OK;}
开发者ID:RangeeGmbH,项目名称:FreeRDP,代码行数:61,
示例24: mainint main(int argc, char **argv) { SSL_load_error_strings(); ERR_load_BIO_strings(); SSL_library_init(); /*BIO *SSLout = BIO_new_connect(BROKER_CONN); if (!SSLout) { fprintf(stderr, "Error creating BIO/n"); exit(EXIT_FAILURE); } if (BIO_do_connect(SSLout) <= 0) { fprintf(stderr,"Error connecting BIO/n"); exit(EXIT_FAILURE); } char buf[BUFSIZ]; */ printf("HERE/n"); SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method()); if (!SSL_CTX_load_verify_locations(ctx,BROKER_CERT,NULL)) { fprintf(stderr,"Failed to load broker cert/n"); exit(EXIT_FAILURE); } printf("HERE/n"); SSL *ssl = SSL_new(ctx); SSL_set_mode(ssl,SSL_MODE_AUTO_RETRY); BIO *sslconn = BIO_new_ssl_connect(ctx); BIO_get_ssl(sslconn, &ssl); printf("HERE/n"); // Do connection BIO_set_conn_hostname(sslconn,BROKER_CONN); BIO_set_conn_port(sslconn,BROKER_PORT); if (BIO_do_connect(sslconn) < 0) { fprintf(stderr,"Failed to make ssl connection/n"); fprintf(stderr,"Error description: %s/n", ERR_reason_error_string(ERR_get_error())); exit(EXIT_FAILURE); } int err; if((err = SSL_connect(ssl)) < 1) { fprintf(stderr, "Failed to initiate handshake:%s/n", ERR_reason_error_string(ERR_get_error())); } printf("HERE/n"); char buf[BUFSIZ]; strcpy(buf,"OHAITHAR!/n"); if( BIO_write(sslconn,buf,strlen(buf)) <= 0 ) { if(! BIO_should_retry(sslconn)) { } } /*if we want to reuse, start fresh BIO_reset(sslconn); */ BIO_free_all(sslconn); return 0;}
开发者ID:eltommo,项目名称:licenceliber,代码行数:66,
|