Struct rings_core::session::Session
source · pub struct Session {
pub sig: Vec<u8>,
pub auth: AuthorizedInfo,
}Expand description
Session contain signature which sign with Signer, so need AuthorizedInfo as well.
Fields§
§sig: Vec<u8>§auth: AuthorizedInfoImplementations§
source§impl Session
impl Session
sourcepub fn new(sig: &[u8], auth_info: &AuthorizedInfo) -> Self
pub fn new(sig: &[u8], auth_info: &AuthorizedInfo) -> Self
Examples found in repository?
src/session.rs (line 215)
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
pub fn new(sig: &[u8], auth_info: &AuthorizedInfo, session_key: &SecretKey) -> Self {
let inner = SessionWithKey {
session: Session::new(sig, auth_info),
session_key: *session_key,
};
Self {
inner: Arc::new(RwLock::new(inner)),
}
}
/// generate Session with private key
/// only use it for unittest
pub fn new_with_seckey(key: &SecretKey, ttl: Option<Ttl>) -> Result<Self> {
let (auth, s_key) = Self::gen_unsign_info(key.address().into(), ttl, None);
let sig = key.sign(&auth.to_string()?).to_vec();
Ok(Self::new(&sig, &auth, &s_key))
}
pub fn renew(&self, sig: &[u8], auth_info: &AuthorizedInfo, key: &SecretKey) -> Result<&Self> {
let new_inner = SessionWithKey {
session: Session::new(sig, auth_info),
session_key: *key,
};
let mut inner = self
.inner
.try_write()
.map_err(|_| Error::SessionTryLockFailed)?;
*inner = new_inner;
Ok(self)
}sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Examples found in repository?
src/session.rs (line 114)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
pub fn verify(&self) -> bool {
if self.is_expired() {
return false;
}
if let Ok(auth_str) = self.auth.to_string() {
match self.auth.signer {
Signer::DEFAULT => {
signers::default::verify(&auth_str, &self.auth.authorizer.did.into(), &self.sig)
}
Signer::EIP191 => {
signers::eip191::verify(&auth_str, &self.auth.authorizer.did.into(), &self.sig)
}
Signer::EdDSA => match self.authorizer_pubkey() {
Ok(p) => signers::ed25519::verify(
&auth_str,
&self.auth.authorizer.did.into(),
&self.sig,
p,
),
Err(_) => false,
},
}
} else {
false
}
}sourcepub fn verify(&self) -> bool
pub fn verify(&self) -> bool
Examples found in repository?
More examples
src/message/protocols/verify.rs (line 23)
21 22 23 24 25 26 27 28 29 30 31 32 33 34
pub fn verify<T>(&self, data: &T) -> bool
where T: Serialize {
if !self.session.verify() {
tracing::warn!("session is expired");
return false;
}
if let (Ok(did), Ok(msg)) = (self.session.did(), self.msg(data)) {
signers::default::verify(&msg, &did, &self.sig)
} else {
tracing::warn!("failed to verify message");
false
}
}sourcepub fn did(&self) -> Result<Did>
pub fn did(&self) -> Result<Did>
Examples found in repository?
src/message/protocols/verify.rs (line 28)
21 22 23 24 25 26 27 28 29 30 31 32 33 34
pub fn verify<T>(&self, data: &T) -> bool
where T: Serialize {
if !self.session.verify() {
tracing::warn!("session is expired");
return false;
}
if let (Ok(did), Ok(msg)) = (self.session.did(), self.msg(data)) {
signers::default::verify(&msg, &did, &self.sig)
} else {
tracing::warn!("failed to verify message");
false
}
}Examples found in repository?
src/session.rs (line 125)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
pub fn verify(&self) -> bool {
if self.is_expired() {
return false;
}
if let Ok(auth_str) = self.auth.to_string() {
match self.auth.signer {
Signer::DEFAULT => {
signers::default::verify(&auth_str, &self.auth.authorizer.did.into(), &self.sig)
}
Signer::EIP191 => {
signers::eip191::verify(&auth_str, &self.auth.authorizer.did.into(), &self.sig)
}
Signer::EdDSA => match self.authorizer_pubkey() {
Ok(p) => signers::ed25519::verify(
&auth_str,
&self.auth.authorizer.did.into(),
&self.sig,
p,
),
Err(_) => false,
},
}
} else {
false
}
}More examples
src/transports/default/transport.rs (line 503)
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
async fn register_remote_info(&self, data: Encoded) -> Result<Did> {
let data: MessagePayload<TricklePayload> = data.decode()?;
tracing::trace!("register remote info: {:?}", data);
match data.verify() {
true => {
let sdp = serde_json::from_str::<RTCSessionDescription>(&data.data.sdp)
.map_err(Error::Deserialize)?;
tracing::trace!("setting remote sdp: {:?}", sdp);
self.set_remote_description(sdp).await?;
tracing::trace!("setting remote candidate");
for c in &data.data.candidates {
tracing::trace!("add candidates: {:?}", c);
if self.add_ice_candidate(c.clone()).await.is_err() {
tracing::warn!("failed on add add candidates: {:?}", c.clone());
};
}
if let Ok(public_key) = data.origin_verification.session.authorizer_pubkey() {
let mut pk = self.public_key.write().await;
*pk = Some(public_key);
};
{
let mut services = self.services.write().await;
*services = data.data.services.into_iter().collect();
}
Ok(data.addr)
}
_ => {
tracing::error!("cannot verify message sig");
return Err(Error::VerifySignatureFailed);
}
}
}Trait Implementations§
source§impl<'de> Deserialize<'de> for Session
impl<'de> Deserialize<'de> for Session
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<Session> for Session
impl PartialEq<Session> for Session
impl Eq for Session
impl StructuralEq for Session
impl StructuralPartialEq for Session
Auto Trait Implementations§
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.