| 581 | } |
| 582 | |
| 583 | struct deserialize_impl |
| 584 | { |
| 585 | explicit deserialize_impl(const DDS::OctetSeq& src) |
| 586 | : src_(src), buffer_(BIO_new(BIO_s_mem())) |
| 587 | {} |
| 588 | |
| 589 | ~deserialize_impl() |
| 590 | { |
| 591 | BIO_free(buffer_); |
| 592 | } |
| 593 | |
| 594 | int operator() (X509*& dst) |
| 595 | { |
| 596 | if (dst) { |
| 597 | ACE_ERROR((LM_WARNING, |
| 598 | "(%P|%t) SSL::Certificate::deserialize: WARNING, an X509 certificate " |
| 599 | "has already been loaded\n")); |
| 600 | return 1; |
| 601 | } |
| 602 | |
| 603 | if (0 == src_.length()) { |
| 604 | ACE_ERROR((LM_WARNING, |
| 605 | "(%P|%t) SSL::Certificate::deserialize: WARNING, source OctetSeq contains no data")); |
| 606 | return 1; |
| 607 | } |
| 608 | |
| 609 | if (!buffer_) { |
| 610 | OPENDDS_SSL_LOG_ERR("failed to allocate buffer with BIO_new"); |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | const int len = BIO_write(buffer_, src_.get_buffer(), static_cast<int>(src_.length())); |
| 615 | if (len <= 0) { |
| 616 | OPENDDS_SSL_LOG_ERR("failed to write OctetSeq to BIO"); |
| 617 | return 1; |
| 618 | } |
| 619 | |
| 620 | dst = PEM_read_bio_X509_AUX(buffer_, 0, 0, 0); |
| 621 | if (! dst) { |
| 622 | OPENDDS_SSL_LOG_ERR("failed to read X509 from BIO"); |
| 623 | return 1; |
| 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | private: |
| 630 | const DDS::OctetSeq& src_; |
| 631 | BIO* buffer_; |
| 632 | }; |
| 633 | |
| 634 | int Certificate::deserialize(const DDS::OctetSeq& src) |
| 635 | { |