aboutsummaryrefslogtreecommitdiff
path: root/openssl
diff options
context:
space:
mode:
Diffstat (limited to 'openssl')
-rw-r--r--openssl/src/crypto/pkey.rs12
-rw-r--r--openssl/src/ssl/mod.rs8
-rw-r--r--openssl/src/ssl/tests.rs1
-rw-r--r--openssl/src/x509/mod.rs9
-rw-r--r--openssl/src/x509/tests.rs3
5 files changed, 23 insertions, 10 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index 8454f252..33433b0c 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -11,7 +11,7 @@ use ffi;
use ssl::error::{SslError, StreamError};
#[derive(Copy, Clone)]
-enum Parts {
+pub enum Parts {
Neither,
Public,
Both
@@ -70,6 +70,16 @@ impl PKey {
}
}
+ pub fn from_handle(handle: *mut ffi::EVP_PKEY, parts: Parts) -> PKey {
+ ffi::init();
+ assert!(!handle.is_null());
+
+ PKey {
+ evp: handle,
+ parts: parts,
+ }
+ }
+
/// Reads private key from PEM, takes ownership of handle
pub fn private_key_from_pem<R>(reader: &mut R) -> Result<PKey, SslError> where R: Read {
let mut mem_bio = try!(MemBio::new());
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 0dd2b3cb..26851ade 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -805,13 +805,7 @@ impl<S: Read+Write> SslStream<S> {
SslStream::new_server_from(ssl, stream)
}
- /// Returns a mutable reference to the underlying stream.
- ///
- /// ## Warning
- ///
- /// `read`ing or `write`ing directly to the underlying stream will most
- /// likely desynchronize the SSL session.
- #[deprecated="use get_mut instead"]
+ #[doc(hidden)]
pub fn get_inner(&mut self) -> &mut S {
self.get_mut()
}
diff --git a/openssl/src/ssl/tests.rs b/openssl/src/ssl/tests.rs
index dec1d992..688a5db6 100644
--- a/openssl/src/ssl/tests.rs
+++ b/openssl/src/ssl/tests.rs
@@ -429,7 +429,6 @@ fn test_npn_server_advertise_multiple() {
mod dtlsv1 {
use serialize::hex::FromHex;
use std::net::TcpStream;
- use std::old_io::{Writer};
use std::thread;
use crypto::hash::Type::{SHA256};
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 50731e48..c0e730f7 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -11,7 +11,7 @@ use asn1::{Asn1Time};
use bio::{MemBio};
use crypto::hash;
use crypto::hash::Type as HashType;
-use crypto::pkey::{PKey};
+use crypto::pkey::{PKey,Parts};
use crypto::rand::rand_bytes;
use ffi;
use ssl::error::{SslError, StreamError};
@@ -402,6 +402,13 @@ impl<'ctx> X509<'ctx> {
X509Name { x509: self, name: name }
}
+ pub fn public_key(&self) -> PKey {
+ let pkey = unsafe { ffi::X509_get_pubkey(self.handle) };
+ assert!(!pkey.is_null());
+
+ PKey::from_handle(pkey, Parts::Public)
+ }
+
/// Returns certificate fingerprint calculated using provided hash
pub fn fingerprint(&self, hash_type: hash::Type) -> Option<Vec<u8>> {
let evp = hash_type.evp_md();
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index 5ea0c1dc..1788b556 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -2,6 +2,7 @@ use serialize::hex::FromHex;
use std::io;
use std::path::Path;
use std::fs::File;
+use std::str;
use crypto::hash::Type::{SHA256};
use x509::{X509, X509Generator};
@@ -28,6 +29,8 @@ fn test_cert_gen() {
// FIXME: check data in result to be correct, needs implementation
// of X509 getters
+
+ assert_eq!(pkey.save_pub(), cert.public_key().save_pub());
}
#[test]