-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: tlsn-core #213
Draft: tlsn-core #213
Conversation
tlsn-core/src/session_header.rs
Outdated
/// Verifies the signature over the header against the public key. This is only called when we | ||
/// know that `signature` is Some(). | ||
/// | ||
/// Returns the verified header | ||
fn verify(&self, pubkey: &PubKey) -> Result<SessionHeader, Error> { | ||
let sig = match &self.signature { | ||
Some(sig) => sig, | ||
_ => return Err(Error::InternalError), | ||
}; | ||
|
||
match (sig, pubkey) { | ||
// signature and pubkey types must match | ||
(Signature::P256(_), PubKey::P256(_)) => { | ||
pubkey.verify(&self.header, &sig)?; | ||
} | ||
} | ||
|
||
Ok(self.header.clone()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be implemented on Signature
, eg
struct Signature(..);
impl Signature {
pub fn verify(&self, key: &PubKey, data: &[u8]) -> Result<(), SignatureError> {
..
}
}
or it can be implemented on PubKey
.. might want to look at some other crates to see what pattern they chose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently it is implemented on Pubkey
(line 112). p256
crate also impls it on pubkey
Ok(self.header.clone()) | ||
} | ||
|
||
/// Returns the session header only if the signature is not present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this method. It's a getter that fails if the signature is None
, but it's not clear why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this method shouldnt be pub
, sry for that.)
It is only called internally from SessionHeader::from_msg
It is a safety feature - the caller shouldn't be able to get SessionHeader
from SessionHeaderMsg
if a signature is present. If it is present, then SessionHeader
can only be obtained by calling SessionHeaderMsg::veriffy
. This prevents the caller from accidentally skipping verification.
closing, superceded by #232 |
see the test in tlsn-core/src/lib.rs for the API example