Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rust Openssl
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public Repositories
Rust Openssl
Commits
a495465b
Commit
a495465b
authored
10 years ago
by
Steven Fackler
Browse files
Options
Downloads
Plain Diff
Merge pull request #50 from vhbit/cert-fingerprint
Get certificate fingerprint
parents
efa1a719
f508b7f0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ssl/ffi.rs
+3
-1
3 additions, 1 deletion
src/ssl/ffi.rs
src/ssl/mod.rs
+25
-1
25 additions, 1 deletion
src/ssl/mod.rs
with
28 additions
and
2 deletions
src/ssl/ffi.rs
+
3
−
1
View file @
a495465b
#![allow(non_camel_case_types)]
use
libc
::{
c_int
,
c_void
,
c_long
,
c_ulong
,
c_char
};
use
libc
::{
c_int
,
c_void
,
c_long
,
c_ulong
,
c_char
,
c_uint
};
use
crypto
::
hash
::{
EVP_MD
};
pub
type
SSL_CTX
=
c_void
;
pub
type
SSL_METHOD
=
c_void
;
...
...
@@ -145,6 +146,7 @@ extern "C" {
pub
fn
X509_STORE_CTX_get_error
(
ctx
:
*
mut
X509_STORE_CTX
)
->
c_int
;
pub
fn
X509_get_subject_name
(
x
:
*
mut
X509
)
->
*
mut
X509_NAME
;
pub
fn
X509_digest
(
x
:
*
mut
X509
,
digest
:
*
const
EVP_MD
,
buf
:
*
mut
c_char
,
len
:
*
mut
c_uint
)
->
c_int
;
pub
fn
SSL_new
(
ctx
:
*
mut
SSL_CTX
)
->
*
mut
SSL
;
pub
fn
SSL_free
(
ssl
:
*
mut
SSL
);
...
...
This diff is collapsed.
Click to expand it.
src/ssl/mod.rs
+
25
−
1
View file @
a495465b
use
libc
::{
c_int
,
c_void
,
c_char
};
use
libc
::{
c_int
,
c_uint
,
c_void
,
c_char
};
use
std
::
io
::{
IoResult
,
IoError
,
EndOfFile
,
Stream
,
Reader
,
Writer
};
use
std
::
mem
;
use
std
::
ptr
;
...
...
@@ -6,6 +6,7 @@ use std::rt::mutex::NativeMutex;
use
std
::
string
;
use
sync
::
one
::{
Once
,
ONCE_INIT
};
use
crypto
::
hash
::{
HashType
,
evpmd
};
use
ssl
::
error
::{
SslError
,
SslSessionClosed
,
StreamError
};
pub
mod
error
;
...
...
@@ -230,6 +231,29 @@ impl<'ctx> X509<'ctx> {
let
name
=
unsafe
{
ffi
::
X509_get_subject_name
(
self
.x509
)
};
X509Name
{
x509
:
self
,
name
:
name
}
}
/// Returns certificate fingerprint calculated using provided hash
pub
fn
fingerprint
(
&
self
,
hash_type
:
HashType
)
->
Option
<
Vec
<
u8
>>
{
let
(
evp
,
len
)
=
evpmd
(
hash_type
);
let
v
:
Vec
<
u8
>
=
Vec
::
from_elem
(
len
,
0
);
let
act_len
:
c_uint
=
0
;
let
res
=
unsafe
{
ffi
::
X509_digest
(
self
.x509
,
evp
,
mem
::
transmute
(
v
.as_ptr
()),
mem
::
transmute
(
&
act_len
))
};
match
res
{
0
=>
None
,
_
=>
{
let
act_len
=
act_len
as
uint
;
match
len
.cmp
(
&
act_len
)
{
Greater
=>
None
,
Equal
=>
Some
(
v
),
Less
=>
fail!
(
"Fingerprint buffer was corrupted!"
)
}
}
}
}
}
#[allow(dead_code)]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment